Ejemplo n.º 1
0
        private void MMessageBus_ChangeAvatarRequestHandler(object sender, ChangeAvatarEvent e)
        {
            MBuildingBlock bb = MBuildParts.GetBlock(e.TemplateID);

            if (bb == null)
            {
                Console.WriteLine("MSpawnHandler: Missing Template:" + e.TemplateID);
                return;
            }

            MSceneObject mo = (MSceneObject)MScene.ModelRoot.FindModuleByInstanceID(e.UserID);

            if (mo != null)
            {
                MMessageBus.DeleteRequest(this, mo);
            }

            MServerObject m = new MServerObject();

            m.InstanceID = e.UserID;
            m.TemplateID = e.TemplateID;
            m.OwnerID    = e.UserID;
            m.TextureID  = bb.MaterialID;
            m.Name       = Globals.UserAccount.UserName;
            MScene.Camera.CameraOffset = MassiveTools.VectorFromArray(bb.BoneOffset);
            m.Position = Globals.UserAccount.CurrentPosition;
            m.Rotation = MassiveTools.ArrayFromQuaterniond(Globals.Avatar.GetRotation());
            Spawn(m);
        }
Ejemplo n.º 2
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));
            }
        }
Ejemplo n.º 3
0
        public static MSceneObject LoadTemplate(string TemplateID)
        {
            MBuildingBlock bb = MBuildParts.GetBlock(TemplateID);

            if (bb == null)
            {
                Console.WriteLine("WARNING: MSpawnHandler.LoadTemplate " + TemplateID + " not found in blocks");
                return(null);
            }

            MSceneObject o = null;

            if (bb.Type == MBuildParts.MAnimatedModel)
            {
                o = Helper.CreateAnimatedModel(MScene.TemplateRoot, TemplateID, bb.Model, Vector3d.Zero);
                MAnimatedModel man = (MAnimatedModel)o;
                man.BoneOffset = MassiveTools.VectorFromArray(bb.BoneOffset);
            }

            if (bb.Type == MBuildParts.MModel)
            {
                o = Helper.CreateModel(MScene.TemplateRoot, TemplateID, bb.Model, Vector3d.Zero);
            }

            MMaterial mat = (MMaterial)MScene.MaterialRoot.FindModuleByName(bb.MaterialID);

            if (mat == null)
            {
                Console.WriteLine("MSpawnHandler.LoadTemplate " + bb.MaterialID + " was null");
            }
            o.SetMaterial(mat);

            Vector3d size = MassiveTools.VectorFromArray(bb.Size);

            MPhysicsObject.EShape shape = GetShape(bb.PhysicsShape);
            if (shape != MPhysicsObject.EShape.NULL)
            {
                MPhysicsObject mpo = new MPhysicsObject(o, TemplateID + "_physics", bb.Weight, shape,
                                                        true, size);
                mpo.SetSleep(5);
                mpo.SetFriction(0.5);
                if (shape != MPhysicsObject.EShape.Sphere)
                {
                    mpo.SetAngularFactor(0.0, 0.0, 0.0);
                    mpo.SetDamping(0.5, 0.5);
                    mpo.SetRestitution(0.5);
                }
                else
                {
                    mpo.SetDamping(0.1, 0.1);
                    mpo.SetRestitution(0.8);
                }
            }

            o.TemplateID               = TemplateID;
            o.InstanceID               = TemplateID;
            o.IsTransparent            = bb.IsTransparent;
            o.transform.RotationOffset = Quaterniond.FromEulerAngles(MassiveTools.VectorFromArray(bb.RotationOffset));
            o.Setup();

            AddSubmodules(bb, o);

            return(o);
        }