Add shape extrusion mesh generator for precalced tessellation
This commit is contained in:
@@ -127,6 +127,10 @@ fun GeneratorBuffer.revolve(sides:Int, length:Double, enveloppe: List<Vector2>)
|
||||
generateRevolve(sides, length, enveloppe, this::write)
|
||||
}
|
||||
|
||||
fun GeneratorBuffer.extrudeShape( baseTriangles:List<Vector2>, contours:List<List<Vector2>>, length: Double, scale: Double = 1.0, distanceTolerance: Double = 0.5) {
|
||||
extrudeShape(baseTriangles, contours, -length / 2.0, length / 2.0, scale, scale, true, true, distanceTolerance, false, this::write)
|
||||
}
|
||||
|
||||
fun GeneratorBuffer.extrudeShape(shape: Shape, length: Double, scale: Double = 1.0, distanceTolerance: Double = 0.5) {
|
||||
extrudeShape(shape, -length / 2.0, length / 2.0, scale, scale, true, true, distanceTolerance, false, this::write)
|
||||
}
|
||||
|
||||
@@ -43,12 +43,11 @@ fun extrudeShape(shape: Shape, front: Double, back: Double, distanceTolerance: D
|
||||
extrudeShape(shape, front, back, distanceTolerance = distanceTolerance, flipNormals = false, writer = writer)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* extrudes a [shape] by triangulating it and creating side- and cap geometry
|
||||
* @sample sample
|
||||
* extrudes a [shape] from its triangulations
|
||||
*/
|
||||
fun extrudeShape(shape: Shape,
|
||||
front: Double,
|
||||
fun extrudeShape(baseTriangles: List<Vector2>, contours: List<List<Vector2>>, front: Double,
|
||||
back: Double,
|
||||
frontScale: Double = 1.0,
|
||||
backScale: Double = 1.0,
|
||||
@@ -56,7 +55,7 @@ fun extrudeShape(shape: Shape,
|
||||
backCap: Boolean = true,
|
||||
distanceTolerance: Double = 0.5,
|
||||
flipNormals: Boolean = false, writer: VertexWriter) {
|
||||
val baseTriangles = triangulate(shape, distanceTolerance)
|
||||
|
||||
val depth = back - front
|
||||
val flip = if (flipNormals) 1.0 else -1.0
|
||||
|
||||
@@ -76,8 +75,8 @@ fun extrudeShape(shape: Shape,
|
||||
}
|
||||
}
|
||||
|
||||
shape.contours.forEach {
|
||||
val points = it.adaptivePositions(distanceTolerance)
|
||||
contours.forEach {
|
||||
val points = it
|
||||
|
||||
val normals = (0 until points.size).map {
|
||||
(points[mod(it + 1, points.size)] - points[mod(it - 1, points.size)]).safeNormalized * -flip
|
||||
@@ -106,6 +105,26 @@ fun extrudeShape(shape: Shape,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* extrudes a [shape] by triangulating it and creating side- and cap geometry
|
||||
*/
|
||||
fun extrudeShape(shape: Shape,
|
||||
front: Double,
|
||||
back: Double,
|
||||
frontScale: Double = 1.0,
|
||||
backScale: Double = 1.0,
|
||||
frontCap: Boolean = true,
|
||||
backCap: Boolean = true,
|
||||
distanceTolerance: Double = 0.5,
|
||||
flipNormals: Boolean = false, writer: VertexWriter) {
|
||||
val baseTriangles = triangulate(shape, distanceTolerance)
|
||||
val points = shape.contours.map { it.adaptivePositions(distanceTolerance) }
|
||||
|
||||
extrudeShape(baseTriangles, points, front, back, frontScale, backScale, frontCap, backCap, distanceTolerance,
|
||||
flipNormals, writer)
|
||||
}
|
||||
|
||||
fun extrudeShapes(shapes: List<Shape>,
|
||||
front: Double,
|
||||
back: Double,
|
||||
|
||||
Reference in New Issue
Block a user