vpenades / SharpGLTF

glTF reader and writer for .NET Standard
MIT License
482 stars 77 forks source link

[QUESTION] Any reason morph targets count is sometimes 0 on a mesh? #208

Open Smartkin opened 11 months ago

Smartkin commented 11 months ago

Currently using the library to export meshes with morph targets and I gotta say I love the library and the API for being so intuitive to use. However, one current problem I have is when loading the scene back to import back into my own format the amount of morph targets on a random mesh can be 0. What could be the reason for this? image

vpenades commented 11 months ago

I'ts hard to tell without knowing more about what you're doing.

could you provide a reproducible example?

Smartkin commented 11 months ago

I'ts hard to tell without knowing more about what you're doing.

could you provide a reproducible example?

Looking at the raw model file it seems like at some meshes the delta on all vertexes is 0. I assume then the library just clears the morph targets list if none of them change anything in the mesh?

vpenades commented 11 months ago

I assume then the library just clears the morph targets list if none of them change anything in the mesh?

Yes, that is the case, see https://github.com/vpenades/SharpGLTF/blob/681b03b863000800e71e4976735a5da95e6c71f0/src/SharpGLTF.Toolkit/Geometry/Packed/_PrimitiveHelpers.cs#L48-L49

Now, I am wondering whether this is right or not. From the data perspective, it's a waste of resources to add an effect-less morph target, but not adding it changes the morph targets sequence indexing so it can result in incorrect morph target assignment and animation...

But it also depends on how are you using this...

Smartkin commented 11 months ago

I assume then the library just clears the morph targets list if none of them change anything in the mesh?

Yes, that is the case, see

https://github.com/vpenades/SharpGLTF/blob/681b03b863000800e71e4976735a5da95e6c71f0/src/SharpGLTF.Toolkit/Geometry/Packed/_PrimitiveHelpers.cs#L48-L49

Now, I am wondering whether this is right or not. From the data perspective, it's a waste of resources to add an effect-less morph target, but not adding it changes the morph targets sequence indexing so it can result in incorrect morph target assignment and animation...

But it also depends on how are you using this...

The model format of the game requires that all meshes have the same amount of morph targets. It's not too hard to work around it by just adding zeroed out morphs though

Smartkin commented 11 months ago

I assume then the library just clears the morph targets list if none of them change anything in the mesh?

Yes, that is the case, see

https://github.com/vpenades/SharpGLTF/blob/681b03b863000800e71e4976735a5da95e6c71f0/src/SharpGLTF.Toolkit/Geometry/Packed/_PrimitiveHelpers.cs#L48-L49

Now, I am wondering whether this is right or not. From the data perspective, it's a waste of resources to add an effect-less morph target, but not adding it changes the morph targets sequence indexing so it can result in incorrect morph target assignment and animation...

But it also depends on how are you using this...

Maybe it could potentially be an optional flag? As I said it's not too hard to work around if such behavior is expected but it's also not really mentioned anywhere that this would happen. Don't know how GLTF standard dictates this though

vpenades commented 10 months ago

Don't know how GLTF standard dictates this though

Well, generally speaking, glTF specification does not like adding stuff that has "no effect" into the rendering... in fact, the gltf validator issues warnings if you do stuff like adding a mesh that is never used in the scene and so on