Example #1
0
        public TerrainBatch(TextureAtlasChain overlayAtlasChain, TextureAtlasChain alphaAtlasChain)
        {
            OverlayAtlasChain = overlayAtlasChain;

            AlphaAtlasChain = alphaAtlasChain;

            Batches = new List <TerrainBatchDraw>();
        }
Example #2
0
        public const int MaxVertices = int.MaxValue / SizeOfLandVertexPlus; // 18,512,790 vertices

        public TerrainBatchDraw(TextureAtlasChain overlayAtlasChain, TextureAtlasChain alphaAtlasChain)
        {
            OverlayAtlasChain = overlayAtlasChain;

            AlphaAtlasChain = alphaAtlasChain;

            Init();
        }
        public void BuildStatic(GfxObj gfxObj, Dictionary <TextureFormat, TextureAtlasChain> textureAtlasChains, Dictionary <uint, uint> textureChanges = null, PaletteChanges paletteChanges = null)
        {
            BaseFormats_Solid = new Dictionary <TextureFormatChain, GfxObjInstance_TextureFormat>();

            BaseFormats_Alpha = new Dictionary <TextureFormatChain, GfxObjInstance_TextureFormat>();

            Vertices = new List <VertexPositionNormalTextures>();

            var vertexTable = new Dictionary <VertexPositionNormalTextures, short>();

            foreach (var poly in gfxObj.Polygons)
            {
                // get actual transformed texture -- cannot rely on poly.Texture original format
                var surfaceIdx = poly._polygon.PosSurface;
                var surfaceID  = gfxObj._gfxObj.Surfaces[surfaceIdx];

                var textureId = TextureCache.GetSurfaceTextureID(surfaceID, textureChanges);
                var texture   = TextureCache.Get(surfaceID, textureId, paletteChanges);

                var textureFormat = new TextureFormat(texture.Format, texture.Width, texture.Height, gfxObj.HasWrappingUVs);

                if (!textureAtlasChains.TryGetValue(textureFormat, out var textureAtlasChain))
                {
                    textureAtlasChain = new TextureAtlasChain(textureFormat);
                    textureAtlasChains.Add(textureFormat, textureAtlasChain);
                }

                var surface = DatManager.PortalDat.ReadFromDat <ACE.DatLoader.FileTypes.Surface>(surfaceID);

                var surfaceTextureId = TextureCache.GetSurfaceTextureID(surfaceID, textureChanges);

                var surfaceTexturePalette = new SurfaceTexturePalette(surfaceID, surfaceTextureId, paletteChanges);

                var atlasIdx = textureAtlasChain.GetAtlasIdx(surfaceTexturePalette);

                var textureAtlas = textureAtlasChain.TextureAtlases[atlasIdx];

                var baseFormats = (surface.Type & AlphaSurfaceTypes) == 0 ? BaseFormats_Solid : BaseFormats_Alpha;

                if (!baseFormats.TryGetValue(textureAtlas.TextureFormatChain, out var baseFormat))
                {
                    baseFormat = new GfxObjInstance_TextureFormat(textureAtlas);
                    baseFormats.Add(textureAtlas.TextureFormatChain, baseFormat);
                }

                var textureIdx = textureAtlas.Textures[surfaceTexturePalette];

                baseFormat.AddPolygon(poly, gfxObj.VertexArray, surfaceID, Vertices, vertexTable, textureIdx);
            }
        }