我试图指向对象的某些部分,整个对象都被指向了

I’m trying to point to some part of the object, the whole object is pointed

我试图指向对象的某个部分,整个对象都被指向了,我不知道是什么问题,我尝试了很多选择,我决定寻求帮助

GIf

代码

    function hoverPieces() {
      // Material
      const material = new THREE.MeshBasicMaterial({ color: 0xffff00 });
      raycaster.setFromCamera(mouse, camera);
      const intersects = raycaster.intersectObjects(scene.children, true);

      if (intersects.length > 0) {
        if (INTERSECTED != intersects[0].object) {
          if (INTERSECTED)
            INTERSECTED.material.emissive.setHex(INTERSECTED.currentHex);
          INTERSECTED = intersects[0].object;
          INTERSECTED.currentHex = INTERSECTED.material.emissive.getHex();
          INTERSECTED.material.emissive.setHex(0xff0000);
        }
      } else {
        if (INTERSECTED)
          INTERSECTED.material.emissive.setHex(INTERSECTED.currentHex);
        INTERSECTED = null;
      }
    }

要点Link

https://gist.github.com/artur33s/b26e005283e1f605bab228483ee2e198

如果需要对象(.glb): https://wetransfer.com/downloads/54c0ef08f2fe2a4525388458ee175df220220223203644/3799a1

可以遍历,或者循环遍历gltf场景中的所有对象:

gltf.scene.traverse((object) => {
    if (object.material !== undefined) { //If there is no material on the object
        object.material = object.material.clone(); //clone the material
    }
});

就这些了!