コード例 #1
0
ファイル: AnimationFull.cs プロジェクト: KatekovAnton/Game
        public static FullAnimation From3DMAXStream(System.IO.Stream stream, Skeleton skeleton)
        {
            Matrix[][] Frames;

            var clip = new FullAnimation();
            var reader = new System.IO.BinaryReader(stream);

            var start = reader.ReadInt32();
            var end = reader.ReadInt32();
            var length = end - start + 1;

            clip.BonesCount = reader.ReadInt32();
            var counter = reader.ReadInt32();

            Frames = new Matrix[length][];
            for (int i = 0; i < length; i++)
                Frames[i] = new Matrix[clip.BonesCount];

            for (int i = 0; i < clip.BonesCount; i++)
                for (int j = 0; j < length; j++)
                    Frames[j][i] = reader.ReadMatrix();

            //теперь надо вычислить дельты
            //(идёт загрузка экспортированного из макса)
            for (int i = 0; i < clip.BonesCount; i++)
                for (int @in = 0; @in < length; @in++)
                    Frames[@in][i] = skeleton.bones[i].BaseMatrix * Frames[@in][i];

            Matrix[][] relatedMatrices = Animation.GetRelatedMatrices(Frames, skeleton);
            DecomposedMatrix[][] decomposedMatrices = GetDecomposedMatrices(skeleton, relatedMatrices);

            clip.matrices = decomposedMatrices;
            clip.length = clip.matrices.Length;
            return clip;
        }
コード例 #2
0
ファイル: SkeletonExtended.cs プロジェクト: KatekovAnton/Game
        public void loadbody(System.IO.BinaryReader br)
        {
            baseskelet = Skeleton.FromStream(br);
            HeadIndex = br.ReadInt32();
            WeaponIndex = br.ReadInt32();

            HeadMatrix = br.ReadMatrix();
            WeaponMatrix = br.ReadMatrix();

            RootIndex = br.ReadInt32();
            TopRootIndex = br.ReadInt32();
            BottomRootIndex = br.ReadInt32();
            botomindexes = new int[br.ReadInt32()];
            for (int i = 0; i < botomindexes.Length; i++)
                botomindexes[i] = br.ReadInt32();

            topindexes = new int[br.ReadInt32()];
            for (int i = 0; i < topindexes.Length; i++)
                topindexes[i] = br.ReadInt32();

            //TODO load matrices
        }
コード例 #3
0
ファイル: SkeletonExtended.cs プロジェクト: KatekovAnton/Game
 public SkeletonExtended(Skeleton s)
 {
     baseskelet = s;
 }
コード例 #4
0
ファイル: Skeleton.cs プロジェクト: KatekovAnton/Game
        public static Skeleton FromStream(BinaryReader stream)
        {
            var bones = new Bone[stream.ReadInt32()];
            var parentNames = new string[bones.Length];
            Bone root = null;

            for (int i = 0; i < bones.Length; i++)
            {
                bones[i] = new Bone();
                bones[i].index = i;
                bones[i].Name = stream.ReadPackString();
                parentNames[i] = stream.ReadPackString();
                if (parentNames[i] == "-\0")
                    root = bones[i];
            }

            if (root == null)
                throw new Exception("Root bone can not be null");

            var skeleton = new Skeleton();
            skeleton.Init(root, bones);
            for (int i = 0; i < bones.Length; i++)
            {
                bones[i].BaseMatrix = stream.ReadMatrix();
                if (bones[i] != root)
                    bones[i].Parent = bones[skeleton.IndexOf(parentNames[i])];
            }
            foreach (Bone b in bones)
            {
                List<Bone> chl = new List<Bone>();
                for (int i = 0; i < bones.Length; i++)
                    if (bones[i].Parent == b)
                        chl.Add(bones[i]);
                b.Childrens = chl.ToArray();
            }

            return skeleton;
        }