public static UnityEngine.BoneWeight Convert(SkinBoneIndices boneIndices, SkinBoneWeights boneWeights)
        {
            return new UnityEngine.BoneWeight
            {
                boneIndex0 = (int)boneIndices.Indices[0],
                boneIndex1 = (int)boneIndices.Indices[1],
                boneIndex2 = (int)boneIndices.Indices[2],
                boneIndex3 = (int)boneIndices.Indices[3],

                weight0 = boneWeights.Weights[0],
                weight1 = boneWeights.Weights[1],
                weight2 = boneWeights.Weights[2],
                weight3 = boneWeights.Weights[3],
            };
        }
Exemple #2
0
        public Skin(SectionHeader header, Stream stream)
            : base(header, stream)
        {
            var reader = new BinaryReader(stream);

            Int32  boneCount        = (Int32)reader.ReadByte();
            Int32  boneIdCount      = (Int32)reader.ReadByte();
            UInt16 weightsPerVertex = reader.ReadUInt16();

            byte[] boneIds = reader.ReadBytes(boneIdCount);

            var vertexCount = header.GetParent <Geometry>().VertexCount;

            VertexBoneIndices = new SkinBoneIndices[vertexCount];
            VertexBoneWeights = new SkinBoneWeights[vertexCount];

            for (int i = 0; i < vertexCount; ++i)
            {
                VertexBoneIndices[i] = new SkinBoneIndices(reader);
            }

            for (int i = 0; i < vertexCount; ++i)
            {
                VertexBoneWeights[i] = new SkinBoneWeights(reader);
            }

            SkinToBoneMatrices = new Matrix4x4[boneCount];

            for (int i = 0; i < boneCount; ++i)
            {
                if (boneIdCount == 0)
                {
                    reader.BaseStream.Seek(4, SeekOrigin.Current);
                }

                SkinToBoneMatrices[i] = new Matrix4x4(reader);
            }

            UInt32 boneLimit = reader.ReadUInt32();
            UInt32 meshCount = reader.ReadUInt32();
            UInt32 RLE       = reader.ReadUInt32();

            if (meshCount > 0)
            {
                MeshBoneRemapIndices = reader.ReadBytes((Int32)(boneCount + 2 * (RLE + meshCount)));
            }
        }
Exemple #3
0
        public Skin(SectionHeader header, Stream stream)
            : base(header, stream)
        {
            var reader = new BinaryReader(stream);

            Int32 boneCount = (Int32)reader.ReadByte();
            Int32 boneIdCount = (Int32)reader.ReadByte();
            UInt16 weightsPerVertex = reader.ReadUInt16();

            byte[] boneIds = reader.ReadBytes(boneIdCount);

            var vertexCount = header.GetParent<Geometry>().VertexCount;

            VertexBoneIndices = new SkinBoneIndices[vertexCount];
            VertexBoneWeights = new SkinBoneWeights[vertexCount];

            for (int i = 0; i < vertexCount; ++i)
            {
                VertexBoneIndices[i] = new SkinBoneIndices(reader);
            }

            for (int i = 0; i < vertexCount; ++i)
            {
                VertexBoneWeights[i] = new SkinBoneWeights(reader);
            }

            SkinToBoneMatrices = new Matrix4x4[boneCount];

            for (int i = 0; i < boneCount; ++i)
            {
                if (boneIdCount == 0)
                {
                    reader.BaseStream.Seek(4, SeekOrigin.Current);
                }

                SkinToBoneMatrices[i] = new Matrix4x4(reader);
            }

            UInt32 boneLimit = reader.ReadUInt32();
            UInt32 meshCount = reader.ReadUInt32();
            UInt32 RLE = reader.ReadUInt32();

            if (meshCount > 0)
            {
                MeshBoneRemapIndices = reader.ReadBytes((Int32)(boneCount + 2 * (RLE + meshCount)));
            }
        }
 public static UnityEngine.BoneWeight[] Convert(SkinBoneIndices[] boneIndices, SkinBoneWeights[] boneWeights)
 {
     return Enumerable.Range(0, (int)boneIndices.Length).Select(x => Convert(boneIndices[x], boneWeights[x])).ToArray();
 }