/// <summary> /// Position fingers on hand pose /// </summary> private IEnumerable <MInstruction> MakeHandPose(GameObject go, string side) { List <MInstruction> list = new List <MInstruction>(); if (side.Equals("Left")) { //Get UnitySceneAccess ID of hand //GameObject hand = go.transform.Find("LeftHand(Clone)").gameObject; GameObject hand = HandChecker.GetLeftHand(go); //The desired Hand pose (rotations of the finger Joints) UnityHandPose leftHandPose = hand.GetComponent <UnityHandPose>(); _handPoseIdManager.CurrentHandIdLeft = Guid.NewGuid().ToString(); //Create the instruction to move the fingers MInstruction moveFingersInstructionsLeft = new MInstruction(_handPoseIdManager.CurrentHandIdLeft, "Move Fingers", "Pose/MoveFingers") { Properties = new Dictionary <string, string>() { { "Release", "false" }, { "Hand", "Left" } }, Constraints = new List <MConstraint>() }; //Add properties to the instruction var constraintID = Guid.NewGuid().ToString(); moveFingersInstructionsLeft.Properties.Add("HandPose", constraintID); moveFingersInstructionsLeft.Constraints.Add(new MConstraint() { ID = constraintID, PostureConstraint = leftHandPose.GetPostureConstraint() }); list.Add(moveFingersInstructionsLeft); } if (side.Equals("Right")) { //Get UnitySceneAccess ID of hand //GameObject hand = go.transform.Find("RightHand(Clone)").gameObject; GameObject hand = HandChecker.GetRightHand(go); //String objectID = hand.GetComponent<MMISceneObject>().MSceneObject.ID; //The desired Hand pose (rotations of the finger Joints) UnityHandPose leftHandPose = hand.GetComponent <UnityHandPose>(); _handPoseIdManager.CurrentHandIdRight = Guid.NewGuid().ToString(); //Create the instruction to move the fingers MInstruction moveFingersInstructionsRight = new MInstruction(_handPoseIdManager.CurrentHandIdRight, "Move Fingers", "Pose/MoveFingers") { Properties = new Dictionary <string, string>() { { "Release", "false" }, { "Hand", "Right" } }, Constraints = new List <MConstraint>() }; //Add properties to the instruction var constraintID = Guid.NewGuid().ToString(); moveFingersInstructionsRight.Properties.Add("HandPose", constraintID); moveFingersInstructionsRight.Constraints.Add(new MConstraint() { ID = constraintID, PostureConstraint = leftHandPose.GetPostureConstraint() }); list.Add(moveFingersInstructionsRight); } return(list); }
// Update is called once per frame void Update() { if (Execute && !lastState) { //Pickup the object MSimulationState state = new MSimulationState(this.avatar.GetPosture(), this.avatar.GetPosture()); MInstruction idleInstruction = new MInstruction(MInstructionFactory.GenerateID(), "idle: " + ObjectToTurn.name, "idle"); MInstruction reachInstruction = new MInstruction(MInstructionFactory.GenerateID(), "Reach: " + ObjectToTurn.name, "Pose/Reach") { Properties = new Dictionary <string, string>() { { "Hand", "Right" }, { "TargetID", GraspTarget.MSceneObject.ID } } }; if (this.HandPose != null) { MInstruction moveFingersInstruction = new MInstruction(System.Guid.NewGuid().ToString(), "Move fingers", "Pose/MoveFingers") { Properties = new Dictionary <string, string>() { { "Hand", this.HandPose.HandType.ToString() } }, Constraints = new List <MConstraint>(), StartCondition = reachInstruction.ID + ":" + mmiConstants.MSimulationEvent_End }; if (HandPose != null) { string constraintID = Guid.NewGuid().ToString(); moveFingersInstruction.Properties.Add("HandPose", constraintID); moveFingersInstruction.Constraints.Add(new MConstraint() { ID = constraintID, PostureConstraint = HandPose.GetPostureConstraint() }); } this.avatar.CoSimulator.AssignInstruction(moveFingersInstruction, state); } MInstruction turnObjectInstruction = new MInstruction(Guid.NewGuid().ToString(), "turn: " + ObjectToTurn.name, "Object/Turn") { Properties = new Dictionary <string, string>() { { "SubjectID", ObjectToTurn.MSceneObject.ID }, { "Axis", this.TurnAxis.MSceneObject.ID }, { "Repetitions", this.Repetitions.ToString() }, { "Angle", this.Angle.ToString(System.Globalization.CultureInfo.InvariantCulture) }, { "Hand", Hand.ToString() } }, Constraints = new List <MConstraint>(), StartCondition = reachInstruction.ID + ":" + mmiConstants.MSimulationEvent_End }; InstructionValidation validator = new InstructionValidation(); MBoolResponse res = validator.Validate(turnObjectInstruction, this.avatar.MMUAccess.GetLoadableMMUs()); if (!res.Successful) { foreach (string s in res.LogData) { Debug.LogError(s); } } this.avatar.CoSimulator.AssignInstruction(idleInstruction, state); this.avatar.CoSimulator.AssignInstruction(reachInstruction, state); this.avatar.CoSimulator.AssignInstruction(turnObjectInstruction, state); } if (!Execute && lastState) { //Terminate this.avatar.CoSimulator.Abort(); } lastState = Execute; }