Ejemplo n.º 1
0
        private static void GetWeights()
        {
            int sizeX   = SizeX;
            int sizeY   = SizeY;
            int sizeZ   = SizeZ;
            var weights = new VoxelData.RigData.Weight[sizeX, sizeY, sizeZ];

            // Weights
            if (Data.Rigs.ContainsKey(ModelIndex))
            {
                var rigData = Data.Rigs[ModelIndex];
                if (rigData.Bones.Count > 0 && rigData.Weights.Count > 0)
                {
                    for (int i = 0; i < rigData.Weights.Count; i++)
                    {
                        var source = rigData.Weights[i];
                        if ((source.BoneIndexA >= 0 || source.BoneIndexB >= 0) && source.X >= 0 && source.X < sizeX && source.Y >= 0 && source.Y < sizeY && source.Z >= 0 && source.Z < sizeZ)
                        {
                            weights[source.X, source.Y, source.Z] = new VoxelData.RigData.Weight(source.BoneIndexA, source.BoneIndexB);
                        }
                    }
                }
            }


            // Point Weights
            PointWeights = new BoneWeight[sizeX + 1, sizeY + 1, sizeZ + 1];
            for (int x = 0; x < sizeX + 1; x++)
            {
                for (int y = 0; y < sizeY + 1; y++)
                {
                    for (int z = 0; z < sizeZ + 1; z++)
                    {
                        PointWeights[x, y, z] = GetBoneWeightFromVoxelWeights(
                            new Vector3(x - 0.5f, y - 0.5f, z - 0.5f),
                            weights
                            );
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private static int ReadRig(BinaryReader _br, ref VoxelData data, int version)
        {
            int chunkSize    = _br.ReadInt32();
            int childrenSize = _br.ReadInt32();

            int id = _br.ReadInt32();

            var rigData = new VoxelData.RigData()
            {
                Bones   = new List <VoxelData.RigData.Bone>(),
                Weights = new List <VoxelData.RigData.Weight>(),
                Version = version,
            };

            // Bone
            int boneCount = _br.ReadInt32();

            for (int i = 0; i < boneCount; i++)
            {
                var bone = new VoxelData.RigData.Bone {
                    Name        = ReadString(_br),
                    ParentIndex = _br.ReadInt32(),
                    PositionX   = _br.ReadInt32(),
                    PositionY   = _br.ReadInt32(),
                    PositionZ   = _br.ReadInt32(),
                };
                rigData.Bones.Add(bone);
            }

            for (int i = 0; i < rigData.Bones.Count; i++)
            {
                int pIndex = rigData.Bones[i].ParentIndex;
                if (pIndex >= 0 && pIndex < rigData.Bones.Count)
                {
                    rigData.Bones[i].Parent = rigData.Bones[pIndex];
                }
            }

            // Weight
            int WeightCount = _br.ReadInt32();

            for (int i = 0; i < WeightCount; i++)
            {
                var weight = new VoxelData.RigData.Weight {
                    X          = _br.ReadInt32(),
                    Y          = _br.ReadInt32(),
                    Z          = _br.ReadInt32(),
                    BoneIndexA = _br.ReadInt32(),
                    BoneIndexB = _br.ReadInt32(),
                };
                rigData.Weights.Add(weight);
            }

            // Version
            rigData.FixVersion();

            // End
            if (!data.Rigs.ContainsKey(id))
            {
                data.Rigs.Add(id, rigData);
            }

            if (childrenSize > 0)
            {
                _br.ReadBytes(childrenSize);
            }

            return(chunkSize + childrenSize + 4 + 4);
        }