I am using objloader to load multiple objects. I am trying to move one of the objects and need to have the updated vertex positions. while loading the objects I converted the buffergeometry to geometry and run some functions. I checked some samples all updating the vertices of the buffergeometry. Do I need to convert it back to buffergeometry or not ? I need to have the real time positions while moving to calculate some other functions, so I prefer not to keep on converting from buffer to geometry and vice versa.
Here is a piece of code:
var tool= new THREE.OBJLoader();
tool.load( '../obj/tool.obj', function ( object ) {
var material = new THREE.MeshLambertMaterial({color:0xA0A0A0});
object.traverse( function ( child ) {
if ( child instanceof THREE.Mesh ) {
child.material = material;
Geometry = new THREE.Geometry().fromBufferGeometry(child.geometry);
}
console.log(Geometry.vertices[220]);
Geometry.position.x += 0.01;
Geometry.verticesNeedUpdate = true;
console.log(Geometry.vertices[220]);
Besides, I checked the migration document of the latest versions and checked them out.
OBJLoader
returnsBufferGeometry
. You can update a vertex position like so:Study http://threejs.org/docs/#Reference/Core/BufferAttribute
Instead, you can convert to
Geometry
. In your case, do the following in the loader callback:You then update a vertex position using this pattern:
Only set the
needsUpdate
flag if the geometry has been previously rendered.three.js r.71