From e865e00e560fdaf00c439637f72e571afc32c888 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Thu, 16 Feb 2023 09:08:28 +0100 Subject: [PATCH] Repair caps; remove PenScale again --- scene/lobby.pr | 29 +++++++++++++++++++---------- scene/misc.pr | 8 ++------ src/turtle.ts | 35 ++++++++++++++++++++--------------- 3 files changed, 41 insertions(+), 31 deletions(-) diff --git a/scene/lobby.pr b/scene/lobby.pr index 0806021..e889b8c 100644 --- a/scene/lobby.pr +++ b/scene/lobby.pr @@ -1,5 +1,5 @@ >> -; > +> > >>>>> + >>>> -@ > > diff --git a/src/turtle.ts b/src/turtle.ts index 9d7baf1..04b3cd1 100644 --- a/src/turtle.ts +++ b/src/turtle.ts @@ -18,7 +18,6 @@ export class PenState { templatePath: Vector3[] = [new Vector3()]; paths: Vector3[][] | null = null; directions: Quaternion[] | null = null; - templateScale = new Vector3(1, 1, 1); get isDown(): boolean { return this.paths !== null; @@ -62,14 +61,14 @@ export class PenState { if (d !== null) steps[steps.length - 1] = p.add(lastDir.scale(d)); } this.templatePath.forEach((p, i) => { - const r = p.multiply(this.templateScale).applyRotationQuaternion(q).addInPlace(pos); + const r = p.applyRotationQuaternion(q).addInPlace(pos); const d = pointDistance(r, thisDir, miterPlane); if (d !== null) r.addInPlace(thisDir.scale(d)); paths[i].push(r); }); } else { this.templatePath.forEach((p, i) => { - const r = p.multiply(this.templateScale).applyRotationQuaternion(q).addInPlace(pos); + const r = p.applyRotationQuaternion(q).addInPlace(pos); paths[i].push(r); }); } @@ -164,6 +163,10 @@ export class TurtleVM extends Cat.VM { const pathCount = paths.length; const stepCount = paths[0].length; + if (this.cap === CapType.START || this.cap === CapType.BOTH) { + lines.push(paths.map(p => p[0])); + } + for (let pathIndex = 1; pathIndex < pathCount; pathIndex++) { for (let stepIndex = 1; stepIndex < stepCount; stepIndex++) { lines.push([paths[pathIndex - 1][stepIndex - 1], @@ -173,6 +176,10 @@ export class TurtleVM extends Cat.VM { } } + if (this.cap === CapType.END || this.cap === CapType.BOTH) { + lines.push(paths.map(p => p[p.length - 1])); + } + const meshName = this.container.name + this.counter++; const ls = MeshBuilder.CreateLineSystem(meshName, { lines }, null); ls.parent = this.container; @@ -238,18 +245,20 @@ export class TurtleVM extends Cat.VM { const computePointIndex = this.smooth ? cachedPoint : pushPoint; - function cap(stepIndex: number) { - const capVerts = paths.flatMap(p => p[stepIndex].asArray()); - const capIndices = earcut(capVerts, void 0, 3); + const capIndices = this.cap === CapType.NONE + ? [] + : earcut(this.pen.templatePath.flatMap(p => [p.x, p.y]), void 0, 2); + + function cap(stepIndex: number, a: number, b: number, c: number) { for (let i = 0; i < capIndices.length; i += 3) { - indices.push(computePointIndex(capIndices[i+0], stepIndex), - computePointIndex(capIndices[i+1], stepIndex), - computePointIndex(capIndices[i+2], stepIndex)); + indices.push(computePointIndex(capIndices[i+a], stepIndex), + computePointIndex(capIndices[i+b], stepIndex), + computePointIndex(capIndices[i+c], stepIndex)); } } if (this.cap === CapType.START || this.cap === CapType.BOTH) { - cap(0); + cap(0, 0, 1, 2); } for (let pathIndex = 1; pathIndex < pathCount; pathIndex++) { @@ -265,7 +274,7 @@ export class TurtleVM extends Cat.VM { } if (this.cap === CapType.END || this.cap === CapType.BOTH) { - cap(stepCount - 1); + cap(stepCount - 1, 2, 1, 0); } VertexData.ComputeNormals(positions, indices, normals); @@ -339,10 +348,6 @@ export const TurtlePrimitives: Cat.Environment = Object.assign({}, Cat return []; }, - 'PenScale'(sx, sy, sz) { - this.pen.templateScale = new Vector3(sx as number, sy as number, sz as number); - return []; - }, 'PenDown'() { this.penDown(); return []; }, 'PenUp'() { this.penUp(false); return []; }, 'Close'() { this.penUp(true); return []; },