Class CommonGeometryGroup
Represents a TriLib geometry group. A geometry group contains one or more child geometries (typically sub-meshes) and aggregates vertex data used to build a Unity Mesh.
Namespace: TriLibCore.Geometries
Assembly: TriLibCore.Source.dll
Syntax
public class CommonGeometryGroup : IGeometryGroup, IObject
Fields
TempColor
Temporary color used to stage vertex data before it is committed to the internal lists.
Declaration
public Color TempColor
Field Value
| Type | Description |
|---|---|
| Color |
TempNormal
Temporary normal used to stage vertex data before it is committed to the internal lists.
Declaration
public Vector3 TempNormal
Field Value
| Type | Description |
|---|---|
| Vector3 |
TempOriginalVertexIndex
Temporary original vertex index used to stage vertex data before it is committed.
Declaration
public int TempOriginalVertexIndex
Field Value
| Type | Description |
|---|---|
| int |
TempPosition
Temporary position used to stage vertex data before it is committed to the internal lists.
Declaration
public Vector3 TempPosition
Field Value
| Type | Description |
|---|---|
| Vector3 |
TempTangent
Temporary tangent used to stage vertex data before it is committed to the internal lists.
Declaration
public Vector4 TempTangent
Field Value
| Type | Description |
|---|---|
| Vector4 |
TempUV1
Temporary UV0 used to stage vertex data before it is committed to the internal lists.
Declaration
public Vector2 TempUV1
Field Value
| Type | Description |
|---|---|
| Vector2 |
TempUV2
Temporary UV1 used to stage vertex data before it is committed to the internal lists.
Declaration
public Vector2 TempUV2
Field Value
| Type | Description |
|---|---|
| Vector2 |
TempUV3
Temporary UV2 used to stage vertex data before it is committed to the internal lists.
Declaration
public Vector2 TempUV3
Field Value
| Type | Description |
|---|---|
| Vector2 |
TempUV4
Temporary UV3 used to stage vertex data before it is committed to the internal lists.
Declaration
public Vector2 TempUV4
Field Value
| Type | Description |
|---|---|
| Vector2 |
Properties
BlendShapeKeys
Gets or sets the blend shape keys associated with this geometry group.
Declaration
public List<IBlendShapeKey> BlendShapeKeys { get; set; }
Property Value
| Type | Description |
|---|---|
| List<IBlendShapeKey> |
CanMergeVertices
Gets or sets a value indicating whether the vertices of this geometry group can be merged. Formats storing data which is unique per face, like 3MF, turn this off, as no vertex could ever be merged.
Declaration
public bool CanMergeVertices { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
Colors
Gets or sets the vertex colors list.
Declaration
public List<Color> Colors { get; set; }
Property Value
| Type | Description |
|---|---|
| List<Color> |
GeometriesData
Gets the geometries dictionary indexed by a material/quad derived key. Each entry typically maps to a Unity sub-mesh.
Declaration
public Dictionary<int, IGeometry> GeometriesData { get; }
Property Value
| Type | Description |
|---|---|
| Dictionary<int, IGeometry> |
GeometryCapacity
Gets or sets the expected geometry capacity (sub-mesh count hint).
Declaration
public int GeometryCapacity { get; set; }
Property Value
| Type | Description |
|---|---|
| int |
HasColors
Gets or sets a value indicating whether this geometry group has vertex colors.
Declaration
public bool HasColors { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
HasInvalidNormals
Gets or sets a value indicating whether invalid normals were detected while adding vertices.
Declaration
public bool HasInvalidNormals { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
HasNormals
Gets or sets a value indicating whether this geometry group has normals.
Declaration
public bool HasNormals { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
HasSkin
Gets or sets a value indicating whether this geometry group has skinning data.
Declaration
public bool HasSkin { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
HasTangents
Gets or sets a value indicating whether this geometry group has tangents.
Declaration
public bool HasTangents { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
HasUv1
Gets or sets a value indicating whether this geometry group has UV0.
Declaration
public bool HasUv1 { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
HasUv2
Gets or sets a value indicating whether this geometry group has UV1.
Declaration
public bool HasUv2 { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
HasUv3
Gets or sets a value indicating whether this geometry group has UV2.
Declaration
public bool HasUv3 { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
HasUv4
Gets or sets a value indicating whether this geometry group has UV3.
Declaration
public bool HasUv4 { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
Mesh
Gets or sets the Unity mesh created by this geometry group.
Declaration
public Mesh Mesh { get; set; }
Property Value
| Type | Description |
|---|---|
| Mesh |
Name
Gets or sets the geometry group name (assigned to the resulting mesh name).
Declaration
public string Name { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
Normals
Gets or sets the vertex normals list.
Declaration
public List<Vector3> Normals { get; set; }
Property Value
| Type | Description |
|---|---|
| List<Vector3> |
OriginalVertexIndices
Gets or sets the original vertex indices, mapping each stored vertex entry to its source vertex index.
Declaration
public List<int> OriginalVertexIndices { get; set; }
Property Value
| Type | Description |
|---|---|
| List<int> |
Pivot
Gets or sets a local pivot offset applied to vertex positions when possible.
Declaration
public Vector3 Pivot { get; set; }
Property Value
| Type | Description |
|---|---|
| Vector3 |
Positions
Gets or sets the vertex positions list.
Declaration
public List<Vector3> Positions { get; set; }
Property Value
| Type | Description |
|---|---|
| List<Vector3> |
Tangents
Gets or sets the vertex tangents list.
Declaration
public List<Vector4> Tangents { get; set; }
Property Value
| Type | Description |
|---|---|
| List<Vector4> |
UVs1
Gets or sets the UV0 list.
Declaration
public List<Vector2> UVs1 { get; set; }
Property Value
| Type | Description |
|---|---|
| List<Vector2> |
UVs2
Gets or sets the UV1 list.
Declaration
public List<Vector2> UVs2 { get; set; }
Property Value
| Type | Description |
|---|---|
| List<Vector2> |
UVs3
Gets or sets the UV2 list.
Declaration
public List<Vector2> UVs3 { get; set; }
Property Value
| Type | Description |
|---|---|
| List<Vector2> |
UVs4
Gets or sets the UV3 list.
Declaration
public List<Vector2> UVs4 { get; set; }
Property Value
| Type | Description |
|---|---|
| List<Vector2> |
Used
Gets or sets a value indicating whether this geometry group was used/consumed by the importer pipeline.
Declaration
public bool Used { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
VerticesCapacity
Gets or sets the expected vertex capacity (allocation hint).
Declaration
public int VerticesCapacity { get; set; }
Property Value
| Type | Description |
|---|---|
| int |
VerticesDataCount
Gets the number of vertices currently stored in this geometry group.
Declaration
public int VerticesDataCount { get; }
Property Value
| Type | Description |
|---|---|
| int |
Methods
AddBoneWeight(int, BoneWeight1)
Adds a raw BoneWeight1 entry for the given original vertex index.
Declaration
public void AddBoneWeight(int vertexIndex, BoneWeight1 boneWeight1)
Parameters
| Type | Name | Description |
|---|---|---|
| int | vertexIndex | The original vertex index the weight belongs to. |
| BoneWeight1 | boneWeight1 | The bone weight entry to add. |
AddVertex(AssetLoaderContext, int, Vector3, Vector3, Vector4, Color, Vector2, Vector2, Vector2, Vector2, BoneWeight)
Adds (or merges) a vertex into this geometry group and returns the resulting vertex data index.
Declaration
public int AddVertex(AssetLoaderContext assetLoaderContext, int vertexIndex, Vector3 position, Vector3 normal, Vector4 tangent, Color color, Vector2 uv1, Vector2 uv2, Vector2 uv3, Vector2 uv4, BoneWeight boneWeight)
Parameters
| Type | Name | Description |
|---|---|---|
| AssetLoaderContext | assetLoaderContext | The asset loader context and options. |
| int | vertexIndex | The original vertex index from the source mesh. |
| Vector3 | position | Vertex position. |
| Vector3 | normal | Vertex normal. |
| Vector4 | tangent | Vertex tangent. |
| Color | color | Vertex color. |
| Vector2 | uv1 | UV0. |
| Vector2 | uv2 | UV1. |
| Vector2 | uv3 | UV2. |
| Vector2 | uv4 | UV3. |
| BoneWeight | boneWeight | Bone weight (reserved/legacy; bone weights are collected through AddBoneWeight(int, BoneWeight1)). |
Returns
| Type | Description |
|---|---|
| int | The vertex data index used by geometries (triangle indices reference this index). |
Remarks
When AssetLoaderOptions.MergeVertices is enabled, this method attempts to reuse an existing
vertex entry by hashing/comparing the staged vertex data; otherwise, a new vertex entry is always created.
Create(bool, bool, bool, bool, bool, bool, bool, bool)
Creates a new CommonGeometryGroup with the given vertex attribute flags.
Declaration
public static CommonGeometryGroup Create(bool hasNormal, bool hasTangent, bool hasColor, bool hasUV0, bool hasUV1, bool hasUV2, bool hasUV3, bool hasSkin)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | hasNormal | Whether the group contains normals. |
| bool | hasTangent | Whether the group contains tangents. |
| bool | hasColor | Whether the group contains vertex colors. |
| bool | hasUV0 | Whether the group contains UV0. |
| bool | hasUV1 | Whether the group contains UV1. |
| bool | hasUV2 | Whether the group contains UV2. |
| bool | hasUV3 | Whether the group contains UV3. |
| bool | hasSkin | Whether the group contains skinning data. |
Returns
| Type | Description |
|---|---|
| CommonGeometryGroup | A configured CommonGeometryGroup instance. |
GenerateMesh(AssetLoaderContext, GameObject, IModel)
Generates and populates the Unity Mesh instance for this geometry group.
Declaration
public IEnumerable GenerateMesh(AssetLoaderContext assetLoaderContext, GameObject meshGameObject, IModel meshModel)
Parameters
| Type | Name | Description |
|---|---|---|
| AssetLoaderContext | assetLoaderContext | The asset loader context and options. |
| GameObject | meshGameObject | The target mesh game object. |
| IModel | meshModel | The model holding bind poses, transforms, and hierarchy information. |
Returns
| Type | Description |
|---|---|
| IEnumerable | An enumerator used by the importer pipeline to schedule work across frames. |
Remarks
This method is implemented as an iterator to allow yielding back to the main thread between heavy steps (via ReleaseMainThread()), preventing long frame stalls during import.
GetCenter()
Computes the center point of the geometry group based on the vertex positions.
Declaration
public Vector3 GetCenter()
Returns
| Type | Description |
|---|---|
| Vector3 | The computed bounds center. |
GetGeometry<TGeometry>(AssetLoaderContext, int, bool, bool)
Gets an existing geometry entry for the given material index and topology, or creates and registers a new one if needed.
Declaration
public virtual TGeometry GetGeometry<TGeometry>(AssetLoaderContext assetLoaderContext, int materialIndex, bool isQuad, bool hasBlendShapes) where TGeometry : class, IGeometry, new()
Parameters
| Type | Name | Description |
|---|---|---|
| AssetLoaderContext | assetLoaderContext | The asset loader context and options. |
| int | materialIndex | The material index associated with the geometry. |
| bool | isQuad | Whether the geometry represents quad topology. |
| bool | hasBlendShapes | Whether blend shapes are present for this geometry. |
Returns
| Type | Description |
|---|---|
| TGeometry | The geometry instance registered in GeometriesData. |
Type Parameters
| Name | Description |
|---|---|
| TGeometry | The geometry implementation type. |
Setup(AssetLoaderContext, int, int)
Initializes internal lists and caches using the provided capacity hints and loader options.
Declaration
public virtual void Setup(AssetLoaderContext assetLoaderContext, int verticesCapacity, int geometriesCapacity)
Parameters
| Type | Name | Description |
|---|---|---|
| AssetLoaderContext | assetLoaderContext | The asset loader context and options. |
| int | verticesCapacity | Initial vertex list capacity. |
| int | geometriesCapacity | Initial geometry/sub-mesh dictionary capacity. |
TransferToBlendShape(IGeometryGroup, IBlendShapeKey, IList<int>)
Transfers this geometry group vertex data into a blend shape target.
Declaration
public void TransferToBlendShape(IGeometryGroup baseGeometryGroup, IBlendShapeKey blendShapeKey, IList<int> originalVertexIndices)
Parameters
| Type | Name | Description |
|---|---|---|
| IGeometryGroup | baseGeometryGroup | The base geometry group receiving the blend shape data. |
| IBlendShapeKey | blendShapeKey | The blend shape key/target definition. |
| IList<int> | originalVertexIndices | The original vertex index mapping to use during the transfer. |