Three.js changes texture to material

I set up the texture on the grid in the three.js file, and when it loads, it looks the way I want it too:

texture = THREE.ImageUtils.loadTexture("textures/hash.png"); texture.needsUpdate = true; uniforms = { color: { type: "c", value: new THREE.Color( 0xffffff ) }, texture: { type: "t", value: texture }, }, vertexShader = "varying vec2 vUv; void main() {vUv = uv;gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );}", fragmentShader = "uniform vec3 color; uniform sampler2D texture; varying vec2 vUv; void main() { vec4 tColor = texture2D( texture, vUv ); gl_FragColor = vec4( mix( color, tColor.rgb, tColor.a ), 1.0 );}", material = new THREE.ShaderMaterial({ uniforms : uniforms, vertexShader : vertexShader, fragmentShader : fragmentShader }); 

but I want to change the texture that is on this grid later, I tried this:

 obj.mesh.material.uniforms.texture = THREE.ImageUtils.loadTexture("textures/1.png"); obj.mesh.material.uniforms.texture.needsUpdate = true; 

but this does not change the texture displayed on the grid, how can I change the texture to THREE.ShaderMaterial?

+8
javascript textures
source share
1 answer

Assign the texture obj.mesh.material.uniforms.texture.value . Also consider setting the needsUpdate flag after a successful texture load (subscribe to a load event).

+10
source share

All Articles