Fix problem in UV coord generation of plane meshes
This commit is contained in:
18
build.gradle
18
build.gradle
@@ -20,16 +20,26 @@ project.ext {
|
|||||||
spekVersion = "2.0.10"
|
spekVersion = "2.0.10"
|
||||||
libfreenectVersion = "0.5.7-1.5.2"
|
libfreenectVersion = "0.5.7-1.5.2"
|
||||||
gsonVersion = "2.8.6"
|
gsonVersion = "2.8.6"
|
||||||
}
|
|
||||||
|
|
||||||
|
}
|
||||||
|
switch (org.gradle.internal.os.OperatingSystem.current()) {
|
||||||
|
case org.gradle.internal.os.OperatingSystem.WINDOWS:
|
||||||
|
project.ext.openrndrOS = "windows"
|
||||||
|
break
|
||||||
|
case org.gradle.internal.os.OperatingSystem.LINUX:
|
||||||
|
project.ext.openrndrOS = "linux-x64"
|
||||||
|
break
|
||||||
|
case org.gradle.internal.os.OperatingSystem.MAC_OS:
|
||||||
|
project.ext.openrndrOS = "macos"
|
||||||
|
break
|
||||||
|
}
|
||||||
dokka {
|
dokka {
|
||||||
moduleName = "$rootProject.name"
|
moduleName = "$rootProject.name"
|
||||||
outputDirectory = "$buildDir/docs"
|
outputDirectory = "$buildDir/docs"
|
||||||
outputFormat = "html"
|
outputFormat = "html"
|
||||||
includes = ['Module.md']
|
includes = ['Module.md']
|
||||||
sourceDirs = files(subprojects.collect { p -> new File(p.projectDir, "/src/main/kotlin") })
|
sourceDirs = files(subprojects.collect { p -> new File(p.projectDir, "/src/main/kotlin") })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
allprojects {
|
allprojects {
|
||||||
apply plugin: 'idea'
|
apply plugin: 'idea'
|
||||||
@@ -72,13 +82,11 @@ allprojects {
|
|||||||
runtimeOnly "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"
|
runtimeOnly "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
java {
|
java {
|
||||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||||
targetCompatibility = JavaVersion.VERSION_1_8
|
targetCompatibility = JavaVersion.VERSION_1_8
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
javadoc {
|
javadoc {
|
||||||
options.addBooleanOption 'Xdoclint:none', true
|
options.addBooleanOption 'Xdoclint:none', true
|
||||||
}
|
}
|
||||||
|
|||||||
18
orx-mesh-generators/build.gradle
Normal file
18
orx-mesh-generators/build.gradle
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
sourceSets {
|
||||||
|
demo {
|
||||||
|
java {
|
||||||
|
srcDirs = ["src/demo/kotlin"]
|
||||||
|
compileClasspath += main.getCompileClasspath()
|
||||||
|
runtimeClasspath += main.getRuntimeClasspath()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
demoImplementation(project(":orx-camera"))
|
||||||
|
demoImplementation("org.openrndr:openrndr-core:$openrndrVersion")
|
||||||
|
demoRuntimeOnly("org.openrndr:openrndr-gl3:$openrndrVersion")
|
||||||
|
demoRuntimeOnly("org.openrndr:openrndr-gl3-natives-$openrndrOS:$openrndrVersion")
|
||||||
|
|
||||||
|
demoImplementation(sourceSets.getByName("main").output)
|
||||||
|
}
|
||||||
35
orx-mesh-generators/src/demo/kotlin/DemoBox.kt
Normal file
35
orx-mesh-generators/src/demo/kotlin/DemoBox.kt
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
import org.openrndr.application
|
||||||
|
import org.openrndr.color.ColorRGBa
|
||||||
|
import org.openrndr.draw.DrawPrimitive
|
||||||
|
import org.openrndr.draw.colorBuffer
|
||||||
|
import org.openrndr.draw.shadeStyle
|
||||||
|
import org.openrndr.extras.camera.Orbital
|
||||||
|
import org.openrndr.extras.meshgenerators.boxMesh
|
||||||
|
|
||||||
|
fun main() {
|
||||||
|
application {
|
||||||
|
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())
|
||||||
|
extend {
|
||||||
|
drawer.background(ColorRGBa.PINK)
|
||||||
|
drawer.shadeStyle = shadeStyle {
|
||||||
|
fragmentTransform = """
|
||||||
|
x_fill = texture(p_texture, va_texCoord0.xy);
|
||||||
|
""".trimIndent()
|
||||||
|
parameter("texture", texture)
|
||||||
|
}
|
||||||
|
drawer.vertexBuffer(box, DrawPrimitive.TRIANGLES)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,84 +1,84 @@
|
|||||||
package org.openrndr.extras.meshgenerators
|
package org.openrndr.extras.meshgenerators
|
||||||
|
|
||||||
import org.openrndr.draw.VertexBuffer
|
import org.openrndr.draw.VertexBuffer
|
||||||
import org.openrndr.math.Vector2
|
import org.openrndr.math.Vector2
|
||||||
import org.openrndr.math.Vector3
|
import org.openrndr.math.Vector3
|
||||||
|
|
||||||
fun planeMesh(center: Vector3,
|
fun planeMesh(center: Vector3,
|
||||||
right: Vector3,
|
right: Vector3,
|
||||||
forward: Vector3,
|
forward: Vector3,
|
||||||
up: Vector3 = forward.cross(right).normalized,
|
up: Vector3 = forward.cross(right).normalized,
|
||||||
width: Double = 1.0, height: Double = 1.0,
|
width: Double = 1.0, height: Double = 1.0,
|
||||||
widthSegments: Int = 1, heightSegments: Int = 1): VertexBuffer {
|
widthSegments: Int = 1, heightSegments: Int = 1): VertexBuffer {
|
||||||
|
|
||||||
val vertexCount = (widthSegments * heightSegments) * 6
|
val vertexCount = (widthSegments * heightSegments) * 6
|
||||||
val vb = meshVertexBuffer(vertexCount)
|
val vb = meshVertexBuffer(vertexCount)
|
||||||
vb.put {
|
vb.put {
|
||||||
generatePlane(center, right, forward, up,
|
generatePlane(center, right, forward, up,
|
||||||
width, height, widthSegments, heightSegments, bufferWriter(this))
|
width, height, widthSegments, heightSegments, bufferWriter(this))
|
||||||
}
|
}
|
||||||
return vb
|
return vb
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* generates a finite plane with its center at (0,0,0) and spanning the xz-plane
|
* generates a finite plane with its center at (0,0,0) and spanning the xz-plane
|
||||||
*/
|
*/
|
||||||
fun groundPlaneMesh(width: Double = 1.0,
|
fun groundPlaneMesh(width: Double = 1.0,
|
||||||
height: Double = 1.0,
|
height: Double = 1.0,
|
||||||
widthSegments: Int = 1,
|
widthSegments: Int = 1,
|
||||||
heightSegments: Int = 1): VertexBuffer {
|
heightSegments: Int = 1): VertexBuffer {
|
||||||
return planeMesh(Vector3.ZERO, Vector3.UNIT_X, Vector3.UNIT_Z, Vector3.UNIT_Y,
|
return planeMesh(Vector3.ZERO, Vector3.UNIT_X, Vector3.UNIT_Z, Vector3.UNIT_Y,
|
||||||
width, height, widthSegments, heightSegments)
|
width, height, widthSegments, heightSegments)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* generates a finite plane with its center at (0,0,0) and spanning the xy-plane
|
* generates a finite plane with its center at (0,0,0) and spanning the xy-plane
|
||||||
*/
|
*/
|
||||||
fun wallPlaneMesh(width: Double = 1.0,
|
fun wallPlaneMesh(width: Double = 1.0,
|
||||||
height: Double = 1.0,
|
height: Double = 1.0,
|
||||||
widthSegments: Int = 1,
|
widthSegments: Int = 1,
|
||||||
heightSegments: Int = 1): VertexBuffer {
|
heightSegments: Int = 1): VertexBuffer {
|
||||||
return planeMesh(Vector3.ZERO, Vector3.UNIT_X, Vector3.UNIT_Y, Vector3.UNIT_Z,
|
return planeMesh(Vector3.ZERO, Vector3.UNIT_X, Vector3.UNIT_Y, Vector3.UNIT_Z,
|
||||||
width, height, widthSegments, heightSegments)
|
width, height, widthSegments, heightSegments)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun generatePlane(center: Vector3,
|
fun generatePlane(center: Vector3,
|
||||||
right: Vector3,
|
right: Vector3,
|
||||||
forward: Vector3,
|
forward: Vector3,
|
||||||
up: Vector3 = forward.cross(right).normalized,
|
up: Vector3 = forward.cross(right).normalized,
|
||||||
|
|
||||||
width: Double = 1.0, height: Double = 1.0,
|
width: Double = 1.0, height: Double = 1.0,
|
||||||
widthSegments: Int = 1, heightSegments: Int = 2,
|
widthSegments: Int = 1, heightSegments: Int = 2,
|
||||||
writer: VertexWriter) {
|
writer: VertexWriter) {
|
||||||
|
|
||||||
val forwardStep = forward.normalized * (height / heightSegments)
|
val forwardStep = forward.normalized * (height / heightSegments)
|
||||||
val rightStep = right.normalized * (width / widthSegments)
|
val rightStep = right.normalized * (width / widthSegments)
|
||||||
|
|
||||||
val corner = center - forward.normalized * (height*0.5) - right.normalized * (width * 0.5)
|
val corner = center - forward.normalized * (height*0.5) - right.normalized * (width * 0.5)
|
||||||
|
|
||||||
val step = Vector2(1.0 / width, 1.0 / height)
|
val step = Vector2(1.0 / widthSegments, 1.0 / heightSegments)
|
||||||
|
|
||||||
for (v in 0 until heightSegments) {
|
for (v in 0 until heightSegments) {
|
||||||
for (u in 0 until widthSegments) {
|
for (u in 0 until widthSegments) {
|
||||||
|
|
||||||
val uv00 = Vector2(u + 0.0, v + 0.0) * step
|
val uv00 = Vector2(u + 0.0, v + 0.0) * step
|
||||||
val uv01 = Vector2(u + 0.0, v + 1.0) * step
|
val uv01 = Vector2(u + 0.0, v + 1.0) * step
|
||||||
val uv10 = Vector2(u + 1.0, v + 0.0) * step
|
val uv10 = Vector2(u + 1.0, v + 0.0) * step
|
||||||
val uv11 = Vector2(u + 1.0, v + 1.0) * step
|
val uv11 = Vector2(u + 1.0, v + 1.0) * step
|
||||||
|
|
||||||
val c00 = corner + forwardStep * v.toDouble() + rightStep * u.toDouble()
|
val c00 = corner + forwardStep * v.toDouble() + rightStep * u.toDouble()
|
||||||
val c01 = corner + forwardStep * (v + 1).toDouble() + rightStep * u.toDouble()
|
val c01 = corner + forwardStep * (v + 1).toDouble() + rightStep * u.toDouble()
|
||||||
val c10 = corner + forwardStep * v.toDouble() + rightStep * (u + 1).toDouble()
|
val c10 = corner + forwardStep * v.toDouble() + rightStep * (u + 1).toDouble()
|
||||||
val c11 = corner + forwardStep * (v + 1).toDouble() + rightStep * (u + 1).toDouble()
|
val c11 = corner + forwardStep * (v + 1).toDouble() + rightStep * (u + 1).toDouble()
|
||||||
|
|
||||||
writer(c11, up, uv00)
|
writer(c11, up, uv00)
|
||||||
writer(c10, up, uv10)
|
writer(c10, up, uv10)
|
||||||
writer(c00, up, uv11)
|
writer(c00, up, uv11)
|
||||||
|
|
||||||
writer(c00, up, uv11)
|
writer(c00, up, uv11)
|
||||||
writer(c01, up, uv01)
|
writer(c01, up, uv01)
|
||||||
writer(c11, up, uv00)
|
writer(c11, up, uv00)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user