3

My jQuery:

<script type="text/javascript">
$(document).ready(function(){

$("#button").click(function(){
cube[0].mesh.material.uniforms.texture.value = THREE.ImageUtils.loadTexture("textures/envmap.png");
cube[0].mesh.material.uniforms.texture.needsUpdate = true;
});

});
</script>

I have an array of cubes, and I want to be able to change the texture of the cube when clicking on the #button div.

I get this error in chrome when clicking on the div:

Uncaught TypeError: Cannot read property 'material' of undefined 

How is it possible to change the texture or color for cube[0] that is a THREE.CubeGeometry object.

I have a JS fiddle here: http://jsfiddle.net/SCXNQ/559/

1 Answer 1

2

Follow this example: http://mrdoob.github.com/three.js/examples/webgl_materials_cars.html

Use console.log to debug your app, you are trying to access non-existent objects such as cube[0], or cube.mesh. You get the material by using cube.material. There are no uniforms array because you are using a MeshBasicMaterial.

Thee needsUpdate=true should be triggered in a texture's onload listener.

Sign up to request clarification or add additional context in comments.

3 Comments

can you create a simple example with a cube?
Can you create a simple example with textures, just as I created with colors_
@Railsbeginner Three.js updated so your example didn't work anymore so I went and put a fix: jsfiddle.net/SCXNQ/1007

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.