最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Three.js getting the parent object (a group) from it's children - Stack Overflow

programmeradmin1浏览0评论

In my scene, there are many object groups (Object3Ds), and I have setup a system for clicking / hovering over them to do certain things. When it uses the raycaster to find which objects are under the mouse, it returns the individual object, not the group (which I need).

The code I used to get the objects under the cursor looks like so:

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);
}

In my scene, there are many object groups (Object3Ds), and I have setup a system for clicking / hovering over them to do certain things. When it uses the raycaster to find which objects are under the mouse, it returns the individual object, not the group (which I need).

The code I used to get the objects under the cursor looks like so:

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);
}
Share Improve this question asked Nov 15, 2015 at 20:42 MrGarrettoMrGarretto 2825 silver badges14 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

The Object3D class stores a reference to the parent-Object for you:

var objectGroup = intersects[0].parent;

for (j = 0; j < objectGroup.children.length; j++) {
    objectGroup.children[j].material.color.setHex(0x1A75FF);
}
发布评论

评论列表(0)

  1. 暂无评论