예제 #1
0
        private void CreateTerrain()
        {
            mTMgr = new MET.TerrainManager(OgreEngine.mMgr, "MET");

            mTMgr.SetLodErrorMargin(2, OgreEngine.mWin.Height);
            mTMgr.SetUseLodMorphing(true, 0.2f, "morphFactor");

            mTInfo = new MET.TerrainInfo();
            Mogre.Image image = new Mogre.Image();

            image.Load("heightmap.png", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME);
            MET.TerrainInfo.LoadHeightmapFromImage(mTInfo, image);
            //mTInfo.Extents = new Mogre.AxisAlignedBox(0, 0, 0, land.SizeX + stepWidth, land.SizeZ, land.SizeY + stepHeight);
            mTInfo.Extents = new Mogre.AxisAlignedBox(Vector3.ZERO, Size);

            //lightmap
            Mogre.Image lmImage = new Mogre.Image();
            MET.TerrainInfo.CreateTerraingLightmap(mTInfo, lmImage, Constants.Land.LightmapSize, Constants.Land.LightmapSize, new Vector3(-1, -1, -1), new ColourValue(1, 1, 1), new ColourValue(0.2f, 0.2f, 0.2f), true);
            //lmImage.Save("lightmapa" + land.Id + ".png");
            TexturePtr lightmapTex = TextureManager.Singleton.CreateManual(
                "ETLightmap",
                ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME,
                Mogre.TextureType.TEX_TYPE_2D,
                Constants.Land.LightmapSize,
                Constants.Land.LightmapSize,
                1,
                Mogre.PixelFormat.PF_BYTE_RGB);

            TexturePtr tex = TextureManager.Singleton.GetByName("ETLightmap");
            tex.GetBuffer(0, 0).BlitFromMemory(lmImage.GetPixelBox(0, 0));

            mTMgr.CreateTerrain(mTInfo);
            mTInfo.Dispose();
            mTInfo = mTMgr.TerrainInfo;

            image = new Image();
            image.Load("textureMap0.png", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME);
            TextureSize = image.Width;
            mSMgr = new MET.SplattingManager("ETSplatting", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, image.Width, image.Width, 3);
            mSMgr.NumTextures = 6;

            mSMgr.LoadMapFromImage(0, image);
            image = new Image();
            image.Load("textureMap1.png", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME);
            mSMgr.LoadMapFromImage(1, image);

            mTMgr.Material = MaterialManager.Singleton.GetByName("ETTerrainMaterial");

            // lightmapa
            Pass pass = mTMgr.Material.GetTechnique(0).CreatePass();
            pass.LightingEnabled = false;
            pass.SetSceneBlending(SceneBlendType.SBT_MODULATE);
            pass.SetVertexProgram("ET/Programs/VSLodMorph2");
            pass.SetFragmentProgram("ET/Programs/PSLighting");
            pass.CreateTextureUnitState("ETLightmap");

            pass = mTMgr.Material.GetTechnique(1).CreatePass();
            pass.LightingEnabled = false;
            pass.SetSceneBlending(SceneBlendType.SBT_MODULATE);
            pass.SetVertexProgram("ET/Programs/VSLodMorph2");
            pass.SetFragmentProgram("ET/Programs/PSLighting");
            pass.CreateTextureUnitState("ETLightmap");

            //base texture for non shader graphics
            lmImage = new Mogre.Image();
            //TODO: replace by real bic texture
            lmImage.Load("baseTexture.jpg", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME);
            //lmImage.Save("lightmapa" + land.Id + ".png");
            lightmapTex = TextureManager.Singleton.CreateManual(
                "ETBasemap",
                ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME,
                Mogre.TextureType.TEX_TYPE_2D,
                Constants.Land.LightmapSize,
                Constants.Land.LightmapSize,
                1,
                Mogre.PixelFormat.PF_BYTE_RGB);

            tex = TextureManager.Singleton.GetByName("ETBasemap");
            tex.GetBuffer(0, 0).BlitFromMemory(lmImage.GetPixelBox(0, 0));

            Technique tech = mTMgr.Material.CreateTechnique();
            pass = tech.CreatePass();
            pass.CreateTextureUnitState("ETBasemap");
        }