use*_*195 3 javascript three.js
我想将我已经放置的对象放在一个新位置,但它从本地位置而不是全局位置移动。
this._scene.updateMatrixWorld();
this._scene.add(mesh);
var v1 = new THREE.Vector3();
v1.setFromMatrixPosition( mesh.matrixWorld );
mesh.position.set(v1.x +2, v1.y + 2, v1.z + 2);
Run Code Online (Sandbox Code Playgroud)
我做了什么来解决我的问题:
每个网格都有一个几何属性。这就是为什么你可以调用mesh.geometry。从这一点开始,我在我的网格周围创建了一个 BoundingSphere。
mesh.geometry.computeBoundingSphere();
Run Code Online (Sandbox Code Playgroud)
现在可以获得我的 boundingSphere 的世界位置,同时也是我的网格的世界位置。
var vector = mesh.geometry.boundingSphere.center;
Run Code Online (Sandbox Code Playgroud)
恭喜!'vector'在网格的 (x,y,z) 中获得了中心世界位置。
澄清一下,'mesh' 是一个 THREE.Mesh 对象。
| 归档时间: |
|
| 查看次数: |
4624 次 |
| 最近记录: |