From b48c8707d86ee578bc07414636c4968a95c0cc5b Mon Sep 17 00:00:00 2001 From: ousttrue Date: Fri, 4 Feb 2022 13:42:00 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=B3=E3=83=B3=E3=82=B9=E3=83=88=E3=83=A9?= =?UTF-8?q?=E3=82=AF=E3=82=BF=E3=83=BC=E3=82=92=E4=B8=8A=E3=81=AE=E6=96=B9?= =?UTF-8?q?=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/VRM10/vrmlib/Runtime/BufferAccessor.cs | 114 +++++++++--------- 1 file changed, 57 insertions(+), 57 deletions(-) diff --git a/Assets/VRM10/vrmlib/Runtime/BufferAccessor.cs b/Assets/VRM10/vrmlib/Runtime/BufferAccessor.cs index f85e8553d..4d8c81ef4 100644 --- a/Assets/VRM10/vrmlib/Runtime/BufferAccessor.cs +++ b/Assets/VRM10/vrmlib/Runtime/BufferAccessor.cs @@ -91,6 +91,63 @@ namespace VrmLib public int ByteLength => Stride * Count; + public BufferAccessor(ArraySegment bytes, AccessorValueType componentType, AccessorVectorType accessorType, int count) + { + Bytes = bytes; + ComponentType = componentType; + AccessorType = accessorType; + Count = count; + } + + public static BufferAccessor Create(T[] list) where T : struct + { + var t = typeof(T); + var bytes = new byte[list.Length * Marshal.SizeOf(t)]; + var span = SpanLike.Wrap(new ArraySegment(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(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(buffer), ComponentType, AccessorType, Count + offsetCount); } - public BufferAccessor(ArraySegment bytes, AccessorValueType componentType, AccessorVectorType accessorType, int count) - { - Bytes = bytes; - ComponentType = componentType; - AccessorType = accessorType; - Count = count; - } - - public static BufferAccessor Create(T[] list) where T : struct - { - var t = typeof(T); - var bytes = new byte[list.Length * Marshal.SizeOf(t)]; - var span = SpanLike.Wrap(new ArraySegment(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(bytes), componentType, accessorType, list.Length); - } - public void AddTo(Dictionary dict, string key) { dict.Add(key, this);