@ignifx/editor-host 0.10.0 → 0.11.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/dist/index.d.ts +200 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +445 -101
- package/dist/index.js.map +1 -1
- package/dist/vite.d.ts +4 -1
- package/dist/vite.d.ts.map +1 -1
- package/dist/vite.js +232 -5
- package/dist/vite.js.map +1 -1
- package/package.json +8 -6
- package/skills/editor-host/SKILL.md +18 -3
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as isEditorOrigin, t as EditorHostErrorCode } from "./error-codes.js";
|
|
2
|
-
import { Camera, IgnifxError, Phase, SCENE_FILE_FORMAT, SCENE_FORMAT_VERSION, Script, Transform, VERSION, addComponentFromRecord, canonicalizeNumber, clamp, createApp, createFrameSample, createRay, createSceneAsset, decodeProps, decodeValue, degToRad, describeRegisteredSchemas, describeSchemas, describeSettings, encodeProps, encodeValue, instantiateScene, isIgnifxError, loadSceneDependencies, parseOverridePath, serializeScene, settingsJsonSchema, toJsonSchema, transformSchema, validateSceneFile } from "@ignifx/core";
|
|
2
|
+
import { Camera, Component, IgnifxError, Phase, SCENE_FILE_FORMAT, SCENE_FORMAT_VERSION, Script, Transform, VERSION, addComponentFromRecord, canonicalizeNumber, clamp, createApp, createFrameSample, createRay, createSceneAsset, decodeProps, decodeValue, degToRad, describeRegisteredSchemas, describeSchemas, describeSettings, encodeProps, encodeValue, instantiateScene, isIgnifxError, loadSceneDependencies, parseOverridePath, serializeScene, settingsJsonSchema, toJsonSchema, transformSchema, validateSceneFile } from "@ignifx/core";
|
|
3
3
|
import { addToScene, attachPositionGizmoToNode, attachRotationGizmoToNode, attachScaleGizmoToNode, createLines, createPositionGizmo, createRotationGizmo, createScaleGizmo, isGizmoDragging, isGizmoInteracting, isGizmoPickPending, onBeforeRender, setPositionGizmoLocalCoordinates, setRotationGizmoLocalCoordinates, setScaleGizmoLocalCoordinates } from "@babylonjs/lite";
|
|
4
4
|
//#region src/protocol/rpc.ts
|
|
5
5
|
/**
|
|
@@ -826,7 +826,25 @@ const SceneMethod = {
|
|
|
826
826
|
*/
|
|
827
827
|
describeSettings: "describeSettings",
|
|
828
828
|
/** Switches the view between the 3D and the 2D editor camera. Answers `null`. */
|
|
829
|
-
setViewMode: "setViewMode"
|
|
829
|
+
setViewMode: "setViewMode",
|
|
830
|
+
/**
|
|
831
|
+
* Turns the editor's "animate materials" toggle on or off: whether the shader clock runs in the
|
|
832
|
+
* scene view. Answers `null`. The host starts with it on, after every load. A host from before it
|
|
833
|
+
* answers `RpcErrorCode.methodNotFound`. Additive in 0.3.
|
|
834
|
+
*/
|
|
835
|
+
setAnimateMaterials: "setAnimateMaterials",
|
|
836
|
+
/**
|
|
837
|
+
* Outlines the colliders of entities of the open scene, as world-space line segments, for the
|
|
838
|
+
* editor's collider gizmos. Answers {@link ColliderOutlineSet}. A host from before it answers
|
|
839
|
+
* `RpcErrorCode.methodNotFound`. Additive in 0.3.
|
|
840
|
+
*/
|
|
841
|
+
getColliderOutlines: "getColliderOutlines",
|
|
842
|
+
/**
|
|
843
|
+
* Poses an entity's `Animator` at one point of one state without playing it (engine ADR-0028,
|
|
844
|
+
* amendment 2026-10-20). Answers {@link SampleAnimationResult}. A host from before it answers
|
|
845
|
+
* `RpcErrorCode.methodNotFound`. Additive in 0.3.
|
|
846
|
+
*/
|
|
847
|
+
sampleAnimation: "sampleAnimation"
|
|
830
848
|
};
|
|
831
849
|
/**
|
|
832
850
|
* Scene host → editor: the notifications of protocol 0.3. None has an answer.
|
|
@@ -879,6 +897,36 @@ const TRANSFORM_DRAGGING_INTERVAL_MS = 50;
|
|
|
879
897
|
*/
|
|
880
898
|
const SCREENSHOT_MAX_SIZE = 2048;
|
|
881
899
|
/**
|
|
900
|
+
* The most entities one `getColliderOutlines` request outlines; the rest of a longer list are left
|
|
901
|
+
* out and the answer says `truncated`.
|
|
902
|
+
*
|
|
903
|
+
* @public
|
|
904
|
+
*/
|
|
905
|
+
const COLLIDER_OUTLINES_MAX_ENTITIES = 256;
|
|
906
|
+
/**
|
|
907
|
+
* The most numbers all the `lines` of one `getColliderOutlines` answer hold together, 100 000
|
|
908
|
+
* segments: an outline that would pass it is left out, with every one after it, and the answer
|
|
909
|
+
* says `truncated`.
|
|
910
|
+
*
|
|
911
|
+
* @public
|
|
912
|
+
*/
|
|
913
|
+
const COLLIDER_OUTLINES_MAX_NUMBERS = 6e5;
|
|
914
|
+
/**
|
|
915
|
+
* The most parameter values one `sampleAnimation` request may carry. A request with more fails
|
|
916
|
+
* with `invalidParams`.
|
|
917
|
+
*
|
|
918
|
+
* @public
|
|
919
|
+
*/
|
|
920
|
+
const SAMPLE_ANIMATION_MAX_PARAMETERS = 64;
|
|
921
|
+
/**
|
|
922
|
+
* The longest `entity`, `state` or parameter name, in UTF-16 code units, one `sampleAnimation`
|
|
923
|
+
* request may carry. A request with a longer one fails with `invalidParams`. It also bounds the
|
|
924
|
+
* names an error message echoes back.
|
|
925
|
+
*
|
|
926
|
+
* @public
|
|
927
|
+
*/
|
|
928
|
+
const SAMPLE_ANIMATION_MAX_NAME_LENGTH = 256;
|
|
929
|
+
/**
|
|
882
930
|
* Why the host could not apply one op.
|
|
883
931
|
*
|
|
884
932
|
* @remarks
|
|
@@ -1276,6 +1324,90 @@ function isSetViewModeParams(value) {
|
|
|
1276
1324
|
return isRecord(value) && isOneOf(ViewMode, value["mode"]);
|
|
1277
1325
|
}
|
|
1278
1326
|
/**
|
|
1327
|
+
* Checks the parameters of `setAnimateMaterials`.
|
|
1328
|
+
*
|
|
1329
|
+
* @param value - The received `params`.
|
|
1330
|
+
* @returns True for a boolean `enabled`.
|
|
1331
|
+
*
|
|
1332
|
+
* @public
|
|
1333
|
+
*/
|
|
1334
|
+
function isSetAnimateMaterialsParams(value) {
|
|
1335
|
+
return isRecord(value) && isBoolean(value["enabled"]);
|
|
1336
|
+
}
|
|
1337
|
+
/**
|
|
1338
|
+
* Checks one record of `getColliderOutlines`.
|
|
1339
|
+
*
|
|
1340
|
+
* @param value - The value to test.
|
|
1341
|
+
* @returns True for two uids, a boolean, and a list of finite numbers whose length is a multiple of
|
|
1342
|
+
* six.
|
|
1343
|
+
*
|
|
1344
|
+
* @public
|
|
1345
|
+
*/
|
|
1346
|
+
function isColliderOutlineRecord(value) {
|
|
1347
|
+
if (!isRecord(value)) return false;
|
|
1348
|
+
const lines = value["lines"];
|
|
1349
|
+
return isUidString(value["entity"]) && isUidString(value["component"]) && isBoolean(value["isTrigger"]) && isArrayOf(lines, isFiniteNumber) && lines.length % 6 === 0;
|
|
1350
|
+
}
|
|
1351
|
+
/**
|
|
1352
|
+
* Checks the result of `getColliderOutlines`.
|
|
1353
|
+
*
|
|
1354
|
+
* @param value - The received `result`.
|
|
1355
|
+
* @returns True for a list of outline records and a boolean `truncated`.
|
|
1356
|
+
*
|
|
1357
|
+
* @public
|
|
1358
|
+
*/
|
|
1359
|
+
function isColliderOutlineSet(value) {
|
|
1360
|
+
return isRecord(value) && isArrayOf(value["outlines"], isColliderOutlineRecord) && isBoolean(value["truncated"]);
|
|
1361
|
+
}
|
|
1362
|
+
/**
|
|
1363
|
+
* Checks the parameters of `sampleAnimation`.
|
|
1364
|
+
*
|
|
1365
|
+
* @param value - The received `params`.
|
|
1366
|
+
* @returns True for a uid, a state name, a finite time, and optional parameter values that are
|
|
1367
|
+
* finite numbers or booleans, within {@link SAMPLE_ANIMATION_MAX_NAME_LENGTH} and
|
|
1368
|
+
* {@link SAMPLE_ANIMATION_MAX_PARAMETERS}.
|
|
1369
|
+
*
|
|
1370
|
+
* @public
|
|
1371
|
+
*/
|
|
1372
|
+
function isSampleAnimationParams(value) {
|
|
1373
|
+
return isRecord(value) && isUidString(value["entity"]) && isBoundedName(value["entity"]) && isBoundedName(value["state"]) && isFiniteNumber(value["normalizedTime"]) && optionalField(value, "parameters", isSampleParameters);
|
|
1374
|
+
}
|
|
1375
|
+
/**
|
|
1376
|
+
* Tells whether a value is a string no longer than {@link SAMPLE_ANIMATION_MAX_NAME_LENGTH}.
|
|
1377
|
+
*
|
|
1378
|
+
* @param value - The value to test.
|
|
1379
|
+
* @returns True for such a string.
|
|
1380
|
+
*/
|
|
1381
|
+
function isBoundedName(value) {
|
|
1382
|
+
return isString(value) && value.length <= 256;
|
|
1383
|
+
}
|
|
1384
|
+
/**
|
|
1385
|
+
* Checks the `parameters` of `sampleAnimation`.
|
|
1386
|
+
*
|
|
1387
|
+
* @param value - The value to test.
|
|
1388
|
+
* @returns True for at most {@link SAMPLE_ANIMATION_MAX_PARAMETERS} bounded names, each with a
|
|
1389
|
+
* finite number or a boolean.
|
|
1390
|
+
*/
|
|
1391
|
+
function isSampleParameters(value) {
|
|
1392
|
+
if (!isRecord(value)) return false;
|
|
1393
|
+
const names = Object.keys(value);
|
|
1394
|
+
return names.length <= 64 && names.every((name) => {
|
|
1395
|
+
const entry = value[name];
|
|
1396
|
+
return name.length <= 256 && (isFiniteNumber(entry) || isBoolean(entry));
|
|
1397
|
+
});
|
|
1398
|
+
}
|
|
1399
|
+
/**
|
|
1400
|
+
* Checks the result of `sampleAnimation`.
|
|
1401
|
+
*
|
|
1402
|
+
* @param value - The received `result`.
|
|
1403
|
+
* @returns True for `{ posed: boolean }`.
|
|
1404
|
+
*
|
|
1405
|
+
* @public
|
|
1406
|
+
*/
|
|
1407
|
+
function isSampleAnimationResult(value) {
|
|
1408
|
+
return isRecord(value) && isBoolean(value["posed"]);
|
|
1409
|
+
}
|
|
1410
|
+
/**
|
|
1279
1411
|
* Checks the parameters of `sceneOpened`.
|
|
1280
1412
|
*
|
|
1281
1413
|
* @param value - The received `params`.
|
|
@@ -2295,124 +2427,117 @@ function outermostRoots(index, roots) {
|
|
|
2295
2427
|
});
|
|
2296
2428
|
}
|
|
2297
2429
|
//#endregion
|
|
2298
|
-
//#region src/scene/
|
|
2430
|
+
//#region src/scene/collider-outlines.ts
|
|
2299
2431
|
/**
|
|
2300
|
-
*
|
|
2301
|
-
*
|
|
2302
|
-
*
|
|
2303
|
-
*
|
|
2304
|
-
* (`docs/architecture/17-editor-host.md` §6.1).
|
|
2432
|
+
* `getColliderOutlines`: the physics extensions' collider outlines, made JSON. The host reads
|
|
2433
|
+
* `app.physics.colliderOutlines` and `app.physics2d.colliderOutlines` by shape, as `@ignifx/devtools`
|
|
2434
|
+
* reads `app.physics`, so a project without physics costs the host nothing and the host depends on
|
|
2435
|
+
* neither package (ADR-0028, amendment of 2026-10-20).
|
|
2305
2436
|
*/
|
|
2306
|
-
/**
|
|
2307
|
-
const
|
|
2308
|
-
entityUid: () => null,
|
|
2309
|
-
componentUid: () => null
|
|
2310
|
-
};
|
|
2437
|
+
/** How many decimal places a coordinate keeps on the wire: a hundredth of a millimetre. */
|
|
2438
|
+
const WIRE_PRECISION = 1e5;
|
|
2311
2439
|
/**
|
|
2312
|
-
*
|
|
2313
|
-
* which no file holds, are left out.
|
|
2440
|
+
* Finds `colliderOutlines` on one of the app's physics services.
|
|
2314
2441
|
*
|
|
2315
|
-
* @param app - The
|
|
2316
|
-
* @param
|
|
2317
|
-
* @returns
|
|
2442
|
+
* @param app - The app.
|
|
2443
|
+
* @param property - `"physics"` or `"physics2d"`.
|
|
2444
|
+
* @returns A function that outlines an entity's colliders, or `null` when the project does not
|
|
2445
|
+
* register that extension (or registers one from before the method).
|
|
2318
2446
|
*/
|
|
2319
|
-
function
|
|
2320
|
-
const
|
|
2321
|
-
if (
|
|
2322
|
-
const
|
|
2323
|
-
|
|
2447
|
+
function outlinerOf(app, property) {
|
|
2448
|
+
const service = Reflect.get(app, property);
|
|
2449
|
+
if (typeof service !== "object" || service === null) return null;
|
|
2450
|
+
const method = Reflect.get(service, "colliderOutlines");
|
|
2451
|
+
if (typeof method !== "function") return null;
|
|
2452
|
+
return (entity) => {
|
|
2453
|
+
const answer = Reflect.apply(method, service, [entity]);
|
|
2454
|
+
return Array.isArray(answer) ? answer.filter(isOutlineLike) : [];
|
|
2455
|
+
};
|
|
2324
2456
|
}
|
|
2325
|
-
/** The field defaults of every registered type, as the host last saw them. */
|
|
2326
|
-
var DefaultsTracker = class {
|
|
2327
|
-
#app;
|
|
2328
|
-
#known = /* @__PURE__ */ new Map();
|
|
2329
|
-
/**
|
|
2330
|
-
* Reads the defaults of every type registered now.
|
|
2331
|
-
*
|
|
2332
|
-
* @param app - The scene view's app, started.
|
|
2333
|
-
*/
|
|
2334
|
-
constructor(app) {
|
|
2335
|
-
this.#app = app;
|
|
2336
|
-
for (const [typeId, type] of app.world.registry.registrations()) this.#known.set(typeId, defaultsOf(app, type));
|
|
2337
|
-
}
|
|
2338
|
-
/**
|
|
2339
|
-
* Compares the defaults of reloaded types with the ones seen before, and keeps the new ones.
|
|
2340
|
-
*
|
|
2341
|
-
* @param typeIds - The type ids a hot reload replaced; any other id is ignored.
|
|
2342
|
-
* @returns The fields whose default changed or which are new, by type id. A type seen for the
|
|
2343
|
-
* first time has no change: no document component was built from it.
|
|
2344
|
-
*/
|
|
2345
|
-
changed(typeIds) {
|
|
2346
|
-
const changed = /* @__PURE__ */ new Map();
|
|
2347
|
-
const registry = this.#app.world.registry;
|
|
2348
|
-
for (const typeId of typeIds) {
|
|
2349
|
-
const type = registry.get(typeId);
|
|
2350
|
-
if (type === null) continue;
|
|
2351
|
-
const next = defaultsOf(this.#app, type);
|
|
2352
|
-
const previous = this.#known.get(typeId);
|
|
2353
|
-
this.#known.set(typeId, next);
|
|
2354
|
-
if (previous === void 0 || next === null) continue;
|
|
2355
|
-
const fields = [...next].filter(([name, value]) => previous?.get(name) !== value).map(([name]) => name);
|
|
2356
|
-
if (fields.length > 0) changed.set(typeId, fields);
|
|
2357
|
-
}
|
|
2358
|
-
return changed;
|
|
2359
|
-
}
|
|
2360
|
-
};
|
|
2361
2457
|
/**
|
|
2362
|
-
*
|
|
2458
|
+
* Tells whether a value has an outline's shape.
|
|
2363
2459
|
*
|
|
2364
|
-
* @param
|
|
2365
|
-
* @
|
|
2366
|
-
* @returns Its registered type id, or `null`.
|
|
2460
|
+
* @param value - The value.
|
|
2461
|
+
* @returns True for a component, a boolean, and a `Float32Array`.
|
|
2367
2462
|
*/
|
|
2368
|
-
function
|
|
2369
|
-
return
|
|
2463
|
+
function isOutlineLike(value) {
|
|
2464
|
+
return typeof value === "object" && value !== null && Reflect.get(value, "collider") instanceof Component && typeof Reflect.get(value, "isTrigger") === "boolean" && Reflect.get(value, "lines") instanceof Float32Array;
|
|
2370
2465
|
}
|
|
2371
2466
|
/**
|
|
2372
|
-
*
|
|
2373
|
-
* component the mirror has no record of is left alone.
|
|
2467
|
+
* Rounds a coordinate for the wire, which also drops the float32 noise (`0.30000001192092896`).
|
|
2374
2468
|
*
|
|
2375
|
-
* @param
|
|
2376
|
-
* @
|
|
2377
|
-
* @param index - Its index.
|
|
2378
|
-
* @param changed - The changed fields, by type id.
|
|
2469
|
+
* @param value - The coordinate.
|
|
2470
|
+
* @returns The rounded coordinate.
|
|
2379
2471
|
*/
|
|
2380
|
-
function
|
|
2381
|
-
|
|
2382
|
-
const fields = changed.get(typeIdOf(app, component) ?? "");
|
|
2383
|
-
const set = mirror.propsSetBy(uid);
|
|
2384
|
-
const schema = app.world.registry.describe(component.constructor).schema;
|
|
2385
|
-
if (fields === void 0 || set === null || schema === null) continue;
|
|
2386
|
-
for (const name of fields) {
|
|
2387
|
-
const field = Object.hasOwn(schema, name) ? schema[name] : void 0;
|
|
2388
|
-
if (field !== void 0 && !set.has(name)) Reflect.set(component, name, field.createDefault());
|
|
2389
|
-
}
|
|
2390
|
-
}
|
|
2472
|
+
function wireNumber(value) {
|
|
2473
|
+
return Math.round(value * WIRE_PRECISION) / WIRE_PRECISION;
|
|
2391
2474
|
}
|
|
2392
2475
|
/**
|
|
2393
|
-
*
|
|
2394
|
-
*
|
|
2476
|
+
* Turns 3D segments into wire numbers.
|
|
2477
|
+
*
|
|
2478
|
+
* @param lines - `x, y, z` per end.
|
|
2479
|
+
* @returns The same segments, rounded.
|
|
2480
|
+
*/
|
|
2481
|
+
function lines3D(lines) {
|
|
2482
|
+
return Array.from(lines, wireNumber);
|
|
2483
|
+
}
|
|
2484
|
+
/**
|
|
2485
|
+
* Turns 2D segments into 3D wire numbers at a depth.
|
|
2486
|
+
*
|
|
2487
|
+
* @param lines - `x, y` per end.
|
|
2488
|
+
* @param z - The entity's world `z`.
|
|
2489
|
+
* @returns `x, y, z` per end, rounded.
|
|
2490
|
+
*/
|
|
2491
|
+
function lines2D(lines, z) {
|
|
2492
|
+
const out = [];
|
|
2493
|
+
for (let index = 0; index + 1 < lines.length; index += 2) out.push(wireNumber(lines[index] ?? 0), wireNumber(lines[index + 1] ?? 0), wireNumber(z));
|
|
2494
|
+
return out;
|
|
2495
|
+
}
|
|
2496
|
+
/**
|
|
2497
|
+
* Outlines the colliders of document entities, 3D first and then 2D for each entity, within the
|
|
2498
|
+
* protocol's caps: at most `COLLIDER_OUTLINES_MAX_ENTITIES` entities and
|
|
2499
|
+
* `COLLIDER_OUTLINES_MAX_NUMBERS` numbers of lines. What passes a cap is left out, whole, and the
|
|
2500
|
+
* answer says `truncated`.
|
|
2395
2501
|
*
|
|
2396
2502
|
* @param app - The scene view's app.
|
|
2397
|
-
* @param
|
|
2398
|
-
* @param
|
|
2399
|
-
* @returns The
|
|
2503
|
+
* @param requested - The requested entities, as many as asked, before any is looked up.
|
|
2504
|
+
* @param resolve - Finds a requested uid's entity in the open scene, or `undefined`.
|
|
2505
|
+
* @returns The answer to `getColliderOutlines`.
|
|
2400
2506
|
*/
|
|
2401
|
-
function
|
|
2402
|
-
const
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2507
|
+
function colliderOutlinesOf(app, requested, resolve) {
|
|
2508
|
+
const outline3D = outlinerOf(app, "physics");
|
|
2509
|
+
const outline2D = outlinerOf(app, "physics2d");
|
|
2510
|
+
const outlines = [];
|
|
2511
|
+
const uids = [...new Set(requested)];
|
|
2512
|
+
let truncated = uids.length > 256;
|
|
2513
|
+
let numbers = 0;
|
|
2514
|
+
for (const uid of uids.slice(0, 256)) {
|
|
2515
|
+
const entity = resolve(uid);
|
|
2516
|
+
if (entity === void 0) continue;
|
|
2517
|
+
const z = entity.transform.position.z;
|
|
2518
|
+
const found = [...(outline3D?.(entity) ?? []).map((outline) => [outline, false]), ...(outline2D?.(entity) ?? []).map((outline) => [outline, true])];
|
|
2519
|
+
for (const [outline, is2D] of found) {
|
|
2520
|
+
const count = is2D ? outline.lines.length / 2 * 3 : outline.lines.length;
|
|
2521
|
+
if (numbers + count > 6e5) {
|
|
2522
|
+
truncated = true;
|
|
2523
|
+
return {
|
|
2524
|
+
outlines,
|
|
2525
|
+
truncated
|
|
2526
|
+
};
|
|
2411
2527
|
}
|
|
2412
|
-
|
|
2528
|
+
numbers += count;
|
|
2529
|
+
outlines.push({
|
|
2530
|
+
entity: uid,
|
|
2531
|
+
component: outline.collider.uid,
|
|
2532
|
+
isTrigger: outline.isTrigger,
|
|
2533
|
+
lines: is2D ? lines2D(outline.lines, z) : lines3D(outline.lines)
|
|
2534
|
+
});
|
|
2413
2535
|
}
|
|
2414
2536
|
}
|
|
2415
|
-
return
|
|
2537
|
+
return {
|
|
2538
|
+
outlines,
|
|
2539
|
+
truncated
|
|
2540
|
+
};
|
|
2416
2541
|
}
|
|
2417
2542
|
/** Milliseconds in one second. */
|
|
2418
2543
|
const MILLISECONDS_PER_SECOND = 1e3;
|
|
@@ -2507,6 +2632,17 @@ function assignProps(component, props, references) {
|
|
|
2507
2632
|
message: `${component.uid}.${issue.path}: ${issue.message}`
|
|
2508
2633
|
}));
|
|
2509
2634
|
}
|
|
2635
|
+
/**
|
|
2636
|
+
* Tells a component that the host changed some of its fields, through its `onValidate` hook
|
|
2637
|
+
* (`ComponentHooks`), so one that builds something from them (a physics body) rebuilds it.
|
|
2638
|
+
*
|
|
2639
|
+
* @param component - The component.
|
|
2640
|
+
* @param fields - The fields that changed; nothing is called when the list is empty.
|
|
2641
|
+
*/
|
|
2642
|
+
function validateFields(component, fields) {
|
|
2643
|
+
const hook = Reflect.get(component, "onValidate");
|
|
2644
|
+
if (fields.length > 0 && typeof hook === "function") Reflect.apply(hook, component, [fields]);
|
|
2645
|
+
}
|
|
2510
2646
|
/** The live mirror of the editor's open scene document. */
|
|
2511
2647
|
var DocumentMirror = class {
|
|
2512
2648
|
#app;
|
|
@@ -2799,6 +2935,131 @@ var DocumentMirror = class {
|
|
|
2799
2935
|
}
|
|
2800
2936
|
};
|
|
2801
2937
|
//#endregion
|
|
2938
|
+
//#region src/scene/defaults.ts
|
|
2939
|
+
/**
|
|
2940
|
+
* Defaults that a script's hot reload changes (engine ask E25): which fields of which component
|
|
2941
|
+
* types took a new default, and the live world brought in line with the document for them. A field
|
|
2942
|
+
* a document component's record leaves out takes the new default; a field it sets keeps its value;
|
|
2943
|
+
* a prefab instance whose members hold such a field is rebuilt from its prefab, with its overrides
|
|
2944
|
+
* (`docs/architecture/17-editor-host.md` §6.1).
|
|
2945
|
+
*/
|
|
2946
|
+
/** Defaults hold no reference to anything in a file. */
|
|
2947
|
+
const NO_REFERENCES = {
|
|
2948
|
+
entityUid: () => null,
|
|
2949
|
+
componentUid: () => null
|
|
2950
|
+
};
|
|
2951
|
+
/**
|
|
2952
|
+
* Reads a component type's field defaults as the file format writes them; `transient` fields,
|
|
2953
|
+
* which no file holds, are left out.
|
|
2954
|
+
*
|
|
2955
|
+
* @param app - The scene view's app.
|
|
2956
|
+
* @param type - The registered type.
|
|
2957
|
+
* @returns The defaults, or `null` for a type without a schema.
|
|
2958
|
+
*/
|
|
2959
|
+
function defaultsOf(app, type) {
|
|
2960
|
+
const schema = app.world.registry.describe(type).schema;
|
|
2961
|
+
if (schema === null) return null;
|
|
2962
|
+
const encoded = encodeProps(schema, {}, NO_REFERENCES);
|
|
2963
|
+
return new Map(Object.entries(encoded).map(([name, value]) => [name, JSON.stringify(value)]));
|
|
2964
|
+
}
|
|
2965
|
+
/** The field defaults of every registered type, as the host last saw them. */
|
|
2966
|
+
var DefaultsTracker = class {
|
|
2967
|
+
#app;
|
|
2968
|
+
#known = /* @__PURE__ */ new Map();
|
|
2969
|
+
/**
|
|
2970
|
+
* Reads the defaults of every type registered now.
|
|
2971
|
+
*
|
|
2972
|
+
* @param app - The scene view's app, started.
|
|
2973
|
+
*/
|
|
2974
|
+
constructor(app) {
|
|
2975
|
+
this.#app = app;
|
|
2976
|
+
for (const [typeId, type] of app.world.registry.registrations()) this.#known.set(typeId, defaultsOf(app, type));
|
|
2977
|
+
}
|
|
2978
|
+
/**
|
|
2979
|
+
* Compares the defaults of reloaded types with the ones seen before, and keeps the new ones.
|
|
2980
|
+
*
|
|
2981
|
+
* @param typeIds - The type ids a hot reload replaced; any other id is ignored.
|
|
2982
|
+
* @returns The fields whose default changed or which are new, by type id. A type seen for the
|
|
2983
|
+
* first time has no change: no document component was built from it.
|
|
2984
|
+
*/
|
|
2985
|
+
changed(typeIds) {
|
|
2986
|
+
const changed = /* @__PURE__ */ new Map();
|
|
2987
|
+
const registry = this.#app.world.registry;
|
|
2988
|
+
for (const typeId of typeIds) {
|
|
2989
|
+
const type = registry.get(typeId);
|
|
2990
|
+
if (type === null) continue;
|
|
2991
|
+
const next = defaultsOf(this.#app, type);
|
|
2992
|
+
const previous = this.#known.get(typeId);
|
|
2993
|
+
this.#known.set(typeId, next);
|
|
2994
|
+
if (previous === void 0 || next === null) continue;
|
|
2995
|
+
const fields = [...next].filter(([name, value]) => previous?.get(name) !== value).map(([name]) => name);
|
|
2996
|
+
if (fields.length > 0) changed.set(typeId, fields);
|
|
2997
|
+
}
|
|
2998
|
+
return changed;
|
|
2999
|
+
}
|
|
3000
|
+
};
|
|
3001
|
+
/**
|
|
3002
|
+
* The type id of a live component.
|
|
3003
|
+
*
|
|
3004
|
+
* @param app - The scene view's app.
|
|
3005
|
+
* @param component - The component.
|
|
3006
|
+
* @returns Its registered type id, or `null`.
|
|
3007
|
+
*/
|
|
3008
|
+
function typeIdOf(app, component) {
|
|
3009
|
+
return app.world.registry.describe(component.constructor).typeId;
|
|
3010
|
+
}
|
|
3011
|
+
/**
|
|
3012
|
+
* Gives every document component the new default of each changed field its record leaves out. A
|
|
3013
|
+
* component the mirror has no record of is left alone.
|
|
3014
|
+
*
|
|
3015
|
+
* @param app - The scene view's app.
|
|
3016
|
+
* @param mirror - The open document.
|
|
3017
|
+
* @param index - Its index.
|
|
3018
|
+
* @param changed - The changed fields, by type id.
|
|
3019
|
+
*/
|
|
3020
|
+
function applyDefaults(app, mirror, index, changed) {
|
|
3021
|
+
for (const [uid, component] of index.components) {
|
|
3022
|
+
const fields = changed.get(typeIdOf(app, component) ?? "");
|
|
3023
|
+
const set = mirror.propsSetBy(uid);
|
|
3024
|
+
const schema = app.world.registry.describe(component.constructor).schema;
|
|
3025
|
+
if (fields === void 0 || set === null || schema === null) continue;
|
|
3026
|
+
const assigned = [];
|
|
3027
|
+
for (const name of fields) {
|
|
3028
|
+
const field = Object.hasOwn(schema, name) ? schema[name] : void 0;
|
|
3029
|
+
if (field !== void 0 && !set.has(name)) {
|
|
3030
|
+
Reflect.set(component, name, field.createDefault());
|
|
3031
|
+
assigned.push(name);
|
|
3032
|
+
}
|
|
3033
|
+
}
|
|
3034
|
+
validateFields(component, assigned);
|
|
3035
|
+
}
|
|
3036
|
+
}
|
|
3037
|
+
/**
|
|
3038
|
+
* The document's instance roots whose members (not the document's own components) include a
|
|
3039
|
+
* component of a changed type, in document order.
|
|
3040
|
+
*
|
|
3041
|
+
* @param app - The scene view's app.
|
|
3042
|
+
* @param index - The open document's index.
|
|
3043
|
+
* @param changed - The changed fields, by type id.
|
|
3044
|
+
* @returns The roots' uids.
|
|
3045
|
+
*/
|
|
3046
|
+
function instancesHolding(app, index, changed) {
|
|
3047
|
+
const roots = /* @__PURE__ */ new Set();
|
|
3048
|
+
for (const record of index.file.entities) {
|
|
3049
|
+
const root = index.entities.get(record.uid);
|
|
3050
|
+
if (record.instance === void 0 || root === void 0) continue;
|
|
3051
|
+
const pending = [root];
|
|
3052
|
+
for (let entity = pending.pop(); entity !== void 0; entity = pending.pop()) {
|
|
3053
|
+
if (entity.components.some((component) => !index.components.has(component.uid) && changed.has(typeIdOf(app, component) ?? ""))) {
|
|
3054
|
+
roots.add(record.uid);
|
|
3055
|
+
break;
|
|
3056
|
+
}
|
|
3057
|
+
pending.push(...entity.children);
|
|
3058
|
+
}
|
|
3059
|
+
}
|
|
3060
|
+
return roots;
|
|
3061
|
+
}
|
|
3062
|
+
//#endregion
|
|
2802
3063
|
//#region src/scene/editor-camera.ts
|
|
2803
3064
|
/**
|
|
2804
3065
|
* The scene view's 3D editor camera: an ordinary script on an entity of the host's persistent
|
|
@@ -4253,6 +4514,7 @@ async function setProp(context, op) {
|
|
|
4253
4514
|
if (props === null) throw new OpFailure(ApplyOpFailureCode.invalidValue, "props must be an object.");
|
|
4254
4515
|
rejectIssues(assignProps(component, props, references));
|
|
4255
4516
|
context.mirror.recordProps(op.component, Object.keys(props));
|
|
4517
|
+
validateFields(component, Object.keys(schema));
|
|
4256
4518
|
return;
|
|
4257
4519
|
}
|
|
4258
4520
|
const field = typeof name === "string" && Object.hasOwn(schema, name) ? schema[name] : void 0;
|
|
@@ -4260,6 +4522,7 @@ async function setProp(context, op) {
|
|
|
4260
4522
|
if (rest.length === 0 && op.value === void 0) {
|
|
4261
4523
|
Reflect.set(component, name, field.createDefault());
|
|
4262
4524
|
context.mirror.recordProp(op.component, name, false);
|
|
4525
|
+
validateFields(component, [name]);
|
|
4263
4526
|
return;
|
|
4264
4527
|
}
|
|
4265
4528
|
const json = rest.length > 0 ? withValueAt(encodeLive(field, Reflect.get(component, name)), rest, op.value) : op.value;
|
|
@@ -4270,6 +4533,7 @@ async function setProp(context, op) {
|
|
|
4270
4533
|
})));
|
|
4271
4534
|
Reflect.set(component, name, decoded.value);
|
|
4272
4535
|
context.mirror.recordProp(op.component, name, true);
|
|
4536
|
+
validateFields(component, [name]);
|
|
4273
4537
|
}
|
|
4274
4538
|
/**
|
|
4275
4539
|
* Fails the op on the first decoding problem: the value the field got is not the document's.
|
|
@@ -4484,6 +4748,45 @@ async function removeOverride(context, op) {
|
|
|
4484
4748
|
});
|
|
4485
4749
|
}
|
|
4486
4750
|
//#endregion
|
|
4751
|
+
//#region src/scene/sample-animation.ts
|
|
4752
|
+
/**
|
|
4753
|
+
* `sampleAnimation`: the scene view poses an entity's `Animator` at one point of one state, through
|
|
4754
|
+
* the engine's `Animator.sample` (ADR-0028, amendment 2026-10-20). The host depends on core only, so
|
|
4755
|
+
* it finds the `Animator` by its type id and calls `sample` by shape.
|
|
4756
|
+
*/
|
|
4757
|
+
/** The type id `@ignifx/3d` registers its `Animator` under. */
|
|
4758
|
+
const ANIMATOR_TYPE_ID = "ignifx/Animator";
|
|
4759
|
+
/**
|
|
4760
|
+
* Answers `sampleAnimation` on the open document.
|
|
4761
|
+
*
|
|
4762
|
+
* @param app - The scene view's app.
|
|
4763
|
+
* @param mirror - The open document.
|
|
4764
|
+
* @param params - The received `params`.
|
|
4765
|
+
* @returns Whether the pose was written.
|
|
4766
|
+
* @throws InvalidParamsError for malformed params, an entity the document lacks or one without an
|
|
4767
|
+
* `Animator`, and any `IgnifxError` the engine throws, whose code it carries as `data.code`.
|
|
4768
|
+
*/
|
|
4769
|
+
function sampleAnimation(app, mirror, params) {
|
|
4770
|
+
if (!isSampleAnimationParams(params)) throw new InvalidParamsError(`sampleAnimation takes { entity: uid, state: string, normalizedTime: number, parameters?: { [name]: number | boolean } }, with names of at most ${String(256)} characters and at most ${String(64)} parameters.`);
|
|
4771
|
+
const entity = mirror.index()?.entities.get(params.entity);
|
|
4772
|
+
if (entity === void 0) throw new InvalidParamsError(`sampleAnimation names ${params.entity}, which is not an entity of the open scene.`);
|
|
4773
|
+
const type = componentTypeOf(app, ANIMATOR_TYPE_ID);
|
|
4774
|
+
const animator = type === null ? null : entity.getComponent(type);
|
|
4775
|
+
const sample = animator === null ? void 0 : Reflect.get(animator, "sample");
|
|
4776
|
+
if (animator === null || typeof sample !== "function") throw new InvalidParamsError(`The entity ${params.entity} has no Animator to sample.`);
|
|
4777
|
+
const options = params.parameters === void 0 ? [] : [{ parameters: params.parameters }];
|
|
4778
|
+
try {
|
|
4779
|
+
return { posed: Reflect.apply(sample, animator, [
|
|
4780
|
+
params.state,
|
|
4781
|
+
params.normalizedTime,
|
|
4782
|
+
...options
|
|
4783
|
+
]) === true };
|
|
4784
|
+
} catch (error) {
|
|
4785
|
+
if (isIgnifxError(error)) throw new InvalidParamsError(error.message, { code: error.code });
|
|
4786
|
+
throw error;
|
|
4787
|
+
}
|
|
4788
|
+
}
|
|
4789
|
+
//#endregion
|
|
4487
4790
|
//#region src/scene/schemas.ts
|
|
4488
4791
|
/**
|
|
4489
4792
|
* `getSchemas` and `schemasChanged`: every registered component's schema, as the inspector reads
|
|
@@ -4997,7 +5300,10 @@ var SceneHost = class {
|
|
|
4997
5300
|
[SceneMethod.pick, async (params) => this.#pick(params)],
|
|
4998
5301
|
[SceneMethod.getSchemas, () => this.#getSchemas()],
|
|
4999
5302
|
[SceneMethod.describeSettings, () => this.#describeSettings()],
|
|
5000
|
-
[SceneMethod.setViewMode, (params) => this.#setViewMode(params)]
|
|
5303
|
+
[SceneMethod.setViewMode, (params) => this.#setViewMode(params)],
|
|
5304
|
+
[SceneMethod.setAnimateMaterials, (params) => this.#setAnimateMaterials(params)],
|
|
5305
|
+
[SceneMethod.getColliderOutlines, (params) => this.#getColliderOutlines(params)],
|
|
5306
|
+
[SceneMethod.sampleAnimation, (params) => this.#sampleAnimation(params)]
|
|
5001
5307
|
]);
|
|
5002
5308
|
if (has(HostCapability.gizmos)) methods.set(SceneMethod.setGizmo, (params) => this.#setGizmo(params));
|
|
5003
5309
|
if (has(HostCapability.screenshot)) methods.set(SceneMethod.screenshot, async (params) => this.#screenshot(params));
|
|
@@ -5383,6 +5689,44 @@ var SceneHost = class {
|
|
|
5383
5689
|
return settingsSet(this.#requireApp());
|
|
5384
5690
|
}
|
|
5385
5691
|
/**
|
|
5692
|
+
* `setAnimateMaterials`: the editor's "animate materials" toggle, which runs or holds the shader
|
|
5693
|
+
* clock of the scene view (`app.renderer.animateMaterialsInEditMode`).
|
|
5694
|
+
*
|
|
5695
|
+
* @param params - `{ enabled }`.
|
|
5696
|
+
* @returns `null`.
|
|
5697
|
+
*/
|
|
5698
|
+
#setAnimateMaterials(params) {
|
|
5699
|
+
this.#requireMirror(SceneMethod.setAnimateMaterials);
|
|
5700
|
+
if (!isSetAnimateMaterialsParams(params)) throw new InvalidParamsError("setAnimateMaterials takes { enabled: boolean }.");
|
|
5701
|
+
this.#requireApp().renderer.animateMaterialsInEditMode = params.enabled;
|
|
5702
|
+
return null;
|
|
5703
|
+
}
|
|
5704
|
+
/**
|
|
5705
|
+
* `getColliderOutlines`: the world-space outlines of the requested entities' colliders, from the
|
|
5706
|
+
* project's physics extensions, for the editor's collider gizmos. Changes nothing.
|
|
5707
|
+
*
|
|
5708
|
+
* @param params - `{ entities }`.
|
|
5709
|
+
* @returns The outlines, within the protocol's caps; uids the open scene does not have are skipped.
|
|
5710
|
+
*/
|
|
5711
|
+
#getColliderOutlines(params) {
|
|
5712
|
+
const mirror = this.#requireMirror(SceneMethod.getColliderOutlines);
|
|
5713
|
+
if (!isEntitySelection(params)) throw new InvalidParamsError("getColliderOutlines takes { entities: uid[] }.");
|
|
5714
|
+
this.#requireOpen(SceneMethod.getColliderOutlines);
|
|
5715
|
+
const index = mirror.index();
|
|
5716
|
+
return colliderOutlinesOf(this.#requireApp(), params.entities, (uid) => index?.entities.get(uid));
|
|
5717
|
+
}
|
|
5718
|
+
/**
|
|
5719
|
+
* `sampleAnimation`: poses an entity's `Animator` at one point of one state.
|
|
5720
|
+
*
|
|
5721
|
+
* @param params - `{ entity, state, normalizedTime, parameters? }`.
|
|
5722
|
+
* @returns `{ posed }`.
|
|
5723
|
+
*/
|
|
5724
|
+
#sampleAnimation(params) {
|
|
5725
|
+
const mirror = this.#requireMirror(SceneMethod.sampleAnimation);
|
|
5726
|
+
this.#requireOpen(SceneMethod.sampleAnimation);
|
|
5727
|
+
return sampleAnimation(this.#requireApp(), mirror, params);
|
|
5728
|
+
}
|
|
5729
|
+
/**
|
|
5386
5730
|
* `setViewMode`: switches the view between the 3D editor camera and the 2D one. The first switch
|
|
5387
5731
|
* to 2D on a document starts where the level's own `Camera2D` looks, or frames the document.
|
|
5388
5732
|
*
|
|
@@ -6231,6 +6575,6 @@ function listenForEditorPlayControls(options) {
|
|
|
6231
6575
|
};
|
|
6232
6576
|
}
|
|
6233
6577
|
//#endregion
|
|
6234
|
-
export { ApplyOpFailureCode, DEFAULT_HEARTBEAT_INTERVAL_MS, EDITOR_CONNECT_MESSAGE_TYPE, EditorHostErrorCode, GizmoMode, GizmoSpace, HandshakeMethod, HostCapability, HostKind, HostNotification, JSON_RPC_VERSION, PROTOCOL_VERSION, PickUnit, PlayMethod, PlayNotification, PlayPhase, RpcErrorCode, SCREENSHOT_MAX_SIZE, SceneMethod, SceneNotification, SceneOpKind, ScreenshotFormat, TRANSFORM_DRAGGING_INTERVAL_MS, ViewMode, isAppErrorData, isApplyOpsParams, isApplyOpsResult, isAssetReloadedParams, isEditorConnectMessage, isEditorOrigin, isEntitySelection, isFrameParams, isHostErrorParams, isHotReloadedParams, isIncompatibleProtocolData, isInvalidSceneFileData, isJsonObject, isJsonValue, isLogParams, isOpenSceneParams, isOpenSceneResult, isPickParams, isPickResult, isPlayState, isPlayStateReport, isPlayStats, isProtocolVersion, isReadBackParams, isReadBackResult, isReadyResult, isRpcMessage, isSceneFile, isSceneFileAssetRef, isSceneFileComponent, isSceneFileEntity, isSceneFileInstance, isSceneFileOverride, isSceneFileTransform, isSceneIssue, isSceneOp, isSceneOpenedParams, isSchemaSet, isScreenshotParams, isScreenshotResult, isSetGizmoParams, isSetViewModeParams, isSettingsSet, isTransformDraggedParams, isTransformDraggingParams, listenForEditorPlayControls, protocolVersionIsCompatible, startEditorHost, startEditorPlayControls };
|
|
6578
|
+
export { ApplyOpFailureCode, COLLIDER_OUTLINES_MAX_ENTITIES, COLLIDER_OUTLINES_MAX_NUMBERS, DEFAULT_HEARTBEAT_INTERVAL_MS, EDITOR_CONNECT_MESSAGE_TYPE, EditorHostErrorCode, GizmoMode, GizmoSpace, HandshakeMethod, HostCapability, HostKind, HostNotification, JSON_RPC_VERSION, PROTOCOL_VERSION, PickUnit, PlayMethod, PlayNotification, PlayPhase, RpcErrorCode, SAMPLE_ANIMATION_MAX_NAME_LENGTH, SAMPLE_ANIMATION_MAX_PARAMETERS, SCREENSHOT_MAX_SIZE, SceneMethod, SceneNotification, SceneOpKind, ScreenshotFormat, TRANSFORM_DRAGGING_INTERVAL_MS, ViewMode, isAppErrorData, isApplyOpsParams, isApplyOpsResult, isAssetReloadedParams, isColliderOutlineRecord, isColliderOutlineSet, isEditorConnectMessage, isEditorOrigin, isEntitySelection, isFrameParams, isHostErrorParams, isHotReloadedParams, isIncompatibleProtocolData, isInvalidSceneFileData, isJsonObject, isJsonValue, isLogParams, isOpenSceneParams, isOpenSceneResult, isPickParams, isPickResult, isPlayState, isPlayStateReport, isPlayStats, isProtocolVersion, isReadBackParams, isReadBackResult, isReadyResult, isRpcMessage, isSampleAnimationParams, isSampleAnimationResult, isSceneFile, isSceneFileAssetRef, isSceneFileComponent, isSceneFileEntity, isSceneFileInstance, isSceneFileOverride, isSceneFileTransform, isSceneIssue, isSceneOp, isSceneOpenedParams, isSchemaSet, isScreenshotParams, isScreenshotResult, isSetAnimateMaterialsParams, isSetGizmoParams, isSetViewModeParams, isSettingsSet, isTransformDraggedParams, isTransformDraggingParams, listenForEditorPlayControls, protocolVersionIsCompatible, startEditorHost, startEditorPlayControls };
|
|
6235
6579
|
|
|
6236
6580
|
//# sourceMappingURL=index.js.map
|