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.envelope(basis: Box, volume: BezierVolume)

Deforms the vertices written so far into volume, by their places in the basis box: the CPU form of org.openrndr.extra.shapes.bezierpatches.bezierVolumeShadeStyle, and the counterpart of org.openrndr.extra.shapes.distort.envelope for meshes. Positions go to the point of the volume at their u, v, w in the box, normals are mapped by the inverse transpose of the Jacobian of that mapping and normalized, so lighting follows the deformed surface. Triangles keep their vertices, so a mesh needs enough of them to bend smoothly.

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

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, useFaceNormals: Boolean = false)

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 }, useFaceNormals: Boolean = false)

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

fun TriangleMeshBuilder.extrudeShape(shape: Shape, path: Path3D, scale: (Double) -> Double, torsion: (Double) -> Double, up0: Vector3, contourDistanceTolerance: Double = 0.5, pathDistanceTolerance: Double = 0.5, startCap: Boolean = true, endCap: Boolean = true, useFaceNormals: Boolean = false)
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, useFaceNormals: Boolean = false)

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, useFaceNormals: Boolean = false)

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 any 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.loft(loft: Loft, along: Int, around: Int, caps: Boolean = true, sharpCorners: Boolean = false)

Writes the triangles of loft: its side on a grid of along steps along the path and around steps around the cross-section, and with caps its ends, when it has them: a closed cross-section along a path that is not closed makes a closed solid. Normals point out of the loft, triangles are wound counterclockwise seen from outside. Texture coordinates are (u, v) on the side, and the bounds of the cross-section on the caps. With sharpCorners the corners of the cross-section, its Loft.corners, are sharp edges; see Loft.side.

Link copied to clipboard
fun TriangleMeshBuilder.patchClip(clip: PatchClip, patch: BezierPatch3D, thickness: Double = 0.0)

Writes the part of patch inside clip's shape: the surface, or with a thickness a solid between the surface and its offset along the normal, see PatchClip.vertices. Make the PatchClip once and write it again for a patch that changes.

fun TriangleMeshBuilder.patchClip(patch: BezierPatch3D, shape: Shape, basis: Rectangle, gridSize: Int = 32, thickness: Double = 0.0, distanceTolerance: Double = 0.5)

Writes the part of patch inside shape, by the place of the shape in basis: the surface, or with a thickness a solid between the surface and its offset along the normal, see PatchClip.

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 twist amount. 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.