Hi,
Im trying to update the vertex coordinates on the geometry of a (custom) mesh by doing this on some loop callback:
<meshvar>.geometry.vertices[idx].position.y = someNewYVal;
however the render on the screen is not showing the modifications. My question is whether this should work and the error is somewhere else... or is there anything I need to do to 'invalidate' the mesh geometry?
Thanks!
You are correct, just missing one piece:
.geometry.__dirtyVertices = true;
There are several __dirty* flags which aid performance. They keep the renderer from updating every single geometry value unless it is told otherwise.
It sitll does not work, probably due to my Javascript noobness.
Im doing something like this on startup:
var geometry = new Geometry()
geometry.vertices = someVerticeArray;
geometry.faces = someFaceArray;
geometry.boundingSphere = someIntVal;
this.floor = new THREE.Mesh(geometry, someMaterial)
this.three.scene.add(this.floor);
(floor and three are stored in the class and thus far all works fine)
then... on the loop callback Im doing
this.floor.geometry.vertices[idx].y = someNewYVal;
this.floor.geometry.__dirtyVertices = true;
but nothing happens on the screen.
the only way it works is if I create a new Geometry and a new Mesh from that Geometry, remove the previous Mesh from the scene and add the new one, something like this, on the loop callback:
this.three.scene.remove(this.floor);
var geometry = new THREE.Geometry();
geometry.vertices = this.floor.geometry.vertices; // the updated vertices
geometry.faces = this.floor.geometry.faces;
geometry.boundingSphere = Math.max(this.tileCount.x, this.tileCount.y);
var mesh = new THREE.Mesh(geometry, this.floorMaterial);
this.floor = mesh;
this.three.scene.add(this.floor);
Can you spot what Im doing wrong?
Ah, sorry about that, one more thing to add when you create the geometry:
geometry.dynamic = true;
Yeah that works. Thanks a lot, it's so much faster!!!!
geometry.__dirtyVertices no longer exists. What's the new approach. This issue features quite highly in search results on the topic, so it'd be good to include an up to date explanation here.
It's now geomety.verticesNeedUpdate.
I've a similar problem. I'm still a noob. I have created a 3D cylinder geometry with a set of 2D points using LatheGeometry class. Now I have a small sphere in the scene. What I want is, when the sphere touches the cylinder, I want a groove in the surface of the cylinder at the point of collision. My question is, if I find the collision point using Raycaster, then how do I get to the point (that I defined in 2D) and change the geometry?
Or do I have to do it in some other way? And another question is, if I get to the point (that I defined in 2D) do I have to redraw the cylinder using LatheGeometry?
Most helpful comment
It's now
geomety.verticesNeedUpdate.