react-three-arjs icon indicating copy to clipboard operation
react-three-arjs copied to clipboard

How to get the position of the Markers?

Open Zaniyar opened this issue 1 year ago • 2 comments


	const markerRef= useRef<THREE.Group>(null);
	const modelRef= useRef<THREE.Group>(null);                   
             <ARMarker
		  ref={markerRef}
		  params={{ smooth: true }}
		  type={"pattern"}
		  patternUrl={"data/patt.kanji"}
		  onMarkerFound={(x) => {
			console.log(x); // undefined
		  }}
	      >
		  <Model
			  ref={modelRef}
			  scale={[1, 1, 1]}
			  url="/model.glb"
		  />
	  </ARMarker>

later I try to get the position like this:

   modelRef.current.getWorldPosition(new THREE.Vector3()),

it is always 0

Vector3 {x: 0, y: 0, z: 0}
Vector3 {x: 0, y: 0, z: 0}

Zaniyar avatar Apr 06 '23 19:04 Zaniyar

If I'm not mistaken, the position of the marker is always the center of the world.

mwmwmw avatar Jul 19 '23 17:07 mwmwmw

Yes, the marker position root will be updated. So you need to get the position of the marker root (the parent of your Model)

console.log(modelRef.current.parent.getWorldPosition(new Vector3()))

j-era avatar Jul 24 '23 15:07 j-era