public ISVisualizationJoint(MMICSharp.Common.RJoint jBase, Transform RootBone, Dictionary <MJointType, string> bonenameMap) { if (bonenameMap.ContainsKey(jBase.GetMJoint().Type)) { string name = bonenameMap[jBase.GetMJoint().Type]; this.reference = RootBone.GetChildRecursiveByName(name); } else { this.reference = null; } /* * if (bonemap.ContainsKey(jBase.GetMJoint().ID)) * { * this.referenceBone = bonemap[jBase.GetMJoint().ID]; * } * else * { * //Debug.LogWarning("Retargeting: there is a bone without a reference: " + jBase.GetMJoint().ID); * this.referenceBone = HumanBodyBones.LastBone; * }*/ //this.anim = anim; this.j = jBase; for (int i = 0; i < jBase.children.Count; i++) { MMICSharp.Common.RJoint child = (RJoint)jBase.children[i]; ISVisualizationJoint retjoint = new ISVisualizationJoint(child, RootBone, bonenameMap); retjoint.parent = this; this.children.Add(retjoint); } }
/// <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); }
/// <summary> /// Returns partial MAvatarPostureValues for the defined joint list of the lastPostureValues. /// </summary> /// <param name="avatarID"></param> /// <param name="joints"></param> /// <returns></returns> public MAvatarPostureValues GetCurrentPostureValuesPartial(string avatarID, List <MJointType> joints) { RJoint root = this.hierarchies[avatarID]; List <double> postureValues = root.GetAvatarPostureValuesPartial(joints); MAvatarPostureValues values = new MAvatarPostureValues(avatarID, postureValues); return(values); }
/// <summary> /// Returns the current posture values for the avatar by recomputing the values based on the internal hierarchy. /// </summary> /// <param name="avatarID"></param> /// <returns></returns> public MAvatarPostureValues GetCurrentPostureValues(string avatarID) { RJoint root = this.hierarchies[avatarID]; List <double> postureValues = root.GetAvatarPostureValues(); MAvatarPostureValues values = new MAvatarPostureValues(avatarID, postureValues); return(values); //return this.lastPostureValues[avatarID]; }
public void SetBaseReference(MAvatarPosture posture) { foreach (MJoint j in posture.Joints) { if (j.Type != MJointType.Undefined) { RJoint rj = (RJoint)this.GetChild(j.Type); rj.SetBaseReference(j.Rotation, j.Position); } } }
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); }
/// <summary> /// Initializes the anthropometry from a given description. /// Has to be performed prior to all other interactions with the /// intermediate skeleton (e.g. query for joint positions, etc.). /// </summary> /// <param name="description"></param> public void InitializeAnthropometry(MAvatarDescription description) { this.avatarDescriptions[description.AvatarID] = description; //update joint offsets this.hierarchies[description.AvatarID] = RJoint.Initialize(description.ZeroPosture.Joints); List <double> zero_rotations = new List <double>(); this.hierarchies[description.AvatarID].CreateZeroVector(zero_rotations); MAvatarPostureValues values = new MAvatarPostureValues(description.AvatarID, zero_rotations); this.lastPostureValues[description.AvatarID] = values; List <MJointType> animatedJoints = new List <MJointType>(); foreach (MJoint j in description.ZeroPosture.Joints) { animatedJoints.Add(j.Type); } this.SetAnimatedJoints(description.AvatarID, animatedJoints); }
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); }