Class MeshUtility
Utility class for mesh processing operations used by WaterObject. Handles mesh simplification, convexification, vertex welding, and volume calculations.
Namespace: NWH.DWP2.WaterObjects
Assembly: NWH.DWP2.dll
Syntax
public static class MeshUtility
Methods
| Edit this page View SourceGenerateConvexMesh(Mesh)
Creates a convex hull from the input mesh. Useful for partially hollow meshes or open hulls.
Declaration
public static Mesh GenerateConvexMesh(Mesh mesh)
Parameters
| Type | Name | Description |
|---|---|---|
| Mesh | mesh | Mesh to convexify. |
Returns
| Type | Description |
|---|---|
| Mesh | Convex mesh wrapping the input mesh. |
GenerateMesh(Vector3[], int[])
Generate mesh from vertices and triangles.
Declaration
public static Mesh GenerateMesh(Vector3[] vertices, int[] triangles)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3[] | vertices | Array of vertices. |
| int[] | triangles | Array of triangles (indices). |
Returns
| Type | Description |
|---|---|
| Mesh |
GenerateSimMesh(ref Mesh, ref Mesh, bool, bool, bool, float)
Generates a simulation mesh from the original mesh with optional processing steps. Processes the mesh according to the specified flags and simplification ratio.
Declaration
public static void GenerateSimMesh(ref Mesh originalMesh, ref Mesh simMesh, bool simplifyMesh = false, bool convexifyMesh = false, bool weldColocatedVertices = true, float simplificationRatio = 1)
Parameters
| Type | Name | Description |
|---|---|---|
| Mesh | originalMesh | Source mesh to process. |
| Mesh | simMesh | Output simulation mesh. |
| bool | simplifyMesh | Should the mesh be simplified to reduce triangle count. |
| bool | convexifyMesh | Should the mesh be made convex. |
| bool | weldColocatedVertices | Should vertices at the same position be merged. |
| float | simplificationRatio | Target triangle count as ratio of original (0-1). |
SignedVolumeOfTriangle(Vector3, Vector3, Vector3)
Calculates the signed volume of a triangle with respect to the origin. Used for mesh volume calculations.
Declaration
public static float SignedVolumeOfTriangle(Vector3 p1, Vector3 p2, Vector3 p3)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | p1 | First vertex. |
| Vector3 | p2 | Second vertex. |
| Vector3 | p3 | Third vertex. |
Returns
| Type | Description |
|---|---|
| float | Signed volume of the triangle. |
VolumeOfMesh(Mesh, Transform)
Calculates the volume of a mesh in world space. Takes into account the transform's scale, position and rotation.
Declaration
public static float VolumeOfMesh(Mesh mesh, Transform transform)
Parameters
| Type | Name | Description |
|---|---|---|
| Mesh | mesh | Mesh to calculate volume for. |
| Transform | transform | Transform containing scale information. |
Returns
| Type | Description |
|---|---|
| float | Volume of the mesh in cubic meters. |
WeldVertices(ref Mesh, float)
Merges vertices that are closer than the specified distance threshold. Improves performance by reducing vertex count and removing duplicates.
Declaration
public static void WeldVertices(ref Mesh aMesh, float aMaxDelta = 0.001)
Parameters
| Type | Name | Description |
|---|---|---|
| Mesh | aMesh | Mesh to process. |
| float | aMaxDelta | Maximum distance between vertices to be considered duplicates. |