Exemple #1
0
        /// <summary>
        /// Prepares an object for inclusion in the scene graph
        /// If the template does not exist, it is created first
        /// </summary>
        /// <param name="m"></param>
        public void Spawn(MServerObject m)
        {
            MSceneObject mo = (MSceneObject)MScene.ModelRoot.FindModuleByInstanceID(m.InstanceID);

            if (mo != null)
            {
                return;       //if the object already exists, never mind
            }
            //check if the object template exists. All user objects must exist as a template first
            MSceneObject mt = (MSceneObject)MScene.TemplateRoot.FindModuleByName(m.TemplateID);

            if (mt == null)
            {
                LoadTemplate(m.TemplateID);
            }

            //if ((m.Name == Globals.UserAccount.UserID) && ( m.OwnerID == Globals.UserAccount.UserID)){
            mo = Helper.Spawn(m,
                              MassiveTools.VectorFromArray(m.Position),
                              MassiveTools.QuaternionFromArray(m.Rotation));
            if (mo == null)
            {
                Console.WriteLine("MSpawnHandler: Template not found:" + m.TemplateID);
            }
            else
            {
                mo.InstanceID = m.InstanceID;
                mo.SetRotation(MassiveTools.QuaternionFromArray(m.Rotation));

                //If the object spawning is our avatar
                if (mo.InstanceID == Globals.UserAccount.UserID)
                {
                    Globals.Avatar.SetSceneObject(mo);
                    MBuildingBlock bb = MBuildParts.GetBlock(mo.TemplateID);
                    MScene.Camera.CameraOffset = MassiveTools.VectorFromArray(bb.BoneOffset);
                    MMessageBus.AvatarChanged(this, Globals.UserAccount.UserID, mo.TemplateID);
                }

                SetMaterial(mo, m.TextureID);

                MMessageBus.Created(this, mo);
            }

            if (mo.OwnerID == Globals.UserAccount.UserID)
            {
                MMessageBus.Select(this, new SelectEvent(mo));
            }
        }
        private void But_Click(object sender, EventArgs e)
        {
            Button    b  = (Button)sender;
            MBookmark bm = (MBookmark)b.Tag;

            if (bm != null)
            {
                if (Globals.Network.Connected == true)
                {
                    MMessageBus.TeleportRequest(this,
                                                MassiveTools.VectorFromArray(bm.Position),
                                                MassiveTools.QuaternionFromArray(bm.Rotation));
                }
                else
                {
                    MScene.Camera.transform.Position    = MassiveTools.VectorFromArray(bm.Position);
                    Globals.UserAccount.CurrentPosition = bm.Position;
                    Globals.Avatar.SetPosition(MScene.Camera.transform.Position);
                    MMessageBus.AvatarMoved(this, Globals.UserAccount.UserID,
                                            MScene.Camera.transform.Position,
                                            MassiveTools.QuaternionFromArray(bm.Rotation));
                }
            }
        }