Table of Contents

Class MeshMorphData

Namespace
Stride.Rendering
Assembly
Stride.Rendering.dll

The morph targets of a Mesh: sparse position, normal and tangent deltas, grouped by vertex.

[DataContract]
public sealed class MeshMorphData
Inheritance
object
MeshMorphData
Extension Methods

Remarks

The model importer builds this; most code only reads TargetNames, and drives weights through ModelComponent. It is shared by every instance of the mesh and holds no weights. Only vertices a target moves have an entry for it, sorted by vertex then target, and VertexOffsets gives each vertex's range of entries, so a vertex shader or compute shader reads only the entries of its vertex. Build it with Create(int, ReadOnlySpan<string>, IEnumerable<MeshMorphEntry>, bool, bool), which sorts, packs and validates the entries; treat an instance as immutable.

Fields

Entries

The nonzero deltas, sorted by vertex then target, at most one per vertex and target.

public MeshMorphEntry[] Entries

Field Value

MeshMorphEntry[]

HasNormalDeltas

Whether entries may hold normal deltas; when false, the normals are not morphed.

public bool HasNormalDeltas

Field Value

bool

HasTangentDeltas

Whether entries may hold tangent deltas; when false, the tangents are not morphed.

public bool HasTangentDeltas

Field Value

bool

MaxTargetCount

The maximum number of targets of a mesh: target indices are stored in 16 bits.

public const int MaxTargetCount = 65536

Field Value

int

TargetNames

The target names, unique within the mesh; a name's index is the target index of its entries.

public string[] TargetNames

Field Value

string[]

VertexCount

The number of vertices of the mesh the targets apply to.

public int VertexCount

Field Value

int

VertexOffsets

The first entry of each vertex in Entries, plus an end value: the entries of vertex v are VertexOffsets[v] to VertexOffsets[v + 1] - 1. Its length is VertexCount + 1.

public uint[] VertexOffsets

Field Value

uint[]

Methods

Create(int, ReadOnlySpan<string>, IEnumerable<MeshMorphEntry>, bool, bool)

Creates morph data from the deltas of each vertex and target, in any order.

public static MeshMorphData Create(int vertexCount, ReadOnlySpan<string> names, IEnumerable<MeshMorphEntry> contributions, bool hasNormals = false, bool hasTangents = false)

Parameters

vertexCount int

The number of vertices of the mesh.

names ReadOnlySpan<string>

The target names, nonempty and unique; the names are copied.

contributions IEnumerable<MeshMorphEntry>

The deltas; zero entries are dropped.

hasNormals bool

Whether the deltas include normals.

hasTangents bool

Whether the deltas include tangents.

Returns

MeshMorphData

The validated morph data.

Exceptions

ArgumentException

A count or an entry index is out of range.

InvalidOperationException

A name is empty or repeated, an entry repeats a vertex and target, a delta is not finite, or a normal or tangent delta is given without the matching flag.

Remap(ReadOnlySpan<uint>)

Creates the morph data of a mesh whose vertices were reordered, split or duplicated.

public MeshMorphData Remap(ReadOnlySpan<uint> sourceVertices)

Parameters

sourceVertices ReadOnlySpan<uint>

For each vertex of the new mesh, the vertex of this mesh it comes from.

Returns

MeshMorphData

Morph data with one vertex per element of sourceVertices, each with the deltas of its source.

Exceptions

ArgumentException

A source vertex is out of range.

Transform(Matrix, ReadOnlySpan<Vector3>, ReadOnlySpan<Vector3>)

Creates the morph data of the mesh after a transform of its vertices, such as an import scale or axis change.

public MeshMorphData Transform(Matrix transform, ReadOnlySpan<Vector3> baseNormals, ReadOnlySpan<Vector3> baseTangents)

Parameters

transform Matrix

The transform applied to the mesh vertices.

baseNormals ReadOnlySpan<Vector3>

The mesh normals before the transform; required when HasNormalDeltas.

baseTangents ReadOnlySpan<Vector3>

The mesh tangents before the transform; required when HasTangentDeltas.

Returns

MeshMorphData

The transformed morph data.

Remarks

Call it with the attributes before the mesh is transformed. Position deltas are transformed as vectors; normal and tangent deltas are rebuilt as the difference of the transformed target and base directions.

Exceptions

ArgumentException

A required base attribute is missing or has the wrong length.

Validate()

Checks that the data is consistent, for example after loading it, before it is read or uploaded.

public void Validate()

Exceptions

InvalidOperationException

The data is malformed.