[orx-mesh-generators] Add arguments to make sides in shape extrude optional
This commit is contained in:
@@ -143,16 +143,40 @@ fun GeneratorBuffer.extrudeShape(
|
||||
scale: Double = 1.0,
|
||||
frontCap: Boolean = true,
|
||||
backCap: Boolean = true,
|
||||
sides: Boolean = true,
|
||||
distanceTolerance: Double = 0.5
|
||||
) {
|
||||
extrudeShape(shape, -length / 2.0, length / 2.0, scale, scale, frontCap, backCap, distanceTolerance, false, this::write)
|
||||
extrudeShape(
|
||||
shape = shape,
|
||||
front = -length / 2.0,
|
||||
back = length / 2.0,
|
||||
frontScale = scale,
|
||||
backScale = scale,
|
||||
frontCap = frontCap,
|
||||
backCap = backCap,
|
||||
sides = sides,
|
||||
distanceTolerance = distanceTolerance,
|
||||
flipNormals = false,
|
||||
writer = this::write
|
||||
)
|
||||
}
|
||||
|
||||
fun GeneratorBuffer.extrudeShapes(shapes: List<Shape>, length: Double, scale: Double = 1.0, distanceTolerance: Double = 0.5) {
|
||||
extrudeShapes(shapes, -length / 2.0, length / 2.0, scale, scale, true, true, distanceTolerance, false, this::write)
|
||||
extrudeShapes(
|
||||
shapes = shapes,
|
||||
front = -length / 2.0,
|
||||
back = length / 2.0,
|
||||
frontScale = scale,
|
||||
backScale = scale,
|
||||
frontCap = true,
|
||||
backCap = true,
|
||||
sides = true,
|
||||
distanceTolerance = distanceTolerance,
|
||||
flipNormals = false,
|
||||
writer = this::write
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
fun meshGenerator(vertexBuffer: VertexBuffer? = null, builder: GeneratorBuffer.() -> Unit): VertexBuffer {
|
||||
val gb = GeneratorBuffer()
|
||||
gb.builder()
|
||||
|
||||
@@ -53,6 +53,7 @@ fun extrudeShape(baseTriangles: List<Vector2>, contours: List<List<Vector2>>, fr
|
||||
backScale: Double = 1.0,
|
||||
frontCap: Boolean = true,
|
||||
backCap: Boolean = true,
|
||||
sides: Boolean = true,
|
||||
distanceTolerance: Double = 0.5,
|
||||
flipNormals: Boolean = false, writer: VertexWriter) {
|
||||
|
||||
@@ -75,6 +76,7 @@ fun extrudeShape(baseTriangles: List<Vector2>, contours: List<List<Vector2>>, fr
|
||||
}
|
||||
}
|
||||
|
||||
if (sides) {
|
||||
contours.forEach {
|
||||
val points = it
|
||||
|
||||
@@ -121,6 +123,7 @@ fun extrudeShape(baseTriangles: List<Vector2>, contours: List<List<Vector2>>, fr
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -133,12 +136,13 @@ fun extrudeShape(shape: Shape,
|
||||
backScale: Double = 1.0,
|
||||
frontCap: Boolean = true,
|
||||
backCap: Boolean = true,
|
||||
sides: 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,
|
||||
extrudeShape(baseTriangles, points, front, back, frontScale, backScale, sides, frontCap, backCap, distanceTolerance,
|
||||
flipNormals, writer)
|
||||
}
|
||||
|
||||
@@ -149,10 +153,11 @@ fun extrudeShapes(shapes: List<Shape>,
|
||||
backScale: Double = 1.0,
|
||||
frontCap: Boolean = true,
|
||||
backCap: Boolean = true,
|
||||
sides: Boolean = true,
|
||||
distanceTolerance: Double = 0.5,
|
||||
flipNormals: Boolean = false, writer: VertexWriter) {
|
||||
shapes.forEach {
|
||||
extrudeShape(it, front, back, frontScale, backScale, frontCap, backCap, distanceTolerance, flipNormals, writer)
|
||||
extrudeShape(it, front, back, frontScale, backScale, frontCap, backCap, sides, distanceTolerance, flipNormals, writer)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,15 +169,3 @@ private val Vector2.safeNormalized: Vector2
|
||||
Vector2.ZERO
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @suppress
|
||||
*/
|
||||
private fun sample() {
|
||||
val shape = Circle(100.0, 100.0, 200.0).shape
|
||||
val vbo = meshVertexBuffer(400)
|
||||
|
||||
val vertexCount = vbo.put {
|
||||
extrudeShape(shape, 0.0, 10.0, 0.05, bufferWriter(this))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user