ThreeJS缓冲几何体的位置属性在应用平移时未更新。

6

我使用STLLoader将一个stl文件加载到threeJS场景中,返回一个BufferGeometry。

然后我使用

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

翻译几何图形。这实际上改变了

myMesh.position
myMesh.quaternion

翻译正在进行中,一切都正常。我预计

的内容是:
myMesh.geometry.attributes.position.array

在翻译之前和之后,内容可能会有所不同,但仍然保持相同。 我想从缓冲几何体中提取翻译后的新顶点。 我尝试调用

myMesh.geometry.dynamic = true;
myMesh.geometry.attributes.position.needsUpdate = true;

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


设置网格位置不会修改几何属性数据。另外,请使用myMesh.quaternion.copy( quaternion )代替。 - WestLangley
1个回答

7

您想获取一个网格几何体的世界位置,考虑到网格的变换矩阵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


总体评论:fromAttribute已更名为fromBufferAttribute(github.com/mrdoob/three.js/pull/10412)。 - undefined

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接