@mulmoclaude/shapescript-plugin 1.4.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +65 -14
- package/dist/core/definition.d.ts.map +1 -1
- package/dist/{core-CpVzK-0i.js → core-BvTjfhU2.js} +2 -2
- package/dist/{core-bcFgqR_m.cjs → core-DZvhTmuk.cjs} +1 -1
- package/dist/core.cjs +1 -1
- package/dist/core.js +3 -3
- package/dist/index.cjs +1 -1
- package/dist/index.js +3 -3
- package/dist/render.cjs +1 -1
- package/dist/render.js +1 -1
- package/dist/{samples-DPOGWslc.js → samples-CXhuDdDd.js} +2 -2
- package/dist/{samples-DZNAeuSZ.cjs → samples-DGD0Kjwg.cjs} +86 -20
- package/dist/shapescript/evaluator.d.ts +27 -4
- package/dist/shapescript/evaluator.d.ts.map +1 -1
- package/dist/shapescript/parser.d.ts +18 -0
- package/dist/shapescript/parser.d.ts.map +1 -1
- package/dist/shapescript/toThreeJS.d.ts +42 -2
- package/dist/shapescript/toThreeJS.d.ts.map +1 -1
- package/dist/shapescript/types.d.ts +22 -4
- package/dist/shapescript/types.d.ts.map +1 -1
- package/dist/style.css +1 -1
- package/dist/{toThreeJS-BX_aeGdA.js → toThreeJS-FsP-Na75.js} +341 -284
- package/dist/toThreeJS-MvllBF9e.cjs +10 -0
- package/dist/vue/index.d.ts +1 -1
- package/dist/vue/index.d.ts.map +1 -1
- package/dist/vue.cjs +26 -7
- package/dist/vue.js +26 -7
- package/package.json +1 -1
- package/dist/toThreeJS-XGDoVISb.cjs +0 -10
|
@@ -17,7 +17,7 @@ function i(t) {
|
|
|
17
17
|
//#endregion
|
|
18
18
|
//#region src/shapescript/types.ts
|
|
19
19
|
var a = /* @__PURE__ */ function(e) {
|
|
20
|
-
return e.CUBE = "CUBE", e.SPHERE = "SPHERE", e.CYLINDER = "CYLINDER", e.CONE = "CONE", e.TORUS = "TORUS", e.CIRCLE = "CIRCLE", e.SQUARE = "SQUARE", e.POLYGON = "POLYGON", e.EXTRUDE = "EXTRUDE", e.LOFT = "LOFT", e.LATHE = "LATHE", e.FILL = "FILL", e.HULL = "HULL", e.GROUP = "GROUP", e.PATH = "PATH", e.POINT = "POINT", e.CURVE = "CURVE", e.DETAIL = "DETAIL", e.BACKGROUND = "BACKGROUND", e.TEXTURE = "TEXTURE", e.UNION = "UNION", e.DIFFERENCE = "DIFFERENCE", e.INTERSECTION = "INTERSECTION", e.XOR = "XOR", e.STENCIL = "STENCIL", e.FOR = "FOR", e.IN = "IN", e.TO = "TO", e.STEP = "STEP", e.IF = "IF", e.ELSE = "ELSE", e.SWITCH = "SWITCH", e.CASE = "CASE", e.DEFINE = "DEFINE", e.OPTION = "OPTION", e.POSITION = "POSITION", e.ROTATION = "ROTATION", e.ORIENTATION = "ORIENTATION", e.SIZE = "SIZE", e.COLOR = "COLOR", e.OPACITY = "OPACITY", e.ROTATE = "ROTATE", e.TRANSLATE = "TRANSLATE", e.SCALE = "SCALE", e.NUMBER = "NUMBER", e.IDENTIFIER = "IDENTIFIER", e.STRING = "STRING", e.PLUS = "PLUS", e.MINUS = "MINUS", e.STAR = "STAR", e.DIVIDE = "DIVIDE", e.PERCENT = "PERCENT", e.LPAREN = "LPAREN", e.RPAREN = "RPAREN", e.LBRACKET = "LBRACKET", e.RBRACKET = "RBRACKET", e.DOT = "DOT", e.EQUALS = "EQUALS", e.NOT_EQUALS = "NOT_EQUALS", e.LESS = "LESS", e.LESS_EQUAL = "LESS_EQUAL", e.GREATER = "GREATER", e.GREATER_EQUAL = "GREATER_EQUAL", e.AND = "AND", e.OR = "OR", e.NOT = "NOT", e.LBRACE = "LBRACE", e.RBRACE = "RBRACE", e.COMMA = "COMMA", e.SLASH = "SLASH", e.NEWLINE = "NEWLINE", e.EOF = "EOF", e.COMMENT = "COMMENT", e;
|
|
20
|
+
return e.CUBE = "CUBE", e.SPHERE = "SPHERE", e.CYLINDER = "CYLINDER", e.CONE = "CONE", e.TORUS = "TORUS", e.CIRCLE = "CIRCLE", e.SQUARE = "SQUARE", e.POLYGON = "POLYGON", e.EXTRUDE = "EXTRUDE", e.LOFT = "LOFT", e.LATHE = "LATHE", e.FILL = "FILL", e.HULL = "HULL", e.GROUP = "GROUP", e.PATH = "PATH", e.POINT = "POINT", e.CURVE = "CURVE", e.DETAIL = "DETAIL", e.SEED = "SEED", e.BACKGROUND = "BACKGROUND", e.TEXTURE = "TEXTURE", e.UNION = "UNION", e.DIFFERENCE = "DIFFERENCE", e.INTERSECTION = "INTERSECTION", e.XOR = "XOR", e.STENCIL = "STENCIL", e.FOR = "FOR", e.IN = "IN", e.TO = "TO", e.STEP = "STEP", e.IF = "IF", e.ELSE = "ELSE", e.SWITCH = "SWITCH", e.CASE = "CASE", e.DEFINE = "DEFINE", e.OPTION = "OPTION", e.POSITION = "POSITION", e.ROTATION = "ROTATION", e.ORIENTATION = "ORIENTATION", e.SIZE = "SIZE", e.COLOR = "COLOR", e.OPACITY = "OPACITY", e.ROTATE = "ROTATE", e.TRANSLATE = "TRANSLATE", e.SCALE = "SCALE", e.NUMBER = "NUMBER", e.IDENTIFIER = "IDENTIFIER", e.STRING = "STRING", e.PLUS = "PLUS", e.MINUS = "MINUS", e.STAR = "STAR", e.DIVIDE = "DIVIDE", e.PERCENT = "PERCENT", e.LPAREN = "LPAREN", e.RPAREN = "RPAREN", e.LBRACKET = "LBRACKET", e.RBRACKET = "RBRACKET", e.DOT = "DOT", e.EQUALS = "EQUALS", e.NOT_EQUALS = "NOT_EQUALS", e.LESS = "LESS", e.LESS_EQUAL = "LESS_EQUAL", e.GREATER = "GREATER", e.GREATER_EQUAL = "GREATER_EQUAL", e.AND = "AND", e.OR = "OR", e.NOT = "NOT", e.LBRACE = "LBRACE", e.RBRACE = "RBRACE", e.COMMA = "COMMA", e.SLASH = "SLASH", e.NEWLINE = "NEWLINE", e.EOF = "EOF", e.COMMENT = "COMMENT", e;
|
|
21
21
|
}({}), o = class extends Error {
|
|
22
22
|
line;
|
|
23
23
|
column;
|
|
@@ -92,6 +92,7 @@ var a = /* @__PURE__ */ function(e) {
|
|
|
92
92
|
point: a.POINT,
|
|
93
93
|
curve: a.CURVE,
|
|
94
94
|
detail: a.DETAIL,
|
|
95
|
+
seed: a.SEED,
|
|
95
96
|
background: a.BACKGROUND,
|
|
96
97
|
texture: a.TEXTURE,
|
|
97
98
|
union: a.UNION,
|
|
@@ -429,8 +430,8 @@ var a = /* @__PURE__ */ function(e) {
|
|
|
429
430
|
if (this.advance(), this.current().type === a.LPAREN && !this.current().precedingWhitespace) {
|
|
430
431
|
this.advance();
|
|
431
432
|
let e = [];
|
|
432
|
-
return this.withValueList(!
|
|
433
|
-
|
|
433
|
+
return this.withValueList(!0, () => {
|
|
434
|
+
this.current().type !== a.RPAREN && (e.push(this.parseExpression()), this.current().type === a.COMMA ? this.parseCommaSeparated(e) : this.parseSpaceSeparated(e));
|
|
434
435
|
}), this.expect(a.RPAREN), {
|
|
435
436
|
type: "call",
|
|
436
437
|
name: t,
|
|
@@ -710,6 +711,12 @@ var a = /* @__PURE__ */ function(e) {
|
|
|
710
711
|
value: this.parseExpression()
|
|
711
712
|
};
|
|
712
713
|
}
|
|
714
|
+
parseSeed() {
|
|
715
|
+
return this.advance(), {
|
|
716
|
+
type: "seed",
|
|
717
|
+
value: this.parseExpression()
|
|
718
|
+
};
|
|
719
|
+
}
|
|
713
720
|
parseBackground() {
|
|
714
721
|
return this.advance(), {
|
|
715
722
|
type: "background",
|
|
@@ -795,147 +802,99 @@ var a = /* @__PURE__ */ function(e) {
|
|
|
795
802
|
return this.withValueList(!0, () => this.parseExpression());
|
|
796
803
|
}
|
|
797
804
|
parsePath() {
|
|
798
|
-
this.advance()
|
|
799
|
-
let e =
|
|
805
|
+
this.advance();
|
|
806
|
+
let e = {}, t = this.parsePathBody("path", e);
|
|
807
|
+
return Object.keys(e).length === 0 ? {
|
|
808
|
+
type: "path",
|
|
809
|
+
commands: t
|
|
810
|
+
} : {
|
|
811
|
+
type: "path",
|
|
812
|
+
commands: t,
|
|
813
|
+
properties: e
|
|
814
|
+
};
|
|
815
|
+
}
|
|
816
|
+
parsePathBody(e, t) {
|
|
817
|
+
this.expect(a.LBRACE), this.skipNewlines();
|
|
818
|
+
let n = [];
|
|
800
819
|
for (; this.current().type !== a.RBRACE && this.current().type !== a.EOF;) {
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
e.push(this.parseDefine());
|
|
805
|
-
break;
|
|
806
|
-
case a.DETAIL: {
|
|
807
|
-
this.advance();
|
|
808
|
-
let t = this.parseExpression();
|
|
809
|
-
e.push({
|
|
810
|
-
type: "detail",
|
|
811
|
-
value: t
|
|
812
|
-
});
|
|
813
|
-
break;
|
|
814
|
-
}
|
|
815
|
-
case a.POINT: {
|
|
816
|
-
this.advance();
|
|
817
|
-
let t = this.parsePathValue(), n = {
|
|
818
|
-
type: "number",
|
|
819
|
-
value: 0
|
|
820
|
-
};
|
|
821
|
-
this.startsValue() && (n = this.parsePathValue()), e.push({
|
|
822
|
-
type: "point",
|
|
823
|
-
x: t,
|
|
824
|
-
y: n
|
|
825
|
-
});
|
|
826
|
-
break;
|
|
827
|
-
}
|
|
828
|
-
case a.CURVE: {
|
|
829
|
-
this.advance();
|
|
830
|
-
let t = this.parsePathValue(), n = this.parsePathValue(), r, i;
|
|
831
|
-
this.startsValue() && (r = this.parsePathValue(), this.startsValue() && (i = this.parsePathValue())), e.push({
|
|
832
|
-
type: "curve",
|
|
833
|
-
x: t,
|
|
834
|
-
y: n,
|
|
835
|
-
...r === void 0 ? {} : { controlX: r },
|
|
836
|
-
...i === void 0 ? {} : { controlY: i }
|
|
837
|
-
});
|
|
838
|
-
break;
|
|
839
|
-
}
|
|
840
|
-
case a.ROTATE: {
|
|
841
|
-
this.advance();
|
|
842
|
-
let t = this.parseExpression();
|
|
843
|
-
e.push({
|
|
844
|
-
type: "rotate",
|
|
845
|
-
angle: t
|
|
846
|
-
});
|
|
847
|
-
break;
|
|
848
|
-
}
|
|
849
|
-
case a.TRANSLATE: {
|
|
850
|
-
this.advance();
|
|
851
|
-
let t = this.parsePathValue(), n = this.parsePathValue();
|
|
852
|
-
e.push({
|
|
853
|
-
type: "translate",
|
|
854
|
-
x: t,
|
|
855
|
-
y: n
|
|
856
|
-
});
|
|
857
|
-
break;
|
|
858
|
-
}
|
|
859
|
-
case a.FOR: {
|
|
860
|
-
this.advance();
|
|
861
|
-
let t = "_i";
|
|
862
|
-
this.current().type === a.IDENTIFIER && this.peek(1).type === a.IN && (t = this.current().value, this.advance(), this.expect(a.IN));
|
|
863
|
-
let n = this.parseExpression();
|
|
864
|
-
this.expect(a.TO);
|
|
865
|
-
let r = this.parseExpression(), i = this.current().type === a.STEP ? (this.advance(), this.parseExpression()) : {
|
|
866
|
-
type: "number",
|
|
867
|
-
value: 1
|
|
868
|
-
};
|
|
869
|
-
this.expect(a.LBRACE), this.skipNewlines();
|
|
870
|
-
let s = [];
|
|
871
|
-
for (; this.current().type !== a.RBRACE && this.current().type !== a.EOF;) {
|
|
872
|
-
let e = this.current();
|
|
873
|
-
switch (e.type) {
|
|
874
|
-
case a.POINT: {
|
|
875
|
-
this.advance();
|
|
876
|
-
let e = this.parsePathValue(), t = {
|
|
877
|
-
type: "number",
|
|
878
|
-
value: 0
|
|
879
|
-
};
|
|
880
|
-
this.startsValue() && (t = this.parsePathValue()), s.push({
|
|
881
|
-
type: "point",
|
|
882
|
-
x: e,
|
|
883
|
-
y: t
|
|
884
|
-
});
|
|
885
|
-
break;
|
|
886
|
-
}
|
|
887
|
-
case a.CURVE: {
|
|
888
|
-
this.advance();
|
|
889
|
-
let e = this.parsePathValue(), t = this.parsePathValue(), n, r;
|
|
890
|
-
this.startsValue() && (n = this.parsePathValue(), this.startsValue() && (r = this.parsePathValue())), s.push({
|
|
891
|
-
type: "curve",
|
|
892
|
-
x: e,
|
|
893
|
-
y: t,
|
|
894
|
-
...n === void 0 ? {} : { controlX: n },
|
|
895
|
-
...r === void 0 ? {} : { controlY: r }
|
|
896
|
-
});
|
|
897
|
-
break;
|
|
898
|
-
}
|
|
899
|
-
case a.ROTATE: {
|
|
900
|
-
this.advance();
|
|
901
|
-
let e = this.parseExpression();
|
|
902
|
-
s.push({
|
|
903
|
-
type: "rotate",
|
|
904
|
-
angle: e
|
|
905
|
-
});
|
|
906
|
-
break;
|
|
907
|
-
}
|
|
908
|
-
case a.TRANSLATE: {
|
|
909
|
-
this.advance();
|
|
910
|
-
let e = this.parsePathValue(), t = this.parsePathValue();
|
|
911
|
-
s.push({
|
|
912
|
-
type: "translate",
|
|
913
|
-
x: e,
|
|
914
|
-
y: t
|
|
915
|
-
});
|
|
916
|
-
break;
|
|
917
|
-
}
|
|
918
|
-
default: throw new o(`Unexpected token in path for loop: ${e.type}`, e.line, e.column);
|
|
919
|
-
}
|
|
920
|
-
this.skipNewlines();
|
|
921
|
-
}
|
|
922
|
-
this.expect(a.RBRACE), e.push({
|
|
923
|
-
type: "for",
|
|
924
|
-
variable: t,
|
|
925
|
-
from: n,
|
|
926
|
-
to: r,
|
|
927
|
-
step: i,
|
|
928
|
-
commands: s
|
|
929
|
-
});
|
|
930
|
-
break;
|
|
931
|
-
}
|
|
932
|
-
default: throw new o(`Unexpected token in path: ${t.type}`, t.line, t.column);
|
|
820
|
+
if (t !== void 0 && this.parsePathProperty(t)) {
|
|
821
|
+
this.skipNewlines();
|
|
822
|
+
continue;
|
|
933
823
|
}
|
|
934
|
-
this.skipNewlines();
|
|
824
|
+
n.push(this.parsePathCommand(e)), this.skipNewlines();
|
|
935
825
|
}
|
|
936
|
-
return this.expect(a.RBRACE),
|
|
937
|
-
|
|
938
|
-
|
|
826
|
+
return this.expect(a.RBRACE), n;
|
|
827
|
+
}
|
|
828
|
+
parsePathProperty(e) {
|
|
829
|
+
let t = this.current().type, n = t === a.POSITION ? "position" : t === a.SIZE ? "size" : t === a.ORIENTATION || t === a.ROTATION ? "orientation" : void 0;
|
|
830
|
+
return n !== void 0 && (this.advance(), e[n] = this.parseVectorOrExpression(), !0);
|
|
831
|
+
}
|
|
832
|
+
parsePathCommand(e) {
|
|
833
|
+
let t = this.current();
|
|
834
|
+
switch (t.type) {
|
|
835
|
+
case a.DEFINE: return this.parseDefine();
|
|
836
|
+
case a.DETAIL: return this.advance(), {
|
|
837
|
+
type: "detail",
|
|
838
|
+
value: this.parseExpression()
|
|
839
|
+
};
|
|
840
|
+
case a.POINT:
|
|
841
|
+
case a.CURVE: return this.parsePathPoint(t.type === a.POINT ? "point" : "curve");
|
|
842
|
+
case a.ROTATE: return this.advance(), {
|
|
843
|
+
type: "rotate",
|
|
844
|
+
angle: this.parseExpression()
|
|
845
|
+
};
|
|
846
|
+
case a.TRANSLATE:
|
|
847
|
+
case a.SCALE: return this.parsePathVector(t.type === a.TRANSLATE ? "translate" : "scale");
|
|
848
|
+
case a.FOR: return this.parsePathFor();
|
|
849
|
+
default: throw new o(`Unexpected token in ${e}: ${t.type}`, t.line, t.column);
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
parsePathPoint(e) {
|
|
853
|
+
return this.advance(), {
|
|
854
|
+
type: e,
|
|
855
|
+
x: this.parsePathValue(),
|
|
856
|
+
y: this.startsValue() ? this.parsePathValue() : {
|
|
857
|
+
type: "number",
|
|
858
|
+
value: 0
|
|
859
|
+
}
|
|
860
|
+
};
|
|
861
|
+
}
|
|
862
|
+
parsePathVector(e) {
|
|
863
|
+
this.advance();
|
|
864
|
+
let t = this.parsePathValue();
|
|
865
|
+
return e === "scale" ? this.startsValue() ? {
|
|
866
|
+
type: e,
|
|
867
|
+
x: t,
|
|
868
|
+
y: this.parsePathValue()
|
|
869
|
+
} : {
|
|
870
|
+
type: e,
|
|
871
|
+
x: t
|
|
872
|
+
} : {
|
|
873
|
+
type: e,
|
|
874
|
+
x: t,
|
|
875
|
+
y: this.startsValue() ? this.parsePathValue() : {
|
|
876
|
+
type: "number",
|
|
877
|
+
value: 0
|
|
878
|
+
}
|
|
879
|
+
};
|
|
880
|
+
}
|
|
881
|
+
parsePathFor() {
|
|
882
|
+
this.advance();
|
|
883
|
+
let e = "_i";
|
|
884
|
+
this.current().type === a.IDENTIFIER && this.peek(1).type === a.IN && (e = this.current().value, this.advance(), this.expect(a.IN));
|
|
885
|
+
let t = this.parseExpression();
|
|
886
|
+
this.expect(a.TO);
|
|
887
|
+
let n = this.parseExpression(), r = this.current().type === a.STEP ? (this.advance(), this.parseExpression()) : {
|
|
888
|
+
type: "number",
|
|
889
|
+
value: 1
|
|
890
|
+
};
|
|
891
|
+
return {
|
|
892
|
+
type: "for",
|
|
893
|
+
variable: e,
|
|
894
|
+
from: t,
|
|
895
|
+
to: n,
|
|
896
|
+
step: r,
|
|
897
|
+
commands: this.parsePathBody("path for loop")
|
|
939
898
|
};
|
|
940
899
|
}
|
|
941
900
|
parseNode() {
|
|
@@ -986,6 +945,7 @@ var a = /* @__PURE__ */ function(e) {
|
|
|
986
945
|
case a.DEFINE: return this.parseDefine();
|
|
987
946
|
case a.GROUP: return this.parseGroup();
|
|
988
947
|
case a.DETAIL: return this.parseDetail();
|
|
948
|
+
case a.SEED: return this.parseSeed();
|
|
989
949
|
case a.BACKGROUND: return this.parseBackground();
|
|
990
950
|
case a.TEXTURE: return this.parseTexture();
|
|
991
951
|
case a.PATH: return this.parsePath();
|
|
@@ -11372,10 +11332,26 @@ var vp = class {
|
|
|
11372
11332
|
reset() {
|
|
11373
11333
|
this.triangleSplitter.reset();
|
|
11374
11334
|
}
|
|
11375
|
-
}, yp = class {
|
|
11335
|
+
}, yp = class e {
|
|
11336
|
+
static MODULUS = 4294967296;
|
|
11337
|
+
state;
|
|
11338
|
+
constructor(t) {
|
|
11339
|
+
this.state = e.wrap(t);
|
|
11340
|
+
}
|
|
11341
|
+
static wrap(t) {
|
|
11342
|
+
let n = t % e.MODULUS;
|
|
11343
|
+
return Number.isFinite(n) ? n < 0 ? n + e.MODULUS : n : 0;
|
|
11344
|
+
}
|
|
11345
|
+
next() {
|
|
11346
|
+
return this.state = e.wrap(this.state * 1664525 + 1013904223), this.state / e.MODULUS;
|
|
11347
|
+
}
|
|
11348
|
+
}, bp = class {
|
|
11376
11349
|
scopes = [];
|
|
11377
|
-
constructor() {
|
|
11378
|
-
this.
|
|
11350
|
+
constructor(e = 0) {
|
|
11351
|
+
this.scopes.push({
|
|
11352
|
+
values: /* @__PURE__ */ new Map(),
|
|
11353
|
+
random: new yp(e)
|
|
11354
|
+
});
|
|
11379
11355
|
for (let [e, t] of Object.entries({
|
|
11380
11356
|
pi: Math.PI,
|
|
11381
11357
|
tau: 2 * Math.PI,
|
|
@@ -11383,36 +11359,48 @@ var vp = class {
|
|
|
11383
11359
|
false: !1
|
|
11384
11360
|
})) this.set(e, t);
|
|
11385
11361
|
}
|
|
11362
|
+
innermost() {
|
|
11363
|
+
let e = this.scopes[this.scopes.length - 1];
|
|
11364
|
+
if (e === void 0) throw Error("SymbolTable has no active scope");
|
|
11365
|
+
return e;
|
|
11366
|
+
}
|
|
11386
11367
|
pushScope() {
|
|
11387
|
-
this.scopes.push(
|
|
11368
|
+
this.scopes.push({
|
|
11369
|
+
values: /* @__PURE__ */ new Map(),
|
|
11370
|
+
random: this.innermost().random
|
|
11371
|
+
});
|
|
11388
11372
|
}
|
|
11389
11373
|
popScope() {
|
|
11390
11374
|
this.scopes.length > 1 && this.scopes.pop();
|
|
11391
11375
|
}
|
|
11376
|
+
reseed(e) {
|
|
11377
|
+
this.innermost().random = new yp(e);
|
|
11378
|
+
}
|
|
11379
|
+
nextRandom() {
|
|
11380
|
+
return this.innermost().random.next();
|
|
11381
|
+
}
|
|
11392
11382
|
set(e, t) {
|
|
11393
|
-
|
|
11394
|
-
if (n === void 0) throw Error("SymbolTable has no active scope");
|
|
11395
|
-
n.set(e, t);
|
|
11383
|
+
this.innermost().values.set(e, t);
|
|
11396
11384
|
}
|
|
11397
11385
|
get(e) {
|
|
11398
11386
|
for (let t = this.scopes.length - 1; t >= 0; t--) {
|
|
11399
11387
|
let n = this.scopes[t];
|
|
11400
|
-
if (n?.has(e)) return n.get(e);
|
|
11388
|
+
if (n?.values.has(e)) return n.values.get(e);
|
|
11401
11389
|
}
|
|
11402
11390
|
}
|
|
11403
11391
|
has(e) {
|
|
11404
11392
|
return this.get(e) !== void 0;
|
|
11405
11393
|
}
|
|
11406
11394
|
};
|
|
11407
|
-
function
|
|
11395
|
+
function xp(e) {
|
|
11408
11396
|
let t = 0;
|
|
11409
|
-
for (let n of
|
|
11397
|
+
for (let n of Ep(e)) {
|
|
11410
11398
|
let e = $(n);
|
|
11411
11399
|
t += e * e;
|
|
11412
11400
|
}
|
|
11413
11401
|
return Math.sqrt(t);
|
|
11414
11402
|
}
|
|
11415
|
-
var
|
|
11403
|
+
var Sp = {
|
|
11416
11404
|
x: 0,
|
|
11417
11405
|
y: 1,
|
|
11418
11406
|
z: 2,
|
|
@@ -11425,7 +11413,27 @@ var xp = {
|
|
|
11425
11413
|
green: 1,
|
|
11426
11414
|
blue: 2,
|
|
11427
11415
|
alpha: 3
|
|
11428
|
-
},
|
|
11416
|
+
}, Cp = {
|
|
11417
|
+
first: 0,
|
|
11418
|
+
second: 1,
|
|
11419
|
+
third: 2,
|
|
11420
|
+
fourth: 3,
|
|
11421
|
+
fifth: 4,
|
|
11422
|
+
sixth: 5,
|
|
11423
|
+
seventh: 6,
|
|
11424
|
+
eighth: 7,
|
|
11425
|
+
ninth: 8,
|
|
11426
|
+
tenth: 9
|
|
11427
|
+
};
|
|
11428
|
+
function wp(e, t) {
|
|
11429
|
+
if (t === "count") return e.length;
|
|
11430
|
+
if (t === "last") return e.length > 0 ? e[e.length - 1] : void 0;
|
|
11431
|
+
if (t === "allButFirst") return e.slice(1);
|
|
11432
|
+
if (t === "allButLast") return e.slice(0, -1);
|
|
11433
|
+
let n = Cp[t] ?? (Array.isArray(e) ? Sp[t] : void 0);
|
|
11434
|
+
return n !== void 0 && n < e.length ? e[n] : void 0;
|
|
11435
|
+
}
|
|
11436
|
+
var Tp = {
|
|
11429
11437
|
round: (e) => Math.round($(e)),
|
|
11430
11438
|
floor: (e) => Math.floor($(e)),
|
|
11431
11439
|
ceil: (e) => Math.ceil($(e)),
|
|
@@ -11443,12 +11451,12 @@ var xp = {
|
|
|
11443
11451
|
atan: (e) => Math.atan($(e)),
|
|
11444
11452
|
atan2: (e, t) => Math.atan2($(e), $(t)),
|
|
11445
11453
|
dot: (e, t) => {
|
|
11446
|
-
let n =
|
|
11454
|
+
let n = Ep(e), r = Ep(t), i = 0;
|
|
11447
11455
|
for (let e = 0; e < Math.min(n.length, r.length); e++) i += $(n[e]) * $(r[e]);
|
|
11448
11456
|
return i;
|
|
11449
11457
|
},
|
|
11450
11458
|
cross: (e, t) => {
|
|
11451
|
-
let n =
|
|
11459
|
+
let n = Ep(e), r = Ep(t);
|
|
11452
11460
|
if (n.length < 3 || r.length < 3) throw Error("cross product requires 3D vectors");
|
|
11453
11461
|
let i = $(n[0]), a = $(n[1]), o = $(n[2]), s = $(r[0]), c = $(r[1]), l = $(r[2]);
|
|
11454
11462
|
return [
|
|
@@ -11457,12 +11465,12 @@ var xp = {
|
|
|
11457
11465
|
i * c - a * s
|
|
11458
11466
|
];
|
|
11459
11467
|
},
|
|
11460
|
-
length: (e) =>
|
|
11468
|
+
length: (e) => xp(e),
|
|
11461
11469
|
normalize: (e) => {
|
|
11462
|
-
let t =
|
|
11470
|
+
let t = Ep(e), n = xp(e);
|
|
11463
11471
|
return n === 0 ? t : t.map((e) => $(e) / n);
|
|
11464
11472
|
},
|
|
11465
|
-
sum: (e) =>
|
|
11473
|
+
sum: (e) => Ep(e).reduce((e, t) => e + $(t), 0),
|
|
11466
11474
|
join: (...e) => {
|
|
11467
11475
|
let t = e.length > 0 && typeof e[e.length - 1] == "string" ? e.pop() : "";
|
|
11468
11476
|
return e.flat().map(String).join(t);
|
|
@@ -11481,26 +11489,23 @@ function $(e) {
|
|
|
11481
11489
|
if (Array.isArray(e) && e.length > 0) return $(e[0]);
|
|
11482
11490
|
throw Error(`Cannot convert ${typeof e} to number`);
|
|
11483
11491
|
}
|
|
11484
|
-
function
|
|
11492
|
+
function Ep(e) {
|
|
11485
11493
|
return Array.isArray(e) ? e : [e];
|
|
11486
11494
|
}
|
|
11487
|
-
function
|
|
11495
|
+
function Dp(e) {
|
|
11488
11496
|
return typeof e == "boolean" ? e : typeof e == "number" ? e !== 0 : typeof e == "string" || Array.isArray(e) ? e.length > 0 : !1;
|
|
11489
11497
|
}
|
|
11490
|
-
var
|
|
11491
|
-
function Ep(e) {
|
|
11492
|
-
let t = e >>> 0;
|
|
11493
|
-
return () => {
|
|
11494
|
-
t = t + 1831565813 >>> 0;
|
|
11495
|
-
let e = t;
|
|
11496
|
-
return e = Math.imul(e ^ e >>> 15, e | 1), e ^= e + Math.imul(e ^ e >>> 7, e | 61), ((e ^ e >>> 14) >>> 0) / 4294967296;
|
|
11497
|
-
};
|
|
11498
|
-
}
|
|
11499
|
-
var Dp = class {
|
|
11498
|
+
var Op = class {
|
|
11500
11499
|
symbols;
|
|
11501
|
-
|
|
11502
|
-
|
|
11503
|
-
|
|
11500
|
+
constructor(e, t) {
|
|
11501
|
+
this.symbols = e || new bp(t), t !== void 0 && this.symbols.reseed(t);
|
|
11502
|
+
}
|
|
11503
|
+
random() {
|
|
11504
|
+
return this.symbols.nextRandom();
|
|
11505
|
+
}
|
|
11506
|
+
reseed(e) {
|
|
11507
|
+
if (!Number.isFinite(e)) throw Error("`seed` needs a finite number");
|
|
11508
|
+
this.symbols.reseed(e);
|
|
11504
11509
|
}
|
|
11505
11510
|
getSymbols() {
|
|
11506
11511
|
return this.symbols;
|
|
@@ -11518,8 +11523,8 @@ var Dp = class {
|
|
|
11518
11523
|
}
|
|
11519
11524
|
case "binary": {
|
|
11520
11525
|
let t = this.evaluate(e.left);
|
|
11521
|
-
if (e.operator === "and" && !
|
|
11522
|
-
if (e.operator === "or" &&
|
|
11526
|
+
if (e.operator === "and" && !Dp(t)) return !1;
|
|
11527
|
+
if (e.operator === "or" && Dp(t)) return !0;
|
|
11523
11528
|
let n = this.evaluate(e.right);
|
|
11524
11529
|
switch (e.operator) {
|
|
11525
11530
|
case "+":
|
|
@@ -11569,8 +11574,8 @@ var Dp = class {
|
|
|
11569
11574
|
case "<=": return $(t) <= $(n);
|
|
11570
11575
|
case ">": return $(t) > $(n);
|
|
11571
11576
|
case ">=": return $(t) >= $(n);
|
|
11572
|
-
case "and": return
|
|
11573
|
-
case "or": return
|
|
11577
|
+
case "and": return Dp(t) && Dp(n);
|
|
11578
|
+
case "or": return Dp(t) || Dp(n);
|
|
11574
11579
|
default: throw Error(`Unknown binary operator: ${e.operator}`);
|
|
11575
11580
|
}
|
|
11576
11581
|
}
|
|
@@ -11579,24 +11584,22 @@ var Dp = class {
|
|
|
11579
11584
|
switch (e.operator) {
|
|
11580
11585
|
case "+": return Array.isArray(t) ? t.map($) : $(t);
|
|
11581
11586
|
case "-": return Array.isArray(t) ? t.map((e) => -$(e)) : -$(t);
|
|
11582
|
-
case "not": return !
|
|
11587
|
+
case "not": return !Dp(t);
|
|
11583
11588
|
default: throw Error(`Unknown unary operator: ${e.operator}`);
|
|
11584
11589
|
}
|
|
11585
11590
|
}
|
|
11586
11591
|
case "call": {
|
|
11587
11592
|
let t = e.name.toLowerCase();
|
|
11588
11593
|
if (t === "rand") return this.random();
|
|
11589
|
-
let n = Object.prototype.hasOwnProperty.call(
|
|
11594
|
+
let n = Object.prototype.hasOwnProperty.call(Tp, t) ? Tp[t] : void 0;
|
|
11590
11595
|
if (!n) throw Error(`Unknown function: ${e.name}`);
|
|
11591
11596
|
return n(...e.args.map((e) => this.evaluate(e)));
|
|
11592
11597
|
}
|
|
11593
11598
|
case "tuple": return e.elements.map((e) => this.evaluate(e));
|
|
11594
11599
|
case "member": {
|
|
11595
|
-
let t = this.evaluate(e.object);
|
|
11596
|
-
if (
|
|
11597
|
-
|
|
11598
|
-
if (Object.hasOwn(xp, e.member) && n !== void 0 && Array.isArray(t) && n < t.length) return t[n];
|
|
11599
|
-
throw Error(`Unknown member: ${e.member}`);
|
|
11600
|
+
let t = this.evaluate(e.object), n = Array.isArray(t) || typeof t == "string" ? wp(t, e.member) : void 0;
|
|
11601
|
+
if (n === void 0) throw Error(`Unknown member: ${e.member}`);
|
|
11602
|
+
return n;
|
|
11600
11603
|
}
|
|
11601
11604
|
case "subscript": {
|
|
11602
11605
|
let t = this.evaluate(e.object), n = this.evaluate(e.index);
|
|
@@ -11611,7 +11614,7 @@ var Dp = class {
|
|
|
11611
11614
|
return $(this.evaluate(e));
|
|
11612
11615
|
}
|
|
11613
11616
|
evaluateToBoolean(e) {
|
|
11614
|
-
return
|
|
11617
|
+
return Dp(this.evaluate(e));
|
|
11615
11618
|
}
|
|
11616
11619
|
evaluateToVector3(e) {
|
|
11617
11620
|
if (Array.isArray(e) && typeof e[0] == "number") return e;
|
|
@@ -11646,48 +11649,61 @@ var Dp = class {
|
|
|
11646
11649
|
};
|
|
11647
11650
|
//#endregion
|
|
11648
11651
|
//#region src/shapescript/dispose.ts
|
|
11649
|
-
function
|
|
11652
|
+
function kp() {
|
|
11650
11653
|
return {
|
|
11651
11654
|
geometries: /* @__PURE__ */ new Set(),
|
|
11652
11655
|
materials: /* @__PURE__ */ new Set(),
|
|
11653
11656
|
textures: /* @__PURE__ */ new Set()
|
|
11654
11657
|
};
|
|
11655
11658
|
}
|
|
11656
|
-
function
|
|
11659
|
+
function Ap(e) {
|
|
11657
11660
|
let { material: t } = e;
|
|
11658
11661
|
return Array.isArray(t) ? t : t?.isMaterial ? [t] : [];
|
|
11659
11662
|
}
|
|
11660
|
-
function
|
|
11663
|
+
function jp(e, t) {
|
|
11661
11664
|
return e.traverse((e) => {
|
|
11662
11665
|
let n = e;
|
|
11663
11666
|
n.geometry?.isBufferGeometry && t.geometries.add(n.geometry);
|
|
11664
|
-
for (let e of
|
|
11667
|
+
for (let e of Ap(n)) {
|
|
11665
11668
|
t.materials.add(e);
|
|
11666
11669
|
for (let n of Object.values(e)) n && n.isTexture && t.textures.add(n);
|
|
11667
11670
|
}
|
|
11668
11671
|
}), t;
|
|
11669
11672
|
}
|
|
11670
|
-
function
|
|
11673
|
+
function Mp(e, t) {
|
|
11671
11674
|
for (let n of e.geometries) t.geometries.has(n) || n.dispose();
|
|
11672
11675
|
for (let n of e.textures) t.textures.has(n) || n.dispose();
|
|
11673
11676
|
for (let n of e.materials) t.materials.has(n) || n.dispose();
|
|
11674
11677
|
}
|
|
11675
|
-
function
|
|
11676
|
-
jp(
|
|
11677
|
-
}
|
|
11678
|
-
function Np(e, t) {
|
|
11679
|
-
let n = Ap(t, Op()), r = Op();
|
|
11680
|
-
for (let n of e) n !== t && Ap(n, r);
|
|
11681
|
-
jp(r, n);
|
|
11678
|
+
function Np(e) {
|
|
11679
|
+
Mp(jp(e, kp()), kp());
|
|
11682
11680
|
}
|
|
11683
11681
|
function Pp(e, t) {
|
|
11684
|
-
|
|
11682
|
+
let n = jp(t, kp()), r = kp();
|
|
11683
|
+
for (let n of e) n !== t && jp(n, r);
|
|
11684
|
+
Mp(r, n);
|
|
11685
11685
|
}
|
|
11686
|
-
|
|
11686
|
+
function Fp(e, t) {
|
|
11687
|
+
t && (e?.remove(t), Np(t));
|
|
11688
|
+
}
|
|
11689
|
+
//#endregion
|
|
11690
|
+
//#region src/shapescript/toThreeJS.ts
|
|
11691
|
+
var Ip = 1e-9;
|
|
11692
|
+
function Lp(e, t) {
|
|
11693
|
+
return Math.abs(e.x - t.x) < Ip && Math.abs(e.y - t.y) < Ip;
|
|
11694
|
+
}
|
|
11695
|
+
function Rp(e, t) {
|
|
11696
|
+
return {
|
|
11697
|
+
x: (e.x + t.x) / 2,
|
|
11698
|
+
y: (e.y + t.y) / 2,
|
|
11699
|
+
curved: !1
|
|
11700
|
+
};
|
|
11701
|
+
}
|
|
11702
|
+
var zp = 3e4, Bp = 12, Vp = 4, Hp = 1e-9, Up = class extends Error {
|
|
11687
11703
|
constructor(e) {
|
|
11688
11704
|
super(e), this.name = "ShapeScriptLimitError";
|
|
11689
11705
|
}
|
|
11690
|
-
},
|
|
11706
|
+
}, Wp = class {
|
|
11691
11707
|
options;
|
|
11692
11708
|
evaluator;
|
|
11693
11709
|
symbols;
|
|
@@ -11698,14 +11714,14 @@ var Fp = 3e4, Ip = 12, Lp = 4, Rp = 1e-9, zp = class extends Error {
|
|
|
11698
11714
|
startedAt = Date.now();
|
|
11699
11715
|
transformStack = [];
|
|
11700
11716
|
constructor(e = {}) {
|
|
11701
|
-
this.options = e, this.symbols = new
|
|
11717
|
+
this.options = e, this.symbols = new bp(), this.evaluator = new Op(this.symbols, e.randomSeed), this.pushTransform();
|
|
11702
11718
|
}
|
|
11703
11719
|
convert(e) {
|
|
11704
11720
|
let t = new Nn();
|
|
11705
11721
|
try {
|
|
11706
11722
|
this.addChildren(t, e);
|
|
11707
11723
|
} catch (e) {
|
|
11708
|
-
throw
|
|
11724
|
+
throw Np(t), e;
|
|
11709
11725
|
}
|
|
11710
11726
|
return t;
|
|
11711
11727
|
}
|
|
@@ -11726,24 +11742,24 @@ var Fp = 3e4, Ip = 12, Lp = 4, Rp = 1e-9, zp = class extends Error {
|
|
|
11726
11742
|
this.chargeEstimate(r * n);
|
|
11727
11743
|
}
|
|
11728
11744
|
chargeEstimate(e) {
|
|
11729
|
-
if (this.vertexCount + e > this.maxVertices) throw new
|
|
11745
|
+
if (this.vertexCount + e > this.maxVertices) throw new Up(`ShapeScript exceeds ${this.maxVertices} vertices — lower \`detail\` or simplify the path`);
|
|
11730
11746
|
}
|
|
11731
11747
|
makeMesh(e, t) {
|
|
11732
|
-
if (this.vertexCount += e.getAttribute("position")?.count ?? 0, this.vertexCount > this.maxVertices) throw e.dispose(), t.dispose(), new
|
|
11748
|
+
if (this.vertexCount += e.getAttribute("position")?.count ?? 0, this.vertexCount > this.maxVertices) throw e.dispose(), t.dispose(), new Up(`ShapeScript exceeds ${this.maxVertices} vertices — lower \`detail\` or use fewer shapes`);
|
|
11733
11749
|
return new ii(e, t);
|
|
11734
11750
|
}
|
|
11735
11751
|
rangeIterations(e, t, n) {
|
|
11736
11752
|
if (n === 0 || !Number.isFinite(n) || !Number.isFinite(e) || !Number.isFinite(t)) throw Error("Loop bounds and step must be finite, with a nonzero step");
|
|
11737
11753
|
let r = [];
|
|
11738
11754
|
for (let i = e; n > 0 ? i <= t : i >= t; i += n) {
|
|
11739
|
-
if (r.length >= this.maxLoopIterations) throw new
|
|
11755
|
+
if (r.length >= this.maxLoopIterations) throw new Up(`ShapeScript loop exceeds ${this.maxLoopIterations} iterations — narrow the range or increase the step`);
|
|
11740
11756
|
r.push(i);
|
|
11741
11757
|
}
|
|
11742
11758
|
return r;
|
|
11743
11759
|
}
|
|
11744
11760
|
convertNode(e) {
|
|
11745
|
-
if (this.nodeCount += 1, this.nodeCount > this.maxNodes) throw new
|
|
11746
|
-
if (Date.now() - this.startedAt > this.maxDurationMs) throw new
|
|
11761
|
+
if (this.nodeCount += 1, this.nodeCount > this.maxNodes) throw new Up(`ShapeScript produced more than ${this.maxNodes} objects — reduce the loop counts or the nesting`);
|
|
11762
|
+
if (Date.now() - this.startedAt > this.maxDurationMs) throw new Up(`ShapeScript took longer than ${this.maxDurationMs}ms to build — simplify the model or use fewer boolean operations`);
|
|
11747
11763
|
switch (e.type) {
|
|
11748
11764
|
case "shape": return this.convertShape(e);
|
|
11749
11765
|
case "csg": return this.convertCSG(e);
|
|
@@ -11759,6 +11775,7 @@ var Fp = 3e4, Ip = 12, Lp = 4, Rp = 1e-9, zp = class extends Error {
|
|
|
11759
11775
|
case "hull": return this.convertHull(e);
|
|
11760
11776
|
case "group": return this.convertBlock(e);
|
|
11761
11777
|
case "detail": return this.handleDetail(e), null;
|
|
11778
|
+
case "seed": return this.evaluator.reseed(this.evaluateNumber(e.value)), null;
|
|
11762
11779
|
case "color": return this.handleColorCommand(e), null;
|
|
11763
11780
|
case "rotate": return this.handleRotateCommand(e), null;
|
|
11764
11781
|
case "orientation": return this.handleOrientationCommand(e), null;
|
|
@@ -11767,8 +11784,8 @@ var Fp = 3e4, Ip = 12, Lp = 4, Rp = 1e-9, zp = class extends Error {
|
|
|
11767
11784
|
case "customShape": return this.convertCustomShape(e);
|
|
11768
11785
|
case "path": {
|
|
11769
11786
|
let t = this.buildPath(e);
|
|
11770
|
-
this.chargePathEstimate(t,
|
|
11771
|
-
let n = this.makeMesh(new to(t), this.createMaterial({ properties: {} }));
|
|
11787
|
+
this.chargePathEstimate(t, Bp), this.requireEnclosedArea(t, "path");
|
|
11788
|
+
let n = this.makeMesh(this.placePath(new to(t), e), this.createMaterial({ properties: {} }));
|
|
11772
11789
|
return this.applyCurrentTransform(n), n;
|
|
11773
11790
|
}
|
|
11774
11791
|
default: throw Error(`Unsupported command: ${e.type}`);
|
|
@@ -11779,7 +11796,7 @@ var Fp = 3e4, Ip = 12, Lp = 4, Rp = 1e-9, zp = class extends Error {
|
|
|
11779
11796
|
try {
|
|
11780
11797
|
t();
|
|
11781
11798
|
} catch (t) {
|
|
11782
|
-
throw
|
|
11799
|
+
throw Np(e), t;
|
|
11783
11800
|
}
|
|
11784
11801
|
return e;
|
|
11785
11802
|
});
|
|
@@ -11807,7 +11824,7 @@ var Fp = 3e4, Ip = 12, Lp = 4, Rp = 1e-9, zp = class extends Error {
|
|
|
11807
11824
|
try {
|
|
11808
11825
|
return n = this.makeMesh(e, this.createMaterial(t)), this.applyExplicitTransforms(n, t.properties), this.applyCurrentTransform(n), n;
|
|
11809
11826
|
} catch (t) {
|
|
11810
|
-
throw n ?
|
|
11827
|
+
throw n ? Np(n) : e.dispose(), t;
|
|
11811
11828
|
}
|
|
11812
11829
|
}
|
|
11813
11830
|
convertShape(e) {
|
|
@@ -11828,32 +11845,34 @@ var Fp = 3e4, Ip = 12, Lp = 4, Rp = 1e-9, zp = class extends Error {
|
|
|
11828
11845
|
t[0]
|
|
11829
11846
|
]), e.primitive) {
|
|
11830
11847
|
case "cube": return this.requireExtent("cube", t), new Ni(t[0], t[1], t[2]);
|
|
11831
|
-
case "sphere": return this.requireExtent("sphere", t), new ro(
|
|
11848
|
+
case "sphere": return this.requireExtent("sphere", t), new ro(.5, this.detailLevel, this.detailLevel).scale(...t);
|
|
11832
11849
|
case "cylinder": {
|
|
11833
|
-
let n = e.properties.radiusTop ? this.evaluateNumber(e.properties.radiusTop) : t[0], r = e.properties.radiusBottom ? this.evaluateNumber(e.properties.radiusBottom) : t[0], i = e.properties.height ? this.evaluateNumber(e.properties.height) : t[1];
|
|
11850
|
+
let n = e.properties.radiusTop ? this.evaluateNumber(e.properties.radiusTop) : t[0] / 2, r = e.properties.radiusBottom ? this.evaluateNumber(e.properties.radiusBottom) : t[0] / 2, i = e.properties.height ? this.evaluateNumber(e.properties.height) : t[1];
|
|
11834
11851
|
return this.requireExtent("cylinder", [n || r, i]), new Fi(n, r, i, this.detailLevel);
|
|
11835
11852
|
}
|
|
11836
11853
|
case "cone": {
|
|
11837
|
-
let n = t[0], r = e.properties.height ? this.evaluateNumber(e.properties.height) : t[1];
|
|
11854
|
+
let n = t[0] / 2, r = e.properties.height ? this.evaluateNumber(e.properties.height) : t[1];
|
|
11838
11855
|
return this.requireExtent("cone", [n, r]), new Ii(n, r, this.detailLevel);
|
|
11839
11856
|
}
|
|
11840
|
-
case "torus":
|
|
11841
|
-
|
|
11842
|
-
return this.requireExtent("torus", [n, r]), new io(n, r, Math.max(3, Math.floor(this.detailLevel / 2)), this.detailLevel);
|
|
11843
|
-
}
|
|
11844
|
-
case "circle": return new Pi(t[0] || 1, this.detailLevel);
|
|
11857
|
+
case "torus": return this.createTorus(e, t);
|
|
11858
|
+
case "circle": return new Pi((t[0] || 1) / 2, this.detailLevel);
|
|
11845
11859
|
case "square": {
|
|
11846
11860
|
let e = t[0] || 1;
|
|
11847
11861
|
return new eo(e, t[1] || e);
|
|
11848
11862
|
}
|
|
11849
11863
|
case "polygon": {
|
|
11850
|
-
let n = t[0] || 1, r = e.properties.sides === void 0 ? 6 : this.evaluateNumber(e.properties.sides);
|
|
11864
|
+
let n = (t[0] || 1) / 2, r = e.properties.sides === void 0 ? 6 : this.evaluateNumber(e.properties.sides);
|
|
11851
11865
|
if (!Number.isInteger(r) || r < 3 || r > 256) throw Error("Polygon sides must be an integer from 3 to 256");
|
|
11852
11866
|
return new Pi(n, r);
|
|
11853
11867
|
}
|
|
11854
11868
|
default: throw Error(`Unknown primitive: ${e.primitive}`);
|
|
11855
11869
|
}
|
|
11856
11870
|
}
|
|
11871
|
+
createTorus(e, t) {
|
|
11872
|
+
let n = t[0] / 2, r = e.properties.innerRadius ? this.evaluateNumber(e.properties.innerRadius) : void 0, i = (e.properties.outerRadius ? this.evaluateNumber(e.properties.outerRadius) : void 0) ?? (r === void 0 ? n / 1.4 : n - r), a = r ?? i * .4;
|
|
11873
|
+
if (i <= 0) throw Error("`torus` tube is as wide as the whole shape — its ring has no radius left");
|
|
11874
|
+
return this.requireExtent("torus", [i, a]), new io(i, a, Math.max(3, Math.floor(this.detailLevel / 2)), this.detailLevel);
|
|
11875
|
+
}
|
|
11857
11876
|
materialColor(e) {
|
|
11858
11877
|
if (e !== void 0) {
|
|
11859
11878
|
let [t = .8, n = .8, r = .8] = this.evaluateColor(e);
|
|
@@ -11948,9 +11967,9 @@ var Fp = 3e4, Ip = 12, Lp = 4, Rp = 1e-9, zp = class extends Error {
|
|
|
11948
11967
|
}
|
|
11949
11968
|
}
|
|
11950
11969
|
}
|
|
11951
|
-
return s.material || (s.material = o.material), s.applyMatrix4(t), s.updateMatrixWorld(!0),
|
|
11970
|
+
return s.material || (s.material = o.material), s.applyMatrix4(t), s.updateMatrixWorld(!0), Pp(n, s), s;
|
|
11952
11971
|
} catch (e) {
|
|
11953
|
-
throw
|
|
11972
|
+
throw Pp(n, new Nn()), e;
|
|
11954
11973
|
}
|
|
11955
11974
|
}
|
|
11956
11975
|
convertForLoop(e) {
|
|
@@ -11958,7 +11977,7 @@ var Fp = 3e4, Ip = 12, Lp = 4, Rp = 1e-9, zp = class extends Error {
|
|
|
11958
11977
|
return this.inScope(t, () => {
|
|
11959
11978
|
if (e.iterableValues) {
|
|
11960
11979
|
let n = this.evaluator.evaluate(e.iterableValues), r = Array.isArray(n) ? n : [n];
|
|
11961
|
-
if (r.length > this.maxLoopIterations) throw new
|
|
11980
|
+
if (r.length > this.maxLoopIterations) throw new Up(`ShapeScript loop exceeds ${this.maxLoopIterations} iterations — narrow the range or increase the step`);
|
|
11962
11981
|
for (let n of r) this.symbols.set(e.variable, n), this.addChildren(t, e.body);
|
|
11963
11982
|
} else {
|
|
11964
11983
|
let n = this.evaluateNumber(e.from), r = this.evaluateNumber(e.to), i = e.step ? this.evaluateNumber(e.step) : 1, a = this.rangeIterations(n, r, i);
|
|
@@ -12020,14 +12039,24 @@ var Fp = 3e4, Ip = 12, Lp = 4, Rp = 1e-9, zp = class extends Error {
|
|
|
12020
12039
|
let n = this.evaluateVector3(t.position);
|
|
12021
12040
|
e.position.set(...n);
|
|
12022
12041
|
}
|
|
12023
|
-
|
|
12024
|
-
|
|
12025
|
-
|
|
12026
|
-
|
|
12027
|
-
|
|
12028
|
-
|
|
12029
|
-
e.
|
|
12042
|
+
let n = t.orientation ?? t.rotation;
|
|
12043
|
+
n && e.quaternion.copy(this.rotationOf(n));
|
|
12044
|
+
}
|
|
12045
|
+
rotationOf(e) {
|
|
12046
|
+
let t = this.rotationComponents(e);
|
|
12047
|
+
if (t.length === 4) {
|
|
12048
|
+
let [e = 0, n = 0, r = 0, i = 0] = t, a = Math.max(Math.abs(n), Math.abs(r), Math.abs(i));
|
|
12049
|
+
if (a === 0) throw Error("Rotation axis must not be zero");
|
|
12050
|
+
let o = new J(n / a, r / a, i / a).normalize();
|
|
12051
|
+
return new Ft().setFromAxisAngle(o, -e * Math.PI);
|
|
12030
12052
|
}
|
|
12053
|
+
let [n = 0, r = 0, i = 0] = t;
|
|
12054
|
+
return new Ft().setFromEuler(new hn(-i * Math.PI, -r * Math.PI, -n * Math.PI, "ZYX"));
|
|
12055
|
+
}
|
|
12056
|
+
rotationComponents(e) {
|
|
12057
|
+
let t = Array.isArray(e) && typeof e[0] == "number" ? e : this.evaluator.evaluate(e), n = (Array.isArray(t) ? t : [t]).map((e) => typeof e == "number" ? e : NaN);
|
|
12058
|
+
if (n.length === 0 || n.length > 4 || !n.every(Number.isFinite)) throw Error("Expected a rotation of 1 to 3 half-turn components (roll yaw pitch) or an angle and an axis (angle x y z)");
|
|
12059
|
+
return n;
|
|
12031
12060
|
}
|
|
12032
12061
|
handleDetail(e) {
|
|
12033
12062
|
let t = this.evaluateNumber(e.value);
|
|
@@ -12038,14 +12067,11 @@ var Fp = 3e4, Ip = 12, Lp = 4, Rp = 1e-9, zp = class extends Error {
|
|
|
12038
12067
|
this.currentTransform().color = new Bn(t[0], t[1], t[2]);
|
|
12039
12068
|
}
|
|
12040
12069
|
handleRotateCommand(e) {
|
|
12041
|
-
|
|
12042
|
-
r.makeRotationFromEuler(i), n.matrix.multiply(r);
|
|
12070
|
+
this.currentTransform().matrix.multiply(new Y().makeRotationFromQuaternion(this.rotationOf(e.value)));
|
|
12043
12071
|
}
|
|
12044
12072
|
handleOrientationCommand(e) {
|
|
12045
|
-
let t = this.
|
|
12046
|
-
|
|
12047
|
-
let a = new hn(t[0] * Math.PI * 2, t[1] * Math.PI * 2, t[2] * Math.PI * 2, "XYZ");
|
|
12048
|
-
n.matrix.compose(r, new Ft().setFromEuler(a), i);
|
|
12073
|
+
let t = this.currentTransform(), n = new J(), r = new J();
|
|
12074
|
+
t.matrix.decompose(n, new Ft(), r), t.matrix.compose(n, this.rotationOf(e.value), r);
|
|
12049
12075
|
}
|
|
12050
12076
|
handleTranslateCommand(e) {
|
|
12051
12077
|
let t = this.currentTransform(), [n, r, i] = this.evaluateTranslateVector(e.value);
|
|
@@ -12062,9 +12088,9 @@ var Fp = 3e4, Ip = 12, Lp = 4, Rp = 1e-9, zp = class extends Error {
|
|
|
12062
12088
|
n.matrix.multiply(r);
|
|
12063
12089
|
}
|
|
12064
12090
|
requireEnclosedArea(e, t) {
|
|
12065
|
-
let n = e.getPoints(
|
|
12091
|
+
let n = e.getPoints(Bp), r = qa.area(n);
|
|
12066
12092
|
if (!Number.isFinite(r)) throw Error(`\`${t}\` needs finite path coordinates — these overflow`);
|
|
12067
|
-
if (n.length < 3 || Math.abs(r) <
|
|
12093
|
+
if (n.length < 3 || Math.abs(r) < Hp) throw Error(`\`${t}\` needs a path that encloses an area — this one has fewer than three distinct points, or they are collinear`);
|
|
12068
12094
|
return e;
|
|
12069
12095
|
}
|
|
12070
12096
|
convertExtrude(e) {
|
|
@@ -12091,19 +12117,40 @@ var Fp = 3e4, Ip = 12, Lp = 4, Rp = 1e-9, zp = class extends Error {
|
|
|
12091
12117
|
1,
|
|
12092
12118
|
1
|
|
12093
12119
|
])[2] || 1, r = Math.max(1, Math.floor(this.detailLevel / 4));
|
|
12094
|
-
this.chargePathEstimate(t, r,
|
|
12095
|
-
let i = new Xa(t, {
|
|
12120
|
+
this.chargePathEstimate(t, r, Vp);
|
|
12121
|
+
let i = this.placePath(new Xa(t, {
|
|
12096
12122
|
depth: n,
|
|
12097
12123
|
bevelEnabled: !1,
|
|
12098
12124
|
curveSegments: r
|
|
12099
|
-
}), a = this.createMaterial(e), o = this.makeMesh(i, a);
|
|
12125
|
+
}), e.path), a = this.createMaterial(e), o = this.makeMesh(i, a);
|
|
12100
12126
|
return this.applyExplicitTransforms(o, e.properties), this.applyCurrentTransform(o), o;
|
|
12101
12127
|
}
|
|
12102
12128
|
buildPath(e) {
|
|
12103
|
-
|
|
12104
|
-
|
|
12105
|
-
|
|
12106
|
-
|
|
12129
|
+
return this.shapeFromPathPoints(this.collectPathPoints(e));
|
|
12130
|
+
}
|
|
12131
|
+
placePath(e, t) {
|
|
12132
|
+
let n = t.properties;
|
|
12133
|
+
if (!n) return e;
|
|
12134
|
+
let r = new J(...this.evaluateVector3(n.position)), i = n.orientation ?? n.rotation, a = i ? this.rotationOf(i) : new Ft(), o = new J(...n.size ? this.evaluateVector3(n.size) : [
|
|
12135
|
+
1,
|
|
12136
|
+
1,
|
|
12137
|
+
1
|
|
12138
|
+
]);
|
|
12139
|
+
return e.applyMatrix4(new Y().compose(r, a, o));
|
|
12140
|
+
}
|
|
12141
|
+
collectPathPoints(e) {
|
|
12142
|
+
let t = new Y(), n = [], r = (e) => {
|
|
12143
|
+
let r = new J(this.evaluateNumber(e.x), this.evaluateNumber(e.y), 0).applyMatrix4(t);
|
|
12144
|
+
if (!Number.isFinite(r.x) || !Number.isFinite(r.y)) throw Error("Path coordinates overflowed to a non-finite value");
|
|
12145
|
+
n.push({
|
|
12146
|
+
x: r.x,
|
|
12147
|
+
y: r.y,
|
|
12148
|
+
curved: e.type === "curve"
|
|
12149
|
+
});
|
|
12150
|
+
}, i = (e) => {
|
|
12151
|
+
if (t.multiply(e), !t.elements.every(Number.isFinite)) throw Error("Path transform overflowed to a non-finite value — `translate`, `rotate` and `scale` accumulate inside a path");
|
|
12152
|
+
}, a = (e) => {
|
|
12153
|
+
if (++this.pathCommandCount > this.maxLoopIterations) throw new Up(`ShapeScript path exceeds ${this.maxLoopIterations} commands`);
|
|
12107
12154
|
switch (e.type) {
|
|
12108
12155
|
case "define":
|
|
12109
12156
|
this.handleDefine(e);
|
|
@@ -12111,46 +12158,55 @@ var Fp = 3e4, Ip = 12, Lp = 4, Rp = 1e-9, zp = class extends Error {
|
|
|
12111
12158
|
case "detail":
|
|
12112
12159
|
this.handleDetail(e);
|
|
12113
12160
|
break;
|
|
12114
|
-
case "point":
|
|
12115
|
-
|
|
12116
|
-
|
|
12161
|
+
case "point":
|
|
12162
|
+
case "curve":
|
|
12163
|
+
r(e);
|
|
12117
12164
|
break;
|
|
12118
|
-
|
|
12119
|
-
|
|
12120
|
-
let s = this.evaluateNumber(e.x), c = this.evaluateNumber(e.y), l = Math.cos(i), u = Math.sin(i), d = s * l - c * u, f = s * u + c * l;
|
|
12121
|
-
if (o(d, f), !a) {
|
|
12122
|
-
t.moveTo(n, r), a = !0;
|
|
12123
|
-
break;
|
|
12124
|
-
}
|
|
12125
|
-
if (e.controlX !== void 0 && e.controlY !== void 0) {
|
|
12126
|
-
let i = this.evaluateNumber(e.controlX), a = this.evaluateNumber(e.controlY), o = i * l - a * u, s = i * u + a * l;
|
|
12127
|
-
if (!Number.isFinite(n + o) || !Number.isFinite(r + s)) throw Error("Curve control point overflowed to a non-finite value");
|
|
12128
|
-
t.quadraticCurveTo(n + o, r + s, n, r);
|
|
12129
|
-
} else t.lineTo(n, r);
|
|
12130
|
-
break;
|
|
12131
|
-
}
|
|
12132
|
-
case "rotate": {
|
|
12133
|
-
let t = this.evaluateNumber(e.angle);
|
|
12134
|
-
if (i += t * Math.PI * 2, !Number.isFinite(i)) throw Error("Path rotation overflowed to a non-finite angle");
|
|
12165
|
+
case "rotate":
|
|
12166
|
+
i(new Y().makeRotationZ(-this.evaluateNumber(e.angle) * Math.PI));
|
|
12135
12167
|
break;
|
|
12136
|
-
}
|
|
12137
12168
|
case "translate":
|
|
12138
|
-
|
|
12169
|
+
i(new Y().makeTranslation(this.evaluateNumber(e.x), this.evaluateNumber(e.y), 0));
|
|
12139
12170
|
break;
|
|
12140
|
-
case "
|
|
12141
|
-
this.
|
|
12142
|
-
|
|
12143
|
-
for (let t of i) {
|
|
12144
|
-
this.symbols.set(e.variable, t);
|
|
12145
|
-
for (let t of e.commands) s(t);
|
|
12146
|
-
}
|
|
12147
|
-
this.symbols.popScope();
|
|
12171
|
+
case "scale": {
|
|
12172
|
+
let t = this.evaluateNumber(e.x);
|
|
12173
|
+
i(new Y().makeScale(t, e.y === void 0 ? t : this.evaluateNumber(e.y), 1));
|
|
12148
12174
|
break;
|
|
12149
12175
|
}
|
|
12176
|
+
case "for": this.runPathLoop(e, a);
|
|
12150
12177
|
}
|
|
12151
12178
|
};
|
|
12152
|
-
for (let t of e.commands)
|
|
12153
|
-
return
|
|
12179
|
+
for (let t of e.commands) a(t);
|
|
12180
|
+
return n;
|
|
12181
|
+
}
|
|
12182
|
+
runPathLoop(e, t) {
|
|
12183
|
+
this.symbols.pushScope();
|
|
12184
|
+
try {
|
|
12185
|
+
let n = this.evaluateNumber(e.from), r = this.evaluateNumber(e.to), i = e.step ? this.evaluateNumber(e.step) : 1;
|
|
12186
|
+
for (let a of this.rangeIterations(n, r, i)) {
|
|
12187
|
+
this.symbols.set(e.variable, a);
|
|
12188
|
+
for (let n of e.commands) t(n);
|
|
12189
|
+
}
|
|
12190
|
+
} finally {
|
|
12191
|
+
this.symbols.popScope();
|
|
12192
|
+
}
|
|
12193
|
+
}
|
|
12194
|
+
shapeFromPathPoints(e) {
|
|
12195
|
+
let t = new pa(), n = e[0];
|
|
12196
|
+
if (n === void 0) return t;
|
|
12197
|
+
let r = e[e.length - 1], i = e.length > 2 && Lp(n, r), a = i ? e.slice(0, -1) : e, o = (e) => a[(e + a.length) % a.length], s = i && n.curved ? ((e, t) => e.curved ? Rp(e, t) : e)(o(-1), n) : n;
|
|
12198
|
+
t.moveTo(s.x, s.y);
|
|
12199
|
+
let c = !1;
|
|
12200
|
+
for (let e = +!i; e < a.length; e++) {
|
|
12201
|
+
let n = o(e), r = i || e < a.length - 1 ? o(e + 1) : void 0;
|
|
12202
|
+
if (!n.curved || r === void 0) {
|
|
12203
|
+
c || t.lineTo(n.x, n.y), c = !1;
|
|
12204
|
+
continue;
|
|
12205
|
+
}
|
|
12206
|
+
let s = r.curved ? Rp(n, r) : r;
|
|
12207
|
+
t.quadraticCurveTo(n.x, n.y, s.x, s.y), c = !r.curved;
|
|
12208
|
+
}
|
|
12209
|
+
return i && !c && !Lp(o(-1), s) && t.lineTo(s.x, s.y), t;
|
|
12154
12210
|
}
|
|
12155
12211
|
convertLathe(e) {
|
|
12156
12212
|
return this.inFrame(() => this.buildLathe(e));
|
|
@@ -12158,7 +12214,7 @@ var Fp = 3e4, Ip = 12, Lp = 4, Rp = 1e-9, zp = class extends Error {
|
|
|
12158
12214
|
requireLatheProfile(e) {
|
|
12159
12215
|
if (!e.every((e) => Number.isFinite(e.x) && Number.isFinite(e.y))) throw Error("`lathe` profile has non-finite coordinates — a curve control point or a path command overflowed");
|
|
12160
12216
|
let t = Math.max(...e.map((e) => Math.abs(e.x))), n = Math.max(...e.map((e) => e.y)) - Math.min(...e.map((e) => e.y));
|
|
12161
|
-
if (t <
|
|
12217
|
+
if (t < Hp || n < Hp) throw Error("`lathe` needs a profile with both radius and height — one on the axis of rotation sweeps nothing");
|
|
12162
12218
|
}
|
|
12163
12219
|
buildLathe(e) {
|
|
12164
12220
|
let t = null;
|
|
@@ -12167,6 +12223,7 @@ var Fp = 3e4, Ip = 12, Lp = 4, Rp = 1e-9, zp = class extends Error {
|
|
|
12167
12223
|
break;
|
|
12168
12224
|
}
|
|
12169
12225
|
if (!t) throw Error("Lathe requires a path child");
|
|
12226
|
+
if (t.properties) throw Error("`lathe` does not support position/orientation/size on its profile path — place the lathe itself instead");
|
|
12170
12227
|
let n = this.buildPath(t);
|
|
12171
12228
|
this.chargePathEstimate(n, this.detailLevel, this.detailLevel + 1);
|
|
12172
12229
|
let r = n.getPoints(this.detailLevel);
|
|
@@ -12189,7 +12246,7 @@ var Fp = 3e4, Ip = 12, Lp = 4, Rp = 1e-9, zp = class extends Error {
|
|
|
12189
12246
|
try {
|
|
12190
12247
|
i = t(this.buildOperands(n, e.children));
|
|
12191
12248
|
} finally {
|
|
12192
|
-
|
|
12249
|
+
Np(n), this.vertexCount = r;
|
|
12193
12250
|
}
|
|
12194
12251
|
return this.finishMesh(i, e);
|
|
12195
12252
|
}
|
|
@@ -12214,8 +12271,8 @@ var Fp = 3e4, Ip = 12, Lp = 4, Rp = 1e-9, zp = class extends Error {
|
|
|
12214
12271
|
return new to(t, 1);
|
|
12215
12272
|
});
|
|
12216
12273
|
let n = this.buildPath(t);
|
|
12217
|
-
this.chargePathEstimate(n,
|
|
12218
|
-
let r = new to(n), i = this.makeMesh(r, this.createMaterial(e));
|
|
12274
|
+
this.chargePathEstimate(n, Bp), this.requireEnclosedArea(n, "fill");
|
|
12275
|
+
let r = this.placePath(new to(n), t), i = this.makeMesh(r, this.createMaterial(e));
|
|
12219
12276
|
return this.applyExplicitTransforms(i, e.properties), this.applyCurrentTransform(i), i;
|
|
12220
12277
|
});
|
|
12221
12278
|
}
|
|
@@ -12324,8 +12381,8 @@ var Fp = 3e4, Ip = 12, Lp = 4, Rp = 1e-9, zp = class extends Error {
|
|
|
12324
12381
|
return e === t;
|
|
12325
12382
|
}
|
|
12326
12383
|
};
|
|
12327
|
-
function
|
|
12328
|
-
return new
|
|
12384
|
+
function Gp(e, t = {}) {
|
|
12385
|
+
return new Wp(t).convert(e);
|
|
12329
12386
|
}
|
|
12330
12387
|
//#endregion
|
|
12331
|
-
export { g as $, me as $t, D as A, lo as An, oe as At, Ge as B, r as Bn, ie as Bt, I as C, nn as Cn, ye as Ct, ct as D, et as Dn, ke as Dt, Jo as E, tt as En, Se as Et, T as F, at as Fn, Ae as Ft, Y as G, Gr as Gt, u as H, z as Ht, gn as I, l as In, je as It, _o as J, f as Jt, ii as K, R as Kt, v as L, o as Ln, ce as Lt, Xe as M, oo as Mn, ne as Mt, xs as N, ot as Nn, re as Nt, Mi as O, G as On, ue as Ot, O as P, W as Pn, P as Pt, _ as Q, Ne as Qt, b as R, e as Rn, le as Rt, si as S, Ze as Sn, ve as St, Ai as T, ao as Tn, xe as Tt, Pt as U, B as Ut, Ke as V, i as Vn, H as Vt, Rt as W, ho as Wt, m as X, fe as Xt, vo as Y, st as Yt, h as Z, Fe as Zt, Qo as _, A as _n, De as _t,
|
|
12388
|
+
export { g as $, me as $t, D as A, lo as An, oe as At, Ge as B, r as Bn, ie as Bt, I as C, nn as Cn, ye as Ct, ct as D, et as Dn, ke as Dt, Jo as E, tt as En, Se as Et, T as F, at as Fn, Ae as Ft, Y as G, Gr as Gt, u as H, z as Ht, gn as I, l as In, je as It, _o as J, f as Jt, ii as K, R as Kt, v as L, o as Ln, ce as Lt, Xe as M, oo as Mn, ne as Mt, xs as N, ot as Nn, re as Nt, Mi as O, G as On, ue as Ot, O as P, W as Pn, P as Pt, _ as Q, Ne as Qt, b as R, e as Rn, le as Rt, si as S, Ze as Sn, ve as St, Ai as T, ao as Tn, xe as Tt, Pt as U, B as Ut, Ke as V, i as Vn, H as Vt, Rt as W, ho as Wt, m as X, fe as Xt, vo as Y, st as Yt, h as Z, Fe as Zt, Qo as _, A as _n, De as _t, Fp as a, fs as an, Ft as at, an as b, J as bn, ge as bt, $o as c, Sr as cn, Pe as ct, Fr as d, x as dn, F as dt, We as en, Ko as et, S as f, N as fn, V as ft, Ss as g, k as gn, Te as gt, Ut as h, E as hn, we as ht, Np as i, C as in, ds as it, hi as j, rt as jn, U as jt, X as k, Cs as kn, se as kt, Ni as l, Cr as ln, Me as lt, Bn as m, M as mn, Ce as mt, Up as n, Hn as nn, di as nt, ee as o, d as on, de as ot, p, j as pn, Ee as pt, Kr as q, te as qt, Gp as r, mo as rn, eo as rt, Yo as s, $t as sn, ft as st, zp as t, qe as tn, Go as tt, xr as u, uo as un, pe as ut, ji as v, w as vn, Oe as vt, L as w, Fn as wn, be as wt, rn as x, en as xn, _e as xt, ki as y, q as yn, he as yt, y as z, t as zn, ae as zt };
|