glTFast icon indicating copy to clipboard operation
glTFast copied to clipboard

Unable to import a mesh generated inside Unity after it has been exported

Open GDCim opened this issue 3 years ago • 1 comments

My project workflow goes like this : a user can cut parts of a mesh, generating a new mesh in the process. For memory management reasons, I need to export some versions of a mesh and keep a path reference to it so the user can undo their changes by re-importing said meshes.

Describe the bug My problem is this : I cannot import a mesh that has been modified by my cutting algorithm and exported by this library. The weird thing is, I can open the mesh just fine in blender, but it simply will not work with on unity. When I try import to import a mesh, whether in the editor or during runtime, I error messages like these :

GLTFast.GltfImport.GetIndicesJob (GLTFast.Schema.Root gltf, System.Int32 accessorIndex, System.Int32[]& indices, System.Nullable`1[Unity.Jobs.JobHandle]& jobHandle, System.Runtime.InteropServices.GCHandle& resultHandle, System.Boolean flip) (at Library/PackageCache/com.atteneder.gltfast@8e0ed8eed4/Runtime/Scripts/GltfImport.cs:2887)
GLTFast.GltfImport+<LoadAccessorData>d__119.MoveNext () (at Library/PackageCache/com.atteneder.gltfast@8e0ed8eed4/Runtime/Scripts/GltfImport.cs:2527)
--- 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+<Prepare>d__105.MoveNext () (at Library/PackageCache/com.atteneder.gltfast@8e0ed8eed4/Runtime/Scripts/GltfImport.cs:1472)
--- 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__87.MoveNext () (at Library/PackageCache/com.atteneder.gltfast@8e0ed8eed4/Runtime/Scripts/GltfImport.cs:752)
--- 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__51.MoveNext () (at Library/PackageCache/com.atteneder.gltfast@8e0ed8eed4/Runtime/Scripts/GltfImport.cs:331)
--- 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__50.MoveNext () (at Library/PackageCache/com.atteneder.gltfast@8e0ed8eed4/Runtime/Scripts/GltfImport.cs:319)
--- 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@8e0ed8eed4/Editor/Scripts/AsyncHelpers.cs:63)
Rethrow as AggregateException: AsyncHelpers.Run method threw an exception.
GLTFast.Utils.AsyncHelpers+ExclusiveSynchronizationContext.BeginMessageLoop () (at Library/PackageCache/com.atteneder.gltfast@8e0ed8eed4/Editor/Scripts/AsyncHelpers.cs:119)
GLTFast.Utils.AsyncHelpers.RunSync[T] (System.Func`1[TResult] task) (at Library/PackageCache/com.atteneder.gltfast@8e0ed8eed4/Editor/Scripts/AsyncHelpers.cs:70)
GLTFast.Editor.GltfImporter.OnImportAsset (UnityEditor.AssetImporters.AssetImportContext ctx) (at Library/PackageCache/com.atteneder.gltfast@8e0ed8eed4/Editor/Scripts/GltfImporter.cs:115)
UnityEditor.AssetImporters.ScriptedImporter.GenerateAssetData (UnityEditor.AssetImporters.AssetImportContext ctx) (at <68089899e4c84456bfc1de3436accf4a>:0)
UnityEditor.PopupCallbackInfo:SetEnumValueDelegate(Object, String[], Int32)

I also get memory leak error messages :

A Native Collection has not been disposed, resulting in a memory leak. Allocated from:
Unity.Collections.NativeArray`1:.ctor(Int32, Allocator, NativeArrayOptions)
GLTFast.VertexBufferConfig`1:ScheduleVertexJobs(IGltfBuffers, Int32, Int32, Int32, Int32[], Int32, Int32, Int32) (at Library\PackageCache\com.atteneder.gltfast@8e0ed8eed4\Runtime\Scripts\VertexBufferConfig.cs:77)
GLTFast.<LoadAccessorData>d__119:MoveNext() (at Library\PackageCache\com.atteneder.gltfast@8e0ed8eed4\Runtime\Scripts\GltfImport.cs:2447)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1:Start(<LoadAccessorData>d__119&)
GLTFast.GltfImport:LoadAccessorData(Root)
GLTFast.<Prepare>d__105:MoveNext() (at Library\PackageCache\com.atteneder.gltfast@8e0ed8eed4\Runtime\Scripts\GltfImport.cs:1472)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1:Start(<Prepare>d__105&)
GLTFast.GltfImport:Prepare()
GLTFast.<LoadFromUri>d__87:MoveNext() (at Library\PackageCache\com.atteneder.gltfast@8e0ed8eed4\Runtime\Scripts\GltfImport.cs:752)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1:Start(<LoadFromUri>d__87&)
GLTFast.GltfImport:LoadFromUri(Uri)
GLTFast.<Load>d__51:MoveNext() (at Library\PackageCache\com.atteneder.gltfast@8e0ed8eed4\Runtime\Scripts\GltfImport.cs:331)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1:Start(<Load>d__51&)
GLTFast.GltfImport:Load(Uri, ImportSettings)
GLTFast.<Load>d__50:MoveNext() (at Library\PackageCache\com.atteneder.gltfast@8e0ed8eed4\Runtime\Scripts\GltfImport.cs:319)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1:Start(<Load>d__50&)
GLTFast.GltfImport:Load(String, ImportSettings)
GLTFast.Editor.<>c__DisplayClass8_0:<OnImportAsset>b__0() (at Library\PackageCache\com.atteneder.gltfast@8e0ed8eed4\Editor\Scripts\GltfImporter.cs:115)
GLTFast.Utils.<<RunSync>b__0>d:MoveNext() (at Library\PackageCache\com.atteneder.gltfast@8e0ed8eed4\Editor\Scripts\AsyncHelpers.cs:58)
System.Runtime.CompilerServices.AsyncVoidMethodBuilder:Start(<<RunSync>b__0>d&)
GLTFast.Utils.<>c__DisplayClass1_0`1:<RunSync>b__0(Object)
GLTFast.Utils.ExclusiveSynchronizationContext:BeginMessageLoop() (at Library\PackageCache\com.atteneder.gltfast@8e0ed8eed4\Editor\Scripts\AsyncHelpers.cs:116)
GLTFast.Utils.AsyncHelpers:RunSync(Func`1) (at Library\PackageCache\com.atteneder.gltfast@8e0ed8eed4\Editor\Scripts\AsyncHelpers.cs:70)
GLTFast.Editor.GltfImporter:OnImportAsset(AssetImportContext) (at Library\PackageCache\com.atteneder.gltfast@8e0ed8eed4\Editor\Scripts\GltfImporter.cs:115)
UnityEditor.AssetImporters.ScriptedImporter:GenerateAssetData(AssetImportContext)
UnityEditor.AssetDatabase:StopAssetEditing()
UnityEditor.AssetImporters.AssetImporterEditor:DrawImporterSelectionPopup()
UnityEditor.AssetImporters.AssetImporterEditor:OnHeaderControlsGUI()
UnityEditor.Editor:DrawHeaderGUI(Editor, String, Single)
UnityEditor.Editor:DrawHeaderGUI(Editor, String)
UnityEditor.Editor:OnHeaderGUI()
UnityEditor.Editor:DrawHeader()
UnityEditor.UIElements.EditorElement:DrawEditorLargeHeader(Editor[], Boolean&)
UnityEditor.UIElements.EditorElement:DrawEditorHeader(Editor[], Object, Boolean&)
UnityEditor.UIElements.EditorElement:HeaderOnGUI()
UnityEngine.UIElements.IMGUIContainer:DoOnGUI(Event, Matrix4x4, Rect, Boolean, Rect, Action, Boolean)
UnityEngine.UIElements.IMGUIContainer:HandleIMGUIEvent(Event, Matrix4x4, Rect, Action, Boolean)
UnityEngine.UIElements.IMGUIContainer:HandleIMGUIEvent(Event, Action, Boolean)
UnityEngine.UIElements.IMGUIContainer:HandleIMGUIEvent(Event, Boolean)
UnityEngine.UIElements.IMGUIContainer:SendEventToIMGUIRaw(EventBase, Boolean, Boolean)
UnityEngine.UIElements.IMGUIContainer:SendEventToIMGUI(EventBase, Boolean, Boolean)
UnityEngine.UIElements.CommandEventDispatchingStrategy:DispatchEvent(EventBase, IPanel)
UnityEngine.UIElements.EventDispatcher:ApplyDispatchingStrategies(EventBase, IPanel, Boolean)
UnityEngine.UIElements.EventDispatcher:ProcessEvent(EventBase, IPanel)
UnityEngine.UIElements.EventDispatcher:Dispatch(EventBase, IPanel, DispatchMode)
UnityEngine.UIElements.BaseVisualElementPanel:SendEvent(EventBase, DispatchMode)
UnityEngine.UIElements.UIElementsUtility:DoDispatch(BaseVisualElementPanel)
UnityEngine.UIElements.UIElementsUtility:UnityEngine.UIElements.IUIElementsUtility.ProcessEvent(Int32, IntPtr, Boolean&)
UnityEngine.UIElements.UIEventRegistration:ProcessEvent(Int32, IntPtr)
UnityEngine.UIElements.<>c:<.cctor>b__1_2(Int32, IntPtr)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)
UnityEditor.GUIView:Internal_SendEvent(Event)
UnityEditor.GUIView:SendEvent(Event)
UnityEditor.PopupCallbackInfo:SetEnumValueDelegate(Object, String[], Int32)

Files Here is an original .glb file and a separate .glb file generated after the cut. ExportedMeshes.zip I understand the the second .glb file fails the glTF Validator , which is either because of the exporting process or the cutting process, but I find it weird since Blender is still able to import the file despite the errors.

Software versions

  • glTFast version : 4.8.3
  • Unity Editor version : 2020.3.30f1
  • Render Pipeline and version : Universal Render Pipeline 10.8.1
  • Platform: Windows and Android

GDCim avatar Nov 05 '22 16:11 GDCim

Thanks for the report.

Seems like one of the meshes has an index buffer of length zero and thus no triangles at all. I'll look into making glTFast more robust towards non-sensical data like this, but I suggest you fix your split operation to filter out empty meshes as well.

atteneder avatar Nov 06 '22 11:11 atteneder

Note: In the upcoming release 6.10.0 this test asset works, because it creates one mesh with two submeshes where only the second submesh has zero triangles (instead of two meshes, one of them being empty).

atteneder avatar Dec 12 '24 15:12 atteneder