コード例 #1
0
 public static void Load_hTextures()
 {
     if (ADTTexData.textureBlockData.MTXP)
     {
         ADTTexData.textureBlockData.terrainHTextures = new Dictionary <string, ADTTexData.Texture2Ddata>();
         foreach (string texturePath in ADTTexData.textureBlockData.terrainTexturePaths)
         {
             string noExtension   = Path.GetFileNameWithoutExtension(texturePath);
             string directoryPath = Path.GetDirectoryName(texturePath);
             string hTexturePath  = directoryPath + @"\" + noExtension + "_h" + ".blp";
             if (Casc.FileExists(hTexturePath))
             {
                 string  extractedPath = Casc.GetFile(hTexturePath);
                 Stream  stream        = File.Open(extractedPath, FileMode.Open);
                 BLP     blp           = new BLP();
                 byte[]  data          = blp.GetUncompressed(stream, true);
                 BLPinfo info          = blp.Info();
                 ADTTexData.Texture2Ddata texture2Ddata = new ADTTexData.Texture2Ddata();
                 texture2Ddata.hasMipmaps = info.hasMipmaps;
                 texture2Ddata.width      = info.width;
                 texture2Ddata.height     = info.height;
                 if (info.width != info.height) // Unity doesn't support nonsquare mipmaps // sigh
                 {
                     texture2Ddata.hasMipmaps = false;
                 }
                 texture2Ddata.textureFormat = info.textureFormat;
                 texture2Ddata.TextureData   = data;
                 ADTTexData.textureBlockData.terrainHTextures.Add(texturePath, texture2Ddata);
                 stream.Close();
                 stream = null;
             }
         }
     }
 }
コード例 #2
0
    public void ReadMTEX(MemoryStream ADTtexstream, int MTEXsize)
    {
        if (ADTtexstream.Length == ADTtexstream.Position)
        {
            return;
        }

        // texture path strings, separated by 0
        string texturePath      = "";
        int    numberOfTextures = 0;

        for (int a = 0; a < MTEXsize; a++)
        {
            int b = ADTtexstream.ReadByte();
            if (b != 0)
            {
                var stringSymbol = System.Convert.ToChar(b);
                texturePath = texturePath + stringSymbol;
            }
            else if (b == 0)
            {
                ADTTexData.textureBlockData.terrainTexturePaths.Add(texturePath);
                string extractedPath = Casc.GetFile(texturePath);
                using (Stream stream = File.Open(extractedPath, FileMode.Open))
                {
                    BLP     blp  = new BLP();
                    byte[]  data = blp.GetUncompressed(stream, true);
                    BLPinfo info = blp.Info();
                    ADTTexData.Texture2Ddata texture2Ddata = new ADTTexData.Texture2Ddata();
                    texture2Ddata.hasMipmaps = info.hasMipmaps;
                    texture2Ddata.width      = info.width;
                    texture2Ddata.height     = info.height;
                    if (info.width != info.height) // Unity doesn't support nonsquare mipmaps // sigh
                    {
                        texture2Ddata.hasMipmaps = false;
                    }
                    texture2Ddata.textureFormat = info.textureFormat;
                    texture2Ddata.TextureData   = data;
                    ADTTexData.textureBlockData.terrainTextures.Add(texturePath, texture2Ddata);
                    texturePath = null;
                    numberOfTextures++;
                }
            }
        }
    }
コード例 #3
0
    // Create a part of the ADT block textures //
    private void CreateHTextureQuarter(int fS, int Q, ADTTexData.TextureBlockData data, GameObject Block)
    {
        if (working)
        {
            if (Block != null)
            {
                StreamTools s = new StreamTools();
                for (int i = (256 / fS) * (Q - 1); i < (256 / fS) * Q; i++)
                {
                    //////////////////////////////
                    #region Textures
                    //////////////////////////////

                    float[]  HeightScales  = new float[4];
                    float[]  heightOffsets = new float[4];
                    string[] DiffuseLayers = new string[4];
                    string[] HeightLayers  = new string[4];
                    Flags.TerrainTextureFlag[] TextureFlags = new Flags.TerrainTextureFlag[4];
                    Texture2D[] AlphaLayers = new Texture2D[4];
                    Texture2D   ShadowMap   = null;

                    for (int layer = 0; layer < data.textureChunksData[i].NumberOfTextureLayers; layer++)
                    {
                        // Diffuse Texture //
                        string textureName = data.terrainTexturePaths[data.textureChunksData[i].textureIds[layer]];
                        if (!LoadedTerrainTextures.ContainsKey(textureName))
                        {
                            ADTTexData.Texture2Ddata tdata = data.terrainTextures[textureName];
                            Texture2D tex = new Texture2D(tdata.width, tdata.height, tdata.textureFormat, tdata.hasMipmaps);
                            tex.LoadRawTextureData(tdata.TextureData);
                            tex.mipMapBias = Settings.highMipMapBias;
                            tex.Apply();
                            LoadedTerrainTextures[textureName] = tex;
                        }
                        DiffuseLayers[layer] = textureName;

                        // Height Texture //
                        if (data.terrainHTextures.ContainsKey(textureName))
                        {
                            if (!LoadedHTerrainTextures.ContainsKey(textureName))
                            {
                                ADTTexData.Texture2Ddata tdata = data.terrainHTextures[textureName];
                                Texture2D tex = new Texture2D(tdata.width, tdata.height, tdata.textureFormat, tdata.hasMipmaps);
                                tex.LoadRawTextureData(tdata.TextureData);
                                tex.Apply();
                                LoadedHTerrainTextures[textureName] = tex;
                            }
                            HeightLayers[layer] = textureName;
                        }
                        // Height Values //
                        data.heightScales.TryGetValue(textureName, out HeightScales[layer]);
                        data.heightOffsets.TryGetValue(textureName, out heightOffsets[layer]);
                        data.textureFlags.TryGetValue(textureName, out TextureFlags[layer]);

                        // Alpha Texture //
                        if (data.textureChunksData[i].alphaLayers.Count > 0 && layer > 0)
                        {
                            if (data.textureChunksData[i].alphaLayers[0] != null)
                            {
                                AlphaLayers[layer] = new Texture2D(64, 64, TextureFormat.Alpha8, false);
                                AlphaLayers[layer].LoadRawTextureData(data.textureChunksData[i].alphaLayers[layer - 1]);
                                AlphaLayers[layer].wrapMode = TextureWrapMode.Clamp;
                                AlphaLayers[layer].Apply();
                            }
                        }
                    }
                    #endregion

                    //////////////////////////////
                    #region Shadow Maps
                    //////////////////////////////

                    if (SettingsTerrainImport.LoadShadowMaps)
                    {
                        if (data.textureChunksData[i].shadowMapTexture.Length > 0)
                        {
                            ShadowMap = new Texture2D(64, 64, TextureFormat.Alpha8, false);
                            ShadowMap.LoadRawTextureData(data.textureChunksData[i].shadowMapTexture);
                            //Color32[] pixels = ShadowMap.GetPixels32();
                            //pixels = s.RotateMatrix(pixels, 64);
                            //ShadowMap.SetPixels32(pixels);
                            ShadowMap.Apply();
                            ShadowMap.wrapMode = TextureWrapMode.Clamp;
                            // need to enable in shader too //
                        }
                    }
                    #endregion

                    //////////////////////////////
                    #region Material
                    //////////////////////////////

                    Material mat = new Material(shaderWoWTerrainHigh);

                    for (int ln = 0; ln < 4; ln++)
                    {
                        if (DiffuseLayers[ln] != null)
                        {
                            mat.SetTexture("_layer" + ln, LoadedTerrainTextures[DiffuseLayers[ln]]);
                        }
                        mat.SetTextureScale("_layer" + ln, new Vector2(1, 1));
                        if (HeightLayers[ln] != null)
                        {
                            mat.SetTexture("_height" + ln, LoadedHTerrainTextures[HeightLayers[ln]]);
                        }
                        mat.SetTextureScale("_height" + ln, new Vector2(1, 1));
                        if (ln > 0 && AlphaLayers[ln] != null)
                        {
                            mat.SetTexture("_blend" + ln, AlphaLayers[ln]);
                        }
                        if (data.MTXP)
                        {
                            mat.SetFloat("layer" + ln + "scale", TextureFlags[ln].texture_scale);
                        }
                    }
                    if (data.MTXP)
                    {
                        mat.SetVector("heightScale", new Vector4(HeightScales[0], HeightScales[1], HeightScales[2], HeightScales[3]));
                        mat.SetVector("heightOffset", new Vector4(heightOffsets[0], heightOffsets[1], heightOffsets[2], heightOffsets[3]));
                    }
                    if (SettingsTerrainImport.LoadShadowMaps)
                    {
                        mat.SetTexture("_shadowMap", ShadowMap);
                    }
                    Block.transform.GetChild(i).GetComponent <ADTChunk>().MaterialReady(0, mat);

                    #endregion
                }
            }
        }
    }