Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="skeleton"></param>
        /// <returns></returns>
        public JPSkeleton ReadSkeleton(Skeleton skeleton)
        {
            rigidIndices         = skeleton.GetRigidIndices();
            smoothIndices        = skeleton.GetSmoothIndices();
            boneList             = skeleton.MatrixToBoneList;
            inverseModelMatrices = skeleton.InverseModelMatrices;
            flagsRotation        = skeleton.FlagsRotation;
            flagsScaling         = skeleton.FlagsScaling;

            this.bones.Clear();
            short count = 0;

            foreach (Bone bone in skeleton.Bones.Values)
            {
                JPBone jpBone = new JPBone(this, count++);
                jpBone = jpBone.ReadBone(bone);
                this.bones.Add(jpBone);
            }

            this.Reset();
            return(this);
        }
Exemplo n.º 2
0
        public void Update(bool reset = false)
        {
            updated = true;
            List <JPBone> bonesToProcess = new List <JPBone>();

            // Add root bone
            foreach (JPBone bone in bones)
            {
                if (bone.parentIndex == -1)
                {
                    bonesToProcess.Add(bone);
                }
            }

            // some special processing for the root bones before we start
            foreach (JPBone rootBone in bonesToProcess)
            {
                rootBone.Transform = OpenTK.Matrix4.CreateScale(rootBone.sca) * OpenTK.Matrix4.CreateFromQuaternion(rootBone.rot) * OpenTK.Matrix4.CreateTranslation(rootBone.pos);

                // scale down the model in its entirety only when mid-animation (i.e. reset == false)
                // Maybe not relevant?
                if (!reset)
                {
                    rootBone.Transform *= OpenTK.Matrix4.CreateScale(1);
                }
            }

            int numRootNodes = bonesToProcess.Count;

            for (int i = 0; i < numRootNodes; i++)
            {
                bonesToProcess.AddRange(bonesToProcess[0].GetChildren());
                bonesToProcess.RemoveAt(0);
            }
            while (bonesToProcess.Count > 0)
            {
                // BFS
                JPBone bone = bonesToProcess[0];
                bonesToProcess.RemoveAt(0);
                bonesToProcess.AddRange(bone.GetChildren());

                bone.Transform = OpenTK.Matrix4.CreateScale(bone.sca) * OpenTK.Matrix4.CreateFromQuaternion(bone.rot) * OpenTK.Matrix4.CreateTranslation(bone.pos);
                if (bone.parentIndex != -1)
                {
                    if (bone.UseSegmentScaleCompensate && bones[bone.parentIndex] != null &&
                        bones[bone.parentIndex] is JPBone)
                    {
                        bone.Transform *= OpenTK.Matrix4.CreateScale(
                            1f / bones[bone.parentIndex].sca.X,
                            1f / bones[bone.parentIndex].sca.Y,
                            1f / bones[bone.parentIndex].sca.Z);

                        bone.Transform *= bones[bone.parentIndex].Transform;
                    }
                    else
                    {
                        bone.Transform = bone.Transform * bones[bone.parentIndex].Transform;
                    }
                }
            }
        }