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

Add additional names to GLTF entities for easier querying #13473

Open
MatrixDev opened this issue May 22, 2024 · 1 comment · May be fixed by #13912
Open

Add additional names to GLTF entities for easier querying #13473

MatrixDev opened this issue May 22, 2024 · 1 comment · May be fixed by #13912
Labels
A-Assets Load files from disk to use for things like images, models, and sounds C-Usability A simple quality-of-life change that makes Bevy easier to use

Comments

@MatrixDev
Copy link

MatrixDev commented May 22, 2024

What problem does this solve or what need does it fill?

I have a very simple blender file with a single mesh and multiple materials:
image

When exporting to GLTF it creates a mesh with multiple primitives:
image

Bevy creates an entity for the node object and separate entity per each primitive of the mesh (no mesh-specific entity):
image

There are few problems:

  1. there is no mesh entity at all when multiple primitives are available (there is nothing with 'PlaneMesh' name)
  2. I don't know which primitive contains which material. In case I want to motify some named material, I have to play with scene directly, used entities mapping, it's a boilerplate mess and not ECS friendly.
  3. I can't just query for primitives because their names are generated with indexes.

What solution would you like?

I'd like to add more Name-like components to make querying much easier:

// added to all Gltf node entities
#[derive(Component)]
struct GltfNodeName(Arc<str>);

// added to all Gltf mesh entities (or each primitive when mesh is split into multiple entities)
#[derive(Component)]
struct GltfMeshName(Arc<str>);

// added to all entities that contain Gltf materials
#[derive(Component)]
struct GltfMaterialName(Arc<str>);

// added to all entities associated to a Gltf scene
#[derive(Component)]
struct SceneInstanceNode(InstanceId);

Names are not enough in this case because:

  1. some nodes might have mulitple names (Mesh+Material for example)
  2. name doesn't specify which type of entity we're actually talking about

In such case it will be trivial to find/replace components for any Gltf scene.

What alternative(s) have you considered?

I don't see currently any ECS friendly alternative.

We could also have GltfInstance component attached to the root node that will map entities by type/name but IMHO it is not really ECS way of doing things:

#[derive(Component)]
struct GltfInstance {
    nodes: HashMap<String, Entity>,
    meshes: HashMap<String, Vec<Entity>>,
    materials: HashMap<String, Vec<Entity>>,
}

Additional context

This is just a suggestion.

There are 100% better ways to solve this problem but we should improve Gltf usability for sure. Currently it just way to cumbersome and requires huge amount of boilerplate code.

@MatrixDev MatrixDev added C-Enhancement A new feature S-Needs-Triage This issue needs to be labelled labels May 22, 2024
@alice-i-cecile alice-i-cecile added A-Assets Load files from disk to use for things like images, models, and sounds C-Usability A simple quality-of-life change that makes Bevy easier to use and removed C-Enhancement A new feature S-Needs-Triage This issue needs to be labelled labels May 22, 2024
@janhohenheim
Copy link
Member

@kaosat-dev you might have expert opinions on this :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Assets Load files from disk to use for things like images, models, and sounds C-Usability A simple quality-of-life change that makes Bevy easier to use
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants