mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-04-14 00:58:46 -05:00
Merge pull request #1279 from ousttrue/fix10/mv_spanlike
[Maintenance] mv VrmLib.SpanLike to UniGLTF.SpanLike
This commit is contained in:
commit
5f1499862d
|
|
@ -134,7 +134,7 @@ namespace UniGLTF
|
|||
}
|
||||
|
||||
public static class ArraySegmentExtensions
|
||||
{
|
||||
{
|
||||
public static ArraySegment<T> Slice<T>(this ArraySegment<T> self, int start, int length)
|
||||
{
|
||||
if (start + length > self.Count)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
using System;
|
||||
using System.Numerics;
|
||||
|
||||
namespace VrmLib
|
||||
namespace UniGLTF
|
||||
{
|
||||
public static class NumericsExtensions
|
||||
{
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 482b4ffcefb6ff04d90272038c48b27f
|
||||
guid: d4a7532836c4d1d4d965dc867e51cbd7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
|
|
@ -9,7 +9,7 @@ using UniJSON;
|
|||
namespace UniGLTF
|
||||
{
|
||||
[Serializable, StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
struct Byte4
|
||||
public struct Byte4
|
||||
{
|
||||
public readonly byte x;
|
||||
public readonly byte y;
|
||||
|
|
@ -25,7 +25,7 @@ namespace UniGLTF
|
|||
}
|
||||
|
||||
[Serializable, StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
struct UShort4
|
||||
public struct UShort4
|
||||
{
|
||||
public readonly ushort x;
|
||||
public readonly ushort y;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace VrmLib
|
||||
namespace UniGLTF
|
||||
{
|
||||
public static class ArrayPin
|
||||
{
|
||||
|
|
@ -85,7 +85,7 @@ namespace VrmLib
|
|||
#endregion
|
||||
}
|
||||
|
||||
public static class ArrayExtensions
|
||||
public static class ArrayPinExtensions
|
||||
{
|
||||
public static int FromBytes<T>(this ArraySegment<byte> src, T[] dst) where T : struct
|
||||
{
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c431387eb7732aa4fb43d54385c8e0dc
|
||||
guid: 451e525839f17f84e8092265effaddcb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
using System;
|
||||
|
||||
namespace VrmLib
|
||||
namespace UniGLTF
|
||||
{
|
||||
public struct SkinJoints : IEquatable<SkinJoints>
|
||||
{
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 51bc7ca26fb1f094588cd8c181d48c89
|
||||
guid: 1881e2dc50569df478f166eb4d6ca8f1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
|
|
@ -3,24 +3,8 @@ using System.Collections;
|
|||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace VrmLib
|
||||
namespace UniGLTF
|
||||
{
|
||||
public struct Byte4
|
||||
{
|
||||
public byte X;
|
||||
public byte Y;
|
||||
public byte Z;
|
||||
public byte W;
|
||||
}
|
||||
|
||||
public struct UShort4
|
||||
{
|
||||
public ushort X;
|
||||
public ushort Y;
|
||||
public ushort Z;
|
||||
public ushort W;
|
||||
}
|
||||
|
||||
static class BitWriter
|
||||
{
|
||||
public static void Write(byte[] bytes, int i, Int32 value)
|
||||
|
|
@ -115,10 +99,10 @@ namespace VrmLib
|
|||
|
||||
public static void Write(byte[] bytes, int i, UShort4 value)
|
||||
{
|
||||
Write(bytes, i, value.X);
|
||||
Write(bytes, i + 2, value.Y);
|
||||
Write(bytes, i + 4, value.Z);
|
||||
Write(bytes, i + 6, value.W);
|
||||
Write(bytes, i, value.x);
|
||||
Write(bytes, i + 2, value.y);
|
||||
Write(bytes, i + 4, value.z);
|
||||
Write(bytes, i + 6, value.w);
|
||||
}
|
||||
|
||||
public static void Write(byte[] bytes, int i, SkinJoints value)
|
||||
|
|
@ -131,10 +115,10 @@ namespace VrmLib
|
|||
|
||||
public static void Write(byte[] bytes, int i, Byte4 value)
|
||||
{
|
||||
bytes[i++] = value.X;
|
||||
bytes[i++] = value.Y;
|
||||
bytes[i++] = value.Z;
|
||||
bytes[i++] = value.W;
|
||||
bytes[i++] = value.x;
|
||||
bytes[i++] = value.y;
|
||||
bytes[i++] = value.z;
|
||||
bytes[i++] = value.w;
|
||||
}
|
||||
|
||||
public static void Write(byte[] bytes, int i, UnityEngine.Vector2 value)
|
||||
|
|
@ -387,24 +371,22 @@ namespace VrmLib
|
|||
}},
|
||||
{typeof(Byte4), new GetSet<Byte4>{
|
||||
Getter = (array, start) =>
|
||||
new Byte4
|
||||
{
|
||||
X = array[start],
|
||||
Y = array[start + 1],
|
||||
Z = array[start + 2],
|
||||
W = array[start + 3],
|
||||
},
|
||||
new Byte4(
|
||||
array[start],
|
||||
array[start + 1],
|
||||
array[start + 2],
|
||||
array[start + 3]
|
||||
),
|
||||
Setter = BitWriter.Write
|
||||
}},
|
||||
{typeof(UShort4), new GetSet<UShort4>{
|
||||
Getter = (array, start) =>
|
||||
new UShort4
|
||||
{
|
||||
X = BitConverter.ToUInt16(array, start),
|
||||
Y = BitConverter.ToUInt16(array, start + 2),
|
||||
Z = BitConverter.ToUInt16(array, start + 4),
|
||||
W = BitConverter.ToUInt16(array, start + 6)
|
||||
},
|
||||
new UShort4(
|
||||
BitConverter.ToUInt16(array, start),
|
||||
BitConverter.ToUInt16(array, start + 2),
|
||||
BitConverter.ToUInt16(array, start + 4),
|
||||
BitConverter.ToUInt16(array, start + 6)
|
||||
),
|
||||
Setter = BitWriter.Write
|
||||
}},
|
||||
{typeof(SkinJoints), new GetSet<SkinJoints>{
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 48a1d420ea119e944861a729a7d1c6f4
|
||||
guid: 8ef774aa861dc6f46a94330c7169bf04
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
|
|
@ -1,10 +1,9 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Numerics;
|
||||
using VrmLib;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace VrmLibTests
|
||||
namespace UniGLTF
|
||||
{
|
||||
public class NumericTests
|
||||
{
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 534d323846a2b9949b4bb43ae75ab8f8
|
||||
guid: 36c14eec5ed000f4cbb5dddf4e4c1af4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
|
|
@ -1,8 +1,7 @@
|
|||
using System;
|
||||
using VrmLib;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace VrmLibTests
|
||||
namespace UniGLTF
|
||||
{
|
||||
public class SpanLikeTests
|
||||
{
|
||||
|
|
@ -32,7 +31,7 @@ namespace VrmLibTests
|
|||
v0,
|
||||
v1,
|
||||
};
|
||||
var span = VrmLib.SpanLike.CopyFrom(positions);
|
||||
var span = SpanLike.CopyFrom(positions);
|
||||
|
||||
Assert.AreEqual(2, span.Length);
|
||||
Assert.AreEqual(v0, span[0]);
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 212282563b23d744dbd55e78db0f91f5
|
||||
guid: f70b7312ba0d32b4493231c6f8a42e4c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
|
|
@ -42,7 +42,7 @@ namespace UniVRM10
|
|||
/// <param name="expressionWeights"></param>
|
||||
public void SetValues(Dictionary<ExpressionKey, float> expressionWeights)
|
||||
{
|
||||
foreach (var (key, weight) in expressionWeights)
|
||||
foreach (var (key, weight) in expressionWeights.Select(kv => (kv.Key, kv.Value)))
|
||||
{
|
||||
AccumulateValue(key, weight);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -143,7 +143,7 @@ namespace UniVRM10
|
|||
|
||||
public void Replace(IDictionary<VRM10Expression, VRM10Expression> map)
|
||||
{
|
||||
foreach (var (k, v) in map)
|
||||
foreach (var (k, v) in map.Select(kv => (kv.Key, kv.Value)))
|
||||
{
|
||||
Replace(k, v);
|
||||
}
|
||||
|
|
@ -341,7 +341,7 @@ namespace UniVRM10
|
|||
|
||||
public void SetWeights(IEnumerable<KeyValuePair<ExpressionKey, float>> weights)
|
||||
{
|
||||
foreach (var (expressionKey, weight) in weights)
|
||||
foreach (var (expressionKey, weight) in weights.Select(kv => (kv.Key, kv.Value)))
|
||||
{
|
||||
if (_inputWeights.ContainsKey(expressionKey))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -105,9 +105,9 @@ namespace UniVRM10
|
|||
{
|
||||
// use sparse
|
||||
var sparseIndexBin = new ArraySegment<byte>(new byte[sparseValuesWithIndex.Count * 4]);
|
||||
var sparseIndexSpan = VrmLib.SpanLike.Wrap<Int32>(sparseIndexBin);
|
||||
var sparseIndexSpan = SpanLike.Wrap<Int32>(sparseIndexBin);
|
||||
var sparseValueBin = new ArraySegment<byte>(new byte[sparseValuesWithIndex.Count * 12]);
|
||||
var sparseValueSpan = VrmLib.SpanLike.Wrap<Vector3>(sparseValueBin);
|
||||
var sparseValueSpan = SpanLike.Wrap<Vector3>(sparseValueBin);
|
||||
|
||||
for (int i = 0; i < sparseValuesWithIndex.Count; ++i)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using UniGLTF;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UniVRM10
|
||||
|
|
@ -28,7 +29,7 @@ namespace UniVRM10
|
|||
throw new ArgumentException();
|
||||
}
|
||||
var weights = src.VertexBuffer.Weights.GetSpan<Vector4>();
|
||||
var joints = src.VertexBuffer.Joints.GetSpan<VrmLib.SkinJoints>();
|
||||
var joints = src.VertexBuffer.Joints.GetSpan<SkinJoints>();
|
||||
if (skin != null)
|
||||
{
|
||||
mesh.bindposes = skin.InverseMatrices.GetSpan<Matrix4x4>().ToArray();
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UniGLTF;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UniVRM10
|
||||
|
|
@ -26,7 +27,7 @@ namespace UniVRM10
|
|||
uv.AddRange(mesh.VertexBuffer.TexCoords.GetSpan<Vector2>());
|
||||
if (src.Skin != null)
|
||||
{
|
||||
var j = mesh.VertexBuffer.Joints.GetSpan<VrmLib.SkinJoints>();
|
||||
var j = mesh.VertexBuffer.Joints.GetSpan<SkinJoints>();
|
||||
var w = mesh.VertexBuffer.Weights.GetSpan<Vector4>();
|
||||
for (int i = 0; i < mesh.VertexBuffer.Count; ++i)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UniGLTF;
|
||||
using UnityEngine;
|
||||
using VrmLib;
|
||||
|
||||
|
|
@ -183,7 +184,7 @@ namespace UniVRM10
|
|||
vrmMesh.VertexBuffer.Add(
|
||||
VrmLib.VertexBuffer.JointKey,
|
||||
ToBufferAccessor(mesh.boneWeights.Select(x =>
|
||||
new VrmLib.SkinJoints((ushort)x.boneIndex0, (ushort)x.boneIndex1, (ushort)x.boneIndex2, (ushort)x.boneIndex3)).ToArray()
|
||||
new SkinJoints((ushort)x.boneIndex0, (ushort)x.boneIndex1, (ushort)x.boneIndex2, (ushort)x.boneIndex3)).ToArray()
|
||||
));
|
||||
}
|
||||
if (mesh.uv.Length == mesh.vertexCount) vrmMesh.VertexBuffer.Add(VrmLib.VertexBuffer.TexCoordKey, ToBufferAccessor(mesh.uv));
|
||||
|
|
@ -269,7 +270,7 @@ namespace UniVRM10
|
|||
return skin;
|
||||
}
|
||||
|
||||
private static VrmLib.BufferAccessor ToBufferAccessor(VrmLib.SkinJoints[] values)
|
||||
private static VrmLib.BufferAccessor ToBufferAccessor(SkinJoints[] values)
|
||||
{
|
||||
return ToBufferAccessor(values, VrmLib.AccessorValueType.UNSIGNED_SHORT, VrmLib.AccessorVectorType.VEC4);
|
||||
}
|
||||
|
|
@ -306,7 +307,7 @@ namespace UniVRM10
|
|||
|
||||
private static VrmLib.BufferAccessor ToBufferAccessor<T>(T[] value, VrmLib.AccessorValueType valueType, VrmLib.AccessorVectorType vectorType) where T : struct
|
||||
{
|
||||
var span = VrmLib.SpanLike.CopyFrom(value);
|
||||
var span = SpanLike.CopyFrom(value);
|
||||
return new VrmLib.BufferAccessor(
|
||||
span.Bytes,
|
||||
valueType,
|
||||
|
|
|
|||
|
|
@ -209,7 +209,7 @@ namespace UniVRM10
|
|||
|
||||
// renderer
|
||||
var map = m_map;
|
||||
foreach (var (node, go) in map.Nodes)
|
||||
foreach (var (node, go) in map.Nodes.Select(kv => (kv.Key, kv.Value)))
|
||||
{
|
||||
if (node.MeshGroup is null)
|
||||
{
|
||||
|
|
@ -408,7 +408,7 @@ namespace UniVRM10
|
|||
vrm.Expression.LookRight = GetOrLoadExpression(ExpressionKey.LookRight.SubAssetKey, ExpressionPreset.lookRight, vrmExtension.Expressions?.Preset?.LookRight);
|
||||
if (vrmExtension?.Expressions?.Custom != null)
|
||||
{
|
||||
foreach (var (name, expression) in vrmExtension.Expressions.Custom)
|
||||
foreach (var (name, expression) in vrmExtension.Expressions.Custom.Select(kv => (kv.Key, kv.Value)))
|
||||
{
|
||||
var key = ExpressionKey.CreateCustom(name);
|
||||
var preset = ExpressionPreset.custom;
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ namespace UniVRM10
|
|||
if (bufferViewIndex != -1)
|
||||
{
|
||||
var buffer = gltf.GetViewBytes(bufferViewIndex);
|
||||
var span = VrmLib.SpanLike.Wrap<UnityEngine.Vector3>(buffer);
|
||||
var span = SpanLike.Wrap<UnityEngine.Vector3>(buffer);
|
||||
for (int i = 0; i < span.Length; ++i)
|
||||
{
|
||||
span[i] = span[i].RotateY180();
|
||||
|
|
@ -114,7 +114,7 @@ namespace UniVRM10
|
|||
{
|
||||
var accessor = gltf.accessors[skin.inverseBindMatrices];
|
||||
var buffer = gltf.GetViewBytes(accessor.bufferView);
|
||||
var span = VrmLib.SpanLike.Wrap<UnityEngine.Matrix4x4>(buffer);
|
||||
var span = SpanLike.Wrap<UnityEngine.Matrix4x4>(buffer);
|
||||
for (int i = 0; i < span.Length; ++i)
|
||||
{
|
||||
span[i] = span[i].RotateY180();
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
|
||||
using UniGLTF;
|
||||
|
||||
namespace VrmLib
|
||||
{
|
||||
|
|
@ -82,9 +82,9 @@ namespace VrmLib
|
|||
elapsed -= m_lastTime;
|
||||
}
|
||||
|
||||
foreach (var (node, animation) in NodeMap)
|
||||
foreach (var (node, animation) in NodeMap.Select(kv => (kv.Key, kv.Value)))
|
||||
{
|
||||
foreach (var (target, curve) in animation.Curves)
|
||||
foreach (var (target, curve) in animation.Curves.Select(kv => (kv.Key, kv.Value)))
|
||||
{
|
||||
switch (target)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -230,10 +230,7 @@ namespace VrmLib
|
|||
var span = SpanLike.Wrap<Byte4>(Bytes);
|
||||
for (int i = 0; i < span.Length; ++i)
|
||||
{
|
||||
array[i].X = span[i].X;
|
||||
array[i].Y = span[i].Y;
|
||||
array[i].Z = span[i].Z;
|
||||
array[i].W = span[i].W;
|
||||
array[i] = new UShort4(span[i].x, span[i].y, span[i].z, span[i].w);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UniGLTF;
|
||||
|
||||
namespace VrmLib
|
||||
{
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Runtime.InteropServices;
|
||||
using UniGLTF;
|
||||
|
||||
namespace VrmLib
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using UniGLTF;
|
||||
|
||||
namespace VrmLib
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using UniGLTF;
|
||||
|
||||
namespace VrmLib
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Numerics;
|
||||
using System.Runtime.InteropServices;
|
||||
using UniGLTF;
|
||||
|
||||
namespace VrmLib
|
||||
{
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ using System.Linq;
|
|||
using System.Numerics;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using UniGLTF;
|
||||
|
||||
namespace VrmLib
|
||||
{
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Runtime.InteropServices;
|
||||
using UniGLTF;
|
||||
|
||||
namespace VrmLib
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Numerics;
|
||||
using UniGLTF;
|
||||
|
||||
namespace VrmLib
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user