Last active
September 14, 2021 16:25
-
-
Save lojjic/9af97e97e5f091968876754fd470264b to your computer and use it in GitHub Desktop.
R3F instancing API - with mixed instancing types
This file contains 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
// Each InstanceTemplate becomes an InstancedMesh behind the scenes. | |
// In this example we'll end up with 2 draw calls. | |
// This proposal uses a string `id` to refer to the templates, but it | |
// could also possibly be done by reference? | |
const Example = () => { | |
return <Instances> | |
<InstanceTemplate id="instancedBox"> | |
<boxGeometry /> | |
<meshStandardMaterial /> | |
</InstanceTemplate> | |
<InstanceTemplate id="instancedSphere"> | |
<sphereGeometry /> | |
<meshStandardMaterial /> | |
</InstanceTemplate> | |
{[0, 1, 2, 3, 4, 5].map(x => | |
<Thing position={[x, 0, 0]} boxColor={...} /> | |
)} | |
</Instances> | |
} | |
const Thing = (props) => { | |
return <group position={props.position}> | |
<Instance template="instancedBox" color={props.boxColor} ... /> | |
<Instance template="instancedSphere" ... /> | |
</group> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment