How to use method on geometry? #516
SarahVanDenBerghe
started this conversation in
General
Replies: 1 comment 2 replies
-
either you create it const geo = useMemo(() => new THREE.BufferGeometry().setFromPoints(points), [points])
return <mesh geometry={geo} ... /> or you feed it as a side-effect (useLayoutEffect is called next "frame", but before the threejs renders it) const ref = useRef()
useLayoutEffect(() => void ref.current.setFromPoints(points), [points])
return (
<mesh>
<bufferGeometry attach="geometry" ref={ref} /> there's also a convenience hook, it is practically the same but shorter const ref = useUpdate(geo => geo.setFromPoints(points), [points])
return (
<mesh>
<bufferGeometry attach="geometry" ref={ref} /> it's imo best packed away as a re-usable component, see: https://github.com/react-spring/react-three-fiber/blob/master/recipes.md#managing-imperative-code |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hey, sorry just another little question! I'm trying to understand how to use a method on a geometry within this library. For example, the Spline Curve, on the
BufferGeometry
, there's a methodsetFromPoints()
, but I don't really know how to properly translate this to be usable within this library.On the website of Three JS they show a simple example, I think I got the most part right within r3f, just the
setFromPoint()
I'm having issues with.I've tried it on Code Sandbox, can anyone point out what I'm doing wrong precisely? I've tried working with
useRef()
, the shortcut from the API,args
, but none seem to work.Thank you!! 😊
Beta Was this translation helpful? Give feedback.
All reactions