diff --git a/orx-mesh-generators/build.gradle.kts b/orx-mesh-generators/build.gradle.kts index 41d26602..2b03a28c 100644 --- a/orx-mesh-generators/build.gradle.kts +++ b/orx-mesh-generators/build.gradle.kts @@ -18,6 +18,7 @@ kotlin { implementation(project(":orx-shapes")) implementation(project(":orx-mesh-generators")) implementation(project(":orx-camera")) + implementation(project(":orx-noise")) } } } diff --git a/orx-mesh-generators/src/commonMain/kotlin/TriangleMeshBuilder.kt b/orx-mesh-generators/src/commonMain/kotlin/TriangleMeshBuilder.kt index f6ec9eb6..c14d2e70 100644 --- a/orx-mesh-generators/src/commonMain/kotlin/TriangleMeshBuilder.kt +++ b/orx-mesh-generators/src/commonMain/kotlin/TriangleMeshBuilder.kt @@ -42,6 +42,16 @@ class TriangleMeshBuilder { } } + /** + * Applies a three-dimensional translation to the [transform] matrix. + * Affects meshes added afterward. + */ + fun translate(translation: Vector3) { + transform *= buildTransform { + translate(translation) + } + } + /** * Applies a rotation over an arbitrary axis to the [transform] matrix. * Affects meshes added afterward. diff --git a/orx-mesh-generators/src/jvmDemo/kotlin/DemoComplex06.kt b/orx-mesh-generators/src/jvmDemo/kotlin/DemoComplex06.kt new file mode 100644 index 00000000..bdfa6993 --- /dev/null +++ b/orx-mesh-generators/src/jvmDemo/kotlin/DemoComplex06.kt @@ -0,0 +1,62 @@ +import org.openrndr.WindowMultisample +import org.openrndr.application +import org.openrndr.color.rgb +import org.openrndr.draw.DrawPrimitive +import org.openrndr.draw.shadeStyle +import org.openrndr.extra.camera.Orbital +import org.openrndr.extra.meshgenerators.* +import org.openrndr.extra.noise.simplex +import org.openrndr.math.Vector3 + +/** + * Generates a grid of grids of boxes. + * Interactive orbital camera. + * + */ +fun main() { + application { + configure { + width = 800 + height = 800 + multisample = WindowMultisample.SampleCount(8) + } + program { + extend(Orbital()) { + this.eye = Vector3(3.0, 3.0, 10.0) + this.fov = 60.0 + } + val m = buildTriangleMesh { + grid(5, 5) { u, v -> + isolated { + grid(3, 3, 3, GridCoordinates.UNIPOLAR) { x, y, z -> + val pos0 = Vector3(u, v, 0.0) * 10.0 + val pos1 = Vector3(x, y, z) * 2.0 + val pos2 = pos0 + pos1 + Vector3( + y * 0.12 + z * 0.3, + x * 0.14 + z * 0.15, + x * 0.16 + y * 0.17 + ) + // Drop some boxes + if(simplex(0, pos1 * 0.5 + pos0 * 0.05) > 0) { + translate(pos2) + color = rgb(x, y, z) + box(1.2, 1.2, 1.2) + } + } + } + } + } + + extend { + drawer.shadeStyle = shadeStyle { + fragmentTransform = """ + x_fill = va_color; + vec3 s = sin(v_worldPosition.xyz * 2.5); + x_fill.rgb += s * 0.1 - 0.1; + """.trimIndent() + } + drawer.vertexBuffer(m, DrawPrimitive.TRIANGLES) + } + } + } +} \ No newline at end of file diff --git a/orx-mesh-generators/src/jvmDemo/kotlin/DemoExtrude04.kt b/orx-mesh-generators/src/jvmDemo/kotlin/DemoExtrude04.kt new file mode 100644 index 00000000..0f5cd333 --- /dev/null +++ b/orx-mesh-generators/src/jvmDemo/kotlin/DemoExtrude04.kt @@ -0,0 +1,86 @@ +import org.openrndr.WindowMultisample +import org.openrndr.application +import org.openrndr.color.ColorRGBa +import org.openrndr.draw.DrawPrimitive +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.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. + * + */ +fun main() { + application { + configure { + width = 800 + height = 800 + multisample = WindowMultisample.SampleCount(8) + } + program { + val crossSection = Circle(0.0, 0.0, 0.2).contour + + extend(Orbital()) { + this.eye = Vector3(0.0, 3.0, 7.0) + this.lookAt = Vector3(0.0, 0.0, 0.0) + } + + extend { + drawer.shadeStyle = shadeStyle { + fragmentTransform = """ + x_fill = va_color; + x_fill.rgb *= v_viewNormal.z; + """.trimIndent() + } + + 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 + } + Segment3D( + Vector3(n[0], n[1], n[2]), + Vector3(n[3], n[4], n[5]), + Vector3(n[6], n[7], n[8]), + Vector3(n[9], n[10], n[11]) + ) + } + + for (i in 0 until 20) { + val t = i / (20.0 - 1.0) + val path = Path3D( + listOf( + Segment3D( + beziers[0].position(t), + beziers[1].position(t), + beziers[2].position(t), + beziers[3].position(t) + ) + ), false + ) + color = if(i % 2 == 0) ColorRGBa.PINK else ColorRGBa.WHITE.shade(0.1) + extrudeContourSteps( + crossSection, + path, + 120, + Vector3.UNIT_Y, + contourDistanceTolerance = 0.05, + pathDistanceTolerance = 0.05 + ) + } + } + + drawer.vertexBuffer(m, DrawPrimitive.TRIANGLES) + + // Remember to free the memory! Otherwise, the computer will quickly run out of RAM. + m.destroy() + } + } + } +}