|
@@ -1,5 +1,5 @@
|
|
|
/**
|
|
|
- * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
|
|
+ * Copyright (c) 2018-2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
|
|
*
|
|
|
* @author Alexander Rose <alexander.rose@weirdbyte.de>
|
|
|
*/
|
|
@@ -12,10 +12,10 @@ const on = Vec3.create(0, 0, -0.5), op = Vec3.create(0, 0, 0.5)
|
|
|
const a = Vec3.zero(), b = Vec3.zero(), c = Vec3.zero(), d = Vec3.zero()
|
|
|
|
|
|
/**
|
|
|
- * Create a pyramid with a poligonal base
|
|
|
+ * Create a pyramid with a polygonal base
|
|
|
*/
|
|
|
export function Pyramid(points: ArrayLike<number>): Primitive {
|
|
|
- const sideCount = points.length / 2
|
|
|
+ const sideCount = points.length / 3
|
|
|
const baseCount = sideCount === 3 ? 1 : sideCount === 4 ? 2 : sideCount
|
|
|
const count = 2 * baseCount + 2 * sideCount
|
|
|
const builder = PrimitiveBuilder(count)
|
|
@@ -23,29 +23,29 @@ export function Pyramid(points: ArrayLike<number>): Primitive {
|
|
|
// create sides
|
|
|
for (let i = 0; i < sideCount; ++i) {
|
|
|
const ni = (i + 1) % sideCount
|
|
|
- Vec3.set(a, points[i * 2], points[i * 2 + 1], -0.5)
|
|
|
- Vec3.set(b, points[ni * 2], points[ni * 2 + 1], -0.5)
|
|
|
+ Vec3.set(a, points[i * 3], points[i * 3 + 1], -0.5)
|
|
|
+ Vec3.set(b, points[ni * 3], points[ni * 3 + 1], -0.5)
|
|
|
builder.add(a, b, op)
|
|
|
}
|
|
|
|
|
|
// create base
|
|
|
if (sideCount === 3) {
|
|
|
Vec3.set(a, points[0], points[1], -0.5)
|
|
|
- Vec3.set(b, points[2], points[3], -0.5)
|
|
|
- Vec3.set(c, points[4], points[5], -0.5)
|
|
|
+ Vec3.set(b, points[3], points[4], -0.5)
|
|
|
+ Vec3.set(c, points[6], points[7], -0.5)
|
|
|
builder.add(c, b, a)
|
|
|
} else if (sideCount === 4) {
|
|
|
Vec3.set(a, points[0], points[1], -0.5)
|
|
|
- Vec3.set(b, points[2], points[3], -0.5)
|
|
|
- Vec3.set(c, points[4], points[5], -0.5)
|
|
|
- Vec3.set(d, points[6], points[7], -0.5)
|
|
|
+ Vec3.set(b, points[3], points[4], -0.5)
|
|
|
+ Vec3.set(c, points[6], points[7], -0.5)
|
|
|
+ Vec3.set(d, points[9], points[10], -0.5)
|
|
|
builder.add(c, b, a)
|
|
|
builder.add(a, d, c)
|
|
|
} else {
|
|
|
for (let i = 0; i < sideCount; ++i) {
|
|
|
const ni = (i + 1) % sideCount
|
|
|
- Vec3.set(a, points[i * 2], points[i * 2 + 1], -0.5)
|
|
|
- Vec3.set(b, points[ni * 2], points[ni * 2 + 1], -0.5)
|
|
|
+ Vec3.set(a, points[i * 3], points[i * 3 + 1], -0.5)
|
|
|
+ Vec3.set(b, points[ni * 3], points[ni * 3 + 1], -0.5)
|
|
|
builder.add(on, b, a)
|
|
|
}
|
|
|
}
|
|
@@ -67,8 +67,8 @@ export function PerforatedOctagonalPyramid() {
|
|
|
const points = polygon(8, true)
|
|
|
const vertices = new Float32Array(8 * 3 + 6)
|
|
|
for (let i = 0; i < 8; ++i) {
|
|
|
- vertices[i * 3] = points[i * 2]
|
|
|
- vertices[i * 3 + 1] = points[i * 2 + 1]
|
|
|
+ vertices[i * 3] = points[i * 3]
|
|
|
+ vertices[i * 3 + 1] = points[i * 3 + 1]
|
|
|
vertices[i * 3 + 2] = -0.5
|
|
|
}
|
|
|
vertices[8 * 3] = 0
|