public static MRemoteModel CreateModelURL(MObject parent, string URL, string TexURL, string OwnerID, string sName, Vector3d pos, Quaterniond rot) { if (parent == null) { parent = MScene.ModelRoot; } MRemoteModel m = new MRemoteModel(); m.OwnerID = OwnerID; m.Name = sName; parent.Add(m); m.transform.Position = pos; m.transform.Rotation = rot; //MMaterial mat = new MMaterial(sName+ "_mat"); //mat.AddShader((MShader)MScene.MaterialRoot.FindModuleByName(MShader.DEFAULT_SHADER)); //mat.AddTexture(TexturePool.GetTexture(TexURL)); //m.SetMaterial(mat); try { m.Load(URL); } catch (Exception e) { Console.WriteLine("Error createing model:" + URL + "." + e.Message); } parent.Add(m); return(m); }
public static void NotifyChange(object sender, MObject mo, GraphChangedEvent.ChangeType Reason) { if (GraphChangeHandler != null) { GraphChangeHandler(sender, new GraphChangedEvent(mo, Reason)); } }
public static MSceneObject FindNearestObject(Vector3d Pos, string TemplateID) { double dist = 999999999999999999; MSceneObject Closest = null; for (int i = 0; i < MScene.Priority1.Modules.Count; i++) { MObject m = MScene.Priority1.Modules[i]; if (!m.Renderable) { continue; } MSceneObject mo = (MSceneObject)m; if (mo.InstanceID.Equals(Globals.UserAccount.UserID)) { continue; } if (mo != null) { double dtm = Vector3d.Distance(mo.transform.Position, Pos); if (dtm < dist) { Closest = mo; dist = dtm; } } } return(Closest); }
public MTerrainHandler(MAstroBody body) : base(EType.Other, "TerrainHandler") { CurrentBody = body; Tiles = new Dictionary <string, MTerrainTile>(); Container = new MObject(EType.Other, "container"); }
// processes a node in a recursive fashion. Processes each individual mesh located at the node and repeats this process on its children nodes (if any). void processNode(Node node, Scene scene, MObject parent) { MMesh NewNode = null; if (parent == null) { parent = this; } // process each mesh located at the current node for (int i = 0; i < node.MeshCount; i++) { // the node object only contains indices to index the actual objects in the scene. // the scene contains all the data, node is just to keep stuff organized (like relations between nodes). Mesh m = scene.Meshes[node.MeshIndices[i]]; // meshes.Add(processMesh(m, scene)); Matrix4d tr = FromMatrixd(node.Transform); // tr.Transpose(); NewNode = processMesh(m, scene, node.Name, tr); if (parent != null) { NewNode.OwnerID = parent.OwnerID; NewNode.FaceCount = m.FaceCount; parent.Add(NewNode); } } // after we've processed all of the meshes (if any) we then recursively process each of the children nodes for (int i = 0; i < node.ChildCount; i++) { processNode(node.Children[i], scene, NewNode); } }
public static MObject AddNull(MObject parent, string sName = "NULL") { MObject mo = new MObject(MObject.EType.Null, sName); parent.Add(mo); return(mo); }
public override void CopyTo(MObject mo) { base.CopyTo(mo); MModel md = (MModel)mo; md.Filename = Filename; }
public MSystemScript(string inClassName, MObject Target) : base(EType.Script, "Script:" + inClassName) { _ref = Target; _ScriptHost = Globals.ScriptHost; ClassName = inClassName; // _compiler.CreateInstance(ClassName); }
public override void CopyTo(MObject dobj) { MSound d = (MSound)dobj; d.Filename = Filename; d.Loop = Loop; d.Volume = Volume; d.PlayOnAwake = PlayOnAwake; d.Rate = Rate; base.CopyTo(d); }
public void Init(MObject pref) { _this = pref; if (_this != null) { Console.WriteLine("Initialized from dll:" + _this.Name); } else { Console.WriteLine("Init called, with no linking MassiveObject"); } }
public static MInstanceModel SpawnInstanced(MObject parent, string TemplateID, string OwnerID, string sName, Vector3d pos) { MInstanceModel mo = (MInstanceModel)MScene.TemplateRoot.FindModuleByInstanceID(TemplateID); MInstanceModel m = new MInstanceModel(sName, mo.ModelPath, mo.MeshTexture); m.OwnerID = OwnerID; m.transform.Position = pos; mo.CopyTo(m); parent.Add(m); return(m); }
public static MCube CreateCube(MObject parent, string sName, Vector3d pos) { if (parent == null) { parent = MScene.ModelRoot; } MCube c = new MCube(sName); c.transform.Position = pos; c.Setup(); parent.Add(c); c.SetMaterial((MMaterial)MScene.MaterialRoot.FindModuleByName(MMaterial.DEFAULT_MATERIAL)); return(c); }
public static MSphere CreateSphere(MObject parent, int Recursion, string sName, Vector3d pos) { if (parent == null) { parent = MScene.ModelRoot; } MSphere sphere = new MSphere(sName, Recursion); sphere.transform.Position = pos; sphere.Setup(); parent.Add(sphere); sphere.material = (MMaterial)MScene.MaterialRoot.FindModuleByName(MMaterial.DEFAULT_MATERIAL); sphere.Add(sphere.material); return(sphere); }
public static void CheckGLError(MObject mo, string Extra = "") { #if DEBUG ErrorCode c = GL.GetError(); if (c != ErrorCode.NoError) { StackTrace stackTrace = new StackTrace(); string sCaller = stackTrace.GetFrame(1).GetMethod().Name; sCaller += " @" + stackTrace.GetFrame(1).GetFileLineNumber(); for (int i = 0; i < stackTrace.FrameCount; i++) { StackFrame frame = stackTrace.GetFrame(i); sCaller += " >" + frame.GetMethod().Name; } //Console.WriteLine(c + " @" + Extra + " OPENGL:" + mo.Name + "(" + sCaller + "): "); } #endif }
public bool Owns(MObject mo) { if (string.IsNullOrEmpty(Globals.UserAccount.UserID)) { return(false); } if (mo == null) { return(false); } if (string.IsNullOrEmpty(mo.OwnerID)) { return(false); } if (Globals.UserAccount.UserID.Equals(mo.OwnerID)) { return(true); } return(false); }
public static MModel CreateModel(MObject parent, string sName, string Filename, Vector3d pos) { if (parent == null) { parent = MScene.ModelRoot; } MModel m = new MModel(MObject.EType.Model, sName); m.transform.Position = pos; try { m.Load(Filename); } catch (Exception e) { Console.WriteLine("CreateModel: Failed to load model:" + sName + " :" + Filename); } parent.Add(m); return(m); }
public static MAnimatedModel SpawnAnimatedModel(MObject parent, string TemplateID, string OwnerID, string sName, Vector3d pos) { MAnimatedModel mo = (MAnimatedModel)MScene.TemplateRoot.FindModuleByInstanceID(TemplateID); //MMesh sm = (MMesh)mo.FindModuleByType(MObject.EType.Mesh); MAnimatedModel m = new MAnimatedModel(MObject.EType.AnimatedModel, sName); m.OwnerID = OwnerID; m.transform.Position = pos; mo.CopyTo(m); parent.Add(m); for (int i = 0; i < mo.Modules.Count; i++) { if (mo.Modules[i].Type != MObject.EType.BoneMesh) { continue; } MAnimatedMesh mr = (MAnimatedMesh)mo.Modules[i]; // m.Add(mr); MAnimatedMesh mesh = new MAnimatedMesh(sName); mesh.OwnerID = mr.OwnerID; mr.transform.CopyTo(mesh); m.Add(mesh); mesh.VBO = mr.VBO; mesh.VAO = mr.VAO; mesh.EBO = mr.EBO; mesh.Indices = mr.Indices; mesh.IndicesLength = mr.IndicesLength; mesh.Vertices = mr.Vertices; mesh.VerticesLength = mr.VerticesLength; mesh.Normals = mr.Normals; mesh.material = mo.material; m.material = mo.material; //parent.Add(m); } return(m); }
/// <summary> /// The main setup point for the initial scene graph and tools /// </summary> public void SetupInitialObjects() { Root = new MObject(MObject.EType.Null, "Root"); //Root.Deletable = false; TemplateRoot = new MObject(MObject.EType.Null, "TemplateRoot"); Root.Add(TemplateRoot); TemplateRoot.Enabled = false; //disable updates SelectionRoot = new MObject(MObject.EType.Null, "Selection"); Root.Add(SelectionRoot); UtilityRoot = new MObject(MObject.EType.Null, "Utility"); UtilityRoot.Deletable = false; Root.Add(UtilityRoot); time = new Time(); UtilityRoot.Add(time); LightRoot = new MObject(MObject.EType.Null, "LightRoot"); Root.Add(LightRoot); Globals.ScriptHost = new MScriptHost(); UtilityRoot.Add(Globals.ScriptHost); MSystemScript sc = new MSystemScript("Massive.Main", Root); sc.SetActivator(Globals.ScriptHost.GetMainActivator()); Root.Add(sc); Globals.TexturePool = new TexturePool(); UtilityRoot.Add(Globals.TexturePool); Renderer = new MRenderer(); UtilityRoot.Add(Renderer); DefaultShader = new MShader(MShader.DEFAULT_SHADER); DefaultShader.Load("default_v.glsl", "default_f.glsl", "Terrain\\eval.glsl", "Terrain\\control.glsl"); DefaultShader.Bind(); DefaultShader.SetInt("material.diffuse", MShader.LOCATION_DIFFUSE); DefaultShader.SetInt("material.specular", MShader.LOCATION_SPECULAR); DefaultShader.SetInt("material.multitex", MShader.LOCATION_MULTITEX); DefaultShader.SetInt("material.normalmap", MShader.LOCATION_NORMALMAP); DefaultShader.SetInt("material.shadowMap", MShader.LOCATION_SHADOWMAP); //DefaultShader.Deletable = false; Helper.CheckGLError(this, "TestPoint 1"); // MShader GUIShader = new MShader("DefaultGUIShader"); // GUIShader.Load("gui_v.glsl", "gui_f.glsl"); //GUIShader.Bind(); //GUIShader.Deletable = false; MaterialRoot = new MObject(MObject.EType.Null, "MaterialRoot"); //MaterialRoot.Deletable = false; Root.Add(MaterialRoot); Helper.CheckGLError(this); if (Physics != null) { Physics.Dispose(); } Physics = new MPhysics(); Physics.Setup(); //only need to do this once //Physics.Deletable = false; UtilityRoot.Add(Physics); Helper.CheckGLError(this, "TestPoint 2"); //UtilityRoot.Add(Globals.Network); //Globals.Network.Deletable = false; DistanceClipper = new MDistanceClipper(); UtilityRoot.Add(DistanceClipper); FrustrumCuller = new MFrustrumCuller(); UtilityRoot.Add(FrustrumCuller); Globals.Avatar = new MAvatar("Player1"); UtilityRoot.Add(Globals.Avatar); Background = new MObject(MObject.EType.Null, "Background"); Root.Add(Background); Background2 = new MObject(MObject.EType.Null, "Background2"); Root.Add(Background2); ModelRoot = new MObject(MObject.EType.Null, "ModelRoot"); Root.Add(ModelRoot); ModelRoot.Deletable = false; AstroRoot = new MObject(MObject.EType.Null, "AstroRoot"); //ModelRoot.Add(AstroRoot); UtilityRoot.Add(AstroRoot); AstroRoot.Deletable = false; if (Settings.DrawPlanets == true) { MPlanetHandler mpi = new MPlanetHandler(); UtilityRoot.Add(mpi); MGrass grass = new MGrass(); Background2.Add(grass); } Priority1 = new MObject(MObject.EType.Null, "Priority1"); ModelRoot.Add(Priority1); Priority2 = new MObject(MObject.EType.Null, "Priority2"); ModelRoot.Add(Priority2); Overlay = new MObject(MObject.EType.Null, "Overlay"); //ModelRoot.Add(Overlay); //manually drawn in render if (Settings.DrawBackdrop == true) { AddBackdrop(); } Fog = new MFog(); UtilityRoot.Add(Fog); DefaultMaterial = new MMaterial(MMaterial.DEFAULT_MATERIAL); DefaultMaterial.Deletable = false; DefaultMaterial.AddShader(DefaultShader); //DefaultMaterial.SetDiffuseTexture(Globals.TexturePool.GetTexture("Textures\\default.jpg")); MaterialRoot.Add(DefaultMaterial); MTexture DefaultTexture = new MTexture(MTexture.DEFAULT_TEXTURE); DefaultTexture.LoadTextureData(MFileSystem.ProjectPath + "Assets\\Textures\\default.jpg"); DefaultTexture.DoAssign = true; DefaultMaterial.SetDiffuseTexture(DefaultTexture); MMaterial GUIMat = new MMaterial("DefaultGUIMaterial"); //GUIMat.Deletable = false; //GUIMat.AddShader(GUIShader); //GUIMat.SetDiffuseTexture(Globals.TexturePool.GetTexture("Textures\\unwrap_helper_1024.jpg")); //MaterialRoot.Add(GUIMat); MMaterial DepthMaterial = new MMaterial("Depth"); DepthMaterial.Deletable = false; simpleDepthShader = new MShader("simpleDepthShader"); simpleDepthShader.Load("shadow_mapping_depth_v.glsl", "shadow_mapping_depth_f.glsl", "", "") ; DepthMaterial.shader = simpleDepthShader; DepthMaterial.Add(simpleDepthShader); MaterialRoot.Add(DepthMaterial); Helper.CheckGLError(this, "TestPoint 5"); //UtilityRoot.Add(audioListener); //audioListener.Deletable = false; Camera = new MCamera("MainCam"); Camera.OwnerID = MObject.OWNER_SYSTEM; Camera.transform.Position = new Vector3d(9, 5, 9); UtilityRoot.Add(Camera); audioListener = new MAudioListener(); Camera.Add(audioListener); // Camera.Deletable = false; light = new MLight("DirLight"); light.OwnerID = MObject.OWNER_SYSTEM; light.transform.Position = new Vector3d(-10, 20.0f, -10.0f); UtilityRoot.Add(light); //light.Deletable = false; ScreenPick = new MScreenPick(); // ScreenPick.Setup(); UtilityRoot.Add(ScreenPick); // ScreenPick.Deletable = false; MShader debugDepthQuad = new MShader("debugDepthQuad"); debugDepthQuad.Load("debug_quad_v.glsl", "debug_quad_f.glsl", "Terrain\\eval.glsl", "Terrain\\control.glsl"); debugDepthQuad.Bind(); debugDepthQuad.SetInt("depthMap", 0); //debugDepthQuad.SetFloat("near_plane", light.NearPlane); //debugDepthQuad.SetFloat("far_plane", light.FarPlane); UtilityRoot.Add(debugDepthQuad); debugDepthQuad.Deletable = false; MMaterial debugmat = new MMaterial("DEBUG"); debugmat.shader = debugDepthQuad; //debugmat.Deletable = false; debugQuad = new DebugQuad("DEBUGQUAD"); debugQuad.material = debugmat; UtilityRoot.Add(debugQuad); debugQuad.Deletable = false; GUIRoot = new MGUI(); Root.Add(GUIRoot); Helper.CheckGLError(this, "TestPoint 6"); }
public GraphChangedEvent(MObject inObject, ChangeType inReason) { ChangedObject = inObject; Reason = inReason; }
public override void CopyTo(MObject m1) { base.CopyTo(m1); MSceneObject mo = (MSceneObject)m1; mo.transform.Scale = transform.Scale; mo.transform.RotationOffset = transform.RotationOffset; //we don't want to use the template position, since these will be set by the world map //mo.transform.Position = transform.Position; //mo.transform.Rotation = transform.Rotation; mo.SetMaterial(material); mo.TemplateID = TemplateID; mo.IsAvatar = IsAvatar; mo.CastsShadow = CastsShadow; mo.BoundingBox = BoundingBox; mo.IndicesLength = IndicesLength; mo.VerticesLength = VerticesLength; mo.IsTransparent = IsTransparent; foreach (MObject m in Modules) { if (m.Type == EType.PhysicsObject) { MPhysicsObject p1 = (MPhysicsObject)m; MPhysicsObject p2 = new MPhysicsObject(mo, mo.Name, (float)p1.Mass, p1.Shape, false, p1.CreateScale); p2.Name = p1.Name; p2.SetDamping(p1._rigidBody.LinearDamping, p1._rigidBody.AngularDamping); p2._rigidBody.AngularFactor = p1._rigidBody.AngularFactor; p2._rigidBody.LinearFactor = p1._rigidBody.LinearFactor; p2._rigidBody.Restitution = p1._rigidBody.Restitution; p2.SetPosRot(mo.transform.Position, mo.transform.Rotation); //p2.SetPosition(mo.transform.Position); //p2.SetRotation(mo.transform.Rotation); p2.StopAllMotion(); } if (m.Type == EType.PointLight) { MPointLight p = new MPointLight(m.Name); MScene.LightRoot.Add(p); m.CopyTo(p); mo.Add(p); } if (m.Type == EType.Sound) { MSound os = (MSound)m; MSound s = new MSound(); os.CopyTo(s); s.Error = os.Error; s.Load(os.Filename, mo); mo.Add(s); } //network objects can only be owned by the user. When the user is offline the network object is dormant //if (mo.OwnerID.Equals(Globals.UserAccount.UserID)) if (m.Type == EType.NetworkObject) { MNetworkObject mn = (MNetworkObject)m.FindModuleByType(MObject.EType.NetworkObject); if (mn != null) { mo.Add(mn); } } if (m.Type == EType.NPCPlayer) { MNPC p = new MNPC(mo, m.Name); m.CopyTo(p); mo.Add(p); } if (m.Type == EType.Door) { MDoor d2 = new MDoor(mo); m.CopyTo(d2); mo.Add(d2); } } }
public static MSphere CreateSphere(MObject parent, int Recursion, string sName = "Sphere") { return(CreateSphere(parent, Recursion, sName, Vector3d.Zero)); }
/** * Creates a copy of an existing object from the TemplateRoot * */ public static MSceneObject Spawn(MServerObject mso, Vector3d Pos, Quaterniond Rot) { MSceneObject m = (MSceneObject)MScene.TemplateRoot.FindModuleByInstanceID(mso.TemplateID); if (m == null) { Console.WriteLine("TEMPLATE NOT LOADED INTO MScene.TemplateRoot:" + mso.TemplateID); return(null); } MSceneObject t = null; MObject TargetRoot = MScene.ModelRoot; if (m.IsTransparent) { TargetRoot = MScene.Priority2; } else { TargetRoot = MScene.Priority1; } if (m.Type == MObject.EType.PrimitiveCube) { t = CreateCube(TargetRoot, mso.Name, Pos); } if (m.Type == MObject.EType.PrimitiveSphere) { t = CreateSphere(TargetRoot, 2, mso.Name, Pos); } if (m.Type == MObject.EType.Model) { t = SpawnModel(TargetRoot, mso.TemplateID, mso.OwnerID, mso.Name, Pos); } if (m.Type == MObject.EType.AnimatedModel) { t = SpawnAnimatedModel(TargetRoot, mso.TemplateID, mso.OwnerID, mso.Name, Pos); //MAnimatedModel man = (MAnimatedModel)m; //man.BoneOffset = MassiveTools.VectorFromArray(t.BoneOffset); } if (m.Type == MObject.EType.InstanceMesh) { t = SpawnInstanced(TargetRoot, mso.TemplateID, mso.OwnerID, mso.Name, Pos); } t.transform.Position = Pos; t.transform.Rotation = Rot; m.CopyTo(t); t.OwnerID = mso.OwnerID; t.transform.Position = Pos; t.transform.Rotation = Rot; t.Tag = mso.Tag; MClickHandler ch = (MClickHandler)m.FindModuleByType(MObject.EType.ClickHandler); if (ch != null) { MClickHandler ch2 = new MClickHandler(); ch2.Clicked = ch.Clicked; ch2.RightClicked = ch.RightClicked; ch2.DoubleClicked = ch.DoubleClicked; t.Add(ch2); } return(t); }
public static MCube CreateCube(MObject parent, string sName) { return(CreateCube(parent, sName, Vector3d.Zero)); }