typescript - ThreeJS 将一个网格世界位置旋转复制到另一个
问题描述
我有 3 个网格:cube(a)、tempSphere(b)、m_mesh(c)。我在一个组中有网格 a 和 b,a 作为父级。
我设置了组的位置旋转和位置,a 和 b 应该自行更新。现在我想将 c 设置为 b 的当前位置和旋转。这就是我所拥有的并且不起作用
const cube: Mesh = this.createCube(size, objectColor);
group.add(cube);
const homePos: THREE.Vector3 = this.getHomePosition(size, homePosition);
const tempSphere = this.createHomePosition(cube, homePosition);
group.add(tempSphere);
// set local position of group
group.position.x = meshPosition.x;
group.position.y = meshPosition.y;
group.position.z = meshPosition.z;
// set local rotation of group
const rad = rotationZ * Math.PI / 180;
group.rotation.z = rad;
// trying to update world matrix of group and tempSphere
group.updateMatrixWorld(true);
tempSphere.updateMatrix();
tempSphere.updateMatrixWorld(true);
tempSphere.updateWorldMatrix(true, true);
// get world matrix of tempSphere
let worldRotQuat: THREE.Quaternion;
let worldPos: THREE.Vector3;
tempSphere.getWorldQuaternion(worldRotQuat);
tempSphere.getWorldPosition(worldPos);
// set world matrix of tempSphere to outside mesh
if (this.transScaleTool.m_mesh !== null) {
this.transScaleTool.m_mesh.matrixWorld.setRotationFromQuaternion(worldRotQuat);
this.transScaleTool.m_mesh.matrixWorld.setPosition(worldPos);
}
解决方案
它应该是以下代码模式(假设c
没有旋转的父级):
b.getWorldQuaternion( c.quaternion );
Object3D.getWorldQuaternion()
自动更新世界矩阵,b
因此不需要手动更新调用。
推荐阅读
- json - 如何从 couchbase 查询深层嵌套的 json 值?
- python - 如何在python中缓存类级别的属性?
- visual-studio-2015 - Skia C++ VS2015 项目设置
- angular - *ngIf 条件在 HTTP 请求完成后没有更新?
- php - 是否可以在 Laravel 的当前模型中获取相关模型的数据?
- excel - vba:将工作簿添加到集合
- docker - OKD 3.9 jenkins slave 权限被拒绝
- postgresql - 去模拟 postgresql 错误
- .net - System.Windows.Forms 对象禁用 AzureRM cmdlet
- java - BufferedWriter.newLine() 除了最后一行之后