Three.js 从其子项中获取父对象(一组)
Three.js getting the parent object (a group) from it's children
在我的场景中,有很多对象组 (Object3D),我已经设置了一个系统来单击/悬停在它们上面以执行某些操作。当它使用光线投射器查找鼠标下方的对象时,它 returns 单个对象,而不是组(我需要)。
我用来获取光标下对象的代码如下所示:
raycaster.setFromCamera(mouse, camera);
clickobjstore = raycaster.intersectObjects(objects, true);
// The following doesn't work because intersects[0] is not the group, it's the object within the group!
for (j = 0; j < intersects[0].object.children.length; j++) {
intersects[0].object.children[j].material.color.setHex(0x1A75FF);
}
Object3D class 为您存储对 parent
-对象的引用:
var objectGroup = intersects[0].parent;
for (j = 0; j < objectGroup.children.length; j++) {
objectGroup.children[j].material.color.setHex(0x1A75FF);
}
在我的场景中,有很多对象组 (Object3D),我已经设置了一个系统来单击/悬停在它们上面以执行某些操作。当它使用光线投射器查找鼠标下方的对象时,它 returns 单个对象,而不是组(我需要)。
我用来获取光标下对象的代码如下所示:
raycaster.setFromCamera(mouse, camera);
clickobjstore = raycaster.intersectObjects(objects, true);
// The following doesn't work because intersects[0] is not the group, it's the object within the group!
for (j = 0; j < intersects[0].object.children.length; j++) {
intersects[0].object.children[j].material.color.setHex(0x1A75FF);
}
Object3D class 为您存储对 parent
-对象的引用:
var objectGroup = intersects[0].parent;
for (j = 0; j < objectGroup.children.length; j++) {
objectGroup.children[j].material.color.setHex(0x1A75FF);
}