Skip to content

Instantly share code, notes, and snippets.

@lojjic
Last active September 14, 2021 16:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lojjic/9af97e97e5f091968876754fd470264b to your computer and use it in GitHub Desktop.
Save lojjic/9af97e97e5f091968876754fd470264b to your computer and use it in GitHub Desktop.
R3F instancing API - with mixed instancing types
// 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