Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rabelais88/d2626499b9a17a900b41de7b564ac29b to your computer and use it in GitHub Desktop.
Save rabelais88/d2626499b9a17a900b41de7b564ac29b to your computer and use it in GitHub Desktop.
declarative vertices in React-three-fiber
const Line = () => {
const vertices = useMemo(() => {
let p = [
[0, 0, 0],
[0, 1, 1],
[0, 1, -1]
];
const flatArr = p.reduce((ac, cv) => [...cv, ...ac], []);
return new Float32Array(flatArr);
}, []);
return (
<line>
<bufferGeometry attach="geometry">
<bufferAttribute
attachObject={["attributes", "position"]}
array={vertices}
itemSize={3}
count={vertices.length / 3}
/>
</bufferGeometry>
<lineBasicMaterial color="red" />
</line>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment