From 570b56a52c8a689732bb8724647874636d9b2852 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Mon, 14 Feb 2022 13:35:20 +0900 Subject: [PATCH] Remove unused. --- .../Runtime/UniGLTF/IO/ExportingGltfData.cs | 12 -- Assets/VRM10/vrmlib/Runtime/Animation.cs | 103 --------------- Assets/VRM10/vrmlib/Runtime/BufferAccessor.cs | 121 ------------------ Assets/VRM10/vrmlib/Runtime/Model.cs | 52 -------- Assets/VRM10/vrmlib/Runtime/Skin.cs | 36 +----- Assets/VRM10/vrmlib/Runtime/VertexBuffer.cs | 107 +--------------- 6 files changed, 2 insertions(+), 429 deletions(-) diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/ExportingGltfData.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/ExportingGltfData.cs index 94903c2b9..b5d535cc5 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/ExportingGltfData.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/ExportingGltfData.cs @@ -169,18 +169,6 @@ namespace UniGLTF return Glb.Create(json, BinBytes).ToBytes(); } - // public byte[] ToBytes() - // { - // GLTF.buffers[0].byteLength = _buffer.Bytes.Count; - - // var f = new JsonFormatter(); - // UniGLTF.GltfSerializer.Serialize(f, GLTF); - // var json = f.GetStoreBytes(); - - // var glb = UniGLTF.Glb.Create(json, _buffer.Bytes); - // return glb.ToBytes(); - // } - /// /// glTF 形式で出力する? /// diff --git a/Assets/VRM10/vrmlib/Runtime/Animation.cs b/Assets/VRM10/vrmlib/Runtime/Animation.cs index 77a650fdb..01d2f7049 100644 --- a/Assets/VRM10/vrmlib/Runtime/Animation.cs +++ b/Assets/VRM10/vrmlib/Runtime/Animation.cs @@ -218,108 +218,5 @@ namespace VrmLib return m_root; } } - - // /// - // /// モーションの基本姿勢を basePose ベースに再計算する - // /// - // /// basePose は Humanoid.CopyNodes が必用 ! - // /// - // public Animation RebaseAnimation(Humanoid basePose) - // { - // var map = NodeMap.ToDictionary(kv => kv.Key, kv => new List()); - // var hipsPositions = new List(); - - // foreach (var (seconds, keyframes) in KeyFramesGroupBySeconds()) - // { - // // モーション適用 - // SetTime(seconds); - // Root.CalcWorldMatrix(); - - // foreach (var keyframe in keyframes) - // { - // if (!keyframe.Node.HumanoidBone.HasValue - // || keyframe.Node.HumanoidBone.Value == HumanoidBones.unknown) - // { - // continue; - // } - - // // ローカル回転を算出する - // var t = basePose[keyframe.Node].Rotation; - // var w = keyframe.Node.Rotation; - // var w_from_t = w * Quaternion.Inverse(t); - - // // parent - // var key = keyframe.Node.HumanoidBone.Value; - // var curve = map[keyframe.Node]; - // if (key != HumanoidBones.hips) - // { - // if (basePose[key].Parent == null) - // { - // throw new Exception(); - // } - // var parent_t = basePose[key].Parent.Rotation; - // var parent_w = keyframe.Node.Parent.Rotation; - // var parent_w_from_t = parent_w * Quaternion.Inverse(parent_t); - - // var r = Quaternion.Inverse(parent_w_from_t) * w_from_t; - // curve.Add(r); - // } - // else - // { - // // hips - // curve.Add(w_from_t); - // hipsPositions.Add(keyframe.Node.Translation); - // } - // } - // } - - // var dst = new Animation(Name + ".tpose"); - // foreach (var kv in map) - // { - // if (!kv.Value.Any()) - // { - // continue; - // } - - // var bone = kv.Key.HumanoidBone.Value; - - // var inCurve = NodeMap[kv.Key].Curves[AnimationPathType.Rotation].In; - // if (inCurve.Count != kv.Value.Count) - // { - // throw new Exception(); - // } - - // var nodeAnimation = new NodeAnimation(); - // nodeAnimation.Curves.Add(AnimationPathType.Rotation, new CurveSampler - // { - // In = inCurve, - // Out = BufferAccessor.Create(kv.Value.ToArray()), - // }); - // if (bone == HumanoidBones.hips) - // { - // nodeAnimation.Curves.Add(AnimationPathType.Translation, new CurveSampler - // { - // In = inCurve, - // Out = BufferAccessor.Create(hipsPositions.ToArray()), - // }); - // } - // dst.AddCurve(kv.Key, nodeAnimation); - // } - // return dst; - // } - - // /// - // /// 指定された数のフレームを先頭から取り除く - // /// - // public void SkipFrame(int skipFrames) - // { - // foreach (var kv in NodeMap) - // { - // foreach (var curve in kv.Value.Curves) - // { - // curve.Value.SkipFrame(skipFrames); - // } - // } - // } } } diff --git a/Assets/VRM10/vrmlib/Runtime/BufferAccessor.cs b/Assets/VRM10/vrmlib/Runtime/BufferAccessor.cs index 2694f30de..602ded4c3 100644 --- a/Assets/VRM10/vrmlib/Runtime/BufferAccessor.cs +++ b/Assets/VRM10/vrmlib/Runtime/BufferAccessor.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Numerics; using System.Runtime.InteropServices; using UniGLTF; @@ -164,40 +163,6 @@ namespace VrmLib return Bytes.Reinterpret(1); } - // /// - // /// バッファをNativeArrayに変換して返す - // /// 開放の責務は使い手側にある点に注意 - // /// - // public unsafe NativeArray AsNativeArray(Allocator allocator) where T : struct - // { - // if (Stride == Marshal.SizeOf(typeof(T))) - // { - // fixed (byte* byteArray = Bytes.Array) - // { - // var nativeArray = new NativeArray(Bytes.Count / Marshal.SizeOf(), allocator); - // UnsafeUtility.MemCpy(nativeArray.GetUnsafePtr(), byteArray + Bytes.Offset, Bytes.Count); - // return nativeArray; - // } - // } - // else - // { - // if (typeof(T) == typeof(SkinJoints) && Stride == 4) - // { - // // 例えば SkinJoints を使う JOINTS_0 は UNSIGNED_BYTE と UNSIGNED_SHORT の2種類がありえる。 - // fixed (UShort4* p = GetAsUShort4()) - // { - // var nativeArray = new NativeArray(Count, allocator); - // UnsafeUtility.MemCpy(nativeArray.GetUnsafePtr(), p, Bytes.Count); - // return nativeArray; - // } - // } - // else - // { - // throw new Exception($"Stride:{Stride}!= sizeof({typeof(T).Name}:{Marshal.SizeOf(typeof(T))}"); - // } - // } - // } - /// /// バッファをNativeSliceへと書き込む /// @@ -262,92 +227,6 @@ namespace VrmLib } } - // public List GetAsIntList() - // { - // if (AccessorType != AccessorVectorType.SCALAR) - // { - // throw new InvalidOperationException("not scalar"); - // } - // switch (ComponentType) - // { - // case AccessorValueType.UNSIGNED_SHORT: - // { - // var span = SpanLike.Wrap(Bytes); - // var array = new List(Count); - // if (span.Length != Count) - // { - // for (int i = 0; i < Count; ++i) - // { - // array.Add(span[i]); - // } - // } - // else - // { - // // Spanが動かない?WorkAround - // var bytes = Bytes.ToArray(); - // var offset = 0; - // for (int i = 0; i < Count; ++i) - // { - // array.Add(BitConverter.ToUInt16(bytes, offset)); - // offset += 2; - // } - // } - // return array; - // } - - // case AccessorValueType.UNSIGNED_INT: - // return SpanLike.Wrap(Bytes).ToArray().ToList(); - - // default: - // throw new NotImplementedException(); - // } - // } - - // // Joints用 - // public UShort4[] GetAsUShort4() - // { - // if (AccessorType != AccessorVectorType.VEC4) - // { - // throw new InvalidOperationException("not vec4"); - // } - // switch (ComponentType) - // { - // case AccessorValueType.UNSIGNED_SHORT: - // return SpanLike.Wrap(Bytes).ToArray(); - - // case AccessorValueType.UNSIGNED_BYTE: - // { - // var array = new UShort4[Count]; - // var span = SpanLike.Wrap(Bytes); - // for (int i = 0; i < span.Length; ++i) - // { - // array[i] = new UShort4(span[i].x, span[i].y, span[i].z, span[i].w); - // } - // return array; - // } - - // default: - // throw new NotImplementedException(); - // } - // } - - // // Weigt用 - // public Vector4[] GetAsVector4() - // { - // if (AccessorType != AccessorVectorType.VEC4) - // { - // throw new InvalidOperationException("not vec4"); - // } - // switch (ComponentType) - // { - // case AccessorValueType.FLOAT: - // return SpanLike.Wrap(Bytes).ToArray(); - - // default: - // throw new NotImplementedException(); - // } - // } - public void Resize(int count) { if (count < Count) diff --git a/Assets/VRM10/vrmlib/Runtime/Model.cs b/Assets/VRM10/vrmlib/Runtime/Model.cs index 7234845f6..297839456 100644 --- a/Assets/VRM10/vrmlib/Runtime/Model.cs +++ b/Assets/VRM10/vrmlib/Runtime/Model.cs @@ -223,58 +223,6 @@ namespace VrmLib this.Nodes.Remove(remove); } - - // /// - // /// Nodeを置き換える。参照を置換する。 - // /// - // public void NodeReplace(Node src, Node dst) - // { - // if (src == null) - // { - // throw new ArgumentNullException(); - // } - // if (dst == null) - // { - // throw new ArgumentNullException(); - // } - - // // add dst same parent - // src.Parent.Add(dst, ChildMatrixMode.KeepWorld); - - // // remove all child - // foreach (var child in src.Children.ToArray()) - // { - // dst.Add(child, ChildMatrixMode.KeepWorld); - // } - - // // remove from parent - // src.Parent.Remove(src); - // this.Nodes.Remove(src); - - // // remove from skinning - // foreach (var skin in this.Skins) - // { - // skin.Replace(src, dst); - // } - - // // fix animation reference - // foreach (var animation in this.Animations) - // { - // if (animation.NodeMap.TryGetValue(src, out NodeAnimation nodeAnimation)) - // { - // animation.NodeMap.Remove(src); - // animation.NodeMap.Add(dst, nodeAnimation); - // } - // } - - // if (this.Nodes.Contains(dst)) - // { - // throw new Exception("already exists"); - // } - // this.Nodes.Add(dst); - - // // TODO: SpringBone - // } #endregion public string SkinningBake(NativeArrayManager arrayManager) diff --git a/Assets/VRM10/vrmlib/Runtime/Skin.cs b/Assets/VRM10/vrmlib/Runtime/Skin.cs index e788469a8..50a915ec2 100644 --- a/Assets/VRM10/vrmlib/Runtime/Skin.cs +++ b/Assets/VRM10/vrmlib/Runtime/Skin.cs @@ -276,39 +276,5 @@ namespace VrmLib index = (ushort)indexMap[index]; } } - - // /// - // /// nullになったjointを除去して、boneweightを前に詰める - // /// - // public void FixBoneWeight(BufferAccessor jointsAccessor, BufferAccessor weightsAccessor) - // { - // var map = Joints.Select((x, i) => ValueTuple.Create(i, x)).Where(x => x.Item2 != null).ToArray(); - // var indexMap = Enumerable.Repeat(-1, Joints.Count).ToArray(); - // { - // for (int i = 0; i < map.Length; ++i) - // { - // indexMap[map[i].Item1] = i; - // } - // } - // Joints.RemoveAll(x => x == null); - - // var joints = jointsAccessor.GetSpan(); - // var weights = weightsAccessor.GetSpan(); - // for (int i = 0; i < joints.Length; ++i) - // { - // var j = joints[i]; - // var w = weights[i]; - - // Update(ref w.X, ref j.Joint0, indexMap); - // Update(ref w.Y, ref j.Joint1, indexMap); - // Update(ref w.Z, ref j.Joint2, indexMap); - // Update(ref w.W, ref j.Joint3, indexMap); - - // joints[i] = j; - // weights[i] = w; - // } - - // CalcInverseMatrices(); - // } } -} \ No newline at end of file +} diff --git a/Assets/VRM10/vrmlib/Runtime/VertexBuffer.cs b/Assets/VRM10/vrmlib/Runtime/VertexBuffer.cs index 37168892e..44dbd87df 100644 --- a/Assets/VRM10/vrmlib/Runtime/VertexBuffer.cs +++ b/Assets/VRM10/vrmlib/Runtime/VertexBuffer.cs @@ -2,9 +2,6 @@ using System; using System.Collections; using System.Collections.Generic; using System.Linq; -using System.Numerics; -using System.Runtime.InteropServices; -using UniGLTF; namespace VrmLib { @@ -185,107 +182,5 @@ namespace VrmLib public VertexBuffer() { } - - public VertexBuffer CloneWithOffset(int offsetCount) - { - var vb = new VertexBuffer(); - foreach (var kv in VertexBuffers) - { - vb.VertexBuffers[kv.Key] = kv.Value.CloneWithOffset(offsetCount); - } - return vb; - } - - // public SpanLike GetOrCreateJoints() - // { - // var buffer = Joints; - // if (buffer == null) - // { - // buffer = new BufferAccessor( - // new ArraySegment(new byte[Marshal.SizeOf(typeof(SkinJoints)) * Count]), - // AccessorValueType.UNSIGNED_SHORT, - // AccessorVectorType.VEC4, Count); - // Add(JointKey, buffer); - // } - // return SpanLike.Wrap(buffer.Bytes); - // } - - // public SpanLike GetOrCreateWeights() - // { - // var buffer = Weights; - // if (buffer == null) - // { - // buffer = new BufferAccessor( - // new ArraySegment(new byte[Marshal.SizeOf(typeof(Vector4)) * Count]), - // AccessorValueType.FLOAT, - // AccessorVectorType.VEC4, Count); - // Add(WeightKey, buffer); - // } - // return SpanLike.Wrap(buffer.Bytes); - // } - - static bool HasSameKeys(Dictionary lhs, Dictionary rhs) - { - if (lhs.Count != rhs.Count) return false; - foreach (var (l, r) in Enumerable.Zip(lhs.Keys.OrderBy(x => x), rhs.Keys.OrderBy(x => x), (l, r) => (l, r))) - { - if (l != r) - { - return false; - } - } - return true; - } - - // public void Append(VertexBuffer v) - // { - // var keys = VertexBuffers.Keys.ToList(); - - // var lastCount = Count; - - // // v から VertexBufferfs に足す - // foreach (var kv in v.VertexBuffers) - // { - // if (VertexBuffers.TryGetValue(kv.Key, out BufferAccessor buffer)) - // { - // // used - // keys.Remove(kv.Key); - // if (buffer.Count != lastCount) - // { - // throw new ArgumentException(); - // } - // } - // else - // { - // // add empty - // var byteLength = lastCount * kv.Value.Stride; - // buffer = new BufferAccessor(new ArraySegment(new byte[byteLength]), kv.Value.ComponentType, kv.Value.AccessorType, lastCount); - // if (buffer.Count != lastCount) - // { - // throw new ArgumentException(); - // } - // VertexBuffers.Add(kv.Key, buffer); - // } - - // buffer.Append(kv.Value); - // } - - // // 足されなかったキーに同じ長さを詰める - // foreach (var key in keys) - // { - // var dst = VertexBuffers[key]; - // dst.Extend(v.Positions.Count); - // } - - // ValidateLength(); - // } - - public void Resize(int n) - { - foreach (var kv in VertexBuffers) - { - kv.Value.Resize(n); - } - } } -} \ No newline at end of file +}