Class ModelExtensions
Provides extension methods to facilitate various operations on IModel objects, such as calculating transforms, retrieving bones, sorting children, and adjusting pivots.
Inherited Members
Namespace: TriLibCore.Extensions
Assembly: TriLibCore.dll
Syntax
public static class ModelExtensions
Methods
CalculateBounds(IModel)
Calculates the local or global bounds of the given IModel, taking into account its geometry and the geometry of its children.
Declaration
public static Bounds CalculateBounds(this IModel model)
Parameters
| Type | Name | Description |
|---|---|---|
| IModel | model | The IModel to calculate bounds for. |
Returns
| Type | Description |
|---|---|
| Bounds | A UnityEngine.Bounds object representing the model's bounds in world space. |
Remarks
The method traverses the entire hierarchy of the model, using GetGlobalMatrix(IModel) to determine the final position of each vertex in world space.
CountChild(IModel)
Recursively counts the total number of child models under this model.
Declaration
public static int CountChild(this IModel model)
Parameters
| Type | Name | Description |
|---|---|---|
| IModel | model | The IModel whose child count is needed. |
Returns
| Type | Description |
|---|---|
| int | An integer representing the total count of child models. |
GetBones(IModel, AssetLoaderContext, List<Transform>)
Finds all UnityEngine.GameObject instances with only Transform components under this model
and appends them to the specified bones list.
Declaration
public static void GetBones(this IModel model, AssetLoaderContext assetLoaderContext, List<Transform> bones)
Parameters
| Type | Name | Description |
|---|---|---|
| IModel | model | The IModel to search for bone-like objects. |
| AssetLoaderContext | assetLoaderContext | The AssetLoaderContext containing references to the model hierarchy and loaded UnityEngine.GameObjects. |
| List<Transform> | bones | The list to which discovered bone transforms will be added. |
GetGlobalMatrix(IModel)
Computes the global transformation matrix for this model by concatenating its GetLocalMatrix(IModel) with its parent's global matrix (and so on up the hierarchy).
Declaration
public static Matrix4x4 GetGlobalMatrix(this IModel model)
Parameters
| Type | Name | Description |
|---|---|---|
| IModel | model | The IModel to compute the global matrix for. |
Returns
| Type | Description |
|---|---|
| Matrix4x4 | A UnityEngine.Matrix4x4 representing the global position, rotation, and scale of the model relative to the world. |
GetGlobalMatrixNoScale(IModel)
Computes the global transformation matrix for this model by concatenating its GetLocalMatrixNoScale(IModel) with its parent's global matrix (and so on up the hierarchy), ignoring scale.
Declaration
public static Matrix4x4 GetGlobalMatrixNoScale(this IModel model)
Parameters
| Type | Name | Description |
|---|---|---|
| IModel | model | The IModel to compute the global matrix for. |
Returns
| Type | Description |
|---|---|
| Matrix4x4 | A UnityEngine.Matrix4x4 representing the global position and rotation of the model relative to the world, ignoring scaling. |
GetGlobalParentMatrix(IModel)
Computes the global transformation matrix for the parent of this model.
Declaration
public static Matrix4x4 GetGlobalParentMatrix(this IModel model)
Parameters
| Type | Name | Description |
|---|---|---|
| IModel | model | The IModel whose parent hierarchy matrix is computed. |
Returns
| Type | Description |
|---|---|
| Matrix4x4 | A UnityEngine.Matrix4x4 representing the parent's global matrix. |
GetLocalMatrix(IModel)
Computes the local transformation matrix for this model using its LocalPosition, LocalRotation, and LocalScale.
Declaration
public static Matrix4x4 GetLocalMatrix(this IModel model)
Parameters
| Type | Name | Description |
|---|---|---|
| IModel | model | The IModel to compute the local matrix for. |
Returns
| Type | Description |
|---|---|
| Matrix4x4 | A UnityEngine.Matrix4x4 representing the local position, rotation, and scale of the model. |
GetLocalMatrixNoScale(IModel)
Computes the local transformation matrix for this model using its LocalPosition and LocalRotation, but without scale.
Declaration
public static Matrix4x4 GetLocalMatrixNoScale(this IModel model)
Parameters
| Type | Name | Description |
|---|---|---|
| IModel | model | The IModel to compute the local matrix for. |
Returns
| Type | Description |
|---|---|
| Matrix4x4 | A UnityEngine.Matrix4x4 representing the local position and rotation of the model with a uniform scale of 1. |
MovePivot(IModel, AssetLoaderContext)
Moves the pivot of the given IModel according to the PivotPosition set in the provided AssetLoaderContext. If the model has skinning data, the pivot is not moved.
Declaration
public static void MovePivot(this IModel model, AssetLoaderContext assetLoaderContext)
Parameters
| Type | Name | Description |
|---|---|---|
| IModel | model | The IModel whose pivot will be moved. |
| AssetLoaderContext | assetLoaderContext | The context object containing options for moving the pivot and references to other models. |
Remarks
This operation is skipped if the model contains bind poses (i.e., it's skinned), to avoid invalidating the skinning data.
SortByName(IModel)
Recursively sorts the children of this model by their name in ascending order.
Declaration
public static void SortByName(this IModel model)
Parameters
| Type | Name | Description |
|---|---|---|
| IModel | model | The IModel whose children will be sorted. |