Are geometries and meshes being recreated every time? #1526
-
Hi! I'm currently experimenting with this amazing library, but I have some doubts regard creation of meshes. If I'm running a code like this: function Picture(props) {
return (
<mesh position={props.position} >
<planeBufferGeometry args={[4.5, 4.5]} />
<meshBasicMaterial wireframe />
</mesh>
)
}
const arr = [];
for (let i = 0; i < 50; i++) {
arr.push(<Picture position={[x, y, z ]} />)
} The geometry and material are being recreated 50 times? Because I would like to have same geometry and material for every Mesh. Thanks in advance. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
they are. and that will quickly become a problem. if you want to share geometries and materials you can put them in global space, or into a state manager. for instance: https://codesandbox.io/s/zxpv7?file=/src/App.js everything you load via useloader is cached and can be re-used without problem. you can also use use-asset directly (a caching library) in order to cache and re-use resources. another thing that will become important is instancing. each mesh, even if you re-use geometries and materials means a draw call. you can have maybe a 100 of those if they're reasonably complex. if you can't instance look into this: https://twitter.com/0xca0a/status/1413600110177574915 |
Beta Was this translation helpful? Give feedback.
they are. and that will quickly become a problem. if you want to share geometries and materials you can put them in global space, or into a state manager. for instance: https://codesandbox.io/s/zxpv7?file=/src/App.js
everything you load via useloader is cached and can be re-used without problem. you can also use use-asset directly (a caching library) in order to cache and re-use resources.
another thing that will become important is instancing. each mesh, even if you re-use geometries and materials means a draw call. you can have maybe a 100 of those if they're reasonably complex. if you can't instance look into this: https://twitter.com/0xca0a/status/1413600110177574915