Esempio n. 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);
            }
        }
Esempio n. 2
0
        public void AddEntity(IEntityG entity)
        {
            switch (entity.Type)
            {
            case EntityGType.line:
                Lines.Add((LineG)entity);
                break;

            case EntityGType.arc:
                Circles.Add((CircleG)entity);
                break;

            case EntityGType.loop:
                Loops.Add((LoopG)entity);
                break;

            case EntityGType.surf:
                Surfaces.Add((PlaneSurface)entity);
                break;

            case EntityGType.phsurf:
                PhySurfaces.Add((PhysicalSurface)entity);
                break;

            case EntityGType.phcurve:
                PhyCurves.Add((PhysicalCurve)entity);
                break;

            case EntityGType.point:
                Points.Add((PointG)entity);
                break;
            }
        }
Esempio n. 3
0
 /// <summary> Adds surface. </summary>
 internal void AddSurface(Surface surface, Action <Mesh> modifyMeshAction)
 {
     lock (Surfaces)
     {
         Surfaces.Add(new Tuple <Surface, Action <Mesh> >(surface, modifyMeshAction));
     }
 }
Esempio n. 4
0
 /// <summary>
 /// Add a surface to the list of surfaces that the scene should render to.
 /// This only applies to the Scene's graphics, NOT the entities in the scene.
 /// </summary>
 /// <param name="target"></param>
 public void AddSurface(Surface target)
 {
     if (Surfaces == null)
     {
         Surfaces = new List <Surface>();
     }
     Surfaces.Add(target);
 }
Esempio n. 5
0
 public void AddSurface(Surface newSurface)
 {
     Surfaces.Add(newSurface);
     if (newSurface.IsExterior)
     {
         ExteriorSurfaces.Add(newSurface);
     }
     DragCoefficients.Add(newSurface.DragCoefficient);
 }
Esempio n. 6
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}");
            }
        }
Esempio n. 7
0
        public GameSurfaceManager(
            ShaderManager shaders,
            Matrix4Uniform view,
            Matrix4Uniform projection)
        {
            var hex = new IndexedSurface <UVColorVertexData>()
                      .WithShader(shaders["Deferred/gSprite"])
                      .AndSettings(
                view, projection,
                new TextureUniform("diffuseTexture", new Texture(sprite("hex-diffuse.png")), TextureUnit.Texture0),
                new TextureUniform("normalTexture", new Texture(sprite("hex-normal.png")), TextureUnit.Texture1)
                );

            Surfaces.Add("hex", hex);

            SurfaceList = Surfaces.Values.ToList <Surface>().AsReadOnly();
        }
Esempio n. 8
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);
            }
        }
Esempio n. 9
0
        public override void Unpack(BinaryReader reader)
        {
            Id = reader.ReadUInt32();

            Flags = (EnvCellFlags)reader.ReadUInt32();

            reader.BaseStream.Position += 4; // Skip ahead 4 bytes, because this is the CellId. Again. Twice.

            byte   numSurfaces = reader.ReadByte();
            byte   numPortals  = reader.ReadByte();     // Note that "portal" in this context does not refer to the swirly pink/purple thing, its basically connecting cells
            ushort numStabs    = reader.ReadUInt16();   // I believe this is what cells can be seen from this one. So the engine knows what else it needs to load/draw.

            // Read what surfaces are used in this cell
            for (uint i = 0; i < numSurfaces; i++)
            {
                Surfaces.Add(0x08000000u | reader.ReadUInt16()); // these are stored in the dat as short values, so we'll make them a full dword
            }
            EnvironmentId = (0x0D000000u | reader.ReadUInt16());

            CellStructure = reader.ReadUInt16();

            Position.Unpack(reader);

            CellPortals.Unpack(reader, numPortals);

            for (uint i = 0; i < numStabs; i++)
            {
                VisibleCells.Add(reader.ReadUInt16());
            }

            if ((Flags & EnvCellFlags.HasStaticObjs) != 0)
            {
                StaticObjects.Unpack(reader);
            }

            if ((Flags & EnvCellFlags.HasRestrictionObj) != 0)
            {
                RestrictionObj = reader.ReadUInt32();
            }
        }
Esempio n. 10
0
 /// <summary>
 /// Add a surface to the list of surfaces to be rendered to the window.
 /// </summary>
 /// <param name="surface">The surface to add.</param>
 public void AddSurface(Surface surface)
 {
     surface.Scroll = 0;
     Surfaces.Add(surface);
 }
Esempio n. 11
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
                });
            }
        }
Esempio n. 12
0
 /// <summary>
 /// Add a surface to the list of surfaces to be rendered to the window.
 /// </summary>
 /// <param name="surface">The surface to add.</param>
 public void AddSurface(Surface surface)
 {
     surface.Scroll = 0;
     surface.Repeat = Repeat.XY;
     Surfaces.Add(surface);
 }
Esempio n. 13
0
        public void Read(Texture tex)
        {
            ImageKey         = "Texture";
            SelectedImageKey = "Texture";
            Text             = tex.Name;

            texture = tex;

            Width  = tex.Width;
            Height = tex.Height;
            Format = ConvertFormat(tex.Format);
            format = (int)tex.Format;
            int  swizzle = (int)tex.Swizzle;
            int  pitch   = (int)tex.Pitch;
            uint bpp     = GTX.surfaceGetBitsPerPixel((uint)format) >> 3;

            GTX.GX2Surface surf = new GTX.GX2Surface();
            surf.bpp       = bpp;
            surf.height    = tex.Height;
            surf.width     = tex.Width;
            surf.aa        = (uint)tex.AAMode;
            surf.alignment = tex.Alignment;
            surf.depth     = tex.Depth;
            surf.dim       = (uint)tex.Dim;
            surf.format    = (uint)tex.Format;
            surf.use       = (uint)tex.Use;
            surf.pitch     = tex.Pitch;
            surf.data      = tex.Data;
            surf.numMips   = tex.MipCount;
            surf.mipOffset = tex.MipOffsets;
            surf.mipData   = tex.MipData;
            surf.tileMode  = (uint)tex.TileMode;
            surf.swizzle   = tex.Swizzle;

            //Determine tex2 botw files to get mip maps
            string Tex1 = GetFilePath();

            if (Tex1.Contains(".Tex1"))
            {
                string Tex2 = Tex1.Replace(".Tex1", ".Tex2");
                Console.WriteLine(Tex2);

                if (System.IO.File.Exists(Tex2))
                {
                    ResFile resFile2 = new ResFile(new System.IO.MemoryStream(
                                                       EveryFileExplorer.YAZ0.Decompress(Tex2)));

                    if (resFile2.Textures.ContainsKey(tex.Name))
                    {
                        surf.mipData   = resFile2.Textures[tex.Name].MipData;
                        surf.mipOffset = resFile2.Textures[tex.Name].MipOffsets;
                    }
                }
            }


            if (surf.mipData == null)
            {
                surf.numMips = 1;
            }

            List <byte[]> mips = GTX.Decode(surf);

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

            RenderableTex.LoadOpenGLTexture(this);
        }
Esempio n. 14
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
                });
            }
Esempio n. 15
0
 public void AddSurfaceMesh(int surfaceID, MeshFile meshFile)
 {
     Surfaces.Add(new PartSurfaceMesh(PartID, surfaceID, meshFile));
 }
Esempio n. 16
0
 /// <summary>
 /// Add a surface that the entity should render to.
 /// </summary>
 /// <param name="target"></param>
 public void AddSurface(Surface target)
 {
     Surfaces.Add(target);
 }
Esempio n. 17
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);
        }