Created
July 8, 2021 13:36
-
-
Save rabelais88/d2626499b9a17a900b41de7b564ac29b to your computer and use it in GitHub Desktop.
declarative vertices in React-three-fiber
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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