CosmeticPacker
A class in Root.Township, Alta.Customization.
Client: merges a character's cosmetic parts into a few meshes and one packed texture, then applies them to the character's clothes. Packing is queued on CosmeticPackScheduler.
- Listed in Customization and screenshots
- Inherits or implements
MonoBehaviour - Nested types
Input,PartId
Constructors
| Member | What it is |
|---|---|
CosmeticPacker() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
27 private and internal fields
| Member | What it is |
|---|---|
private static readonly int _Additional | Shader property ID for _Additional. |
private static readonly int _BumpMap | Shader property ID for the normal map texture. |
private static readonly int _MainTex | Shader property ID for the diffuse texture. |
private Material blendMaterial | Material for alpha-blended parts, made from material with blendShader when any input needs blending. |
private Shader blendShader | Shader used for the transparent (alpha-blended) clothing material. |
private BonesBaking bonesBaking | Bakes bone data into the packed meshes on Android. |
private Dictionary<CosmeticPacker.PartId, CosmeticPacker.Input> cacheInputs | Copy of inputs taken at the start of a pack, so changes during the pack don't affect it. |
private Matrix4x4[] defaultBindposes | Bind poses passed to the mesh packer for the combined meshes. |
private Texture2D defaultNormal | Fallback normal map used when packing textures. |
private RenderTexture diffuse | The packed diffuse render texture for all parts. |
private CharacterDummy dummy | The character the packed clothes are applied to. |
private Mesh[] headMeshes | Packed opaque head mesh, used when the head is separate (first person). |
private Dictionary<CosmeticPacker.PartId, CosmeticPacker.Input> inputs | The current cosmetic parts to pack, keyed by part ID. Exposed as Inputs. |
private bool isPackedWhilePaused | Set when PackAndApply is called while paused, so Unpause packs then. |
private bool isPackingAtTheEndOfTheFrame | Declared but not used in this class. |
private bool isPaused | While true, PackAndApply only marks a pack as pending. |
private static Logger logger | NLog logger for packing errors. |
private Material material | The opaque clothing material using the packed textures; made on first pack. |
private int maxLODToBakeBodyType | Highest LOD (exclusive) baked on Android for third-person characters. |
private Mesh[] meshes | Packed opaque body meshes, one per LOD. |
private RenderTexture normal | The packed normal map render texture. |
private IEnumerator pack | Declared but not used in this class. |
private Dictionary<CosmeticPacker.PartId, ICosmeticMeshPartBase> partMap | Loaded mesh part for each part ID, filled by FillPartMap and cleared after each pack. |
private Shader shader | Shader used for the opaque clothing material. |
private Mesh[] transparentHeadMeshes | Packed transparent head mesh for first person. |
private Mesh[] transparentMeshes | Packed transparent body meshes, one per LOD. |
private Dictionary<CosmeticPacker.PartId, int> workingIndexes | Index for each part during a pack; parts that copy another part share its index. |
Properties
| Member | What it is |
|---|---|
float AndroidTextureSizeMultiplier { get; set; } | Scale applied to the packed texture size on Android. |
int BodyTypeIndex { get; set; } | The body type used when baking bones on Android. |
Dictionary<CosmeticPacker.PartId, CosmeticPacker.Input> Inputs { get; } | The parts to pack, by part ID. Change these, then call PackAndApply. |
bool IsTextureSharingAllowed { get; set; } | Whether parts may share texture space when packing. |
2 private and internal properties
Events
Methods
| Member | What it is |
|---|---|
void Clean() | Cancels any queued pack and frees the inputs, textures, materials and meshes. Called on destroy. |
void PackAndApply() | Queues a pack for the next frame. While paused, it waits until Unpause. |
async Task PackFromScheduler(AddressableSession session, CancellationToken cancellation) | Runs the pack. Called by the scheduler, not by your code. |
void Pause() | Holds back PackAndApply until Unpause. |
void Unpause() | Ends a pause, and packs if a pack was asked for meanwhile. |
6 private and internal methods
| Member | What it is |
|---|---|
private IEnumerable<Mesh> BakingMeshes(int startingLOD) (iterator) | Lists the packed meshes to bake bones into on Android: all LODs from the start for first person, up to maxLODToBakeBodyType otherwise. |
private async Task FillPartMap(AddressableSession session, CancellationToken cancellationToken) | Loads each input's cosmetic definition by hash and stores its mesh part in partMap; logs and skips parts that fail. |
private IEnumerable<T> GetSafeEnumerable<T>(T[] elements, int start, int end) (iterator) | Yields array elements from a start index up to an end index, clamped to the array length. |
private void OnDestroy() | Calls Clean to free the packed textures, materials and meshes. |
private async Task PackMeshes(int startingLOD, bool isHeadSeparate, CancellationToken cancellation) | Combines the part meshes into opaque and transparent meshes, with the head split out in first person. Logs the part list on failure. |
private async Task PackTask(AddressableSession session, CancellationToken cancellation) | Does one full pack: snapshots inputs, resolves copied colours, loads parts, packs textures and meshes, then applies them to the dummy's clothes. |
Used in
Members of other types that take, return or hold a CosmeticPacker: