예제 #1
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);
        }
예제 #2
0
        public void LoadHeightMap()
        {
            string sHeight = string.Format("earth\\{0}\\continuity\\{1}_{2}.png", ZoomLevel, TileX, TileY);

            sHeight = Path.Combine(Settings.TileDataPath, sHeight);
            if (File.Exists(sHeight))
            {
                Heightmap = new MTexture("Heightmap");
                Heightmap.LoadTextureData(sHeight);
                if (Heightmap != null)
                {
                    Heightmap.DoAssign = true;
                }
            }
        }
예제 #3
0
        public void LoadBiome()
        {
            string sText = string.Format("earth\\{0}\\biome\\{1}_{2}.png", ZoomLevel, TileX, TileY);

            sText = Path.Combine(Settings.TileDataPath, sText);
            if (File.Exists(sText))
            {
                Biome          = new MTexture(TileX + "," + TileY + " RGB");
                Biome.Readable = true;
                Biome.LoadTextureData(sText);
                _biome.InitFromBitmap(Biome);
                Biome.DoAssign         = true;
                Biome._TextureWrapMode = TextureWrapMode.ClampToEdge;
                material.SetDiffuseTexture(Biome);
            }
        }
예제 #4
0
        public void LoadTexture()
        {
            //string sText = string.Format("earth\\{0}\\continuity\\{1}_{2}.jpg", ZoomLevel, TileX, TileY);
            string sText = string.Format("earth\\{0}\\biome\\{1}_{2}.png", ZoomLevel, TileX, TileY);

            sText = Path.Combine(Settings.TileDataPath, sText);
            if (File.Exists(sText))
            {
                //MTexture rgb = Globals.TexturePool.GetTexture(sText);
                MTexture rgb = new MTexture(TileX + "," + TileY + " RGB");
                rgb.Readable = false;
                rgb.LoadTextureData(sText);
                rgb.DoAssign         = true;
                rgb._TextureWrapMode = TextureWrapMode.ClampToEdge;
                if (material != null)
                {
                    material.SetDiffuseTexture(rgb);
                }
            }

            //string sText2 = string.Format("earth\\{0}\\biome\\{1}_{2}.png", ZoomLevel, TileX, TileY);
            //string sText2 = string.Format("earth\\{0}\\biome\\{1}_{2}.png", ZoomLevel, TileX, TileY);
            //string sText = string.Format("earth\\{0}\\biome\\{1}_{2}.png", ZoomLevel, TileX, TileY);
            string sText2 = Path.Combine(MFileSystem.AssetsPath, "Textures\\terrain\\dirt.jpg");

            if (File.Exists(sText2))
            {
                //MTexture rgb = Globals.TexturePool.GetTexture(sText);
                MTexture rgb = new MTexture(TileX + "," + TileY + " DIRT");
                rgb.Readable = false;
                rgb.LoadTextureData(sText2);
                rgb.DoAssign         = true;
                rgb._TextureUnit     = TextureUnit.Texture1;
                rgb._TextureWrapMode = TextureWrapMode.Repeat;
                if (material != null)
                {
                    material.SetMultiTexture(rgb);
                }
            }
        }
예제 #5
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");
        }
예제 #6
0
        private void Bw_DoWork(object sender, DoWorkEventArgs e)
        {
            while ((Globals.ApplicationExiting == false) && (done == false))
            {
                if (Current == null)
                {
                    if (Downloads.Count > 0)
                    {
                        Current = Downloads[0];
                        if (Current != null)
                        {
                            if (MassiveTools.IsURL(Current.Filename))
                            {
                                if (File.Exists(Current.CacheFilename))
                                {
                                    //Console.WriteLine("Cache hit:" + Current.Filename + " -> " + Current.CacheFilename);
                                }
                                else
                                {
                                    Globals.Log(this, "Downloading:" + Current.Filename);
                                    DownloadFromURL();
                                }
                                Current.LoadTextureData(Current.CacheFilename);
                            }
                            else
                            {
                                if (File.Exists(Current.Filename))
                                {
                                    Current.LoadTextureData(Current.Filename);
                                }
                                else
                                {
                                    string sAbsolute = Path.Combine(MFileSystem.AssetsPath, Current.Filename);
                                    if (File.Exists(sAbsolute))
                                    {
                                        Current.LoadTextureData(sAbsolute);
                                    }
                                    else
                                    {
                                        Current.Error = "File not found " + Current.Filename;
                                    }
                                }
                            }

                            Downloads.RemoveAt(0);
                            if (Current.DataIsReady == true)
                            {
                                Current.DoAssign = true; //tell the texture to upload to the GPU on next GUI cycle
                                Current          = null;
                            }
                            else
                            {
                                //was there a problem? place at the end of the queue to try again
                                //Downloads.Add(Current);
                                Current = null;
                            }

                            Thread.Sleep(30);
                        }
                    }
                    else
                    {
                        done = true;
                    }
                }
            }
            Current = null;
            _worker = null;
        }