mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-05-14 14:29:52 -05:00
テスト追加
HasNormal が true にならない
This commit is contained in:
parent
7dce5db6d7
commit
d3243fcda7
|
|
@ -8,7 +8,7 @@ using UnityEngine.Rendering;
|
|||
|
||||
namespace UniGLTF
|
||||
{
|
||||
internal class MeshData : IDisposable
|
||||
public class MeshData : IDisposable
|
||||
{
|
||||
private NativeArray<MeshVertex> _vertices;
|
||||
public NativeArray<MeshVertex> Vertices => _vertices.GetSubArray(0, _currentVertexCount);
|
||||
|
|
@ -63,12 +63,13 @@ namespace UniGLTF
|
|||
/// バッファ共有方式(vrm-0.x)の判定。
|
||||
/// import の後方互換性のためで、vrm-1.0 export では使いません。
|
||||
///
|
||||
/// * バッファ共用方式は VertexBuffer が同じでSubMeshの index buffer がスライドしていく方式
|
||||
/// バッファ共用方式は連結済みの VertexBuffer を共有して、SubMeshの index buffer による参照がスライドしていく方式
|
||||
///
|
||||
/// * バッファがひとつのとき
|
||||
/// * すべての primitive の attribute が 同一の accessor を使用している時
|
||||
///
|
||||
/// </summary>
|
||||
private static bool HasSharedVertexBuffer(glTFMesh gltfMesh)
|
||||
public static bool HasSharedVertexBuffer(glTFMesh gltfMesh)
|
||||
{
|
||||
glTFAttributes lastAttributes = null;
|
||||
foreach (var prim in gltfMesh.primitives)
|
||||
|
|
@ -324,7 +325,7 @@ namespace UniGLTF
|
|||
var texCoords1 = primitives.GetTexCoords1(data, positions.Length);
|
||||
var colors = primitives.GetColors(data, positions.Length);
|
||||
var skinning = SkinningInfo.Create(data, gltfMesh, primitives);
|
||||
AssignBoneWeight = skinning.ShouldSetRendererNodeAsBone ;
|
||||
AssignBoneWeight = skinning.ShouldSetRendererNodeAsBone;
|
||||
|
||||
CheckAttributeUsages(primitives);
|
||||
|
||||
|
|
@ -456,7 +457,7 @@ namespace UniGLTF
|
|||
var texCoords1 = primitives.GetTexCoords1(data, positions.Length);
|
||||
var colors = primitives.GetColors(data, positions.Length);
|
||||
var skinning = SkinningInfo.Create(data, gltfMesh, primitives);
|
||||
AssignBoneWeight = skinning.ShouldSetRendererNodeAsBone ;
|
||||
AssignBoneWeight = skinning.ShouldSetRendererNodeAsBone;
|
||||
|
||||
CheckAttributeUsages(primitives);
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ namespace UniGLTF
|
|||
/// そのままGPUにアップロードされる
|
||||
/// </summary>
|
||||
[Serializable, StructLayout(LayoutKind.Sequential)]
|
||||
internal readonly struct MeshVertex
|
||||
public readonly struct MeshVertex
|
||||
{
|
||||
private readonly Vector3 _position;
|
||||
private readonly Vector3 _normal;
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ namespace UniGLTF
|
|||
/// そのままGPUにアップロードされる
|
||||
/// </summary>
|
||||
[Serializable, StructLayout(LayoutKind.Sequential)]
|
||||
internal readonly struct SkinnedMeshVertex
|
||||
public readonly struct SkinnedMeshVertex
|
||||
{
|
||||
private readonly float _boneWeight0;
|
||||
private readonly float _boneWeight1;
|
||||
|
|
|
|||
210
Assets/UniGLTF/Tests/UniGLTF/MeshDataTests.cs
Normal file
210
Assets/UniGLTF/Tests/UniGLTF/MeshDataTests.cs
Normal file
|
|
@ -0,0 +1,210 @@
|
|||
using System;
|
||||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UniGLTF
|
||||
{
|
||||
public class MeshDataTests
|
||||
{
|
||||
/// <summary>
|
||||
/// shared
|
||||
/// 3 2
|
||||
/// +-+
|
||||
/// |/|
|
||||
/// +-+
|
||||
/// 0 1
|
||||
///
|
||||
/// divided
|
||||
/// 2
|
||||
/// +
|
||||
/// /|
|
||||
/// +-+
|
||||
/// 0 1
|
||||
/// 4 3
|
||||
/// +-+
|
||||
/// |/
|
||||
/// +
|
||||
/// 5
|
||||
/// </summary>
|
||||
static byte[] CreateTestData(bool shared, bool hasNormal)
|
||||
{
|
||||
var data = new ExportingGltfData();
|
||||
data.Gltf.asset.version = "2.0";
|
||||
var mesh = new glTFMesh();
|
||||
data.Gltf.meshes.Add(mesh);
|
||||
|
||||
if (shared)
|
||||
{
|
||||
var positions = new Vector3[]
|
||||
{
|
||||
new Vector3(),
|
||||
new Vector3(),
|
||||
new Vector3(),
|
||||
new Vector3(),
|
||||
};
|
||||
var normals = new Vector3[]
|
||||
{
|
||||
new Vector3(),
|
||||
new Vector3(),
|
||||
new Vector3(),
|
||||
new Vector3(),
|
||||
};
|
||||
|
||||
var position = data.ExtendBufferAndGetAccessorIndex(positions);
|
||||
var normal = data.ExtendBufferAndGetAccessorIndex(normals);
|
||||
{
|
||||
var prim = new glTFPrimitives
|
||||
{
|
||||
attributes = new glTFAttributes
|
||||
{
|
||||
POSITION = position,
|
||||
},
|
||||
indices = data.ExtendBufferAndGetAccessorIndex(new uint[] { 0, 1, 2 }),
|
||||
};
|
||||
mesh.primitives.Add(prim);
|
||||
if (hasNormal)
|
||||
{
|
||||
prim.attributes.NORMAL = normal;
|
||||
}
|
||||
}
|
||||
{
|
||||
var prim = new glTFPrimitives
|
||||
{
|
||||
attributes = new glTFAttributes
|
||||
{
|
||||
POSITION = position,
|
||||
},
|
||||
indices = data.ExtendBufferAndGetAccessorIndex(new uint[] { 2, 3, 0 }),
|
||||
};
|
||||
mesh.primitives.Add(prim);
|
||||
if (hasNormal)
|
||||
{
|
||||
prim.attributes.NORMAL = normal;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
var positions = new Vector3[]
|
||||
{
|
||||
new Vector3(),
|
||||
new Vector3(),
|
||||
new Vector3(),
|
||||
};
|
||||
var position = data.ExtendBufferAndGetAccessorIndex(positions);
|
||||
var prim = new glTFPrimitives
|
||||
{
|
||||
attributes = new glTFAttributes
|
||||
{
|
||||
POSITION = position,
|
||||
},
|
||||
indices = data.ExtendBufferAndGetAccessorIndex(new uint[] { 0, 1, 2 }),
|
||||
};
|
||||
if (hasNormal)
|
||||
{
|
||||
var normals = new Vector3[]
|
||||
{
|
||||
new Vector3(),
|
||||
new Vector3(),
|
||||
new Vector3(),
|
||||
};
|
||||
var normal = data.ExtendBufferAndGetAccessorIndex(normals);
|
||||
prim.attributes.NORMAL = normal;
|
||||
}
|
||||
mesh.primitives.Add(prim);
|
||||
}
|
||||
{
|
||||
var positions = new Vector3[]
|
||||
{
|
||||
new Vector3(),
|
||||
new Vector3(),
|
||||
new Vector3(),
|
||||
};
|
||||
var position = data.ExtendBufferAndGetAccessorIndex(positions);
|
||||
var prim = new glTFPrimitives
|
||||
{
|
||||
attributes = new glTFAttributes
|
||||
{
|
||||
POSITION = position,
|
||||
},
|
||||
indices = data.ExtendBufferAndGetAccessorIndex(new uint[] { 0, 1, 2 }),
|
||||
};
|
||||
if (hasNormal)
|
||||
{
|
||||
var normals = new Vector3[]
|
||||
{
|
||||
new Vector3(),
|
||||
new Vector3(),
|
||||
new Vector3(),
|
||||
};
|
||||
var normal = data.ExtendBufferAndGetAccessorIndex(normals);
|
||||
prim.attributes.NORMAL = normal;
|
||||
}
|
||||
mesh.primitives.Add(prim);
|
||||
}
|
||||
}
|
||||
return data.ToGlbBytes();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SharedHasNormalTest()
|
||||
{
|
||||
var glb = CreateTestData(true, true);
|
||||
using (var parsed = new GlbBinaryParser(glb, "test").Parse())
|
||||
{
|
||||
Assert.True(MeshData.HasSharedVertexBuffer(parsed.GLTF.meshes[0]));
|
||||
using (var data = new MeshData(6, 6))
|
||||
{
|
||||
data.LoadFromGltf(parsed, 0, new ReverseZ());
|
||||
Assert.True(data.HasNormal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SharedNotHasNormalTest()
|
||||
{
|
||||
var glb = CreateTestData(true, false);
|
||||
using (var parsed = new GlbBinaryParser(glb, "test").Parse())
|
||||
{
|
||||
Assert.True(MeshData.HasSharedVertexBuffer(parsed.GLTF.meshes[0]));
|
||||
using (var data = new MeshData(6, 6))
|
||||
{
|
||||
data.LoadFromGltf(parsed, 0, new ReverseZ());
|
||||
Assert.False(data.HasNormal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DividedHasNormalTest()
|
||||
{
|
||||
var glb = CreateTestData(false, true);
|
||||
using (var parsed = new GlbBinaryParser(glb, "test").Parse())
|
||||
{
|
||||
Assert.False(MeshData.HasSharedVertexBuffer(parsed.GLTF.meshes[0]));
|
||||
using (var data = new MeshData(6, 6))
|
||||
{
|
||||
data.LoadFromGltf(parsed, 0, new ReverseZ());
|
||||
Assert.True(data.HasNormal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DividedNotHasNormalTest()
|
||||
{
|
||||
var glb = CreateTestData(false, false);
|
||||
using (var parsed = new GlbBinaryParser(glb, "test").Parse())
|
||||
{
|
||||
Assert.False(MeshData.HasSharedVertexBuffer(parsed.GLTF.meshes[0]));
|
||||
using (var data = new MeshData(6, 6))
|
||||
{
|
||||
data.LoadFromGltf(parsed, 0, new ReverseZ());
|
||||
Assert.False(data.HasNormal);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/UniGLTF/Tests/UniGLTF/MeshDataTests.cs.meta
Normal file
11
Assets/UniGLTF/Tests/UniGLTF/MeshDataTests.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e1e46a1dd2717854194c1b10ec096bef
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loading…
Reference in New Issue
Block a user