Skip to content

Conversation

bandinopla
Copy link

When working in blender you can make linked copies of objects, so they all share the same geometry. Then when exporting to GLB you can enable GPU Instancing which will allow the file to be lighter, sharing a single geometry across many instances. Then when loading into Three these will be seen as InstancedMesh. But if these instances share the same materials we can combine them into a BatchedMesh to optimize performance even more.

In this example an environment is loaded that has many InstancedMeshes but they all share the same material, so they are combined into a single BatchedMesh.

import * as THREE from 'three';
import Stats from 'three/addons/libs/stats.module.js';
import { RoomEnvironment } from 'three/addons/environments/RoomEnvironment.js';
import { GUI } from 'three/addons/libs/lil-gui.module.min.js';

Check notice

Code scanning / CodeQL

Unused variable, import, function or class Note

Unused import GUI.
@andredsm
Copy link
Contributor

andredsm commented Sep 25, 2025

Using the BatchedMesh for rendering several InstancedMeshes does not always result in the best performance due to its current implementation. For example, if you have two different geometries and a lot of instances of each one, the best approach is likely to keep them as two InstancedMesh.

I am also investigating related optimization regarding BatchedMesh and InstancedMesh because I am developing an application that has a lot of instanced geometries. In fact, if you have a lot of InstancedMesh, the performance rapidly degrades because it is 1 drawcall per InstancedMesh. Nonetheless, putting all instanced meshes into a BatchMesh can also not be a good option, because the current implementation does not use multidrawElementsInstanced for rendering instances; instead, it uses the multiDrawElements API and emulates instancing by repeating the mesh parameters in the function call, but this approach is slower. I commented more in #31935

@bandinopla
Copy link
Author

Replied to this in this post: #31935 (comment)

@bandinopla bandinopla changed the title Combine multiple InstancedMesh into a single BatchedMesh Examples: Combine multiple InstancedMesh into a single BatchedMesh Sep 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants