Class HammerMeshBuilder
Namespace: ValveResourceFormat.IO
Assembly: ValveResourceFormat.dll
Builds a Hammer editable mesh and writes it out as a .
public class HammerMeshBuilderInheritance
Remarks
Add vertices with and faces with (or use one of the adders for render and physics meshes), then write the result with .
There are options for features such as to join triangle pairs into quads or to split the mesh by mesh connectivity, or to weld it first.
The mesh itself is a , a half edge topology with the data of a Hammer mesh, position per vertex, corner data per half edge, material per face. loops through it and writes the vmap format.
Properties
DefaultProjectedTextureSize
Texture size assumed for a projected face when gives none: a texture that repeats every 128 units at , the usual Hammer world mapping.
public Vector2 DefaultProjectedTextureSize { get; init; }Property Value
FacesRemoved
Number of faces dropped while building, either degenerate or non manifold.
public int FacesRemoved { get; }Property Value
Mesh
The mesh being built. Its editing operations (merging, dissolving, splitting into islands) can be used once all faces were added, before the mesh is written out.
public PolygonMesh Mesh { get; }Property Value
OriginalFaceCount
Number of faces handed to the builder, including the ones it dropped.
public int OriginalFaceCount { get; }Property Value
PhysicsTriangleMatcher
Matcher that reports which physics triangles a render mesh already covers.
public PhysicsTriangleMatcher? PhysicsTriangleMatcher { get; init; }Property Value
ProgressReporter
General logging.
public IProgress<string>? ProgressReporter { get; init; }Property Value
TextureSizeProvider
Returns the size in texels of the texture a material uses, for faces added without texture coordinates: their texture is projected onto them in texels, like Hammer does. Null for materials it doesn't know, which are projected with .
public Func<string, Vector2?>? TextureSizeProvider { get; init; }Property Value
Untriangulate
Join coplanar triangle pairs into quads when writing the mesh out, where they use the same material and agree on their corner data along the shared edge. Off by default, the faces are written as they were added.
public bool Untriangulate { get; init; }Property Value
Methods
AddFace(ReadOnlySpan<int>, string, ReadOnlySpan<Corner>)
Adds one face. Faces that would leave the mesh non manifold are added on duplicated vertices instead and counted in , degenerate faces are dropped.
public void AddFace(ReadOnlySpan<int> indices, string material, ReadOnlySpan<HammerMeshBuilder.Corner> corners = default)Parameters
indices ReadOnlySpan<int>
Corner vertices, as indices into the vertices added so far.
material string
Material the face uses.
corners ReadOnlySpan<HammerMeshBuilder.Corner>
Corner data, one per index, or empty to compute it from the face.
AddPhysHull(HullDescriptor, PhysAggregateData, Func<string, string>, Matrix4x4, string?)
Adds a physics hull as mesh faces.
public void AddPhysHull(HullDescriptor desc, PhysAggregateData phys, Func<string, string> materialNameProvider, Matrix4x4 transform, string? materialOverride = null)Parameters
desc HullDescriptor
Hull to add.
phys PhysAggregateData
Physics data the hull belongs to, read for its collision attributes.
materialNameProvider Func<string, string>
Maps a surface property to the material to use.
transform Matrix4x4
Transform applied to every position.
materialOverride string?
Material to use instead of the one the surface property picks.
AddPhysMesh(MeshDescriptor, PhysAggregateData, Func<string, string>, IReadOnlySet<int>?, Matrix4x4, string?)
Adds a physics mesh as mesh faces.
public void AddPhysMesh(MeshDescriptor desc, PhysAggregateData phys, Func<string, string> materialNameProvider, IReadOnlySet<int>? deletedTriangles, Matrix4x4 transform, string? materialOverride = null)Parameters
desc MeshDescriptor
Mesh to add.
phys PhysAggregateData
Physics data the mesh belongs to, read for its collision attributes.
materialNameProvider Func<string, string>
Maps a surface property to the material to use.
deletedTriangles IReadOnlySet<int>?
Triangles to leave out, by index, usually the ones render geometry already covers.
transform Matrix4x4
Transform applied to every position.
materialOverride string?
Material to use instead of the one the surface property picks.
AddRenderMesh(DmeMesh, Matrix4x4)
Adds a render mesh, splitting it per face set so each keeps its own material.
public void AddRenderMesh(DmeMesh shape, Matrix4x4 transform)Parameters
shape DmeMesh
Mesh to add.
transform Matrix4x4
Transform applied to positions, normals and tangents.
AddVertices(ReadOnlySpan<Vector3>)
Adds the vertices of one source mesh. Faces added afterwards index into these vertices, offset by the returned base index when several source meshes are added to one builder.
public int AddVertices(ReadOnlySpan<Vector3> positions)Parameters
positions ReadOnlySpan<Vector3>
Vertex positions.
Returns
Index of the first added vertex, to add to the indices handed to .
AddVertices(ReadOnlySpan<Vector3>, Matrix4x4)
Adds the vertices of one source mesh. Faces added afterwards index into these vertices, offset by the returned base index when several source meshes are added to one builder.
public int AddVertices(ReadOnlySpan<Vector3> positions, Matrix4x4 transform)Parameters
positions ReadOnlySpan<Vector3>
Vertex positions.
transform Matrix4x4
Transform applied to every position.
Returns
Index of the first added vertex, to add to the indices handed to .
CreateStream<TArray>(CDmePolygonMeshDataArray, int, string, string?)
Adds a named, empty mesh data stream to a data array.
public static TArray CreateStream<TArray>(CDmePolygonMeshDataArray dataArray, int dataStateFlags, string name, string? standardAttributeName = null) where TArray : IList, new()Parameters
dataArray CDmePolygonMeshDataArray
Data array the stream is added to.
dataStateFlags int
Flags describing how the stream is stored.
name string
Stream name, in "semantic:index" form.
standardAttributeName string?
Name Hammer knows the stream by, defaults to the semantic.
Returns
TArray
The array backing the stream, to be filled with its values.
Type Parameters
TArray
Datamodel array type backing the stream.
GenerateMesh()
Writes everything added so far out as a Hammer mesh.
public CDmePolygonMesh GenerateMesh()Returns
GenerateMeshes()
Writes everything added so far out as Hammer meshes, one per island of faces connected through shared edges. Faces that were extracted because they didn't fit the topology are grouped by coinciding positions. Each island is copied into its own mesh and written out, untriangulated when is set.
public List<CDmePolygonMesh> GenerateMeshes()Returns
GenerateMeshes(float)
Welds everything added so far together where it coincides within the distance, the draw calls of one object becoming one mesh again, and writes it out as one Hammer mesh per connected part, see
. Each part is untriangulated when is set.public List<CDmePolygonMesh> GenerateMeshes(float weldDistance)Parameters
weldDistance float
How far apart coinciding vertices may be.
Returns
ReindexTriangleMesh(ReadOnlySpan<Vector3>, ReadOnlySpan<Triangle>, int, int)
Rebuilds a triangle range against a vertex list holding only the vertices that range uses.
public static (List<Vector3> NewTriangles, List<Vector3> NewVertices) ReindexTriangleMesh(ReadOnlySpan<Vector3> vertices, ReadOnlySpan<Mesh.Triangle> triangles, int trianglesRangeStart, int trianglesRangeEnd)Parameters
vertices ReadOnlySpan<Vector3>
Vertices the triangles index into.
triangles ReadOnlySpan<Mesh.Triangle>
Triangles to reindex.
trianglesRangeStart int
First triangle to take.
trianglesRangeEnd int
Triangle to stop before.
Returns
(List<Vector3> NewTriangles, List<Vector3> NewVertices)
WriteMesh(PolygonMesh)
Writes a polygon mesh out as a Hammer mesh.
public static CDmePolygonMesh WriteMesh(PolygonMesh polygonMesh)Parameters
polygonMesh PolygonMesh
Mesh to write.

