Added box, plane and sphere mesh generators
This commit is contained in:
61
orx-mesh-generators/src/main/kotlin/Box.kt
Normal file
61
orx-mesh-generators/src/main/kotlin/Box.kt
Normal file
@@ -0,0 +1,61 @@
|
||||
package org.openrndr.extras.meshgenerators
|
||||
|
||||
import org.openrndr.draw.VertexBuffer
|
||||
import org.openrndr.math.Vector3
|
||||
|
||||
fun boxMesh(width: Double = 1.0, height: Double = 1.0, depth: Double,
|
||||
widthSegments: Int = 1, heightSegments: Int = 1, depthSegments: Int = 1,
|
||||
invert: Boolean = false): VertexBuffer {
|
||||
val vb = meshVertexBuffer(widthSegments * heightSegments * 6 * 2 +
|
||||
widthSegments * depthSegments * 6 * 2 +
|
||||
heightSegments * depthSegments * 6 * 2)
|
||||
vb.put {
|
||||
generateBox(width, height, depth,
|
||||
widthSegments, heightSegments, depthSegments,
|
||||
invert, bufferWriter(this))
|
||||
}
|
||||
return vb
|
||||
}
|
||||
|
||||
fun generateBox(width: Double = 1.0, height: Double = 1.0, depth: Double = 1.0,
|
||||
widthSegments: Int = 1, heightSegments: Int = 1, depthSegments: Int = 1,
|
||||
invert: Boolean = false,
|
||||
writer: VertexWriter) {
|
||||
|
||||
val sign = if (invert) -1.0 else 1.0
|
||||
// +x -- ZY
|
||||
generatePlane(Vector3(width / 2.0 * sign, 0.0, 0.0),
|
||||
Vector3.UNIT_Z, Vector3.UNIT_Y, Vector3.UNIT_X,
|
||||
depth, height,
|
||||
depthSegments, heightSegments, writer)
|
||||
|
||||
// -x -- ZY
|
||||
generatePlane(Vector3(-width / 2.0 * sign, 0.0, 0.0),
|
||||
Vector3.UNIT_Z, Vector3.UNIT_Y, -Vector3.UNIT_X,
|
||||
depth, height,
|
||||
depthSegments, heightSegments, writer)
|
||||
|
||||
// +y -- XZ
|
||||
generatePlane(Vector3(0.0, height / 2.0 * sign, 0.0),
|
||||
Vector3.UNIT_X, Vector3.UNIT_Z, Vector3.UNIT_Y,
|
||||
width, depth,
|
||||
widthSegments, depthSegments, writer)
|
||||
|
||||
// -y -- XZ
|
||||
generatePlane(Vector3(0.0, -height / 2.0 * sign, 0.0),
|
||||
Vector3.UNIT_X, Vector3.UNIT_Z, -Vector3.UNIT_Y,
|
||||
width, depth,
|
||||
widthSegments, depthSegments, writer)
|
||||
|
||||
// +z -- XY
|
||||
generatePlane(Vector3(0.0, 0.0, depth / 2.0 * sign),
|
||||
Vector3.UNIT_X, Vector3.UNIT_Y, Vector3.UNIT_Z,
|
||||
width, height,
|
||||
widthSegments, heightSegments, writer)
|
||||
|
||||
// -z -- XY
|
||||
generatePlane(Vector3(0.0, 0.0, -depth / 2.0 * sign),
|
||||
Vector3.UNIT_X, Vector3.UNIT_Y, -Vector3.UNIT_Z,
|
||||
width, height,
|
||||
widthSegments, heightSegments, writer)
|
||||
}
|
||||
Reference in New Issue
Block a user