-
Notifications
You must be signed in to change notification settings - Fork 37
/
DemoComplex04.kt
104 lines (97 loc) · 3.73 KB
/
DemoComplex04.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import org.openrndr.WindowMultisample
import org.openrndr.application
import org.openrndr.draw.DrawPrimitive
import org.openrndr.draw.shadeStyle
import org.openrndr.extra.camera.Orbital
import org.openrndr.extra.meshgenerators.*
import org.openrndr.math.Vector2
import org.openrndr.math.Vector3
fun main() {
application {
configure {
width = 800
height = 800
multisample = WindowMultisample.SampleCount(8)
}
program {
extend(Orbital()) {
this.eye = Vector3(0.0, 15.0, 15.0)
}
val m = buildTriangleMesh {
val sides = 12
isolated {
translate(0.0, 12.0, 0.0)
cap(sides, 5.0, listOf(
Vector2(0.0, 1.0),
Vector2(0.5, 1.0),
Vector2(0.5, 0.5),
Vector2(0.9, 0.5),
Vector2(1.0, 0.0))
)
}
val ridges = 5
val midLength = 6.0
val ridgeLength = midLength / ridges
val ridgeRadius = 5.5
for (r in 0 until ridges) {
isolated {
translate(
0.0,
ridgeLength / 6.0 + r * ridgeLength + 6.0,
0.0
)
rotate(Vector3.UNIT_X, 270.0)
taperedCylinder(sides, 1, 5.0, ridgeRadius, ridgeLength / 3.0, center = true)
}
isolated {
translate(
0.0,
ridgeLength / 6.0 + ridgeLength / 3.0 + r * ridgeLength + 6.0,
0.0
)
rotate(Vector3.UNIT_X, 270.0)
taperedCylinder(sides, 1, ridgeRadius, ridgeRadius, ridgeLength / 3.0, center = true)
}
isolated {
translate(
0.0,
ridgeLength / 6.0 + 2 * ridgeLength / 3.0 + r * ridgeLength + 6.0,
0.0
)
rotate(Vector3.UNIT_X, 270.0)
taperedCylinder(sides, 1, ridgeRadius, 5.0, ridgeLength / 3.0, center = true)
}
}
isolated {
translate(0.0, 6.0, 0.0)
rotate(Vector3.UNIT_X, 180.0)
cap(sides, 5.0, listOf(Vector2(0.0, 0.0), Vector2(1.0, 0.0)))
}
isolated {
val legCount = 12
val baseRadius = 4.5
val legRadius = 0.05
val legLength = 7.0
for (i in 0 until legCount) {
isolated {
val dphi = 360.0 / legCount
rotate(Vector3.UNIT_Y, dphi * i)
translate(baseRadius, 0.0, 0.0)
translate(0.0, legLength / 2.0, 0.0)
rotate(Vector3.UNIT_X, 90.0)
cylinder(sides, 1, legRadius, legLength, center = true)
}
}
}
}
extend {
drawer.shadeStyle = shadeStyle {
fragmentTransform = """
x_fill.rgb *= v_viewNormal.z;
""".trimIndent()
}
drawer.vertexBuffer(m, DrawPrimitive.TRIANGLES)
}
}
}
}