diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/MeshIO/MeshData.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/MeshIO/MeshData.cs index cb54df9ca..aaefc0aae 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/MeshIO/MeshData.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/MeshIO/MeshData.cs @@ -13,6 +13,7 @@ namespace UniGLTF private NativeArray _vertices; public NativeArray Vertices => _vertices.GetSubArray(0, _currentVertexCount); int _currentVertexCount = 0; + private NativeArray _skinnedMeshVertices; public NativeArray SkinnedMeshVertices => _skinnedMeshVertices.GetSubArray(0, _currentSkinCount); int _currentSkinCount = 0; @@ -23,12 +24,14 @@ namespace UniGLTF private readonly List _subMeshes = new List(); public IReadOnlyList SubMeshes => _subMeshes; + private readonly List _materialIndices = new List(); public IReadOnlyList MaterialIndices => _materialIndices; + private readonly List _blendShapes = new List(); public IReadOnlyList BlendShapes => _blendShapes; - public bool HasNormal { get; private set; } = true; + public bool HasNormal { get; private set; } public string Name { get; private set; } public bool AssignBoneWeight { get; private set; } @@ -197,15 +200,6 @@ namespace UniGLTF return (vertexCount, indexCount); } - /// - /// 各種頂点属性が使われているかどうかをチェックし、使われていなかったらフラグを切る - /// MEMO: O(1)で検知する手段がありそう - /// - private void CheckAttributeUsages(glTFPrimitives primitives) - { - if (!primitives.HasNormal()) HasNormal = false; - } - private BlendShape GetOrCreateBlendShape(int i) { if (i < _blendShapes.Count && _blendShapes[i] != null) @@ -318,17 +312,19 @@ namespace UniGLTF var vertexOffset = _currentVertexCount; var indexBufferCount = primitives.indices; - // position は必ずある + // position は必ず存在する。normal, texCoords, colors, skinning は無いかもしれない var positions = primitives.GetPositions(data); var normals = primitives.GetNormals(data, positions.Length); + if (normals.HasValue) + { + HasNormal = true; + } var texCoords0 = primitives.GetTexCoords0(data, positions.Length); var texCoords1 = primitives.GetTexCoords1(data, positions.Length); var colors = primitives.GetColors(data, positions.Length); var skinning = SkinningInfo.Create(data, gltfMesh, primitives); AssignBoneWeight = skinning.ShouldSetRendererNodeAsBone; - CheckAttributeUsages(primitives); - for (var i = 0; i < positions.Length; ++i) { var position = inverter.InvertVector3(positions[i]); @@ -448,19 +444,21 @@ namespace UniGLTF var isOldVersion = data.GLTF.IsGeneratedUniGLTFAndOlder(1, 16); { - // 同じVertexBufferを共有しているので先頭のモノを使う + // すべての primitives で連結済みの VertexBuffer を共有している。代表して先頭を使う var primitives = gltfMesh.primitives.First(); var positions = primitives.GetPositions(data); var normals = primitives.GetNormals(data, positions.Length); + if (normals.HasValue) + { + HasNormal = true; + } var texCoords0 = primitives.GetTexCoords0(data, positions.Length); var texCoords1 = primitives.GetTexCoords1(data, positions.Length); var colors = primitives.GetColors(data, positions.Length); var skinning = SkinningInfo.Create(data, gltfMesh, primitives); AssignBoneWeight = skinning.ShouldSetRendererNodeAsBone; - CheckAttributeUsages(primitives); - for (var i = 0; i < positions.Length; ++i) { var position = inverter.InvertVector3(positions[i]);