-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathDemoMeshNoise01.kt
54 lines (51 loc) · 1.93 KB
/
DemoMeshNoise01.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
import org.openrndr.WindowMultisample
import org.openrndr.application
import org.openrndr.draw.DrawPrimitive
import org.openrndr.draw.isolated
import org.openrndr.draw.shadeStyle
import org.openrndr.extra.camera.Orbital
import org.openrndr.extra.objloader.loadOBJMeshData
import org.openrndr.extra.mesh.noise.uniform
import org.openrndr.extra.meshgenerators.sphereMesh
import org.openrndr.math.Vector3
import java.io.File
import kotlin.random.Random
/**
* This demo creates a 3D visualization program using the OPENRNDR framework.
* It demonstrates loading an OBJ model, generating uniform points on the surface
* of the mesh, and rendering these points as small spheres using a custom shader.
*
* The following key processes are performed:
* - Loading mesh data from an OBJ file.
* - Generating a list of uniformly distributed points on the mesh surface.
* - Rendering the generated points with small spheres.
* - Using an "Orbital" extension for interactive camera control.
* - Applying a shader effect to visualize surface normals.
*
* The application runs with a window size of 720x720 pixels and positions the camera
* in front of the scene using the "Orbital" extension.
*/
fun main() = application {
configure {
width = 720
height = 720
multisample = WindowMultisample.SampleCount(8)
}
program {
val mesh = loadOBJMeshData(File("demo-data/obj-models/suzanne/Suzanne.obj")).toMeshData()
val points = mesh.uniform(1000, Random(0))
val sphere = sphereMesh(radius = 0.1)
extend(Orbital()) {
eye = Vector3(0.0, 0.0, 2.0)
}
extend {
drawer.shadeStyle = shadeStyle {
fragmentTransform = "x_fill = vec4(v_viewNormal*0.5+0.5, 1.0);"
}
for (point in points) drawer.isolated {
drawer.translate(point)
drawer.vertexBuffer(sphere, DrawPrimitive.TRIANGLES)
}
}
}
}