diff --git a/orx-mesh-generators/src/jvmDemo/kotlin/DemoExtrude01.kt b/orx-mesh-generators/src/jvmDemo/kotlin/DemoExtrude01.kt index a9ed6908..639bccdf 100644 --- a/orx-mesh-generators/src/jvmDemo/kotlin/DemoExtrude01.kt +++ b/orx-mesh-generators/src/jvmDemo/kotlin/DemoExtrude01.kt @@ -11,6 +11,16 @@ import org.openrndr.extra.shapes.splines.toPath3D import org.openrndr.math.Vector3 import org.openrndr.shape.Circle +/** + * Demonstrates how to create curved tubes by extruding + * a circular contour along a 3D catmullRom-path + * using [buildTriangleMesh] and [extrudeContourSteps]. + * + * The result is a [org.openrndr.draw.VertexBuffer] which can be rendered with + * `drawer.vertexBuffer()`. + * An [Orbital] camera makes the scene interactive. A minimal `shadeStyle` is used + * to simulate a directional light. + */ fun main() = application { configure { width = 720 diff --git a/orx-mesh-generators/src/jvmDemo/kotlin/DemoExtrude02.kt b/orx-mesh-generators/src/jvmDemo/kotlin/DemoExtrude02.kt index 240d7a77..d2fad7e3 100644 --- a/orx-mesh-generators/src/jvmDemo/kotlin/DemoExtrude02.kt +++ b/orx-mesh-generators/src/jvmDemo/kotlin/DemoExtrude02.kt @@ -12,6 +12,16 @@ import org.openrndr.math.Vector3 import org.openrndr.shape.Circle import org.openrndr.shape.Shape +/** + * Demonstrates how to create hollow tubes with thickness by extruding + * a circular [Shape] built out of two concentric circular contours. + * Note that the inner contour is reversed. + * + * The result is a [org.openrndr.draw.VertexBuffer] which can be rendered with + * `drawer.vertexBuffer()`. + * An [Orbital] camera makes the scene interactive. A minimal `shadeStyle` is used + * to simulate a directional light. + */ fun main() = application { configure { width = 720 @@ -33,7 +43,12 @@ fun main() = application { translate(-5.0, 0.0, 0.0) - val ring = Shape(listOf(Circle(0.0, 0.0, 0.5).contour, Circle(0.0, 0.0, 0.25).contour.reversed)) + val ring = Shape( + listOf( + Circle(0.0, 0.0, 0.5).contour, + Circle(0.0, 0.0, 0.25).contour.reversed + ) + ) for (i in 0 until 5) { extrudeShapeSteps( diff --git a/orx-mesh-generators/src/jvmDemo/kotlin/DemoExtrude03.kt b/orx-mesh-generators/src/jvmDemo/kotlin/DemoExtrude03.kt index 1ce96a8a..5cb54f7c 100644 --- a/orx-mesh-generators/src/jvmDemo/kotlin/DemoExtrude03.kt +++ b/orx-mesh-generators/src/jvmDemo/kotlin/DemoExtrude03.kt @@ -6,6 +6,7 @@ import org.openrndr.draw.shadeStyle import org.openrndr.extra.camera.Orbital import org.openrndr.extra.meshgenerators.buildTriangleMesh import org.openrndr.extra.meshgenerators.extrudeContourAdaptive +import org.openrndr.extra.meshgenerators.extrudeContourSteps import org.openrndr.math.Polar import org.openrndr.math.Vector3 import org.openrndr.math.asDegrees @@ -15,6 +16,19 @@ import org.openrndr.shape.Path3D import kotlin.math.PI import kotlin.math.exp +/** + * Demonstration creating two intersecting spirals + * using [buildTriangleMesh] and [extrudeContourAdaptive]. + * This approach generates as many vertices as needed + * based on the provided tolerance. + * + * The result is a [org.openrndr.draw.VertexBuffer] which can be rendered with + * `drawer.vertexBuffer()`. + * + * The [Orbital] camera slowly rotates on its own while + * still being interactive. + * A minimal `shadeStyle` is used to simulate a directional light. + */ fun main() = application { configure { width = 720 diff --git a/orx-mesh-generators/src/jvmDemo/kotlin/DemoExtrude04.kt b/orx-mesh-generators/src/jvmDemo/kotlin/DemoExtrude04.kt index 56cb2bda..e00f5c06 100644 --- a/orx-mesh-generators/src/jvmDemo/kotlin/DemoExtrude04.kt +++ b/orx-mesh-generators/src/jvmDemo/kotlin/DemoExtrude04.kt @@ -6,14 +6,22 @@ import org.openrndr.draw.shadeStyle import org.openrndr.extra.camera.Orbital import org.openrndr.extra.meshgenerators.buildTriangleMesh import org.openrndr.extra.meshgenerators.extrudeContourSteps -import org.openrndr.extra.noise.Random +import org.openrndr.extra.noise.simplex import org.openrndr.math.Vector3 import org.openrndr.shape.Circle import org.openrndr.shape.Path3D import org.openrndr.shape.Segment3D /** - * Extruded Bézier tubes grown on a morphing Bézier surface. + * A series of 3D Bézier tubes grown on an animated, + * morphing, invisible Bézier surface. + * + * As if we were drawing a series of parallel lines + * on a piece of paper, then twisting and bending + * that paper over time. + * + * Demonstrates how to destroy a [org.openrndr.draw.VertexBuffer] + * on every animation frame to avoid filling out the memory. * */ fun main() = application { @@ -41,7 +49,7 @@ fun main() = application { val m = buildTriangleMesh { val beziers = List(4) { curveId -> val n = List(12) { - Random.simplex(it * 7.387, curveId * 5.531 + seconds * 0.05) * 10.0 + simplex(1413, it * 7.387, curveId * 5.531 + seconds * 0.05) * 10.0 } Segment3D( Vector3(n[0], n[1], n[2]), diff --git a/orx-mesh-generators/src/jvmDemo/kotlin/DemoExtrude05.kt b/orx-mesh-generators/src/jvmDemo/kotlin/DemoExtrude05.kt index 83bcd763..1a840aa1 100644 --- a/orx-mesh-generators/src/jvmDemo/kotlin/DemoExtrude05.kt +++ b/orx-mesh-generators/src/jvmDemo/kotlin/DemoExtrude05.kt @@ -6,7 +6,7 @@ import org.openrndr.draw.shadeStyle import org.openrndr.extra.camera.Orbital import org.openrndr.extra.meshgenerators.buildTriangleMesh import org.openrndr.extra.meshgenerators.extrudeContourStepsScaled -import org.openrndr.extra.noise.Random +import org.openrndr.extra.noise.simplex import org.openrndr.math.Vector3 import org.openrndr.shape.Circle import org.openrndr.shape.Path3D @@ -15,7 +15,15 @@ import kotlin.math.PI import kotlin.math.cos /** - * Extruded Bézier tubes grown on a morphing Bézier surface. + * A series of 3D Bézier tubes grown on an animated, + * morphing, invisible Bézier surface. + * + * This variation uses [extrudeContourStepsScaled] to + * apply a varying scaling to the cross-sections, + * making the ends shrink to a hairline. + * + * Calls `destroy` on the [org.openrndr.draw.VertexBuffer] + * on every animation frame to free the used memory. * */ fun main() = application { @@ -43,7 +51,7 @@ fun main() = application { val m = buildTriangleMesh { val beziers = List(4) { curveId -> val n = List(12) { - Random.simplex(it * 7.387, curveId * 5.531 + seconds * 0.05) * 10.0 + simplex(7453, it * 7.387, curveId * 5.531 + seconds * 0.05) * 10.0 } Segment3D( Vector3(n[0], n[1], n[2]), diff --git a/orx-mesh-generators/src/jvmDemo/kotlin/DemoExtrude06.kt b/orx-mesh-generators/src/jvmDemo/kotlin/DemoExtrude06.kt index 491a608b..b1ab5056 100644 --- a/orx-mesh-generators/src/jvmDemo/kotlin/DemoExtrude06.kt +++ b/orx-mesh-generators/src/jvmDemo/kotlin/DemoExtrude06.kt @@ -5,7 +5,6 @@ import org.openrndr.draw.* import org.openrndr.extra.camera.Orbital import org.openrndr.extra.meshgenerators.buildTriangleMesh import org.openrndr.extra.meshgenerators.extrudeContourStepsMorphed -import org.openrndr.extra.noise.Random import org.openrndr.extra.noise.simplex import org.openrndr.math.Polar import org.openrndr.math.Vector2 @@ -18,9 +17,16 @@ import kotlin.math.PI import kotlin.math.cos /** - * Demo extrudeContourStepsMorphed which allows to create a mesh with a morphing cross-section - * based on the t value along a Path3D. In other words, a tube in which the cross-section does not need - * to be constant, but can be scaled, rotated and displaced along its curvy axis. + * Demo [extrudeContourStepsMorphed] which allows creating a mesh with an animated, morphing cross-section + * based on the t value along a [Path3D]. In other words, a tube in which the cross-section does not need + * to be constant, but can be scaled, rotated and displaced along its curved axis. + * + * Loads a texture and applies a repeat-wrapping mode to it. + * The texture can be enabled in the GLSL code inside + * the shadeStyle. + * + * The mesh is rendered 5 times rotated around axis Z + * for a radial-symmetry effect. */ fun main() = application { configure { @@ -29,8 +35,6 @@ fun main() = application { multisample = WindowMultisample.SampleCount(8) } program { - Random.seed = System.currentTimeMillis().toString() - val texture = loadImage("demo-data/images/peopleCity01.jpg").also { it.wrapU = WrapMode.REPEAT it.wrapV = WrapMode.REPEAT @@ -94,7 +98,7 @@ val crossSection = Circle(Vector2.ZERO, 0.1).contour.transform( transform { scale(5.0, 1.0, 1.0) } ) -// Create simplex-based 3D path +// Create a simplex-based 3D path fun get3DPath(scale: Double, time: Double, steps: Int): Path3D { val mult = 0.005 val points = List(steps) { Vector3.simplex(337, time + it * mult) * scale }