コード例 #1
0
        /// <summary>
        /// Loads the specified BLP image from the archives and deserialize it.
        /// </summary>
        /// <param name="fileReference">A reference to a BLP image.</param>
        /// <returns>A BLP object containing the image data pointed to by the reference.</returns>
        public static BLP LoadBinaryImage(FileReference fileReference)
        {
            if (fileReference == null)
            {
                throw new ArgumentNullException(nameof(fileReference));
            }

            BLP image;

            try
            {
                var fileData = fileReference.Extract();

                try
                {
                    image = new BLP(fileData);
                }
                catch (FileLoadException fex)
                {
                    Log.Warn(
                        $"FileLoadException when loading BLP image: {fex.Message}\n" +
                        $"Please report this on GitHub or via email.");
                    throw;
                }
            }
            catch (FileNotFoundException fex)
            {
                Log.Warn($"Failed to extract image: {fex}");
                throw;
            }

            return(image);
        }
コード例 #2
0
        public static void ReadTXID(BinaryReader reader, M2Model model, uint chunkSize)
        {
            var txidSize = chunkSize / 4;

            for (var i = 0; i < txidSize; ++i)
            {
                var fileDataId = reader.ReadUInt32();

                if (!TextureFileIds.Contains(fileDataId))
                {
                    var m2Texture   = new M2Texture();
                    var textureData = new TextureData();

                    using (var blpStream = CASC.OpenFile(fileDataId))
                    {
                        var blp     = new BLP();
                        var blpData = blp.GetUncompressed(blpStream);
                        var blpInfo = blp.GetInfo();

                        textureData.HasMipmaps    = blpInfo.hasMipmaps;
                        textureData.Width         = blpInfo.width;
                        textureData.Height        = blpInfo.height;
                        textureData.RawData       = blpData;
                        textureData.TextureFormat = blpInfo.textureFormat;

                        m2Texture.TextureData = textureData;
                        m2Texture.FileDataId  = fileDataId;

                        TextureFileIds.Add(fileDataId);
                    }

                    model.Textures.Add(m2Texture);
                }
            }
        }
コード例 #3
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;
             }
         }
     }
 }
コード例 #4
0
ファイル: RenderCache.cs プロジェクト: bmjoy/Everlook
        /// <summary>
        /// Creates a cached texture for the specifed texture, using the specified path
        /// as a lookup key. This method will create a new texture, and cache it.
        /// </summary>
        /// /// <param name="imageData">A bitmap containing the image data.</param>
        /// <param name="texturePath">
        /// The path to the texture in its corresponding package group. This is used as a lookup key.
        /// </param>
        /// <param name="wrappingMode">How the texture should wrap.</param>
        /// <returns>A new cached texture created from the data.</returns>
        public Texture2D CreateCachedTexture(BLP imageData, string texturePath, TextureWrapMode wrappingMode = TextureWrapMode.Repeat)
        {
            Texture2D texture = new Texture2D(imageData, wrappingMode);

            this.TextureCache.Add(texturePath.ConvertPathSeparatorsToCurrentNativeSeparator().ToUpperInvariant(), texture);
            return(texture);
        }
コード例 #5
0
 public static void Load_hTextures(CASCHandler Handler)
 {
     if (ADTTexData.textureBlockData.MTXP)
     {
         ADTTexData.textureBlockData.terrainHTextures = new Dictionary <uint, ADTTexData.Texture2Ddata>();
         foreach (uint TextureFileDataId in ADTTexData.textureBlockData.terrainTextureFileDataIds)
         {
             using (var stream = Handler.OpenFile(TextureFileDataId))
             {
                 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(TextureFileDataId, texture2Ddata);
                 stream.Close();
             }
         }
     }
 }
コード例 #6
0
ファイル: WMO_Root.cs プロジェクト: adan830/wowedit_unity
    // texture paths //
    public static void ReadMOTX(Stream WMOrootstream, int MOTXsize)
    {
        long currentPos = WMOrootstream.Position;

        while (WMOrootstream.Position < currentPos + MOTXsize)
        {
            int    position = (int)(WMOrootstream.Position - currentPos);
            string path     = ReadNullTerminatedString(WMOrootstream);
            if (path != "") //&& !wmoData.textureData.ContainsKey(path))
            {
                //Debug.Log(path);
                wmoData.texturePaths.Add(position, path);
                string        extractedPath = Casc.GetFile(path);
                Stream        stream        = File.Open(extractedPath, FileMode.Open);
                byte[]        data          = BLP.GetUncompressed(stream, true);
                BLPinfo       info          = BLP.Info();
                Texture2Ddata texture2Ddata = new 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;
                wmoData.textureData[path]   = texture2Ddata;
                stream.Close();
                stream = null;
            }
        }
    } // loaded
コード例 #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Everlook.Viewport.Rendering.RenderableBLP"/> class.
        /// </summary>
        /// <param name="inImage">An image object with populated data.</param>
        /// <param name="inTexturePath">The path under which this renderable texture is stored in the archives.</param>
        public RenderableBLP(BLP inImage, string inTexturePath)
        {
            this.Image       = inImage;
            this.TexturePath = inTexturePath;

            this.IsInitialized = false;
        }
コード例 #8
0
ファイル: M2_Main.cs プロジェクト: nexustheru/wowedit_unity
    public static void ReadTXID(BinaryReader br, M2Data m2Data, CASCHandler CascHandler, uint Size)
    {
        LoadedBLPFileDataIds.Clear();
        var numTextures = Size / 4;

        for (int i = 0; i < numTextures; i++)
        {
            uint texture = br.ReadUInt32();

            M2Texture     m2Texture     = new M2Texture();
            Texture2Ddata texture2Ddata = new Texture2Ddata();
            if (!LoadedBLPFileDataIds.Contains(texture))
            {
                var     stream = CascHandler.OpenFile(texture);
                BLP     blp    = new BLP();
                byte[]  data   = blp.GetUncompressed(stream, true);
                BLPinfo info   = blp.Info();

                texture2Ddata.hasMipmaps    = info.hasMipmaps;
                texture2Ddata.width         = info.width;
                texture2Ddata.height        = info.height;
                texture2Ddata.textureFormat = info.textureFormat;
                texture2Ddata.TextureData   = data;

                m2Texture.texture2Ddata = texture2Ddata;
                m2Texture.FileDataId    = texture;

                stream.Close();
                stream.Dispose();

                LoadedBLPFileDataIds.Add(texture);
            }
            m2Data.m2Tex.Add(m2Texture);
        }
    }
コード例 #9
0
    public static TextureData Open(uint fileDataId)
    {
        if (fileDataId == 0)
        {
            return(null);
        }

        var stream = CASC.OpenFile(fileDataId);

        if (stream == null)
        {
            return(null);
        }

        var textureData = new TextureData();
        var blp         = new BLP();
        var blpData     = blp.GetUncompressed(stream);
        var blpInfo     = blp.GetInfo();

        textureData.HasMipmaps    = blpInfo.hasMipmaps;
        textureData.Width         = blpInfo.width;
        textureData.Height        = blpInfo.height;
        textureData.RawData       = blpData;
        textureData.TextureFormat = blpInfo.textureFormat;

        return(textureData);
    }
コード例 #10
0
    public static void Load(string mapName, Vector2 coords)
    {
        string          dataPath             = @"world\maptextures\" + mapName + @"\" + mapName + "_" + coords.x + "_" + coords.y + ".blp";
        MapTextureBlock mapTextureBlock      = new MapTextureBlock();
        Texture2Ddata   texture2Ddata        = new Texture2Ddata();
        string          extractedTexturePath = Casc.GetFile(dataPath);

        using (Stream stream = File.Open(extractedTexturePath, FileMode.Open))
        {
            BLP     blp  = new BLP();
            byte[]  data = blp.GetUncompressed(stream, true);
            BLPinfo info = blp.Info();
            texture2Ddata.hasMipmaps    = info.hasMipmaps;
            texture2Ddata.height        = info.height;
            texture2Ddata.width         = info.width;
            texture2Ddata.textureFormat = info.textureFormat;
            texture2Ddata.TextureData   = data;
            mapTextureBlock.dataPath    = dataPath;
            mapTextureBlock.mapName     = mapName;
            mapTextureBlock.coords      = coords;
            mapTextureBlock.data        = texture2Ddata;
            if (ADT.working)
            {
                MapTextureDataQueue.Enqueue(mapTextureBlock);
            }
            MapTextureThreadRunning = false;
        }
    }
コード例 #11
0
ファイル: WMO_Root.cs プロジェクト: EmuZONE/WOW-Editor-Unity
        // materials //
        public static void ReadMOMT(BinaryReader reader, int MOMTsize, CASCHandler Handler)
        {
            wmoData.Info.nMaterials = MOMTsize / 64;
            for (int i = 0; i < wmoData.Info.nMaterials; i++)
            {
                WMOMaterial material = new WMOMaterial();

                material.flags      = reader.ReadMaterialFlags();
                material.ShaderType = (WMOFragmentShader)reader.ReadUInt32();           // Index into CMapObj::s_wmoShaderMetaData. See below (shader types).
                material.BlendMode  = (BlendingMode)reader.ReadUInt32();                // Blending: see https://wowdev.wiki/Rendering#EGxBlend

                material.TextureId1     = reader.ReadUInt32();                          // offset into MOTX; ≥ Battle (8.1.0.27826) No longer references MOTX but is a filedata id directly.
                material.SidnColor      = reader.ReadBGRA();                            // emissive color; see below (emissive color)
                material.FrameSidnColor = reader.ReadBGRA();                            // sidn emissive color; set at runtime; gets sidn-manipulated emissive color; see below (emissive color)
                material.TextureId2     = reader.ReadUInt32();                          // Environment Texture; envNameIndex; offset into MOTX
                material.DiffColor      = reader.ReadBGRA();                            // diffuse color; CWorldView::GatherMapObjDefGroupLiquids(): geomFactory->SetDiffuseColor((CImVectorⁱ*)(smo+7));
                                                                                        // environment textures don't need flags

                material.GroundType     = reader.ReadUInt32();                          // foreign_keyⁱ< uint32_t, &TerrainTypeRec::m_ID > ground_type; // according to CMapObjDef::GetGroundType
                material.TextureId3     = reader.ReadUInt32();                          // offset into MOTX
                material.Color          = reader.ReadBGRA();
                material.texture3_flags = reader.ReadMaterialFlags();

                // skip runtime data //
                reader.BaseStream.Seek(16, SeekOrigin.Current);

                wmoData.materials.Add(material);
                if (!wmoData.texturePaths.ContainsKey(material.TextureId1))
                {
                    wmoData.texturePaths.Add(material.TextureId1, material.TextureId1);
                }

                if (material.TextureId1 != 0)
                {
                    Texture2Ddata textureData = new Texture2Ddata();
                    Stream        stream      = Handler.OpenFile(material.TextureId1);
                    BLP           blp         = new BLP();
                    byte[]        data        = blp.GetUncompressed(stream, true);
                    BLPinfo       info        = blp.Info();
                    textureData.hasMipmaps    = info.hasMipmaps;
                    textureData.width         = info.width;
                    textureData.height        = info.height;
                    textureData.textureFormat = info.textureFormat;
                    textureData.TextureData   = data;
                    stream.Close();
                    stream.Dispose();
                    LoadedBLPs.Add(material.TextureId1);

                    if (!wmoData.textureData.ContainsKey(material.TextureId1))
                    {
                        wmoData.textureData.Add(material.TextureId1, textureData);
                    }
                }
            }
        }   // loaded
コード例 #12
0
        /// <summary>
        /// Creates a renderable object from the specified BLP object, aand the specified <see cref="FileReference"/>
        /// it is associated with.
        /// NOTE: This method *must* be called in the UI thread after the OpenGL context has been made current.
        ///
        /// The <see cref="IRenderable"/> constructors commonly make extensive use of OpenGL methods.
        /// </summary>
        /// <param name="binaryImage">The image object.</param>
        /// <param name="fileReference">The package group it belongs to.</param>
        /// <returns>An encapsulated renderable OpenGL object.</returns>
        public static IRenderable CreateRenderableBinaryImage(BLP binaryImage, FileReference fileReference)
        {
            if (binaryImage == null)
            {
                return(null);
            }

            RenderableBLP renderableImage = new RenderableBLP(binaryImage, fileReference.FilePath);

            return(renderableImage);
        }
コード例 #13
0
        /// <summary>
        /// Creates a cached texture for the specifed texture, using the specified path
        /// as a lookup key.
        /// </summary>
        public int CreateCachedTexture(BLP texture, string texturePath, TextureWrapMode textureWrapMode = TextureWrapMode.Repeat)
        {
            if (texture == null)
            {
                throw new ArgumentNullException(nameof(texture));
            }

            int textureID = GL.GenTexture();

            if (texture.GetCompressionType() == TextureCompressionType.DXTC)
            {
                try
                {
                    LoadDXTTexture(textureID, texture);
                }
                catch (GraphicsErrorException gex)
                {
                    Log.Warn($"GraphicsErrorException in CreateCachedTexture (failed to create DXT texture): {gex.Message}\n" +
                             "The texture will be loaded as a bitmap instead.");
                }
                finally
                {
                    // Load a fallback bitmap instead
                    using (Bitmap mipZero = texture.GetMipMap(0))
                    {
                        LoadBitmapTexture(textureID, mipZero);
                    }
                }
            }
            else
            {
                using (Bitmap mipZero = texture.GetMipMap(0))
                {
                    LoadBitmapTexture(textureID, mipZero);
                }
            }

            // Use linear mipmapped filtering
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.LinearMipmapLinear);

            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)textureWrapMode);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)textureWrapMode);

            int maximalMipLevel = texture.GetMipMapCount() == 0 ? 0 : texture.GetMipMapCount() - 1;

            GL.TexParameterI(TextureTarget.Texture2D, TextureParameterName.TextureMaxLevel, ref maximalMipLevel);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureBaseLevel, 0);

            this.GLTextureCache.Add(texturePath.ConvertPathSeparatorsToCurrentNativeSeparator().ToUpperInvariant(), textureID);
            return(textureID);
        }
コード例 #14
0
        /// <summary>
        /// Gets a <see cref="Texture2D"/> instance from the cache. If the texture is not already cached, it is
        /// extracted from the given <see cref="IPackage"/>. If it is cached, the cached version is returned. If no
        /// texture can be extracted, a fallback texture is returned.
        /// </summary>
        /// <param name="texturePath">The path to the texture in the package.</param>
        /// <param name="package">The package where the texture is stored.</param>
        /// <param name="wrappingModeS">The wrapping mode to use for the texture on the S axis.</param>
        /// <param name="wrappingModeT">The wrapping mode to use for the texture on the T axis.</param>
        /// <returns>A <see cref="Texture2D"/> object.</returns>
        public Texture2D GetTexture(string texturePath, IPackage package, TextureWrapMode wrappingModeS = TextureWrapMode.Repeat, TextureWrapMode wrappingModeT = TextureWrapMode.Repeat)
        {
            ThrowIfDisposed();

            if (HasCachedTextureForPath(texturePath))
            {
                return(GetCachedTexture(texturePath));
            }

            try
            {
                WarcraftFileType textureType = FileInfoUtilities.GetFileType(texturePath);
                switch (textureType)
                {
                case WarcraftFileType.BinaryImage:
                {
                    var textureData = package.ExtractFile(texturePath);

                    if (textureData == null)
                    {
                        return(this.FallbackTexture);
                    }

                    BLP texture = new BLP(textureData);
                    return(CreateCachedTexture(texture, texturePath, wrappingModeS, wrappingModeT));
                }

                case WarcraftFileType.BitmapImage:
                case WarcraftFileType.GIFImage:
                case WarcraftFileType.IconImage:
                case WarcraftFileType.PNGImage:
                case WarcraftFileType.JPGImage:
                case WarcraftFileType.TargaImage:
                {
                    using (MemoryStream ms = new MemoryStream(package.ExtractFile(texturePath)))
                    {
                        Bitmap texture = new Bitmap(ms);
                        return(CreateCachedTexture(texture, texturePath));
                    }
                }
                }
            }
            catch (InvalidFileSectorTableException fex)
            {
                Log.Warn
                (
                    $"Failed to load the texture \"{texturePath}\" due to an invalid sector table (\"{fex.Message}\").\nA fallback texture has been loaded instead."
                );
            }

            return(this.FallbackTexture);
        }
コード例 #15
0
        /// <summary>
        /// Loads the specified compressed image (in <see cref="BLP"/> format) into a native OpenGL texture.
        /// </summary>
        /// <param name="textureID">The ID of the texture to load the image into.</param>
        /// <param name="compressedImage">The compressed image to load.</param>
        /// <exception cref="ArgumentException">
        /// Thrown if the image format does not match the pixel format.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// Thrown if the input image is null.
        /// </exception>
        private static void LoadDXTTexture(int textureID, BLP compressedImage)
        {
            if (compressedImage == null)
            {
                throw new ArgumentNullException(nameof(compressedImage));
            }

            GL.BindTexture(TextureTarget.Texture2D, textureID);

            // Load the set of raw compressed mipmaps
            for (uint i = 0; i < compressedImage.GetMipMapCount(); ++i)
            {
                byte[]     compressedMipMap = compressedImage.GetRawMipMap(i);
                Resolution mipResolution    = compressedImage.GetMipLevelResolution(i);

                PixelInternalFormat compressionFormat;
                switch (compressedImage.GetPixelFormat())
                {
                case BLPPixelFormat.DXT1:
                {
                    compressionFormat = PixelInternalFormat.CompressedRgbaS3tcDxt1Ext;
                    break;
                }

                case BLPPixelFormat.DXT3:
                {
                    compressionFormat = PixelInternalFormat.CompressedRgbaS3tcDxt3Ext;
                    break;
                }

                case BLPPixelFormat.DXT5:
                {
                    compressionFormat = PixelInternalFormat.CompressedRgbaS3tcDxt5Ext;
                    break;
                }

                default:
                {
                    throw new ArgumentException($"Image format (DXTC) did not match pixel format: {compressedImage.GetPixelFormat()}", nameof(Image));
                }
                }

                // Load the mipmap into the texture
                GL.CompressedTexImage2D(TextureTarget.Texture2D, (int)i,
                                        compressionFormat,
                                        (int)mipResolution.X,
                                        (int)mipResolution.Y,
                                        0,
                                        compressedMipMap.Length,
                                        compressedMipMap);
            }
        }
コード例 #16
0
ファイル: RenderCache.cs プロジェクト: znerxx/Everlook
        /// <summary>
        /// Gets a <see cref="Texture2D"/> instance from the cache. If the texture is not already cached, it is
        /// extracted from the given <see cref="IPackage"/>. If it is cached, the cached version is returned. If no
        /// texture can be extracted, a fallback texture is returned.
        /// </summary>
        /// <param name="texturePath">The path to the texture in the package.</param>
        /// <param name="package">The package where the texture is stored.</param>
        /// <param name="wrappingModeS">The wrapping mode to use for the texture on the S axis.</param>
        /// <param name="wrappingModeT">The wrapping mode to use for the texture on the T axis.</param>
        /// <returns>A <see cref="Texture2D"/> object.</returns>
        public Texture2D GetTexture
        (
            string texturePath,
            IPackage package,
            TextureWrapMode wrappingModeS = TextureWrapMode.Repeat,
            TextureWrapMode wrappingModeT = TextureWrapMode.Repeat
        )
        {
            ThrowIfDisposed();

            if (HasCachedTextureForPath(texturePath))
            {
                return(GetCachedTexture(texturePath));
            }

            var textureType = FileInfoUtilities.GetFileType(texturePath);

            switch (textureType)
            {
            case WarcraftFileType.BinaryImage:
            {
                if (!package.TryExtractFile(texturePath, out var textureData))
                {
                    return(this.FallbackTexture);
                }

                var texture = new BLP(textureData);
                return(CreateCachedTexture(texture, texturePath, wrappingModeS, wrappingModeT));
            }

            case WarcraftFileType.BitmapImage:
            case WarcraftFileType.GIFImage:
            case WarcraftFileType.IconImage:
            case WarcraftFileType.PNGImage:
            case WarcraftFileType.JPGImage:
            case WarcraftFileType.TargaImage:
            {
                if (!package.TryExtractFile(texturePath, out var data))
                {
                    return(this.FallbackTexture);
                }

                using (var ms = new MemoryStream(data))
                {
                    var texture = new Bitmap(ms);
                    return(CreateCachedTexture(texture, texturePath));
                }
            }
            }

            return(this.FallbackTexture);
        }
コード例 #17
0
        public IActionResult OnPost(long bookId, string returnUrl)
        {
            BLP bLP = repository.BLPs
                      .FirstOrDefault(p => p.BookId == bookId);

/*            Cart = HttpContext.Session.GetJson<Cart>("cart") ?? new Cart();
 */          /*Method to add a new book */
            Cart.AddItem(bLP, 1);

/*            HttpContext.Session.SetJson("cart", Cart);
 */
            return(RedirectToPage(new { returnUrl = returnUrl }));
        }
コード例 #18
0
        public IActionResult OnPostRemove(long bookId, string returnUrl)
        {
            BLP bLP = repository.BLPs
                      .FirstOrDefault(p => p.BookId == bookId);

            Cart = HttpContext.Session.GetJson <Cart>("cart") ?? new Cart();

/*            if we find the same id already exist, remove it from the db and return to the url
 */         Cart.RemoveLine(Cart.Lines.First(c =>
                                             c.Project.BookId == bookId).Project);

            HttpContext.Session.SetJson("cart", Cart);

            return(RedirectToPage(new { returnUrl = returnUrl }));
        }
コード例 #19
0
ファイル: RenderCache.cs プロジェクト: znerxx/Everlook
        /// <summary>
        /// Creates a cached texture for the specified texture, using the specified path
        /// as a lookup key. This method will create a new texture, and cache it.
        /// </summary>
        /// /// <param name="imageData">A bitmap containing the image data.</param>
        /// <param name="texturePath">
        /// The path to the texture in its corresponding package group. This is used as a lookup key.
        /// </param>
        /// <param name="wrappingModeS">How the texture should wrap on the S axis.</param>
        /// <param name="wrappingModeT">How the texture should wrap on the T axis.</param>
        /// <returns>A new cached texture created from the data.</returns>
        public Texture2D CreateCachedTexture
        (
            BLP imageData,
            string texturePath,
            TextureWrapMode wrappingModeS = TextureWrapMode.Repeat,
            TextureWrapMode wrappingModeT = TextureWrapMode.Repeat
        )
        {
            ThrowIfDisposed();

            var texture = new Texture2D(imageData, wrappingModeS, wrappingModeT);

            _textureCache.Add(texturePath.ConvertPathSeparatorsToCurrentNativeSeparator().ToUpperInvariant(), texture);
            return(texture);
        }
コード例 #20
0
 private void CacheTexture(string texturePath, TextureWrapMode textureWrapMode = TextureWrapMode.Repeat)
 {
     if (Cache.HasCachedTextureForPath(texturePath))
     {
         if (!this.textureLookup.ContainsKey(texturePath))
         {
             this.textureLookup.Add(texturePath, Cache.GetCachedTexture(texturePath));
         }
     }
     else
     {
         BLP texture = new BLP(ModelPackageGroup.ExtractFile(texturePath));
         this.textureLookup.Add(texturePath, Cache.CreateCachedTexture(texture, texturePath, textureWrapMode));
     }
 }
コード例 #21
0
    private void AssignMinimapTexture(GameObject MinimapObject, string minimapName)
    {
        string path          = @"world\minimaps\" + minimapName + @"\" + MinimapObject.name + ".blp";
        string extractedPath = Casc.GetFile(path);
        Stream stream        = File.Open(extractedPath, FileMode.Open);

        byte[]    data = BLP.GetUncompressed(stream, false);
        BLPinfo   info = BLP.Info();
        Texture2D tex  = new Texture2D(info.width, info.height, BLP.TxFormat(), false);

        tex.LoadRawTextureData(data);
        MinimapObject.GetComponent <RawImage>().texture = tex;
        MinimapObject.GetComponent <RawImage>().uvRect  = new Rect(0, 0, 1, -1);
        tex.Apply();
        stream.Close();
        BLP.Close();
    }
コード例 #22
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++;
                }
            }
        }
    }
コード例 #23
0
        private void LoadInformation()
        {
            string ImageFilename = System.IO.Path.GetFileNameWithoutExtension(ExtensionMethods.ConvertPathSeparatorsToCurrentNativeSeparator(ExportTarget.ItemPath));

            this.Title = $"Export Image | {ImageFilename}";

            byte[] file = ExportTarget.Extract();
            Image = new BLP(file);

            ExportFormatComboBox.Active = (int)Config.GetDefaultImageFormat();

            MipLevelListStore.Clear();
            foreach (string mipString in Image.GetMipMapLevelStrings())
            {
                MipLevelListStore.AppendValues(true, mipString);
            }

            ExportDirectoryFileChooserButton.SetFilename(Config.GetDefaultExportDirectory());
        }
コード例 #24
0
        /// <summary>
        /// Loads the information from the image into the UI.
        /// </summary>
        private void LoadInformation()
        {
            string imageFilename = IOPath.GetFileNameWithoutExtension(this.ExportTarget.FilePath.ConvertPathSeparatorsToCurrentNativeSeparator());

            this.Title = $"Export Image | {imageFilename}";

            byte[] file = this.ExportTarget.Extract();
            this.Image = new BLP(file);

            this.ExportFormatComboBox.Active = (int)this.Config.DefaultImageExportFormat;

            this.MipLevelListStore.Clear();
            foreach (string mipString in this.Image.GetMipMapLevelStrings())
            {
                this.MipLevelListStore.AppendValues(true, mipString);
            }

            this.ExportDirectoryFileChooserButton.SetFilename(this.Config.DefaultExportDirectory);
        }
コード例 #25
0
        /// <summary>
        /// Read the Textures from the Tex0 adt.
        /// </summary>
        public static void ReadTextures(BinaryReader reader, uint chunkSize, ADTModel data)
        {
            var textureSize = chunkSize / 4;

            for (var i = 0; i < textureSize; ++i)
            {
                var texFileDataId = reader.ReadUInt32();
                if (!data.TextureFileDataId.Contains(texFileDataId))
                {
                    var textureData = BLP.Open(texFileDataId);
                    if (textureData == null)
                    {
                        continue;
                    }

                    data.TextureFileDataId.Add(texFileDataId);
                    data.TextureDatas.Add(texFileDataId, textureData);
                }
            }
        }
コード例 #26
0
    // Request a minimap image from the parser //
    private static void RequestBlock(Minimap.MinimapRequest minimapRequest)
    {
        string mapName       = minimapRequest.mapName;
        string fileName      = "map" + minimapRequest.coords.x + "_" + minimapRequest.coords.y + ".blp";
        string path          = @"world\minimaps\" + mapName + @"\" + fileName;
        string extractedPath = Casc.GetFile(path);

        using (Stream stream = File.Open(extractedPath, FileMode.Open))
        {
            BLP     blp  = new BLP();
            byte[]  data = blp.GetUncompressed(stream, true);
            BLPinfo info = blp.Info();
            MinimapData.MinimapBlockData blockData = new MinimapData.MinimapBlockData();
            blockData.mapName         = mapName;
            blockData.coords          = minimapRequest.coords;
            blockData.textureInfo     = info;
            blockData.minimapByteData = data;

            MinimapData.MinimapDataQueue.Enqueue(blockData);
        }
    }
コード例 #27
0
 private void CacheTexture(string texturePath, TextureWrapMode textureWrapMode = TextureWrapMode.Repeat)
 {
     if (this.Cache.HasCachedTextureForPath(texturePath))
     {
         if (!this.textureLookup.ContainsKey(texturePath))
         {
             this.textureLookup.Add(texturePath, this.Cache.GetCachedTexture(texturePath));
         }
     }
     else
     {
         try
         {
             BLP texture = new BLP(this.ModelPackageGroup.ExtractFile(texturePath));
             this.textureLookup.Add(texturePath, this.Cache.CreateCachedTexture(texture, texturePath, textureWrapMode));
         }
         catch (InvalidFileSectorTableException fex)
         {
             Log.Warn($"Failed to load the texture \"{texturePath}\" due to an invalid sector table (\"{fex.Message}\").\n" +
                      $" A fallback texture has been loaded instead.");
             this.textureLookup.Add(texturePath, this.Cache.FallbackTexture);
         }
     }
 }
コード例 #28
0
    // texture paths //
    public static void ReadMOTX(Stream WMOrootstream, int MOTXsize)
    {
        long currentPos = WMOrootstream.Position;

        while (WMOrootstream.Position < currentPos + MOTXsize)
        {
            int    position = (int)(WMOrootstream.Position - currentPos);
            string path     = ReadNullTerminatedString(WMOrootstream);
            if (path != "") //&& !wmoData.textureData.ContainsKey(path))
            {
                wmoData.texturePaths.Add(position, path);
                if (!LoadedBLPs.Contains(path))
                {
                    string extractedPath = Casc.GetFile(path);
                    if (File.Exists(extractedPath))
                    {
                        Stream        stream        = File.Open(extractedPath, FileMode.Open);
                        BLP           blp           = new BLP();
                        byte[]        data          = blp.GetUncompressed(stream, true);
                        BLPinfo       info          = blp.Info();
                        Texture2Ddata texture2Ddata = new Texture2Ddata();
                        texture2Ddata.hasMipmaps    = info.hasMipmaps;
                        texture2Ddata.width         = info.width;
                        texture2Ddata.height        = info.height;
                        texture2Ddata.textureFormat = info.textureFormat;
                        texture2Ddata.TextureData   = data;
                        wmoData.textureData[path]   = texture2Ddata;
                        stream.Close();
                        stream.Dispose();
                        stream = null;
                    }
                    LoadedBLPs.Add(path);
                }
            }
        }
    } // loaded
コード例 #29
0
ファイル: M2_Main.cs プロジェクト: wzx1598763/wowedit_unity
    public static void ReadMD21(MemoryStream ms, M2Data m2Data, M2Texture m2Tex)
    {
        long md20position = ms.Position;

        StreamTools s                               = new StreamTools();
        int         MD20                            = s.ReadLong(ms);    // "MD20". Legion uses a chunked file format starting with MD21.
        int         version                         = s.ReadLong(ms);
        M2Array     name                            = s.ReadM2Array(ms); // should be globally unique, used to reload by name in internal clients
        var         flags                           = s.ReadLong(ms);
        M2Array     global_loops                    = s.ReadM2Array(ms); // Timestamps used in global looping animations.
        M2Array     sequences                       = s.ReadM2Array(ms); // Information about the animations in the model.
        M2Array     sequences_lookups               = s.ReadM2Array(ms); // Mapping of sequence IDs to the entries in the Animation sequences block.
        M2Array     bones                           = s.ReadM2Array(ms); // MAX_BONES = 0x100 => Creature\SlimeGiant\GiantSlime.M2 has 312 bones(Wrath)
        M2Array     key_bone_lookup                 = s.ReadM2Array(ms); // Lookup table for key skeletal bones.
        M2Array     vertices                        = s.ReadM2Array(ms);
        int         num_skin_profiles               = s.ReadLong(ms);
        M2Array     colors                          = s.ReadM2Array(ms); // Color and alpha animations definitions.
        M2Array     textures                        = s.ReadM2Array(ms);
        M2Array     texture_weights                 = s.ReadM2Array(ms); // Transparency of textures.
        M2Array     texture_transforms              = s.ReadM2Array(ms);
        M2Array     replaceable_texture_lookup      = s.ReadM2Array(ms);
        M2Array     materials                       = s.ReadM2Array(ms); // Blending modes / render flags.
        M2Array     bone_lookup_table               = s.ReadM2Array(ms);
        M2Array     texture_lookup_table            = s.ReadM2Array(ms);
        M2Array     tex_unit_lookup_table           = s.ReadM2Array(ms); // ≥ Cata: unused
        M2Array     transparency_lookup_table       = s.ReadM2Array(ms);
        M2Array     texture_transforms_lookup_table = s.ReadM2Array(ms);

        m2Data.bounding_box = s.ReadBoundingBox(ms);                    // min/max( [1].z, 2.0277779f ) - 0.16f seems to be the maximum camera height
        float       bounding_sphere_radius  = s.ReadFloat(ms);          // detail doodad draw dist = clamp (bounding_sphere_radius * detailDoodadDensityFade * detailDoodadDist, …)
        BoundingBox collision_box           = s.ReadBoundingBox(ms);
        float       collision_sphere_radius = s.ReadFloat(ms);

        M2Array collision_triangles     = s.ReadM2Array(ms);
        M2Array collision_vertices      = s.ReadM2Array(ms);
        M2Array collision_normals       = s.ReadM2Array(ms);
        M2Array attachments             = s.ReadM2Array(ms);            // position of equipped weapons or effects
        M2Array attachment_lookup_table = s.ReadM2Array(ms);
        M2Array events              = s.ReadM2Array(ms);                // Used for playing sounds when dying and a lot else.
        M2Array lights              = s.ReadM2Array(ms);                // Lights are mainly used in loginscreens but in wands and some doodads too.
        M2Array cameras             = s.ReadM2Array(ms);                // The cameras are present in most models for having a model in the character tab.
        M2Array camera_lookup_table = s.ReadM2Array(ms);
        M2Array ribbon_emitters     = s.ReadM2Array(ms);                // Things swirling around. See the CoT-entrance for light-trails.
        M2Array particle_emitters   = s.ReadM2Array(ms);

        // Name //
        ms.Position = name.offset + md20position;
        for (int n = 0; n < name.size; n++)
        {
            m2Data.name += Convert.ToChar(ms.ReadByte());
        }


        // Bones //
        ms.Position = bones.offset + md20position;
        M2TrackBase[] translationM2track = new M2TrackBase[bones.size];
        M2TrackBase[] rotationM22track   = new M2TrackBase[bones.size];
        M2TrackBase[] scaleM22track      = new M2TrackBase[bones.size];
        for (int cb = 0; cb < bones.size; cb++)
        {
            M2CompBone m2CompBone = new M2CompBone();

            m2CompBone.key_bone_id      = s.ReadLong(ms);               // Back-reference to the key bone lookup table. -1 if this is no key bone.
            m2CompBone.flags            = s.ReadUint32(ms);
            m2CompBone.parent_bone      = s.ReadShort(ms);
            m2CompBone.submesh_id       = s.ReadUint16(ms);
            m2CompBone.uDistToFurthDesc = s.ReadUint16(ms);
            m2CompBone.uZRatioOfChain   = s.ReadUint16(ms);

            translationM2track[cb] = s.ReadM2Track(ms);
            rotationM22track[cb]   = s.ReadM2Track(ms);
            scaleM22track[cb]      = s.ReadM2Track(ms);

            Vector3 pivotRaw = new Vector3(s.ReadFloat(ms) / Settings.worldScale, s.ReadFloat(ms) / Settings.worldScale, s.ReadFloat(ms) / Settings.worldScale);
            m2CompBone.pivot = new Vector3(-pivotRaw.x, pivotRaw.z, -pivotRaw.y);

            m2Data.m2CompBone.Add(m2CompBone);
        }


        // Animations //
        int numberOfAnimations = 0;

        for (int ab = 0; ab < bones.size; ab++)
        {
            List <Animation_Vector3>    bone_position_animations = new List <Animation_Vector3>();
            List <Animation_Quaternion> bone_rotation_animations = new List <Animation_Quaternion>();
            List <Animation_Vector3>    bone_scale_animations    = new List <Animation_Vector3>();

            // Position //
            int numberOfPositionAnimations = translationM2track[ab].Timestamps.size;
            if (numberOfAnimations < numberOfPositionAnimations)
            {
                numberOfAnimations = numberOfPositionAnimations;
            }
            for (int at = 0; at < numberOfPositionAnimations; at++)
            {
                Animation         bone_animation = new Animation();
                Animation_Vector3 positions      = new Animation_Vector3();

                // Timestamps //
                List <int> timeStamps = new List <int>();
                ms.Position = translationM2track[ab].Timestamps.offset + md20position;
                M2Array m2AnimationOffset = s.ReadM2Array(ms);
                ms.Position = m2AnimationOffset.offset;
                for (int t = 0; t < m2AnimationOffset.size; t++)
                {
                    timeStamps.Add(s.ReadLong(ms));
                }
                positions.timeStamps = timeStamps;

                // Values //
                List <Vector3> values = new List <Vector3>();
                ms.Position = translationM2track[ab].Values.offset + md20position;
                M2Array m2AnimationValues = s.ReadM2Array(ms);
                ms.Position = m2AnimationValues.offset;
                for (int t = 0; t < m2AnimationValues.size; t++)
                {
                    Vector3 rawPosition = new Vector3(s.ReadFloat(ms) / Settings.worldScale, s.ReadFloat(ms) / Settings.worldScale, s.ReadFloat(ms) / Settings.worldScale);
                    values.Add(new Vector3(-rawPosition.x, rawPosition.z, -rawPosition.y));
                }
                positions.values = values;
                bone_position_animations.Add(positions);
            }


            // Rotation //
            int numberOfRotationAnimations = rotationM22track[ab].Timestamps.size;
            if (numberOfAnimations < numberOfRotationAnimations)
            {
                numberOfAnimations = numberOfRotationAnimations;
            }
            for (int ar = 0; ar < numberOfRotationAnimations; ar++)
            {
                Animation_Quaternion rotations = new Animation_Quaternion();

                // Timestamps //
                List <int> timeStamps = new List <int>();
                ms.Position = rotationM22track[ab].Timestamps.offset + md20position;
                M2Array m2AnimationOffset = s.ReadM2Array(ms);
                ms.Position = m2AnimationOffset.offset;
                for (int t = 0; t < m2AnimationOffset.size; t++)
                {
                    timeStamps.Add(s.ReadLong(ms));
                }
                rotations.timeStamps = timeStamps;

                // Values //
                List <Quaternion> values = new List <Quaternion>();
                ms.Position = rotationM22track[ab].Values.offset + md20position;
                M2Array m2AnimationValues = s.ReadM2Array(ms);
                ms.Position = m2AnimationValues.offset;
                for (int t = 0; t < m2AnimationValues.size; t++)
                {
                    Quaternion rawRotation = s.ReadQuaternion16(ms);
                    values.Add(new Quaternion(rawRotation.x, rawRotation.y, rawRotation.z, rawRotation.w));
                }
                rotations.values = values;
                bone_rotation_animations.Add(rotations);
            }

            // Scale //
            int numberOfScaleAnimations = scaleM22track[ab].Timestamps.size;
            if (numberOfAnimations < numberOfScaleAnimations)
            {
                numberOfAnimations = numberOfScaleAnimations;
            }
            for (int aS = 0; aS < numberOfScaleAnimations; aS++)
            {
                Animation_Vector3 scales = new Animation_Vector3();

                // Timestamps //
                List <int> timeStamps = new List <int>();
                ms.Position = scaleM22track[ab].Timestamps.offset + md20position;
                M2Array m2AnimationOffset = s.ReadM2Array(ms);
                ms.Position = m2AnimationOffset.offset;
                for (int t = 0; t < m2AnimationOffset.size; t++)
                {
                    timeStamps.Add(s.ReadLong(ms));
                }
                scales.timeStamps = timeStamps;

                // Values //
                List <Vector3> values = new List <Vector3>();
                ms.Position = scaleM22track[ab].Values.offset + md20position;
                M2Array m2AnimationValues = s.ReadM2Array(ms);
                ms.Position = m2AnimationValues.offset;
                for (int t = 0; t < m2AnimationValues.size; t++)
                {
                    Vector3 rawScale = new Vector3(s.ReadFloat(ms) / Settings.worldScale, s.ReadFloat(ms) / Settings.worldScale, s.ReadFloat(ms) / Settings.worldScale);
                    values.Add(new Vector3(-rawScale.x, rawScale.z, -rawScale.y));
                }
                scales.values = values;
                bone_scale_animations.Add(scales);
            }
            //Debug.Log(numberOfPositionAnimations + " " + numberOfRotationAnimations + " " + numberOfScaleAnimations);
            m2Data.position_animations.Add(bone_position_animations);
            m2Data.rotation_animations.Add(bone_rotation_animations);
            m2Data.scale_animations.Add(bone_scale_animations);
        }
        m2Data.numberOfAnimations = numberOfAnimations;

        // Bone Lookup Table //
        ms.Position = bone_lookup_table.offset + md20position;
        for (int blt = 0; blt < key_bone_lookup.size; blt++)
        {
            m2Data.bone_lookup_table.Add(s.ReadUint16(ms));
        }

        // Key-Bone Lookup //
        ms.Position = key_bone_lookup.offset + md20position;
        for (int kbl = 0; kbl < key_bone_lookup.size; kbl++)
        {
            m2Data.key_bone_lookup.Add(s.ReadShort(ms));
        }

        // Vertices //
        ms.Position     = vertices.offset + md20position;
        m2Data.meshData = new MeshData();
        for (int v = 0; v < vertices.size; v++)
        {
            Vector3 rawPosition = new Vector3(s.ReadFloat(ms) / Settings.worldScale, s.ReadFloat(ms) / Settings.worldScale, s.ReadFloat(ms) / Settings.worldScale);
            m2Data.meshData.pos.Add(new Vector3(-rawPosition.x, rawPosition.z, -rawPosition.y));
            m2Data.meshData.bone_weights.Add(new float[] { ms.ReadByte() / 255.0f, ms.ReadByte() / 255.0f, ms.ReadByte() / 255.0f, ms.ReadByte() / 255.0f });
            m2Data.meshData.bone_indices.Add(new int[] { ms.ReadByte(), ms.ReadByte(), ms.ReadByte(), ms.ReadByte() });
            //Debug.Log(m2Data.meshData.bone_indices[v][0] + " " + m2Data.meshData.bone_indices[v][1] + " " + m2Data.meshData.bone_indices[v][2] + " " + m2Data.meshData.bone_indices[v][3]);
            Vector3 rawnormal = new Vector3(s.ReadFloat(ms) * Settings.worldScale, s.ReadFloat(ms) * Settings.worldScale, s.ReadFloat(ms) * Settings.worldScale);
            m2Data.meshData.normal.Add(new Vector3(-rawnormal.x, rawnormal.z, -rawnormal.y));
            m2Data.meshData.tex_coords.Add(new Vector2(s.ReadFloat(ms), s.ReadFloat(ms)));
            m2Data.meshData.tex_coords2.Add(new Vector2(s.ReadFloat(ms), s.ReadFloat(ms)));
        }

        // Textures //
        ms.Position = textures.offset + md20position;
        for (int t = 0; t < textures.size; t++)
        {
            M2Texture m2Texture = new M2Texture();

            m2Texture.type  = s.ReadLong(ms);
            m2Texture.flags = s.ReadLong(ms);

            M2Array filename = s.ReadM2Array(ms);

            // seek to filename and read //
            long savePosition = ms.Position;
            ms.Position = filename.offset + md20position;
            string fileNameString = "";
            for (int n = 0; n < filename.size; n++)
            {
                fileNameString += Convert.ToChar(ms.ReadByte());
            }
            ms.Position = savePosition;

            string fileNameStringFix = fileNameString.TrimEnd(fileNameString[fileNameString.Length - 1]);
            m2Texture.filename = fileNameStringFix;

            Texture2Ddata texture2Ddata = new Texture2Ddata();

            if (fileNameStringFix.Length > 1)
            {
                if (!LoadedBLPs.Contains(fileNameStringFix))
                {
                    string  extractedPath = Casc.GetFile(fileNameStringFix);
                    Stream  stream        = File.Open(extractedPath, FileMode.Open);
                    BLP     blp           = new BLP();
                    byte[]  data          = blp.GetUncompressed(stream, true);
                    BLPinfo info          = blp.Info();
                    texture2Ddata.hasMipmaps    = info.hasMipmaps;
                    texture2Ddata.width         = info.width;
                    texture2Ddata.height        = info.height;
                    texture2Ddata.textureFormat = info.textureFormat;
                    texture2Ddata.TextureData   = data;
                    m2Texture.texture2Ddata     = texture2Ddata;
                    stream.Close();
                    stream.Dispose();
                    stream = null;
                    LoadedBLPs.Add(fileNameString);
                }
            }
            m2Data.m2Tex.Add(m2Texture);
        }

        // texture_lookup_table //
        ms.Position = texture_lookup_table.offset + md20position;
        for (int tl = 0; tl < texture_lookup_table.size; tl++)
        {
            m2Data.textureLookupTable.Add(s.ReadUint16(ms));
        }
    }