Package-level declarations

Types

Link copied to clipboard

Used by the grid methods. Specifies how the UV or UVW coordinates the user function receives are scaled.

Link copied to clipboard

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

Link copied to clipboard
typealias VertexWriter = (position: Vector3, normal: Vector3, texCoord: Vector2) -> Unit

Vertex writer function interface

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 boxMesh(width: Double = 1.0, height: Double = 1.0, depth: Double = 1.0, widthSegments: Int = 1, heightSegments: Int = 1, depthSegments: Int = 1, flipNormals: Boolean = false): VertexBuffer

Returns a Box mesh

Link copied to clipboard
fun bufferWriter(bw: BufferWriter): VertexWriter

create a VertexWriter that writes into a java.nio.ByteBuffer through BufferWriter

Link copied to clipboard
fun buildTriangleMesh(vertexBuffer: VertexBuffer? = null, builder: TriangleMeshBuilder.() -> Unit): VertexBuffer

Creates a triangle mesh builder

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
fun capMesh(sides: Int, radius: Double, envelope: List<Vector2> = listOf( Vector2(0.0, 0.0), Vector2(1.0, 0.0) )): VertexBuffer

A shape created by rotating an envelope around a vertical axis.

Link copied to clipboard
fun contourSegment(linearContour: List<Vector2>, frame0: Matrix44, frame1: Matrix44, writer: VertexWriter)

Writes quads to writer creating a surface that connects two displaced instances of linearContour. The positions and orientations of the two contours are defined by the frame0 and frame1 matrices.

fun contourSegment(linearContour0: List<Vector2>, linearContour1: List<Vector2>, frame0: Matrix44, frame1: Matrix44, writer: VertexWriter)

Writes quads to writer creating a surface that connects linearContour0 with linearContour1. The positions and orientations of the two contours are defined by the frame0 and frame1 matrices.

fun contourSegment(linearContour0: List<Vector2>, linearContour1: List<Vector2>, frame0: Matrix44, frame1: Matrix44, v0: Double, v1: Double, writer: VertexWriter)

Contour segment

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
fun cylinderMesh(sides: Int = 16, segments: Int = 16, radius: Double = 1.0, length: Double, flipNormals: Boolean = false, center: Boolean = false): VertexBuffer

Creates a cylinder along the z-axis

Link copied to clipboard

Generate dodecahedron mesh

Link copied to clipboard
fun dodecahedronMesh(radius: Double = 1.0): VertexBuffer

A dodecahedron mesh

Link copied to clipboard
fun extrudeCaps(linearShape: Shape, path: Path3D, startCap: Boolean, endCap: Boolean, frames: List<Matrix44>, writer: VertexWriter)

Adds caps to an extruded shape

Link copied to clipboard
fun extrudeContourAdaptive(contour: ShapeContour, path: Path3D, up0: Vector3, contourDistanceTolerance: Double = 0.5, pathDistanceTolerance: Double = 0.5, steps: List<Vector3> = path.adaptivePositions(pathDistanceTolerance), frames: List<Matrix44> = steps.frames(up0), startCap: Boolean = true, endCap: Boolean = true, writer: VertexWriter)

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.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 extrudeContourSteps(contour: ShapeContour, path: Path3D, stepCount: Int, up0: Vector3, contourDistanceTolerance: Double = 0.5, pathDistanceTolerance: Double = 0.5, steps: List<Vector3> = path.equidistantPositions( stepCount, pathDistanceTolerance ), frames: List<Matrix44> = steps.frames(up0), startCap: Boolean = true, endCap: Boolean = true, writer: VertexWriter)

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

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 extrudeContourStepsMorphed(contour: (Double) -> ShapeContour, path: Path3D, stepCount: Int, up0: Vector3, contourDistanceTolerance: Double = 0.5, pathDistanceTolerance: Double = 0.5, steps: List<Vector3> = path.equidistantPositions( stepCount, pathDistanceTolerance ), frames: List<Matrix44> = steps.frames(up0), startCap: Boolean = true, endCap: Boolean = true, writer: VertexWriter)

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 extrudeContourStepsScaled(contour: ShapeContour, path: Path3D, stepCount: Int, up0: Vector3, contourDistanceTolerance: Double = 0.5, pathDistanceTolerance: Double = 0.5, steps: List<Vector3> = path.equidistantPositions( stepCount, pathDistanceTolerance ), frames: List<Matrix44> = steps.frames(up0), startCap: Boolean = true, endCap: Boolean = true, scale: (Double) -> Double = { _ -> 1.0 }, writer: VertexWriter)

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.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 extrudeShape(shape: Shape, front: Double, back: Double, distanceTolerance: Double = 0.5, writer: VertexWriter)

fun extrudeShape(baseTriangles: List<Vector2>, contours: List<List<Vector2>>, front: Double, back: Double, frontScale: Double = 1.0, backScale: Double = 1.0, frontCap: Boolean = true, backCap: Boolean = true, sides: Boolean = true, flipNormals: Boolean = false, writer: VertexWriter)

Extrudes a Shape from its triangulations

fun extrudeShape(shape: Shape, front: Double, back: Double, frontScale: Double = 1.0, backScale: Double = 1.0, frontCap: Boolean = true, backCap: Boolean = true, sides: Boolean = true, distanceTolerance: Double = 0.5, flipNormals: Boolean = false, writer: VertexWriter)

Extrudes a shape by triangulating it and creating side- and cap geometry.

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 extrudeShapeAdaptive(shape: Shape, path: Path3D, up0: Vector3, contourDistanceTolerance: Double = 0.5, pathDistanceTolerance: Double = 0.5, steps: List<Vector3> = path.adaptivePositions(pathDistanceTolerance), frames: List<Matrix44> = steps.frames(up0), startCap: Boolean, endCap: Boolean, writer: VertexWriter)

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.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 extrudeShapes(shapes: List<Shape>, front: Double, back: Double, frontScale: Double = 1.0, backScale: Double = 1.0, frontCap: Boolean = true, backCap: Boolean = true, sides: Boolean = true, distanceTolerance: Double = 0.5, flipNormals: Boolean = false, writer: VertexWriter)

Extrudes all shapes. Uses writer to write the resulting 3D meshes. The arguments are passed unmodified to extrudeShape.

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 extrudeShapeSteps(shape: Shape, path: Path3D, stepCount: Int, up0: Vector3, contourDistanceTolerance: Double = 0.5, pathDistanceTolerance: Double = 0.5, steps: List<Vector3> = path.equidistantPositions(stepCount, pathDistanceTolerance), frames: List<Matrix44> = steps.frames(up0), startCap: Boolean, endCap: Boolean, writer: VertexWriter)

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

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 generateBox(width: Double = 1.0, height: Double = 1.0, depth: Double = 1.0, widthSegments: Int = 1, heightSegments: Int = 1, depthSegments: Int = 1, flipNormals: Boolean = false, writer: VertexWriter)

Generate a box

Link copied to clipboard
fun generateCap(sides: Int, radius: Double, envelope: List<Vector2> = listOf( Vector2(0.0, 0.0), Vector2(1.0, 0.0) ), writer: VertexWriter)

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

Link copied to clipboard
fun generateCylinder(sides: Int, segments: Int, radius: Double, length: Double, flipNormals: Boolean = false, center: Boolean = false, writer: VertexWriter)

Generate a cylinder along the z-axis

Link copied to clipboard
fun generateDodecahedron(radius: Double = 1.0, writer: VertexWriter)

Generate dodecahedron mesh

Link copied to clipboard
fun generateHemisphere(sides: Int, segments: Int, radius: Double = 1.0, flipNormals: Boolean = false, writer: VertexWriter)

Generate hemisphere centered at the origin.

Link copied to clipboard
fun generatePlane(center: Vector3, right: Vector3, forward: Vector3, up: Vector3 = forward.cross(right).normalized, width: Double = 1.0, height: Double = 1.0, widthSegments: Int = 1, heightSegments: Int = 1, writer: VertexWriter)

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
fun generateRevolve(sides: Int, length: Double, envelope: List<Vector2> = listOf( Vector2(1.0, 0.0), Vector2(1.0, 1.0) ), writer: VertexWriter)

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

Link copied to clipboard
fun generateSphere(sides: Int, segments: Int, radius: Double = 1.0, flipNormals: Boolean = false, writer: VertexWriter)

Generate sphere centered at the origin.

Link copied to clipboard
fun generateTaperedCylinder(sides: Int, segments: Int, radiusStart: Double, radiusEnd: Double, length: Double, flipNormals: Boolean = false, center: Boolean = false, writer: VertexWriter)

Generate a tapered cylinder along the z-axis

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
fun groundPlaneMesh(width: Double = 1.0, height: Double = 1.0, widthSegments: Int = 1, heightSegments: Int = 1): VertexBuffer

Generates a finite plane with its center at (0,0,0) and spanning the xz-plane.

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 meshVertexBuffer(size: Int): VertexBuffer

Creates a VertexBuffer that is suited for holding meshes. Each vertex contains:

Link copied to clipboard
fun meshVertexBufferWithColor(size: Int): VertexBuffer

Creates a VertexBuffer that is suited for holding meshes. Each vertex contains:

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
fun planeMesh(center: Vector3, right: Vector3, forward: Vector3, up: Vector3 = forward.cross(right).normalized, width: Double = 1.0, height: Double = 1.0, widthSegments: Int = 1, heightSegments: Int = 1): VertexBuffer

Generate a finite 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
fun quadToTris(v00: Vector3, v01: Vector3, v10: Vector3, v11: Vector3, faceNormal: Vector3, writer: VertexWriter)

Writes two triangles to writer representing the quad formed by four vertices.

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 revolveMesh(sides: Int, length: Double, envelope: List<Vector2> = listOf( Vector2(1.0, 0.0), Vector2(1.0, 1.0) )): VertexBuffer

A shape created by rotating an envelope around a vertical axis.

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 sphereMesh(sides: Int = 16, segments: Int = 16, radius: Double = 1.0, flipNormals: Boolean = false): VertexBuffer

Returns 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 Rectangle.toMesh(resolution: Double = 2.0): VertexBuffer

Converts a Rectangle to a VertexBuffer 2D mesh matching its location and dimensions. resolution specifies the size in pixels of the triangles in the mesh.

Link copied to clipboard
fun triangulationWithFrame(triangulation: List<Triangle>, frame: Matrix44, flipNormals: Boolean = true, writer: VertexWriter)

Writes a list of triangles transformed by the frame transformation matrix into writer.

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 wallPlaneMesh(width: Double = 1.0, height: Double = 1.0, widthSegments: Int = 1, heightSegments: Int = 1): VertexBuffer

Generates a finite plane with its center at (0,0,0) and spanning the xy-plane

Link copied to clipboard
fun writeTri(v0: Vector3, v1: Vector3, v2: Vector3, tc0: Vector2, tc1: Vector2, tc2: Vector2, faceNormal: Vector3, writer: VertexWriter)

Writes a triangle to writer.