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>>>
|
<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 "sky" [] <skybox "textures/Daylight Box UV_0">>
|
||||||
|
|
||||||
<sprite "ground" []
|
<sprite "ground" []
|
||||||
|
@ -36,7 +36,7 @@
|
||||||
<box>>>>>>
|
<box>>>>>>
|
||||||
|
|
||||||
<sprite "t" []
|
<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>
|
<rotate <v 0.0 0.0 0.0>
|
||||||
<texture ["textures/pixar128/wall/Rattan_pxr128.jpg"]
|
<texture ["textures/pixar128/wall/Rattan_pxr128.jpg"]
|
||||||
<turtle [
|
<turtle [
|
||||||
|
@ -45,7 +45,7 @@
|
||||||
ClearPen
|
ClearPen
|
||||||
PenDown
|
PenDown
|
||||||
[
|
[
|
||||||
30 to lean
|
15 to lean
|
||||||
1 lean cos / to len
|
1 lean cos / to len
|
||||||
lean R
|
lean R
|
||||||
[len F 90 lean + L 0.1 F 90 lean - L] 2 times
|
[len F 90 lean + L 0.1 F 90 lean - L] 2 times
|
||||||
|
@ -59,35 +59,40 @@
|
||||||
|
|
||||||
[ to [f] PenDown f PenUp ] to draw
|
[ to [f] PenDown f PenUp ] to draw
|
||||||
|
|
||||||
4 to nSides
|
40 to nSides
|
||||||
360 nSides / to angle
|
360 nSides / to angle
|
||||||
20 nSides / to dist
|
20 nSides / to dist
|
||||||
|
|
||||||
[
|
[
|
||||||
angle R 0 F
|
angle R 0 F
|
||||||
[dist F angle R 0 F] nSides times
|
[dist F angle R 0 F] nSides 0.95 * times
|
||||||
angle L
|
angle L
|
||||||
] to plotArea
|
] to plotArea
|
||||||
|
|
||||||
Home
|
Home
|
||||||
ClearPen
|
ClearPen
|
||||||
|
90 R 0.05 B 90 L
|
||||||
|
PenDown 0.1 F DefinePen
|
||||||
|
Home
|
||||||
PenDown
|
PenDown
|
||||||
90 D
|
90 D
|
||||||
plotArea
|
0 F plotArea
|
||||||
DefinePen GetPen to floorPen
|
DefinePen GetPen to floorPen
|
||||||
Home
|
Home
|
||||||
|
|
||||||
Home
|
Home
|
||||||
[
|
[
|
||||||
floorPen SetPen
|
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
|
vPen SetPen
|
||||||
|
#t SetSmooth
|
||||||
quote plotArea draw 90 U 1 F 90 D
|
quote plotArea draw 90 U 1 F 90 D
|
||||||
|
#f SetSmooth
|
||||||
] 3 times
|
] 3 times
|
||||||
]>
|
]>
|
||||||
>>>>
|
>>>>
|
||||||
|
|
||||||
@<sprite "house" []
|
<sprite "house" []
|
||||||
<move <v 0.0 0.0 10.0>
|
<move <v 0.0 0.0 10.0>
|
||||||
<rotate <v 0.0 0.0 0.0>
|
<rotate <v 0.0 0.0 0.0>
|
||||||
<texture ["textures/oak-herringbone-5e80fb40b00c9-1200.jpg"]
|
<texture ["textures/oak-herringbone-5e80fb40b00c9-1200.jpg"]
|
||||||
|
@ -140,6 +145,10 @@
|
||||||
[ 90 L miter ] to --
|
[ 90 L miter ] to --
|
||||||
[ 90 R miter ] to ++
|
[ 90 R miter ] to ++
|
||||||
|
|
||||||
|
; [ Home 90 U 0.5 F 90 D ] to goHome
|
||||||
|
quote Home to goHome
|
||||||
|
goHome
|
||||||
|
|
||||||
exteriorWall
|
exteriorWall
|
||||||
--
|
--
|
||||||
[
|
[
|
||||||
|
@ -157,7 +166,7 @@
|
||||||
] draw
|
] draw
|
||||||
|
|
||||||
interiorWall
|
interiorWall
|
||||||
Home
|
goHome
|
||||||
2.1 F
|
2.1 F
|
||||||
[0.2 F [1 F] iDoor 6.5 F] draw
|
[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
|
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
|
[0.1 F [0.7 F] iDoor 0.2 F] draw
|
||||||
[-- [3.8 F] draw] saved
|
[-- [3.8 F] draw] saved
|
||||||
[0.9 F [0.6 F] iDoor 3.0 F] draw
|
[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
|
[0.2 F [0.7 F] iDoor 0.4 F] draw
|
||||||
[++ [1.7 F] draw] saved
|
[++ [1.7 F] draw] saved
|
||||||
[0.1 F [0.6 F] iDoor 0.2 F] draw
|
[0.1 F [0.6 F] iDoor 0.2 F] draw
|
||||||
|
|
|
@ -157,13 +157,9 @@
|
||||||
; [ R 0 F 60 D ] to rr
|
; [ R 0 F 60 D ] to rr
|
||||||
; [ 4 to k k / [dup R 0 F] k times drop ] to rr
|
; [ 4 to k k / [dup R 0 F] k times drop ] to rr
|
||||||
|
|
||||||
PenDown
|
|
||||||
60 to sides
|
60 to sides
|
||||||
[4 sides / ff 360 sides / rr] sides 2 / 2 - times
|
PenDown
|
||||||
1 0.5 1 PenScale 0 F
|
[4 sides / ff 360 sides / rr] sides times
|
||||||
[4 sides / ff 360 sides / rr] 4 times
|
|
||||||
1 1 1 PenScale 0 F
|
|
||||||
[4 sides / ff 360 sides / rr] sides 2 / 2 - times
|
|
||||||
PenUp
|
PenUp
|
||||||
]>>
|
]>>
|
||||||
<mesh <box>>
|
<mesh <box>>
|
||||||
|
|
|
@ -18,7 +18,6 @@ export class PenState {
|
||||||
templatePath: Vector3[] = [new Vector3()];
|
templatePath: Vector3[] = [new Vector3()];
|
||||||
paths: Vector3[][] | null = null;
|
paths: Vector3[][] | null = null;
|
||||||
directions: Quaternion[] | null = null;
|
directions: Quaternion[] | null = null;
|
||||||
templateScale = new Vector3(1, 1, 1);
|
|
||||||
|
|
||||||
get isDown(): boolean {
|
get isDown(): boolean {
|
||||||
return this.paths !== null;
|
return this.paths !== null;
|
||||||
|
@ -62,14 +61,14 @@ export class PenState {
|
||||||
if (d !== null) steps[steps.length - 1] = p.add(lastDir.scale(d));
|
if (d !== null) steps[steps.length - 1] = p.add(lastDir.scale(d));
|
||||||
}
|
}
|
||||||
this.templatePath.forEach((p, i) => {
|
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);
|
const d = pointDistance(r, thisDir, miterPlane);
|
||||||
if (d !== null) r.addInPlace(thisDir.scale(d));
|
if (d !== null) r.addInPlace(thisDir.scale(d));
|
||||||
paths[i].push(r);
|
paths[i].push(r);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
this.templatePath.forEach((p, i) => {
|
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);
|
paths[i].push(r);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -164,6 +163,10 @@ export class TurtleVM extends Cat.VM<TurtleVM> {
|
||||||
const pathCount = paths.length;
|
const pathCount = paths.length;
|
||||||
const stepCount = paths[0].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 pathIndex = 1; pathIndex < pathCount; pathIndex++) {
|
||||||
for (let stepIndex = 1; stepIndex < stepCount; stepIndex++) {
|
for (let stepIndex = 1; stepIndex < stepCount; stepIndex++) {
|
||||||
lines.push([paths[pathIndex - 1][stepIndex - 1],
|
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 meshName = this.container.name + this.counter++;
|
||||||
const ls = MeshBuilder.CreateLineSystem(meshName, { lines }, null);
|
const ls = MeshBuilder.CreateLineSystem(meshName, { lines }, null);
|
||||||
ls.parent = this.container;
|
ls.parent = this.container;
|
||||||
|
@ -238,18 +245,20 @@ export class TurtleVM extends Cat.VM<TurtleVM> {
|
||||||
|
|
||||||
const computePointIndex = this.smooth ? cachedPoint : pushPoint;
|
const computePointIndex = this.smooth ? cachedPoint : pushPoint;
|
||||||
|
|
||||||
function cap(stepIndex: number) {
|
const capIndices = this.cap === CapType.NONE
|
||||||
const capVerts = paths.flatMap(p => p[stepIndex].asArray());
|
? []
|
||||||
const capIndices = earcut(capVerts, void 0, 3);
|
: 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) {
|
for (let i = 0; i < capIndices.length; i += 3) {
|
||||||
indices.push(computePointIndex(capIndices[i+0], stepIndex),
|
indices.push(computePointIndex(capIndices[i+a], stepIndex),
|
||||||
computePointIndex(capIndices[i+1], stepIndex),
|
computePointIndex(capIndices[i+b], stepIndex),
|
||||||
computePointIndex(capIndices[i+2], stepIndex));
|
computePointIndex(capIndices[i+c], stepIndex));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.cap === CapType.START || this.cap === CapType.BOTH) {
|
if (this.cap === CapType.START || this.cap === CapType.BOTH) {
|
||||||
cap(0);
|
cap(0, 0, 1, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let pathIndex = 1; pathIndex < pathCount; pathIndex++) {
|
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) {
|
if (this.cap === CapType.END || this.cap === CapType.BOTH) {
|
||||||
cap(stepCount - 1);
|
cap(stepCount - 1, 2, 1, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
VertexData.ComputeNormals(positions, indices, normals);
|
VertexData.ComputeNormals(positions, indices, normals);
|
||||||
|
@ -339,10 +348,6 @@ export const TurtlePrimitives: Cat.Environment<TurtleVM> = Object.assign({}, Cat
|
||||||
return [];
|
return [];
|
||||||
},
|
},
|
||||||
|
|
||||||
'PenScale'(sx, sy, sz) {
|
|
||||||
this.pen.templateScale = new Vector3(sx as number, sy as number, sz as number);
|
|
||||||
return [];
|
|
||||||
},
|
|
||||||
'PenDown'() { this.penDown(); return []; },
|
'PenDown'() { this.penDown(); return []; },
|
||||||
'PenUp'() { this.penUp(false); return []; },
|
'PenUp'() { this.penUp(false); return []; },
|
||||||
'Close'() { this.penUp(true); return []; },
|
'Close'() { this.penUp(true); return []; },
|
||||||
|
|
Loading…
Reference in New Issue