Hello, I know there’s quite a few questions on this forum on performance, but I tried to follow most guidelines and I want to know if I am doing anything wrong in particular with how I am using react-three-fiber. I also don’t really know what to make of my performance stats:
I read that three.js should be able to handle 400 geometries just fine, but I get very low fps. Also I have no idea what to make of the other numbers, is 808 calls bad?
I read this page which has a lot of helpful tips. And one of them is to avoid disposing of geometries, as opposed to making them invisible. As well as avoiding recreating geometries and vectors and instead use the same ones that were already created. I tried to do these things, but I get confused how they can be implemented with r3f. For example, I have an array in zustand that I am using to render my geometries, it gets updated from time to time, so I am using react’s framework to my advantage and update the scene as the array changes like this:
const Boxes = (props) => {
const shapes = useShapes(state => state.shapes) // my zustand store, which is just an array of points
const onClickHandler = (i) => {//.... on click handler changes for each mesh
return (
<>
{shapes.map( (shape, i) => (
<mesh onClick={() => onClickHandler(i)}>
<extrudeGeometry args={[new THREE.Shape(shape), {depth: 1}]}
<meshStandardMaterial/>
<Outlines .../>
<Edges .../> // Drei outline and edges
</mesh>
))}
</>
)
}
In my mind this seems to be the most intuitive way of using r3f for an array of geometries, but maybe that would dispose of these geometries when the array changes, would it? In addition, regarding is this part:
new THREE.Shape(shape)
Is this something I’d want to avoid? As I am creating new shape objects each time it runs?
I also thought of using instanced meshes but each of my meshes have different click handlers
Do you identify anything that seems indicative of problems in my current use of three.js? Or am I probably looking at the wrong place entirely? I am not entirely sure where the issue could be, if it is in my use of three.js, in my use of r3f, or somewhere else!
Thank you!!