0

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.

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.