From 0da88134cffe0681bbf2a5a501e282d4edc9b153 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Thu, 14 Jul 2022 15:37:47 +0900 Subject: [PATCH] =?UTF-8?q?HasNormal=E3=80=80=E3=81=AE=E4=BD=BF=E3=81=84?= =?UTF-8?q?=E6=96=B9=E3=82=92=E9=80=86=E3=81=AB=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * default = false * if exists => true --- .../Runtime/UniGLTF/IO/MeshIO/MeshData.cs | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) 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]);