コード例 #1
0
        /// <summary>
        /// Method to setup the simulation controller
        /// </summary>
        public virtual void Setup()
        {
            //Manually update the phsyics
            Physics.autoSimulation = false;

            //Specify the target frame rate
            Application.targetFrameRate = 90;

            //Creates a new session ID
            if (this.AutoCreateSessionID)
            {
                //Create a new session id
                this.SessionId = UnitySceneAccess.CreateUUID();
            }

            //Get all avatars
            this.Avatars = this.GetComponentsInChildren <MMIAvatar>().ToList();


            MMISettings settings = this.GetComponent <MMISettings>();

            //Setup the avatars
            foreach (MMIAvatar avatar in this.Avatars)
            {
                //Setup the avatar
                avatar.Setup(settings.MMIRegisterAddress, settings.MMIRegisterPort, this.SessionId);
            }

            //Wait and check if all connections are initialized
            this.StartCoroutine(CheckInitialization());
        }
コード例 #2
0
        // Use this for initialization
        protected virtual void Start()
        {
            //Manually update the phsyics
            Physics.autoSimulation = false;

            //Specify the target frame rate
            Application.targetFrameRate = 90;

            //Creates a new session ID
            if (this.AutoCreateSessionID)
            {
                //Create a new session id
                this.SessionId = UnitySceneAccess.CreateUUID();
            }

            //Get all avatars
            this.Avatars = this.GetComponentsInChildren <MMIAvatar>().ToList();

            //Setup the avatars
            foreach (MMIAvatar avatar in this.Avatars)
            {
                //Setup the avatar
                avatar.Setup(this.RegisterAddress, this.RegisterPort, this.SessionId);
            }

            //Wait and check if all connections are initialized
            this.StartCoroutine(CheckInitialization());

            //Create a timer
            this.timer = new Timer(TimerCallback, "finished", 0, (int)(this.FixedStepTime * 1000.0f));
        }
コード例 #3
0
        /// <summary>
        /// Basic awake routine
        /// </summary>
        protected virtual void Awake()
        {
            //Create a unique id for the scene object (only valid in the current session -> otherwise UUID required)
            string id = UnitySceneAccess.CreateSceneObjectID();


            //To check -> Is this informaton be required for every use case? Or should be remove it from here.
            Dictionary <string, string> _dict = new Dictionary <string, string>();

            if (Type == Types.Part)
            {
                _dict.Add("type", Type.ToString());
                if (InitialLocation != null)
                {
                    _dict.Add("initialLocation", InitialLocation.MSceneObject.ID);
                }
                if (FinalLocation != null)
                {
                    _dict.Add("finalLocation", FinalLocation.MSceneObject.ID);
                }
                if (IsLocatedAt != null)
                {
                    _dict.Add("isLocatedAt", InitialLocation.MSceneObject.ID);
                }
            }
            else if (Type == Types.Tool)
            {
                _dict.Add("type", Tool);
                if (InitialLocation != null)
                {
                    _dict.Add("initialLocation", InitialLocation.MSceneObject.ID);
                }
                if (FinalLocation != null)
                {
                    _dict.Add("finalLocation", FinalLocation.MSceneObject.ID);
                }
                if (IsLocatedAt != null)
                {
                    _dict.Add("isLocatedAt", InitialLocation.MSceneObject.ID);
                }
            }
            else
            {
                _dict.Add("type", Type.ToString());
            }

            //Create a new instance
            this.MSceneObject = new MSceneObject()
            {
                Name        = this.name,
                ID          = id,
                Properties  = _dict,
                Transform   = new MTransform(id, new MVector3(0, 0, 0), new MQuaternion(0, 0, 0, 1)),
                Constraints = this.Constraints
            };

            //Create a new transform tracker
            this.transformTracker = new TransformTracker(this.MSceneObject);
        }
コード例 #4
0
        /// <summary>
        /// Synchronizes the (internal) MSceneObject with the present data
        /// </summary>
        public virtual void Synchronize()
        {
            this.UpdateTransform(false);
            this.MSceneObject.Constraints = Constraints;

            //To do -> further actions in here
            UnitySceneAccess.SceneObjectChanged(this.MSceneObject);
        }
コード例 #5
0
ファイル: MMIAvatar.cs プロジェクト: dr-iskandar/MOSIM_Core
        /// <summary>
        /// Method to setup the actual retargeting
        /// </summary>
        protected virtual void SetupRetargeting()
        {
            //Only do the retargeting setup if not happened in before
            if (!setupRetargeting)
            {
                setupRetargeting = true;
                // find and load retargeting configuration file
                //Create a unique id for the avatar (only valid in the current session -> otherwise UUID required)
                string id = UnitySceneAccess.CreateAvatarID();

                //Only load the configuration if defined
                if (LoadRetargetingConfiguration)
                {
                    if (!System.IO.File.Exists(Application.dataPath + "/" + this.ConfigurationFilePath))
                    {
                        Debug.LogError($"Problem setting up retargeting: The required file: {Application.dataPath + "/" + this.ConfigurationFilePath} is not available");
                        return;
                    }

                    string skelConf = System.IO.File.ReadAllText(Application.dataPath + "/" + this.ConfigurationFilePath);



                    MAvatarPosture p = MMICSharp.Common.Communication.Serialization.FromJsonString <MAvatarPosture>(skelConf);//JsonConvert.DeserializeObject<MAvatarPosture>(skelConf);
                    p.AvatarID = id;

                    this.SetupRetargeting(id, p);
                    this.AssignPostureValues(retargetingService.RetargetToIntermediate(p));
                }

                //If not defined use the global posture
                else
                {
                    this.SetupRetargeting(id);
                }

                MAvatarDescription avatarDescription = this.GetSkeletonAccess().GetAvatarDescription(id);

                //Create a new MAvatar (the representation within MMI framework)
                MAvatarPostureValues zeroPosture = this.GetSkeletonAccess().GetCurrentPostureValues(id);

                //Create the avatar
                this.MAvatar = new MAvatar()
                {
                    Name          = this.name,
                    ID            = id,
                    Description   = avatarDescription,
                    PostureValues = zeroPosture,
                    Properties    = new Dictionary <string, string>(),
                    SceneObjects  = new List <string>()
                };

                //Add the avatar to the scene access
                UnitySceneAccess.AddAvatar(this.MAvatar);

                Debug.Log("Retargeting successfully set up");
            }
        }
コード例 #6
0
        /// <summary>
        /// Pushes the scene to each adapter/MMU
        /// Scene synchronization
        /// </summary>
        protected void PushScene()
        {
            //Synchronizes the scene in before each update
            //To do parallelize in future
            for (int i = 0; i < this.Avatars.Count; i++)
            {
                this.Avatars[i].MMUAccess.PushScene(false);
            }

            //Clear the events since the current events have been already synchronized
            UnitySceneAccess.ClearChanges();
        }
コード例 #7
0
ファイル: MMIAvatar.cs プロジェクト: dr-iskandar/MOSIM_Core
        /// <summary>
        /// Update routine which is called for each frame
        /// </summary>
        protected virtual void Update()
        {
            //Check if avatar instance is already created (should be the case)
            if (this.MAvatar != null)
            {
                //Get the posture values of the current posture
                this.MAvatar.PostureValues = this.GetPosture();

                //To do define a threshold to avoid unnecessary calls

                //Notify the scene concerning the update
                UnitySceneAccess.PostureValuesChanged(this.MAvatar, this.MAvatar.PostureValues);
            }
        }
コード例 #8
0
        /// <summary>
        /// Updates the transform of the corresponding MSceneObject
        /// </summary>
        public virtual void UpdateTransform(bool raiseEvent = true)
        {
            string parent = this.MSceneObject.Transform.Parent;

            //Set the transform to the current values
            this.MSceneObject.Transform.Position = this.transform.position.ToMVector3();
            this.MSceneObject.Transform.Rotation = this.transform.rotation.ToMQuaternion();
            this.MSceneObject.Transform.Parent   = parent;

            if (raiseEvent)
            {
                //only transmit the changed data
                UnitySceneAccess.TransformationChanged(this.MSceneObject, this.MSceneObject.Transform.Position, this.MSceneObject.Transform.Rotation, this.MSceneObject.Transform.Parent);
                this.transform.hasChanged = false;
            }
        }
コード例 #9
0
        // Update is called once per frame
        protected virtual void Update()
        {
            //Handle physics
            if (this.rigidBody != null && physicsEnabled)
            {
                this.rigidBody.detectCollisions = this.UpdatePhysicsCurrentFrame;
                this.rigidBody.isKinematic      = !this.UpdatePhysicsCurrentFrame;

                //Reset the value
                this.UpdatePhysicsCurrentFrame = true;
            }

            //Handle fixed velocity
            if (this.Velocity.magnitude > 0 && this.rigidBody != null)
            {
                if (this.rigidBody != null)
                {
                    this.rigidBody.velocity = this.Velocity;
                }
            }


            //Check the transformation changes
            if (this.transform.hasChanged && this.transformTracker.HasChanged(this.transform))
            {
                //Write the transform of the mscene object
                this.transformTracker.Update(transform);

                //Signalize transformation change
                UnitySceneAccess.TransformationChanged(this.MSceneObject, this.MSceneObject.Transform.Position, this.MSceneObject.Transform.Rotation, this.MSceneObject.Transform.Parent);
            }

            //Also track the changes in terms of physics
            if (this.rigidBody != null)
            {
                List <MPhysicsInteraction> physicsChanges = this.physicsTracker.GetChanges(this.rigidBody);

                //If some changes occur -> Update the phsysics properties and inform the UnitySceneAccess
                if (physicsChanges.Count > 0)
                {
                    this.physicsTracker.Update(this.rigidBody);
                    UnitySceneAccess.PhysicsPropertiesChanged(this.MSceneObject, this.MSceneObject.PhysicsProperties);
                }
            }
        }
コード例 #10
0
        // Use this for initialization
        protected virtual void Start()
        {
            //Setup the transforms of the MSceneObject
            this.SetupTransform();

            //Try to get the rigid body (if available)
            this.rigidBody = this.GetComponent <Rigidbody>();

            //Add the physics properties if rigid body is available
            if (this.rigidBody != null)
            {
                this.MSceneObject.PhysicsProperties = new MPhysicsProperties()
                {
                    Mass         = this.rigidBody.mass,
                    Inertia      = this.rigidBody.inertiaTensor.ToList(),
                    CenterOfMass = this.rigidBody.centerOfMass.ToList()
                };

                //Create a new physics tracker to monitor potential changes with regard to physics
                this.physicsTracker = new PhysicsTracker(this.MSceneObject);
            }

            //Setup the collider and write the result to MSceneObject
            if (!this.IgnoreCollision)
            {
                this.SetupCollider();
            }

            //Setup the mesh and write the result to MSceneObject
            if (this.TransferMesh)
            {
                this.SetupMesh();
            }

            //Add the scene object to the scene access
            UnitySceneAccess.AddSceneObject(this.MSceneObject);
        }
コード例 #11
0
 /// <summary>
 /// Basic constructor
 /// </summary>
 /// <param name="sceneAccess"></param>
 public RemoteSceneManipulationRequest(UnitySceneAccess sceneAccess)
 {
     this.sceneAccess = sceneAccess;
 }