From c5ec3932c80b65ff3ed909490d839be4b612452b Mon Sep 17 00:00:00 2001 From: Edwin Jakobs Date: Fri, 16 Oct 2020 10:57:22 +0200 Subject: [PATCH] [orx-mesh-generators] Fix normal transforms and add plane to GeneratorBuffer --- .../src/main/kotlin/GeneratorBuffer.kt | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/orx-mesh-generators/src/main/kotlin/GeneratorBuffer.kt b/orx-mesh-generators/src/main/kotlin/GeneratorBuffer.kt index 4bf6c8ac..aa8b98ce 100644 --- a/orx-mesh-generators/src/main/kotlin/GeneratorBuffer.kt +++ b/orx-mesh-generators/src/main/kotlin/GeneratorBuffer.kt @@ -4,6 +4,7 @@ import org.openrndr.draw.VertexBuffer import org.openrndr.math.Matrix44 import org.openrndr.math.Vector2 import org.openrndr.math.Vector3 +import org.openrndr.math.transforms.normalMatrix import org.openrndr.math.transforms.rotate import org.openrndr.math.transforms.transform import org.openrndr.shape.Shape @@ -24,8 +25,15 @@ class GeneratorBuffer { } fun transform(m: Matrix44) { + val nm = normalMatrix(m) data = data.map { - VertexData((m * (it.position.xyz1)).xyz, (m * (it.normal.xyz0)).xyz, it.texCoord) + VertexData((m * (it.position.xyz1)).xyz, (nm * (it.normal.xyz0)).xyz, it.texCoord) + }.toMutableList() + } + + fun transformUV(m: Matrix44) { + data = data.map { + VertexData(it.position, it.normal, (m * (it.texCoord.xy01)).xy) }.toMutableList() } @@ -125,6 +133,11 @@ fun GeneratorBuffer.revolve(sides: Int, length: Double, enveloppe: List generateRevolve(sides, length, enveloppe, this::write) } +fun GeneratorBuffer.plane(center: Vector3, right: Vector3, forward: Vector3, up: Vector3, width: Double = 1.0, height: Double = 1.0, +widthSegments: Int = 1, heightSegments: Int= 1) = + generatePlane(center, right, forward, up, width, height, widthSegments, heightSegments, this::write) + + fun GeneratorBuffer.extrudeShape( baseTriangles: List, contours: List>,