Beispiel #1
0
        //public unsafe void Replace3(Mogre.Image image, string textureName)
        //{
        //    if (this.IndexOf(textureName) < 0) throw new ArgumentException("The texture \"" + textureName + "\"doesn't exist");
        //    TexturePtr pTexture = this[textureName];
        //    HardwarePixelBufferSharedPtr texBuffer = pTexture.GetBuffer();
        //    texBuffer.Lock(HardwareBuffer.LockOptions.HBL_DISCARD);
        //    PixelBox pb = texBuffer.CurrentLock;

        //    PixelBox imagBox = image.GetPixelBox();
        //    imagBox.data
        //    Marshal.Copy(bytes, 0, pb.data, bytes.Length);
        //    texBuffer.Unlock();
        //    texBuffer.Dispose();
        //}

        public byte[] ConvertImageToRgbValues(byte[] inBytes)
        {
            Mogre.Image   image = new Mogre.Image();
            MemoryStream  ms    = new MemoryStream(inBytes);
            DataStreamPtr fs2   = new DataStreamPtr(new ManagedDataStream(ms));

            image.Load(fs2);
            PixelBox imagBox = image.GetPixelBox();
            uint     bytes   = imagBox.GetConsecutiveSize();

            byte[] rgbValues = new byte[bytes];
            Marshal.Copy(imagBox.data, rgbValues, 0, (int)bytes);
            image.Dispose();
            fs2.Close();
            ms.Close();
            return(rgbValues);
        }
Beispiel #2
0
        public void Replace(byte[] bytes, string textureName)
        {
            if (this.IndexOf(textureName) < 0)
            {
                throw new ArgumentException("The texture \"" + textureName + "\"doesn't exist");
            }
            Mogre.Image   image = new Mogre.Image();
            MemoryStream  ms    = new MemoryStream(bytes);
            DataStreamPtr fs2   = new DataStreamPtr(new ManagedDataStream(ms));

            image.Load(fs2);
            PixelBox            imagBox         = image.GetPixelBox();
            TexturePtr          pTexture        = this[textureName];
            TextureManager      lTextureManager = TextureManager.Singleton;
            HardwarePixelBuffer buffer          = pTexture.GetBuffer();

            unsafe
            {
                buffer.BlitFromMemory(imagBox);
            }
            image.Dispose();
            fs2.Close();
            ms.Close();
        }
Beispiel #3
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");
        }
Beispiel #4
0
        public void UpdateLightMap()
        {
            try
            {
                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.5f, 0.5f, 0.5f), true);

                TexturePtr tex = TextureManager.Singleton.GetByName("ETLightmap" + "0");
                tex.GetBuffer(0, 0).BlitFromMemory(lmImage.GetPixelBox(0, 0));
            }
            catch (Exception e)
            {
                LogManager.Singleton.LogMessage("Lightmap exception: " + e.StackTrace);
                // in some cases lightmap crashes...never mind
            }
            ///
        }
Beispiel #5
0
 public void Replace(byte[] bytes, string textureName)
 {
     if (this.IndexOf(textureName) < 0) throw new ArgumentException("The texture \"" + textureName + "\"doesn't exist");
     Mogre.Image image = new Mogre.Image();
     MemoryStream ms = new MemoryStream(bytes);
     DataStreamPtr fs2 = new DataStreamPtr(new ManagedDataStream(ms));
     image.Load(fs2);
     PixelBox imagBox = image.GetPixelBox();
     TexturePtr pTexture = this[textureName];
     TextureManager lTextureManager = TextureManager.Singleton;
     HardwarePixelBuffer buffer = pTexture.GetBuffer();
     unsafe
     {
         buffer.BlitFromMemory(imagBox);
     }
     image.Dispose();
     fs2.Close();
     ms.Close();
 }
Beispiel #6
0
 //public unsafe void Replace3(Mogre.Image image, string textureName)
 //{
 //    if (this.IndexOf(textureName) < 0) throw new ArgumentException("The texture \"" + textureName + "\"doesn't exist");
 //    TexturePtr pTexture = this[textureName];
 //    HardwarePixelBufferSharedPtr texBuffer = pTexture.GetBuffer();
 //    texBuffer.Lock(HardwareBuffer.LockOptions.HBL_DISCARD);
 //    PixelBox pb = texBuffer.CurrentLock;
 //    PixelBox imagBox = image.GetPixelBox();
 //    imagBox.data
 //    Marshal.Copy(bytes, 0, pb.data, bytes.Length);
 //    texBuffer.Unlock();
 //    texBuffer.Dispose();
 //}
 public byte[] ConvertImageToRgbValues(byte[] inBytes)
 {
     Mogre.Image image = new Mogre.Image();
     MemoryStream ms = new MemoryStream(inBytes);
     DataStreamPtr fs2 = new DataStreamPtr(new ManagedDataStream(ms));
     image.Load(fs2);
     PixelBox imagBox = image.GetPixelBox();
     uint bytes = imagBox.GetConsecutiveSize();
     byte[] rgbValues = new byte[bytes];
     Marshal.Copy(imagBox.data, rgbValues, 0, (int)bytes);
     image.Dispose();
     fs2.Close();
     ms.Close();
     return rgbValues;
 }