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

Allowing glTFs to be loaded that don't have uvs and normals #406

Merged
merged 4 commits into from
Sep 4, 2020

Conversation

julhe
Copy link
Contributor

@julhe julhe commented Aug 31, 2020

Issue

Bevy will panic when rendering a glTF mesh that doesn't have UVs and normals

Fix

UVs and normal attributes will now be filled up with zeros.

Generally I think it is a better approach to fill up missing attributes with zeros. That will make it easier to deal with different meshs from render side.

Risks

It is now mandatory for the mesh to contain a position attribute. I really can't think of a case were a mesh wouldn't contain that, but may someone else has. 🤔

@cart
Copy link
Member

cart commented Aug 31, 2020

This is a nice temporary fix, but I think I would actually prefer it if loaded GLTFs only contained the attributes that have been specified.

The Mesh type was designed to be flexible in terms of vertex buffer attributes. You can pass in a VertexBufferDescriptor and it will output a gpu buffer that matches the format. The missing piece is that currently it will only do that for attributes that are in the Mesh.

I think we should extend Mesh to (optionally) fill in missing attributes with zeros.

@cart
Copy link
Member

cart commented Aug 31, 2020

get_vertex_buffer_bytes is the method where this would happen.

@karroffel karroffel added A-Assets Load files from disk to use for things like images, models, and sounds C-Bug An unexpected or incorrect behavior A-Rendering Drawing game state to the screen labels Aug 31, 2020
…by filling missing attributes them with zeros"

This reverts commit e16ddb3.
@julhe
Copy link
Contributor Author

julhe commented Sep 1, 2020

Okay, so something like this:

pub enum MissingVertexAttributeBehaviour{
    /// Attribute doesn't need to contain meaningfull data. Example: VertexColor
    DefaultValue(VertexAttributeValues //TODO),
    /// Attribute is optional, but must contain meaningfull data. 
    /// Example: eg. SecondaryUV for lightmaps which can also be the PrimaryUV
    /// Cool Trick?: instead of cloning the fallback buffer, bind it to the same slot as the missing one
    FallbackAttribute(Cow<'static, str>),
    /// attribute is required. Example: VertexPosition
    Panic, 
}

Or do you think thats too verbose?

@cart
Copy link
Member

cart commented Sep 2, 2020

Hmm I think short term I'd prefer something simpler like this.

fn get_vertex_buffer_bytes(&self, vertex_buffer_descriptor: &VertexBufferDescriptor, fill_in_missing_attributes: bool) -> Result<Vec<u8>, MeshToVertexBufferError> {
  /* existing logic here, but fill in missing attributes with zeros */
}

If later consumers decide that its overly limiting, we can revisit it. But I'm guessing this will be "good enough".

@julhe
Copy link
Contributor Author

julhe commented Sep 2, 2020

okay, new commit online 🙂

@cart
Copy link
Member

cart commented Sep 4, 2020

haha i totally forgot we were already generating arrays filled with zeros 😄

@cart cart merged commit cc3e993 into bevyengine:master Sep 4, 2020
mrk-its pushed a commit to mrk-its/bevy that referenced this pull request Oct 6, 2020
…ne#406)

allowing gltfs to be loaded that don't have uvs and normals, by filling missing attributes them with zeros
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 A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants