Exemple #1
0
    void LateUpdate()
    {
        if (Execute && !lastState && GazeTarget != null)
        {
            MInstruction instruction = new MInstruction(System.Guid.NewGuid().ToString(), "gaze", "Pose/Gaze")
            {
                Properties = new Dictionary <string, string>()
                {
                    { "TargetID", this.GazeTarget.MSceneObject.ID }
                }
            };

            this.lastInstructionID = instruction.ID;

            MMIAvatar avatar = this.GetComponent <MMIAvatar>();

            //Add the motion type to the cosim
            avatar.CoSimulator.SetPriority("Pose/Gaze", 10);

            avatar.CoSimulator.AssignInstruction(instruction, new MSimulationState(avatar.GetPosture(), avatar.GetPosture()));
        }

        if (!Execute && lastState)
        {
            this.avatar.CoSimulator.Abort(lastInstructionID);
        }

        lastState = Execute;
    }
Exemple #2
0
    private void OnGUI()
    {
        if (GUI.Button(new Rect(300, 200, 200, 100), "Grasp object (trajectory)"))
        {
            MPathConstraint pathConstraint = new MPathConstraint()
            {
                PolygonPoints = new List <MGeometryConstraint>()
            };

            foreach (Transform transform in this.TrajectoryPoints)
            {
                MVector3 position      = transform.position.ToMVector3();
                MVector3 rotationEuler = transform.rotation.eulerAngles.ToMVector3();


                pathConstraint.PolygonPoints.Add(new MGeometryConstraint("")
                {
                    TranslationConstraint = new MTranslationConstraint()
                    {
                        Type   = MTranslationConstraintType.BOX,
                        Limits = position.ToMInterval3(this.TranslationTolerance)
                    },
                    RotationConstraint = new MRotationConstraint()
                    {
                        Limits = rotationEuler.ToMInterval3(this.RotationTolerance)
                    }
                });
            }

            MConstraint moveConstraint = new MConstraint(System.Guid.NewGuid().ToString())
            {
                PathConstraint = pathConstraint
            };

            MInstruction idleInstruction = new MInstruction(MInstructionFactory.GenerateID(), "Idle", "idle");

            MInstruction reachRight = new MInstruction(MInstructionFactory.GenerateID(), "reach right", "Pose/Reach")
            {
                Properties = PropertiesCreator.Create("TargetID", UnitySceneAccess.Instance["GraspTargetR"].ID, "Hand", "Right", "MinDistance", 2.0.ToString()),
            };

            MInstruction moveRight = new MInstruction(MInstructionFactory.GenerateID(), "move right", "Object/Move")
            {
                Properties = new Dictionary <string, string>()
                {
                    { "SubjectID", this.GetComponent <MMISceneObject>().MSceneObject.ID },
                    { "Hand", "Right" },
                    { "MinDistance", 2.0.ToString() },
                    { "trajectory", moveConstraint.ID }
                },
                StartCondition = reachRight.ID + ":" + mmiConstants.MSimulationEvent_End,
                Constraints    = new List <MConstraint>()
                {
                    moveConstraint
                }
            };

            MMIAvatar avatar = GameObject.FindObjectOfType <MMIAvatar>();

            //this.CoSimulator.Abort();
            avatar.CoSimulator.AssignInstruction(idleInstruction, new MSimulationState()
            {
                Initial = avatar.GetPosture(), Current = avatar.GetPosture()
            });
            avatar.CoSimulator.AssignInstruction(reachRight, new MSimulationState()
            {
                Initial = avatar.GetPosture(), Current = avatar.GetPosture()
            });
            avatar.CoSimulator.AssignInstruction(moveRight, new MSimulationState()
            {
                Initial = avatar.GetPosture(), Current = avatar.GetPosture()
            });
        }
    }
Exemple #3
0
    // Update is called once per frame
    void Update()
    {
        if (Execute && !lastState)
        {
            if (LeftHandPose != null)
            {
                //Create the instruction to move the fingers
                MInstruction moveFingersInstructions = new MInstruction(System.Guid.NewGuid().ToString(), "Move fingers", "Pose/MoveFingers")
                {
                    Properties = new Dictionary <string, string>()
                    {
                        { "Release", this.Release.ToString() },
                        { "Hand", "Left" }
                    },

                    Constraints = new List <MConstraint>()
                };

                string constraintID = System.Guid.NewGuid().ToString();
                moveFingersInstructions.Properties.Add("HandPose", constraintID);
                moveFingersInstructions.Constraints.Add(new MConstraint()
                {
                    ID = constraintID,
                    PostureConstraint = this.LeftHandPose.GetPostureConstraint()
                });

                this.avatar.CoSimulator.AssignInstruction(moveFingersInstructions, new MSimulationState(avatar.GetPosture(), avatar.GetPosture()));
            }

            if (this.RightHandPose != null)
            {
                //Create the instruction to move the fingers
                MInstruction moveFingersInstructions = new MInstruction(System.Guid.NewGuid().ToString(), "Move fingers", "Pose/MoveFingers")
                {
                    Properties = new Dictionary <string, string>()
                    {
                        { "Release", this.Release.ToString() },
                        { "Hand", "Right" }
                    },

                    Constraints = new List <MConstraint>()
                };

                string constraintID = System.Guid.NewGuid().ToString();
                moveFingersInstructions.Properties.Add("HandPose", constraintID);
                moveFingersInstructions.Constraints.Add(new MConstraint()
                {
                    ID = constraintID,
                    PostureConstraint = this.RightHandPose.GetPostureConstraint()
                });

                this.avatar.CoSimulator.AssignInstruction(moveFingersInstructions, new MSimulationState(avatar.GetPosture(), avatar.GetPosture()));
            }
        }

        if (!Execute && lastState)
        {
            //Terminate
            this.avatar.CoSimulator.Abort(this.lastInstructionID);
        }

        lastState = Execute;
    }