TriangleMeshBuilder

A class that provides a simple Domain Specific Language to construct and deform triangle-based 3D meshes.

Constructors

Link copied to clipboard
constructor()

Types

Link copied to clipboard
class VertexData(val position: Vector3, val normal: Vector3, val texCoord: Vector2, val color: ColorRGBa)

A container class for vertex position, normal, texCoord and color.

Properties

Link copied to clipboard
var color: ColorRGBa
Link copied to clipboard
Link copied to clipboard
var normalTransform: Matrix44
Link copied to clipboard
var transform: Matrix44

Functions

Link copied to clipboard
fun TriangleMeshBuilder.box(width: Double, height: Double, depth: Double, widthSegments: Int = 1, heightSegments: Int = 1, depthSegments: Int = 1, flipNormals: Boolean = false)

Generate a box of size width, height and depth. Specify the number of segments with widthSegments, heightSegments and depthSegments. Use flipNormals for an inside-out shape.

Link copied to clipboard
fun TriangleMeshBuilder.cap(sides: Int, radius: Double, envelope: List<Vector2>)

Generate a shape by rotating an envelope around a vertical axis.

Link copied to clipboard

Append other data into data, combining the two meshes.

Link copied to clipboard
fun TriangleMeshBuilder.cylinder(sides: Int, segments: Int, radius: Double, length: Double, flipNormals: Boolean = false, center: Boolean = false)

Generate a cylinder

Link copied to clipboard

Generate dodecahedron mesh

Link copied to clipboard
fun TriangleMeshBuilder.extrudeContourAdaptive(contour: ShapeContour, path: Path3D, up0: Vector3, contourDistanceTolerance: Double = 0.5, pathDistanceTolerance: Double = 0.5)

Extrude a contour along a path. The number of resulting steps along the path depends on the tolerance values.

Link copied to clipboard
fun TriangleMeshBuilder.extrudeContourSteps(contour: ShapeContour, path: Path3D, stepCount: Int, up0: Vector3, contourDistanceTolerance: Double = 0.5, pathDistanceTolerance: Double = 0.5)

Extrude a contour along a path specifying the number of steps.

Link copied to clipboard
fun TriangleMeshBuilder.extrudeContourStepsMorphed(contour: (Double) -> ShapeContour, path: Path3D, stepCount: Int, up0: Vector3, startCap: Boolean = true, endCap: Boolean = true, contourDistanceTolerance: Double = 0.5, pathDistanceTolerance: Double = 0.5)

Extrude a contour along a path specifying the number of steps.

Link copied to clipboard
fun TriangleMeshBuilder.extrudeContourStepsScaled(contour: ShapeContour, path: Path3D, stepCount: Int, up0: Vector3, contourDistanceTolerance: Double = 0.5, pathDistanceTolerance: Double = 0.5, startCap: Boolean = true, endCap: Boolean = true, scale: (Double) -> Double = { _ -> 1.0 })

Extrude a contour along a path specifying the number of steps. The scale argument can be used to make variable width shapes. For example scale = { t: Double -> 0.5 - 0.5 * cos(t * 2 * PI) } produces an extruded shape that begins and ends with hairline thickness.

Link copied to clipboard
fun TriangleMeshBuilder.extrudeShape(baseTriangles: List<Vector2>, contours: List<List<Vector2>>, length: Double, scale: Double = 1.0, frontCap: Boolean = true, backCap: Boolean = true, sides: Boolean = true)

Extrudes a Shape from its triangulations

fun TriangleMeshBuilder.extrudeShape(shape: Shape, length: Double, scale: Double = 1.0, frontCap: Boolean = true, backCap: Boolean = true, sides: Boolean = true, distanceTolerance: Double = 0.5)

Extrudes a Shape

Link copied to clipboard
fun TriangleMeshBuilder.extrudeShapeAdaptive(shape: Shape, path: Path3D, up0: Vector3, contourDistanceTolerance: Double = 0.5, pathDistanceTolerance: Double = 0.5, startCap: Boolean = true, endCap: Boolean = true)

Extrude a shape along a path. The number of resulting steps along the path depends on the tolerance values.

Link copied to clipboard
fun TriangleMeshBuilder.extrudeShapes(shapes: List<Shape>, length: Double, scale: Double = 1.0, distanceTolerance: Double = 0.5)

Extrudes a list of Shape

Link copied to clipboard
fun TriangleMeshBuilder.extrudeShapeSteps(shape: Shape, path: Path3D, stepCount: Int, up0: Vector3, contourDistanceTolerance: Double = 0.5, pathDistanceTolerance: Double = 0.5, startCap: Boolean = true, endCap: Boolean = true)

Extrude a shape along a path specifying the number of steps.

Link copied to clipboard
fun TriangleMeshBuilder.grid(width: Int, height: Int, coordinates: GridCoordinates = GridCoordinates.BIPOLAR, builder: TriangleMeshBuilder.(u: Double, v: Double) -> Unit)

Create a 2D grid of width x height 3D elements. The builder function will get called with the u and v coordinates of each grid cell, so you have an opportunity to add meshes to the scene using those coordinates. The coordinate values will be scaled according to coordinates. Use:

fun TriangleMeshBuilder.grid(width: Int, height: Int, depth: Int, coordinates: GridCoordinates = GridCoordinates.BIPOLAR, builder: TriangleMeshBuilder.(u: Double, v: Double, w: Double) -> Unit)

Create a 3D grid of width x height x depth 3D elements. The builder function will get called with the u, v and w coordinates of each grid cell, so you have an opportunity to add meshes to the scene using those coordinates. The coordinate values will be scaled according to coordinates. Use:

Link copied to clipboard

Creates a group. Can be used to avoid leaking mesh properties like color and transform into following meshes or groups.

Link copied to clipboard
fun TriangleMeshBuilder.hemisphere(sides: Int, segments: Int, radius: Double, flipNormals: Boolean = false)

Add a hemisphere

Link copied to clipboard
fun isolated(function: TriangleMeshBuilder.() -> Unit)

Pushes the transform matrix, calls function and pops.

Link copied to clipboard
fun TriangleMeshBuilder.plane(center: Vector3, right: Vector3, forward: Vector3, up: Vector3, width: Double = 1.0, height: Double = 1.0, widthSegments: Int = 1, heightSegments: Int = 1)

Generate plane centered at center, using the right, forward and up vectors for its orientation. width and height specify the dimensions of the plane. widthSegments and heightSegments control the plane's number of segments.

Link copied to clipboard

Pop the active transform matrix from the transform state stack.

Link copied to clipboard

Push the active transform matrix on the transform state stack.

Link copied to clipboard
fun TriangleMeshBuilder.revolve(sides: Int, length: Double, envelope: List<Vector2>)

Generate a shape by rotating an envelope around a vertical axis.

Link copied to clipboard
fun rotate(axis: Vector3, degrees: Double)

Applies a rotation over an arbitrary axis to the transform matrix. Affects meshes added afterward.

Link copied to clipboard
fun TriangleMeshBuilder.sphere(sides: Int, segments: Int, radius: Double, flipNormals: Boolean = false)

Add a sphere mesh

Link copied to clipboard
fun TriangleMeshBuilder.taperedCylinder(sides: Int, segments: Int, startRadius: Double, endRadius: Double, length: Double, flipNormals: Boolean = false, center: Boolean = false)

Generate a tapered cylinder along the z-axis

Link copied to clipboard
fun toByteBuffer(): MPPBuffer

Returns a MPPBuffer representation of data used for rendering.

Link copied to clipboard
fun translate(translation: Vector3)
fun translate(x: Double, y: Double, z: Double)

Applies a three-dimensional translation to the transform matrix. Affects meshes added afterward.

Link copied to clipboard
fun TriangleMeshBuilder.twist(degreesPerUnit: Double, start: Double, axis: Vector3 = Vector3.UNIT_Y)

Twists a 3D mesh around an axis that starts at Vector3.ZERO and ends at axis. degreesPerUnit controls the amount of twist. start is currently unused.

Link copied to clipboard
fun write(position: Vector3, normal: Vector3, texCoord: Vector2)

Write new vertex data into data. The current color is used for the vertex.