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

Rendering multiple instances of the same filamesh::MeshReader::Mesh? #2091

Closed
roxlu opened this issue Feb 1, 2020 · 3 comments
Closed

Rendering multiple instances of the same filamesh::MeshReader::Mesh? #2091

roxlu opened this issue Feb 1, 2020 · 3 comments

Comments

@roxlu
Copy link
Contributor

roxlu commented Feb 1, 2020

When I use the filamesh util to create a .filamesh file and the filamesh::MeshReader to load this mesh, it creates the vertex and index buffers together with a utils::Entity which represents a renderable:

struct Mesh {
    utils::Entity renderable;
    filament::VertexBuffer* vertexBuffer = nullptr;
    filament::IndexBuffer* indexBuffer = nullptr;
};

When I want to create multiple instances of this mesh (e.g. rendering many trees of the same mesh) what is the recommended approach? Do I load the mesh, keep it around and create new renderable entities for each instance I want to draw?

If this is the case you would need to copy the properties of the entity. Some can be retrieved via the getters in RenderableManager.h like getPrimitiveCount(), getMaterialIntanceAt().

But how would I get the values for the calls to setGeometryAt()? The utils::Entity aka renderable does not have getters that allow me to retrieve all the necessary information and the filamesh::MeshReader doesn't keep the necessary info either.

void setGeometryAt(Instance instance, size_t primitiveIndex,
        PrimitiveType type, VertexBuffer* vertices, IndexBuffer* indices,
        size_t offset, size_t count) noexcept;

This seems to be somewhat related to gltfio and this issue: #1513.

@romainguy
Copy link
Collaborator

This is just a simple helper API for samples or simple apps, it’s not meant to do more than it provides. You would indeed have to create multiple renderables. To do so you’d need to expose the information about each part. Note that the filamesh format is fully documented in the readme file of the filamesh tool if you want to create your own more advanced loader.

@prideout
Copy link
Contributor

prideout commented Feb 1, 2020

If you craft a glTF and create multiple node objects that reference the same mesh object, gltfio will do the right thing by sharing the same VertexBuffers and IndexBuffers amongst several renderables. That other issue you referenced is more about efficiently instancing the entire glTF asset.

@roxlu
Copy link
Contributor Author

roxlu commented Feb 1, 2020

OK thanks.

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

No branches or pull requests

3 participants