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); }
/// <summary> /// Submodules offer extra functionality for e.g. user interaction, linking click handlers to widgets /// We don't want to copy their instance, because each has unique values, e.g. door state. /// </summary> /// <param name="bb"></param> /// <param name="o"></param> static void AddSubmodules(MBuildingBlock bb, MSceneObject o) { if (bb.SubModule == "MDoor") { MDoor door = new MDoor(o); o.Add(door); } if (bb.SubModule == "MLinker") { MLinker link = new MLinker(); o.Add(link); MClickHandler mc = new MClickHandler(); mc.DoubleClicked = MLinkerWidget.Mc_DoubleClick; mc.RightClicked = MLinkerWidget.Mc_RightClick; o.Add(mc); o.Tag = "LINKER01|URL:"; } if (bb.SubModule == "MTeleporter") { MClickHandler mc = new MClickHandler(); mc.DoubleClicked = MTeleporterWidget.Mc_DoubleClick; mc.RightClicked = MTeleporterWidget.Mc_RightClick; o.Add(mc); o.Tag = "TELEPORTER01|XYZ:"; } if (bb.SubModule == "MPicture") { MClickHandler mc = new MClickHandler(); mc.DoubleClicked = MPictureWidget.Mc_DoubleClick; mc.RightClicked = MPictureWidget.Mc_RightClick; o.Add(mc); o.Tag = "PICTURE01|This Picture|Description"; } if (bb.SubModule == "MStatus") { MClickHandler mc = new MClickHandler(); mc.DoubleClicked = MStatusWidget.Mc_DoubleClick; mc.RightClicked = MStatusWidget.Mc_RightClick; o.Add(mc); o.Tag = "STATUS01|This Status|Description"; } if (bb.SubModule == "MNPC") { MNPC npc = new MNPC(o, "NPC"); o.Add(npc); } }
private void PartsView_MouseDoubleClick(object sender, MouseEventArgs e) { if (PartsView.SelectedItems.Count > 0) { ListViewItem lvi = PartsView.SelectedItems[0]; MBuildingBlock mb = (MBuildingBlock)lvi.Tag; if (mb != null) { Add(mb); } } }
/// <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)); } }
void Add(MBuildingBlock bb) { LastBuild = bb; if (MStateMachine.ZoneLocked == true) { MMessageBus.Error(this, "Can't build here, zone is locked / other building nearby"); return; } Vector3d pos = Globals.Avatar.GetPosition(); if (bb.TemplateID.Equals(MBuildParts.FOUNDATION01)) { pos += Globals.Avatar.Forward() * 13 - Globals.Avatar.Up() * 1.0; } else { pos += Globals.Avatar.Forward() * 4 + Globals.Avatar.Up() * 3.0; } Quaterniond rot = Globals.LocalUpRotation(); if (SelectedItem != null) { rot = SelectedItem.transform.Rotation; //prevent smaller items getting lost in the foundation if (SelectedItem.TemplateID != MBuildParts.FOUNDATION01) { //pos = SelectedItem.transform.Position; } } if (Globals.Network.Connected == true) { Globals.Network.SpawnRequest(bb.TemplateID, "TEXTURE01", bb.TemplateID, bb.TemplateID, pos, rot); } else { MServerObject mso = new MServerObject(); mso.InstanceID = Helper.GUID(); mso.OwnerID = Globals.UserAccount.UserID; mso.TextureID = bb.TextureID; mso.TemplateID = bb.TemplateID; mso.Position = MassiveTools.ArrayFromVector(pos); mso.Rotation = MassiveTools.ArrayFromQuaterniond(rot); MMessageBus.CreateObjectRequest(this, mso); } }
void CreateButtons() { Dictionary <string, MBuildingBlock> blocks = MBuildParts.GetBlocks(); foreach (KeyValuePair <string, MBuildingBlock> k in blocks) { MBuildingBlock bb = k.Value; if (bb.Type != MBuildingBlock.MATERIAL_TYPE) { continue; } string sPath = Path.Combine(MFileSystem.AssetsPath, bb.Path); Bitmap bmp = new Bitmap(Path.GetFullPath(sPath)); ListViewItem lvi = new ListViewItem(bb.Name); imageList1.Images.Add(bb.TextureID, bmp); lvi.ImageKey = bb.TextureID; lvi.Tag = bb.TextureID; TextureView.Items.Add(lvi); } }
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); }