Reputation: 43
what I'm trying to achieve: at first, you're only able to select objects within the group "interactable". when you click on an "interactable" object, you can now select any object within group "master". (you're picking up an interactable then selecting an object to place it on.)
"master" contains the group "interactable". right now I'm only able to switch from selecting within "interactable" to selecting within "master" without "interactable".
here's my code:
function render() {
raycaster.setFromCamera(mouse, camera);
if (obj_selected) {intersects = raycaster.intersectObjects(master.children)}
else {intersects = raycaster.intersectObjects(interactable.children)}
if (intersects.length > 0) {
if (INTERSECTED) INTERSECTED.material.emissive.setHex(INTERSECTED.currentHex);
INTERSECTED = intersects[0].object;
INTERSECTED.currentHex = INTERSECTED.material.emissive.getHex();
INTERSECTED.material.emissive.setHex( 0xf4425f );
} else {
if (INTERSECTED) INTERSECTED.material.emissive.setHex(INTERSECTED.currentHex);
INTERSECTED = null;
}
renderer.render(scene, camera);
}
I hope my explanation wasn't too confusing. thanks in advance.
Upvotes: 0
Views: 176
Reputation: 43
never mind, I figured it out!
so instead of putting things in groups, I added meshes to an array. I have three arrays: master, static, and interactable. if I get the intersections for master, then I can access all the objects in my scene without messing with groups.
conclusion: I don't think I should use groups when I'm simply categorizing things.
Upvotes: 1