2015-09-07 428 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

相關問題