Repair caps; remove PenScale again
This commit is contained in:
parent
096946d0ad
commit
e865e00e56
|
@ -1,5 +1,5 @@
|
|||
<sprite "light" [] <hemispheric-light <v 0.2 1.0 0.0>>>
|
||||
; <gravity <v 0.0 -9.81 0.0>>
|
||||
<gravity <v 0.0 -9.81 0.0>>
|
||||
<sprite "sky" [] <skybox "textures/Daylight Box UV_0">>
|
||||
|
||||
<sprite "ground" []
|
||||
|
@ -36,7 +36,7 @@
|
|||
<box>>>>>>
|
||||
|
||||
<sprite "t" []
|
||||
<move <v -2.0 0.001 0.0>
|
||||
<move <v -2.0 0.001 -10.0>
|
||||
<rotate <v 0.0 0.0 0.0>
|
||||
<texture ["textures/pixar128/wall/Rattan_pxr128.jpg"]
|
||||
<turtle [
|
||||
|
@ -45,7 +45,7 @@
|
|||
ClearPen
|
||||
PenDown
|
||||
[
|
||||
30 to lean
|
||||
15 to lean
|
||||
1 lean cos / to len
|
||||
lean R
|
||||
[len F 90 lean + L 0.1 F 90 lean - L] 2 times
|
||||
|
@ -59,35 +59,40 @@
|
|||
|
||||
[ to [f] PenDown f PenUp ] to draw
|
||||
|
||||
4 to nSides
|
||||
40 to nSides
|
||||
360 nSides / to angle
|
||||
20 nSides / to dist
|
||||
|
||||
[
|
||||
angle R 0 F
|
||||
[dist F angle R 0 F] nSides times
|
||||
[dist F angle R 0 F] nSides 0.95 * times
|
||||
angle L
|
||||
] to plotArea
|
||||
|
||||
Home
|
||||
ClearPen
|
||||
90 R 0.05 B 90 L
|
||||
PenDown 0.1 F DefinePen
|
||||
Home
|
||||
PenDown
|
||||
90 D
|
||||
plotArea
|
||||
0 F plotArea
|
||||
DefinePen GetPen to floorPen
|
||||
Home
|
||||
|
||||
Home
|
||||
[
|
||||
floorPen SetPen
|
||||
90 U [0.1 F] draw 90 D
|
||||
90 U 0.001 F [0.05 F] draw "NONE" SetCap [0.949 F] draw "BOTH" SetCap 90 D
|
||||
vPen SetPen
|
||||
#t SetSmooth
|
||||
quote plotArea draw 90 U 1 F 90 D
|
||||
#f SetSmooth
|
||||
] 3 times
|
||||
]>
|
||||
>>>>
|
||||
|
||||
@<sprite "house" []
|
||||
<sprite "house" []
|
||||
<move <v 0.0 0.0 10.0>
|
||||
<rotate <v 0.0 0.0 0.0>
|
||||
<texture ["textures/oak-herringbone-5e80fb40b00c9-1200.jpg"]
|
||||
|
@ -140,6 +145,10 @@
|
|||
[ 90 L miter ] to --
|
||||
[ 90 R miter ] to ++
|
||||
|
||||
; [ Home 90 U 0.5 F 90 D ] to goHome
|
||||
quote Home to goHome
|
||||
goHome
|
||||
|
||||
exteriorWall
|
||||
--
|
||||
[
|
||||
|
@ -157,7 +166,7 @@
|
|||
] draw
|
||||
|
||||
interiorWall
|
||||
Home
|
||||
goHome
|
||||
2.1 F
|
||||
[0.2 F [1 F] iDoor 6.5 F] draw
|
||||
1.1 B [90 L [0.2 F [1 F] iDoor 1 F] draw] saved
|
||||
|
@ -171,7 +180,7 @@
|
|||
[0.1 F [0.7 F] iDoor 0.2 F] draw
|
||||
[-- [3.8 F] draw] saved
|
||||
[0.9 F [0.6 F] iDoor 3.0 F] draw
|
||||
[-- [3.1 F] draw] saved
|
||||
[-- [0.4 F [0.6 F] iDoor 2.1 F] draw] saved
|
||||
[0.2 F [0.7 F] iDoor 0.4 F] draw
|
||||
[++ [1.7 F] draw] saved
|
||||
[0.1 F [0.6 F] iDoor 0.2 F] draw
|
||||
|
|
|
@ -157,13 +157,9 @@
|
|||
; [ R 0 F 60 D ] to rr
|
||||
; [ 4 to k k / [dup R 0 F] k times drop ] to rr
|
||||
|
||||
PenDown
|
||||
60 to sides
|
||||
[4 sides / ff 360 sides / rr] sides 2 / 2 - times
|
||||
1 0.5 1 PenScale 0 F
|
||||
[4 sides / ff 360 sides / rr] 4 times
|
||||
1 1 1 PenScale 0 F
|
||||
[4 sides / ff 360 sides / rr] sides 2 / 2 - times
|
||||
PenDown
|
||||
[4 sides / ff 360 sides / rr] sides times
|
||||
PenUp
|
||||
]>>
|
||||
<mesh <box>>
|
||||
|
|
|
@ -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<TurtleVM> {
|
|||
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<TurtleVM> {
|
|||
}
|
||||
}
|
||||
|
||||
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<TurtleVM> {
|
|||
|
||||
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<TurtleVM> {
|
|||
}
|
||||
|
||||
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<TurtleVM> = 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 []; },
|
||||
|
|
Loading…
Reference in New Issue