From 8dc4bfd8fc0812089b78b75099db8bf3e756ef01 Mon Sep 17 00:00:00 2001 From: Edwin Jakobs Date: Tue, 14 Jan 2020 23:47:18 +0100 Subject: [PATCH] Add option to use existing vertex buffer in meshGenerator --- .../src/main/kotlin/GeneratorBuffer.kt | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/orx-mesh-generators/src/main/kotlin/GeneratorBuffer.kt b/orx-mesh-generators/src/main/kotlin/GeneratorBuffer.kt index 527c6121..4fe3bf62 100644 --- a/orx-mesh-generators/src/main/kotlin/GeneratorBuffer.kt +++ b/orx-mesh-generators/src/main/kotlin/GeneratorBuffer.kt @@ -1,8 +1,6 @@ package org.openrndr.extras.meshgenerators import org.openrndr.draw.VertexBuffer -import org.openrndr.draw.vertexBuffer -import org.openrndr.draw.vertexFormat import org.openrndr.math.Matrix44 import org.openrndr.math.Vector2 import org.openrndr.math.Vector3 @@ -123,11 +121,11 @@ fun GeneratorBuffer.cap(sides: Int, radius: Double, enveloppe: List) { generateCap(sides, radius, enveloppe, this::write) } -fun GeneratorBuffer.revolve(sides:Int, length:Double, enveloppe: List) { +fun GeneratorBuffer.revolve(sides: Int, length: Double, enveloppe: List) { generateRevolve(sides, length, enveloppe, this::write) } -fun GeneratorBuffer.extrudeShape( baseTriangles:List, contours:List>, length: Double, scale: Double = 1.0, distanceTolerance: Double = 0.5) { +fun GeneratorBuffer.extrudeShape(baseTriangles: List, contours: List>, length: Double, scale: Double = 1.0, distanceTolerance: Double = 0.5) { extrudeShape(baseTriangles, contours, -length / 2.0, length / 2.0, scale, scale, true, true, distanceTolerance, false, this::write) } @@ -140,16 +138,11 @@ fun GeneratorBuffer.extrudeShapes(shapes: List, length: Double, scale: Do } - -fun meshGenerator(builder: GeneratorBuffer.() -> Unit): VertexBuffer { +fun meshGenerator(vertexBuffer: VertexBuffer? = null, builder: GeneratorBuffer.() -> Unit): VertexBuffer { val gb = GeneratorBuffer() gb.builder() - val vb = vertexBuffer(vertexFormat { - position(3) - normal(3) - textureCoordinate(2) - }, gb.data.size) + val vb = vertexBuffer ?: meshVertexBuffer(gb.data.size) val bb = gb.toByteBuffer() bb.rewind()