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

UnityMeshData.MorphTargetNormals[i] may need to check null on Import #682

Closed
FujiSunflower opened this issue Feb 1, 2024 · 6 comments
Closed

Comments

@FujiSunflower
Copy link

Problem

UnityMeshData.MorphTargetNormals[i] may need to check null on import.

tarAttrNorm.AccessorContent.AsVec3s.ToUnityVector3Raw(unityData.MorphTargetNormals[i], (int)vertOffset);

References

It is because the array has null check on AddBlendShapesToMesh in ConstructUnityMesh.

private void AddBlendShapesToMesh(UnityMeshData unityMeshData, int meshIndex, Mesh mesh)

@pfcDorn
Copy link
Contributor

pfcDorn commented Feb 2, 2024

I don't think this is needed, because we already check if there is a attribute for the morphtargetnormals.
Or do you have a gltf file which cause an error there?

@FujiSunflower
Copy link
Author

Ah, I tried to import ".glb" file changed suffix from ".vrm". It happened this error.
Perhaps, VRM format has any wrong as glTF. VRM is the format based on glTF. So VRM has to change GLB.
GLB : Seed-san.zip

NullReferenceException: Object reference not set to an instance of an object
UnityGLTF.GLTFSceneImporter.ConvertAttributeAccessorsToUnityTypes (UnityGLTF.Cache.MeshCacheData+PrimitiveCacheData primData, UnityGLTF.UnityMeshData unityData, System.UInt32 vertOffset, System.Int32 indexOffset) (at Library/PackageCache/org.khronos.unitygltf@4ebe065f27/Runtime/Scripts/SceneImporter/ImporterMeshes.cs:908)
UnityGLTF.GLTFSceneImporter.ConstructMesh (GLTF.Schema.GLTFMesh mesh, System.Int32 meshIndex, System.Threading.CancellationToken cancellationToken) (at Library/PackageCache/org.khronos.unitygltf@4ebe065f27/Runtime/Scripts/SceneImporter/ImporterMeshes.cs:120)
UnityGLTF.GLTFSceneImporter.ConstructNode (GLTF.Schema.Node node, System.Int32 nodeIndex, System.Threading.CancellationToken cancellationToken) (at Library/PackageCache/org.khronos.unitygltf@4ebe065f27/Runtime/Scripts/GLTFSceneImporter.cs:809)
UnityGLTF.GLTFSceneImporter.GetNode (System.Int32 nodeId, System.Threading.CancellationToken cancellationToken) (at Library/PackageCache/org.khronos.unitygltf@4ebe065f27/Runtime/Scripts/GLTFSceneImporter.cs:771)
UnityGLTF.GLTFSceneImporter.ConstructScene (GLTF.Schema.GLTFScene scene, System.Boolean showSceneObj, System.Threading.CancellationToken cancellationToken) (at Library/PackageCache/org.khronos.unitygltf@4ebe065f27/Runtime/Scripts/GLTFSceneImporter.cs:1087)
UnityGLTF.GLTFSceneImporter._LoadScene (System.Int32 sceneIndex, System.Boolean showSceneObj, System.Threading.CancellationToken cancellationToken) (at Library/PackageCache/org.khronos.unitygltf@4ebe065f27/Runtime/Scripts/GLTFSceneImporter.cs:623)
UnityGLTF.GLTFSceneImporter.LoadSceneAsync (System.Int32 sceneIndex, System.Boolean showSceneObj, System.Action`2[T1,T2] onLoadComplete, System.Threading.CancellationToken cancellationToken, System.IProgress`1[T] progress) (at Library/PackageCache/org.khronos.unitygltf@4ebe065f27/Runtime/Scripts/GLTFSceneImporter.cs:425)
UnityGLTF.AsyncHelpers+<>c__DisplayClass0_0.<RunSync>b__0 (System.Object _) (at Library/PackageCache/org.khronos.unitygltf@4ebe065f27/Editor/Scripts/Internal/AsyncHelpers.cs:30)
Rethrow as AggregateException: AsyncHelpers.Run method threw an exception. (Object reference not set to an instance of an object)
UnityGLTF.AsyncHelpers+ExclusiveSynchronizationContext.BeginMessageLoop () (at Library/PackageCache/org.khronos.unitygltf@4ebe065f27/Editor/Scripts/Internal/AsyncHelpers.cs:130)
UnityGLTF.AsyncHelpers.RunSync (System.Func`1[TResult] task) (at Library/PackageCache/org.khronos.unitygltf@4ebe065f27/Editor/Scripts/Internal/AsyncHelpers.cs:37)
UnityGLTF.GLTFImporter.CreateGLTFScene (UnityGLTF.Plugins.GLTFImportContext context, UnityEngine.GameObject& scene, UnityEngine.AnimationClip[]& animationClips, UnityGLTF.GLTFSceneImporter& importer) (at Library/PackageCache/org.khronos.unitygltf@4ebe065f27/Editor/Scripts/GLTFImporter.cs:867)
UnityGLTF.GLTFImporter.OnImportAsset (UnityEditor.AssetImporters.AssetImportContext ctx) (at Library/PackageCache/org.khronos.unitygltf@4ebe065f27/Editor/Scripts/GLTFImporter.cs:296)
UnityEngine.Debug:LogException(Exception)
UnityGLTF.GLTFImporter:OnImportAsset(AssetImportContext) (at Library/PackageCache/org.khronos.unitygltf@4ebe065f27/Editor/Scripts/GLTFImporter.cs:741)
UnityEditor.AssetImporters.ScriptedImporter:GenerateAssetData(AssetImportContext)
UnityEditorInternal.InternalEditorUtility:ProjectWindowDrag(HierarchyProperty, Boolean)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)

Refererence

https://github.com/vrm-c/vrm-specification/blob/master/samples/Seed-san/vrm/Seed-san.vrm

@pfcDorn
Copy link
Contributor

pfcDorn commented Feb 2, 2024

Ah...i see....not all Targets have a normal blendshape. We currently check only for the first one. Need some more changes i guess. I will take an eye of it next week !

image

@hybridherbst
Copy link
Collaborator

@FujiSunflower out of curiosity, where was that file created / what software was it created with?

@FujiSunflower
Copy link
Author

FujiSunflower commented Feb 2, 2024

Maybe it was made by UniVRM as Refererence's url. I re-tested by UniVRM. I found the file uses Sparse Accessor.
If UniVRM use no Sparse Accessor, the file is success.
If UniVRM use Sparse Accessor, the file is failure.
And the file can import by glTFast.
Perhaps UniVRM has any problem in Sparse Accessor. But I don't know the detail.
UniVRM : https://github.com/vrm-c/UniVRM

@hybridherbst
Copy link
Collaborator

Thank you! I believe the file is perfectly valid, it's just unusual that some blend shapes include normals and others not, so was curious where it comes from / what the reasoning is.

pfcDorn pushed a commit to prefrontalcortex/UnityGLTF that referenced this issue Feb 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants