2

I'm trying to get the updated position of a mesh after moving it with the Drei Pivot Controls, but digging into the object it says the position is [0,0,0]. How can I console.log the position after dragging a mesh?

  const meshRef = useRef();
  const handleDragEnd = () => {
    const model = meshRef.current
    debugger
  };
  
  return (
    <PivotControls anchor={[0, 0, 0]} onDragEnd ={handleDragEnd}>
        <primitive ref={meshRef} scale={scale} position={position} rotation={rotation} object={loadedModel.scene} />
    </PivotControls>
  )
Ashbury
  • 2,160
  • 3
  • 27
  • 52

1 Answers1

2

You have to grab it during the "onDrag" event and store it somewhere. I believe it's in global coordinates, so you might have to convert to local.

    onDrag={(l, dl, w, dw) => {
      // Extract the position and rotation
      const position = new THREE.Vector3()
      const rotation = new THREE.Quaternion()
      // I'm never sure whether to grab "l" or "w" here... sorry
      w.decompose(position, rotation, new Vector3())
      setPosition(position)
  }}
>