[orx-noise] Add hash functions
This commit is contained in:
72
orx-mesh-generators/src/commonMain/kotlin/mesh/Box.kt
Normal file
72
orx-mesh-generators/src/commonMain/kotlin/mesh/Box.kt
Normal file
@@ -0,0 +1,72 @@
|
||||
package org.openrndr.extra.mesh.generators
|
||||
|
||||
import org.openrndr.extra.mesh.*
|
||||
import org.openrndr.math.Vector2
|
||||
import org.openrndr.math.Vector3
|
||||
|
||||
class MeshBuilder {
|
||||
val vertexData = MutableVertexData()
|
||||
val polygons = mutableListOf<IndexedPolygon>()
|
||||
val mesh = MutableMeshData(vertexData, polygons)
|
||||
}
|
||||
|
||||
fun box(): MeshData {
|
||||
|
||||
val positions = listOf(
|
||||
Vector3(-0.5, -0.5, -0.5),
|
||||
Vector3(0.5, -0.5, -0.5),
|
||||
Vector3(-0.5, 0.5, -0.5),
|
||||
Vector3(0.5, 0.5, -0.5),
|
||||
|
||||
Vector3(-0.5, -0.5, 0.5),
|
||||
Vector3(0.5, -0.5, 0.5),
|
||||
Vector3(-0.5, 0.5, 0.5),
|
||||
Vector3(0.5, 0.5, 0.5),
|
||||
)
|
||||
|
||||
val textureCoords = listOf(
|
||||
Vector2(0.0, 0.0),
|
||||
Vector2(1.0, 0.0),
|
||||
Vector2(0.0, 1.0),
|
||||
Vector2(1.0, 1.0),
|
||||
)
|
||||
|
||||
val normals = listOf(
|
||||
Vector3(-1.0, 0.0, 0.0),
|
||||
Vector3(1.0, 0.0, 0.0),
|
||||
Vector3(0.0, -1.0, 0.0),
|
||||
Vector3(0.0, 1.0, 0.0),
|
||||
Vector3(0.0, 0.0, -1.0),
|
||||
Vector3(0.0, 0.0, 1.0)
|
||||
)
|
||||
|
||||
val polygons = listOf(
|
||||
// -x
|
||||
IndexedPolygon(
|
||||
positions = listOf(0, 2, 4, 6),
|
||||
textureCoords = listOf(0, 1, 3, 2),
|
||||
colors = emptyList(),
|
||||
normals = listOf(0, 0, 0, 0),
|
||||
tangents = listOf(5, 5, 5, 5),
|
||||
bitangents = listOf(3, 3, 3, 3)
|
||||
),
|
||||
// +x
|
||||
IndexedPolygon(
|
||||
positions = listOf(1, 3, 5, 7),
|
||||
textureCoords = listOf(0, 1, 3, 2),
|
||||
colors = emptyList(),
|
||||
normals = listOf(1, 1, 1, 1),
|
||||
tangents = listOf(4, 4, 4, 4),
|
||||
bitangents = listOf(3, 3, 3, 3)
|
||||
)
|
||||
)
|
||||
return MeshData(
|
||||
VertexData(
|
||||
positions = positions,
|
||||
textureCoords = textureCoords,
|
||||
normals = normals,
|
||||
tangents = normals,
|
||||
bitangents = normals
|
||||
), polygons
|
||||
)
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import java.io.File
|
||||
|
||||
/**
|
||||
* Demonstrate decal generator as an object slicer
|
||||
* @see <img src="https://raw.githubusercontent.com/openrndr/orx/media/orx-mesh-generators/images/decal-DemoDecal01Kt.png">
|
||||
*/
|
||||
fun main() {
|
||||
application {
|
||||
|
||||
@@ -15,6 +15,7 @@ import kotlin.math.PI
|
||||
|
||||
/**
|
||||
* Demonstrate decal generation and rendering
|
||||
* @see <img src="https://raw.githubusercontent.com/openrndr/orx/media/orx-mesh-generators/images/decal-DemoDecal02Kt.png">
|
||||
*/
|
||||
fun main() {
|
||||
application {
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package tangents
|
||||
|
||||
import org.openrndr.application
|
||||
import org.openrndr.draw.DrawPrimitive
|
||||
import org.openrndr.draw.shadeStyle
|
||||
import org.openrndr.extra.camera.Orbital
|
||||
import org.openrndr.extra.mesh.toVertexBuffer
|
||||
import org.openrndr.extra.meshgenerators.tangents.estimateTangents
|
||||
import org.openrndr.extra.objloader.loadOBJMeshData
|
||||
import org.openrndr.math.Vector3
|
||||
import java.io.File
|
||||
|
||||
fun main() = application {
|
||||
program {
|
||||
val obj = loadOBJMeshData(File("demo-data/obj-models/suzanne/Suzanne.obj")).toMeshData().triangulate()
|
||||
val tangentObj = obj.estimateTangents()
|
||||
|
||||
val objVB = tangentObj.toVertexBuffer()
|
||||
|
||||
extend(Orbital()) {
|
||||
eye = Vector3(0.0, 0.0, 2.0)
|
||||
}
|
||||
extend {
|
||||
drawer.shadeStyle = shadeStyle {
|
||||
fragmentTransform = """
|
||||
vec3 viewTangent = (u_viewNormalMatrix * u_modelNormalMatrix * vec4(va_tangent, 0.0)).xyz;
|
||||
vec3 viewBitangent = (u_viewNormalMatrix * u_modelNormalMatrix * vec4(va_bitangent, 0.0)).xyz;
|
||||
float c = cos(100.0*dot(v_worldPosition, va_normal)) * 0.5 + 0.5;
|
||||
|
||||
//x_fill.rgb = normalize(viewTangent)*0.5+0.5;
|
||||
x_fill.rgb = vec3(c);
|
||||
""".trimIndent()
|
||||
|
||||
}
|
||||
|
||||
drawer.vertexBuffer(objVB, DrawPrimitive.TRIANGLES)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user