-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathDemoBox.kt
More file actions
60 lines (57 loc) · 1.85 KB
/
DemoBox.kt
File metadata and controls
60 lines (57 loc) · 1.85 KB
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
import org.openrndr.WindowMultisample
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.draw.CullTestPass
import org.openrndr.draw.DrawPrimitive
import org.openrndr.draw.colorBuffer
import org.openrndr.draw.shadeStyle
import org.openrndr.extra.camera.Orbital
import org.openrndr.extra.meshgenerators.boxMesh
import org.openrndr.math.Vector3
/**
* Demonstrates how to create a 3D mesh box by specifying its width, height and depth.
*
* The `box` is a `VertexBuffer` and contains texture coordinates which can be
* used to apply a texture to its faces.
*
* After creating the box, the program creates a texture with a gradient.
* In it, the red component increases along the x-axis and the green component
* along the y-axis.
*
* The scene is rendered with an interactive `Orbital` 3D camera.
*
* A shade style is used to apply the texture to the box.
*
*/
fun main() = application {
configure {
width = 720
height = 720
multisample = WindowMultisample.SampleCount(8)
}
program {
val box = boxMesh(1.0, 1.0, 1.0)
val texture = colorBuffer(256, 256)
val s = texture.shadow
for (y in 0 until 256) {
for (x in 0 until 256) {
s[x, y] = ColorRGBa(x / 256.0, y / 256.0, 0.0, 1.0)
}
}
s.upload()
extend(Orbital()) {
eye = Vector3(1.0, 1.0, 1.0)
}
extend {
drawer.clear(ColorRGBa.PINK)
drawer.shadeStyle = shadeStyle {
fragmentTransform = """
x_fill = texture(p_texture, va_texCoord0.xy);
""".trimIndent()
parameter("texture", texture)
}
drawer.drawStyle.cullTestPass = CullTestPass.FRONT
drawer.vertexBuffer(box, DrawPrimitive.TRIANGLES)
}
}
}