Class HammerMeshBuilder
Namespace: ValveResourceFormat.IO
Assembly: ValveResourceFormat.dll
Builds a Hammer editable mesh and writes it out as a CDmePolygonMesh.
public class HammerMeshBuilderInheritance
object ← HammerMeshBuilder
Remarks
Add vertices with HammerMeshBuilder.AddVertices(ReadOnlySpan<Vector3>) and faces with HammerMeshBuilder.AddFace(ReadOnlySpan<int>, string, ReadOnlySpan<Corner>) (or use one of the adders for render and physics meshes), then write the result with HammerMeshBuilder.GenerateMesh().
HammerMeshBuilder.Untriangulate joins triangle pairs into quads, HammerMeshBuilder.GenerateMeshes() splits the mesh by connectivity and HammerMeshBuilder.GenerateMeshes(float) welds it first.
The mesh is a PolygonMesh, a half edge topology with Hammer data: position per vertex, corner data per half edge, material per face. HammerMeshBuilder.WriteMesh(PolygonMesh) writes it as a vmap.
Properties
DefaultProjectedTextureSize
Texture size assumed for a projected face when HammerMeshBuilder.TextureSizeProvider gives none: a texture that repeats every 128 units at HammerMeshBuilder.DefaultTextureScale, the usual Hammer world mapping.
public Vector2 DefaultProjectedTextureSize { get; }Property Value
DefaultTextureScale
Units one texel spans on a projected face, the game's Hammer/DefaultTextureScale.
public float DefaultTextureScale { get; init; }Property Value
float
FacesRemoved
Number of faces dropped while building, either degenerate or non manifold.
public int FacesRemoved { get; }Property Value
int
Mesh
The mesh being built. Editing operations (merging, dissolving, splitting into islands) apply once all faces are added, before writing.
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
int
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
IProgress<string>?
SurfacePropertyNames
The game's surface property names by hash, which name the surface properties of the physics shapes added.
public IReadOnlyDictionary<uint, string>? SurfacePropertyNames { get; init; }Property Value
IReadOnlyDictionary<uint, string>?
TextureSizeProvider
Size in texels of a material's texture, for projecting faces added without texture coordinates the way Hammer does. Null for unknown materials, which use HammerMeshBuilder.DefaultProjectedTextureSize.
public Func<string, Vector2?>? TextureSizeProvider { get; init; }Property Value
Untriangulate
Join coplanar triangle pairs into quads when writing, if they share a material and agree on corner data along their shared edge. Off by default.
public bool Untriangulate { get; init; }Property Value
bool
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 HammerMeshBuilder.FacesRemoved, 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.
AddPhysCapsule(CapsuleDescriptor, PhysAggregateData, Func<string, string>, Matrix4x4, string?)
Adds a physics capsule as the faces of a convex polyhedron inscribed in it.
public void AddPhysCapsule(CapsuleDescriptor desc, PhysAggregateData phys, Func<string, string> materialNameProvider, Matrix4x4 transform, string? materialOverride = null)Parameters
desc CapsuleDescriptor
Capsule to add.
phys PhysAggregateData
Physics data the capsule 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.
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.
AddPhysSphere(SphereDescriptor, PhysAggregateData, Func<string, string>, Matrix4x4, string?)
Adds a physics sphere as the faces of a convex polyhedron inscribed in it.
public void AddPhysSphere(SphereDescriptor desc, PhysAggregateData phys, Func<string, string> materialNameProvider, Matrix4x4 transform, string? materialOverride = null)Parameters
desc SphereDescriptor
Sphere to add.
phys PhysAggregateData
Physics data the sphere 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.
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
int
Index of the first added vertex, to add to the indices handed to HammerMeshBuilder.AddFace(ReadOnlySpan<int>, string, ReadOnlySpan<Corner>).
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
int
Index of the first added vertex, to add to the indices handed to HammerMeshBuilder.AddFace(ReadOnlySpan<int>, string, ReadOnlySpan<Corner>).
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 as Hammer meshes, one per island of faces connected through shared edges. Faces that did not fit the topology are grouped by coinciding positions. Untriangulated when HammerMeshBuilder.Untriangulate is set.
public List<CDmePolygonMesh> GenerateMeshes()Returns
GenerateMeshes(float)
Welds everything added so far where vertices coincide within the distance, so the draw calls of one object become one mesh again, and writes one Hammer mesh per connected part, see PolygonMesh.RemergeDrawCalls(float). Each part is untriangulated when HammerMeshBuilder.Untriangulate 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.

