mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-08-23 19:15:07 -05:00
Merge pull request #1308 from ousttrue/fix/ushort_indices
[1.0] ushort, byte 型の indices を持つモデルのマイグレーション
This commit is contained in:
@@ -72,6 +72,18 @@ namespace UniGLTF
|
||||
{
|
||||
return cv.ComponentType;
|
||||
}
|
||||
else if (typeof(T) == typeof(sbyte))
|
||||
{
|
||||
return glComponentType.BYTE;
|
||||
}
|
||||
else if (typeof(T) == typeof(byte))
|
||||
{
|
||||
return glComponentType.UNSIGNED_BYTE;
|
||||
}
|
||||
else if (typeof(T) == typeof(ushort))
|
||||
{
|
||||
return glComponentType.UNSIGNED_SHORT;
|
||||
}
|
||||
else if (typeof(T) == typeof(uint))
|
||||
{
|
||||
return glComponentType.UNSIGNED_INT;
|
||||
|
||||
@@ -475,10 +475,10 @@ namespace UniGLTF
|
||||
return new SpanLike<T>(bytes, Marshal.SizeOf<T>(), getset.Getter, getset.Setter);
|
||||
}
|
||||
|
||||
public static SpanLike<T> Create<T>(int count) where T : struct
|
||||
public static SpanLike<T> Create<T>(int itemCount) where T : struct
|
||||
{
|
||||
var itemSize = Marshal.SizeOf<T>();
|
||||
var array = new byte[count / itemSize];
|
||||
var array = new byte[itemCount * itemSize];
|
||||
return Wrap<T>(new ArraySegment<byte>(array));
|
||||
}
|
||||
|
||||
|
||||
@@ -76,7 +76,43 @@ 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 1:
|
||||
{
|
||||
// byte
|
||||
var byte_indices = mesh.IndexBuffer.GetSpan<byte>();
|
||||
indices = SpanLike.Create<uint>(byte_indices.Length);
|
||||
for (int i = 0; i < byte_indices.Length; ++i)
|
||||
{
|
||||
indices[i] = byte_indices[i];
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user