public int GetTextureIdx(uint textureId) { var stp = new SurfaceTexturePalette(textureId, textureId); var atlasIdx = GetAtlasIdx(stp); return(TextureAtlases[atlasIdx].Textures[stp]); }
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); } }
public int GetAtlasIdx(SurfaceTexturePalette surfaceTexturePalette) { if (!TextureAtlasIndices.TryGetValue(surfaceTexturePalette, out var atlasIdx)) { if (CurrentTextureAtlas == null || CurrentTextureAtlas.Textures.Count >= MaxTexturesPerAtlas) { CurrentTextureAtlas = new TextureAtlas(TextureFormat, TextureAtlases.Count); TextureAtlases.Add(CurrentTextureAtlas); } atlasIdx = CurrentTextureAtlas.TextureFormatChain.AtlasChainIdx; CurrentTextureAtlas.Textures.Add(surfaceTexturePalette, TextureAtlasIndices.Count); TextureAtlasIndices.Add(surfaceTexturePalette, atlasIdx); } return(atlasIdx); }