diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/BufferAccessor.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/BufferAccessor.cs index 43e4a6273..6ead44a56 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/BufferAccessor.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/BufferAccessor.cs @@ -157,6 +157,9 @@ namespace UniGLTF } switch (ComponentType) { + case AccessorValueType.UNSIGNED_BYTE: + return ArrayManager.Convert(Bytes, (byte x) => (int)x); + case AccessorValueType.UNSIGNED_SHORT: return ArrayManager.Convert(Bytes.Reinterpret(1), (ushort x) => (int)x); diff --git a/Assets/VRM10/Runtime/IO/Model/MeshImporter.cs b/Assets/VRM10/Runtime/IO/Model/MeshImporter.cs index d27a78e76..035fdd7df 100644 --- a/Assets/VRM10/Runtime/IO/Model/MeshImporter.cs +++ b/Assets/VRM10/Runtime/IO/Model/MeshImporter.cs @@ -65,16 +65,27 @@ namespace UniVRM10 // Indexを更新 switch (src.IndexBuffer.ComponentType) { + case AccessorValueType.UNSIGNED_BYTE: + { + var intIndices = src.IndexBuffer.GetAsIntArray(); + mesh.SetIndexBufferParams(intIndices.Length, IndexFormat.UInt32); + mesh.SetIndexBufferData(intIndices, 0, 0, intIndices.Length); + break; + } case AccessorValueType.UNSIGNED_SHORT: - var shortIndices = src.IndexBuffer.Bytes.Reinterpret(1); - mesh.SetIndexBufferParams(shortIndices.Length, IndexFormat.UInt16); - mesh.SetIndexBufferData(shortIndices, 0, 0, shortIndices.Length); - break; + { + var shortIndices = src.IndexBuffer.Bytes.Reinterpret(1); + mesh.SetIndexBufferParams(shortIndices.Length, IndexFormat.UInt16); + mesh.SetIndexBufferData(shortIndices, 0, 0, shortIndices.Length); + break; + } case AccessorValueType.UNSIGNED_INT: - var intIndices = src.IndexBuffer.Bytes.Reinterpret(1); - mesh.SetIndexBufferParams(intIndices.Length, IndexFormat.UInt32); - mesh.SetIndexBufferData(intIndices, 0, 0, intIndices.Length); - break; + { + var intIndices = src.IndexBuffer.Bytes.Reinterpret(1); + mesh.SetIndexBufferParams(intIndices.Length, IndexFormat.UInt32); + mesh.SetIndexBufferData(intIndices, 0, 0, intIndices.Length); + break; + } default: throw new NotImplementedException(); } @@ -101,6 +112,10 @@ namespace UniVRM10 // 各種パラメーターを再計算 mesh.RecalculateBounds(); mesh.RecalculateTangents(); + if (src.VertexBuffer.Normals == null) + { + mesh.RecalculateNormals(); + } Profiler.EndSample(); diff --git a/Assets/VRM10/Runtime/IO/Model/MeshImporterDivided.cs b/Assets/VRM10/Runtime/IO/Model/MeshImporterDivided.cs index 91d71c6e9..49de5fc71 100644 --- a/Assets/VRM10/Runtime/IO/Model/MeshImporterDivided.cs +++ b/Assets/VRM10/Runtime/IO/Model/MeshImporterDivided.cs @@ -42,6 +42,10 @@ namespace UniVRM10 // 各種データを再構築 resultMesh.RecalculateBounds(); resultMesh.RecalculateTangents(); + if (meshGroup.Meshes.Any(mesh => mesh.VertexBuffer.Normals == null)) + { + resultMesh.RecalculateNormals(); + } // BlendShapeを更新 var blendShapeCount = meshGroup.Meshes[0].MorphTargets.Count; diff --git a/Assets/VRM10/Runtime/IO/Model/MeshReader.cs b/Assets/VRM10/Runtime/IO/Model/MeshReader.cs index 9a5383ec1..cd99b6896 100644 --- a/Assets/VRM10/Runtime/IO/Model/MeshReader.cs +++ b/Assets/VRM10/Runtime/IO/Model/MeshReader.cs @@ -67,6 +67,13 @@ namespace UniVRM10 mesh.IndexBuffer = storage.CreateAccessor(primitive.indices); } + if (mesh.IndexBuffer == null) + { + var indices = Enumerable.Range(0, mesh.VertexBuffer.Count).ToArray(); + var na = storage.Data.NativeArrayManager.CreateNativeArray(indices); + mesh.IndexBuffer = new BufferAccessor(storage.Data.NativeArrayManager, na.Reinterpret(4), AccessorValueType.UNSIGNED_INT, AccessorVectorType.SCALAR, na.Length); + } + { gltf_mesh_extras_targetNames.TryGet(x, out List targetNames); diff --git a/Assets/VRM10/Runtime/IO/Vrm10ImportData.cs b/Assets/VRM10/Runtime/IO/Vrm10ImportData.cs index c174a3d62..ada4c16f8 100644 --- a/Assets/VRM10/Runtime/IO/Vrm10ImportData.cs +++ b/Assets/VRM10/Runtime/IO/Vrm10ImportData.cs @@ -12,6 +12,7 @@ namespace UniVRM10 public class Vrm10ImportData { UniGLTF.GltfData m_data; + public UniGLTF.GltfData Data => m_data; public UniGLTF.glTF Gltf => m_data.GLTF; public string AssetVersion => Gltf.asset.version; @@ -363,12 +364,7 @@ namespace UniVRM10 if (x.translation != null && x.translation.Length > 0) throw new Exception("matrix with translation"); if (x.rotation != null && x.rotation.Length > 0) throw new Exception("matrix with rotation"); if (x.scale != null && x.scale.Length > 0) throw new Exception("matrix with scale"); - var m = new Matrix4x4( - new Vector4(x.matrix[0], x.matrix[4], x.matrix[8], x.matrix[12]), - new Vector4(x.matrix[1], x.matrix[5], x.matrix[9], x.matrix[13]), - new Vector4(x.matrix[2], x.matrix[6], x.matrix[10], x.matrix[14]), - new Vector4(x.matrix[3], x.matrix[7], x.matrix[11], x.matrix[15]) - ); + var m = UnityExtensions.MatrixFromArray(x.matrix); node.SetLocalMatrix(m, true); }