Replies: 1 comment 5 replies
-
I'm not sure about your last question, but you could add a non-null assertion if TS is seeing incorrect undefined behavior -- e.g. requiring you to null-check in effects. const mesh = React.useRef<THREE.Mesh>(null!) // non-null assertion so we don't null-check in later effects
useHitTest((hitMatrix: THREE.Matrix4, hit: XRHitTestResult) => {
hitMatrix.decompose(mesh.current.position, mesh.current.quaternion, mesh.current.scale)
})
return (
<mesh ref={mesh}>
<boxGeometry />
<meshBasicMaterial color="blue" />
</mesh>
) |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I've seen a few examples of using
useHitTest
with versions of @react-three/xr lower than v5, but I'm not quite sure how to convert the syntax using the newer versions.. (and using useRef with Typescript, which might be a separate issue).Here is an example of the older syntax:
plane detection with react-three/xr
and
https://codesandbox.io/s/react-xr-usehittest-demo-5iff9?file=/src/App.tsx
But I'm not sure (based on this react-three/xr documentation):
a. How to add
sessionInit={{ requiredFeatures: ['hit-test'] }}
toCanvas
orXR
tags, post deprecation ofARCanvas
.b. Whether
hit.decompose
is still needed.c. Whether
mesh.applyMatrix4(hitMatrix)
is needed, or whether something likeref={hitPoint}
is still neededd. If using
ref
with Typescript, how to solve theType
'MutableRefObject<undefined>' is not assignable
error when adding to a mesh. As per this answer, maybe I need to force mount the component or something..Any help or examples appreciated. Thanks
Beta Was this translation helpful? Give feedback.
All reactions