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

gltfio: Add support for "software instancing". #2607

Merged
merged 4 commits into from
May 29, 2020
Merged

Conversation

prideout
Copy link
Contributor

This adds createInstancedAsset() to AssetLoader, which creates a master asset and a set of slave instances. Vertex buffers, index buffers, textures, and material instances are shared. Entities and components are duplicated.

Instances have their own API object that exposes a subset of the master asset's entity hierarchy and an optional Animator object.

This also adds a new sample app called gltf_instances. It is similar to gltf_viewer but with no GUI. It has additional command line arguments for a number of instances and animation.

Java and JavaScript bindings will be added in a subsequent PR.

Fixes #1513

curl 10 41 40 AM

prideout added 3 commits May 28, 2020 13:47
This adds createInstancedAsset() to AssetLoader, which creates a master
asset and a set of slave instances. Vertex buffers, index buffers,
textures, and material instances are shared. Entities and components are
duplicated.

Instances have their own API object that is very simple. Light sources
and material instances are not instanced, so are not accessible through
the instance API object.

The master-slave ownership model lets us avoid complex shared ownership
semantics. The existing cache structures in AssetLoader allow the
implementation of this feature to be fairly simple.

The master asset exposes the union of all entities and allows clients to
modify all instances en masse if they wish. This design also works
naturally with ResourceLoader, which does not need to know about
instancing. For example, asynchronous loading is completely unchanged;
the dependency graph simply contains the union of entities across all
instances.

Support for animation is added in a subsequent commit.

Fixes #1513.
When animation is applied to the master asset, all instances are
animated.

Instances can also be individually animated via the Animator in
FilamentInstance.

Fixes #1513.
@prideout prideout requested a review from pixelflinger May 28, 2020 20:47
@prideout prideout requested review from romainguy and bejado May 28, 2020 20:47

namespace gltfio {

namespace details { struct FFilamentAsset; }
namespace details {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in another PR, maybe we should get rid of details:: in gltfio too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I would definitely like to do that.

@prideout prideout merged commit 6870d36 into master May 29, 2020
@prideout prideout deleted the pr/instancing3 branch May 29, 2020 14:44
@davidwarford
Copy link

davidwarford commented Nov 9, 2020

@prideout Hay just a question about this part of the API. this seems to require you know how many instances you are going to need upfront. What is the intended method to add new instances at run time? I don't want to keep loading the asset every time I need to draw a new copy of my model.

@prideout
Copy link
Contributor Author

prideout commented Nov 9, 2020

You can use the new AssetLoader::createInstance() method to dynamically add instances, but it has a few limitations. Firstly, you still need to load the asset using createInstancedAsset (you can set numInstances to 1). Secondly, the newly added instances do not support animation yet -- that's TBD.

@davidwarford
Copy link

This is not exposed in the web api yet, any idea on when it could be?

@prideout
Copy link
Contributor Author

prideout commented Nov 9, 2020

@davidwarford
Copy link

oh, I'm sorry must have been added after I pulled or something, will have to pull again. Thank you!

@davidwarford
Copy link

@prideout after pulling and some confusion, I noticed that yes the function is in the definition file and in the jsbindings file it does not exist in the filament.js file. Should this be elevated to an issue?

@prideout
Copy link
Contributor Author

prideout commented Nov 9, 2020

filament.js is the glue layer between filament.wasm and the client application, it does not contain entry points unless they require specialized glue code (e.g. Scene's addEntity method isn't in there either).

However I can easily believe that there is an issue with the web bindings for this entry point since I have not yet tested. Feel free to file an issue if you see an error message in Chrome's developer console when calling this method.

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

Successfully merging this pull request may close these issues.

How to render a renderable in different positions of one scene at a time
4 participants