atteneder / glTFast

Efficient glTF 3D import / export package for Unity
Other
1.24k stars 251 forks source link

Exporting model with rig Animation Type not set to "None" and subsequently importing in editor or runtime results in NullReferenceException #556

Closed MorganMoon closed 1 year ago

MorganMoon commented 1 year ago

Describe the bug When exporting in the editor a specific model with a rig & animation as either glb or gltf, if it is imported at runtime or back into the editor, a NullReferenceException occurs, and the glb or gltf is invalid according to glTF-Validator. If I modify the import settings so the Rig -> Animation Type is set to "None" it then imports successfully, however without the wanted animation.

When exporting this using Blender into a .glb, and importing into unity using glTFast, it works as expected, so the issue seems to be with the glTFast exporter in the editor

The NullReferenceException is because ScheduleVertexJobs() is called on VertexBufferConfigBase in GltfImport.LoadAccessorData() and the "HasValue" property is false and "success" is false so "m_AccessorData" is never set and is then null in the foreach in GltfImport.Prepare()

NullReferenceException: Object reference not set to an instance of an object
GLTFast.GltfImport+<Prepare>d__111.MoveNext () (at Library/PackageCache/com.atteneder.gltfast@5.0.0/Runtime/Scripts/GltfImport.cs:1762)
--- End of stack trace from previous location where exception was thrown ---
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () (at <695d1cc93cca45069c528c15c9fdd749>:0)
GLTFast.GltfImport+<LoadFromUri>d__93.MoveNext () (at Library/PackageCache/com.atteneder.gltfast@5.0.0/Runtime/Scripts/GltfImport.cs:890)
--- End of stack trace from previous location where exception was thrown ---
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () (at <695d1cc93cca45069c528c15c9fdd749>:0)
GLTFast.GltfImport+<Load>d__53.MoveNext () (at Library/PackageCache/com.atteneder.gltfast@5.0.0/Runtime/Scripts/GltfImport.cs:348)
--- End of stack trace from previous location where exception was thrown ---
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () (at <695d1cc93cca45069c528c15c9fdd749>:0)
GLTFast.GltfImport+<Load>d__52.MoveNext () (at Library/PackageCache/com.atteneder.gltfast@5.0.0/Runtime/Scripts/GltfImport.cs:330)
--- End of stack trace from previous location where exception was thrown ---
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () (at <695d1cc93cca45069c528c15c9fdd749>:0)
GLTFast.Utils.AsyncHelpers+<>c__DisplayClass1_0`1+<<RunSync>b__0>d[T].MoveNext () (at Library/PackageCache/com.atteneder.gltfast@5.0.0/Editor/Scripts/AsyncHelpers.cs:66)
Rethrow as AggregateException: AsyncHelpers.Run method threw an exception.
GLTFast.Utils.AsyncHelpers+ExclusiveSynchronizationContext.BeginMessageLoop () (at Library/PackageCache/com.atteneder.gltfast@5.0.0/Editor/Scripts/AsyncHelpers.cs:122)
GLTFast.Utils.AsyncHelpers.RunSync[T] (System.Func`1[TResult] task) (at Library/PackageCache/com.atteneder.gltfast@5.0.0/Editor/Scripts/AsyncHelpers.cs:73)
GLTFast.Editor.GltfImporter.OnImportAsset (UnityEditor.AssetImporters.AssetImportContext ctx) (at Library/PackageCache/com.atteneder.gltfast@5.0.0/Editor/Scripts/GltfImporter.cs:131)
UnityEditor.AssetImporters.ScriptedImporter.GenerateAssetData (UnityEditor.AssetImporters.AssetImportContext ctx) (at <786b546700bc48b68852821de5e46ca9>:0)

Files

Attached here is a .zip which contains a .gltf and .glb with the issue as well as the original .fbx EmpiresDragonGltfIssue.zip

When ran through the validator, there are 7 errors:

            {
                "code": "MESH_PRIMITIVE_ATTRIBUTES_ACCESSOR_INVALID_FORMAT",
                "message": "Invalid accessor format '{VEC4, UNSIGNED_INT}' for this attribute semantic. Must be one of ('{VEC4, UNSIGNED_BYTE}', '{VEC4, UNSIGNED_SHORT}').",
                "severity": 0,
                "pointer": "/meshes/0/primitives/0/attributes/JOINTS_0"
            },
            {
                "code": "ACCESSOR_MIN_MISMATCH",
                "message": "Declared minimum value for this component (-2.9125702381134033) does not match actual minimum (-2.9060423374176025).",
                "severity": 0,
                "pointer": "/accessors/0/min/0"
            },
            {
                "code": "ACCESSOR_MIN_MISMATCH",
                "message": "Declared minimum value for this component (-1.6278042793273926) does not match actual minimum (-1.621886968612671).",
                "severity": 0,
                "pointer": "/accessors/0/min/1"
            },
            {
                "code": "ACCESSOR_MIN_MISMATCH",
                "message": "Declared minimum value for this component (-2.968715190887451) does not match actual minimum (-2.962307929992676).",
                "severity": 0,
                "pointer": "/accessors/0/min/2"
            },
            {
                "code": "ACCESSOR_MAX_MISMATCH",
                "message": "Declared maximum value for this component (2.9125702381134033) does not match actual maximum (2.9045865535736084).",
                "severity": 0,
                "pointer": "/accessors/0/max/0"
            },
            {
                "code": "ACCESSOR_MAX_MISMATCH",
                "message": "Declared maximum value for this component (3.605107307434082) does not match actual maximum (3.5987000465393066).",
                "severity": 0,
                "pointer": "/accessors/0/max/1"
            },
            {
                "code": "ACCESSOR_MAX_MISMATCH",
                "message": "Declared maximum value for this component (2.6229052543640137) does not match actual maximum (2.6174349784851074).",
                "severity": 0,
                "pointer": "/accessors/0/max/2"
            }

To Reproduce Steps to reproduce the behavior:

  1. Import the provided .fbx into Unity
  2. Export as .gltf or .glb using glTFast library
  3. Import .glb or .gltf back into the editor or import at runtime

Expected behavior A working export able to be re-imported without validation errors

Desktop (please complete the following information):

atteneder commented 1 year ago

Hi @MorganMoon ,

Thanks for reporting. Skinned meshes are not supported yet. I merged a fix that does not try to export blend weights/indices, so the result can be re-imported (though without skinning or naimation).

hth