Upgrade to Kotlin 1.4, Gradle 6.6
This commit is contained in:
@@ -17,9 +17,12 @@ dependencies {
|
||||
|
||||
demoImplementation(project(":orx-camera"))
|
||||
demoImplementation(project(":orx-mesh-generators"))
|
||||
demoImplementation(project(":orx-noise"))
|
||||
|
||||
demoImplementation("org.openrndr:openrndr-core:$openrndrVersion")
|
||||
demoImplementation("org.openrndr:openrndr-extensions:$openrndrVersion")
|
||||
demoImplementation("org.openrndr:openrndr-ffmpeg:$openrndrVersion")
|
||||
|
||||
demoRuntimeOnly("org.openrndr:openrndr-gl3:$openrndrVersion")
|
||||
demoRuntimeOnly("org.openrndr:openrndr-gl3-natives-$openrndrOS:$openrndrVersion")
|
||||
demoImplementation(sourceSets.getByName("main").output)
|
||||
|
||||
87
orx-dnk3/src/demo/kotlin/DemoDSL02.kt
Normal file
87
orx-dnk3/src/demo/kotlin/DemoDSL02.kt
Normal file
@@ -0,0 +1,87 @@
|
||||
import org.openrndr.application
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.extensions.SingleScreenshot
|
||||
import org.openrndr.extra.dnk3.dsl.*
|
||||
import org.openrndr.extra.dnk3.renderers.dryRenderer
|
||||
import org.openrndr.extra.dnk3.tools.addSkybox
|
||||
import org.openrndr.extra.noise.simplex
|
||||
import org.openrndr.extras.camera.Orbital
|
||||
import org.openrndr.extras.meshgenerators.groundPlaneMesh
|
||||
import org.openrndr.math.Vector3
|
||||
import org.openrndr.math.transforms.transform
|
||||
import org.openrndr.shape.path3D
|
||||
|
||||
fun main() = application {
|
||||
configure {
|
||||
width = 1280
|
||||
height = 720
|
||||
}
|
||||
|
||||
program {
|
||||
if (System.getProperty("takeScreenshot") == "true") {
|
||||
extend(SingleScreenshot()) {
|
||||
this.outputFile = System.getProperty("screenshotPath")
|
||||
}
|
||||
}
|
||||
extend(Orbital()) {
|
||||
eye = Vector3(4.0, 4.0, 4.0)
|
||||
}
|
||||
|
||||
val renderer = dryRenderer()
|
||||
val scene = scene {
|
||||
|
||||
addSkybox("file:demo-data/cubemaps/garage_iem.dds")
|
||||
|
||||
root.hemisphereLight {
|
||||
upColor = ColorRGBa.WHITE.shade(0.1)
|
||||
downColor = ColorRGBa.BLACK
|
||||
}
|
||||
|
||||
root.node {
|
||||
transform = transform {
|
||||
translate(0.0, 2.0, 0.0)
|
||||
}
|
||||
|
||||
pointLight {
|
||||
constantAttenuation = 0.0
|
||||
quadraticAttenuation = 1.0
|
||||
}
|
||||
}
|
||||
|
||||
root.node {
|
||||
simpleMesh {
|
||||
vertexBuffer = groundPlaneMesh(100.0, 100.0)
|
||||
material = pbrMaterial {
|
||||
color = ColorRGBa.GREEN
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
root.node {
|
||||
pathMesh {
|
||||
weight = 10.0
|
||||
material = pbrMaterial {
|
||||
color = ColorRGBa.PINK
|
||||
}
|
||||
update {
|
||||
paths = mutableListOf(
|
||||
path3D {
|
||||
val t = seconds * 0.1
|
||||
moveTo(Vector3.ZERO)
|
||||
val control = Vector3.simplex(3032, t).let { it.copy(y = it.y * 0.5 + 0.5) } * 4.0
|
||||
val target = Vector3.simplex(5077, t).let { it.copy(y = it.y * 0.5 + 0.5) } * 4.0
|
||||
val end = Vector3.simplex(9041, t).let { it.copy(y = it.y * 0.5 + 0.5) } * 4.0
|
||||
curveTo(control, target)
|
||||
continueTo(end)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
extend {
|
||||
drawer.clear(ColorRGBa.BLACK)
|
||||
renderer.draw(drawer, scene)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,12 @@
|
||||
package org.openrndr.extra.dnk3
|
||||
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.draw.*
|
||||
import org.openrndr.draw.DrawPrimitive
|
||||
import org.openrndr.draw.IndexBuffer
|
||||
import org.openrndr.draw.VertexBuffer
|
||||
import org.openrndr.math.Matrix44
|
||||
import org.openrndr.math.transforms.perspective
|
||||
import org.openrndr.shape.Path3D
|
||||
|
||||
|
||||
class Geometry(val vertexBuffers: List<VertexBuffer>,
|
||||
@@ -15,6 +18,7 @@ class Geometry(val vertexBuffers: List<VertexBuffer>,
|
||||
override fun toString(): String {
|
||||
return "Geometry(vertexBuffers: $vertexBuffers, indexBuffers: $indexBuffer, primitive: $primitive, offset: $offset, vertexCount: $vertexCount)"
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = 0
|
||||
result = 31 * result + primitive.ordinal.hashCode()
|
||||
@@ -41,11 +45,22 @@ class MeshPrimitive(var geometry: Geometry, var material: Material) {
|
||||
|
||||
class MeshPrimitiveInstance(val primitive: MeshPrimitive, val instances: Int, val attributes: List<VertexBuffer>)
|
||||
|
||||
class PathMesh(var paths: MutableList<Path3D>, var material: Material, var weight: Double) : Entity() {
|
||||
override fun toString(): String {
|
||||
return "PathMesh(paths=$paths)"
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
return paths.hashCode()
|
||||
}
|
||||
}
|
||||
|
||||
abstract class MeshBase(var primitives: List<MeshPrimitive>) : Entity()
|
||||
class Mesh(primitives: List<MeshPrimitive>) : MeshBase(primitives) {
|
||||
override fun toString(): String {
|
||||
return "Mesh(primitives: $primitives)"
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
return primitives.hashCode()
|
||||
}
|
||||
@@ -62,7 +77,7 @@ class InstancedMesh(primitives: List<MeshPrimitive>,
|
||||
var attributes: List<VertexBuffer>) : MeshBase(primitives)
|
||||
|
||||
|
||||
data class Fog(var color: ColorRGBa = ColorRGBa.WHITE, var end : Double = 100.0) : Entity()
|
||||
data class Fog(var color: ColorRGBa = ColorRGBa.WHITE, var end: Double = 100.0) : Entity()
|
||||
|
||||
abstract class Light : Entity() {
|
||||
var color: ColorRGBa = ColorRGBa.WHITE
|
||||
@@ -75,14 +90,14 @@ abstract class Camera : Entity() {
|
||||
|
||||
abstract class CubemapProbe : Entity() {
|
||||
open val projectionMatrix: Matrix44
|
||||
get() {
|
||||
return perspective(90.0, 1.0, 0.1, 150.0)
|
||||
}
|
||||
get() {
|
||||
return perspective(90.0, 1.0, 0.1, 150.0)
|
||||
}
|
||||
var dirty = true
|
||||
}
|
||||
|
||||
class IrradianceProbe: CubemapProbe() {
|
||||
override fun hashCode(): Int {
|
||||
class IrradianceProbe : CubemapProbe() {
|
||||
override fun hashCode(): Int {
|
||||
return true.hashCode()
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,7 @@ private val noise128 by lazy {
|
||||
for (y in 0 until cb.height) {
|
||||
for (x in 0 until cb.width) {
|
||||
for (i in 0 until 4)
|
||||
buffer.put((Math.random() * 255).toByte())
|
||||
buffer.put((Math.random() * 255).toInt().toByte())
|
||||
}
|
||||
}
|
||||
buffer.rewind()
|
||||
|
||||
@@ -13,11 +13,11 @@ class RenderContext(
|
||||
val meshes: List<NodeContent<Mesh>>,
|
||||
val skinnedMeshes: List<NodeContent<SkinnedMesh>>,
|
||||
val instancedMeshes: List<NodeContent<InstancedMesh>>,
|
||||
val pathMeshes: List<NodeContent<PathMesh>>,
|
||||
val fogs: List<NodeContent<Fog>>
|
||||
)
|
||||
|
||||
class SceneRenderer {
|
||||
|
||||
class Configuration {
|
||||
var multisampleLines = false
|
||||
}
|
||||
@@ -64,7 +64,8 @@ class SceneRenderer {
|
||||
meshes = scene.root.findContent { this as? Mesh },
|
||||
skinnedMeshes = scene.root.findContent { this as? SkinnedMesh },
|
||||
fogs = scene.root.findContent { this as? Fog },
|
||||
instancedMeshes = scene.root.findContent { this as? InstancedMesh }
|
||||
instancedMeshes = scene.root.findContent { this as? InstancedMesh },
|
||||
pathMeshes = scene.root.findContent { this as? PathMesh}
|
||||
)
|
||||
|
||||
// shadow passes
|
||||
@@ -140,7 +141,7 @@ class SceneRenderer {
|
||||
pass.combiners.forEach {
|
||||
if (it is ColorBufferFacetCombiner) {
|
||||
val index = target.colorAttachmentIndexByName(it.targetOutput)
|
||||
?: error("attachement not found ${it.targetOutput}")
|
||||
?: error("attachment not found ${it.targetOutput}")
|
||||
target.blendMode(index, it.blendMode)
|
||||
}
|
||||
}
|
||||
@@ -305,7 +306,26 @@ class SceneRenderer {
|
||||
primitive.primitive.geometry.vertexCount)
|
||||
}
|
||||
}
|
||||
drawer.depthWrite = true
|
||||
|
||||
context.pathMeshes.filter { (it.content.material.transparent && pass.renderTransparent) || (!it.content.material.transparent && pass.renderOpaque) }
|
||||
.forEach {
|
||||
drawer.isolated {
|
||||
val primitiveContext = PrimitiveContext(true, false)
|
||||
val shadeStyle = it.content.material.generateShadeStyle(materialContext, primitiveContext)
|
||||
shadeStyle.parameter("viewMatrixInverse", drawer.view.inversed)
|
||||
it.content.material.applyToShadeStyle(materialContext, shadeStyle)
|
||||
drawer.drawStyle.cullTestPass = CullTestPass.ALWAYS
|
||||
drawer.shadeStyle = shadeStyle
|
||||
drawer.model = it.node.worldTransform
|
||||
drawer.strokeWeight = it.content.weight
|
||||
for (path in it.content.paths) {
|
||||
drawer.path(path.sampleLinear(0.0005))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
drawer.depthWrite = true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@ open class CubemapFilter(private val shader: Shader? = null, private val watcher
|
||||
renderTarget.detachDepthBuffer()
|
||||
}
|
||||
|
||||
renderTarget.detachColorBuffers()
|
||||
renderTarget.detachColorAttachments()
|
||||
renderTarget.destroy()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ fun SceneNode.node(builder: SceneNode.() -> Unit): SceneNode {
|
||||
return node
|
||||
}
|
||||
|
||||
fun SceneNode.hemisphereLight(builder: HemisphereLight.() -> Unit) : HemisphereLight {
|
||||
fun SceneNode.hemisphereLight(builder: HemisphereLight.() -> Unit): HemisphereLight {
|
||||
val hemisphereLight = HemisphereLight()
|
||||
hemisphereLight.builder()
|
||||
entities.add(hemisphereLight)
|
||||
@@ -64,17 +64,25 @@ class SimpleMeshBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
fun Scene.update(function: ()->Unit) {
|
||||
dispatcher.launch {
|
||||
while (true) {
|
||||
function()
|
||||
yield()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun SceneNode.simpleMesh(builder: SimpleMeshBuilder.() -> Unit): Mesh {
|
||||
val mesh = SimpleMeshBuilder().apply { builder() }.build()
|
||||
entities.add(mesh)
|
||||
return mesh
|
||||
}
|
||||
|
||||
|
||||
fun SceneNode.pathMesh(builder: PathMesh.() -> Unit): PathMesh {
|
||||
val pathMesh = PathMesh(mutableListOf(), DummyMaterial(), 1.0)
|
||||
pathMesh.builder()
|
||||
entities.add(pathMesh)
|
||||
return pathMesh
|
||||
}
|
||||
|
||||
fun Scene.update(function: () -> Unit) {
|
||||
dispatcher.launch {
|
||||
while (true) {
|
||||
function()
|
||||
yield()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ import kotlin.reflect.KMutableProperty0
|
||||
class SceneAnimation(var channels: List<AnimationChannel>) {
|
||||
val duration: Double
|
||||
get() {
|
||||
return channels.maxBy { it.duration }?.duration ?: 0.0
|
||||
return channels.maxByOrNull { it.duration }?.duration ?: 0.0
|
||||
}
|
||||
fun applyToTargets(input: Double) {
|
||||
for (channel in channels) {
|
||||
|
||||
Reference in New Issue
Block a user