forked from openrndr/orx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DemoObject01.kt
40 lines (37 loc) · 1.29 KB
/
DemoObject01.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
32
33
34
35
36
37
38
39
40
import org.openrndr.application
import org.openrndr.draw.DrawPrimitive
import org.openrndr.draw.shadeStyle
import org.openrndr.extra.camera.Orbital
import org.openrndr.extra.dnk3.gltf.loadGltfFromFile
import org.openrndr.math.Vector3
import java.io.File
fun main() = application {
program {
val gltf = loadGltfFromFile(File("demo-data/gltf-models/duck/Duck.gltf"))
val meshes = gltf.meshes.map {
it.createDrawCommands(gltf)
}
extend(Orbital()) {
far = 400.0
lookAt = Vector3(0.0, 50.0, 0.0)
eye = Vector3(100.0, 200.0, 150.0)
fov = 45.0
}
extend {
drawer.shadeStyle = shadeStyle {
fragmentTransform = """
x_fill.rgb = vec3(v_viewNormal.z);
""".trimIndent()
}
for (mesh in meshes) {
for (primitive in mesh) {
if (primitive.indexBuffer == null) {
drawer.vertexBuffer(primitive.vertexBuffer, DrawPrimitive.TRIANGLES)
} else {
drawer.vertexBuffer(primitive.indexBuffer!!, listOf(primitive.vertexBuffer), DrawPrimitive.TRIANGLES)
}
}
}
}
}
}