forked from openrndr/orx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DemoWireframe01.kt
63 lines (57 loc) · 2.09 KB
/
DemoWireframe01.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/**
Display wireframe and non-planar faces
*/
import org.openrndr.WindowMultisample
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.draw.DrawPrimitive
import org.openrndr.draw.TransformTarget
import org.openrndr.draw.shadeStyle
import org.openrndr.extra.camera.Orbital
import org.openrndr.extra.objloader.readObjMeshData
import org.openrndr.extra.objloader.loadOBJasVertexBuffer
import org.openrndr.extra.mesh.wireframe
import org.openrndr.math.Vector3
import org.openrndr.shape.Path3D
import java.io.File
import kotlin.math.cos
fun main() {
application {
configure {
width = 720
height = 720
multisample = WindowMultisample.SampleCount(4)
}
program {
val vb = loadOBJasVertexBuffer("orx-obj-loader/test-data/non-planar.obj")
val md = readObjMeshData(File("orx-obj-loader/test-data/non-planar.obj").readLines())
val paths = md.wireframe().map {
Path3D.fromPoints(it, true)
}
extend(Orbital())
extend {
drawer.rotate(Vector3.Companion.UNIT_Y, seconds * 45.0 + 45.0, TransformTarget.MODEL)
drawer.translate(0.0, 0.0, 9.0, TransformTarget.VIEW)
drawer.shadeStyle = shadeStyle {
fragmentTransform = """
x_fill.rgb = normalize(v_viewNormal) * 0.5 + vec3(0.5);
""".trimIndent()
}
drawer.vertexBuffer(vb, DrawPrimitive.TRIANGLES)
drawer.stroke = ColorRGBa.WHITE
drawer.strokeWeight = 1.0
drawer.shadeStyle = shadeStyle {
vertexTransform = """
x_projectionMatrix[3][2] -= 0.001;
""".trimIndent()
}
drawer.strokeWeight = 1.0
drawer.paths(paths.mapIndexed { index, it ->
it.sub(
0.0, cos(seconds * 0.5 + index * 0.5) * 0.5 + 0.5
)
})
}
}
}
}