应用转换时,ThreeJS bufferGeometry位置属性未更新

ahm*_*sny 4 javascript three.js buffer-geometry

我使用STLLoader将stl加载到返回BufferGeometry的ThreeJS场景上。

然后我用

myMesh.position.set( x,y,z ) 
myMesh.rotation.setFromQuaternion ( quaternion , 'XYZ');
Run Code Online (Sandbox Code Playgroud)

平移几何。这有效地改变了

myMesh.position
myMesh.quaternion
Run Code Online (Sandbox Code Playgroud)

翻译正在现场进行,并且一切正常。我期望

myMesh.geometry.attributes.position.array
Run Code Online (Sandbox Code Playgroud)

翻译前后会有所不同-但仍然相同。我想在翻译后从buffergeometry中提取新的veritces。我试图打电话

myMesh.geometry.dynamic = true;
myMesh.geometry.attributes.position.needsUpdate = true;
Run Code Online (Sandbox Code Playgroud)

在渲染循环中,但是没有运气,因为我还没有明确更新顶点。

Wes*_*ley 5

您想要获得网格几何图形的世界位置,同时考虑到网格的变换矩阵mesh.matrix。另外,您的网格几何形状为THREE.BufferGeometry

这是遵循的模式:

mesh = new THREE.Mesh( geometry, material );
mesh.position.set( 10, 10, 10 );
mesh.rotation.set( - Math.PI / 2, 0, 0 );
mesh.scale.set( 1, 1, 1 );
scene.add( mesh );

mesh.updateMatrix(); // make sure the mesh's matrix is updated

var vec = new THREE.Vector3();
var attribute = mesh.geometry.attributes.position; // we want the position data
var index = 1; // index is zero-based, so this the the 2nd vertex

vec.fromAttribute( attribute, index ); // extract the x,y,z coordinates

vec.applyMatrix4( mesh.matrix ); // apply the mesh's matrix transform
Run Code Online (Sandbox Code Playgroud)

three.js r.71