vpenades / SharpGLTF

glTF reader and writer for .NET Standard
MIT License
454 stars 72 forks source link

[BUG] Unable to retrieve vertices from morph target when using SceneBuilder #239

Closed BlueCyro closed 4 weeks ago

BlueCyro commented 1 month ago

Describe the bug Loading a model, creating a scene builder from that ModelRoot, and attempting to get a created morph target's vertices results in an exception:

Unhandled exception. System.InvalidCastException: Unable to cast object of type 'KeyCollection[SharpGLTF.Geometry.VertexTypes.VertexPositionNormal,System.Collections.Generic.List`1[System.ValueTuple`2[SharpGLTF.Geometry.PrimitiveBuilder`4[SharpGLTF.Materials.MaterialBuilder,SharpGLTF.Geometry.VertexTypes.VertexPositionNormal,SharpGLTF.Geometry.VertexTypes.VertexTexture1,SharpGLTF.Geometry.VertexTypes.VertexEmpty],System.Int32]]]' to type 'System.Collections.Generic.IReadOnlyList`1[SharpGLTF.Geometry.VertexTypes.IVertexGeometry]'.
   at SharpGLTF.Geometry.MorphTargetBuilder`4.SharpGLTF.Geometry.IMorphTargetBuilder.get_Vertices()
   at Program.<Main>$(String[] args) in C:\Users\Cyro\Documents\Coding Stuff\GLTF custom normal stuff\Program.cs:line 21

I'm currently attempting to load a model, add a blendshape, then save it. The context being that blender currently doesn't support custom normals per-blendshape, so I want to write a simple external program that will merge several deformed versions of the mesh into a single one with blendshapes that each have the proper custom normals instead of auto-calculated ones.

I've looked around and I can only really see examples where the mesh is being made from scratch - not loaded from an existing one as I'm intending, so if I'm doing something obviously wrong here please let me know.

To Reproduce

Load this provided project and observe as the exception occurs when "test normals 2.gltf" is loaded.

vpenades commented 1 month ago

Yes, it's seems there's a wrong cast bug there... I'll look into it...