mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-05-20 17:57:57 -05:00
コンストラクターを上の方に
This commit is contained in:
parent
6905f85284
commit
b48c8707d8
|
|
@ -91,6 +91,63 @@ namespace VrmLib
|
|||
|
||||
public int ByteLength => Stride * Count;
|
||||
|
||||
public BufferAccessor(ArraySegment<byte> bytes, AccessorValueType componentType, AccessorVectorType accessorType, int count)
|
||||
{
|
||||
Bytes = bytes;
|
||||
ComponentType = componentType;
|
||||
AccessorType = accessorType;
|
||||
Count = count;
|
||||
}
|
||||
|
||||
public static BufferAccessor Create<T>(T[] list) where T : struct
|
||||
{
|
||||
var t = typeof(T);
|
||||
var bytes = new byte[list.Length * Marshal.SizeOf(t)];
|
||||
var span = SpanLike.Wrap<T>(new ArraySegment<byte>(bytes));
|
||||
for (int i = 0; i < list.Length; ++i)
|
||||
{
|
||||
span[i] = list[i];
|
||||
}
|
||||
AccessorValueType componentType = default(AccessorValueType);
|
||||
AccessorVectorType accessorType = default(AccessorVectorType);
|
||||
if (t == typeof(Vector2))
|
||||
{
|
||||
componentType = AccessorValueType.FLOAT;
|
||||
accessorType = AccessorVectorType.VEC2;
|
||||
}
|
||||
else if (t == typeof(Vector3))
|
||||
{
|
||||
componentType = AccessorValueType.FLOAT;
|
||||
accessorType = AccessorVectorType.VEC3;
|
||||
}
|
||||
else if (t == typeof(Vector4))
|
||||
{
|
||||
componentType = AccessorValueType.FLOAT;
|
||||
accessorType = AccessorVectorType.VEC4;
|
||||
}
|
||||
else if (t == typeof(Quaternion))
|
||||
{
|
||||
componentType = AccessorValueType.FLOAT;
|
||||
accessorType = AccessorVectorType.VEC4;
|
||||
}
|
||||
else if (t == typeof(SkinJoints))
|
||||
{
|
||||
componentType = AccessorValueType.UNSIGNED_SHORT;
|
||||
accessorType = AccessorVectorType.VEC4;
|
||||
}
|
||||
else if (t == typeof(int))
|
||||
{
|
||||
componentType = AccessorValueType.UNSIGNED_INT;
|
||||
accessorType = AccessorVectorType.SCALAR;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
return new BufferAccessor(
|
||||
new ArraySegment<byte>(bytes), componentType, accessorType, list.Length);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{Stride}stride x{Count}";
|
||||
|
|
@ -444,63 +501,6 @@ namespace VrmLib
|
|||
return new BufferAccessor(new ArraySegment<byte>(buffer), ComponentType, AccessorType, Count + offsetCount);
|
||||
}
|
||||
|
||||
public BufferAccessor(ArraySegment<byte> bytes, AccessorValueType componentType, AccessorVectorType accessorType, int count)
|
||||
{
|
||||
Bytes = bytes;
|
||||
ComponentType = componentType;
|
||||
AccessorType = accessorType;
|
||||
Count = count;
|
||||
}
|
||||
|
||||
public static BufferAccessor Create<T>(T[] list) where T : struct
|
||||
{
|
||||
var t = typeof(T);
|
||||
var bytes = new byte[list.Length * Marshal.SizeOf(t)];
|
||||
var span = SpanLike.Wrap<T>(new ArraySegment<byte>(bytes));
|
||||
for (int i = 0; i < list.Length; ++i)
|
||||
{
|
||||
span[i] = list[i];
|
||||
}
|
||||
AccessorValueType componentType = default(AccessorValueType);
|
||||
AccessorVectorType accessorType = default(AccessorVectorType);
|
||||
if (t == typeof(Vector2))
|
||||
{
|
||||
componentType = AccessorValueType.FLOAT;
|
||||
accessorType = AccessorVectorType.VEC2;
|
||||
}
|
||||
else if (t == typeof(Vector3))
|
||||
{
|
||||
componentType = AccessorValueType.FLOAT;
|
||||
accessorType = AccessorVectorType.VEC3;
|
||||
}
|
||||
else if (t == typeof(Vector4))
|
||||
{
|
||||
componentType = AccessorValueType.FLOAT;
|
||||
accessorType = AccessorVectorType.VEC4;
|
||||
}
|
||||
else if (t == typeof(Quaternion))
|
||||
{
|
||||
componentType = AccessorValueType.FLOAT;
|
||||
accessorType = AccessorVectorType.VEC4;
|
||||
}
|
||||
else if (t == typeof(SkinJoints))
|
||||
{
|
||||
componentType = AccessorValueType.UNSIGNED_SHORT;
|
||||
accessorType = AccessorVectorType.VEC4;
|
||||
}
|
||||
else if (t == typeof(int))
|
||||
{
|
||||
componentType = AccessorValueType.UNSIGNED_INT;
|
||||
accessorType = AccessorVectorType.SCALAR;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
return new BufferAccessor(
|
||||
new ArraySegment<byte>(bytes), componentType, accessorType, list.Length);
|
||||
}
|
||||
|
||||
public void AddTo(Dictionary<string, BufferAccessor> dict, string key)
|
||||
{
|
||||
dict.Add(key, this);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user