Improve orx-olive
This commit is contained in:
@@ -12,7 +12,7 @@ class Debug3D(eye: Vector3 = Vector3(0.0, 0.0, 10.0), lookAt: Vector3 = Vector3.
|
|||||||
|
|
||||||
override var enabled: Boolean = true
|
override var enabled: Boolean = true
|
||||||
var showGrid = false
|
var showGrid = false
|
||||||
val orbitalCamera = OrbitalCamera(eye, lookAt, 90.0)
|
val orbitalCamera = OrbitalCamera(eye, lookAt, fov)
|
||||||
private val orbitalControls = OrbitalControls(orbitalCamera, userInteraction)
|
private val orbitalControls = OrbitalControls(orbitalCamera, userInteraction)
|
||||||
private var lastSeconds: Double = -1.0
|
private var lastSeconds: Double = -1.0
|
||||||
|
|
||||||
|
|||||||
74
orx-olive/README.md
Normal file
74
orx-olive/README.md
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
# orx-olive
|
||||||
|
|
||||||
|
Live coding extension for OPENRNDR
|
||||||
|
|
||||||
|
## usage
|
||||||
|
|
||||||
|
make sure that you add the following to your list of dependencies (next to orx-olive)
|
||||||
|
```
|
||||||
|
compile "org.jetbrains.kotlin:kotlin-scripting-compiler-embeddable:1.3.31"
|
||||||
|
```
|
||||||
|
|
||||||
|
Then a simple live setup can created as follows:
|
||||||
|
|
||||||
|
```kotlin
|
||||||
|
import org.openrndr.Program
|
||||||
|
import org.openrndr.application
|
||||||
|
import org.openrndr.extra.olive.Olive
|
||||||
|
|
||||||
|
fun main() = application {
|
||||||
|
configure {
|
||||||
|
width = 768
|
||||||
|
height = 576
|
||||||
|
}
|
||||||
|
program {
|
||||||
|
extend(Olive<Program>())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
The extension will create a template script for you in `src/main/kotlin/live.kts`. You can
|
||||||
|
edit this to see how the program updates automatically.
|
||||||
|
|
||||||
|
## Persistent Data
|
||||||
|
|
||||||
|
Sometimes you want to keep parts of your application persistent. In the following example
|
||||||
|
we show how you can prepare the host program to contain a persistent camera device.
|
||||||
|
|
||||||
|
```kotlin
|
||||||
|
import org.openrndr.Program
|
||||||
|
import org.openrndr.application
|
||||||
|
|
||||||
|
class PersistentProgram: Program() {
|
||||||
|
lateinit var camera;
|
||||||
|
}
|
||||||
|
|
||||||
|
fun main() = application{
|
||||||
|
program(PersistentProgram()) {
|
||||||
|
camera = FFMPEGVideoPlayer.fromDevice()
|
||||||
|
camera.start()
|
||||||
|
|
||||||
|
extend(Olive<PersistentProgram>()) {
|
||||||
|
script = "src/main/PersistentCamera.Kt"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
The live script `src/main/PersistentCamera.kt` then looks like this:
|
||||||
|
|
||||||
|
```kotlin
|
||||||
|
@file:Suppress("UNUSED_LAMBDA_EXPRESSION")
|
||||||
|
import org.openrndr.color.ColorRGBa
|
||||||
|
import org.openrndr.draw.*
|
||||||
|
|
||||||
|
{ program: PersistentProgram ->
|
||||||
|
program.apply {
|
||||||
|
extend {
|
||||||
|
camera.next()
|
||||||
|
drawer.drawStyle.colorMatrix = tint(ColorRGBa.GREEN) * grayscale(0.0, 0.0, 1.0)
|
||||||
|
camera.draw(drawer)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
@@ -1,10 +1,8 @@
|
|||||||
dependencies {
|
dependencies {
|
||||||
compile project(":orx-file-watcher")
|
compile project(":orx-file-watcher")
|
||||||
runtime "org.openrndr:openrndr-gl3:0.4.0-SNAPSHOT"
|
compile "org.jetbrains.kotlin:kotlin-scripting-compiler-embeddable:1.3.31"
|
||||||
runtime "org.openrndr:openrndr-gl3-natives-linux-x64:0.4.0-SNAPSHOT"
|
compile "org.jetbrains.kotlin:kotlin-compiler-embeddable:1.3.31"
|
||||||
compile "org.jetbrains.kotlin:kotlin-scripting-compiler-embeddable"
|
compile "org.jetbrains.kotlin:kotlin-script-runtime:1.3.31"
|
||||||
compile "org.jetbrains.kotlin:kotlin-compiler-embeddable"
|
compile "org.jetbrains.kotlin:kotlin-script-util:1.3.31"
|
||||||
compile "org.jetbrains.kotlin:kotlin-script-runtime"
|
compile "org.jetbrains.kotlin:kotlin-scripting-compiler:1.3.31"
|
||||||
compile "org.jetbrains.kotlin:kotlin-script-util"
|
|
||||||
runtime "org.jetbrains.kotlin:kotlin-scripting-compiler"
|
|
||||||
}
|
}
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
package org.openrndr.extra.olive
|
|
||||||
|
|
||||||
import org.openrndr.Program
|
|
||||||
import org.openrndr.application
|
|
||||||
|
|
||||||
class StupidProgram:Program() {
|
|
||||||
val thisIsStupid = 5
|
|
||||||
}
|
|
||||||
|
|
||||||
fun main() = application{
|
|
||||||
program(StupidProgram()) {
|
|
||||||
extend(Olive<StupidProgram>())
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -4,9 +4,9 @@ import java.io.InputStream
|
|||||||
import java.io.Reader
|
import java.io.Reader
|
||||||
import javax.script.ScriptEngineManager
|
import javax.script.ScriptEngineManager
|
||||||
|
|
||||||
class LoadException(message: String? = null, cause: Throwable? = null) : RuntimeException(message, cause)
|
internal class LoadException(message: String? = null, cause: Throwable? = null) : RuntimeException(message, cause)
|
||||||
|
|
||||||
class KtsObjectLoader(classLoader: ClassLoader? = Thread.currentThread().contextClassLoader) {
|
internal class KtsObjectLoader(classLoader: ClassLoader? = Thread.currentThread().contextClassLoader) {
|
||||||
|
|
||||||
val engine = ScriptEngineManager(classLoader).getEngineByExtension("kts")
|
val engine = ScriptEngineManager(classLoader).getEngineByExtension("kts")
|
||||||
|
|
||||||
@@ -17,10 +17,8 @@ class KtsObjectLoader(classLoader: ClassLoader? = Thread.currentThread().context
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline fun <R> safeEval(noinline evaluation: () -> R?) = try {
|
inline fun <R> safeEval(noinline evaluation: () -> R?) = try {
|
||||||
println(evaluation)
|
|
||||||
evaluation()
|
evaluation()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
|
||||||
throw LoadException("Cannot load script", e)
|
throw LoadException("Cannot load script", e)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,25 +6,29 @@ import org.openrndr.draw.Session
|
|||||||
import org.operndr.extras.filewatcher.watchFile
|
import org.operndr.extras.filewatcher.watchFile
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
class Olive<P:Program>():Extension {
|
class Olive<P : Program> : Extension {
|
||||||
override var enabled: Boolean = true
|
override var enabled: Boolean = true
|
||||||
var session: Session? = null
|
var session: Session? = null
|
||||||
|
|
||||||
var script = "src/main/kotlin/live.kts"
|
var script = "src/main/kotlin/live.kts"
|
||||||
|
|
||||||
override fun setup(program: Program) {
|
override fun setup(program: Program) {
|
||||||
|
System.setProperty("idea.io.use.fallback", "true")
|
||||||
|
|
||||||
val f = File(script)
|
val f = File(script)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (!f.exists()) {
|
if (!f.exists()) {
|
||||||
f.parentFile.mkdirs()
|
f.parentFile.mkdirs()
|
||||||
|
var className = program.javaClass.name
|
||||||
|
if (className.contains("$"))
|
||||||
|
className = "Program"
|
||||||
|
|
||||||
f.writeText("""
|
f.writeText("""
|
||||||
@file:Suppress("UNUSED_LAMBDA_EXPRESSION")
|
@file:Suppress("UNUSED_LAMBDA_EXPRESSION")
|
||||||
import org.openrndr.Program
|
import org.openrndr.Program
|
||||||
import org.openrndr.draw.*
|
import org.openrndr.draw.*
|
||||||
|
|
||||||
{ program: ${program.javaClass.name} ->
|
{ program: $className ->
|
||||||
program.apply {
|
program.apply {
|
||||||
extend {
|
extend {
|
||||||
|
|
||||||
@@ -38,8 +42,6 @@ class Olive<P:Program>():Extension {
|
|||||||
try {
|
try {
|
||||||
|
|
||||||
val script = it.readText()
|
val script = it.readText()
|
||||||
|
|
||||||
println(script)
|
|
||||||
val func = KtsObjectLoader().load<P.() -> Unit>(script)
|
val func = KtsObjectLoader().load<P.() -> Unit>(script)
|
||||||
|
|
||||||
program.extensions.clear()
|
program.extensions.clear()
|
||||||
|
|||||||
Reference in New Issue
Block a user