@motionscript/math 0.1.0-alpha.5 → 0.1.0-alpha.6
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/CHANGELOG.md +22 -0
- package/README.md +39 -33
- package/dist/annotate/angle-mark.d.ts +52 -27
- package/dist/annotate/angle-mark.d.ts.map +1 -1
- package/dist/annotate/angle-mark.js +80 -115
- package/dist/annotate/angle-mark.js.map +1 -1
- package/dist/annotate/curly-brace.d.ts +59 -25
- package/dist/annotate/curly-brace.d.ts.map +1 -1
- package/dist/annotate/curly-brace.js +85 -100
- package/dist/annotate/curly-brace.js.map +1 -1
- package/dist/annotate/emphasis-mark.d.ts +43 -9
- package/dist/annotate/emphasis-mark.d.ts.map +1 -1
- package/dist/annotate/emphasis-mark.js +33 -34
- package/dist/annotate/emphasis-mark.js.map +1 -1
- package/dist/browser/chunks/chunk-ABYBW64J.js +2 -0
- package/dist/browser/chunks/chunk-ABYBW64J.js.map +7 -0
- package/dist/browser/chunks/chunk-K77KLQX4.js +2 -0
- package/dist/browser/chunks/chunk-K77KLQX4.js.map +7 -0
- package/dist/browser/index.js +1 -1
- package/dist/browser/index.js.map +3 -3
- package/dist/browser/kit.js +1 -1
- package/dist/browser/manifest.json +1 -1
- package/dist/browser/tex.js +1 -1
- package/dist/browser/tex.js.map +2 -2
- package/dist/engine.d.ts +26 -19
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +17 -14
- package/dist/engine.js.map +1 -1
- package/dist/kit/component.d.ts +51 -0
- package/dist/kit/component.d.ts.map +1 -0
- package/dist/kit/component.js +30 -0
- package/dist/kit/component.js.map +1 -0
- package/dist/kit/curve.d.ts +22 -11
- package/dist/kit/curve.d.ts.map +1 -1
- package/dist/kit/curve.js +25 -18
- package/dist/kit/curve.js.map +1 -1
- package/dist/kit/field-mark.d.ts +58 -35
- package/dist/kit/field-mark.d.ts.map +1 -1
- package/dist/kit/field-mark.js +100 -120
- package/dist/kit/field-mark.js.map +1 -1
- package/dist/kit/follow.d.ts +67 -29
- package/dist/kit/follow.d.ts.map +1 -1
- package/dist/kit/follow.js +114 -110
- package/dist/kit/follow.js.map +1 -1
- package/dist/kit/furniture.d.ts +3 -1
- package/dist/kit/furniture.d.ts.map +1 -1
- package/dist/kit/furniture.js +5 -0
- package/dist/kit/furniture.js.map +1 -1
- package/dist/kit/graph.d.ts +46 -0
- package/dist/kit/graph.d.ts.map +1 -0
- package/dist/kit/graph.js +90 -0
- package/dist/kit/graph.js.map +1 -0
- package/dist/kit/mark.d.ts +64 -39
- package/dist/kit/mark.d.ts.map +1 -1
- package/dist/kit/mark.js +80 -96
- package/dist/kit/mark.js.map +1 -1
- package/dist/kit/place.d.ts +10 -8
- package/dist/kit/place.d.ts.map +1 -1
- package/dist/kit/place.js +28 -30
- package/dist/kit/place.js.map +1 -1
- package/dist/kit/system.d.ts +27 -29
- package/dist/kit/system.d.ts.map +1 -1
- package/dist/kit/system.js +62 -58
- package/dist/kit/system.js.map +1 -1
- package/dist/kit/withdrawn.d.ts +3 -3
- package/dist/kit/withdrawn.js +3 -3
- package/dist/kit/withdrawn.js.map +1 -1
- package/dist/marks/curve-area.d.ts +24 -18
- package/dist/marks/curve-area.d.ts.map +1 -1
- package/dist/marks/curve-area.js +50 -73
- package/dist/marks/curve-area.js.map +1 -1
- package/dist/marks/drop-lines.d.ts +28 -10
- package/dist/marks/drop-lines.d.ts.map +1 -1
- package/dist/marks/drop-lines.js +37 -52
- package/dist/marks/drop-lines.js.map +1 -1
- package/dist/marks/plot-point.d.ts +37 -20
- package/dist/marks/plot-point.d.ts.map +1 -1
- package/dist/marks/plot-point.js +65 -91
- package/dist/marks/plot-point.js.map +1 -1
- package/dist/marks/riemann-sum.d.ts +30 -26
- package/dist/marks/riemann-sum.d.ts.map +1 -1
- package/dist/marks/riemann-sum.js +57 -85
- package/dist/marks/riemann-sum.js.map +1 -1
- package/dist/marks/tangent-line.d.ts +38 -14
- package/dist/marks/tangent-line.d.ts.map +1 -1
- package/dist/marks/tangent-line.js +73 -87
- package/dist/marks/tangent-line.js.map +1 -1
- package/dist/marks/vector-arrow.d.ts +30 -20
- package/dist/marks/vector-arrow.d.ts.map +1 -1
- package/dist/marks/vector-arrow.js +58 -78
- package/dist/marks/vector-arrow.js.map +1 -1
- package/dist/nodes.d.ts +13 -5
- package/dist/nodes.d.ts.map +1 -1
- package/dist/nodes.js +0 -6
- package/dist/nodes.js.map +1 -1
- package/dist/plots/function-plot.d.ts +107 -43
- package/dist/plots/function-plot.d.ts.map +1 -1
- package/dist/plots/function-plot.js +146 -177
- package/dist/plots/function-plot.js.map +1 -1
- package/dist/plots/points-plot.d.ts +34 -19
- package/dist/plots/points-plot.d.ts.map +1 -1
- package/dist/plots/points-plot.js +31 -58
- package/dist/plots/points-plot.js.map +1 -1
- package/dist/plots/stream-lines.d.ts +38 -19
- package/dist/plots/stream-lines.d.ts.map +1 -1
- package/dist/plots/stream-lines.js +60 -79
- package/dist/plots/stream-lines.js.map +1 -1
- package/dist/plots/traced-path.d.ts +34 -15
- package/dist/plots/traced-path.d.ts.map +1 -1
- package/dist/plots/traced-path.js +33 -48
- package/dist/plots/traced-path.js.map +1 -1
- package/dist/plots/vector-field.d.ts +31 -11
- package/dist/plots/vector-field.d.ts.map +1 -1
- package/dist/plots/vector-field.js +50 -64
- package/dist/plots/vector-field.js.map +1 -1
- package/dist/structures/network-graph.d.ts +99 -49
- package/dist/structures/network-graph.d.ts.map +1 -1
- package/dist/structures/network-graph.js +168 -217
- package/dist/structures/network-graph.js.map +1 -1
- package/dist/structures/sample-space.d.ts +69 -38
- package/dist/structures/sample-space.d.ts.map +1 -1
- package/dist/structures/sample-space.js +132 -170
- package/dist/structures/sample-space.js.map +1 -1
- package/dist/systems/axes2d.d.ts +126 -37
- package/dist/systems/axes2d.d.ts.map +1 -1
- package/dist/systems/axes2d.js +147 -183
- package/dist/systems/axes2d.js.map +1 -1
- package/dist/systems/number-line.d.ts +51 -28
- package/dist/systems/number-line.d.ts.map +1 -1
- package/dist/systems/number-line.js +82 -118
- package/dist/systems/number-line.js.map +1 -1
- package/dist/systems/number-plane.d.ts +92 -31
- package/dist/systems/number-plane.d.ts.map +1 -1
- package/dist/systems/number-plane.js +142 -149
- package/dist/systems/number-plane.js.map +1 -1
- package/dist/systems/polar-plane.d.ts +47 -26
- package/dist/systems/polar-plane.d.ts.map +1 -1
- package/dist/systems/polar-plane.js +107 -133
- package/dist/systems/polar-plane.js.map +1 -1
- package/dist/tex/index.d.ts.map +1 -1
- package/dist/tex/index.js +1 -0
- package/dist/tex/index.js.map +1 -1
- package/dist/tex/matrix.d.ts +56 -18
- package/dist/tex/matrix.d.ts.map +1 -1
- package/dist/tex/matrix.js +33 -50
- package/dist/tex/matrix.js.map +1 -1
- package/dist/tex/node.d.ts +55 -201
- package/dist/tex/node.d.ts.map +1 -1
- package/dist/tex/node.js +23 -593
- package/dist/tex/node.js.map +1 -1
- package/dist/tex/typeset.d.ts +133 -0
- package/dist/tex/typeset.d.ts.map +1 -0
- package/dist/tex/typeset.js +403 -0
- package/dist/tex/typeset.js.map +1 -0
- package/dist/three/axes3d.d.ts +140 -54
- package/dist/three/axes3d.d.ts.map +1 -1
- package/dist/three/axes3d.js +159 -204
- package/dist/three/axes3d.js.map +1 -1
- package/dist/three/curve-plot3d.d.ts +70 -42
- package/dist/three/curve-plot3d.d.ts.map +1 -1
- package/dist/three/curve-plot3d.js +97 -132
- package/dist/three/curve-plot3d.js.map +1 -1
- package/dist/three/entries.d.ts +17 -0
- package/dist/three/entries.d.ts.map +1 -0
- package/dist/three/entries.js +15 -0
- package/dist/three/entries.js.map +1 -0
- package/dist/three/plot-point3d.d.ts +57 -12
- package/dist/three/plot-point3d.d.ts.map +1 -1
- package/dist/three/plot-point3d.js +27 -53
- package/dist/three/plot-point3d.js.map +1 -1
- package/dist/three/space.d.ts +17 -2
- package/dist/three/space.d.ts.map +1 -1
- package/dist/three/space.js +19 -8
- package/dist/three/space.js.map +1 -1
- package/dist/three/surface-plot3d.d.ts +131 -49
- package/dist/three/surface-plot3d.d.ts.map +1 -1
- package/dist/three/surface-plot3d.js +227 -261
- package/dist/three/surface-plot3d.js.map +1 -1
- package/dist/three/vector-arrow3d.d.ts +58 -16
- package/dist/three/vector-arrow3d.d.ts.map +1 -1
- package/dist/three/vector-arrow3d.js +48 -67
- package/dist/three/vector-arrow3d.js.map +1 -1
- package/package.json +4 -4
- package/src/annotate/angle-mark.ts +95 -105
- package/src/annotate/curly-brace.ts +107 -85
- package/src/annotate/emphasis-mark.ts +55 -26
- package/src/engine.ts +35 -21
- package/src/kit/component.ts +57 -0
- package/src/kit/curve.ts +38 -20
- package/src/kit/field-mark.ts +124 -108
- package/src/kit/follow.ts +146 -120
- package/src/kit/furniture.ts +6 -1
- package/src/kit/graph.ts +116 -0
- package/src/kit/mark.ts +135 -114
- package/src/kit/place.ts +32 -56
- package/src/kit/system.ts +77 -71
- package/src/kit/withdrawn.ts +3 -3
- package/src/marks/curve-area.ts +65 -65
- package/src/marks/drop-lines.ts +50 -42
- package/src/marks/plot-point.ts +77 -82
- package/src/marks/riemann-sum.ts +73 -72
- package/src/marks/tangent-line.ts +87 -71
- package/src/marks/vector-arrow.ts +73 -73
- package/src/nodes.ts +41 -5
- package/src/plots/function-plot.ts +155 -171
- package/src/plots/points-plot.ts +46 -50
- package/src/plots/stream-lines.ts +75 -66
- package/src/plots/traced-path.ts +51 -33
- package/src/plots/vector-field.ts +68 -49
- package/src/structures/network-graph.ts +168 -185
- package/src/structures/sample-space.ts +149 -148
- package/src/systems/axes2d.ts +165 -156
- package/src/systems/number-line.ts +91 -92
- package/src/systems/number-plane.ts +149 -120
- package/src/systems/polar-plane.ts +117 -116
- package/src/tex/index.ts +2 -1
- package/src/tex/matrix.ts +62 -40
- package/src/tex/node.ts +54 -621
- package/src/tex/typeset.ts +461 -0
- package/src/three/axes3d.ts +182 -161
- package/src/three/curve-plot3d.ts +107 -110
- package/src/three/entries.ts +42 -0
- package/src/three/plot-point3d.ts +42 -45
- package/src/three/space.ts +34 -9
- package/src/three/surface-plot3d.ts +312 -323
- package/src/three/vector-arrow3d.ts +65 -54
- package/dist/browser/chunks/chunk-3GJB6AVO.js +0 -2
- package/dist/browser/chunks/chunk-3GJB6AVO.js.map +0 -7
- package/dist/browser/chunks/chunk-D5WHCVBC.js +0 -2
- package/dist/browser/chunks/chunk-D5WHCVBC.js.map +0 -7
- package/dist/browser/chunks/chunk-WL4KEX7Y.js +0 -2
- package/dist/browser/chunks/chunk-WL4KEX7Y.js.map +0 -7
- package/src/kit/placement.ts +0 -8
|
@@ -1,281 +1,247 @@
|
|
|
1
|
-
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
import { colorOps, command, Geo, Graphics3D, Mat, Mesh3D, node, property, } from "@motionscript/sdk";
|
|
1
|
+
import { colorOps, component3d, Geo, Graphics3D, Mat, Material, Types, } from "@motionscript/sdk";
|
|
8
2
|
import { parseSurface, surfaceParams } from "../kit/equation3d.js";
|
|
9
3
|
import { PLOT_COLOR } from "../kit/furniture.js";
|
|
10
|
-
import { clamp
|
|
4
|
+
import { clamp } from "../kit/geometry.js";
|
|
11
5
|
import { colorAt, lerpScale, readScale } from "../kit/scale.js";
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
6
|
+
import { lerpParams, lerpSource, readSource, revisionOf, scopeFor } from "../kit/source.js";
|
|
7
|
+
import { domainEntry, meshEntries } from "./entries.js";
|
|
8
|
+
import { graphEntry, graphOf } from "./space.js";
|
|
9
|
+
const state = {
|
|
10
|
+
...meshEntries,
|
|
11
|
+
expression: Types.custom("", {
|
|
12
|
+
resolve: readSource,
|
|
13
|
+
lerp: lerpSource,
|
|
14
|
+
kind: "surfaceEquation",
|
|
15
|
+
}),
|
|
16
|
+
/**
|
|
17
|
+
* The span of each variable that is drawn: x and y for a height, which run
|
|
18
|
+
* the width of the axes when left out, u and v for a parametric surface,
|
|
19
|
+
* which run from 0 to 1.
|
|
20
|
+
*/
|
|
21
|
+
uDomain: domainEntry(-3, 3),
|
|
22
|
+
vDomain: domainEntry(-3, 3),
|
|
23
|
+
/** The equation's named values: any name in it that is not a variable, a function or a constant. */
|
|
24
|
+
params: Types.custom({}, { lerp: lerpParams }),
|
|
25
|
+
/** How finely the surface is sampled, each way. */
|
|
26
|
+
segments: Types.number(48, { min: 2, max: 256, step: 1, animatable: false }),
|
|
27
|
+
/** Colours by height, lowest first, over the axes' z range. Empty paints the surface in its fill. */
|
|
28
|
+
colorScale: Types.custom([], { resolve: readScale, lerp: lerpScale, kind: "vector" }),
|
|
29
|
+
/** How many lines are drawn across the surface each way; zero leaves it bare. */
|
|
30
|
+
meshLines: Types.number(12, { min: 0, max: 64, step: 1, animatable: false }),
|
|
31
|
+
meshColor: Types.custom("#0b1220", { kind: "color" }),
|
|
32
|
+
/** The opacity of the surface's shadow, laid flat on the floor of the axes and coloured by height; zero draws none. */
|
|
33
|
+
floorShadow: Types.number(0, { min: 0, max: 1, step: 0.01 }),
|
|
34
|
+
graph: graphEntry(),
|
|
35
|
+
};
|
|
14
36
|
/**
|
|
15
37
|
* A surface in a 3D graph: a height over x and y (`sin(x) * cos(y)`), or three
|
|
16
38
|
* parts in u and v. A point put inside it rides it.
|
|
17
39
|
*/
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
return space.offset(point.x, point.y, point.z);
|
|
74
|
-
},
|
|
75
|
-
...(scale.length > 0
|
|
76
|
-
? { color: (_u, _v, position) => colorAt(scale, high > low ? (position.y - low) / (high - low) : 0) }
|
|
77
|
-
: {}),
|
|
78
|
-
computeNormals: true,
|
|
79
|
-
revision: revisionOf(`${this._key(space)}|${JSON.stringify(scale)}`),
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
materialShorthand() {
|
|
83
|
-
const own = super.materialShorthand();
|
|
84
|
-
const scaled = this.colorScale.length > 0;
|
|
85
|
-
// A surface is seen from both sides; a vertex colour multiplies the fill, so a scale is shown on white.
|
|
86
|
-
return { faces: "both", ...own, ...(scaled ? { vertexColors: true, fill: "white" } : {}) };
|
|
87
|
-
}
|
|
88
|
-
buildGraphics3D() {
|
|
89
|
-
const g3 = new Graphics3D();
|
|
90
|
-
const space = spaceOf(this);
|
|
91
|
-
const lines = space ? this._meshLines(space) : [];
|
|
92
|
-
for (const op of super.buildGraphics3D().ops()) {
|
|
93
|
-
if (op.kind !== "mesh")
|
|
94
|
-
continue;
|
|
95
|
-
g3.mesh(op.geometry, mapMaterials(op.material, (material) => ({
|
|
96
|
-
...material,
|
|
97
|
-
// Pushed back a hair so the lines drawn on it are not fought for, and blended rather than a hole when faded.
|
|
98
|
-
...(lines.length > 0 ? { polygonOffset: true, polygonOffsetFactor: 1, polygonOffsetUnits: 1 } : {}),
|
|
99
|
-
...((this.opacity ?? 1) < 1 ? { depthWrite: false } : {}),
|
|
100
|
-
})), op.transform);
|
|
101
|
-
}
|
|
102
|
-
if (lines.length > 0) {
|
|
103
|
-
const color = colorOps.resolve(this.meshColor);
|
|
104
|
-
g3.line({ points: lines, segments: true, stroke: { fill: color }, opacity: color[3] * (this.opacity ?? 1) });
|
|
105
|
-
}
|
|
106
|
-
const shadow = space && this.floorShadow > 0 ? this._floorShadow(space) : undefined;
|
|
107
|
-
if (shadow) {
|
|
108
|
-
const scaled = this.colorScale.length > 0;
|
|
109
|
-
g3.mesh(shadow, Mat.basic({
|
|
110
|
-
color: scaled ? "white" : PLOT_COLOR,
|
|
111
|
-
vertexColors: scaled,
|
|
112
|
-
opacity: this.floorShadow * (this.opacity ?? 1),
|
|
113
|
-
transparent: true,
|
|
114
|
-
// Translucent and under everything: writing depth would hide the floor's grid lines behind it.
|
|
115
|
-
depthWrite: false,
|
|
116
|
-
faces: "both",
|
|
117
|
-
}));
|
|
118
|
-
}
|
|
119
|
-
return g3;
|
|
120
|
-
}
|
|
121
|
-
_linesKey = "";
|
|
122
|
-
_lines = [];
|
|
123
|
-
_heightOf(source, x, y) {
|
|
124
|
-
const equation = equationOf(source);
|
|
125
|
-
if (equation?.kind !== "height")
|
|
126
|
-
return NaN;
|
|
127
|
-
return equation.f(x, y, scopeFor(surfaceParams(source), this.params));
|
|
40
|
+
export const SurfacePlot3d = component3d({
|
|
41
|
+
key: "surfacePlot3d",
|
|
42
|
+
state,
|
|
43
|
+
defaults: { fill: PLOT_COLOR },
|
|
44
|
+
commands: {
|
|
45
|
+
/** Change the equation, the surface bending from the one into the other. */
|
|
46
|
+
morphTo: { args: ["expression"] },
|
|
47
|
+
/** Animate the equation's named values. */
|
|
48
|
+
paramsTo: { args: ["params"] },
|
|
49
|
+
/** Animate the spans that are drawn. */
|
|
50
|
+
domainTo: { args: ["uDomain", "vDomain"] },
|
|
51
|
+
},
|
|
52
|
+
space: (s) => surfaceSpace(s),
|
|
53
|
+
render: (ctx, s) => ctx.draw(drawSurface(s)),
|
|
54
|
+
});
|
|
55
|
+
/**
|
|
56
|
+
* The surface's height above its own origin at graph `(x, y)`, or `NaN`
|
|
57
|
+
* where it has none or is not a height. What a point riding it reads.
|
|
58
|
+
*/
|
|
59
|
+
export function surfaceValueAt(surface, x, y) {
|
|
60
|
+
const { source, blend } = surface.expression;
|
|
61
|
+
const value = heightOf(surface, source, x, y);
|
|
62
|
+
if (!blend)
|
|
63
|
+
return value;
|
|
64
|
+
const from = heightOf(surface, blend.from, x, y);
|
|
65
|
+
return from + (value - from) * blend.t;
|
|
66
|
+
}
|
|
67
|
+
/** A point inside a surface stands on it: its `x` and `y` say where, and its height is the surface's. */
|
|
68
|
+
function surfaceSpace(s) {
|
|
69
|
+
const space = graphOf(s);
|
|
70
|
+
if (!space)
|
|
71
|
+
return null;
|
|
72
|
+
return {
|
|
73
|
+
toLocal: (x, y, z) => {
|
|
74
|
+
const height = surfaceValueAt(s, x, y);
|
|
75
|
+
return space.offset(x, y, Number.isFinite(height) ? height : z);
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function drawSurface(s) {
|
|
80
|
+
const g3 = new Graphics3D();
|
|
81
|
+
const space = graphOf(s);
|
|
82
|
+
const lines = space ? meshLines(s, space) : [];
|
|
83
|
+
const scaled = s.colorScale.length > 0;
|
|
84
|
+
// A surface is seen from both sides; a vertex colour multiplies the fill, so a scale is shown on white.
|
|
85
|
+
const surface = { ...s, faces: s.faces ?? "both", ...(scaled ? { vertexColors: true, fill: "white" } : {}) };
|
|
86
|
+
for (const op of Material.mesh(surface, space ? surfaceGeometry(s, space) : undefined).ops()) {
|
|
87
|
+
if (op.kind !== "mesh")
|
|
88
|
+
continue;
|
|
89
|
+
g3.mesh(op.geometry, mapMaterials(op.material, (material) => ({
|
|
90
|
+
...material,
|
|
91
|
+
// Pushed back a hair so the lines drawn on it are not fought for, and blended rather than a hole when faded.
|
|
92
|
+
...(lines.length > 0 ? { polygonOffset: true, polygonOffsetFactor: 1, polygonOffsetUnits: 1 } : {}),
|
|
93
|
+
...((s.opacity ?? 1) < 1 ? { depthWrite: false } : {}),
|
|
94
|
+
})), op.transform);
|
|
128
95
|
}
|
|
129
|
-
|
|
130
|
-
const
|
|
131
|
-
|
|
96
|
+
if (lines.length > 0) {
|
|
97
|
+
const color = colorOps.resolve(s.meshColor);
|
|
98
|
+
g3.line({ points: lines, segments: true, stroke: { fill: color }, opacity: color[3] * (s.opacity ?? 1) });
|
|
132
99
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
to(u, v, out);
|
|
145
|
-
out.x = start.x + (out.x - start.x) * blend.t;
|
|
146
|
-
out.y = start.y + (out.y - start.y) * blend.t;
|
|
147
|
-
out.z = start.z + (out.z - start.z) * blend.t;
|
|
148
|
-
};
|
|
100
|
+
const shadow = space && s.floorShadow > 0 ? floorShadow(s, space) : undefined;
|
|
101
|
+
if (shadow) {
|
|
102
|
+
g3.mesh(shadow, Mat.basic({
|
|
103
|
+
color: scaled ? "white" : PLOT_COLOR,
|
|
104
|
+
vertexColors: scaled,
|
|
105
|
+
opacity: s.floorShadow * (s.opacity ?? 1),
|
|
106
|
+
transparent: true,
|
|
107
|
+
// Translucent and under everything: writing depth would hide the floor's grid lines behind it.
|
|
108
|
+
depthWrite: false,
|
|
109
|
+
faces: "both",
|
|
110
|
+
}));
|
|
149
111
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
112
|
+
return g3;
|
|
113
|
+
}
|
|
114
|
+
function surfaceGeometry(s, space) {
|
|
115
|
+
const sample = sampler(s, space);
|
|
116
|
+
if (!sample)
|
|
117
|
+
return undefined;
|
|
118
|
+
const scale = s.colorScale;
|
|
119
|
+
const point = { x: 0, y: 0, z: 0 };
|
|
120
|
+
const low = space.offset(0, 0, space.zRange[0] - s.z).y;
|
|
121
|
+
const high = space.offset(0, 0, space.zRange[1] - s.z).y;
|
|
122
|
+
return Geo.parametric({
|
|
123
|
+
segments: Math.max(2, Math.round(s.segments)),
|
|
124
|
+
vertex: (u, v) => {
|
|
125
|
+
sample(u, v, point);
|
|
126
|
+
return space.offset(point.x, point.y, point.z);
|
|
127
|
+
},
|
|
128
|
+
...(scale.length > 0
|
|
129
|
+
? { color: (_u, _v, position) => colorAt(scale, high > low ? (position.y - low) / (high - low) : 0) }
|
|
130
|
+
: {}),
|
|
131
|
+
computeNormals: true,
|
|
132
|
+
revision: revisionOf(`${keyOf(s, space)}|${JSON.stringify(scale)}`),
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
function heightOf(surface, source, x, y) {
|
|
136
|
+
const equation = equationOf(source);
|
|
137
|
+
if (equation?.kind !== "height")
|
|
138
|
+
return NaN;
|
|
139
|
+
return equation.f(x, y, scopeFor(surfaceParams(source), surface.params));
|
|
140
|
+
}
|
|
141
|
+
function keyOf(s, space) {
|
|
142
|
+
const { source, blend } = s.expression;
|
|
143
|
+
return [source, blend?.from, blend?.t, space.revision, s.uDomain, s.vDomain, JSON.stringify(s.params), s.x, s.y, s.z].join("|");
|
|
144
|
+
}
|
|
145
|
+
function sampler(s, space) {
|
|
146
|
+
const { source, blend } = s.expression;
|
|
147
|
+
const to = surfaceOf(s, source, space);
|
|
148
|
+
if (!to || !blend)
|
|
149
|
+
return to;
|
|
150
|
+
const from = surfaceOf(s, blend.from, space);
|
|
151
|
+
if (!from)
|
|
152
|
+
return to;
|
|
153
|
+
const start = { x: 0, y: 0, z: 0 };
|
|
154
|
+
return (u, v, out) => {
|
|
155
|
+
from(u, v, start);
|
|
156
|
+
to(u, v, out);
|
|
157
|
+
out.x = start.x + (out.x - start.x) * blend.t;
|
|
158
|
+
out.y = start.y + (out.y - start.y) * blend.t;
|
|
159
|
+
out.z = start.z + (out.z - start.z) * blend.t;
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
/** `source` as graph points, measured from the surface's own position. */
|
|
163
|
+
function surfaceOf(s, source, space) {
|
|
164
|
+
const equation = equationOf(source);
|
|
165
|
+
if (!equation)
|
|
166
|
+
return null;
|
|
167
|
+
const params = scopeFor(surfaceParams(source), s.params);
|
|
168
|
+
if (equation.kind === "parametric") {
|
|
169
|
+
const [u0, u1] = s.uDomain ?? [0, 1];
|
|
170
|
+
const [v0, v1] = s.vDomain ?? [0, 1];
|
|
171
|
+
const { x, y, z } = equation;
|
|
174
172
|
return (u, v, out) => {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
out.
|
|
173
|
+
const a = u0 + (u1 - u0) * u;
|
|
174
|
+
const b = v0 + (v1 - v0) * v;
|
|
175
|
+
out.x = finite(x(a, b, params));
|
|
176
|
+
out.y = finite(y(a, b, params));
|
|
177
|
+
out.z = finite(z(a, b, params));
|
|
178
178
|
};
|
|
179
179
|
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
_meshLines(space) {
|
|
206
|
-
const count = Math.round(this.meshLines);
|
|
207
|
-
const sample = count > 0 ? this._sampler(space) : null;
|
|
208
|
-
if (!sample)
|
|
209
|
-
return [];
|
|
210
|
-
const steps = Math.max(2, Math.round(this.segments));
|
|
211
|
-
const key = `${this._key(space)}|${count}|${steps}`;
|
|
212
|
-
if (key === this._linesKey)
|
|
213
|
-
return this._lines;
|
|
214
|
-
const lines = [];
|
|
215
|
-
const point = { x: 0, y: 0, z: 0 };
|
|
216
|
-
const at = (u, v) => {
|
|
180
|
+
const [x0, x1] = s.uDomain ?? [space.xRange[0] - s.x, space.xRange[1] - s.x];
|
|
181
|
+
const [y0, y1] = s.vDomain ?? [space.yRange[0] - s.y, space.yRange[1] - s.y];
|
|
182
|
+
// Held inside the axes: a pole would otherwise stretch one triangle across the scene.
|
|
183
|
+
const low = space.zRange[0] - s.z;
|
|
184
|
+
const high = space.zRange[1] - s.z;
|
|
185
|
+
const { f } = equation;
|
|
186
|
+
return (u, v, out) => {
|
|
187
|
+
out.x = x0 + (x1 - x0) * u;
|
|
188
|
+
out.y = y0 + (y1 - y0) * v;
|
|
189
|
+
out.z = clamp(finite(f(out.x, out.y, params)), low, high);
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
function floorShadow(s, space) {
|
|
193
|
+
const sample = sampler(s, space);
|
|
194
|
+
if (!sample)
|
|
195
|
+
return undefined;
|
|
196
|
+
const scale = s.colorScale;
|
|
197
|
+
const [low, high] = space.zRange;
|
|
198
|
+
const floor = low - s.z;
|
|
199
|
+
const point = { x: 0, y: 0, z: 0 };
|
|
200
|
+
return Geo.parametric({
|
|
201
|
+
segments: Math.max(2, Math.round(s.segments)),
|
|
202
|
+
vertex: (u, v) => {
|
|
217
203
|
sample(u, v, point);
|
|
218
|
-
return space.offset(point.x, point.y,
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
204
|
+
return space.offset(point.x, point.y, floor);
|
|
205
|
+
},
|
|
206
|
+
...(scale.length > 0
|
|
207
|
+
? {
|
|
208
|
+
color: (u, v) => {
|
|
209
|
+
sample(u, v, point);
|
|
210
|
+
return colorAt(scale, high > low ? (point.z + s.z - low) / (high - low) : 0);
|
|
211
|
+
},
|
|
225
212
|
}
|
|
213
|
+
: {}),
|
|
214
|
+
revision: revisionOf(`${keyOf(s, space)}|${JSON.stringify(scale)}|floor`),
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
/** The last lines drawn for each surface, kept while what they are drawn from is unchanged. */
|
|
218
|
+
const linesDrawn = new WeakMap();
|
|
219
|
+
function meshLines(s, space) {
|
|
220
|
+
const count = Math.round(s.meshLines);
|
|
221
|
+
const sample = count > 0 ? sampler(s, space) : null;
|
|
222
|
+
if (!sample)
|
|
223
|
+
return [];
|
|
224
|
+
const steps = Math.max(2, Math.round(s.segments));
|
|
225
|
+
const key = `${keyOf(s, space)}|${count}|${steps}`;
|
|
226
|
+
const kept = linesDrawn.get(s);
|
|
227
|
+
if (kept?.key === key)
|
|
228
|
+
return kept.lines;
|
|
229
|
+
const lines = [];
|
|
230
|
+
const point = { x: 0, y: 0, z: 0 };
|
|
231
|
+
const at = (u, v) => {
|
|
232
|
+
sample(u, v, point);
|
|
233
|
+
return space.offset(point.x, point.y, point.z);
|
|
234
|
+
};
|
|
235
|
+
for (let i = 0; i <= count; i++) {
|
|
236
|
+
const fixed = i / count;
|
|
237
|
+
for (let j = 0; j < steps; j++) {
|
|
238
|
+
lines.push(at(fixed, j / steps), at(fixed, (j + 1) / steps));
|
|
239
|
+
lines.push(at(j / steps, fixed), at((j + 1) / steps, fixed));
|
|
226
240
|
}
|
|
227
|
-
this._lines = lines;
|
|
228
|
-
this._linesKey = key;
|
|
229
|
-
return lines;
|
|
230
241
|
}
|
|
231
|
-
};
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
], SurfacePlot3d.prototype, "expression", void 0);
|
|
235
|
-
__decorate([
|
|
236
|
-
property({ default: null, tween: lerpDomain, kind: "range", defaultMin: -3, defaultMax: 3 })
|
|
237
|
-
], SurfacePlot3d.prototype, "uDomain", void 0);
|
|
238
|
-
__decorate([
|
|
239
|
-
property({ default: null, tween: lerpDomain, kind: "range", defaultMin: -3, defaultMax: 3 })
|
|
240
|
-
], SurfacePlot3d.prototype, "vDomain", void 0);
|
|
241
|
-
__decorate([
|
|
242
|
-
property({ default: {}, tween: lerpParams })
|
|
243
|
-
], SurfacePlot3d.prototype, "params", void 0);
|
|
244
|
-
__decorate([
|
|
245
|
-
property({ default: 48, min: 2, max: 256, step: 1, animatable: false })
|
|
246
|
-
], SurfacePlot3d.prototype, "segments", void 0);
|
|
247
|
-
__decorate([
|
|
248
|
-
property({ default: [], mapper: readScale, tween: lerpScale, kind: "vector" })
|
|
249
|
-
], SurfacePlot3d.prototype, "colorScale", void 0);
|
|
250
|
-
__decorate([
|
|
251
|
-
property({ default: 12, min: 0, max: 64, step: 1, animatable: false })
|
|
252
|
-
], SurfacePlot3d.prototype, "meshLines", void 0);
|
|
253
|
-
__decorate([
|
|
254
|
-
property({ default: "#0b1220", kind: "color" })
|
|
255
|
-
], SurfacePlot3d.prototype, "meshColor", void 0);
|
|
256
|
-
__decorate([
|
|
257
|
-
property({ default: 0, min: 0, max: 1, step: 0.01 })
|
|
258
|
-
], SurfacePlot3d.prototype, "floorShadow", void 0);
|
|
259
|
-
__decorate([
|
|
260
|
-
command({ args: ["expression"] })
|
|
261
|
-
], SurfacePlot3d.prototype, "morphTo", null);
|
|
262
|
-
__decorate([
|
|
263
|
-
command({ args: ["params"] })
|
|
264
|
-
], SurfacePlot3d.prototype, "paramsTo", null);
|
|
265
|
-
__decorate([
|
|
266
|
-
command({ args: ["uDomain", "vDomain"] })
|
|
267
|
-
], SurfacePlot3d.prototype, "domainTo", null);
|
|
268
|
-
SurfacePlot3d = __decorate([
|
|
269
|
-
node({
|
|
270
|
-
key: "surfacePlot3d",
|
|
271
|
-
within: ["axes3d"],
|
|
272
|
-
closed: true,
|
|
273
|
-
forkable: true,
|
|
274
|
-
layout: { acceptsChildren: true },
|
|
275
|
-
seed: { expression: "sin(x) * cos(y)", fill: PLOT_COLOR },
|
|
276
|
-
})
|
|
277
|
-
], SurfacePlot3d);
|
|
278
|
-
export { SurfacePlot3d };
|
|
242
|
+
linesDrawn.set(s, { key, lines });
|
|
243
|
+
return lines;
|
|
244
|
+
}
|
|
279
245
|
function equationOf(source) {
|
|
280
246
|
const equation = parseSurface(source, surfaceParams(source));
|
|
281
247
|
return equation instanceof Error ? null : equation;
|