[orx-shapes, orx-mesh-generator] Move frames code from orx-mesh-generator to orx-shapes

This commit is contained in:
Edwin Jakobs
2024-03-19 17:54:03 +01:00
parent 76f96d2278
commit c48aa83ced
10 changed files with 167 additions and 23 deletions

View File

@@ -9,6 +9,7 @@ kotlin {
dependencies {
api(libs.openrndr.application)
api(libs.openrndr.math)
implementation(project(":orx-shapes"))
}
}

View File

@@ -1,14 +1,12 @@
package org.openrndr.extra.meshgenerators
import org.openrndr.extra.shapes.frames.frames
import org.openrndr.math.Matrix44
import org.openrndr.math.Vector2
import org.openrndr.math.Vector3
import org.openrndr.math.Vector4
import org.openrndr.math.transforms.normalMatrix
import org.openrndr.shape.Path3D
import org.openrndr.shape.Shape
import org.openrndr.shape.ShapeContour
import org.openrndr.shape.Triangle
/**
* Writes quads to [writer] creating a surface that connects two

View File

@@ -1,5 +1,6 @@
package org.openrndr.extra.meshgenerators
import org.openrndr.extra.shapes.frames.frames
import org.openrndr.math.Matrix44
import org.openrndr.math.Vector3
import org.openrndr.shape.Path3D

View File

@@ -1,5 +1,6 @@
package org.openrndr.extra.meshgenerators
import org.openrndr.extra.shapes.frames.frames
import org.openrndr.math.Matrix44
import org.openrndr.math.Vector3
import org.openrndr.shape.Path3D

View File

@@ -1,60 +0,0 @@
package org.openrndr.extra.meshgenerators
import org.openrndr.math.Matrix44
import org.openrndr.math.Vector3
import org.openrndr.math.Vector4
import org.openrndr.math.transforms.buildTransform
/**
* Calculate frames (pose matrices) using parallel transport
* @param up0 initial up vector, should not be collinear with `this[1] - this[0]`
*/
fun List<Vector3>.frames(up0: Vector3): List<Matrix44> {
val result = mutableListOf<Matrix44>()
if (this.isEmpty()) {
return emptyList()
}
if (this.size == 1) {
return listOf(Matrix44.IDENTITY)
}
var up = up0.normalized
run {
val current = this[0]
val next = this[1]
val forward = (next - current).normalized
val right = (forward cross up).normalized
up = ((right cross forward)).normalized
result.add(Matrix44.fromColumnVectors(right.xyz0, up.xyz0, forward.xyz0, current.xyz1))
}
require(up.length > 0.0) { "initial `up.length` is zero in .frames()" }
for (i in 1 until size - 1) {
val prev = this[i - 1]
val current = this[i]
val next = this[i + 1]
val f1 = (next - current).normalized
val f0 = (current - prev).normalized
val forward = (f0 + f1).normalized
require(forward.length > 0.0) { "`forward.length` is zero in .frames()" }
val right = (forward cross up).normalized
up = ((right cross forward)).normalized
require(up.length > 0.0) { "`up.length` is zero in .frames()" }
require(right.length > 0.0) { "`right.length` is zero in .frames()" }
//val m = Matrix44.fromColumnVectors(right.xyz0, up.xyz0, forward.xyz0, current.xyz1)
val m = buildTransform {
translate(current)
multiply(Matrix44.fromColumnVectors(right.xyz0, up.xyz0, forward.xyz0, Vector4.UNIT_W))
}
result.add(m)
}
return result
}