Esempio n. 1
0
        /// <summary>
        /// Retargets the global posture to the intermediate skeleton
        /// </summary>
        /// <param name="globalTarget"></param>
        /// <returns></returns>
        public MAvatarPostureValues RetargetToIntermediate(MAvatarPosture globalTarget)
        {
            RJoint root      = ((RJoint)this.skeleton.GetRoot(globalTarget.AvatarID));
            bool   rootFound = false;

            foreach (MJoint j in globalTarget.Joints)
            {
                if (j.Type != MJointType.Undefined)
                {
                    RJoint rj = ((RJoint)root.GetChild(j.Type));
                    rj.RetargetPositionToIS(j.Position, j.Rotation);
                    rj.RetargetRotationToIS(j.Rotation);

                    if (!rootFound)
                    {
                        rootFound = true;
                        if (j.Type == MJointType.Root)
                        {
                        }
                        else
                        {
                            MVector3 globalPos = rj.GetGlobalPosManually();
                            root.SetGlobalPosManually(new MVector3(globalPos.X, 0, globalPos.Z));
                            //rj.SetGlobalPosManually(new MVector3(0, globalPos.Y, 0));
                        }
                    }
                }
            }

            root.RecomputeLocalTransformations();
            MAvatarPostureValues ret = new MAvatarPostureValues(globalTarget.AvatarID, root.GetAvatarPostureValues());

            return(ret);
        }
Esempio n. 2
0
        public new static RJoint Initialize(List <MJoint> joints)
        {
            RJoint root = new RJoint(joints[0]);

            for (int i = 1; i < joints.Count; i++)
            {
                RJoint parent = (RJoint)root.GetChild(joints[i].Parent);
                RJoint j      = new RJoint(joints[i]);
                if (parent != null)
                {
                    parent.children.Add(j);
                }
                j.parentJoint = parent;
            }

            // initialize zero posture
            root.SetAvatarPostureValues(null);
            return(root);
        }
Esempio n. 3
0
        public MAvatarPosture RetargetToTarget(MAvatarPostureValues intermediatePostureValues)
        {
            string id   = intermediatePostureValues.AvatarID;
            RJoint root = ((RJoint)this.skeleton.GetRoot(id));

            root.SetAvatarPostureValues(intermediatePostureValues);

            MAvatarPosture targetOut = new MAvatarPosture();

            targetOut.AvatarID = id;
            targetOut.Joints   = new List <MJoint>();
            foreach (MJoint j in this.basePostures[id].Joints)
            {
                MJoint outJ = new MJoint();
                outJ.ID     = j.ID;
                outJ.Type   = j.Type;
                outJ.Parent = j.Parent;
                if (outJ.Type != MJointType.Undefined)
                {
                    RJoint rj = (RJoint)root.GetChild(j.Type);
                    outJ.Position = (rj).RetargetPositionToTarget();
                    outJ.Rotation = (rj).RetargetRotationToTarget();
                }
                else
                {
                    outJ.Position = j.Position;
                    outJ.Rotation = j.Rotation;
                }
                targetOut.Joints.Add(outJ);
            }
            Dictionary <string, string> _children = this.children[id];

            for (int i = 0; i < targetOut.Joints.Count; i++)
            {
                MJoint outJ = targetOut.Joints[i];
                if (outJ.Type == MJointType.Undefined)
                {
                    bool setRot = false;
                    bool setPos = false;
                    Console.WriteLine("no jointtype " + outJ.ID);
                    if (i == 0)
                    {
                        // find first joint that is mapped
                        foreach (MJoint j in targetOut.Joints)
                        {
                            if (j.Type != MJointType.Undefined)
                            {
                                outJ.Position = new MVector3(j.Position.X, 0, j.Position.Z);
                                //j.Position.X = 0;
                                //j.Position.Z = 0;

                                MVector3 forward = outJ.Rotation.Multiply(new MVector3(0, 0, 1));
                                forward.Y = 0;
                                forward.Normalize();
                                MVector3    currentForward = j.Rotation.Multiply(new MVector3(0, 0, 1));
                                MQuaternion drot           = MVector3Extensions.FromToRotation(currentForward, forward);
                                outJ.Rotation = drot.Multiply(j.Rotation);
                                //outJ.Rotation = MQuaternionExtensions.Inverse(drot).Multiply(outJ.Rotation);

                                setPos = true;
                                setRot = true;
                                break;
                            }
                        }
                    }
                    else
                    {
                        /*
                         * This is disabled for now, as it was not working propperly.
                         *
                         * if(_children.ContainsKey(outJ.ID) && _children[outJ.ID] != "")
                         * {
                         *  for(int jID = i+1; jID < targetOut.Joints.Count; jID ++)
                         *  {
                         *      MJoint j = targetOut.Joints[jID];
                         *      if (j.ID == _children[outJ.ID])
                         *      {
                         *
                         *          MVector3 srcDir = new MVector3(0, 1, 0);//outJ.Rotation.Multiply(new MVector3(0, 1, 0)).Normalize
                         *          MVector3 trgDir = null;
                         *          MQuaternion parentRot = null;
                         *          if(outJ.Parent != null)
                         *          {
                         *              for(int pID = i-1; pID > 0; pID--)
                         *              {
                         *                  if(targetOut.Joints[pID].ID == outJ.Parent)
                         *                  {
                         *                      if(targetOut.Joints[pID].Type != MJointType.Undefined)
                         *                      {
                         *                          parentRot = targetOut.Joints[pID].Rotation;
                         *                          trgDir = MQuaternionExtensions.Inverse(parentRot).Multiply(j.Position.Subtract(outJ.Position).Normalize());
                         *                      }
                         *                  }
                         *              }
                         *          }
                         *          if(trgDir != null)
                         *          {
                         *              MQuaternion rot = MVector3Extensions.FromToRotation(srcDir, trgDir);
                         *              outJ.Rotation = parentRot.Multiply(rot);
                         *              outJ.Position = null;
                         *              setRot = true;
                         *              break;
                         *
                         *          }
                         *
                         *
                         *      }
                         *  }
                         * }*/
                    }
                    if (!setRot)
                    {
                        outJ.Rotation = null;
                    }
                    if (!setPos)
                    {
                        outJ.Position = null;
                    }
                }
            }
            return(targetOut);
        }