@womp/spark-agent 0.3.0 → 1.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 +18 -3
- package/dist/client.js +15 -15
- package/dist/generated/scene-declarations.d.ts +1 -1
- package/dist/generated/scene-declarations.js +1 -1
- package/dist/kakapo-capability.d.ts +44 -5
- package/dist/kakapo-capability.js +155 -36
- package/dist/kakapo.d.ts +5 -4
- package/dist/kakapo.js +6 -2
- package/dist/pricing.js +29 -9
- package/dist/runtime.d.ts +36 -17
- package/dist/runtime.js +119 -137
- package/dist/server/express.js +4 -2
- package/dist/server/index.d.ts +1 -1
- package/dist/server/index.js +1 -1
- package/dist/server/standalone.js +9 -3
- package/dist/server/store.js +1 -3
- package/package.json +7 -4
- package/.env.example +0 -4
- package/dist/coordinates.d.ts +0 -22
- package/dist/coordinates.js +0 -123
- package/dist/generated/kakapo-declarations.d.ts +0 -1
- package/dist/generated/kakapo-declarations.js +0 -3
- package/dist/kakapo-capability-api.d.ts +0 -18
- package/dist/kakapo-capability-api.js +0 -1
- package/dist/kakapo-scene-skill.d.ts +0 -1
- package/dist/kakapo-scene-skill.js +0 -54
- package/dist/womp-scene-api.d.ts +0 -246
- package/dist/womp-scene-api.js +0 -844
package/dist/womp-scene-api.js
DELETED
|
@@ -1,844 +0,0 @@
|
|
|
1
|
-
import { convertRotationBasis, fromEngineDimensions, fromEngineBlend, fromEngineMirrorRotation, fromEnginePosition, toEngineBlend, toEngineDimensions, toEngineMirrorGoop, toEngineMirrorRotation, toEnginePosition, } from "./coordinates.js";
|
|
2
|
-
export const NodeType = {
|
|
3
|
-
Primitive: 0,
|
|
4
|
-
Union: 1,
|
|
5
|
-
Light: 2,
|
|
6
|
-
Curve: 3,
|
|
7
|
-
Group: 4,
|
|
8
|
-
Text: 5,
|
|
9
|
-
Field: 6,
|
|
10
|
-
SVG: 7,
|
|
11
|
-
Mesh: 8,
|
|
12
|
-
Decal: 9,
|
|
13
|
-
OpenSCAD: 10,
|
|
14
|
-
Socket: 11,
|
|
15
|
-
};
|
|
16
|
-
export const PrimitiveTypeValue = {
|
|
17
|
-
Sphere: 0,
|
|
18
|
-
Cylinder: 1,
|
|
19
|
-
Cube: 2,
|
|
20
|
-
Cone: 3,
|
|
21
|
-
Torus: 4,
|
|
22
|
-
Pyramid: 9,
|
|
23
|
-
};
|
|
24
|
-
export const OperationType = {
|
|
25
|
-
Subtract: 0,
|
|
26
|
-
Union: 1,
|
|
27
|
-
Stain: 2,
|
|
28
|
-
Intersect: 3,
|
|
29
|
-
};
|
|
30
|
-
export const LightTypeValue = {
|
|
31
|
-
Rect: 0,
|
|
32
|
-
Sphere: 1,
|
|
33
|
-
Distant: 2,
|
|
34
|
-
};
|
|
35
|
-
const MIN_SIZE = 0.01;
|
|
36
|
-
const MAX_SIZE = 1000;
|
|
37
|
-
const MAX_CURVE_POINTS = 100;
|
|
38
|
-
const NODE_TYPE_BY_KIND = {
|
|
39
|
-
primitive: NodeType.Primitive,
|
|
40
|
-
union: NodeType.Union,
|
|
41
|
-
light: NodeType.Light,
|
|
42
|
-
curve: NodeType.Curve,
|
|
43
|
-
group: NodeType.Group,
|
|
44
|
-
text: NodeType.Text,
|
|
45
|
-
field: NodeType.Field,
|
|
46
|
-
svg: NodeType.SVG,
|
|
47
|
-
mesh: NodeType.Mesh,
|
|
48
|
-
decal: NodeType.Decal,
|
|
49
|
-
openScad: NodeType.OpenSCAD,
|
|
50
|
-
socket: NodeType.Socket,
|
|
51
|
-
};
|
|
52
|
-
const NODE_KIND_BY_TYPE = new Map(Object.entries(NODE_TYPE_BY_KIND).map(([kind, type]) => [type, kind]));
|
|
53
|
-
const PUBLIC_PRIMITIVES = new Map([
|
|
54
|
-
[PrimitiveTypeValue.Sphere, "sphere"],
|
|
55
|
-
[PrimitiveTypeValue.Cylinder, "cylinder"],
|
|
56
|
-
[PrimitiveTypeValue.Cube, "box"],
|
|
57
|
-
[PrimitiveTypeValue.Cone, "cone"],
|
|
58
|
-
[PrimitiveTypeValue.Torus, "torus"],
|
|
59
|
-
[PrimitiveTypeValue.Pyramid, "pyramid"],
|
|
60
|
-
]);
|
|
61
|
-
const PUBLIC_PRIMITIVE_VALUES = new Map([...PUBLIC_PRIMITIVES].map(([value, primitive]) => [primitive, value]));
|
|
62
|
-
const OPERATIONS = ["subtract", "union", "brush", "intersect"];
|
|
63
|
-
const LIGHT_TYPES = ["rect", "sphere", "distant"];
|
|
64
|
-
const WRAPS = ["disabled", "always", "whiteSpace"];
|
|
65
|
-
const ALIGNS = ["left", "center", "right"];
|
|
66
|
-
const CREATABLE_KINDS = new Set([
|
|
67
|
-
"primitive",
|
|
68
|
-
"union",
|
|
69
|
-
"light",
|
|
70
|
-
"curve",
|
|
71
|
-
"group",
|
|
72
|
-
"text",
|
|
73
|
-
]);
|
|
74
|
-
function clamp(value, min, max) {
|
|
75
|
-
if (!Number.isFinite(value))
|
|
76
|
-
return min;
|
|
77
|
-
return Math.max(min, Math.min(max, value));
|
|
78
|
-
}
|
|
79
|
-
function finite(value, label) {
|
|
80
|
-
const number = typeof value === "number" ? value : Number(value);
|
|
81
|
-
if (!Number.isFinite(number))
|
|
82
|
-
throw new Error(`${label} must be a finite number`);
|
|
83
|
-
return number;
|
|
84
|
-
}
|
|
85
|
-
function vector(value, label) {
|
|
86
|
-
return {
|
|
87
|
-
x: finite(value?.x, `${label}.x`),
|
|
88
|
-
y: finite(value?.y, `${label}.y`),
|
|
89
|
-
z: finite(value?.z, `${label}.z`),
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
function color255(value) {
|
|
93
|
-
return {
|
|
94
|
-
r: Math.round(value.x * 255),
|
|
95
|
-
g: Math.round(value.y * 255),
|
|
96
|
-
b: Math.round(value.z * 255),
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
function color1(value) {
|
|
100
|
-
const input = value;
|
|
101
|
-
return {
|
|
102
|
-
x: clamp(finite(input.r ?? input.x, "color.r"), 0, 255) / 255,
|
|
103
|
-
y: clamp(finite(input.g ?? input.y, "color.g"), 0, 255) / 255,
|
|
104
|
-
z: clamp(finite(input.b ?? input.z, "color.b"), 0, 255) / 255,
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
function runtimeEnum(values) {
|
|
108
|
-
const names = {};
|
|
109
|
-
for (const [name, value] of Object.entries(values))
|
|
110
|
-
names[value] = name;
|
|
111
|
-
return { ...values, ...names };
|
|
112
|
-
}
|
|
113
|
-
function normalizePrimitiveSize(primitive, size) {
|
|
114
|
-
switch (primitive) {
|
|
115
|
-
case "sphere":
|
|
116
|
-
return { x: size.x, y: size.x, z: size.x };
|
|
117
|
-
case "cylinder":
|
|
118
|
-
case "cone":
|
|
119
|
-
case "torus":
|
|
120
|
-
case "pyramid":
|
|
121
|
-
return { x: size.x, y: size.y, z: size.x };
|
|
122
|
-
default:
|
|
123
|
-
return size;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
function scale(value, amount) {
|
|
127
|
-
return { x: value.x * amount, y: value.y * amount, z: value.z * amount };
|
|
128
|
-
}
|
|
129
|
-
function convertAABB(box) {
|
|
130
|
-
return {
|
|
131
|
-
min: {
|
|
132
|
-
x: fromEnginePosition({ x: 0, y: 0, z: box.max.z }).x,
|
|
133
|
-
y: fromEnginePosition({ x: 0, y: box.min.y, z: 0 }).y,
|
|
134
|
-
z: fromEnginePosition({ x: box.max.x, y: 0, z: 0 }).z,
|
|
135
|
-
},
|
|
136
|
-
max: {
|
|
137
|
-
x: fromEnginePosition({ x: 0, y: 0, z: box.min.z }).x,
|
|
138
|
-
y: fromEnginePosition({ x: 0, y: box.max.y, z: 0 }).y,
|
|
139
|
-
z: fromEnginePosition({ x: box.min.x, y: 0, z: 0 }).z,
|
|
140
|
-
},
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
function lookAt(origin, target) {
|
|
144
|
-
const forward = normalize({
|
|
145
|
-
x: target.x - origin.x,
|
|
146
|
-
y: target.y - origin.y,
|
|
147
|
-
z: target.z - origin.z,
|
|
148
|
-
});
|
|
149
|
-
let up = { x: 0, y: 1, z: 0 };
|
|
150
|
-
let right = cross(up, forward);
|
|
151
|
-
if (Math.hypot(right.x, right.y, right.z) < 1e-6) {
|
|
152
|
-
up = { x: 0, y: 0, z: 1 };
|
|
153
|
-
right = cross(up, forward);
|
|
154
|
-
}
|
|
155
|
-
right = normalize(right);
|
|
156
|
-
const correctedUp = cross(forward, right);
|
|
157
|
-
return {
|
|
158
|
-
x: (Math.asin(clamp(correctedUp.z, -1, 1)) * 180) / Math.PI,
|
|
159
|
-
y: (Math.atan2(-right.z, forward.z) * 180) / Math.PI,
|
|
160
|
-
z: (Math.atan2(-correctedUp.x, correctedUp.y) * 180) / Math.PI,
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
function normalize(value) {
|
|
164
|
-
const length = Math.hypot(value.x, value.y, value.z);
|
|
165
|
-
return length < 1e-10
|
|
166
|
-
? { x: 0, y: 0, z: 0 }
|
|
167
|
-
: { x: value.x / length, y: value.y / length, z: value.z / length };
|
|
168
|
-
}
|
|
169
|
-
function cross(left, right) {
|
|
170
|
-
return {
|
|
171
|
-
x: left.y * right.z - left.z * right.y,
|
|
172
|
-
y: left.z * right.x - left.x * right.z,
|
|
173
|
-
z: left.x * right.y - left.y * right.x,
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
export function createWompSceneApi(context) {
|
|
177
|
-
const { scene } = context;
|
|
178
|
-
const actualParent = (parentId) => (parentId === 0 ? context.rootId : parentId);
|
|
179
|
-
const publicParent = (parentId) => parentId === null || parentId === context.rootId ? 0 : parentId;
|
|
180
|
-
const requireNode = (id) => {
|
|
181
|
-
context.requireNode(id);
|
|
182
|
-
return scene.getNode(id);
|
|
183
|
-
};
|
|
184
|
-
const ancestorScale = (id, includeSelf = false) => {
|
|
185
|
-
let total = 1;
|
|
186
|
-
let current = includeSelf
|
|
187
|
-
? requireNode(id)
|
|
188
|
-
: scene.getNode(requireNode(id).parentId ?? context.rootId);
|
|
189
|
-
const visited = new Set();
|
|
190
|
-
while (current.id !== context.rootId && !visited.has(current.id)) {
|
|
191
|
-
visited.add(current.id);
|
|
192
|
-
if (current.kind === "union")
|
|
193
|
-
total *= current.transform.scale.x;
|
|
194
|
-
const parentId = current.parentId;
|
|
195
|
-
if (parentId === null || parentId === context.rootId)
|
|
196
|
-
break;
|
|
197
|
-
current = scene.getNode(parentId);
|
|
198
|
-
}
|
|
199
|
-
return total;
|
|
200
|
-
};
|
|
201
|
-
const nodePosition = (id) => fromEnginePosition(scale(requireNode(id).transform.position, ancestorScale(id)));
|
|
202
|
-
const nodeRotation = (id) => convertRotationBasis(requireNode(id).transform.rotation);
|
|
203
|
-
const hasCsgBaseBefore = (parentId, nodeId, index) => {
|
|
204
|
-
const siblings = scene.getNodeChildren(parentId).filter(({ id }) => id !== nodeId);
|
|
205
|
-
const targetIndex = index ?? siblings.length;
|
|
206
|
-
return siblings
|
|
207
|
-
.slice(0, targetIndex)
|
|
208
|
-
.some((sibling) => sibling.kind === "union" ||
|
|
209
|
-
sibling.kind === "group" ||
|
|
210
|
-
("operation" in sibling && sibling.operation === "union"));
|
|
211
|
-
};
|
|
212
|
-
const nodeSize = (id) => {
|
|
213
|
-
const node = requireNode(id);
|
|
214
|
-
const parentScale = ancestorScale(id);
|
|
215
|
-
if (node.kind === "union" || node.kind === "group") {
|
|
216
|
-
const size = node.transform.scale.x * parentScale;
|
|
217
|
-
return { x: size, y: size, z: size };
|
|
218
|
-
}
|
|
219
|
-
const size = fromEngineDimensions(scale(node.transform.scale, parentScale));
|
|
220
|
-
return node.kind === "primitive" ? normalizePrimitiveSize(node.primitive, size) : size;
|
|
221
|
-
};
|
|
222
|
-
const update = (id, changes) => {
|
|
223
|
-
context.call("updateNode", [id, changes], () => scene.updateNode(id, changes));
|
|
224
|
-
};
|
|
225
|
-
const material = (id) => {
|
|
226
|
-
context.requireMaterial(id);
|
|
227
|
-
return scene.getMaterial(id);
|
|
228
|
-
};
|
|
229
|
-
const writeMaterial = (id, changes) => {
|
|
230
|
-
context.requireMaterial(id);
|
|
231
|
-
context.call("updateMaterial", [id, changes], () => scene.updateMaterial(id, changes));
|
|
232
|
-
};
|
|
233
|
-
const requireCurve = (id) => {
|
|
234
|
-
const node = requireNode(id);
|
|
235
|
-
if (node.kind !== "curve")
|
|
236
|
-
throw new Error(`Node ${id} is not a Curve node`);
|
|
237
|
-
return node;
|
|
238
|
-
};
|
|
239
|
-
const requireText = (id) => {
|
|
240
|
-
const node = requireNode(id);
|
|
241
|
-
if (node.kind !== "text")
|
|
242
|
-
throw new Error(`Node ${id} is not a Text node`);
|
|
243
|
-
return node;
|
|
244
|
-
};
|
|
245
|
-
const requireLight = (id) => {
|
|
246
|
-
const node = requireNode(id);
|
|
247
|
-
if (node.kind !== "light")
|
|
248
|
-
throw new Error(`Node ${id} is not a Light node`);
|
|
249
|
-
return node;
|
|
250
|
-
};
|
|
251
|
-
const requireMirrorNode = (id) => {
|
|
252
|
-
const node = requireNode(id);
|
|
253
|
-
if (node.kind !== "primitive" && node.kind !== "curve") {
|
|
254
|
-
throw new Error("Mirror APIs are only valid for Primitive and Curve nodes");
|
|
255
|
-
}
|
|
256
|
-
return node;
|
|
257
|
-
};
|
|
258
|
-
const mirrorSlot = (slot) => {
|
|
259
|
-
const value = finite(slot, "Mirror slot");
|
|
260
|
-
if (!Number.isInteger(value) || value < 0 || value > 3) {
|
|
261
|
-
throw new Error("Mirror slot must be an integer from 0 to 3");
|
|
262
|
-
}
|
|
263
|
-
return value;
|
|
264
|
-
};
|
|
265
|
-
const copyMirrors = (id) => requireMirrorNode(id).mirrors.map((plane) => ({
|
|
266
|
-
...plane,
|
|
267
|
-
position: { ...plane.position },
|
|
268
|
-
rotation: { ...plane.rotation },
|
|
269
|
-
...(plane.customRotation ? { customRotation: { ...plane.customRotation } } : {}),
|
|
270
|
-
}));
|
|
271
|
-
const curvePoints = (id) => requireCurve(id).points.map((point) => ({
|
|
272
|
-
...point,
|
|
273
|
-
position: { ...point.position },
|
|
274
|
-
rotation: { ...point.rotation },
|
|
275
|
-
scale: { ...point.scale },
|
|
276
|
-
}));
|
|
277
|
-
const requirePoint = (curveId, pointIndex) => {
|
|
278
|
-
const index = Math.round(finite(pointIndex, "pointIndex"));
|
|
279
|
-
const count = requireCurve(curveId).points.length;
|
|
280
|
-
if (index < 0 || index >= count)
|
|
281
|
-
throw new Error(`Curve point ${index} is out of range`);
|
|
282
|
-
return index;
|
|
283
|
-
};
|
|
284
|
-
const pointPosition = (curveId, point) => fromEnginePosition(scale(point.position, ancestorScale(curveId)));
|
|
285
|
-
const pointSize = (curveId, point) => fromEngineDimensions(scale(point.scale, ancestorScale(curveId)));
|
|
286
|
-
const setPoint = (curveId, pointIndex, patch) => {
|
|
287
|
-
const points = curvePoints(curveId);
|
|
288
|
-
const index = requirePoint(curveId, pointIndex);
|
|
289
|
-
points[index] = { ...points[index], ...patch };
|
|
290
|
-
update(curveId, { points });
|
|
291
|
-
};
|
|
292
|
-
const applyPointInput = (curveId, index, input) => {
|
|
293
|
-
const patch = {};
|
|
294
|
-
const parentScale = ancestorScale(curveId);
|
|
295
|
-
if (input.pos) {
|
|
296
|
-
patch.position = scale(toEnginePosition(vector(input.pos, "pos")), 1 / parentScale);
|
|
297
|
-
}
|
|
298
|
-
if (input.rot)
|
|
299
|
-
patch.rotation = convertRotationBasis(vector(input.rot, "rot"));
|
|
300
|
-
if (input.size) {
|
|
301
|
-
patch.scale = scale(toEngineDimensions(vector(input.size, "size")), 1 / parentScale);
|
|
302
|
-
}
|
|
303
|
-
if (input.fixed !== undefined)
|
|
304
|
-
patch.fixed = Boolean(input.fixed);
|
|
305
|
-
if (input.round !== undefined)
|
|
306
|
-
patch.round = clamp(finite(input.round, "round"), 0, 1);
|
|
307
|
-
if (input.materialId !== undefined) {
|
|
308
|
-
const materialId = finite(input.materialId, "materialId");
|
|
309
|
-
context.requireMaterial(materialId);
|
|
310
|
-
patch.materialId = materialId;
|
|
311
|
-
}
|
|
312
|
-
if (Object.keys(patch).length)
|
|
313
|
-
setPoint(curveId, index, patch);
|
|
314
|
-
};
|
|
315
|
-
const setNodeSize = (id, sizeValue) => {
|
|
316
|
-
const node = requireNode(id);
|
|
317
|
-
const requestedSize = vector(sizeValue, "size");
|
|
318
|
-
const size = node.kind === "primitive"
|
|
319
|
-
? normalizePrimitiveSize(node.primitive, requestedSize)
|
|
320
|
-
: requestedSize;
|
|
321
|
-
if (size.x <= 0 || size.y <= 0 || size.z <= 0)
|
|
322
|
-
throw new Error("Size must be positive");
|
|
323
|
-
const parentScale = ancestorScale(id);
|
|
324
|
-
const converted = node.kind === "union" || node.kind === "group"
|
|
325
|
-
? { ...node.transform.scale, x: clamp(size.x, MIN_SIZE, MAX_SIZE) / parentScale }
|
|
326
|
-
: scale(toEngineDimensions(size), 1 / parentScale);
|
|
327
|
-
context.call("setNodeScale", [id, converted], () => scene.setNodeScale(id, converted));
|
|
328
|
-
};
|
|
329
|
-
const getNodeAABB = async (id) => {
|
|
330
|
-
requireNode(id);
|
|
331
|
-
const box = await context.callAsync("getNodeBoundingBox", [id], () => context.engine.getNodeBoundingBox(id));
|
|
332
|
-
const converted = convertAABB(box);
|
|
333
|
-
const empty = converted.min.x === converted.max.x &&
|
|
334
|
-
converted.min.y === converted.max.y &&
|
|
335
|
-
converted.min.z === converted.max.z;
|
|
336
|
-
if (empty && requireNode(id).parentId !== 0) {
|
|
337
|
-
throw new Error("Kakapo exposes renderer bounds for top-level Areas; inspect the containing Area.");
|
|
338
|
-
}
|
|
339
|
-
return converted;
|
|
340
|
-
};
|
|
341
|
-
const insertCurvePoint = (curveId, pointIndex, point = {}) => {
|
|
342
|
-
const points = curvePoints(curveId);
|
|
343
|
-
if (points.length >= MAX_CURVE_POINTS)
|
|
344
|
-
throw new Error("A curve cannot exceed 100 points");
|
|
345
|
-
const index = Math.round(finite(pointIndex, "pointIndex"));
|
|
346
|
-
if (index < 0 || index > points.length)
|
|
347
|
-
throw new Error("Curve insertion index is out of range");
|
|
348
|
-
const source = points[Math.max(0, index - 1)] ?? points[0];
|
|
349
|
-
if (!source)
|
|
350
|
-
throw new Error("Cannot add to an empty curve");
|
|
351
|
-
points.splice(index, 0, {
|
|
352
|
-
...source,
|
|
353
|
-
position: { ...source.position },
|
|
354
|
-
rotation: { ...source.rotation },
|
|
355
|
-
scale: { ...source.scale },
|
|
356
|
-
});
|
|
357
|
-
update(curveId, { points });
|
|
358
|
-
applyPointInput(curveId, index, point);
|
|
359
|
-
return index;
|
|
360
|
-
};
|
|
361
|
-
const api = {
|
|
362
|
-
NodeType: runtimeEnum(NodeType),
|
|
363
|
-
PrimitiveType: runtimeEnum(PrimitiveTypeValue),
|
|
364
|
-
OperationType: runtimeEnum(OperationType),
|
|
365
|
-
LightType: runtimeEnum(LightTypeValue),
|
|
366
|
-
nodeCreate: (type, parentId = 0) => {
|
|
367
|
-
const kind = NODE_KIND_BY_TYPE.get(type);
|
|
368
|
-
if (!kind || !CREATABLE_KINDS.has(kind)) {
|
|
369
|
-
throw new Error(`nodeCreate() invalid node type: ${type}`);
|
|
370
|
-
}
|
|
371
|
-
if (["primitive", "curve", "text"].includes(kind) && parentId === 0) {
|
|
372
|
-
throw new Error(`Can't create a ${kind} without a parent area`);
|
|
373
|
-
}
|
|
374
|
-
const parent = kind === "light" ? 0 : actualParent(parentId);
|
|
375
|
-
if (kind === "light" && parentId !== 0)
|
|
376
|
-
throw new Error("Lights must be created at root");
|
|
377
|
-
if (parent !== 0)
|
|
378
|
-
context.requireNode(parent);
|
|
379
|
-
const parentScale = parent === 0 || parent === context.rootId ? 1 : ancestorScale(parent, true);
|
|
380
|
-
const properties = kind === "primitive"
|
|
381
|
-
? {
|
|
382
|
-
color: { x: 1, y: 1, z: 1 },
|
|
383
|
-
primitive: "sphere",
|
|
384
|
-
operation: "union",
|
|
385
|
-
blend: 0,
|
|
386
|
-
round: 0,
|
|
387
|
-
materialId: context.getDefaultMaterialId(),
|
|
388
|
-
transform: {
|
|
389
|
-
position: scale(toEnginePosition({ x: 0, y: 2, z: 0 }), 1 / parentScale),
|
|
390
|
-
rotation: { x: 0, y: 0, z: 0 },
|
|
391
|
-
scale: scale(toEngineDimensions({ x: 4, y: 4, z: 4 }), 1 / parentScale),
|
|
392
|
-
},
|
|
393
|
-
}
|
|
394
|
-
: kind === "curve"
|
|
395
|
-
? {
|
|
396
|
-
primitive: "sphere",
|
|
397
|
-
operation: "union",
|
|
398
|
-
blend: toEngineBlend(0.36),
|
|
399
|
-
density: 80,
|
|
400
|
-
roundness: 2,
|
|
401
|
-
smoothing: 0.02,
|
|
402
|
-
materialId: context.getDefaultMaterialId(),
|
|
403
|
-
points: [
|
|
404
|
-
{
|
|
405
|
-
position: scale(toEnginePosition({ x: 0, y: 2, z: 0 }), 1 / parentScale),
|
|
406
|
-
rotation: { x: 0, y: 0, z: 0 },
|
|
407
|
-
scale: scale(toEngineDimensions({ x: 4, y: 4, z: 4 }), 1 / parentScale),
|
|
408
|
-
materialId: context.getDefaultMaterialId(),
|
|
409
|
-
fixed: false,
|
|
410
|
-
round: 0,
|
|
411
|
-
},
|
|
412
|
-
{
|
|
413
|
-
position: scale(toEnginePosition({ x: 6, y: 2, z: 0 }), 1 / parentScale),
|
|
414
|
-
rotation: { x: 0, y: 0, z: 0 },
|
|
415
|
-
scale: scale(toEngineDimensions({ x: 4, y: 4, z: 4 }), 1 / parentScale),
|
|
416
|
-
materialId: context.getDefaultMaterialId(),
|
|
417
|
-
fixed: false,
|
|
418
|
-
round: 0,
|
|
419
|
-
},
|
|
420
|
-
],
|
|
421
|
-
}
|
|
422
|
-
: kind === "text"
|
|
423
|
-
? {
|
|
424
|
-
text: "Hello Womp",
|
|
425
|
-
fontFamily: "Roboto",
|
|
426
|
-
weight: 500,
|
|
427
|
-
materialId: context.getDefaultMaterialId(),
|
|
428
|
-
transform: {
|
|
429
|
-
position: scale(toEnginePosition({ x: 0, y: 0.07, z: 0.58 }), 1 / parentScale),
|
|
430
|
-
rotation: { x: 0, y: 0, z: 0 },
|
|
431
|
-
scale: scale(toEngineDimensions({ x: 1.8, y: 1.8, z: 0.8 }), 1 / parentScale),
|
|
432
|
-
},
|
|
433
|
-
}
|
|
434
|
-
: kind === "union" || kind === "group"
|
|
435
|
-
? {
|
|
436
|
-
transform: {
|
|
437
|
-
position: { x: 0, y: 0, z: 0 },
|
|
438
|
-
rotation: { x: 0, y: 0, z: 0 },
|
|
439
|
-
scale: { x: 1 / parentScale, y: 1, z: 1 },
|
|
440
|
-
},
|
|
441
|
-
...(kind === "union" ? { resolution: 0.35 } : {}),
|
|
442
|
-
}
|
|
443
|
-
: {};
|
|
444
|
-
const created = context.call("createNode", [{ kind, parentId: parent, properties }], () => scene.createNode({ kind, parentId: parent, properties }));
|
|
445
|
-
context.trackNode(created.id);
|
|
446
|
-
return created.id;
|
|
447
|
-
},
|
|
448
|
-
nodeDelete: (id) => {
|
|
449
|
-
if (id === context.rootId)
|
|
450
|
-
throw new Error("The scene root cannot be deleted");
|
|
451
|
-
requireNode(id);
|
|
452
|
-
context.call("deleteNode", [id], () => scene.deleteNode(id));
|
|
453
|
-
},
|
|
454
|
-
nodeClone: (id) => {
|
|
455
|
-
requireNode(id);
|
|
456
|
-
const clone = context.call("cloneNode", [id], () => scene.cloneNode(id));
|
|
457
|
-
context.trackNode(clone.id);
|
|
458
|
-
return clone.id;
|
|
459
|
-
},
|
|
460
|
-
nodeList: () => scene
|
|
461
|
-
.listNodes()
|
|
462
|
-
.filter((node) => node.id !== context.rootId)
|
|
463
|
-
.filter((node) => {
|
|
464
|
-
try {
|
|
465
|
-
context.requireNode(node.id);
|
|
466
|
-
return true;
|
|
467
|
-
}
|
|
468
|
-
catch {
|
|
469
|
-
return false;
|
|
470
|
-
}
|
|
471
|
-
})
|
|
472
|
-
.map((node) => node.id),
|
|
473
|
-
nodeChildren: (parentId) => scene
|
|
474
|
-
.getNodeChildren(actualParent(parentId))
|
|
475
|
-
.filter((node) => {
|
|
476
|
-
try {
|
|
477
|
-
context.requireNode(node.id);
|
|
478
|
-
return true;
|
|
479
|
-
}
|
|
480
|
-
catch {
|
|
481
|
-
return false;
|
|
482
|
-
}
|
|
483
|
-
})
|
|
484
|
-
.map((node) => node.id),
|
|
485
|
-
nodeSetParent: (id, parentId, index) => {
|
|
486
|
-
requireNode(id);
|
|
487
|
-
const parent = actualParent(parentId);
|
|
488
|
-
context.requireNode(parent);
|
|
489
|
-
const node = requireNode(id);
|
|
490
|
-
if (parent !== context.rootId &&
|
|
491
|
-
requireNode(parent).kind === "union" &&
|
|
492
|
-
"operation" in node &&
|
|
493
|
-
node.operation !== "union") {
|
|
494
|
-
if (!hasCsgBaseBefore(parent, id, index)) {
|
|
495
|
-
throw new Error("Subtract, Stain, and Intersect nodes must follow Union geometry in their parent Area");
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
context.call("setNodeParent", [id, parent, index], () => scene.setNodeParent(id, parent, index));
|
|
499
|
-
},
|
|
500
|
-
nodeGetType: (id) => NODE_TYPE_BY_KIND[requireNode(id).kind],
|
|
501
|
-
nodeGetName: (id) => requireNode(id).name,
|
|
502
|
-
nodeSetName: (id, name) => {
|
|
503
|
-
requireNode(id);
|
|
504
|
-
const normalized = String(name).trim();
|
|
505
|
-
if (!normalized)
|
|
506
|
-
throw new Error("Name cannot be empty");
|
|
507
|
-
context.call("setNodeName", [id, normalized], () => scene.setNodeName(id, normalized));
|
|
508
|
-
},
|
|
509
|
-
nodeGetParentId: (id) => publicParent(requireNode(id).parentId),
|
|
510
|
-
nodeGetPos: nodePosition,
|
|
511
|
-
nodeSetPos: (id, position) => {
|
|
512
|
-
const converted = scale(toEnginePosition(vector(position, "pos")), 1 / ancestorScale(id));
|
|
513
|
-
context.call("setNodePosition", [id, converted], () => scene.setNodePosition(id, converted));
|
|
514
|
-
},
|
|
515
|
-
nodeGetRot: nodeRotation,
|
|
516
|
-
nodeSetRot: (id, rotation) => {
|
|
517
|
-
const converted = convertRotationBasis(vector(rotation, "rot"));
|
|
518
|
-
context.call("setNodeRotation", [id, converted], () => scene.setNodeRotation(id, converted));
|
|
519
|
-
},
|
|
520
|
-
nodeGetSize: nodeSize,
|
|
521
|
-
nodeSetSize: setNodeSize,
|
|
522
|
-
nodeGetHide: (id) => {
|
|
523
|
-
const node = requireNode(id);
|
|
524
|
-
return "hidden" in node ? Boolean(node.hidden) : false;
|
|
525
|
-
},
|
|
526
|
-
nodeSetHide: (id, hidden) => {
|
|
527
|
-
requireNode(id);
|
|
528
|
-
context.call("setNodeVisible", [id, !hidden], () => scene.setNodeVisible(id, !hidden));
|
|
529
|
-
},
|
|
530
|
-
nodeGetOp: (id) => {
|
|
531
|
-
const node = requireNode(id);
|
|
532
|
-
return "operation" in node ? OPERATIONS.indexOf(node.operation) : OperationType.Union;
|
|
533
|
-
},
|
|
534
|
-
nodeSetOp: (id, operation) => {
|
|
535
|
-
const value = OPERATIONS[Math.round(finite(operation, "operation"))];
|
|
536
|
-
if (!value)
|
|
537
|
-
throw new Error("Operation must be from 0 to 3");
|
|
538
|
-
const node = requireNode(id);
|
|
539
|
-
if (value !== "union" && node.parentId !== null) {
|
|
540
|
-
const parent = scene.getNode(node.parentId);
|
|
541
|
-
if (parent.kind === "union") {
|
|
542
|
-
const index = scene
|
|
543
|
-
.getNodeChildren(parent.id)
|
|
544
|
-
.findIndex(({ id: siblingId }) => siblingId === id);
|
|
545
|
-
if (!hasCsgBaseBefore(parent.id, id, index)) {
|
|
546
|
-
throw new Error("Subtract, Stain, and Intersect nodes must follow Union geometry in their parent Area");
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
|
-
context.call("setNodeOperation", [id, value], () => scene.setNodeOperation(id, value));
|
|
551
|
-
},
|
|
552
|
-
nodeGetBlend: (id) => {
|
|
553
|
-
const node = requireNode(id);
|
|
554
|
-
return "blend" in node ? fromEngineBlend(node.blend) : 0;
|
|
555
|
-
},
|
|
556
|
-
nodeSetBlend: (id, blend) => update(id, { blend: toEngineBlend(finite(blend, "blend")) }),
|
|
557
|
-
nodeGetRound: (id) => {
|
|
558
|
-
const node = requireNode(id);
|
|
559
|
-
if (node.kind !== "primitive" && node.kind !== "text")
|
|
560
|
-
throw new Error("Round is unsupported");
|
|
561
|
-
return node.round;
|
|
562
|
-
},
|
|
563
|
-
nodeSetRound: (id, round) => update(id, { round: clamp(finite(round, "round"), 0, 1) }),
|
|
564
|
-
nodeGetColor: (id) => {
|
|
565
|
-
const node = requireNode(id);
|
|
566
|
-
return color255(node.kind === "primitive" || node.kind === "light" ? node.color : { x: 0, y: 0, z: 0 });
|
|
567
|
-
},
|
|
568
|
-
nodeSetColor: (id, color) => update(id, { color: color1(color) }),
|
|
569
|
-
nodeGetMaterialId: (id) => {
|
|
570
|
-
const node = requireNode(id);
|
|
571
|
-
return "materialId" in node ? node.materialId : null;
|
|
572
|
-
},
|
|
573
|
-
nodeSetMaterialId: (id, materialId) => {
|
|
574
|
-
context.requireMaterial(materialId);
|
|
575
|
-
context.call("setNodeMaterial", [id, materialId], () => scene.setNodeMaterial(id, materialId));
|
|
576
|
-
},
|
|
577
|
-
nodeGetResolution: (id) => {
|
|
578
|
-
const node = requireNode(id);
|
|
579
|
-
if (node.kind !== "union")
|
|
580
|
-
throw new Error("Resolution is only valid for Unions");
|
|
581
|
-
return node.resolution;
|
|
582
|
-
},
|
|
583
|
-
nodeSetResolution: (id, resolution) => {
|
|
584
|
-
const node = requireNode(id);
|
|
585
|
-
if (node.kind !== "union")
|
|
586
|
-
throw new Error("Resolution is only valid for Unions");
|
|
587
|
-
update(id, { resolution: clamp(finite(resolution, "resolution"), 0, 0.65) });
|
|
588
|
-
},
|
|
589
|
-
nodeGetLightType: (id) => LIGHT_TYPES.indexOf(requireLight(id).lightType),
|
|
590
|
-
nodeSetLightType: (id, lightType) => {
|
|
591
|
-
const value = LIGHT_TYPES[Math.round(finite(lightType, "lightType"))];
|
|
592
|
-
if (!value)
|
|
593
|
-
throw new Error("LightType must be from 0 to 2");
|
|
594
|
-
update(id, { lightType: value });
|
|
595
|
-
},
|
|
596
|
-
nodeGetPower: (id) => requireLight(id).power,
|
|
597
|
-
nodeSetPower: (id, power) => update(id, { power: clamp(finite(power, "power"), 0, 100) }),
|
|
598
|
-
nodeGetText: (id) => requireText(id).text,
|
|
599
|
-
nodeSetText: (id, text) => update(id, { text: String(text) }),
|
|
600
|
-
nodeGetFont: (id) => requireText(id).fontFamily,
|
|
601
|
-
nodeSetFont: (id, font) => {
|
|
602
|
-
const match = context.fonts.find((family) => family.name.toLowerCase() === font.toLowerCase());
|
|
603
|
-
if (!match && context.fonts.length)
|
|
604
|
-
throw new Error(`Unknown font "${font}"`);
|
|
605
|
-
update(id, { fontFamily: match?.name ?? font });
|
|
606
|
-
},
|
|
607
|
-
nodeGetWeight: (id) => requireText(id).weight,
|
|
608
|
-
nodeSetWeight: (id, weight) => update(id, { weight: clamp(finite(weight, "weight"), 100, 900) }),
|
|
609
|
-
nodeGetItalic: (id) => requireText(id).italic,
|
|
610
|
-
nodeSetItalic: (id, italic) => update(id, { italic: Boolean(italic) }),
|
|
611
|
-
nodeGetAlign: (id) => ALIGNS.indexOf(requireText(id).align),
|
|
612
|
-
nodeSetAlign: (id, align) => {
|
|
613
|
-
const value = ALIGNS[Math.round(finite(align, "align"))];
|
|
614
|
-
if (!value)
|
|
615
|
-
throw new Error("Align must be from 0 to 2");
|
|
616
|
-
update(id, { align: value });
|
|
617
|
-
},
|
|
618
|
-
nodeGetWrap: (id) => WRAPS.indexOf(requireText(id).wrap),
|
|
619
|
-
nodeSetWrap: (id, wrap) => {
|
|
620
|
-
const value = WRAPS[Math.round(finite(wrap, "wrap"))];
|
|
621
|
-
if (!value)
|
|
622
|
-
throw new Error("Wrap must be from 0 to 2");
|
|
623
|
-
update(id, { wrap: value });
|
|
624
|
-
},
|
|
625
|
-
nodeGetWidth: (id) => requireText(id).width,
|
|
626
|
-
nodeSetWidth: (id, width) => update(id, { width: finite(width, "width") }),
|
|
627
|
-
nodeGetSpacing: (id) => requireText(id).spacing,
|
|
628
|
-
nodeSetSpacing: (id, spacing) => update(id, { spacing: clamp(finite(spacing, "spacing"), -1, 1) }),
|
|
629
|
-
nodeGetLineHeight: (id) => requireText(id).lineHeight,
|
|
630
|
-
nodeSetLineHeight: (id, lineHeight) => update(id, { lineHeight: clamp(finite(lineHeight, "lineHeight"), 0.5, 3) }),
|
|
631
|
-
nodeGetDensity: (id) => requireCurve(id).density,
|
|
632
|
-
nodeSetDensity: (id, density) => update(id, { density: clamp(Math.round(finite(density, "density")), 0, 250) }),
|
|
633
|
-
nodeGetRoundness: (id) => requireCurve(id).roundness,
|
|
634
|
-
nodeSetRoundness: (id, roundness) => update(id, { roundness: clamp(Math.round(finite(roundness, "roundness")), 1, 10) }),
|
|
635
|
-
nodeGetSmoothing: (id) => requireCurve(id).smoothing,
|
|
636
|
-
nodeSetSmoothing: (id, smoothing) => update(id, { smoothing: clamp(finite(smoothing, "smoothing"), 0, 1) }),
|
|
637
|
-
nodeGetPrimType: (id) => {
|
|
638
|
-
const node = requireNode(id);
|
|
639
|
-
if (node.kind !== "primitive" && node.kind !== "curve")
|
|
640
|
-
throw new Error("Primitive type is unsupported");
|
|
641
|
-
const value = PUBLIC_PRIMITIVE_VALUES.get(node.primitive);
|
|
642
|
-
if (value === undefined)
|
|
643
|
-
throw new Error(`Primitive type '${node.primitive}' is unsupported`);
|
|
644
|
-
return value;
|
|
645
|
-
},
|
|
646
|
-
nodeSetPrimType: (id, primitive) => {
|
|
647
|
-
const value = PUBLIC_PRIMITIVES.get(Math.round(finite(primitive, "primitive")));
|
|
648
|
-
if (!value)
|
|
649
|
-
throw new Error("PrimitiveType must be Sphere, Cylinder, Cube, Cone, Torus, or Pyramid");
|
|
650
|
-
const node = requireNode(id);
|
|
651
|
-
if (node.kind !== "primitive" && node.kind !== "curve") {
|
|
652
|
-
throw new Error("Primitive type is unsupported");
|
|
653
|
-
}
|
|
654
|
-
if (node.kind === "primitive") {
|
|
655
|
-
const parentScale = ancestorScale(id);
|
|
656
|
-
const publicSize = fromEngineDimensions(scale(node.transform.scale, parentScale));
|
|
657
|
-
const normalized = normalizePrimitiveSize(value, publicSize);
|
|
658
|
-
update(id, {
|
|
659
|
-
primitive: value,
|
|
660
|
-
transform: {
|
|
661
|
-
...node.transform,
|
|
662
|
-
scale: scale(toEngineDimensions(normalized), 1 / parentScale),
|
|
663
|
-
},
|
|
664
|
-
});
|
|
665
|
-
return;
|
|
666
|
-
}
|
|
667
|
-
update(id, { primitive: value });
|
|
668
|
-
},
|
|
669
|
-
nodeGetMirror: (id, slot) => {
|
|
670
|
-
const plane = requireMirrorNode(id).mirrors[mirrorSlot(slot)];
|
|
671
|
-
if (plane.value < 0)
|
|
672
|
-
return { axis: "disabled", planePosition: 0, goop: 0 };
|
|
673
|
-
const axis = fromEngineMirrorRotation(plane.rotation);
|
|
674
|
-
const position = fromEnginePosition(scale(plane.position, ancestorScale(id)));
|
|
675
|
-
return {
|
|
676
|
-
axis: axis ?? "custom",
|
|
677
|
-
planePosition: axis ? position[axis] : 0,
|
|
678
|
-
goop: fromEngineBlend(plane.value),
|
|
679
|
-
};
|
|
680
|
-
},
|
|
681
|
-
nodeSetMirror: (id, slot, axis, planePosition = 0, goop = 0) => {
|
|
682
|
-
const mirrors = copyMirrors(id);
|
|
683
|
-
const index = mirrorSlot(slot);
|
|
684
|
-
const normalizedAxis = String(axis).toLowerCase();
|
|
685
|
-
if (normalizedAxis === "disabled") {
|
|
686
|
-
mirrors[index] = { ...mirrors[index], value: -1 };
|
|
687
|
-
update(id, { mirrors });
|
|
688
|
-
return;
|
|
689
|
-
}
|
|
690
|
-
if (normalizedAxis !== "x" && normalizedAxis !== "y" && normalizedAxis !== "z") {
|
|
691
|
-
throw new Error('Mirror axis must be "x", "y", "z", or "disabled"');
|
|
692
|
-
}
|
|
693
|
-
const publicPosition = { x: 0, y: 0, z: 0 };
|
|
694
|
-
publicPosition[normalizedAxis] = finite(planePosition, "Mirror plane position");
|
|
695
|
-
const rotation = toEngineMirrorRotation(normalizedAxis);
|
|
696
|
-
const constraint = normalizedAxis === "y" ? 1 : 3;
|
|
697
|
-
mirrors[index] = {
|
|
698
|
-
position: scale(toEnginePosition(publicPosition), 1 / ancestorScale(id)),
|
|
699
|
-
rotation,
|
|
700
|
-
value: toEngineMirrorGoop(finite(goop, "Mirror goop")),
|
|
701
|
-
hide: 0,
|
|
702
|
-
hideMirrorPlane: true,
|
|
703
|
-
constraint,
|
|
704
|
-
...(constraint === 3 ? { customRotation: rotation } : {}),
|
|
705
|
-
};
|
|
706
|
-
update(id, { mirrors });
|
|
707
|
-
},
|
|
708
|
-
nodeGetThickness: (id) => {
|
|
709
|
-
const node = requireNode(id);
|
|
710
|
-
if (node.kind !== "primitive" && node.kind !== "union")
|
|
711
|
-
throw new Error("Thickness is unsupported");
|
|
712
|
-
return node.thickness;
|
|
713
|
-
},
|
|
714
|
-
nodeSetThickness: (id, thickness) => update(id, { thickness: clamp(finite(thickness, "thickness"), 0, 1000) }),
|
|
715
|
-
curvePointCount: (curveId) => requireCurve(curveId).points.length,
|
|
716
|
-
curvePointAdd: (curveId, point = {}) => insertCurvePoint(curveId, requireCurve(curveId).points.length, point),
|
|
717
|
-
curvePointInsert: insertCurvePoint,
|
|
718
|
-
curvePointRemove: (curveId, pointIndex) => {
|
|
719
|
-
const points = curvePoints(curveId);
|
|
720
|
-
if (points.length <= 1)
|
|
721
|
-
throw new Error("A curve must keep at least one point");
|
|
722
|
-
points.splice(requirePoint(curveId, pointIndex), 1);
|
|
723
|
-
update(curveId, { points });
|
|
724
|
-
},
|
|
725
|
-
curvePointGetPos: (curveId, pointIndex) => pointPosition(curveId, requireCurve(curveId).points[requirePoint(curveId, pointIndex)]),
|
|
726
|
-
curvePointSetPos: (curveId, pointIndex, position) => setPoint(curveId, pointIndex, {
|
|
727
|
-
position: scale(toEnginePosition(vector(position, "pos")), 1 / ancestorScale(curveId)),
|
|
728
|
-
}),
|
|
729
|
-
curvePointGetRot: (curveId, pointIndex) => convertRotationBasis(requireCurve(curveId).points[requirePoint(curveId, pointIndex)].rotation),
|
|
730
|
-
curvePointSetRot: (curveId, pointIndex, rotation) => setPoint(curveId, pointIndex, { rotation: convertRotationBasis(vector(rotation, "rot")) }),
|
|
731
|
-
curvePointGetSize: (curveId, pointIndex) => pointSize(curveId, requireCurve(curveId).points[requirePoint(curveId, pointIndex)]),
|
|
732
|
-
curvePointSetSize: (curveId, pointIndex, sizeValue) => setPoint(curveId, pointIndex, {
|
|
733
|
-
scale: scale(toEngineDimensions(vector(sizeValue, "size")), 1 / ancestorScale(curveId)),
|
|
734
|
-
}),
|
|
735
|
-
curvePointGetFixed: (curveId, pointIndex) => requireCurve(curveId).points[requirePoint(curveId, pointIndex)].fixed,
|
|
736
|
-
curvePointSetFixed: (curveId, pointIndex, fixed) => setPoint(curveId, pointIndex, { fixed: Boolean(fixed) }),
|
|
737
|
-
curvePointGetRound: (curveId, pointIndex) => requireCurve(curveId).points[requirePoint(curveId, pointIndex)].round,
|
|
738
|
-
curvePointSetRound: (curveId, pointIndex, round) => setPoint(curveId, pointIndex, { round: clamp(finite(round, "round"), 0, 1) }),
|
|
739
|
-
curvePointGetMaterialId: (curveId, pointIndex) => requireCurve(curveId).points[requirePoint(curveId, pointIndex)].materialId,
|
|
740
|
-
curvePointSetMaterialId: (curveId, pointIndex, materialId) => {
|
|
741
|
-
context.requireMaterial(materialId);
|
|
742
|
-
setPoint(curveId, pointIndex, { materialId });
|
|
743
|
-
},
|
|
744
|
-
materialCreate: () => {
|
|
745
|
-
const created = context.call("createMaterial", [], () => scene.createMaterial({
|
|
746
|
-
color: { x: 189 / 255, y: 189 / 255, z: 189 / 255 },
|
|
747
|
-
roughness: 0.22,
|
|
748
|
-
}));
|
|
749
|
-
context.trackMaterial(created.id);
|
|
750
|
-
return created.id;
|
|
751
|
-
},
|
|
752
|
-
materialDelete: (id) => {
|
|
753
|
-
context.requireMaterial(id);
|
|
754
|
-
context.call("deleteMaterial", [id], () => scene.deleteMaterial(id));
|
|
755
|
-
context.untrackMaterial(id);
|
|
756
|
-
},
|
|
757
|
-
materialList: () => context.listMaterialIds(),
|
|
758
|
-
materialGetName: (id) => {
|
|
759
|
-
material(id);
|
|
760
|
-
return context.getMaterialName(id);
|
|
761
|
-
},
|
|
762
|
-
materialSetName: (id, name) => {
|
|
763
|
-
material(id);
|
|
764
|
-
const normalized = String(name).trim();
|
|
765
|
-
if (!normalized)
|
|
766
|
-
throw new Error("Material name cannot be empty");
|
|
767
|
-
context.setMaterialName(id, normalized);
|
|
768
|
-
},
|
|
769
|
-
materialGetColor: (id) => color255(material(id).data.color),
|
|
770
|
-
materialSetColor: (id, color) => writeMaterial(id, { color: color1(color) }),
|
|
771
|
-
materialGetSecondaryColor: (id) => color255(material(id).data.secondaryColor),
|
|
772
|
-
materialSetSecondaryColor: (id, color) => writeMaterial(id, { secondaryColor: color1(color) }),
|
|
773
|
-
materialGetSubsurfaceColor: (id) => color255(material(id).data.subsurface),
|
|
774
|
-
materialSetSubsurfaceColor: (id, color) => writeMaterial(id, { subsurface: color1(color) }),
|
|
775
|
-
materialGetRoughness: (id) => material(id).data.roughness,
|
|
776
|
-
materialSetRoughness: (id, value) => writeMaterial(id, { roughness: clamp(finite(value, "roughness"), 0, 1) }),
|
|
777
|
-
materialGetMetalness: (id) => material(id).data.metalness,
|
|
778
|
-
materialSetMetalness: (id, value) => writeMaterial(id, { metalness: clamp(finite(value, "metalness"), 0, 1) }),
|
|
779
|
-
materialGetTransmittance: (id) => material(id).data.transmittance,
|
|
780
|
-
materialSetTransmittance: (id, value) => writeMaterial(id, { transmittance: clamp(finite(value, "transmittance"), 0, 1) }),
|
|
781
|
-
materialGetTranslucency: (id) => material(id).data.translucency,
|
|
782
|
-
materialSetTranslucency: (id, value) => writeMaterial(id, { translucency: clamp(finite(value, "translucency"), 0, 1) }),
|
|
783
|
-
materialGetIor: (id) => material(id).data.indexOfRefraction,
|
|
784
|
-
materialSetIor: (id, value) => writeMaterial(id, { indexOfRefraction: clamp(finite(value, "ior"), 1, 2) }),
|
|
785
|
-
materialGetSheen: (id) => material(id).data.sheen,
|
|
786
|
-
materialSetSheen: (id, value) => writeMaterial(id, { sheen: clamp(finite(value, "sheen"), 0, 1) }),
|
|
787
|
-
materialGetSheenRoughness: (id) => material(id).data.sheenRoughness,
|
|
788
|
-
materialSetSheenRoughness: (id, value) => writeMaterial(id, { sheenRoughness: clamp(finite(value, "sheenRoughness"), 0, 1) }),
|
|
789
|
-
materialGetSpecularTint: (id) => material(id).data.specularTint,
|
|
790
|
-
materialSetSpecularTint: (id, value) => writeMaterial(id, { specularTint: clamp(finite(value, "specularTint"), 0, 1) }),
|
|
791
|
-
materialGetAbsorption: (id) => material(id).data.absorption,
|
|
792
|
-
materialSetAbsorption: (id, value) => writeMaterial(id, { absorption: clamp(finite(value, "absorption"), 0, 1) }),
|
|
793
|
-
materialGetEmission: (id) => material(id).data.emission,
|
|
794
|
-
materialSetEmission: (id, value) => writeMaterial(id, { emission: clamp(finite(value, "emission"), 0, 1) }),
|
|
795
|
-
materialGetIridescence: (id) => material(id).data.iridescence,
|
|
796
|
-
materialSetIridescence: (id, value) => writeMaterial(id, { iridescence: clamp(finite(value, "iridescence"), 0, 1) }),
|
|
797
|
-
materialGetTranslucencyWeight: (id) => material(id).data.translucencyWeight,
|
|
798
|
-
materialSetTranslucencyWeight: (id, value) => writeMaterial(id, { translucencyWeight: clamp(finite(value, "translucencyWeight"), 0, 1) }),
|
|
799
|
-
materialGetDispersion: (id) => material(id).data.dispersion,
|
|
800
|
-
materialSetDispersion: (id, value) => writeMaterial(id, { dispersion: clamp(finite(value, "dispersion"), 0, 1) }),
|
|
801
|
-
materialGetSurfaceOpacity: (id) => material(id).data.surfaceOpacity,
|
|
802
|
-
materialSetSurfaceOpacity: (id, value) => writeMaterial(id, { surfaceOpacity: clamp(finite(value, "surfaceOpacity"), 0, 1) }),
|
|
803
|
-
listFontFamilies: () => context.fonts.map((family) => ({
|
|
804
|
-
name: family.name,
|
|
805
|
-
variants: family.fonts.map((font) => ({
|
|
806
|
-
weight: String(font.weight),
|
|
807
|
-
italic: font.italic,
|
|
808
|
-
})),
|
|
809
|
-
})),
|
|
810
|
-
print: (...values) => context.print(...values),
|
|
811
|
-
nodeGetAABB: getNodeAABB,
|
|
812
|
-
nodeResize: async (id, dimensions) => {
|
|
813
|
-
const node = requireNode(id);
|
|
814
|
-
if (node.kind !== "union" || publicParent(node.parentId) !== 0) {
|
|
815
|
-
throw new Error("nodeResize() only supports top-level Areas");
|
|
816
|
-
}
|
|
817
|
-
const box = await getNodeAABB(id);
|
|
818
|
-
const current = nodeSize(id);
|
|
819
|
-
const axis = dimensions.x !== undefined
|
|
820
|
-
? "x"
|
|
821
|
-
: dimensions.y !== undefined
|
|
822
|
-
? "y"
|
|
823
|
-
: dimensions.z !== undefined
|
|
824
|
-
? "z"
|
|
825
|
-
: undefined;
|
|
826
|
-
if (!axis)
|
|
827
|
-
return;
|
|
828
|
-
const target = finite(dimensions[axis], `dimensions.${axis}`);
|
|
829
|
-
const currentDimension = box.max[axis] - box.min[axis];
|
|
830
|
-
if (target <= 0 || currentDimension <= 0)
|
|
831
|
-
throw new Error("Resize dimensions must be positive");
|
|
832
|
-
const amount = target / currentDimension;
|
|
833
|
-
setNodeSize(id, scale(current, amount));
|
|
834
|
-
},
|
|
835
|
-
aabbCenter: (box) => ({
|
|
836
|
-
x: (box.min.x + box.max.x) / 2,
|
|
837
|
-
y: (box.min.y + box.max.y) / 2,
|
|
838
|
-
z: (box.min.z + box.max.z) / 2,
|
|
839
|
-
}),
|
|
840
|
-
aabbRadius: (box) => Math.hypot(box.max.x - box.min.x, box.max.y - box.min.y, box.max.z - box.min.z) / 2,
|
|
841
|
-
lookAt,
|
|
842
|
-
};
|
|
843
|
-
return api;
|
|
844
|
-
}
|