Bumped version to 0.0.12. Added orx-mesh-generators. OPENRNDR 0.3.29
This commit is contained in:
@@ -7,10 +7,11 @@ A growing library of assorted data structures, algorithms and utilities.
|
||||
- [`orx-integral-image`](orx-integral-image/README.md), a CPU-based implementation for integral images (summed area tables)
|
||||
- `orx-jumpflood`, a filter/shader based implementation of the jump flood algorithm for finding fast approximate (directional) distance fields
|
||||
- `orx-kdtree`, a kd-tree implementation for fast nearest point searches
|
||||
- [`orx-mesh-generators`](orx-mesh-generators/README.md), triangular mesh generators
|
||||
- [`orx-no-clear`](orx-no-clear/README.md), a simple extension that provides drawing without clearing the background
|
||||
|
||||
## Usage
|
||||
ORX is built against OPENRNDR 0.3.28, make sure you use this version in your project. Because OPENRNDR's API is pre 1.0 it tends to change from time to time.
|
||||
ORX 0.0.12 is built against OPENRNDR 0.3.29, make sure you use this version in your project. Because OPENRNDR's API is pre 1.0 it tends to change from time to time.
|
||||
|
||||
The easiest way to add ORX to your project is through the use of Jitpack. [Jitpack](http://jitpack.io) is a service that pulls Gradle based libraries from Github, builds them and serves the jar files.
|
||||
|
||||
@@ -24,13 +25,13 @@ repositories {
|
||||
You can then add any of the ORX artefacts to your `dependencies {}`:
|
||||
```
|
||||
dependencies {
|
||||
compile 'com.github.openrndr.orx:<orx-artifact>:v0.0.11'
|
||||
compile 'com.github.openrndr.orx:<orx-artifact>:v0.0.12'
|
||||
}
|
||||
```
|
||||
|
||||
For example if you want to use the `orx-no-clear` artifact one would use:
|
||||
```
|
||||
dependencies {
|
||||
compile 'com.github.openrndr.orx:orx-no-clear:v0.0.11'
|
||||
compile 'com.github.openrndr.orx:orx-no-clear:v0.0.12'
|
||||
}
|
||||
```
|
||||
|
||||
10
build.gradle
10
build.gradle
@@ -1,18 +1,19 @@
|
||||
plugins {
|
||||
id 'org.jetbrains.kotlin.jvm' version '1.3.0'
|
||||
id 'org.jetbrains.kotlin.jvm' version '1.3.10'
|
||||
}
|
||||
|
||||
allprojects {
|
||||
group 'org.openrndr.extra'
|
||||
version '0.0.11'
|
||||
version '0.0.12'
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
ext {
|
||||
openrndrVersion = "0.3.28"
|
||||
openrndrVersion = "0.3.29-rc2"
|
||||
}
|
||||
|
||||
subprojects {
|
||||
@@ -30,7 +31,8 @@ subprojects {
|
||||
dependencies {
|
||||
compile "org.openrndr:openrndr-core:$openrndrVersion"
|
||||
compile "org.openrndr:openrndr-filter:$openrndrVersion"
|
||||
compile group: 'org.jetbrains.kotlinx', name: 'kotlinx-coroutines-core', version: '1.0.0'
|
||||
compile "org.openrndr:openrndr-shape:$openrndrVersion"
|
||||
compile group: 'org.jetbrains.kotlinx', name: 'kotlinx-coroutines-core', version: '1.0.1'
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import org.openrndr.Extension
|
||||
import org.openrndr.Program
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.draw.*
|
||||
import org.openrndr.math.Matrix44
|
||||
|
||||
/**
|
||||
* Extends the [Program] with a [Filter]. This is achieved by wrapping the Filter in an Extension.
|
||||
@@ -16,6 +17,8 @@ fun <F : Filter> Program.extend(filter: F, configuration: F.() -> Unit = {}): Ex
|
||||
var renderTarget: RenderTarget? = null
|
||||
var filtered: ColorBuffer? = null
|
||||
override fun beforeDraw(drawer: Drawer, program: Program) {
|
||||
|
||||
drawer.pushStyle()
|
||||
if (renderTarget == null || renderTarget?.width != program.width || renderTarget?.height != program.height) {
|
||||
renderTarget?.let {
|
||||
it.colorBuffer(0).destroy()
|
||||
@@ -38,10 +41,13 @@ fun <F : Filter> Program.extend(filter: F, configuration: F.() -> Unit = {}): Ex
|
||||
}
|
||||
}
|
||||
renderTarget?.bind()
|
||||
|
||||
program.backgroundColor?.let {
|
||||
drawer.background(it)
|
||||
}
|
||||
}
|
||||
|
||||
override fun afterDraw(drawer: Drawer, program: Program) {
|
||||
drawer.popStyle()
|
||||
renderTarget?.unbind()
|
||||
|
||||
filter.configuration()
|
||||
@@ -49,6 +55,8 @@ fun <F : Filter> Program.extend(filter: F, configuration: F.() -> Unit = {}): Ex
|
||||
filtered?.let { filtered ->
|
||||
drawer.isolated {
|
||||
drawer.ortho()
|
||||
drawer.view = Matrix44.IDENTITY
|
||||
drawer.model = Matrix44.IDENTITY
|
||||
filter.apply(it.colorBuffer(0), filtered)
|
||||
drawer.image(filtered)
|
||||
}
|
||||
|
||||
3
orx-mesh-generators/README.md
Normal file
3
orx-mesh-generators/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
# orx-mesh-generators
|
||||
|
||||
Simple mesh generators for OPENRNDR
|
||||
104
orx-mesh-generators/src/main/kotlin/MeshGenerators.kt
Normal file
104
orx-mesh-generators/src/main/kotlin/MeshGenerators.kt
Normal file
@@ -0,0 +1,104 @@
|
||||
package org.openrndr.extras.meshgenerators
|
||||
|
||||
import org.openrndr.draw.BufferWriter
|
||||
import org.openrndr.draw.VertexBuffer
|
||||
import org.openrndr.draw.vertexBuffer
|
||||
import org.openrndr.draw.vertexFormat
|
||||
import org.openrndr.math.Vector2
|
||||
import org.openrndr.math.Vector3
|
||||
import org.openrndr.math.mod
|
||||
import org.openrndr.shape.Circle
|
||||
import org.openrndr.shape.Shape
|
||||
import org.openrndr.shape.triangulate
|
||||
|
||||
/**
|
||||
* Vertex writer function interface
|
||||
*/
|
||||
typealias VertexWriter = (position: Vector3, normal: Vector3, texCoord: Vector2) -> Unit
|
||||
|
||||
/**
|
||||
* create a [VertexWriter] that writes into a [java.nio.ByteBuffer] through [BufferWriter]
|
||||
*/
|
||||
fun bufferWriter(bw: BufferWriter): VertexWriter {
|
||||
return { p, n, t ->
|
||||
bw.write(p)
|
||||
bw.write(n)
|
||||
bw.write(t)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* creates a [VertexBuffer] that is suited for holding meshes
|
||||
*/
|
||||
fun meshVertexBuffer(size: Int): VertexBuffer {
|
||||
return vertexBuffer(vertexFormat {
|
||||
position(3)
|
||||
normal(3)
|
||||
textureCoordinate(2)
|
||||
}, size)
|
||||
}
|
||||
|
||||
/**
|
||||
* extrudes a [shape] by triangulating it and creating sides and cap geometry
|
||||
* @sample sample
|
||||
*/
|
||||
fun extrudeShape(shape: Shape, front: Double, back: Double, distanceTolerance: Double = 0.5, writer: VertexWriter) {
|
||||
val baseTriangles = triangulate(shape, distanceTolerance)
|
||||
val depth = back - front
|
||||
val normal = Vector3(0.0, 0.0, depth).normalized
|
||||
val negativeNormal = normal * -1.0
|
||||
|
||||
baseTriangles.forEach {
|
||||
writer(it.vector3(z = front), normal, Vector2.ZERO)
|
||||
}
|
||||
baseTriangles.forEach {
|
||||
writer(it.vector3(z = back), negativeNormal, Vector2.ZERO)
|
||||
}
|
||||
|
||||
shape.contours.forEach {
|
||||
val points = it.adaptivePositions(distanceTolerance)
|
||||
|
||||
val normals = (0 until points.size).map {
|
||||
(points[mod(it+1, points.size)]-points[mod(it-1, points.size)]).safeNormalized
|
||||
}
|
||||
|
||||
val forward = Vector3(0.0, 0.0, depth)
|
||||
val base = Vector3(0.0, 0.0, front)
|
||||
|
||||
(points zip normals).zipWithNext().forEach { (left, right) ->
|
||||
val lnormal = left.second.perpendicular.vector3()
|
||||
val rnormal = right.second.perpendicular.vector3()
|
||||
|
||||
writer(left.first.vector3() + base, lnormal, Vector2.ZERO)
|
||||
writer(right.first.vector3() + base, rnormal, Vector2.ZERO)
|
||||
writer(right.first.vector3() + base + forward, rnormal, Vector2.ZERO)
|
||||
|
||||
writer(right.first.vector3() + base + forward, rnormal, Vector2.ZERO)
|
||||
writer(left.first.vector3() + base + forward, lnormal, Vector2.ZERO)
|
||||
writer(left.first.vector3() + base, lnormal, Vector2.ZERO)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val Vector2.safeNormalized: Vector2
|
||||
get() {
|
||||
|
||||
return if (length > 0.0001) {
|
||||
normalized
|
||||
} else {
|
||||
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))
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import org.openrndr.draw.Drawer
|
||||
import org.openrndr.draw.RenderTarget
|
||||
import org.openrndr.draw.isolated
|
||||
import org.openrndr.draw.renderTarget
|
||||
import org.openrndr.math.Matrix44
|
||||
|
||||
class NoClear : Extension {
|
||||
override var enabled: Boolean = true
|
||||
@@ -40,6 +41,8 @@ class NoClear : Extension {
|
||||
renderTarget?.let {
|
||||
drawer.isolated {
|
||||
drawer.ortho()
|
||||
drawer.view = Matrix44.IDENTITY
|
||||
drawer.model = Matrix44.IDENTITY
|
||||
drawer.image(it.colorBuffer(0))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ include 'orx-compositor',
|
||||
'orx-integral-image',
|
||||
'orx-jumpflood',
|
||||
'orx-kdtree',
|
||||
'orx-mesh-generators',
|
||||
'orx-no-clear'
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user