/// <summary> /// indicesの最大値が65535未満(-1を避ける)ならばushort 型で、 /// そうでなければ int型で IndexBufferを代入する /// </summary> public void AssignIndexBuffer(Span <int> indices) { bool isInt = false; foreach (var i in indices) { if (i >= short.MaxValue) { isInt = true; break; } } if (isInt) { if (IndexBuffer.Stride != 4) { IndexBuffer.ComponentType = AccessorValueType.UNSIGNED_INT; if (IndexBuffer.AccessorType != AccessorVectorType.SCALAR) { throw new Exception(); } } // 変換なし IndexBuffer.Assign(indices); } else { // int to ushort IndexBuffer.AssignAsShort(indices); } }
/// <summary> /// BoneSkinningもしくはMorphTargetの適用 /// <summary> public void Skinning(INativeArrayManager arrayManager, VertexBuffer vertexBuffer = null) { m_indexOfRoot = (ushort)Joints.IndexOf(Root); var addRoot = Root != null && m_indexOfRoot == ushort.MaxValue; if (addRoot) { m_indexOfRoot = (ushort)Joints.Count; Joints.Add(Root); } if (m_matrices == null) { m_matrices = new Matrix4x4[Joints.Count]; } if (InverseMatrices == null) { CalcInverseMatrices(arrayManager); } else { if (addRoot) { var inverseArray = InverseMatrices.Bytes.Reinterpret <Matrix4x4>(1); var concat = inverseArray.Concat(new[] { Root.InverseMatrix }).ToArray(); InverseMatrices.Assign(concat); } } var inverse = InverseMatrices.GetSpan <Matrix4x4>(); // if (Root != null) // { // var rootInverse = Root.InverseMatrix; // var root = Root.Matrix; // for (int i = 0; i < m_matrices.Length; ++i) // { // m_matrices[i] = inverse[i] * Joints[i].Matrix * rootInverse; // } // } // else { for (int i = 0; i < m_matrices.Length; ++i) { var inv = i < inverse.Length ? inverse[i] : Joints[i].InverseMatrix; m_matrices[i] = inv * Joints[i].Matrix; } } if (vertexBuffer != null) { Apply(arrayManager, vertexBuffer); } }