Skip to main content

AtlasDefinition

A class in Root.Township, Alta.Utilities.Atlas.

Asset describing a texture atlas: which materials it combines into one baked material, and where each sits in the atlas. ApplyTo swaps renderers over to the baked material and rewrites their mesh UVs. Mostly a build and editor tool.

Constructors​

MemberWhat it is
AtlasDefinition()Use ScriptableObject.CreateInstance instead of new; Unity loads the saved ones from assets.

Fields​

MemberWhat it is
string atlasedMaterialNameBase name for the atlas's files.
int atlasSizeAtlas texture size in pixels (a power of two).
Material bakedMaterialThe combined material renderers are switched to.
string freeDetailsText describing how full the atlas is.
int generalPaddingValueDefault padding between atlas entries.
bool isDisablingAlphaOnDifuseTurns off alpha in the diffuse atlas. Forced on for metal atlases.
bool isForcingNoEmissionLeaves emission out of the atlas.
List<AtlasDefinition.AtlasedMaterial> materialsThe materials in the atlas, each with its rectangle, scale and padding.
bool needsToBakeSet when the atlas needs to be baked again.
uint priorityOrder among atlases.
int smallestTextureHeightHeight of the smallest texture in the atlas.
int smallestTextureWidthWidth of the smallest texture in the atlas.
AtlasTarget targetFlags for which builds or uses this atlas targets.
AtlasType typeKind of atlas, which picks the atlased shader (common, foliage, metal).
UVFixType uvFixTypeHow UVs are remapped: through an extra UV channel (Texcoord) or by rewriting UV 0 (None).
5 private and internal fields
MemberWhat it is
private Dictionary<int, Mesh> bakedMeshesCache of atlased meshes keyed by a mesh and material hash, so each pair is only rebuilt once. Cleared by ClearBakedMeshes.
private static List<Color> colorsShared scratch list of colours.
private static Logger loggerNLog logger for this class.
private Dictionary<Material, AtlasDefinition.AtlasedMaterial> materialReferencesLookup from source material to its AtlasedMaterial entry, built by PrepareReferences.
private static List<Vector4> offsetScaleUVsShared scratch list of UVs reused by FixMeshUVs.

Properties​

MemberWhat it is
static string BasePath { get; }Resource folder for atlases: Atlases/Standalone/ or Atlases/Android/.
static string DefinitionsPath { get; }Folder for atlas definitions under BasePath.
6 private and internal properties
MemberWhat it is
private int HorizontalTakenSize { get; }How many of the smallest textures fit across the atlas width.
private static string MaterialsPath { get; }Project folder for baked atlas materials, under ProjectPath.
private static string MeshesPath { get; }Project folder for baked atlas meshes, under ProjectPath.
private static string ProjectPath { get; }Assets/ plus BasePath, which differs for Android and standalone.
private static string TexturesPath { get; }Project folder for baked atlas textures, under ProjectPath.
private int VerticalTakenSize { get; }How many of the smallest textures fit down the atlas height.

Methods​

MemberWhat it is
bool ApplyTo(IEnumerable<Renderer> renderers, bool isSavingMeshAsAsset = false, bool isSavingToTemporaryFolder = false)Points matching renderers (or one mesh) at the baked material, using UV-fixed mesh copies that are cached. True if anything changed.
bool ApplyTo(Mesh originalMesh, Material baseMaterial, out Mesh resultMesh, bool isSavingToTemporaryFolder = false)Points matching renderers (or one mesh) at the baked material, using UV-fixed mesh copies that are cached. True if anything changed.
void AutoEstimateSize(bool forceRebake = true)Works out the atlas size from the materials' texture sizes and fills in freeDetails. Marks it for rebake by default.
void Bake()Runs AutoEstimateSize if the atlas has a name and materials. It does not draw the atlas itself.
void ClearBakedMeshes()Forgets the cached UV-fixed meshes.
IEnumerable<Renderer> FilterRenderers(IEnumerable<Renderer> renderers) (iterator)Yields the renderers that use any of the atlas's materials (once per matching material).
bool GetMaterialRect(Material material, out AtlasDefinition.AtlasedMaterial reference)Finds the atlas entry for a material.
bool IsTargeting(AtlasTarget target)True if the atlas is for the given target.
void PrepareReferences()Rebuilds the material lookup and clears the mesh cache.
void PrepareReferencesIfNeeded()Builds the material lookup if it is empty.
void UpdateShader()Sets the baked material's shader from the atlas type.
8 private and internal methods
MemberWhat it is
private void Blit(bool rendersEmission, RenderTexture diffuseRT, RenderTexture normalRT, RenderTexture emissionRT, Texture2D defaultWhiteTexture, Texture2D defaultNormal, Texture2D defaultEmission, Vector4 rect, Vector4 interiorRect, Material material)Picks the shader-specific blit for a material and draws its textures into the atlas render textures. Logs an error for unmapped shaders.
private void ClearRT(RenderTexture renderTexture)Clears a render texture to transparent, restoring the previously active one.
private void DeleteTexture(string textureName)Deletes the atlas PNG for a texture name from disk. The one-argument overload is empty.
private void DeleteTexture(string textureBasePath, string textureName)Deletes the atlas PNG for a texture name from disk. The one-argument overload is empty.
private Mesh FixMeshUVs(List<int> triangles, Vector4 offsetScale, Mesh workingMesh, bool hasMultipleSubmeshes, int subMeshIndex, bool isOriginal)Rewrites a mesh's UVs for the atlas rect: writes offset/scale into UV channel 3, or remaps UV0, by uvFixType. Clones originals first.
private Shader GetShader()Finds the hidden atlased shader for type, adding a Texcoord suffix for that UV mode. Used by UpdateShader.
private bool SaveToFile(string basePath, string textureName, RenderTexture renderTexture, bool isLinear, TextureFormat format = 4)Reads a render texture back to a PNG on disk. Returns false and writes nothing if every pixel is empty.
private void SetTexture(string textureName, bool isNormal)Empty in this build.

Used in​

Members of other types that take, return or hold a AtlasDefinition: