ThreeJS bufferGeometry 位置属性在应用翻译时不会更新

2024-04-30

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

然后我用了

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;

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


您想要获取网格几何体的世界位置,同时考虑网格体的变换矩阵,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.fromBufferAttribute( attribute, index ); // extract the x,y,z coordinates

vec.applyMatrix4( mesh.matrix ); // apply the mesh's matrix transform

三.js r157

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

ThreeJS bufferGeometry 位置属性在应用翻译时不会更新 的相关文章