[orx-mesh-noise] Refactor barycentric and mesh sampling logic into specialized files.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import org.openrndr.WindowMultisample
|
||||
import org.openrndr.application
|
||||
import org.openrndr.draw.DrawPrimitive
|
||||
import org.openrndr.draw.isolated
|
||||
@@ -26,31 +27,28 @@ import kotlin.random.Random
|
||||
* 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
|
||||
}
|
||||
program {
|
||||
val mesh = loadOBJMeshData(File("demo-data/obj-models/suzanne/Suzanne.obj")).toMeshData()
|
||||
val points = mesh.uniform(1000, Random(0))
|
||||
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)
|
||||
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);"
|
||||
}
|
||||
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)
|
||||
}
|
||||
}
|
||||
for (point in points) drawer.isolated {
|
||||
drawer.translate(point)
|
||||
drawer.vertexBuffer(sphere, DrawPrimitive.TRIANGLES)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import org.openrndr.WindowMultisample
|
||||
import org.openrndr.application
|
||||
import org.openrndr.draw.DrawPrimitive
|
||||
import org.openrndr.draw.isolated
|
||||
@@ -5,44 +6,36 @@ import org.openrndr.draw.shadeStyle
|
||||
import org.openrndr.extra.camera.Orbital
|
||||
import org.openrndr.extra.mesh.noise.hash
|
||||
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.math.cos
|
||||
import kotlin.random.Random
|
||||
|
||||
/**
|
||||
* Demonstrate uniform point on mesh generation using hash functions
|
||||
*/
|
||||
fun main() {
|
||||
application {
|
||||
configure {
|
||||
width = 720
|
||||
height = 720
|
||||
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 sphere = sphereMesh(radius = 0.01)
|
||||
extend(Orbital()) {
|
||||
eye = Vector3(0.0, 0.0, 2.0)
|
||||
}
|
||||
program {
|
||||
val mesh = loadOBJMeshData(File("demo-data/obj-models/suzanne/Suzanne.obj")).toMeshData()
|
||||
|
||||
val sphere = sphereMesh(radius = 0.01)
|
||||
extend(Orbital()) {
|
||||
eye = Vector3(0.0, 0.0, 2.0)
|
||||
extend {
|
||||
val points = mesh.hash((1000 + (cos(seconds) * 0.5 + 0.5) * 9000).toInt(), 808, (seconds * 1).toInt())
|
||||
drawer.shadeStyle = shadeStyle {
|
||||
fragmentTransform = "x_fill = vec4(v_viewNormal*0.5+0.5, 1.0);"
|
||||
}
|
||||
extend {
|
||||
|
||||
val points = mesh.hash((1000 + (cos(seconds)*0.5+0.5)*9000).toInt(), 808, (seconds*10000).toInt())
|
||||
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
for (point in points) drawer.isolated {
|
||||
drawer.translate(point)
|
||||
drawer.vertexBuffer(sphere, DrawPrimitive.TRIANGLES)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
57
orx-mesh-noise/src/jvmDemo/kotlin/DemoMeshNoise03.kt
Normal file
57
orx-mesh-noise/src/jvmDemo/kotlin/DemoMeshNoise03.kt
Normal file
@@ -0,0 +1,57 @@
|
||||
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.uniformPoints
|
||||
import org.openrndr.extra.meshgenerators.cylinderMesh
|
||||
import org.openrndr.extra.meshgenerators.normals.estimateNormals
|
||||
import org.openrndr.extra.meshgenerators.tangents.estimateTangents
|
||||
import org.openrndr.math.Vector3
|
||||
import org.openrndr.math.transforms.buildTransform
|
||||
import java.io.File
|
||||
import kotlin.math.cos
|
||||
import kotlin.random.Random
|
||||
|
||||
/**
|
||||
* This demo loads a 3D model from an OBJ file, processes the mesh data to estimate normals and tangents, and generates
|
||||
* a set of uniformly distributed pose points. These pose points determine the transformations applied to individual
|
||||
* objects rendered in the viewport.
|
||||
*
|
||||
* It extends the rendering with an orbital camera for navigation and shaders for custom visual
|
||||
* effects. Cylinders represent transformed objects, with their scale animations based on time-dependent
|
||||
* trigonometric functions.
|
||||
*/
|
||||
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().triangulate()
|
||||
.estimateNormals().estimateTangents()
|
||||
val poses = mesh.uniformPoints(10000, Random(0)).map { it.pose() }
|
||||
|
||||
val cylinder = cylinderMesh(radius = 0.01, length = 0.2)
|
||||
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 (pose in poses) {
|
||||
drawer.isolated {
|
||||
drawer.model = buildTransform {
|
||||
multiply(pose)
|
||||
scale(1.0, 1.0, cos(pose.c3r0 * 10.0 + seconds) * 0.5 + 0.5)
|
||||
}
|
||||
drawer.vertexBuffer(cylinder, DrawPrimitive.TRIANGLES)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
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.mesh.IIndexedPolygon
|
||||
import org.openrndr.extra.mesh.IVertexData
|
||||
import org.openrndr.extra.mesh.noise.nonuniform
|
||||
import org.openrndr.extra.mesh.noise.nonuniformHammersley
|
||||
import org.openrndr.extra.mesh.noise.nonuniformRSeq
|
||||
import org.openrndr.extra.objloader.loadOBJMeshData
|
||||
import org.openrndr.extra.mesh.noise.uniform
|
||||
import org.openrndr.extra.meshgenerators.normals.estimateNormals
|
||||
import org.openrndr.extra.meshgenerators.sphereMesh
|
||||
import org.openrndr.math.Spherical
|
||||
import org.openrndr.math.Vector3
|
||||
import java.io.File
|
||||
import kotlin.math.absoluteValue
|
||||
import kotlin.math.cos
|
||||
import kotlin.math.pow
|
||||
import kotlin.math.sin
|
||||
import kotlin.random.Random
|
||||
|
||||
|
||||
/**
|
||||
* The program demonstrates the loading of a 3D model, estimating its normals,
|
||||
* sampling points based on non-uniform distribution, and rendering points as spheres.
|
||||
*
|
||||
* Key functionalities include:
|
||||
* - Loading a 3D model from an OBJ file.
|
||||
* - Estimating per-vertex normals for the mesh.
|
||||
* - Generating and rendering a sphere mesh for sampled points.
|
||||
* - Using a lighting direction vector to bias the point sampling distribution.
|
||||
* - Extending the program with an orbital camera for interactive navigation.
|
||||
* - Applying shading to simulate lighting effects based on vertex normals.
|
||||
*
|
||||
* The rendering of spheres is performed by iterating over the sampled points and isolating each in the transformation matrix.
|
||||
* This setup allows customization for complex rendering pipelines.
|
||||
*/
|
||||
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().estimateNormals()
|
||||
|
||||
val sphere = sphereMesh(radius = 0.0125)
|
||||
extend(Orbital()) {
|
||||
eye = Vector3(0.0, 0.0, 8.0)
|
||||
fov = 25.0
|
||||
}
|
||||
val v = Vector3(1.0, 1.0, 1.0).normalized
|
||||
|
||||
val points = mesh.nonuniformRSeq(
|
||||
10000,
|
||||
false,
|
||||
Random((seconds * 0).toInt())
|
||||
) { vertexData: IVertexData, polygon: IIndexedPolygon, vertexIndex: Int ->
|
||||
vertexData.normals[polygon.normals[vertexIndex]].dot(v).coerceIn(0.1, 1.0).pow(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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user