Пример #1
0
        private void FinalizeScenery()
        {
            if ((parameters != null) && (parameters.SceneryType == SceneryParameters.SceneryTypeEnum.Photofield))
            {
                if (photoScenery != null)
                {
                    photoScenery.Dispose();
                    photoScenery = null;
                }
            }

            owner.Weather.Wind.ClearThermalSources();

            DisposeWater();

            if (sky != null)
            {
                sky.Dispose();
                sky = null;
            }
            if (ground != null)
            {
                ground.Dispose();
                ground = null;
            }
            DisposeSceneryObjects();

            DisposeSurroundings();

            if (vegetation != null)
            {
                vegetation.Dispose();
                vegetation = null;
            }

            DisposeWindmills();

            DisposeDynamicScenery();

            if (lensFlare != null)
            {
                lensFlare.Dispose();
                lensFlare = null;
            }

            /*
             * if (windsock != null)
             * {
             *  windsock.Dispose();
             *  windsock = null;
             * }
             */

            if (photoScenery != null)
            {
                photoScenery.Dispose();
                photoScenery = null;
            }

            /*
             * if (definition != null)
             * {
             *  definition = null;
             * }
             */
#if EDITOR
            DisposeGates();
#endif
        }
Пример #2
0
        private void Initialize()
        {
            if (parameters.SceneryType == SceneryParameters.SceneryTypeEnum.Photofield)
            {
                if (parameters.HeightMapFile != null)
                {
                    heightMap = new Heightmap(parameters.SceneryFolder + parameters.HeightMapFile,
                                              (float)parameters.HeightMapSize, parameters.HeightMapResolution, parameters.HeightMapResolution);
                    heightMap.MinHeight = parameters.MinimumHeight;
                    heightMap.MaxHeight = parameters.MaximumHeight;
                }
                else
                {
                    heightMap = new Heightmap(1000);
                }
                photoScenery = new PhotoScenery(parameters);
                // Set lighting conditions
                if (definition != null)
                {
                    if (definition.SkyTable.Rows.Count > 0)
                    {
                        DataRow dataRow       = definition.SkyTable.Rows[0];
                        Vector3 ambientVector = (Vector3)dataRow["AmbientLight"];
                        Vector3 sunVector     = (Vector3)dataRow["SunLight"];
                        SetSky(null, (Vector3)dataRow["SunPosition"],
                               Color.FromArgb((int)(255 * ambientVector.X), (int)(255 * ambientVector.Y), (int)(255 * ambientVector.Z)),
                               Color.FromArgb((int)(255 * sunVector.X), (int)(255 * sunVector.Y), (int)(255 * sunVector.Z)),
                               (float)(dataRow["TerrainAmbient"]), (float)(dataRow["TerrainSun"]));
                        lensFlare = new LensFlare();
                    }
                }
            }
            else
            {
                vegetation = new Vegetation(owner);

                ground              = new GameObject();
                heightMap           = new Heightmap(parameters.SceneryFolder + parameters.HeightMapFile, 1000f, 100, 100);
                heightMap.MinHeight = parameters.MinimumHeight;
                heightMap.MaxHeight = parameters.MaximumHeight;
                TerrainMesh sceneryMesh = new TerrainMesh(1.0f, heightMap);
                ground.Mesh = sceneryMesh;

                // Load the detail settings
                currentDetail        = Bonsai.Utils.Settings.GetValue("SceneryDetail", "2");
                dynamicSceneryDetail = Convert.ToInt32(Bonsai.Utils.Settings.GetValue("DynamicScenery", "1"));

                if (currentDetail.Equals("1"))
                {
                    sceneryMesh.Texture = new Bonsai.Objects.Textures.TextureBase(parameters.SplatLowFile);
                }
                else
                {
                    //ground.RotateXAngle = (float)Math.PI / 2;

                    //splatShader = new ShaderBase("splatting", "splatting3.fx");
                    //if (Framework.Instance.DeviceCaps.PixelShaderVersion.Major >= 3)
                    //    splatShader.SetTechnique("TextureSplatting_fx30");
                    //else
                    //    splatShader.SetTechnique("TextureSplatting");

                    splatShader = new ShaderBase("splatting", "splat.fx");
                    splatShader.SetTechnique("TextureSplatting");
                    splatShader.SetVariable("matViewProj", ShaderBase.ShaderParameters.CameraProjection);
                    splatShader.SetVariable("sunPosition", new Vector3(1, 1, 1));
                    splatShader.SetVariable("underwater", 0.0f);
                    splatShader.SetVariable("matWorld", ShaderBase.ShaderParameters.World);
                    splatShader.SetVariable("matInvertTransposeWorld", ShaderBase.ShaderParameters.WorldInvertTranspose);
                    splatShader.SetVariable("cameraPos", ShaderBase.ShaderParameters.CameraPosition);
                    splatShader.SetVariable("nearRepeat", 64.0f);
                    splatShader.SetVariable("farRepeat", 16.0f);
                    splatShader.SetVariable("nearFactor2", 1.0f);
                    splatShader.SetVariable("farFactor2", 1.0f);
                    splatShader.SetVariable("nearFactor3", 1.0f);
                    splatShader.SetVariable("farFactor3", 1.0f);
                    splatShader.SetVariable("nearFactor4", 5.0f);
                    splatShader.SetVariable("farFactor4", 5.0f);
                    splatShader.SetVariable("blendSqDistance", 50f * 50f);
                    splatShader.SetVariable("blendSqWidth", 1.0f / (200f * 200f));
                    TextureBase normalMap = new TextureBase(parameters.NormalMapFile);
                    TextureBase alphaMap  = new TextureBase(parameters.SplatHighFile);
                    //TextureBase grassTexture = new TextureBase("data/grass_zoomout.png");
                    TextureBase grassTexture = new TextureBase(parameters.Texture1File);
                    TextureBase rockTexture  = new TextureBase(parameters.Texture2File);
                    //TextureBase rockNormal = new TextureBase("data/splat_rock_normal.jpg");
                    TextureBase sandTexture     = new TextureBase(parameters.Texture3File);
                    TextureBase concreteTexture = new TextureBase(parameters.Texture4File);

                    splatShader.SetVariable("NormalMapTexture", normalMap);
                    splatShader.SetVariable("AlphaTexture", alphaMap);
                    splatShader.SetVariable("DetailTexture1", grassTexture);
                    splatShader.SetVariable("DetailTexture2", rockTexture);
                    //splatShader.SetVariable("DetailTexture2NormalMap", rockNormal);
                    splatShader.SetVariable("DetailTexture3", sandTexture);
                    splatShader.SetVariable("DetailTexture4", concreteTexture);

                    ground.Shader = splatShader;
                }

                CreateSurroundings();

                // Load the trees
                vegetation.LoadTrees(heightMap, definition);

                // Load the simple trees
                LoadSimpleTrees(definition);

                // Load the simple tall trees
                LoadSimpleTallTrees(definition);

                // Load the simple small trees
                LoadSimpleSmallTrees(definition);

                // Load the scenery objects
                LoadSceneryObjects(definition);

                // Load the windmills
                LoadWindmills(definition);

                // Load the weather
                LoadWeather(definition);

                // Load the dynamic scenery
                if (dynamicSceneryDetail > 0)
                {
                    LoadDynamicScenery(definition);
                }

                // Load the sky
                sky = new GameObject();
                DomeMesh skyDome = new DomeMesh(4500, 16, 16);
                sky.Mesh = skyDome;
                DataRow dataRow = definition.SkyTable.Rows[0];
                foreach (DataRow skyRow in definition.SkyTable.Rows)
                {
                    string skyName = skyRow["Name"].ToString();
                    if (skyName.Equals(Bonsai.Utils.Settings.GetValue("Sky")))
                    {
                        dataRow = skyRow;
                        break;
                    }
                }

                // Load the water
                LoadWater(definition);
                //water = new Water(new Vector3(90, 0, 180), 100f, Bonsai.Objects.Terrain.Water.QualityLevelEnum.Low);

                if (dataRow != null)
                {
                    Vector3 ambientVector = (Vector3)dataRow["AmbientLight"];
                    Vector3 sunVector     = (Vector3)dataRow["SunLight"];
                    SetSky(dataRow["Texture"].ToString(), (Vector3)dataRow["SunPosition"],
                           Color.FromArgb((int)(255 * ambientVector.X), (int)(255 * ambientVector.Y), (int)(255 * ambientVector.Z)),
                           Color.FromArgb((int)(255 * sunVector.X), (int)(255 * sunVector.Y), (int)(255 * sunVector.Z)),
                           (float)(dataRow["TerrainAmbient"]), (float)(dataRow["TerrainSun"]));
                }

                // Apply the ads
                if (Utility.MediaExists("ads/ad1.jpg"))
                {
                    ApplyAds("ad.jpg", "ads/ad1.jpg");
                }
                if (Utility.MediaExists("ads/ad2.jpg"))
                {
                    ApplyAds("ad2.jpg", "ads/ad2.jpg");
                }

                lensFlare = new LensFlare();
            }

#if EDITOR
            // Load the racing pylons
            LoadGates(definition);
#else
            if (Program.Instance.Player != null)
            {
                Program.Instance.Player.Heightmap            = heightMap;
                Program.Instance.Player.DefaultStartPosition = parameters.DefaultStartPosition;
                Program.Instance.Player.WaterStartPosition   = parameters.WaterStartPosition;
            }

            SetWaterCallback(Program.Instance.OnFrameRenderWater);
            // Rerender the reflection
            if (Effects.Reflection.Instance != null)
            {
                Effects.Reflection.Instance.Invalidate();
            }
#endif
        }