@vim3d/core 0.2.0 → 0.2.1
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 +6 -2
- package/compile.js +195 -23
- package/contexts.d.ts +55 -0
- package/contexts.js +310 -0
- package/esm/compile.js +195 -23
- package/esm/contexts.js +304 -0
- package/esm/evaluate.js +56 -7
- package/esm/graph.js +27 -5
- package/esm/index.js +1 -0
- package/esm/registry.js +93 -0
- package/evaluate.d.ts +2 -2
- package/evaluate.js +56 -7
- package/graph.d.ts +3 -0
- package/graph.js +27 -5
- package/index.d.ts +3 -1
- package/index.js +4 -1
- package/model.d.ts +6 -0
- package/package.json +2 -2
- package/registry.d.ts +14 -0
- package/registry.js +98 -0
- package/types.d.ts +72 -3
package/README.md
CHANGED
|
@@ -30,5 +30,9 @@ evaluated scalar values and final local and world transforms; a renderer
|
|
|
30
30
|
does not run expressions or constraints again.
|
|
31
31
|
|
|
32
32
|
For a procedural channel, use `add channel` and drive its `value` port
|
|
33
|
-
with `expr`. For
|
|
34
|
-
|
|
33
|
+
with `expr`. For live browser sources (such as Web Audio), declare
|
|
34
|
+
`liveChannels` in `compileScene` options and supply per-frame samples in
|
|
35
|
+
`evaluateFrame(scene, frame, { liveChannels })`; off-time reads (`chf`,
|
|
36
|
+
`cht`, or non-unit `register`) and `{ deterministic: true }` reject live
|
|
37
|
+
graphs. For authored path vertices, use `begin draw`, one XYZ triplet per
|
|
38
|
+
line, and `end`.
|
package/compile.js
CHANGED
|
@@ -3,8 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.compileScene = compileScene;
|
|
4
4
|
const parser_1 = require("@vim3d/parser");
|
|
5
5
|
const channels_js_1 = require("./channels.js");
|
|
6
|
+
const contexts_js_1 = require("./contexts.js");
|
|
6
7
|
const expression_js_1 = require("./expression.js");
|
|
7
8
|
const graph_js_1 = require("./graph.js");
|
|
9
|
+
const registry_js_1 = require("./registry.js");
|
|
8
10
|
const model_js_1 = require("./model.js");
|
|
9
11
|
const types_js_1 = require("./types.js");
|
|
10
12
|
const aliases = {
|
|
@@ -13,8 +15,11 @@ const aliases = {
|
|
|
13
15
|
};
|
|
14
16
|
const primitives = new Set(['cube', 'grid', 'sphere', 'ellipse', 'ellipseFace', 'circle', 'circleFace', 'ring']);
|
|
15
17
|
const prefixes = { geo: 'geo', curve: 'curve', null: 'null', camera: 'cam', light: 'light', channel: 'ch' };
|
|
16
|
-
const deferred = new Set(['parent', 'expr', 'register', 'ref', 'path', 'lookat', 'children']);
|
|
18
|
+
const deferred = new Set(['parent', 'expr', 'register', 'ref', 'path', 'lookat', 'children', 'connect', 'set']);
|
|
17
19
|
const isChannel = (node) => 'ports' in node;
|
|
20
|
+
const isObject = (node) => 'authored' in node;
|
|
21
|
+
const isExtension = (node) => 'definition' in node;
|
|
22
|
+
const isBuiltInPath = (path) => /^\/(?:obj|ch)\//.test(path);
|
|
18
23
|
const commandOf = (text) => Object.hasOwn(aliases, text) ? aliases[text] : text;
|
|
19
24
|
const location = ({ file, line }) => ({ file, line });
|
|
20
25
|
const prop = (name, value) => ({ name, type: typeof value, value });
|
|
@@ -75,6 +80,7 @@ function compileScene(source, options = {}) {
|
|
|
75
80
|
},
|
|
76
81
|
expandDirectives: true,
|
|
77
82
|
reservedCommands: ['expr', 'parent'],
|
|
83
|
+
preserveText: true,
|
|
78
84
|
});
|
|
79
85
|
if (expanded.problems.length)
|
|
80
86
|
return { diagnostics: expanded.problems.map(problem => ({
|
|
@@ -89,6 +95,8 @@ function compileScene(source, options = {}) {
|
|
|
89
95
|
}
|
|
90
96
|
}
|
|
91
97
|
function compile(lines, root, fps, options) {
|
|
98
|
+
const registry = (0, registry_js_1.createContextRegistry)(options.contexts);
|
|
99
|
+
const extensions = new contexts_js_1.Extensions(registry);
|
|
92
100
|
const objects = [];
|
|
93
101
|
const channels = [];
|
|
94
102
|
const objNames = new Map();
|
|
@@ -99,6 +107,26 @@ function compile(lines, root, fps, options) {
|
|
|
99
107
|
const pending = [];
|
|
100
108
|
const timed = [];
|
|
101
109
|
let nextId = 0;
|
|
110
|
+
for (const [name, portNames] of Object.entries(options.liveChannels ?? {})) {
|
|
111
|
+
if (!(0, channels_js_1.validSegment)(name))
|
|
112
|
+
(0, types_js_1.fail)('invalid-live-channel', 'Invalid live channel name: ' + name, root);
|
|
113
|
+
if (!Array.isArray(portNames) || !portNames.length) {
|
|
114
|
+
(0, types_js_1.fail)('invalid-live-channel', 'Live channel must declare at least one port: ' + name, root);
|
|
115
|
+
}
|
|
116
|
+
const ports = new Map();
|
|
117
|
+
for (const portName of portNames) {
|
|
118
|
+
if (typeof portName !== 'string' || !(0, channels_js_1.validSegment)(portName)) {
|
|
119
|
+
(0, types_js_1.fail)('invalid-live-channel', 'Invalid live channel port name: ' + String(portName), root);
|
|
120
|
+
}
|
|
121
|
+
if (ports.has(portName)) {
|
|
122
|
+
(0, types_js_1.fail)('invalid-live-channel', 'Duplicate live channel port: /ch/' + name + '/' + portName, root);
|
|
123
|
+
}
|
|
124
|
+
ports.set(portName, { live: true, source: root });
|
|
125
|
+
}
|
|
126
|
+
const channel = { id: nextId++, name, source: root, live: true, ports };
|
|
127
|
+
channels.push(channel);
|
|
128
|
+
chNames.set(name, channel);
|
|
129
|
+
}
|
|
102
130
|
function nextName(type, names) {
|
|
103
131
|
let n = counters.get(type) ?? 0;
|
|
104
132
|
let name;
|
|
@@ -152,6 +180,30 @@ function compile(lines, root, fps, options) {
|
|
|
152
180
|
(0, types_js_1.fail)('invalid-path', 'Expected an object parameter path: ' + path, source);
|
|
153
181
|
return scalar(getObject(name, source), param, source);
|
|
154
182
|
};
|
|
183
|
+
const extensionAddress = (path, source) => {
|
|
184
|
+
if (!path?.startsWith('/'))
|
|
185
|
+
(0, types_js_1.fail)('invalid-path', 'Expected an absolute path: ' + path, source);
|
|
186
|
+
return normalizePath(path, '/', source);
|
|
187
|
+
};
|
|
188
|
+
const extensionSource = (address, source) => {
|
|
189
|
+
if (address.startsWith('/ch/')) {
|
|
190
|
+
const path = channelOutput(address, source);
|
|
191
|
+
return { address: path, path, type: 'number', port: 'value', stage: 'ch' };
|
|
192
|
+
}
|
|
193
|
+
if (address.startsWith('/obj/')) {
|
|
194
|
+
const [, , name, member, ...extra] = address.split('/');
|
|
195
|
+
if (!member || extra.length)
|
|
196
|
+
(0, types_js_1.fail)('invalid-path', 'Expected an object output path: ' + address, source);
|
|
197
|
+
const object = getObject(name, source);
|
|
198
|
+
if (member === 'worldMatrix' || member === 'localMatrix' || member === 'snapshot') {
|
|
199
|
+
return { address, path: (0, model_js_1.worldStep)(object), port: member === 'worldMatrix' ? 'value' : member,
|
|
200
|
+
type: member === 'snapshot' ? 'object' : 'matrix4', stage: 'obj' };
|
|
201
|
+
}
|
|
202
|
+
const path = scalar(object, member, source);
|
|
203
|
+
return { address: path, path, type: 'number', port: 'value', stage: 'obj' };
|
|
204
|
+
}
|
|
205
|
+
return extensions.output(address, source);
|
|
206
|
+
};
|
|
155
207
|
let current = addObject('camera', root, 'Cam0');
|
|
156
208
|
let viewCamera;
|
|
157
209
|
let backgroundColor;
|
|
@@ -171,6 +223,10 @@ function compile(lines, root, fps, options) {
|
|
|
171
223
|
else if (curve && command !== 'end') {
|
|
172
224
|
(0, types_js_1.fail)('invalid-curve', 'Expected a curve vertex or end', source);
|
|
173
225
|
}
|
|
226
|
+
else if (command === 'node') {
|
|
227
|
+
(0, model_js_1.checkArity)(command, args, [2], source);
|
|
228
|
+
current = extensions.add(extensionAddress(args[0], source), args[1], source);
|
|
229
|
+
}
|
|
174
230
|
else if (command === 'begin') {
|
|
175
231
|
(0, model_js_1.checkArity)(command, args, [0, 1], source);
|
|
176
232
|
if (args.length && args[0] !== 'draw')
|
|
@@ -214,13 +270,16 @@ function compile(lines, root, fps, options) {
|
|
|
214
270
|
}
|
|
215
271
|
else if (command === 'select') {
|
|
216
272
|
(0, model_js_1.checkArity)(command, args, [1], source);
|
|
217
|
-
|
|
273
|
+
const address = args[0].startsWith('/') && !isBuiltInPath(args[0]) ? extensionAddress(args[0], source) : args[0];
|
|
274
|
+
current = extensions.nodes.get(address) ?? lookup(args[0], 'either', source);
|
|
218
275
|
}
|
|
219
276
|
else if (command === 'name') {
|
|
220
277
|
(0, model_js_1.checkArity)(command, args, [1], source);
|
|
221
278
|
const [name] = args;
|
|
222
279
|
if (!(0, channels_js_1.validSegment)(name))
|
|
223
280
|
(0, types_js_1.fail)('invalid-name', 'Invalid name: ' + name, source);
|
|
281
|
+
if (isExtension(current))
|
|
282
|
+
(0, types_js_1.fail)('invalid-subject', 'name requires an object or channel', source);
|
|
224
283
|
if (isChannel(current))
|
|
225
284
|
rename(chNames, current, name, source);
|
|
226
285
|
else
|
|
@@ -265,10 +324,10 @@ function compile(lines, root, fps, options) {
|
|
|
265
324
|
timed.push({ frame, source, command: eventCommand, args: values, objectCount: nextId });
|
|
266
325
|
}
|
|
267
326
|
else if (deferred.has(command)) {
|
|
268
|
-
pending.push({ command, args, source, current });
|
|
327
|
+
pending.push({ command, args, source, current, text: line.text });
|
|
269
328
|
}
|
|
270
329
|
else if (model_js_1.editCommands.has(command)) {
|
|
271
|
-
if (
|
|
330
|
+
if (!isObject(current))
|
|
272
331
|
(0, types_js_1.fail)('invalid-subject', command + ' requires an object', source);
|
|
273
332
|
(0, model_js_1.propertyEdit)(command, args, current, source)(current.authored);
|
|
274
333
|
}
|
|
@@ -291,6 +350,8 @@ function compile(lines, root, fps, options) {
|
|
|
291
350
|
expressionPorts.set((0, model_js_1.channelPath)(channel) + '/' + name, { node: channel, name, port });
|
|
292
351
|
}
|
|
293
352
|
const inputs = new Map();
|
|
353
|
+
const offTimeRefs = [];
|
|
354
|
+
const contextWires = [];
|
|
294
355
|
const depend = (path, on) => {
|
|
295
356
|
if (!inputs.has(path))
|
|
296
357
|
inputs.set(path, new Set());
|
|
@@ -298,6 +359,22 @@ function compile(lines, root, fps, options) {
|
|
|
298
359
|
};
|
|
299
360
|
const bind = (text, path, source) => (0, expression_js_1.bindExpression)((0, expression_js_1.parseExpression)(text, source), (ref, name) => {
|
|
300
361
|
const address = normalizePath(ref, path.slice(0, path.lastIndexOf('/')), source);
|
|
362
|
+
const targetStage = path.startsWith('/ch/') ? 'ch' : 'obj';
|
|
363
|
+
if (!isBuiltInPath(address) && registry.get(address.split('/')[1])) {
|
|
364
|
+
const from = extensionSource(address, source);
|
|
365
|
+
if (!(0, registry_js_1.allowedSource)(targetStage, from.stage)) {
|
|
366
|
+
(0, types_js_1.fail)('extension-stage', 'Built-in nodes cannot read ' + address, source);
|
|
367
|
+
}
|
|
368
|
+
if (from.stage !== 'audio' || name !== 'ch') {
|
|
369
|
+
(0, types_js_1.fail)('off-time-extension-reference', 'Only ch() can read built-in audio scalars: ' + address, source);
|
|
370
|
+
}
|
|
371
|
+
if (from.type !== 'number')
|
|
372
|
+
(0, types_js_1.fail)('extension-port-type', 'Expected a number at ' + from.address, source);
|
|
373
|
+
if (!contextWires.some(wire => wire.to === path && wire.from.address === from.address)) {
|
|
374
|
+
contextWires.push({ to: path, input: from.address, from });
|
|
375
|
+
}
|
|
376
|
+
return from.address;
|
|
377
|
+
}
|
|
301
378
|
if (address.startsWith('/obj/')) {
|
|
302
379
|
if (path.startsWith('/ch/'))
|
|
303
380
|
(0, types_js_1.fail)('channel-object-reference', 'Channel expressions cannot read object parameters: ' + address, source);
|
|
@@ -305,30 +382,92 @@ function compile(lines, root, fps, options) {
|
|
|
305
382
|
(0, types_js_1.fail)('off-time-object-reference', name + ' requires a channel: ' + address, source);
|
|
306
383
|
}
|
|
307
384
|
const input = address.startsWith('/ch/') ? channelOutput(address, source) : objectScalar(address, source);
|
|
385
|
+
if (name !== 'ch' && input.startsWith('/ch/'))
|
|
386
|
+
offTimeRefs.push({ path: input, source });
|
|
308
387
|
depend(path, input);
|
|
309
388
|
return input;
|
|
310
389
|
});
|
|
311
|
-
|
|
390
|
+
const driveScalar = (path, expression, source) => {
|
|
391
|
+
if (path.startsWith('/ch/')) {
|
|
392
|
+
const { port } = expressionPorts.get(path);
|
|
393
|
+
if (port.samples || port.expression || port.live)
|
|
394
|
+
(0, types_js_1.fail)('overlapping-drivers', 'Channel already has a driver: ' + path, source);
|
|
395
|
+
port.expression = expression;
|
|
396
|
+
port.source = source;
|
|
397
|
+
}
|
|
398
|
+
else
|
|
399
|
+
addDriver(path, { kind: 'expr', expression, ...range([], 0, source) });
|
|
400
|
+
};
|
|
401
|
+
for (const { command, args, source, current, text: lineText } of pending) {
|
|
312
402
|
if (command === 'parent')
|
|
313
403
|
continue;
|
|
314
404
|
const numberAt = (i, fallback) => args[i] === undefined ? fallback : (0, model_js_1.readNumber)(args[i], source);
|
|
315
|
-
if (command === '
|
|
405
|
+
if (command === 'set') {
|
|
406
|
+
const [target] = args;
|
|
407
|
+
if (!target)
|
|
408
|
+
(0, types_js_1.fail)('invalid-operands', 'Expected set KEY VALUE', source);
|
|
409
|
+
if (!target.startsWith('/') && !isExtension(current))
|
|
410
|
+
(0, types_js_1.fail)('invalid-subject', 'set requires an extension node', source);
|
|
411
|
+
const address = target.startsWith('/') ? extensionAddress(target, source)
|
|
412
|
+
: current.path + '/' + target;
|
|
413
|
+
extensions.property(address, args.slice(1), lineText, source);
|
|
414
|
+
}
|
|
415
|
+
else if (command === 'connect') {
|
|
416
|
+
(0, model_js_1.checkArity)(command, args, [2], source);
|
|
417
|
+
const to = extensionAddress(args[1], source);
|
|
418
|
+
const from = extensionSource(extensionAddress(args[0], source), source);
|
|
419
|
+
if (isBuiltInPath(to)) {
|
|
420
|
+
if (from.stage === 'audio') {
|
|
421
|
+
if (from.type !== 'number')
|
|
422
|
+
(0, types_js_1.fail)('extension-port-type', 'Expected an audio scalar at ' + from.address, source);
|
|
423
|
+
const path = to.startsWith('/ch/') ? channelOutput(to, source) : objectScalar(to, source);
|
|
424
|
+
driveScalar(path, { kind: 'reference', name: 'ch', path: from.address }, source);
|
|
425
|
+
contextWires.push({ to: path, input: from.address, from });
|
|
426
|
+
continue;
|
|
427
|
+
}
|
|
428
|
+
const [, context, name, input, extra] = to.split('/');
|
|
429
|
+
if (context !== 'obj' || input !== 'geometry' || extra !== undefined || from.stage !== 'geo') {
|
|
430
|
+
(0, types_js_1.fail)('extension-stage', 'connect cannot drive this built-in input: ' + to, source);
|
|
431
|
+
}
|
|
432
|
+
const object = getObject(name, source);
|
|
433
|
+
if (object.kind !== 'geo')
|
|
434
|
+
(0, types_js_1.fail)('invalid-subject', 'A geometry connection requires a geometry object', source);
|
|
435
|
+
if (from.type !== 'object')
|
|
436
|
+
(0, types_js_1.fail)('extension-port-type', 'Expected object geometry at ' + to, source);
|
|
437
|
+
if (object.geometry || object.geometrySource)
|
|
438
|
+
(0, types_js_1.fail)('overlapping-drivers', 'Geometry already assigned: ' + to, source);
|
|
439
|
+
object.geometrySource = from.address;
|
|
440
|
+
contextWires.push({ to: (0, model_js_1.worldStep)(object), input, from });
|
|
441
|
+
}
|
|
442
|
+
else
|
|
443
|
+
extensions.input(to, from.type, { kind: 'wire', from }, source);
|
|
444
|
+
}
|
|
445
|
+
else if (command === 'expr') {
|
|
316
446
|
(0, model_js_1.checkArity)(command, args, [2], source);
|
|
317
447
|
const [target, text] = args;
|
|
318
448
|
if (!target.startsWith('/'))
|
|
319
449
|
(0, types_js_1.fail)('invalid-path', 'Expression targets must be absolute', source);
|
|
320
450
|
const address = normalizePath(target, '/', source);
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
const
|
|
325
|
-
|
|
326
|
-
(
|
|
327
|
-
|
|
328
|
-
|
|
451
|
+
if (!isBuiltInPath(address) && (registry.get(address.split('/')[1]) || options.contexts?.length)) {
|
|
452
|
+
const references = new Map();
|
|
453
|
+
const owner = address.slice(0, address.lastIndexOf('/'));
|
|
454
|
+
const expression = (0, expression_js_1.bindExpression)((0, expression_js_1.parseExpression)(text, source), (ref, name) => {
|
|
455
|
+
const from = extensionSource(normalizePath(ref, owner, source), source);
|
|
456
|
+
if (name !== 'ch' && !from.address.startsWith('/ch/')) {
|
|
457
|
+
(0, types_js_1.fail)('off-time-extension-reference', name + ' requires a channel: ' + from.address, source);
|
|
458
|
+
}
|
|
459
|
+
if (from.type !== 'number')
|
|
460
|
+
(0, types_js_1.fail)('extension-port-type', 'Expected a number at ' + from.address, source);
|
|
461
|
+
if (name !== 'ch' && from.address.startsWith('/ch/'))
|
|
462
|
+
offTimeRefs.push({ path: from.address, source });
|
|
463
|
+
references.set(from.address, from);
|
|
464
|
+
return from.address;
|
|
465
|
+
});
|
|
466
|
+
extensions.input(address, 'number', { kind: 'expr', expression, references: [...references.values()], source }, source);
|
|
467
|
+
continue;
|
|
329
468
|
}
|
|
330
|
-
|
|
331
|
-
|
|
469
|
+
const path = address.startsWith('/ch/') ? channelOutput(address, source) : objectScalar(address, source);
|
|
470
|
+
driveScalar(path, bind(text, path, source), source);
|
|
332
471
|
}
|
|
333
472
|
else if (command === 'register' || command === 'ref') {
|
|
334
473
|
const register = command === 'register';
|
|
@@ -344,6 +483,9 @@ function compile(lines, root, fps, options) {
|
|
|
344
483
|
const common = { input, scale: numberAt(end + 1, 1), offset: numberAt(end + 2, 0), ...range(args, end + 4, source) };
|
|
345
484
|
const freq = numberAt(end, 1);
|
|
346
485
|
const shift = numberAt(end + 3, 0);
|
|
486
|
+
if (register && (freq !== 1 || shift !== 0 || args[1] === 'rx' || args[1] === 'ry' || args[1] === 'rz')) {
|
|
487
|
+
offTimeRefs.push({ path: input, source });
|
|
488
|
+
}
|
|
347
489
|
addDriver(path, register ? { kind: 'register', freq, shift, ...common } : { kind: 'ref', ...common });
|
|
348
490
|
depend(path, input);
|
|
349
491
|
}
|
|
@@ -361,7 +503,7 @@ function compile(lines, root, fps, options) {
|
|
|
361
503
|
else {
|
|
362
504
|
(0, model_js_1.checkArity)(command, args, [2, 4], source);
|
|
363
505
|
const target = getObject(args[1], source);
|
|
364
|
-
if (command === 'children' && (args[0] !== 'lookat' ||
|
|
506
|
+
if (command === 'children' && (args[0] !== 'lookat' || !isObject(current))) {
|
|
365
507
|
(0, types_js_1.fail)('invalid-subject', 'Expected children lookat TARGET with an object current', source);
|
|
366
508
|
}
|
|
367
509
|
const activeRange = range(args, 2, source);
|
|
@@ -395,7 +537,7 @@ function compile(lines, root, fps, options) {
|
|
|
395
537
|
const command = commandOf(event.command);
|
|
396
538
|
if (!model_js_1.editCommands.has(command))
|
|
397
539
|
(0, types_js_1.fail)('forbidden-event-command', 'at cannot execute ' + event.command, source);
|
|
398
|
-
if (
|
|
540
|
+
if (!isObject(selected) || selected.id >= objectCount)
|
|
399
541
|
(0, types_js_1.fail)('event-missing-target', 'No current object is available at the event source', source);
|
|
400
542
|
const edit = (0, model_js_1.propertyEdit)(command, args, selected, source);
|
|
401
543
|
edit(state.get(selected));
|
|
@@ -424,10 +566,13 @@ function compile(lines, root, fps, options) {
|
|
|
424
566
|
}
|
|
425
567
|
}
|
|
426
568
|
for (const [path, { node, name, port }] of expressionPorts) {
|
|
427
|
-
if (!port.samples && !port.expression)
|
|
569
|
+
if (!port.samples && !port.expression && !port.live)
|
|
428
570
|
(0, types_js_1.fail)('missing-channel-driver', 'Missing driver for ' + path, port.source);
|
|
429
|
-
|
|
430
|
-
|
|
571
|
+
const nodeType = node.table ? 'source:table' : port.live ? 'source:live' : 'source:expression';
|
|
572
|
+
const nodeProps = node.table
|
|
573
|
+
? [prop('asset', node.table.asset), prop('sampling', node.table)]
|
|
574
|
+
: port.live ? [] : [prop('ast', port.expression)];
|
|
575
|
+
graph.add(path, nodeType, 'number', [prop('target', path), prop('port', name), ...nodeProps], port.source);
|
|
431
576
|
}
|
|
432
577
|
for (const object of objects) {
|
|
433
578
|
const path = (0, model_js_1.objectPath)(object);
|
|
@@ -463,9 +608,36 @@ function compile(lines, root, fps, options) {
|
|
|
463
608
|
for (const [path, dependencies] of inputs)
|
|
464
609
|
for (const input of dependencies)
|
|
465
610
|
graph.depend(path, input);
|
|
611
|
+
extensions.addToGraph(graph);
|
|
612
|
+
for (const { to, input, from } of contextWires)
|
|
613
|
+
graph.wire(to, input, from.path, from.port);
|
|
466
614
|
const finished = graph.finish();
|
|
467
|
-
const
|
|
615
|
+
const livePorts = new Set();
|
|
616
|
+
for (const path of finished.order) {
|
|
617
|
+
const entry = expressionPorts.get(path);
|
|
618
|
+
if (!entry)
|
|
619
|
+
continue;
|
|
620
|
+
if (entry.port.live || [...(inputs.get(path) ?? [])].some(dep => livePorts.has(dep))) {
|
|
621
|
+
livePorts.add(path);
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
for (const ref of offTimeRefs) {
|
|
625
|
+
if (livePorts.has(ref.path)) {
|
|
626
|
+
(0, types_js_1.fail)('off-time-live-channel', 'Live channel does not support off-time reads: ' + ref.path, ref.source);
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
const liveChannels = channels.filter(channel => channel.live).map(model_js_1.channelPath).sort(graph_js_1.comparePaths);
|
|
630
|
+
const audioChannels = new Set(contextWires.filter(({ to, from }) => to.startsWith('/ch/') && from.stage === 'audio').map(({ to }) => to));
|
|
631
|
+
for (const path of finished.order) {
|
|
632
|
+
if (path.startsWith('/ch/') && [...(inputs.get(path) ?? [])].some(input => audioChannels.has(input))) {
|
|
633
|
+
audioChannels.add(path);
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
const scene = (0, types_js_1.freeze)({
|
|
637
|
+
fps,
|
|
638
|
+
...(options.frameCount !== undefined && { frameCount: options.frameCount }),
|
|
468
639
|
graph: finished.graph,
|
|
640
|
+
liveChannels,
|
|
469
641
|
...((viewCamera || backgroundColor || display) && { view: {
|
|
470
642
|
...(viewCamera && { camera: (0, model_js_1.objectPath)(viewCamera) }),
|
|
471
643
|
...(backgroundColor && { backgroundColor }),
|
|
@@ -474,7 +646,7 @@ function compile(lines, root, fps, options) {
|
|
|
474
646
|
});
|
|
475
647
|
objects.sort((a, b) => (0, graph_js_1.comparePaths)((0, model_js_1.objectPath)(a), (0, model_js_1.objectPath)(b)));
|
|
476
648
|
channels.sort((a, b) => (0, graph_js_1.comparePaths)((0, model_js_1.channelPath)(a), (0, model_js_1.channelPath)(b)));
|
|
477
|
-
model_js_1.plans.set(scene, { objects, channels, drivers, events, order: finished.order });
|
|
649
|
+
model_js_1.plans.set(scene, { objects, channels, drivers, events, order: finished.order, extensions, audioChannels });
|
|
478
650
|
return scene;
|
|
479
651
|
}
|
|
480
652
|
function rename(names, node, name, source) {
|
package/contexts.d.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { type GraphBuilder } from './graph.js';
|
|
2
|
+
import { type Expression } from './expression.js';
|
|
3
|
+
import { type ContextRegistry, type ContextStage } from './registry.js';
|
|
4
|
+
import { type AudioFrameData, type ContextValue, type ContextValues, type EvaluateFrameOptions, type ExtensionNodeType, type ExtensionPropDefinition, type FrameSnapshot, type GraphPort, type SourceLocation } from './types.js';
|
|
5
|
+
interface NodeDefinition {
|
|
6
|
+
type: string;
|
|
7
|
+
inputs: Map<string, GraphPort>;
|
|
8
|
+
outputs: Map<string, GraphPort>;
|
|
9
|
+
props: Map<string, ExtensionPropDefinition>;
|
|
10
|
+
evaluate: (ctx: Parameters<ExtensionNodeType['evaluate']>[0], audio?: AudioFrameData) => ContextValues | void;
|
|
11
|
+
}
|
|
12
|
+
export interface ExtensionSource {
|
|
13
|
+
address: string;
|
|
14
|
+
path: string;
|
|
15
|
+
port: string;
|
|
16
|
+
type: GraphPort['type'];
|
|
17
|
+
stage: ContextStage;
|
|
18
|
+
}
|
|
19
|
+
type InputDriver = {
|
|
20
|
+
kind: 'wire';
|
|
21
|
+
from: ExtensionSource;
|
|
22
|
+
} | {
|
|
23
|
+
kind: 'expr';
|
|
24
|
+
expression: Expression;
|
|
25
|
+
references: ExtensionSource[];
|
|
26
|
+
source: SourceLocation;
|
|
27
|
+
};
|
|
28
|
+
export interface ExtensionNode {
|
|
29
|
+
path: string;
|
|
30
|
+
context: string;
|
|
31
|
+
stage: ContextStage;
|
|
32
|
+
definition: NodeDefinition;
|
|
33
|
+
source: SourceLocation;
|
|
34
|
+
props: Map<string, ContextValue>;
|
|
35
|
+
drivers: Map<string, InputDriver>;
|
|
36
|
+
}
|
|
37
|
+
export declare class Extensions {
|
|
38
|
+
readonly registry: ContextRegistry;
|
|
39
|
+
private readonly types;
|
|
40
|
+
readonly nodes: Map<string, ExtensionNode>;
|
|
41
|
+
constructor(registry: ContextRegistry);
|
|
42
|
+
add(path: string, type: string, source: SourceLocation): ExtensionNode;
|
|
43
|
+
property(address: string, args: string[], text: string, source: SourceLocation): void;
|
|
44
|
+
input(address: string, type: GraphPort['type'], driver: InputDriver, source: SourceLocation): void;
|
|
45
|
+
output(address: string, source: SourceLocation): ExtensionSource;
|
|
46
|
+
private member;
|
|
47
|
+
addToGraph(graph: GraphBuilder): void;
|
|
48
|
+
}
|
|
49
|
+
export declare function checkAudioFrame(path: string, sampleFrame: number, frame: number): void;
|
|
50
|
+
export declare function createContextEvaluation(extensions: Extensions, order: readonly string[], frame: number, time: number, fps: number, frameCount: number | undefined, options: EvaluateFrameOptions, readBuiltIn: (path: string, frame: number) => number): {
|
|
51
|
+
run: (stage: "audio" | "geo" | "evaluate" | "output") => void;
|
|
52
|
+
read: (path: string, sampleFrame: number) => ContextValue;
|
|
53
|
+
finish(snapshotBase: FrameSnapshot): FrameSnapshot;
|
|
54
|
+
};
|
|
55
|
+
export {};
|