Table of Contents

Class IconFactory

Namespace
S1API.Rendering
Assembly
S1API.dll

Factory for generating item icons using the game's IconGenerator and MugshotGenerator.

Item Icon Generation: Use GenerateIcon(Transform, int, bool) for static mesh item models. S1API centers and fits the model to the game's fixed item-thumbnail camera.

Accessory Icon Generation (Confirmed Working): Accessory icon generation using MugshotGenerator is confirmed to work. Use GenerateAccessoryIcon(string, Action<Texture2D?>?, Color?, int) or GenerateAccessoryIconSprite(string, Action<Sprite?>?, Color?, int) for clothing accessories (hats, glasses, etc.).

public static class IconFactory
Inheritance
IconFactory
Inherited Members

Methods

GenerateAccessoryIcon(string, Action<Texture2D?>?, Color?, int)

Generates an icon for an accessory by rendering it on an avatar using MugshotGenerator. This is an asynchronous operation that will invoke the callback when complete.

public static void GenerateAccessoryIcon(string accessoryPath, Action<Texture2D?>? callback, Color? accessoryColor = null, int size = 512)

Parameters

accessoryPath string

The resource path to the accessory (e.g., from Appearances.AccessoryFields.Head)

callback Action<Texture2D>

Callback invoked with the generated texture when complete

accessoryColor Color?

Optional tint color for the accessory (defaults to white)

size int

The size of the square icon (default 512)

Remarks

This method attempts to use the local player's current avatar settings for a personalized icon. However, if called during mod initialization (e.g., in OnSceneWasLoaded), the player may not have spawned yet, causing it to fall back to a generic avatar with neutral face, eyes, and basic clothing. To use the player's actual appearance, consider deferring icon generation until after player spawn by subscribing to LocalPlayerSpawned.

GenerateAccessoryIconSprite(string, Action<Sprite?>?, Color?, int)

Generates an icon for an accessory as a Sprite by rendering it on an avatar using MugshotGenerator. This is an asynchronous operation that will invoke the callback when complete.

public static void GenerateAccessoryIconSprite(string accessoryPath, Action<Sprite?>? callback, Color? accessoryColor = null, int size = 512)

Parameters

accessoryPath string

The resource path to the accessory (e.g., from Appearances.AccessoryFields.Head)

callback Action<Sprite>

Callback invoked with the generated sprite when complete

accessoryColor Color?

Optional tint color for the accessory (defaults to white)

size int

The size of the square icon (default 512)

GenerateIcon(Transform, int, bool)

Generates a preview texture for the specified model.

public static Texture2D? GenerateIcon(Transform model, int size = 512, bool bakeSkinnedMeshes = true)

Parameters

model Transform

The model to generate an icon for.

size int

The size of the square icon (default 512).

bakeSkinnedMeshes bool

If true, bakes SkinnedMeshRenderers to static MeshRenderers to ensure correct bounds (default true).

Returns

Texture2D

A Texture2D containing the icon, or null if generation failed or the render pipeline produced a transparent cold-start capture.

Remarks

This synchronous method requires a render-ready Main or Tutorial scene. Product presentation profiles use a loading-screen queue that waits and retries automatically.

GenerateIcon(Transform, int, bool, bool, float)

Generates a preview texture with explicit native-camera framing controls.

public static Texture2D? GenerateIcon(Transform model, int size, bool bakeSkinnedMeshes, bool fitToCamera, float cameraFill = 0.72)

Parameters

model Transform

The model to generate an icon for.

size int

The size of the square icon.

bakeSkinnedMeshes bool

Whether to bake skinned renderers to static renderers before capture.

fitToCamera bool

Whether to fit renderer bounds to the native fixed thumbnail camera. Set false to preserve the model's authored scale.

cameraFill float

The target share of the native camera's vertical view when fitting, greater than zero through 2. Values above 1 intentionally crop the model.

Returns

Texture2D

A Texture2D containing the icon, or null if generation failed or produced no visible pixels.

Exceptions

ArgumentOutOfRangeException

Thrown when cameraFill is not greater than zero through 2.

GenerateIconSprite(Transform, int, bool)

Generates a preview icon as a Sprite for the specified model.

public static Sprite? GenerateIconSprite(Transform model, int size = 512, bool bakeSkinnedMeshes = true)

Parameters

model Transform

The model to generate an icon for.

size int

The size of the square icon (default 512).

bakeSkinnedMeshes bool

If true, bakes SkinnedMeshRenderers to static MeshRenderers to ensure correct bounds (default true).

Returns

Sprite

A Sprite containing the icon, or null if generation failed.

GenerateIconSprite(Transform, int, bool, bool, float)

Generates a preview sprite with explicit native-camera framing controls.

public static Sprite? GenerateIconSprite(Transform model, int size, bool bakeSkinnedMeshes, bool fitToCamera, float cameraFill = 0.72)

Parameters

model Transform

The model to generate an icon for.

size int

The size of the square icon.

bakeSkinnedMeshes bool

Whether to bake skinned renderers to static renderers before capture.

fitToCamera bool

Whether to fit renderer bounds to the native fixed thumbnail camera.

cameraFill float

The target share of the native camera's vertical view when fitting.

Returns

Sprite

A Sprite containing the icon, or null if generation failed.

Exceptions

ArgumentOutOfRangeException

Thrown when cameraFill is not greater than zero through 2.

GeneratePackagingIcon(string, string)

Generates an icon for a packaging ID and product ID.

public static Texture2D? GeneratePackagingIcon(string packagingID, string productID)

Parameters

packagingID string

The ID of the packaging visuals to use.

productID string

The ID of the product to display in the packaging.

Returns

Texture2D

A Texture2D containing the packaging icon, or null if generation failed.

GeneratePackagingIconSprite(string, string)

Generates an icon as a Sprite for a packaging ID and product ID.

public static Sprite? GeneratePackagingIconSprite(string packagingID, string productID)

Parameters

packagingID string

The ID of the packaging visuals to use.

productID string

The ID of the product to display in the packaging.

Returns

Sprite

A Sprite containing the packaging icon, or null if generation failed.