Skip to content
Snippets Groups Projects
Commit c53c5cc3 authored by Alexander Rose's avatar Alexander Rose
Browse files

fixed wrong winding order in primitives

parent f04abbcb
Branches
Tags
No related merge requests found
...@@ -33,8 +33,8 @@ function createBox(perforated: boolean): Primitive { ...@@ -33,8 +33,8 @@ function createBox(perforated: boolean): Primitive {
Vec3.set(b, points[2], points[3], -0.5) Vec3.set(b, points[2], points[3], -0.5)
Vec3.set(c, points[4], points[5], -0.5) Vec3.set(c, points[4], points[5], -0.5)
Vec3.set(d, points[6], points[7], -0.5) Vec3.set(d, points[6], points[7], -0.5)
builder.add(a, b, c) builder.add(c, b, a)
if (!perforated) builder.add(c, d, a) if (!perforated) builder.add(a, d, c)
Vec3.set(a, points[0], points[1], 0.5) Vec3.set(a, points[0], points[1], 0.5)
Vec3.set(b, points[2], points[3], 0.5) Vec3.set(b, points[2], points[3], 0.5)
Vec3.set(c, points[4], points[5], 0.5) Vec3.set(c, points[4], points[5], 0.5)
......
...@@ -16,7 +16,7 @@ const a = Vec3.zero(), b = Vec3.zero(), c = Vec3.zero(), d = Vec3.zero() ...@@ -16,7 +16,7 @@ const a = Vec3.zero(), b = Vec3.zero(), c = Vec3.zero(), d = Vec3.zero()
*/ */
export function Prism(points: ArrayLike<number>): Primitive { export function Prism(points: ArrayLike<number>): Primitive {
const sideCount = points.length / 2 const sideCount = points.length / 2
if (sideCount < 5) throw new Error('need at least 5 points to build a prism') if (sideCount < 4) throw new Error('need at least 5 points to build a prism')
const count = 4 * sideCount const count = 4 * sideCount
const builder = PrimitiveBuilder(count) const builder = PrimitiveBuilder(count)
...@@ -37,10 +37,10 @@ export function Prism(points: ArrayLike<number>): Primitive { ...@@ -37,10 +37,10 @@ export function Prism(points: ArrayLike<number>): Primitive {
const ni = (i + 1) % sideCount const ni = (i + 1) % sideCount
Vec3.set(a, points[i * 2], points[i * 2 + 1], -0.5) 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(b, points[ni * 2], points[ni * 2 + 1], -0.5)
builder.add(a, b, on) builder.add(on, b, a)
Vec3.set(a, points[i * 2], points[i * 2 + 1], 0.5) 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(b, points[ni * 2], points[ni * 2 + 1], 0.5)
builder.add(op, b, a) builder.add(a, b, op)
} }
return builder.getPrimitive() return builder.getPrimitive()
......
...@@ -33,20 +33,20 @@ export function Pyramide(points: ArrayLike<number>): Primitive { ...@@ -33,20 +33,20 @@ export function Pyramide(points: ArrayLike<number>): Primitive {
Vec3.set(a, points[0], points[1], -0.5) Vec3.set(a, points[0], points[1], -0.5)
Vec3.set(b, points[2], points[3], -0.5) Vec3.set(b, points[2], points[3], -0.5)
Vec3.set(c, points[4], points[5], -0.5) Vec3.set(c, points[4], points[5], -0.5)
builder.add(a, b, c) builder.add(c, b, a)
} else if (sideCount === 4) { } else if (sideCount === 4) {
Vec3.set(a, points[0], points[1], -0.5) Vec3.set(a, points[0], points[1], -0.5)
Vec3.set(b, points[2], points[3], -0.5) Vec3.set(b, points[2], points[3], -0.5)
Vec3.set(c, points[4], points[5], -0.5) Vec3.set(c, points[4], points[5], -0.5)
Vec3.set(d, points[6], points[7], -0.5) Vec3.set(d, points[6], points[7], -0.5)
builder.add(a, b, c) builder.add(c, b, a)
builder.add(c, d, a) builder.add(a, d, c)
} else { } else {
for (let i = 0; i < sideCount; ++i) { for (let i = 0; i < sideCount; ++i) {
const ni = (i + 1) % sideCount const ni = (i + 1) % sideCount
Vec3.set(a, points[i * 2], points[i * 2 + 1], -0.5) 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(b, points[ni * 2], points[ni * 2 + 1], -0.5)
builder.add(a, b, on) builder.add(on, b, a)
} }
} }
......
...@@ -46,9 +46,9 @@ export function Star(props?: StarProps): Primitive { ...@@ -46,9 +46,9 @@ export function Star(props?: StarProps): Primitive {
Vec3.set(c, outerPoints[ni * 2], outerPoints[ni * 2 + 1], 0) Vec3.set(c, outerPoints[ni * 2], outerPoints[ni * 2 + 1], 0)
builder.add(op, a, b) builder.add(op, a, b)
builder.add(on, a, b) builder.add(b, a, on)
builder.add(op, b, c) builder.add(op, b, c)
builder.add(on, b, c) builder.add(c, b, on)
} }
return builder.getPrimitive() return builder.getPrimitive()
......
...@@ -32,11 +32,11 @@ export function createWedge(): Primitive { ...@@ -32,11 +32,11 @@ export function createWedge(): Primitive {
Vec3.set(a, points[0], points[1], -0.5) Vec3.set(a, points[0], points[1], -0.5)
Vec3.set(b, points[2], points[3], -0.5) Vec3.set(b, points[2], points[3], -0.5)
Vec3.set(c, points[4], points[5], -0.5) Vec3.set(c, points[4], points[5], -0.5)
builder.add(a, b, c) builder.add(c, b, a)
Vec3.set(a, points[0], points[1], 0.5) Vec3.set(a, points[0], points[1], 0.5)
Vec3.set(b, points[2], points[3], 0.5) Vec3.set(b, points[2], points[3], 0.5)
Vec3.set(c, points[4], points[5], 0.5) Vec3.set(c, points[4], points[5], 0.5)
builder.add(c, b, a) builder.add(a, b, c)
return builder.getPrimitive() return builder.getPrimitive()
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment