Esempio n. 1
0
 private static List <Bone> GetChildBones(VoxelData.RigData.Bone parent)
 {
     if (Data.Rigs.ContainsKey(ModelIndex))
     {
         var rigData = Data.Rigs[ModelIndex];
         if (rigData.Bones.Count == 0)
         {
             return(null);
         }
         var boneList = new List <Bone>();
         for (int i = 0; i < rigData.Bones.Count; i++)
         {
             var sourceBone = rigData.Bones[i];
             if (sourceBone && sourceBone.Parent == parent)
             {
                 var bone = new Bone()
                 {
                     Index    = i,
                     Name     = sourceBone.Name,
                     Position = new Vector3(
                         sourceBone.PositionX / 2f,
                         sourceBone.PositionY / 2f,
                         sourceBone.PositionZ / 2f
                         ),
                     ChildBones = GetChildBones(sourceBone),
                 };
                 boneList.Add(bone);
             }
         }
         return(boneList);
     }
     return(null);
 }
Esempio 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);
        }