Exemplo n.º 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));
            }
        }