Esempio n. 1
0
        /// <summary>
        /// Retreives the raw pixel data for each texture, collated into a class to hold them.
        /// </summary>
        /// <returns>The texure map data</returns>
        private static async Task <TexMapData> GetTexMapData(Tex tex, XivMtrl mtrl)
        {
            var texMapData = new TexMapData();

            // Use the function that returns proper sane reuslts.
            var ttps = mtrl.GetTextureTypePathList();

            foreach (var ttp in ttps)
            {
                if (ttp.Type != XivTexType.ColorSet)
                {
                    var texData = await tex.GetTexData(ttp);

                    var imageData = await tex.GetImageData(texData);

                    switch (ttp.Type)
                    {
                    case XivTexType.Diffuse:
                        texMapData.Diffuse = new TexInfo {
                            Width = texData.Width, Height = texData.Height, Data = imageData
                        };
                        break;

                    case XivTexType.Specular:
                    case XivTexType.Multi:
                    case XivTexType.Skin:
                        texMapData.Specular = new TexInfo {
                            Width = texData.Width, Height = texData.Height, Data = imageData
                        };;
                        break;

                    case XivTexType.Normal:
                        texMapData.Normal = new TexInfo {
                            Width = texData.Width, Height = texData.Height, Data = imageData
                        };;
                        break;

                    default:
                        // Do not render textures that we do not know how to use
                        break;
                    }
                }
            }

            if (mtrl.ColorSetDataSize > 0)
            {
                var colorSetData = new List <byte>();
                foreach (var half in mtrl.ColorSetData)
                {
                    var colorByte = (byte)(half * 255);

                    if (half > 1)
                    {
                        colorByte = 255;
                    }

                    colorSetData.Add(colorByte);
                }

                texMapData.ColorSet = new TexInfo {
                    Width = 4, Height = 16, Data = colorSetData.ToArray()
                };;
            }

            return(texMapData);
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the data for the texture map
        /// </summary>
        /// <returns>The texure map data</returns>
        private TexMapData GetTexMapData()
        {
            var tex = new Tex(_gameDirectory);

            var texMapData = new TexMapData();

            foreach (var texTypePath in _mtrlData.TextureTypePathList)
            {
                if (texTypePath.Type != XivTexType.ColorSet)
                {
                    var texData = tex.GetTexData(texTypePath);

                    var imageData = tex.GetImageData(texData);

                    switch (texTypePath.Type)
                    {
                    case XivTexType.Diffuse:
                        texMapData.Diffuse = new TexInfo {
                            Width = texData.Width, Height = texData.Height, Data = imageData
                        };
                        break;

                    case XivTexType.Specular:
                        texMapData.Specular = new TexInfo {
                            Width = texData.Width, Height = texData.Height, Data = imageData
                        };;
                        break;

                    case XivTexType.Normal:
                        texMapData.Normal = new TexInfo {
                            Width = texData.Width, Height = texData.Height, Data = imageData
                        };;
                        break;

                    case XivTexType.Multi:
                        texMapData.Multi = new TexInfo {
                            Width = texData.Width, Height = texData.Height, Data = imageData
                        };;
                        break;

                    case XivTexType.Skin:
                        texMapData.Skin = new TexInfo {
                            Width = texData.Width, Height = texData.Height, Data = imageData
                        };;
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }
            }

            foreach (var texPath in _mtrlData.TexturePathList)
            {
                if (texPath.Contains("dummy"))
                {
                    texMapData.HasDummyTextures = true;
                    break;
                }
            }

            if (_mtrlData.ColorSetDataSize > 0)
            {
                var colorSetData = new List <byte>();
                foreach (var half in _mtrlData.ColorSetData)
                {
                    var colorByte = (byte)(half * 255);

                    if (half > 1)
                    {
                        colorByte = 255;
                    }

                    colorSetData.Add(colorByte);
                }

                texMapData.ColorSet = new TexInfo {
                    Width = 4, Height = 16, Data = colorSetData.ToArray()
                };;
            }

            return(texMapData);
        }
Esempio n. 3
0
        private async Task <TextureModel> MakeTextureModel(XivTex tex)
        {
            var layer = (int)Math.Floor(RowData[2][3] * 64);

            if (layer > 63 || layer < 0)
            {
                layer = 0;
            }
            var tileX     = (float)RowData[3][0];
            var tileY     = (float)RowData[3][3];
            var tileSkewX = (float)RowData[3][1];
            var tileSkewY = (float)RowData[3][2];

            var _tex = new Tex(XivCache.GameInfo.GameDirectory);
            var data = await _tex.GetImageData(tex, layer);

            var ogW = 32;
            var ogH = 32;
            var w   = 256;
            var h   = 256;

            Color4[] colors = new Color4[w * h];


            for (int y = 0; y < h; y++)
            {
                for (int x = 0; x < w; x++)
                {
                    var nPixel = (y * w) + x;
                    //U = Dot Product ([u,v], [Red, Green])
                    float u = (float)x / (float)w;
                    float v = ((float)y) / (float)h;

                    // This is now the new U and V coordinates we want to map to.
                    var newU = SharpDX.Vector2.Dot(new SharpDX.Vector2(u, v), new SharpDX.Vector2(tileX, tileSkewX)) % 1.0f;
                    var newV = SharpDX.Vector2.Dot(new SharpDX.Vector2(u, v), new SharpDX.Vector2(tileSkewY, tileY)) % 1.0f;

                    var xPx = (int)(newU * ogW);
                    var yPx = (int)(newV * ogH);

                    xPx = xPx < 0 ? ogW - xPx : xPx;
                    yPx = yPx < 0 ? ogH - yPx : yPx;

                    xPx = xPx >= ogW ? 0 : xPx;
                    yPx = yPx >= ogH ? 0 : yPx;


                    var ogPixel      = (yPx * ogW) + xPx;
                    var ogDataOffset = ogPixel * 4;

                    colors[nPixel] = new Color4()
                    {
                        Red   = data[ogDataOffset] / 255.0f,
                        Green = data[ogDataOffset + 1] / 255.0f,
                        Blue  = data[ogDataOffset + 2] / 255.0f,
                        Alpha = 1.0f,
                    };
                }
            }

            var tm = new TextureModel(colors, w, h);

            return(tm);
        }