-
Hi there 👋 I am trying to display a curve with lines and points from a list of coordinates. For this, I use a // This works
const dataGeometry = useMemo(() => {
const geometry = new BufferGeometry()
geometry.setFromPoints(points)
return geometry
}, [points])
return (
<>
<points geometry={dataGeometry}>
<pointsMaterial attach="material" />
</points>
<line geometry={dataGeometry}>
<lineBasicMaterial attach="material" />
</line>
</>) I wanted then to move to something more declarative with useUpdate. I then used the following code const ref = useUpdate((geo) => geo.setFromPoints(points), [points])
return (
<>
<bufferGeometry ref={ref} />
<points geometry={ref.current}>
<pointsMaterial attach="material" />
</points>
<line geometry={ref.current}>
<lineBasicMaterial attach="material" />
</line>
</>
) However, netiher the line nor the points are displayed at first render ( I reproduced the issue in this CodeSandbox. Launching the app shows nothing but resizing the window makes the line and points appear. Am I doing something wrong here ? What would be the recommended way for sharing geometries declaratively ? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
useUpdate calls you back after the object has rendered. but it doesnt cause a render by itself. in other words, you render, both points and line receive "undefined" (ref.current), then you fill the buffergeometry. i would do it like in your first solution. |
Beta Was this translation helpful? Give feedback.
useUpdate calls you back after the object has rendered. but it doesnt cause a render by itself. in other words, you render, both points and line receive "undefined" (ref.current), then you fill the buffergeometry. i would do it like in your first solution.