-
Notifications
You must be signed in to change notification settings - Fork 37
/
DemoObjLoader01.kt
31 lines (29 loc) · 1.17 KB
/
DemoObjLoader01.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.draw.DepthTestPass
import org.openrndr.draw.DrawPrimitive
import org.openrndr.draw.shadeStyle
import org.openrndr.extra.objloader.loadOBJasVertexBuffer
import org.openrndr.math.Vector3
fun main() = application {
program {
val mesh = loadOBJasVertexBuffer("demo-data/obj-models/suzanne/Suzanne.obj")
extend {
drawer.perspective(60.0, width * 1.0 / height, 0.01, 1000.0)
drawer.depthWrite = true
drawer.depthTestPass = DepthTestPass.LESS_OR_EQUAL
drawer.fill = ColorRGBa.PINK
drawer.shadeStyle = shadeStyle {
fragmentTransform = """
vec3 lightDir = normalize(vec3(0.3, 1.0, 0.5));
float l = dot(va_normal, lightDir) * 0.4 + 0.5;
x_fill.rgb *= l;
""".trimIndent()
}
drawer.translate(0.0, 0.0, -2.0)
drawer.rotate(Vector3.UNIT_X, -seconds * 2 + 30)
drawer.rotate(Vector3.UNIT_Y, -seconds * 15 + 20)
drawer.vertexBuffer(mesh, DrawPrimitive.TRIANGLES)
}
}
}