我有一个从另一个网格克隆的网格。但克隆后,我对其进行平移和旋转。并对它进行光线转换,但它没有按预期工作。在平移和旋转之前保持与原始位置相交。示例代码如下
const raycaster = THREE.Raycaster()
const proposedModel = model.clone()
proposedModel.translateX(1)
proposedModel.translateY(1)
proposedModel.translateZ(1)
const q = new THREE.Quaternion(
-0.847,
-0.002,
-0.505,
0.168
)
proposedModel.applyQuaternion(q)
const point = new THREE.Vector3(1,1,1)
raycaster.set(point, new THREE.Vector3(1,1,1))
const intersects = raycaster.intersectObject(object) // It keep intersecting with original position
很高兴有帮助,谢谢!
最佳答案
变换后从网格中调用 updateMatrixWorld() 将解决问题。感谢@prisoner849
提议的Model.updateMatrixWorld()
原因是
An object's matrix stores the object's transformation relative to the object's parent; to get the object's transformation in world coordinates, you must access the object's Object3D.matrixWorld.
When either the parent or the child object's transformation changes, you can request that the child object's matrixWorld be updated by calling updateMatrixWorld().
在此处查看详细信息 https://threejs.org/docs/#manual/introduction/Matrix-transformations
关于javascript - Three.js 中动态更改网格后的光线转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48662643/