How to create mutable objects in THREE.JS

Suppose I have a simple cube and some variables that determine its width, height and depth.

How to update a three-dimensional grid when changing w / h / d? (I have everything else, like changelisteners, etc.). Am I updating the vertices directly? Or is it easier to just redraw everything?

+2
source share
1 answer

It seems to me the easiest way to create your own cube with 1 units of measure (1x1x1). Then set the dimensions by scaling it:

mesh.scale.x = width;
mesh.scale.y = height;
mesh.scale.z = depth;

Not sure if grid supports scale, if not, you can wrap it in Object3D

var obj = new THREE.Object3D();
    obj.add(mesh);
obj.scale.x = width;
obj.scale.y = height;
obj.scale.z = depth;

Nothing prevents you from directly changing vertices. I think you need to specify geometry.dynamic=true;, and then geometry.verticesNeedUpdate=true;in this case.

+5
source

All Articles