MeshBuilder Class Reference
- Last UpdatedMay 13, 2025
- 3 minute read
public class MeshBuilder
extension MeshBuilder: NativeBase
extension MeshBuilder: Hashable
Builder for meshes. Such meshes can contain different kinds of primitives, like quads or
triangles. Both primitives support adding texture coordinates that are mapped to the
corners of the primitives. See TriangleMeshBuilder
and QuadMeshBuilder
for more details.
Note: Normals cannot be set as they are not necessary when using the MeshBuilder
.
Example how to build a cube using QuadMeshBuilder
let cube = MeshBuilder()
.quad(a: Point3D(x: 0.5, y: 0.5, z: 0.5),
b: Point3D(x: -0.5, y: 0.5, z: 0.5),
c: Point3D(x: 0.5, y: -0.5, z: 0.5),
d: Point3D(x: -0.5, y: -0.5, z: 0.5))
.quad(a: Point3D(x: -0.5, y: 0.5, z: -0.5),
b: Point3D(x: 0.5, y: 0.5, z: -0.5),
c: Point3D(x: -0.5, y: -0.5, z: -0.5),
d: Point3D(x: 0.5, y: -0.5, z: -0.5))
.quad(a: Point3D(x: 0.5, y: 0.5, z: -0.5),
b: Point3D(x: 0.5, y: 0.5, z: 0.5),
c: Point3D(x: 0.5, y: -0.5, z: -0.5),
d: Point3D(x: 0.5, y: -0.5, z: 0.5))
.quad(a: Point3D(x: -0.5, y: 0.5, z: 0.5),
b: Point3D(x: -0.5, y: 0.5, z: -0.5),
c: Point3D(x: -0.5, y: -0.5, z: 0.5),
d: Point3D(x: -0.5, y: -0.5, z: -0.5))
.quad(a: Point3D(x: -0.5, y: 0.5, z: 0.5),
b: Point3D(x: 0.5, y: 0.5, z: 0.5),
c: Point3D(x: -0.5, y: 0.5, z: -0.5),
d: Point3D(x: 0.5, y: 0.5, z: -0.5))
.quad(a: Point3D(x: 0.5, y: -0.5, z: 0.5),
b: Point3D(x: -0.5, y: -0.5, z: 0.5),
c: Point3D(x: 0.5, y: -0.5, z: -0.5),
d: Point3D(x: -0.5, y: -0.5, z: -0.5))
.build()
-
Constructs an instance of MeshBuilder.
Declaration
Swift
public init()
-
Adds a triangle.
Triangle visibility is determined via back-face culling. Front-facing triangles are expected to have counter-clockwise winding.
Declaration
Swift
public func triangle(a: Point3D, b: Point3D, c: Point3D) -> TriangleMeshBuilder
Parameters
a
First vertex of the triangle.
b
Second vertex of the triangle.
c
Third vertex of the triangle.
Return Value
A
TriangleMeshBuilder
instance. -
Adds a quad. Internally, this will be transformed into triangles abc and bdc.
Triangle visibility is determined via back-face culling. Front-facing triangles are expected to have counter-clockwise winding.
Declaration
Swift
public func quad(a: Point3D, b: Point3D, c: Point3D, d: Point3D) -> QuadMeshBuilder
Parameters
a
First vertex of quad.
b
Second vertex of the quad.
c
Third vertex of the quad.
d
Fourth vertex of the quad.
Return Value
A
QuadMeshBuilder
instance. -
Declaration
Swift
public func build() -> Mesh?
Return Value
mesh containing added geometry or ‘null’ if no geometry was added.