Пример #1
0
        private void RefreshTextures()
        {
            if (RootJOBJ == null)
            {
                return;
            }
            Surfaces.Clear();
            tobjToSurface.Clear();
            var tobjs = GetTOBJS();
            List <HSD_Image> Process = new List <HSD_Image>();

            foreach (var tobj in tobjs)
            {
                var surface = new SBSurface();
                surface.Name = "TOBJ_" + tobjs.IndexOf(tobj);
                surface.Arrays.Add(new MipArray()
                {
                    Mipmaps = new List <byte[]>()
                    {
                        tobj.GetDecodedImageData()
                    }
                });
                surface.Width          = tobj.ImageData.Width;
                surface.Height         = tobj.ImageData.Height;
                surface.PixelFormat    = PixelFormat.Bgra;
                surface.PixelType      = PixelType.UnsignedByte;
                surface.InternalFormat = InternalFormat.Rgba;
                tobjToSurface.Add(tobj._s, surface);
                Surfaces.Add(surface);
            }
        }
Пример #2
0
 /// <summary>
 /// Remove all surface targets and revert back to the default game surface.
 /// </summary>
 public void ClearSurfaces()
 {
     if (Surfaces == null)
     {
         Surfaces = new List <Surface>();
     }
     Surfaces.Clear();
 }
Пример #3
0
        public void LoadTexture(Texture tex, int target = 1)
        {
            Surfaces.Clear();

            try
            {
                uint blk_dim   = Formats.blk_dims((uint)((int)tex.Format >> 8));
                uint blkWidth  = blk_dim >> 4;
                uint blkHeight = blk_dim & 0xF;

                int linesPerBlockHeight = (1 << (int)tex.BlockHeightLog2) * 8;

                uint bpp = Formats.bpps((uint)((int)tex.Format >> 8));
                for (int arrayLevel = 0; arrayLevel < tex.ArrayLength; arrayLevel++)
                {
                    int           blockHeightShift = 0;
                    List <byte[]> mips             = new List <byte[]>();
                    for (int mipLevel = 0; mipLevel < tex.TextureData[arrayLevel].Count; mipLevel++)
                    {
                        uint width  = (uint)Math.Max(1, tex.Width >> mipLevel);
                        uint height = (uint)Math.Max(1, tex.Height >> mipLevel);

                        uint size = TegraX1Swizzle.DIV_ROUND_UP(width, blkWidth) * TegraX1Swizzle.DIV_ROUND_UP(height, blkHeight) * bpp;

                        if (TegraX1Swizzle.pow2_round_up(TegraX1Swizzle.DIV_ROUND_UP(height, blkWidth)) < linesPerBlockHeight)
                        {
                            blockHeightShift += 1;
                        }

                        byte[] result = TegraX1Swizzle.deswizzle(width, height, blkWidth, blkHeight, target, bpp, (uint)tex.TileMode, (int)Math.Max(0, tex.BlockHeightLog2 - blockHeightShift), tex.TextureData[arrayLevel][mipLevel]);
                        //Create a copy and use that to remove uneeded data
                        byte[] result_ = new byte[size];
                        Array.Copy(result, 0, result_, 0, size);
                        mips.Add(result_);
                    }
                    Surfaces.Add(new Surface()
                    {
                        mipmaps = mips
                    });
                }

                Texture = tex;
            }
            catch (Exception e)
            {
                MessageBox.Show($"Failed to swizzle texture {Text}! Exception: {e}");
            }
        }
Пример #4
0
        private void fixSurfaces()
        {
            if (!fixedSurfaces)
            {
                Color origFill    = Water.FillColor;
                Color origSurface = Water.SurfaceColor;

                changeColor(fillColorField, origFill, fillColor);
                changeColor(surfaceColorField, origSurface, surfaceColor);

                bool hasTop    = Surfaces.Contains(TopSurface);
                bool hasBottom = Surfaces.Contains(BottomSurface);

                Surfaces.Clear();

                if (hasTop)
                {
                    TopSurface = new Water.Surface(Position + new Vector2(Width / 2f, 8f), new Vector2(0.0f, -1f), Width, Height);
                    Surfaces.Add(TopSurface);

                    actualTopSurface = TopSurface;
                    dummyTopSurface  = new Water.Surface(Position + new Vector2(Width / 2f, 8f), new Vector2(0.0f, -1f), Width, Height);
                }

                if (hasBottom)
                {
                    BottomSurface = new Water.Surface(Position + new Vector2(Width / 2f, Height - 8f), new Vector2(0.0f, 1f), Width, Height);
                    Surfaces.Add(BottomSurface);

                    actualBottomSurface = BottomSurface;
                    dummyBottomSurface  = new Water.Surface(Position + new Vector2(Width / 2f, Height - 8f), new Vector2(0.0f, 1f), Width, Height);
                }

                fixedSurfaces  = true;
                actualSurfaces = Surfaces;
                emptySurfaces  = new List <Surface>();

                changeColor(fillColorField, fillColor, origFill);
                changeColor(surfaceColorField, surfaceColor, origSurface);
            }
        }
Пример #5
0
 /// <summary>
 /// Remove all Surfaces from the list of Surfaces that the Entity should render to.
 /// </summary>
 public void ClearSurfaces()
 {
     Surfaces.Clear();
 }
Пример #6
0
        public void LoadTexture(int target = 1)
        {
            Surfaces.Clear();

            uint blk_dim   = blk_dims((byte)Format);
            uint blkWidth  = blk_dim >> 4;
            uint blkHeight = blk_dim & 0xF;

            uint blockHeight     = TegraX1Swizzle.GetBlockHeight(TegraX1Swizzle.DIV_ROUND_UP(Height, blkHeight));
            uint BlockHeightLog2 = (uint)Convert.ToString(blockHeight, 2).Length - 1;
            uint tileMode        = 0;

            int linesPerBlockHeight = (1 << (int)BlockHeightLog2) * 8;

            uint bpp = bpps((byte)Format);

            for (int arrayLevel = 0; arrayLevel < mipSizes.Count; arrayLevel++)
            {
                int  blockHeightShift = 0;
                uint mipOffset        = 0;

                List <byte[]> mips = new List <byte[]>();
                for (int mipLevel = 0; mipLevel < mipSizes[arrayLevel].Length; mipLevel++)
                {
                    //Get the size from the size array
                    int MipSize = (int)mipSizes[arrayLevel][mipLevel];

                    //Align the size
                    if (mipLevel == 0)
                    {
                        if (MipSize % Alignment != 0)
                        {
                            MipSize = MipSize + (Alignment - (MipSize % Alignment));
                        }
                    }

                    uint width  = (uint)Math.Max(1, Width >> mipLevel);
                    uint height = (uint)Math.Max(1, Height >> mipLevel);

                    uint size = TegraX1Swizzle.DIV_ROUND_UP(width, blkWidth) * TegraX1Swizzle.DIV_ROUND_UP(height, blkHeight) * bpp;

                    if (TegraX1Swizzle.pow2_round_up(TegraX1Swizzle.DIV_ROUND_UP(height, blkWidth)) < linesPerBlockHeight)
                    {
                        blockHeightShift += 1;
                    }

                    Console.WriteLine($"{blk_dim.ToString("x")} {bpp} {width} {height} {linesPerBlockHeight} {blkWidth} {blkHeight} {size} { ImageData.Length}");

                    try
                    {
                        byte[] result = TegraX1Swizzle.deswizzle(width, height, blkWidth, blkHeight, target, bpp, tileMode, (int)Math.Max(0, BlockHeightLog2 - blockHeightShift), ImageData);
                        //Create a copy and use that to remove uneeded data
                        byte[] result_ = new byte[size];
                        Array.Copy(result, mipOffset, result_, 0, size);

                        mips.Add(result_);
                    }
                    catch (Exception e)
                    {
                        System.Windows.Forms.MessageBox.Show($"Failed to swizzle texture {Text}!");
                        Console.WriteLine(e);
                        BadSwizzle = true;
                        break;
                    }
                    mipOffset += (uint)MipSize;
                    break;
                }
                Surfaces.Add(new Surface()
                {
                    mipmaps = mips
                });
            }
        }
Пример #7
0
        private void initializeSurfaces()
        {
            Color origFill    = Water.FillColor;
            Color origSurface = Water.SurfaceColor;

            changeColor(fillColorField, origFill, fillColor);
            changeColor(surfaceColorField, origSurface, surfaceColor);

            bool hasTop    = Surfaces.Contains(TopSurface);
            bool hasBottom = Surfaces.Contains(BottomSurface);

            Surfaces.Clear();

            if (hasTop)
            {
                TopSurface = new Water.Surface(Position + new Vector2(Width / 2f, 8f), new Vector2(0.0f, -1f), Width, Height);
                Surfaces.Add(TopSurface);

                actualTopSurface = TopSurface;
                dummyTopSurface  = new Water.Surface(Position + new Vector2(Width / 2f, 8f), new Vector2(0.0f, -1f), Width, Height);
            }

            if (hasBottom)
            {
                BottomSurface = new Water.Surface(Position + new Vector2(Width / 2f, Height - 8f), new Vector2(0.0f, 1f), Width, Height);
                Surfaces.Add(BottomSurface);

                actualBottomSurface = BottomSurface;
                dummyBottomSurface  = new Water.Surface(Position + new Vector2(Width / 2f, Height - 8f), new Vector2(0.0f, 1f), Width, Height);
            }

            if (hasLeftSurface)
            {
                LeftSurface = new Water.Surface(Position + new Vector2(8, Height / 2), new Vector2(-1f, 0f), Height, Width);
                Surfaces.Add(LeftSurface);

                actualLeftSurface = LeftSurface;
                dummyLeftSurface  = new Water.Surface(Position + new Vector2(8, Height / 2), new Vector2(-1f, 0f), Height, Width);
            }

            if (hasRightSurface)
            {
                RightSurface = new Water.Surface(Position + new Vector2(Width - 8, Height / 2), new Vector2(1f, 0f), Height, Width);
                Surfaces.Add(RightSurface);

                actualRightSurface = RightSurface;
                dummyRightSurface  = new Water.Surface(Position + new Vector2(Width - 8, Height / 2), new Vector2(1f, 0f), Height, Width);
            }

            // Update fill rectangle
            if (!hasUpdatedFill && (hasLeftSurface || hasRightSurface))
            {
                Rectangle fill     = (Rectangle)fillField.GetValue(this);
                int       newX     = fill.X;
                int       newWidth = fill.Width;

                if (hasLeftSurface)
                {
                    newX     += 8;
                    newWidth -= 8;
                }

                if (hasRightSurface)
                {
                    newWidth -= 8;
                }

                Rectangle newFill = new Rectangle(newX, fill.Y, newWidth, fill.Height);

                fillField.SetValue(this, newFill);

                hasUpdatedFill = true;
            }

            actualSurfaces = Surfaces;
            emptySurfaces  = new List <Surface>();

            changeColor(fillColorField, fillColor, origFill);
            changeColor(surfaceColorField, surfaceColor, origSurface);
        }
Пример #8
0
            public void LoadTexture()
            {
                Surfaces.Clear();

                Console.WriteLine(Format);

                uint blk_dim   = XTXFormats.blk_dims((uint)((int)Format >> 8));
                uint blkWidth  = blk_dim >> 4;
                uint blkHeight = blk_dim & 0xF;

                uint blockHeight     = TegraX1Swizzle.GetBlockHeight(TegraX1Swizzle.DIV_ROUND_UP(Height, blkHeight));
                uint BlockHeightLog2 = (uint)Convert.ToString(blockHeight, 2).Length - 1;

                int linesPerBlockHeight = (1 << (int)BlockHeightLog2) * 8;

                int TileMode = 0;

                uint          bpp  = XTXFormats.bpps((uint)Format);
                List <byte[]> mips = new List <byte[]>();

                int blockHeightShift = 0;

                for (int mipLevel = 0; mipLevel < MipOffsets.Length; mipLevel++)
                {
                    uint width  = (uint)Math.Max(1, Width >> mipLevel);
                    uint height = (uint)Math.Max(1, Height >> mipLevel);

                    //  uint size = width * height * bpp;
                    uint size = TegraX1Swizzle.DIV_ROUND_UP(width, blkWidth) * TegraX1Swizzle.DIV_ROUND_UP(height, blkHeight) * bpp;

                    byte[] Output = new byte[size];

                    uint mipOffset;
                    if (mipLevel != 0)
                    {
                        mipOffset = (MipOffsets[mipLevel - 1]);
                        if (mipLevel == 1)
                        {
                            mipOffset -= (uint)size;
                        }

                        Array.Copy(ImageData, mipOffset, Output, 0, size);
                    }
                    else
                    {
                        Output = ImageData;
                    }

                    byte[] output = new byte[size];
                    Console.WriteLine(mipLevel + " " + size);

                    if (TegraX1Swizzle.pow2_round_up(TegraX1Swizzle.DIV_ROUND_UP(height, blkWidth)) < linesPerBlockHeight)
                    {
                        blockHeightShift += 1;
                    }

                    byte[] result = TegraX1Swizzle.deswizzle(width, height, blkWidth, blkHeight, (int)Target, bpp, (uint)TileMode, (int)Math.Max(0, BlockHeightLog2 - blockHeightShift), Output);
                    //Create a copy and use that to remove uneeded data
                    byte[] result_ = new byte[size];
                    Array.Copy(result, 0, result_, 0, size);

                    mips.Add(result_);
                }
                Surfaces.Add(new Surface()
                {
                    mipmaps = mips
                });
            }