diff --git a/build.gradle b/build.gradle index ab94c926..782e5ee1 100644 --- a/build.gradle +++ b/build.gradle @@ -20,16 +20,26 @@ project.ext { spekVersion = "2.0.10" libfreenectVersion = "0.5.7-1.5.2" gsonVersion = "2.8.6" -} +} +switch (org.gradle.internal.os.OperatingSystem.current()) { + case org.gradle.internal.os.OperatingSystem.WINDOWS: + project.ext.openrndrOS = "windows" + break + case org.gradle.internal.os.OperatingSystem.LINUX: + project.ext.openrndrOS = "linux-x64" + break + case org.gradle.internal.os.OperatingSystem.MAC_OS: + project.ext.openrndrOS = "macos" + break +} dokka { moduleName = "$rootProject.name" outputDirectory = "$buildDir/docs" outputFormat = "html" includes = ['Module.md'] sourceDirs = files(subprojects.collect { p -> new File(p.projectDir, "/src/main/kotlin") }) - } - +} allprojects { apply plugin: 'idea' @@ -72,13 +82,11 @@ allprojects { runtimeOnly "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion" } - java { sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 } - javadoc { options.addBooleanOption 'Xdoclint:none', true } diff --git a/orx-mesh-generators/build.gradle b/orx-mesh-generators/build.gradle new file mode 100644 index 00000000..6e7d4be1 --- /dev/null +++ b/orx-mesh-generators/build.gradle @@ -0,0 +1,18 @@ +sourceSets { + demo { + java { + srcDirs = ["src/demo/kotlin"] + compileClasspath += main.getCompileClasspath() + runtimeClasspath += main.getRuntimeClasspath() + } + } +} + +dependencies { + demoImplementation(project(":orx-camera")) + demoImplementation("org.openrndr:openrndr-core:$openrndrVersion") + demoRuntimeOnly("org.openrndr:openrndr-gl3:$openrndrVersion") + demoRuntimeOnly("org.openrndr:openrndr-gl3-natives-$openrndrOS:$openrndrVersion") + + demoImplementation(sourceSets.getByName("main").output) +} \ No newline at end of file diff --git a/orx-mesh-generators/src/demo/kotlin/DemoBox.kt b/orx-mesh-generators/src/demo/kotlin/DemoBox.kt new file mode 100644 index 00000000..63689924 --- /dev/null +++ b/orx-mesh-generators/src/demo/kotlin/DemoBox.kt @@ -0,0 +1,35 @@ +import org.openrndr.application +import org.openrndr.color.ColorRGBa +import org.openrndr.draw.DrawPrimitive +import org.openrndr.draw.colorBuffer +import org.openrndr.draw.shadeStyle +import org.openrndr.extras.camera.Orbital +import org.openrndr.extras.meshgenerators.boxMesh + +fun main() { + application { + program { + val box = boxMesh(1.0, 1.0, 1.0) + val texture = colorBuffer(256, 256) + val s = texture.shadow + for (y in 0 until 256) { + for (x in 0 until 256) { + s[x, y] = ColorRGBa(x/256.0, y/256.0, 0.0, 1.0) + } + } + s.upload() + + extend(Orbital()) + extend { + drawer.background(ColorRGBa.PINK) + drawer.shadeStyle = shadeStyle { + fragmentTransform = """ + x_fill = texture(p_texture, va_texCoord0.xy); + """.trimIndent() + parameter("texture", texture) + } + drawer.vertexBuffer(box, DrawPrimitive.TRIANGLES) + } + } + } +} \ No newline at end of file diff --git a/orx-mesh-generators/src/main/kotlin/Plane.kt b/orx-mesh-generators/src/main/kotlin/Plane.kt index 31e16d78..d56fd019 100644 --- a/orx-mesh-generators/src/main/kotlin/Plane.kt +++ b/orx-mesh-generators/src/main/kotlin/Plane.kt @@ -1,84 +1,84 @@ -package org.openrndr.extras.meshgenerators - -import org.openrndr.draw.VertexBuffer -import org.openrndr.math.Vector2 -import org.openrndr.math.Vector3 - -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 { - - val vertexCount = (widthSegments * heightSegments) * 6 - val vb = meshVertexBuffer(vertexCount) - vb.put { - generatePlane(center, right, forward, up, - width, height, widthSegments, heightSegments, bufferWriter(this)) - } - return vb -} - -/** - * generates a finite plane with its center at (0,0,0) and spanning the xz-plane - */ -fun groundPlaneMesh(width: Double = 1.0, - height: Double = 1.0, - widthSegments: Int = 1, - heightSegments: Int = 1): VertexBuffer { - return planeMesh(Vector3.ZERO, Vector3.UNIT_X, Vector3.UNIT_Z, Vector3.UNIT_Y, - width, height, widthSegments, heightSegments) -} - -/** - * generates a finite plane with its center at (0,0,0) and spanning the xy-plane - */ -fun wallPlaneMesh(width: Double = 1.0, - height: Double = 1.0, - widthSegments: Int = 1, - heightSegments: Int = 1): VertexBuffer { - return planeMesh(Vector3.ZERO, Vector3.UNIT_X, Vector3.UNIT_Y, Vector3.UNIT_Z, - width, height, widthSegments, heightSegments) -} - - -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 = 2, - writer: VertexWriter) { - - val forwardStep = forward.normalized * (height / heightSegments) - val rightStep = right.normalized * (width / widthSegments) - - val corner = center - forward.normalized * (height*0.5) - right.normalized * (width * 0.5) - - val step = Vector2(1.0 / width, 1.0 / height) - - for (v in 0 until heightSegments) { - for (u in 0 until widthSegments) { - - val uv00 = Vector2(u + 0.0, v + 0.0) * step - val uv01 = Vector2(u + 0.0, v + 1.0) * step - val uv10 = Vector2(u + 1.0, v + 0.0) * step - val uv11 = Vector2(u + 1.0, v + 1.0) * step - - val c00 = corner + forwardStep * v.toDouble() + rightStep * u.toDouble() - val c01 = corner + forwardStep * (v + 1).toDouble() + rightStep * u.toDouble() - val c10 = corner + forwardStep * v.toDouble() + rightStep * (u + 1).toDouble() - val c11 = corner + forwardStep * (v + 1).toDouble() + rightStep * (u + 1).toDouble() - - writer(c11, up, uv00) - writer(c10, up, uv10) - writer(c00, up, uv11) - - writer(c00, up, uv11) - writer(c01, up, uv01) - writer(c11, up, uv00) - } - } -} +package org.openrndr.extras.meshgenerators + +import org.openrndr.draw.VertexBuffer +import org.openrndr.math.Vector2 +import org.openrndr.math.Vector3 + +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 { + + val vertexCount = (widthSegments * heightSegments) * 6 + val vb = meshVertexBuffer(vertexCount) + vb.put { + generatePlane(center, right, forward, up, + width, height, widthSegments, heightSegments, bufferWriter(this)) + } + return vb +} + +/** + * generates a finite plane with its center at (0,0,0) and spanning the xz-plane + */ +fun groundPlaneMesh(width: Double = 1.0, + height: Double = 1.0, + widthSegments: Int = 1, + heightSegments: Int = 1): VertexBuffer { + return planeMesh(Vector3.ZERO, Vector3.UNIT_X, Vector3.UNIT_Z, Vector3.UNIT_Y, + width, height, widthSegments, heightSegments) +} + +/** + * generates a finite plane with its center at (0,0,0) and spanning the xy-plane + */ +fun wallPlaneMesh(width: Double = 1.0, + height: Double = 1.0, + widthSegments: Int = 1, + heightSegments: Int = 1): VertexBuffer { + return planeMesh(Vector3.ZERO, Vector3.UNIT_X, Vector3.UNIT_Y, Vector3.UNIT_Z, + width, height, widthSegments, heightSegments) +} + + +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 = 2, + writer: VertexWriter) { + + val forwardStep = forward.normalized * (height / heightSegments) + val rightStep = right.normalized * (width / widthSegments) + + val corner = center - forward.normalized * (height*0.5) - right.normalized * (width * 0.5) + + val step = Vector2(1.0 / widthSegments, 1.0 / heightSegments) + + for (v in 0 until heightSegments) { + for (u in 0 until widthSegments) { + + val uv00 = Vector2(u + 0.0, v + 0.0) * step + val uv01 = Vector2(u + 0.0, v + 1.0) * step + val uv10 = Vector2(u + 1.0, v + 0.0) * step + val uv11 = Vector2(u + 1.0, v + 1.0) * step + + val c00 = corner + forwardStep * v.toDouble() + rightStep * u.toDouble() + val c01 = corner + forwardStep * (v + 1).toDouble() + rightStep * u.toDouble() + val c10 = corner + forwardStep * v.toDouble() + rightStep * (u + 1).toDouble() + val c11 = corner + forwardStep * (v + 1).toDouble() + rightStep * (u + 1).toDouble() + + writer(c11, up, uv00) + writer(c10, up, uv10) + writer(c00, up, uv11) + + writer(c00, up, uv11) + writer(c01, up, uv01) + writer(c11, up, uv00) + } + } +}