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

In my scene, there are many object groups (Object3Ds), and I have setup a system for clickinghoverin

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745373817a4624912.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信