Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

From InstancedMesh to more generic Instances #25078

Open
takahirox opened this issue Dec 4, 2022 · 2 comments
Open

From InstancedMesh to more generic Instances #25078

takahirox opened this issue Dec 4, 2022 · 2 comments

Comments

@takahirox
Copy link
Collaborator

takahirox commented Dec 4, 2022

Is your feature request related to a problem? Please describe.

Three.js has InstancedMesh API to allow easy GPU instancing handling.

It extends Mesh and the constructor takes geometry, material, and count.

Because of this design, it has limiation. It is hard to make the use of GPU instancing with non-regular Mesh, eg. SkinnedMesh, Line, or Points.

Describe the solution you'd like

We support more generic GPU instancing API.

Perhaps Instances( Mesh|SkinnedMesh|Line|Points (or whatever), count ).

It would be more flexible.

Describe alternatives you've considered

  1. Make Instanced API for each object type. eg. InstancedSkinnedMesh, InstancedLine, InstancedPoints. But I don't think it's a good idea because of complexity.
  2. Three.js already has InstancedBufferGeometry/Attribute and they can be used for non-regular Meshes (?). But it may be harder to use for generic users.

Additional context

The idea is from

@Fyrestar
Copy link

Fyrestar commented Dec 5, 2022

I would generally love an API design that gives more control of the rendering/culling process by putting the implementations for gathering the render lists and making draw calls into methods of the specific classes, so the component can decide how to handle it, if static or dynamic.

I made a class for instanced skinnning with individual animation states (also with geometry LOD, culling and automatic bone reduction/skin-remapping LOD)
https://discourse.threejs.org/t/animated-instanced-skinned-meshes-gltf/41958/7
image
(It's basically done i just still don't have a good open test asset that fully utilizes it for a good demo with multiple geometry LODs, would like to make a meta-human detail kind of demo afap)

Other than InstancedMesh regular SkinnedMesh instances are linked to this component and the SkinnedMesh is not removed from the scene hierarchy and can be nested anywhere. This way the component handles the batching witch culling and LOD automatically, while instancing for the meshes can be turned on/off seamlessly. The most expensive part for SkinnedMesh is the animation and matrices computations which, without a LOD system, makes instancing not really a benefit as performance likely suffers earlier from that than draw calls.

There often is a need that you need to render a instance individually again, like highlighting in a emissive color without making that an additional attribute. So a flexible variant to switch between makes it much more intuitive.

Make Instanced API for each object type. eg. InstancedSkinnedMesh, InstancedLine, InstancedPoints. But I don't think it's a good idea because of complexity.

I think separating between "Instanced" and "SkinnedInstanced" would be enough, the only complexity difference is there i suppose.

@looeee
Copy link
Collaborator

looeee commented Dec 7, 2022

There often is a need that you need to render a instance individually again, like highlighting in a emissive color without making that an additional attribute.

Anything that makes this use case more streamlined has my vote.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants