diff --git a/orx-camera/src/main/kotlin/Debug3D.kt b/orx-camera/src/main/kotlin/Debug3D.kt index 0a079697..5ec2a320 100644 --- a/orx-camera/src/main/kotlin/Debug3D.kt +++ b/orx-camera/src/main/kotlin/Debug3D.kt @@ -12,7 +12,7 @@ class Debug3D(eye: Vector3 = Vector3(0.0, 0.0, 10.0), lookAt: Vector3 = Vector3. override var enabled: Boolean = true var showGrid = false - val orbitalCamera = OrbitalCamera(eye, lookAt, 90.0) + val orbitalCamera = OrbitalCamera(eye, lookAt, fov) private val orbitalControls = OrbitalControls(orbitalCamera, userInteraction) private var lastSeconds: Double = -1.0 diff --git a/orx-olive/README.md b/orx-olive/README.md new file mode 100644 index 00000000..abe20123 --- /dev/null +++ b/orx-olive/README.md @@ -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()) + } +} +``` + +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()) { + 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) + } + } +} +``` \ No newline at end of file diff --git a/orx-olive/build.gradle b/orx-olive/build.gradle index 0a97e97a..5b08c5d6 100644 --- a/orx-olive/build.gradle +++ b/orx-olive/build.gradle @@ -1,10 +1,8 @@ dependencies { compile project(":orx-file-watcher") - runtime "org.openrndr:openrndr-gl3:0.4.0-SNAPSHOT" - runtime "org.openrndr:openrndr-gl3-natives-linux-x64:0.4.0-SNAPSHOT" - compile "org.jetbrains.kotlin:kotlin-scripting-compiler-embeddable" - compile "org.jetbrains.kotlin:kotlin-compiler-embeddable" - compile "org.jetbrains.kotlin:kotlin-script-runtime" - compile "org.jetbrains.kotlin:kotlin-script-util" - runtime "org.jetbrains.kotlin:kotlin-scripting-compiler" + compile "org.jetbrains.kotlin:kotlin-scripting-compiler-embeddable:1.3.31" + compile "org.jetbrains.kotlin:kotlin-compiler-embeddable:1.3.31" + compile "org.jetbrains.kotlin:kotlin-script-runtime:1.3.31" + compile "org.jetbrains.kotlin:kotlin-script-util:1.3.31" + compile "org.jetbrains.kotlin:kotlin-scripting-compiler:1.3.31" } \ No newline at end of file diff --git a/orx-olive/src/main/kotlin/Example.kt b/orx-olive/src/main/kotlin/Example.kt deleted file mode 100644 index 4b44a266..00000000 --- a/orx-olive/src/main/kotlin/Example.kt +++ /dev/null @@ -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()) - - } -} \ No newline at end of file diff --git a/orx-olive/src/main/kotlin/KtsObjectLoader.kt b/orx-olive/src/main/kotlin/KtsObjectLoader.kt index 8db53729..a1207e7d 100644 --- a/orx-olive/src/main/kotlin/KtsObjectLoader.kt +++ b/orx-olive/src/main/kotlin/KtsObjectLoader.kt @@ -4,9 +4,9 @@ import java.io.InputStream import java.io.Reader 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") @@ -17,10 +17,8 @@ class KtsObjectLoader(classLoader: ClassLoader? = Thread.currentThread().context } inline fun safeEval(noinline evaluation: () -> R?) = try { - println(evaluation) evaluation() } catch (e: Exception) { - e.printStackTrace() throw LoadException("Cannot load script", e) } diff --git a/orx-olive/src/main/kotlin/Olive.kt b/orx-olive/src/main/kotlin/Olive.kt index 4c2874ac..7480252a 100644 --- a/orx-olive/src/main/kotlin/Olive.kt +++ b/orx-olive/src/main/kotlin/Olive.kt @@ -6,25 +6,29 @@ import org.openrndr.draw.Session import org.operndr.extras.filewatcher.watchFile import java.io.File -class Olive():Extension { +class Olive

: Extension { override var enabled: Boolean = true var session: Session? = null var script = "src/main/kotlin/live.kts" override fun setup(program: Program) { + System.setProperty("idea.io.use.fallback", "true") + val f = File(script) - - if (!f.exists()) { f.parentFile.mkdirs() + var className = program.javaClass.name + if (className.contains("$")) + className = "Program" + f.writeText(""" @file:Suppress("UNUSED_LAMBDA_EXPRESSION") import org.openrndr.Program import org.openrndr.draw.* - { program: ${program.javaClass.name} -> + { program: $className -> program.apply { extend { @@ -37,9 +41,7 @@ class Olive():Extension { program.watchFile(File(script)) { try { - val script =it.readText() - - println(script) + val script = it.readText() val func = KtsObjectLoader().load Unit>(script) program.extensions.clear()