Table of Contents

Class ModelComponentExtensions

Namespace
Stride.CommunityToolkit.Engine
Assembly
Stride.CommunityToolkit.dll

Provides extension methods for the ModelComponent class, enabling additional functionality such as calculating model dimensions and extracting mesh data.

public static class ModelComponentExtensions
Inheritance
ModelComponentExtensions

Methods

GetMeshHWL(ModelComponent)

Calculates the height, width, and length of the model represented by the ModelComponent.

public static Vector3 GetMeshHWL(this ModelComponent modelComponent)

Parameters

modelComponent ModelComponent

The ModelComponent whose model dimensions are to be calculated.

Returns

Vector3

A Vector3 representing the height, width, and length of the model.

Remarks

The dimensions are calculated based on the model's bounding box. The returned Vector3 contains the height (Y-axis), width (X-axis), and length (Z-axis) of the bounding box.

GetMeshHeight(ModelComponent)

Calculates the height of the model represented by the ModelComponent.

public static float GetMeshHeight(this ModelComponent modelComponent)

Parameters

modelComponent ModelComponent

The ModelComponent whose model height is to be calculated.

Returns

float

The height of the model along the Y-axis.

Remarks

The height is calculated based on the model's bounding box, which encompasses its maximum extent in 3D space.

GetMeshVerticesAndIndices(ModelComponent, IGame)

Retrieves the vertices and indices from the ModelComponent's mesh data.

public static (List<Vector3> vertices, List<int> indices) GetMeshVerticesAndIndices(this ModelComponent model, IGame game)

Parameters

model ModelComponent

The ModelComponent from which to extract mesh data.

game IGame

The game instance, used to access graphics context for data extraction.

Returns

(List<Vector3> vertices, List<int> indices)

A tuple containing two lists: the first list holds the vertices (as Vector3), and the second list holds the indices (as int).

Remarks

This method extracts raw vertex and index data from the meshes in the provided ModelComponent. It's useful for operations that require direct access to mesh data, such as custom rendering, collision detection, or physics simulations. Note that this method extracts combined vertex and index data from all meshes in the ModelComponent.

SetMaterialParameter<T>(ModelComponent, ObjectParameterAccessor<T>, T, int, int)

Sets an object of the material pass parameter. Cloning the Material if required.

public static void SetMaterialParameter<T>(this ModelComponent modelComponent, ObjectParameterAccessor<T> parameterAccessor, T value, int materialIndex = 0, int passIndex = 0)

Parameters

modelComponent ModelComponent

The ModelComponent to update material parameter on.

parameterAccessor ObjectParameterAccessor<T>

The parameter to update.

value T

The value.

materialIndex int

The index of the material to update. Default is 0.

passIndex int

The index of the pass of the material to update. Default is 0.

Type Parameters

T

The type of value.

Exceptions

ArgumentNullException

If modelComponent is null.

ArgumentOutOfRangeException

If materialIndex is less than 0 or greater than GetMaterialCount() and not in Materials. Or if passIndex is less than 0 or greater than or equal to the mu,ber of passes the material has.

SetMaterialParameter<T>(ModelComponent, ObjectParameterKey<T>, T, int, int)

Sets an object of the material pass parameter. Cloning the Material if required.

public static void SetMaterialParameter<T>(this ModelComponent modelComponent, ObjectParameterKey<T> parameter, T value, int materialIndex = 0, int passIndex = 0)

Parameters

modelComponent ModelComponent

The ModelComponent to update material parameter on.

parameter ObjectParameterKey<T>

The parameter to update.

value T

The value.

materialIndex int

The index of the material to update. Default is 0.

passIndex int

The index of the pass of the material to update. Default is 0.

Type Parameters

T

The type of value.

Exceptions

ArgumentNullException

If modelComponent is null.

ArgumentOutOfRangeException

If materialIndex is less than 0 or greater than GetMaterialCount() and not in Materials. Or if passIndex is less than 0 or greater than or equal to the mu,ber of passes the material has.

SetMaterialParameter<T>(ModelComponent, PermutationParameterKey<T>, T, int, int)

Sets a permutation of the material pass parameter. Cloning the Material if required.

public static void SetMaterialParameter<T>(this ModelComponent modelComponent, PermutationParameterKey<T> parameter, T value, int materialIndex = 0, int passIndex = 0)

Parameters

modelComponent ModelComponent

The ModelComponent to update material parameter on.

parameter PermutationParameterKey<T>

The parameter to update.

value T

The value.

materialIndex int

The index of the material to update. Default is 0.

passIndex int

The index of the pass of the material to update. Default is 0.

Type Parameters

T

The type of value.

Exceptions

ArgumentNullException

If modelComponent is null.

ArgumentOutOfRangeException

If materialIndex is less than 0 or greater than GetMaterialCount() and not in Materials. Or if passIndex is less than 0 or greater than or equal to the mu,ber of passes the material has.

SetMaterialParameter<T>(ModelComponent, PermutationParameter<T>, T, int, int)

Sets a permutation of the material pass parameter. Cloning the Material if required.

public static void SetMaterialParameter<T>(this ModelComponent modelComponent, PermutationParameter<T> parameter, T value, int materialIndex = 0, int passIndex = 0)

Parameters

modelComponent ModelComponent

The ModelComponent to update material parameter on.

parameter PermutationParameter<T>

The parameter to update.

value T

The value.

materialIndex int

The index of the material to update. Default is 0.

passIndex int

The index of the pass of the material to update. Default is 0.

Type Parameters

T

The type of value.

Exceptions

ArgumentNullException

If modelComponent is null.

ArgumentOutOfRangeException

If materialIndex is less than 0 or greater than GetMaterialCount() and not in Materials. Or if passIndex is less than 0 or greater than or equal to the mu,ber of passes the material has.

SetMaterialParameter<T>(ModelComponent, ValueParameterKey<T>, int, ref T, int, int)

Sets blittable values of the material pass parameter. Cloning the Material if required.

public static void SetMaterialParameter<T>(this ModelComponent modelComponent, ValueParameterKey<T> parameter, int count, ref T firstValue, int materialIndex = 0, int passIndex = 0) where T : struct

Parameters

modelComponent ModelComponent

The ModelComponent to update material parameter on.

parameter ValueParameterKey<T>

The parameter to update.

count int

Number of values.

firstValue T

The values.

materialIndex int

The index of the material to update. Default is 0.

passIndex int

The index of the pass of the material to update. Default is 0.

Type Parameters

T

The type of value.

Exceptions

ArgumentNullException

If modelComponent is null.

ArgumentOutOfRangeException

If materialIndex is less than 0 or greater than GetMaterialCount() and not in Materials. Or if passIndex is less than 0 or greater than or equal to the mu,ber of passes the material has.

SetMaterialParameter<T>(ModelComponent, ValueParameterKey<T>, T, int, int)

Sets a blittable of the material pass parameter. Cloning the Material if required.

public static void SetMaterialParameter<T>(this ModelComponent modelComponent, ValueParameterKey<T> parameter, T value, int materialIndex = 0, int passIndex = 0) where T : struct

Parameters

modelComponent ModelComponent

The ModelComponent to update material parameter on.

parameter ValueParameterKey<T>

The parameter to update.

value T

The value.

materialIndex int

The index of the material to update. Default is 0.

passIndex int

The index of the pass of the material to update. Default is 0.

Type Parameters

T

The type of value.

Exceptions

ArgumentNullException

If modelComponent is null.

ArgumentOutOfRangeException

If materialIndex is less than 0 or greater than GetMaterialCount() and not in Materials. Or if passIndex is less than 0 or greater than or equal to the mu,ber of passes the material has.

SetMaterialParameter<T>(ModelComponent, ValueParameterKey<T>, ref T, int, int)

Sets a blittable value of the material pass parameter. Cloning the Material if required.

public static void SetMaterialParameter<T>(this ModelComponent modelComponent, ValueParameterKey<T> parameter, ref T value, int materialIndex = 0, int passIndex = 0) where T : struct

Parameters

modelComponent ModelComponent

The ModelComponent to update material parameter on.

parameter ValueParameterKey<T>

The parameter to update.

value T

The value.

materialIndex int

The index of the material to update. Default is 0.

passIndex int

The index of the pass of the material to update. Default is 0.

Type Parameters

T

The type of value.

Exceptions

ArgumentNullException

If modelComponent is null.

ArgumentOutOfRangeException

If materialIndex is less than 0 or greater than GetMaterialCount() and not in Materials. Or if passIndex is less than 0 or greater than or equal to the mu,ber of passes the material has.

SetMaterialParameter<T>(ModelComponent, ValueParameterKey<T>, T[], int, int)

Sets blittable values of the material pass parameter. Cloning the Material if required.

public static void SetMaterialParameter<T>(this ModelComponent modelComponent, ValueParameterKey<T> parameter, T[] values, int materialIndex = 0, int passIndex = 0) where T : struct

Parameters

modelComponent ModelComponent

The ModelComponent to update material parameter on.

parameter ValueParameterKey<T>

The parameter to update.

values T[]

The values.

materialIndex int

The index of the material to update. Default is 0.

passIndex int

The index of the pass of the material to update. Default is 0.

Type Parameters

T

The type of value.

Exceptions

ArgumentNullException

If modelComponent is null.

ArgumentOutOfRangeException

If materialIndex is less than 0 or greater than GetMaterialCount() and not in Materials. Or if passIndex is less than 0 or greater than or equal to the mu,ber of passes the material has.

SetMaterialParameter<T>(ModelComponent, ValueParameter<T>, int, ref T, int, int)

Sets blittable values of the material pass parameter. Cloning the Material if required.

public static void SetMaterialParameter<T>(this ModelComponent modelComponent, ValueParameter<T> parameter, int count, ref T firstValue, int materialIndex = 0, int passIndex = 0) where T : struct

Parameters

modelComponent ModelComponent

The ModelComponent to update material parameter on.

parameter ValueParameter<T>

The parameter to update.

count int

Number of values.

firstValue T

The values.

materialIndex int

The index of the material to update. Default is 0.

passIndex int

The index of the pass of the material to update. Default is 0.

Type Parameters

T

The type of value.

Exceptions

ArgumentNullException

If modelComponent is null.

ArgumentOutOfRangeException

If materialIndex is less than 0 or greater than GetMaterialCount() and not in Materials. Or if passIndex is less than 0 or greater than or equal to the mu,ber of passes the material has.

SetMaterialParameter<T>(ModelComponent, ValueParameter<T>, T, int, int)

Sets a blittable value of the material pass parameter. Cloning the Material if required.

public static void SetMaterialParameter<T>(this ModelComponent modelComponent, ValueParameter<T> parameter, T value, int materialIndex = 0, int passIndex = 0) where T : struct

Parameters

modelComponent ModelComponent

The ModelComponent to update material parameter on.

parameter ValueParameter<T>

The parameter to update.

value T

The value.

materialIndex int

The index of the material to update. Default is 0.

passIndex int

The index of the pass of the material to update. Default is 0.

Type Parameters

T

The type of value.

Exceptions

ArgumentNullException

If modelComponent is null.

ArgumentOutOfRangeException

If materialIndex is less than 0 or greater than GetMaterialCount() and not in Materials. Or if passIndex is less than 0 or greater than or equal to the mu,ber of passes the material has.

SetMaterialParameter<T>(ModelComponent, ValueParameter<T>, ref T, int, int)

Sets blittable value of the material pass parameter. Cloning the Material if required.

public static void SetMaterialParameter<T>(this ModelComponent modelComponent, ValueParameter<T> parameter, ref T value, int materialIndex = 0, int passIndex = 0) where T : struct

Parameters

modelComponent ModelComponent

The ModelComponent to update material parameter on.

parameter ValueParameter<T>

The parameter to update.

value T

The value.

materialIndex int

The index of the material to update. Default is 0.

passIndex int

The index of the pass of the material to update. Default is 0.

Type Parameters

T

The type of value.

Exceptions

ArgumentNullException

If modelComponent is null.

ArgumentOutOfRangeException

If materialIndex is less than 0 or greater than GetMaterialCount() and not in Materials. Or if passIndex is less than 0 or greater than or equal to the mu,ber of passes the material has.