2015-09-07 427 views
3

我使用STLLoader将stl加载到返回BufferGeometry的threeJS场景中。ThreeJS bufferGeometry位置属性在应用转换时不更新

然后我用

myMesh.position.set(x,y,z) 
myMesh.rotation.setFromQuaternion (quaternion , 'XYZ'); 

翻译的几何形状。这有效地改变了场景中正在发生的翻译,并且一切正常。 我预计

myMesh.geometry.attributes.position.array 

会前和翻译后的不同 - 但它仍然是相同的。 我想在翻译之后从缓冲几何中提取新的veritces。 我试着打电话给

myMesh.geometry.dynamic = true; 
myMesh.geometry.attributes.position.needsUpdate = true; 
在渲染循环

,但没有运气,因为我还没有更新的顶点明确地。

+0

设置啮合位置不修改几何属性数据。另外,也可以使用'myMesh.quaternion.copy(quaternion)'。 – WestLangley

回答

4

你想获得一个网格几何的世界上的地位,同时考虑到网格的变换矩阵,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 

three.js所r.71

相关问题