Clientx and window.innerWidth Question:

@J450NP13 you can do this:

const mouse = new THREE.Vector2();
function onMouseMove(event) {
  let canvasBounds = renderer.getContext().canvas.getBoundingClientRect();

  mouse.x = ( ( event.clientX - canvasBounds.left ) / ( canvasBounds.right - canvasBounds.left ) ) * 2 - 1;
  mouse.y = - ( ( event.clientY - canvasBounds.top ) / ( canvasBounds.bottom - canvasBounds.top) ) * 2 + 1;
  
  rc.setFromCamera(mouse, camera);
  intscs = rc.intersectObjects(objs, false);
  if (intscs.length > 0) {
    let o = intscs[0];
    poi.copy(o.point);
    o.object.worldToLocal(poi);
    setPos(o.faceIndex);
    o.object.localToWorld(pos);
    marker.position.copy(pos);
  }
}

BTW this question has been answered many times on the forum already, for example:

1 Like