How to get a point coordinate on a SkinnedMaterial for the human demo of three.js?

StackOverflow https://stackoverflow.com/questions/23593833

  •  20-07-2023
  •  | 
  •  

Question

For the human demo http://threejs.org/examples/#webgl_morphtargets_human , I wonder how to get a point on the skin of the human. For example when I click some place on the human body, what's the coordinate of that place?

I tried using the raycaster to get that but in vain.The code is like this:

  var projector;
  init() {
    // Others
    // ...

    projector = new THREE.Projector();
    renderer.domElement.addEventListener('mouseup', onMouseUp, false);
  }

  function onMouseUp(e) {
    e.preventDefault();

    var vector = new THREE.Vector3(
                   ( event.clientX / window.innerWidth ) * 2 - 1,
                   - ( event.clientY / window.innerHeight ) * 2 + 1,
                   0.5
                 );
    projector.unprojectVector( vector, camera );

    var raycaster = new THREE.Raycaster( camera.position, vector.sub( camera.position ).normalize() );

    var intersections = raycaster.intersectObjects( character.root.children );

    if (intersections.length > 0) {
      debugger;
      // ...
    }

  }

But the intersections is always empty.

Three.js is r67

Thanks in advance.

Was it helpful?

Solution 2

Well, finally I find that it's just because the human animation. It works if I comment the animation out.

OTHER TIPS

I'm new to three.js, and i've also tried to draw plots on the human. I manage to do it, but it's not on the "visible" body. In fact, you should first use the intersect method with the recursive arg :

var intersections = raycaster.intersectObjects( scene.children, true );

Thus, you 'll be able to interact with the objects composing the body, but they are not positioned under the "skin". It seems to be that they have been "moved", because you can interact with them if you aim in front of the feet of the body. Unfortunately, I don't know for the moment why, and how to interact with their "visible representation".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top