示例#1
0
        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);
        }
示例#2
0
        void AddBackdrop()
        {
            Helper.CheckGLError(this, "TestPoint 3a");
            MShader BackgroundShader = new MShader("BackgroundShader");

            BackgroundShader.Load("default_v.glsl",
                                  "unlit_f.glsl",
                                  "Terrain\\eval.glsl", "Terrain\\control.glsl"
                                  );

            BackgroundShader.Bind();
            BackgroundShader.SetInt("material.diffuse", MShader.LOCATION_DIFFUSE);
            Helper.CheckGLError(this, "TestPoint 3b");
            //SkyShader.SetInt("shadowMap", 2);

            MMaterial BGMat = new MMaterial("BackgroundMaterial");

            BGMat.AddShader(BackgroundShader);
            Helper.CheckGLError(this, "TestPoint 4a");
            MTexture BackgroundTexure = new MTexture("BackgroundT");

            Helper.CheckGLError(this, "TestPoint 4b");
            BackgroundTexure.LoadTextureData(MFileSystem.ProjectPath + "Assets\\Textures\\Planets\\8k_stars_milky_way.jpg");
            BackgroundTexure.DoAssign = true;

            MaterialRoot.Add(BGMat);
            BGMat.SetDiffuseTexture(BackgroundTexure);
            backdrop = new MSky();
            backdrop.AddMaterial(BGMat);
            UtilityRoot.Add(backdrop);
        }
示例#3
0
        // 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);
            }
        }
示例#4
0
        public static MObject AddNull(MObject parent, string sName = "NULL")
        {
            MObject mo = new MObject(MObject.EType.Null, sName);

            parent.Add(mo);
            return(mo);
        }
示例#5
0
        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);
        }
示例#6
0
        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);
        }
示例#7
0
        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);
        }
示例#8
0
        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);
        }
示例#9
0
        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);
        }
示例#10
0
        /// <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");
        }