private void importSkeletonJoints(Skeleton skeleton, ASFJoint asfJoint, Joint joint)
        {
            joint.CalculateAbsoluteMatrix();
            for (int i = 0; i < asfJoint.children.Count; i++)
            {
                var asfChild = asfJoint.children[i];
                var child    = new Joint();
                child.Parent = joint;
                child.Name   = asfChild.name;
                child.Length = asfChild.length;

                //get rotation component inherited from the parent rotation
                child.CalculateInitialRelativeMatrix(Matrix.Identity);
                child.CalculateAbsoluteMatrix();
                var trans       = Vector3.TransformCoordinate(Vector3.Zero, child.AbsoluteMatrix);
                var rotationMat = child.AbsoluteMatrix * Matrix.Translation(-trans);

                child.CalculateInitialRelativeMatrix(XnaMathExtensions.CreateRotationMatrixMapDirection(Vector3.UnitX.xna(), asfChild.direction.xna()).dx() * Matrix.Invert(rotationMat));
                //Undo rotation of parent
                //child.RelativeMatrix = XnaMathExtensions.CreateRotationMatrixMapDirection(Vector3.UnitX, asfChild.direction) * Matrix.CreateTranslation(trans) * Matrix.Invert(child.AbsoluteMatrix);
                //child.RelativeMatrix = Matrix.Invert(rotationMat) * XnaMathExtensions.CreateRotationMatrixMapDirection(Vector3.UnitX, asfChild.direction);


                skeleton.Joints.Add(child);
                importSkeletonJoints(skeleton, asfChild, child);
            }
        }
        private bool parseCommand()
        {
            if (!line.Line.StartsWith(":"))
            {
                return(false);
            }

            ParseCommandDelegate newCmd = null;

            if (line == ":bonedata")
            {
                newCmd = parseCommandBonedata;
            }
            if (line == ":hierarchy")
            {
                newCmd = parseCommandHierarchy;
            }
            if (line == ":root")
            {
                var j = new ASFJoint();
                j.name = "root";
                Joints.Add(j);
                RootJoint = j;
            }

            if (newCmd != null)
            {
                popCommand();
                pushCommand(newCmd);
            }

            return(true);
        }
Beispiel #3
0
        public Matrix CalculateRelativeMatrix(AMCSegment seg, ASFJoint asfJoint)
        {
            if (asfJoint.name == "root")
            {
                //use root orientation here? prob not
                Matrix c = Matrix.Identity;
                c =
                    Matrix.RotationX(MathHelper.ToRadians(seg.Data[3])) *
                    Matrix.RotationY(MathHelper.ToRadians(seg.Data[4])) * Matrix.RotationZ(MathHelper.ToRadians(seg.Data[5]));

                //use root position here? prob not
                Matrix b = Matrix.Translation(seg.Data[0], seg.Data[1], seg.Data[2]);
                Matrix m = Matrix.Identity;

                m = Matrix.Identity;

                Matrix l = Matrix.Invert(c) * m * c * b;

                return(l);
            }
            else
            {
                //WARNING: not using the given order asfJoint.axisOrder
                Matrix c = Matrix.RotationX(MathHelper.ToRadians(asfJoint.axis.X))
                           * Matrix.RotationY(MathHelper.ToRadians(asfJoint.axis.Y))
                           * Matrix.RotationZ(MathHelper.ToRadians(asfJoint.axis.Z));

                Matrix b = Matrix.Translation(asfJoint.parent.direction * asfJoint.parent.length);
                Matrix m = Matrix.Identity;

                for (int i = 0; i < asfJoint.dof.Length; i++)
                {
                    switch (asfJoint.dof[i])
                    {
                    case "rx":
                        m = m * Matrix.RotationX(MathHelper.ToRadians(seg.Data[i]));
                        break;

                    case "ry":
                        m = m * Matrix.RotationY(MathHelper.ToRadians(seg.Data[i]));
                        break;

                    case "rz":
                        m = m * Matrix.RotationZ(MathHelper.ToRadians(seg.Data[i]));
                        break;
                    }
                }

                Matrix l = Matrix.Invert(c) * m * c * b;
                return(l);
            }
        }
 private bool parseCommandBonedata()
 {
     if (line == "begin")
     {
         currentJoint = new ASFJoint();
         pushCommand(parseCommandJoint);
         return(true);
     }
     if (line == "end")
     {
         Joints.Add(currentJoint);
         popCommand();
         return(true);
     }
     return(false);
 }