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); }
private void MMessageBus_BookmardAddRequestEvent(object sender, BookmarkEvent e) { MBookmark b = new MBookmark(); b.Name = e.Name; b.Position = MassiveTools.ArrayFromVector(e.Position); b.Rotation = MassiveTools.ArrayFromQuaterniond(e.Rotation); Bookmarks.Add(b); Save(); MMessageBus.BookmarkAdded(this, e); }
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); } }
public void InitializePlanets() { //GravityIndicator = Helper.CreateCube(MScene.AstroRoot, "GravitySphere", Vector3d.Zero); //GravityIndicator.transform.Scale = new Vector3d(0.05, 0.1, 0.1); //GravityIndicator.OwnerID = "MasterAstronomer"; //MScene.AstroRoot.Add(GravityIndicator); //GravityIndicator.SetMaterial((MMaterial)MScene.MaterialRoot.FindModuleByName(MMaterial.DEFAULT_MATERIAL)); CreateShaders(); for (int i = 0; i < Bodies.Count; i++) { MAstroBody m = Bodies[i]; //m.Radius = m.Radius * 0.5; if (m.IsTemplate == true) { continue; } m.ListIndex = i; Vector3d pos = m.Position + new Vector3d(-m.Radius.X, 0, 0) * (m.HasRings == true ? 3.0 : 1.1); MServerZone zone = new MServerZone("MASTER_ASTRONOMER", m.Name, "Astronomical", MassiveTools.ToVector3_Server(pos)); zone.Rotation = MassiveTools.ArrayFromQuaterniond(Quaterniond.Identity); zone.Description = m.Description + " \nRadius:" + m.Radius; MMessageBus.AddZone(this, zone); //Extensions.LookAt(m.Position + m.Radius * 2, m.Position), m.Name)); MSceneObject mo; //planet files contain uvs for mercator if (m.HasAtmosphere) { CurrentNear = m; mo = Helper.CreateModel(MScene.AstroRoot, m.Name, @"Models\planets\earth.3ds", Vector3d.Zero); //mo = Helper.CreateSphere(MScene.AstroRoot, 3, "Planet"); //mo.transform.Scale = m.Radius * 1.00055; mo.transform.Scale = m.Radius; } else { mo = Helper.CreateModel(MScene.AstroRoot, m.Name, @"Models\planets\planet_sphere2.3ds", Vector3d.Zero); mo.transform.Scale = m.Radius; } if (m.HasRings) { MModel ring = Helper.CreateModel(MScene.Priority2, m.Name + "_rings", @"Models\planets\planet_rings.3ds", Vector3d.Zero); ring.transform.Position = m.Position; ring.transform.Rotation = Quaterniond.FromEulerAngles(0, 0, 5 * Math.PI / 180); ring.transform.Scale = m.Radius; ring.InstanceID = m.Name; ring.TemplateID = m.Name; ring.DistanceThreshold = m.Radius.X * 12; ring.OwnerID = "MasterAstronomer"; MMaterial ringmat = new MMaterial(m.Name + "_mat"); ringmat.AddShader((MShader)MScene.MaterialRoot.FindModuleByName(MShader.DEFAULT_SHADER)); MTexture ringtex = Globals.TexturePool.GetTexture(@"Textures\Planets\saturn_rings.png"); ringmat.SetDiffuseTexture(ringtex); ring.SetMaterial(ringmat); MPhysicsObject ringpo = new MPhysicsObject(ring, "Physics", 0, MPhysicsObject.EShape.ConcaveMesh, false, m.Radius); ringpo.SetLinearFactor(0, 0, 0); ringpo.SetRestitution(0.5); } mo.transform.Position = m.Position; //mo.transform.Scale = m.Radius * 1.9999; mo.InstanceID = m.Name; mo.TemplateID = m.Name; mo.OwnerID = "MasterAstronomer"; mo.DistanceThreshold = m.Radius.X * 110002; //distance at which it becomes visible //MModel mod = (MModel)mo.FindModuleByType(EType.Model); //mod.DistanceThreshold = mo.DistanceThreshold; //MMesh met = (MMesh)mod.FindModuleByType(EType.Mesh); //if ( met != null ) { //met.DistanceThreshold = mo.DistanceThreshold; //} mo.Tag = m; m.Tag = mo; //now that we have a 3d model, apply some progressive textures (will auto-switch with smooth transition in shader) MMaterial mat = new MMaterial(m.Name + "_mat"); mat.AddShader((MShader)MScene.MaterialRoot.FindModuleByName(MShader.DEFAULT_SHADER)); MTexture tex = Globals.TexturePool.GetTexture(m.TextureName); mat.SetDiffuseTexture(tex); mo.SetMaterial(mat); MTexture tex2 = Globals.TexturePool.GetTexture("Textures\\terrain\\sand01b.jpg"); mat.SetMultiTexture(tex2); MTexture tex3 = Globals.TexturePool.GetTexture("Textures\\terrain\\water.jpg"); mat.SetNormalMap(tex3); double dia = 2.0 * Math.PI * m.Radius.X * 0.0000001; //double dia = 1; mat.Tex2CoordScale = new Vector2((float)dia, (float)dia); mo.SetMaterial(mat); MScene.MaterialRoot.Add(mat); if (m.HasAtmosphere) { if (Settings.DrawTerrains == true) { m.AddDynamicTerrain(); //adds tile based terrain (from e.g. tile service) } //MPhysicsObject po = new MPhysicsObject(mo, "Physics", 0, MPhysicsObject.EShape.ConcaveMesh, //false, m.Radius); MPhysicsObject po = new MPhysicsObject(mo, "Physics", 0, MPhysicsObject.EShape.Sphere, false, m.Radius); //po.SetLinearFactor(0, 0, 0); //po.SetRestitution(0.5); //MSphere moc = Helper.CreateSphere(MScene.AstroRoot, 3, m.Name+ "Clouds", Vector3d.Zero); MModel moc = Helper.CreateModel(MScene.AstroRoot, m.Name + "_clouds", @"Models\planets\clouds.3ds", Vector3d.Zero); moc.CastsShadow = false; moc.transform.Position = m.Position; moc.transform.Scale = m.Radius; moc.DistanceThreshold = m.Radius.X * 3; //moc.transform.Scale = m.Radius*2.1; moc.InstanceID = m.Name; moc.TemplateID = m.Name; moc.OwnerID = "MasterAstronomer"; moc.Tag = m; MMaterial cmat = new MMaterial("CloudMat"); cmat.AddShader((MShader)MScene.MaterialRoot.FindModuleByName(MShader.DEFAULT_SHADER)); cmat.Opacity = 1; cmat.IsSky = 1; // = new MTexture("CloudTex"); MTexture ctex = Globals.TexturePool.GetTexture(CloudTexURL); ctex.Additive = false; cmat.SetDiffuseTexture(ctex); moc.SetMaterial(cmat); MScene.MaterialRoot.Add(cmat); MModel sky = Helper.CreateModel(MScene.AstroRoot, m.Name + "_sky", @"Models\sky.3ds", Vector3d.Zero); sky.CastsShadow = false; sky.transform.Position = m.Position; sky.transform.Scale = m.Radius; //moc.transform.Scale = m.Radius*2.1; sky.InstanceID = m.Name; sky.TemplateID = m.Name; sky.OwnerID = "MasterAstronomer"; sky.Tag = m; sky.SetMaterial(cmat); sky.DistanceThreshold = m.Radius.X * 4; MObjectAnimation ani = new MObjectAnimation(); ani.AngleOffset = Quaterniond.FromEulerAngles(0, 0.002, 0); ani.Speed = 1; sky.Add(ani); sky.SetMaterial(MSkyMaterial); /*MMaterial csky = new MMaterial("Skymat"); * csky.AddShader((MShader)MScene.MaterialRoot.FindModuleByName(MShader.DEFAULT_SHADER)); * csky.Opacity = 0.5; * csky.IsSky = 1; * // = new MTexture("CloudTex"); * MTexture cSkyTex = Globals.TexturePool.GetTexture(OpaqueCloudTexURL); * cSkyTex.Additive = false; * csky.SetDiffuseTexture(cSkyTex); * sky.SetMaterial(csky); * MScene.MaterialRoot.Add(csky); */ /* MSphere water = Helper.CreateSphere(MScene.ModelRoot, 5, "Water"); * water.transform.Position = m.Position; * water.transform.Scale = m.Radius * 2.00; * MMaterial waterman = new MMaterial("Watermat"); * MShader shader = new MShader("watershader"); * shader.Load("ocean_vs.glsl", "ocean_fs.glsl"); * shader.Bind(); * shader.SetInt("diffuseTexture", 0); * shader.SetInt("shadowMap", 1); * waterman.AddShader(shader); * water.SetMaterial(waterman); */ //water.SetMaterial((MMaterial)MScene.MaterialRoot.FindModuleByName(MMaterial.DEFAULT_MATERIAL)); } else { MPhysicsObject po = new MPhysicsObject(mo, "Physics", 0, MPhysicsObject.EShape.Sphere, false, m.Radius * 0.999); po.SetLinearFactor(0, 0, 0); po.SetRestitution(0.5); } m.Setup(); //Console.WriteLine("Created:" + mo.Name + ":" + (mo.transform.Position) + " R:" + m.Radius); } }