ushort の index を uint に変換する

This commit is contained in:
ousttrue
2021-10-14 18:44:15 +09:00
parent 0a9b989d25
commit f52e6b481f

View File

@@ -76,7 +76,31 @@ namespace UniVRM10
// update Mesh
foreach (var (gltfMesh, mesh) in Enumerable.Zip(gltf.meshes, model.MeshGroups, (l, r) => (l, r.Meshes[0])))
{
var indices = mesh.IndexBuffer.GetSpan<uint>();
SpanLike<uint> indices;
switch (mesh.IndexBuffer.Stride)
{
case 2:
{
// ushort
var ushort_indices = mesh.IndexBuffer.GetSpan<ushort>();
indices = SpanLike.Create<uint>(ushort_indices.Length);
for (int i = 0; i < ushort_indices.Length; ++i)
{
indices[i] = ushort_indices[i];
}
break;
}
case 4:
{
// uint
indices = mesh.IndexBuffer.GetSpan<uint>();
break;
}
default:
throw new NotImplementedException();
}
var position = AddAccessor<Vector3>(mesh.VertexBuffer.Positions);
var normal = AddAccessor<Vector3>(mesh.VertexBuffer.Normals);
var uv = AddAccessor<Vector2>(mesh.VertexBuffer.TexCoords);