question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to update cube face canvas texture

See original GitHub issue

Hi there,

I’m quite a beginner with three.js and I’m trying to update text string on a canvas that is a the texture of a cube face.

Here’s the relevant code I use for texture creation:

var canvas = changeCanvas(); // a custom function just to get the canvas by its id and change the text on it
var texture = new THREE.Texture(canvas);
texture.needsUpdate = true;
materials.push( new THREE.MeshBasicMaterial( { map: texture, overdraw: true } ) ); // for the canvas face only. other faces are just new THREE.MeshBasicMaterial( { color: Math.random() * 0xffffff } )

For Cube creation I use the following:

cube = new THREE.Mesh( new THREE.CubeGeometry( 200, 200, 200, 1, 1, 1, materials ), new THREE.MeshFaceMaterial() );

I’m using WebGLRenderer but I’ve also tried to use CanvasRenderer.

The cube is created and on of its faces is indeed the canvas with the text string (other 5 faces are just color squares). I also have on the page the canvas which I choose to show just for debugging purposes.

My problem is that after creation of the cube the text string is changed. I see the changes on the canvas I created in the page. but the same canvas and the text string are not updated when presented on the cube face. I’ve look at number of examples

What am I missing to make the texture updating? I’ve looked at several code examples here plus searched the issues but I still can’t find a solution for this.

Thanks in advance for any help 😃

Issue Analytics

  • State:closed
  • Created 12 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mrdoobcommented, Jun 26, 2012
1reaction
WestLangleycommented, Mar 19, 2012

You need to set texture.needsUpdate = true; as it is set to false afer rendering.

http://jsfiddle.net/xF27w/7/

EDIT:

onKeyDown doesn’t work there.

It does in this fiddle. (I haven’t studied it, so I don’t know what the trick is.) http://jsfiddle.net/2TCvY/3/

Read more comments on GitHub >

github_iconTop Results From Across the Web

UV map of a cube set up once and then draw to a canvas ...
One way would be to mutate the uv attributes over time so that the locations in a single texture change. The other way...
Read more >
Three.js Update Texture image - javascript
I currently have textures for each face of each cube and apply them by making shader materials with the following functions. this.
Read more >
Cubemap | Learn PlayCanvas
You can also select a cubemap face slot and then select a texture asset from ... Under 'Reproject' section, change the 'source' to...
Read more >
Three.js Canvas Textures
The only extra thing we need to do is set the needsUpdate property of the CanvasTexture to tell three.js to update the texture...
Read more >
WebGL2 Cubemaps
Another kind of texture is a cubemap. It consists of 6 faces representing the 6 faces of a cube. Instead of the traditional...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found