@ignifx/editor-host 0.16.0 → 0.18.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/grid.js +32 -5
- package/dist/grid.js.map +1 -1
- package/dist/index.d.ts +79 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +394 -110
- package/dist/index.js.map +1 -1
- package/dist/sprite-game-view.js +132 -0
- package/dist/sprite-game-view.js.map +1 -0
- package/package.json +10 -10
- package/skills/editor-host/SKILL.md +8 -4
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, Component, CoreErrorCode, IgnifxError, Light, Phase, SCENE_ASSET_TYPE, 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, serializeEntity, serializeScene, settingsJsonSchema, toJsonSchema, transformSchema, validateSceneFile } from "@ignifx/core";
|
|
2
|
+
import { Camera, Component, CoreErrorCode, IgnifxError, Light, Phase, RENDERING_SETTINGS_SECTION, SCENE_ASSET_TYPE, SCENE_FILE_FORMAT, SCENE_FORMAT_VERSION, Script, Transform, VERSION, addComponentFromRecord, canonicalizeNumber, clamp, createApp, createFrameSample, createRay, createSceneAsset, decodeProps, decodeValue, degToRad, describeRegisteredSchemas, describeSchemas, describeSettings, encodeProps, encodeValue, instanceComponentAt, instanceEntityAt, instantiateScene, isIgnifxError, loadSceneDependencies, parseOverridePath, serializeEntity, 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
|
/**
|
|
@@ -187,9 +187,9 @@ const HostKind = {
|
|
|
187
187
|
* The play controls send `"heartbeat"`, `"playControls"`, `"logRelay"` and `"queryRuntime"`, plus
|
|
188
188
|
* `"screenshot"` when the game has a canvas and `"sendInput"` when it has `app.input`. The scene
|
|
189
189
|
* host sends `"heartbeat"` and whichever of `"gizmos"`, `"screenshot"`, `"viewMode2d"`,
|
|
190
|
-
* `"pick2d"`, `"gameView"`, `"
|
|
191
|
-
* `"spriteAnimation"` it supports; every
|
|
192
|
-
* 0.3 scene host.
|
|
190
|
+
* `"pick2d"`, `"gameView"`, `"gameViewOnDemand"`, `"gameViewSize"`, `"gameView2d"`, `"thumbnails"`,
|
|
191
|
+
* `"grid"`, `"tilemapCells"`, `"editorLines"` and `"spriteAnimation"` it supports; every
|
|
192
|
+
* `SceneMethod` not tied to one of them is required of a 0.3 scene host.
|
|
193
193
|
*
|
|
194
194
|
* @public
|
|
195
195
|
*/
|
|
@@ -251,6 +251,24 @@ const HostCapability = {
|
|
|
251
251
|
*/
|
|
252
252
|
gameView: "gameView",
|
|
253
253
|
/**
|
|
254
|
+
* The scene host's `gameViewFrame` renders on demand: it does not wait for an animation frame,
|
|
255
|
+
* which a hidden host (a `visibility: hidden` iframe, a background tab) never gets, so it answers
|
|
256
|
+
* at full rate while hidden. Additive in 0.3; without it, a hidden host answers slowly or not
|
|
257
|
+
* at all.
|
|
258
|
+
*/
|
|
259
|
+
gameViewOnDemand: "gameViewOnDemand",
|
|
260
|
+
/**
|
|
261
|
+
* The scene host's `gameViewFrame` takes `width` and `height`, resizing the view first. Additive
|
|
262
|
+
* in 0.3; without it, send `setGameView` to resize.
|
|
263
|
+
*/
|
|
264
|
+
gameViewSize: "gameViewSize",
|
|
265
|
+
/**
|
|
266
|
+
* The scene host's `gameViewFrame` renders a document whose main camera is a `Camera2D`
|
|
267
|
+
* (`@ignifx/2d`): its sprites through that camera, at the view's size. Additive in 0.3; without
|
|
268
|
+
* it, such a document answers `dataUrl: null`.
|
|
269
|
+
*/
|
|
270
|
+
gameView2d: "gameView2d",
|
|
271
|
+
/**
|
|
254
272
|
* The scene host answers `renderThumbnail`: a model or prefab asset rendered on its own
|
|
255
273
|
* (`RenderViewMethod`). From engine ask E8 (additive in 0.3); without it, the host answers it with
|
|
256
274
|
* `RpcErrorCode.methodNotFound`.
|
|
@@ -264,6 +282,13 @@ const HostCapability = {
|
|
|
264
282
|
*/
|
|
265
283
|
grid: "grid",
|
|
266
284
|
/**
|
|
285
|
+
* The scene host's `setGrid` takes `overlay` (the 3D grid draws over the scene, so a floor mesh
|
|
286
|
+
* does not hide it) and `height` (the world `y` of the 3D grid's plane). From the editor's ask of
|
|
287
|
+
* 2026-11-04 (additive in 0.3); without it, the host ignores both fields and draws the grid
|
|
288
|
+
* depth-tested at `y = 0`.
|
|
289
|
+
*/
|
|
290
|
+
gridOverlay: "gridOverlay",
|
|
291
|
+
/**
|
|
267
292
|
* The scene host answers `setTilemapCells`: it writes cells into the open scene's live tilemaps,
|
|
268
293
|
* so a tilemap editor's painting shows without a save. Additive in 0.3; without it, the scene
|
|
269
294
|
* host answers `setTilemapCells` with `RpcErrorCode.methodNotFound`.
|
|
@@ -1074,7 +1099,9 @@ function isSceneOp(value) {
|
|
|
1074
1099
|
*
|
|
1075
1100
|
* The host handles these requests one at a time, in the order they arrive: a request starts only
|
|
1076
1101
|
* after the previous one has been answered, so `applyOps` sent right after `openScene` sees the new
|
|
1077
|
-
* scene.
|
|
1102
|
+
* scene. `renderThumbnail` is the exception: it renders on a stage of its own, never reads the
|
|
1103
|
+
* document, and runs beside the queue, so it holds up no other request and its answer may come
|
|
1104
|
+
* before those of requests sent earlier. Until the host's app has started, every one of them fails with `RpcErrorCode.notReady`;
|
|
1078
1105
|
* the host's first `schemasChanged` is the editor's cue that they are accepted. A method that needs
|
|
1079
1106
|
* an open scene fails with `RpcErrorCode.noScene` while none is open. A method whose capability the
|
|
1080
1107
|
* host does not list in `ready` fails with `RpcErrorCode.methodNotFound`.
|
|
@@ -1343,12 +1370,21 @@ const GRID_MIN_SIZE = .001;
|
|
|
1343
1370
|
*/
|
|
1344
1371
|
const GRID_MAX_SIZE = 1e3;
|
|
1345
1372
|
/**
|
|
1373
|
+
* The farthest from `y = 0` the 3D grid's plane may be put with `setGrid`'s `height`, in metres,
|
|
1374
|
+
* either way.
|
|
1375
|
+
*
|
|
1376
|
+
* @public
|
|
1377
|
+
*/
|
|
1378
|
+
const GRID_MAX_HEIGHT = 1e5;
|
|
1379
|
+
/**
|
|
1346
1380
|
* The most numbers the `cells` of one `setTilemapCells` request may hold: a million cells. A request
|
|
1347
1381
|
* with more fails with `invalidParams`.
|
|
1348
1382
|
*
|
|
1349
1383
|
* @public
|
|
1350
1384
|
*/
|
|
1351
1385
|
const TILEMAP_CELLS_MAX_NUMBERS = 2e6;
|
|
1386
|
+
/** The longest `asset` address and string `layer` of `setTilemapCells`, in UTF-16 code units. */
|
|
1387
|
+
const TILEMAP_CELLS_MAX_NAME_LENGTH = 256;
|
|
1352
1388
|
/**
|
|
1353
1389
|
* The most numbers the `lines` of one `setEditorLines` request may hold: 100 000 segments.
|
|
1354
1390
|
*
|
|
@@ -1687,29 +1723,31 @@ function isSetAnimateMaterialsParams(value) {
|
|
|
1687
1723
|
* Checks the parameters of `setGrid`.
|
|
1688
1724
|
*
|
|
1689
1725
|
* @param value - The received `params`.
|
|
1690
|
-
* @returns True for an object whose `visible`, if present,
|
|
1691
|
-
* present, is a number from {@link GRID_MIN_SIZE} to {@link GRID_MAX_SIZE}
|
|
1726
|
+
* @returns True for an object whose `visible` and `overlay`, if present, are booleans, whose `size`,
|
|
1727
|
+
* if present, is a number from {@link GRID_MIN_SIZE} to {@link GRID_MAX_SIZE}, and whose `height`,
|
|
1728
|
+
* if present, is a number within {@link GRID_MAX_HEIGHT} of zero.
|
|
1692
1729
|
*
|
|
1693
1730
|
* @public
|
|
1694
1731
|
*/
|
|
1695
1732
|
function isSetGridParams(value) {
|
|
1696
1733
|
if (!isRecord(value)) return false;
|
|
1697
1734
|
const size = value["size"];
|
|
1698
|
-
|
|
1735
|
+
const height = value["height"];
|
|
1736
|
+
return optionalField(value, "visible", isBoolean) && optionalField(value, "overlay", isBoolean) && (size === void 0 || isFiniteNumber(size) && size >= .001 && size <= 1e3) && (height === void 0 || isFiniteNumber(height) && Math.abs(height) <= 1e5);
|
|
1699
1737
|
}
|
|
1700
1738
|
/**
|
|
1701
1739
|
* Checks the parameters of `setTilemapCells`.
|
|
1702
1740
|
*
|
|
1703
1741
|
* @param value - The received `params`.
|
|
1704
|
-
* @returns True for a non-empty `asset
|
|
1705
|
-
* {@link TILEMAP_CELLS_MAX_NUMBERS} non-negative integers.
|
|
1742
|
+
* @returns True for a non-empty `asset` and a layer name or index, each name at most 256 code
|
|
1743
|
+
* units, and an even-length list of at most {@link TILEMAP_CELLS_MAX_NUMBERS} non-negative integers.
|
|
1706
1744
|
*
|
|
1707
1745
|
* @public
|
|
1708
1746
|
*/
|
|
1709
1747
|
function isSetTilemapCellsParams(value) {
|
|
1710
1748
|
if (!isRecord(value)) return false;
|
|
1711
1749
|
const { asset, layer, cells } = value;
|
|
1712
|
-
return isUidString(asset) && (isString(layer) || isCount(layer)) && Array.isArray(cells) && cells.length % 2 === 0 && cells.length <= 2e6 && cells.every((item) => isCount(item));
|
|
1750
|
+
return isUidString(asset) && asset.length <= TILEMAP_CELLS_MAX_NAME_LENGTH && (isString(layer) && layer.length <= TILEMAP_CELLS_MAX_NAME_LENGTH || isCount(layer)) && Array.isArray(cells) && cells.length % 2 === 0 && cells.length <= 2e6 && cells.every((item) => isCount(item));
|
|
1713
1751
|
}
|
|
1714
1752
|
/**
|
|
1715
1753
|
* Checks the result of `setTilemapCells`.
|
|
@@ -1986,7 +2024,9 @@ function isLogParams(value) {
|
|
|
1986
2024
|
* @remarks
|
|
1987
2025
|
* A host lists `HostCapability.gameView` when it answers the first two and
|
|
1988
2026
|
* `HostCapability.thumbnails` when it answers the third; one that does not answers
|
|
1989
|
-
* `RpcErrorCode.methodNotFound`. Additive in 0.3.
|
|
2027
|
+
* `RpcErrorCode.methodNotFound`. Additive in 0.3. `HostCapability.gameViewOnDemand`,
|
|
2028
|
+
* `HostCapability.gameViewSize` and `HostCapability.gameView2d` mark what a newer host's
|
|
2029
|
+
* `gameViewFrame` does beyond that.
|
|
1990
2030
|
*
|
|
1991
2031
|
* @public
|
|
1992
2032
|
*/
|
|
@@ -1997,9 +2037,17 @@ const RenderViewMethod = {
|
|
|
1997
2037
|
* Renders the open scene through its own main camera, the one the game would use, and answers
|
|
1998
2038
|
* the image: {@link GameViewFrameResult}. Fails with `RpcErrorCode.noScene` while no scene is
|
|
1999
2039
|
* open and `RpcErrorCode.invalidRequest` while the game view is off.
|
|
2040
|
+
*
|
|
2041
|
+
* A host with `HostCapability.gameViewOnDemand` answers without waiting for an animation frame
|
|
2042
|
+
* (a hidden host gets none); one with `HostCapability.gameViewSize` takes the image size in the
|
|
2043
|
+
* request; one with `HostCapability.gameView2d` renders a `Camera2D` document camera too.
|
|
2000
2044
|
*/
|
|
2001
2045
|
gameViewFrame: "gameViewFrame",
|
|
2002
|
-
/**
|
|
2046
|
+
/**
|
|
2047
|
+
* Renders one model or prefab asset on its own and answers the image: {@link ThumbnailResult}.
|
|
2048
|
+
* It runs beside the one-at-a-time queue of the other methods, so a thumbnail never holds them
|
|
2049
|
+
* up; thumbnails are answered in the order they were asked for.
|
|
2050
|
+
*/
|
|
2003
2051
|
renderThumbnail: "renderThumbnail"
|
|
2004
2052
|
};
|
|
2005
2053
|
/**
|
|
@@ -2084,12 +2132,12 @@ function isGameViewState(value) {
|
|
|
2084
2132
|
* Checks the parameters of `gameViewFrame`.
|
|
2085
2133
|
*
|
|
2086
2134
|
* @param value - The received `params`.
|
|
2087
|
-
* @returns True for a known format
|
|
2135
|
+
* @returns True for a known format, a quality from 0 to 1 and sizes in range when given.
|
|
2088
2136
|
*
|
|
2089
2137
|
* @public
|
|
2090
2138
|
*/
|
|
2091
2139
|
function isGameViewFrameParams(value) {
|
|
2092
|
-
return isRecord(value) && hasImageFormat(value);
|
|
2140
|
+
return isRecord(value) && hasImageFormat(value) && optionalField(value, "width", (width) => isSide(width, 2048)) && optionalField(value, "height", (height) => isSide(height, 2048));
|
|
2093
2141
|
}
|
|
2094
2142
|
/**
|
|
2095
2143
|
* Checks the result of `gameViewFrame`.
|
|
@@ -2342,6 +2390,7 @@ function connectPortOf(event, editorOrigin) {
|
|
|
2342
2390
|
*/
|
|
2343
2391
|
function openChannel(options) {
|
|
2344
2392
|
const { target, editorOrigin, ready, methods, heartbeatIntervalMs, onReady } = options;
|
|
2393
|
+
const unqueued = options.unqueued ?? /* @__PURE__ */ new Set();
|
|
2345
2394
|
let port = null;
|
|
2346
2395
|
let portListener = null;
|
|
2347
2396
|
let isReady = false;
|
|
@@ -2441,7 +2490,7 @@ function openChannel(options) {
|
|
|
2441
2490
|
if (!wasReady && method === HandshakeMethod.hello) onReady?.();
|
|
2442
2491
|
}
|
|
2443
2492
|
};
|
|
2444
|
-
if (method === HandshakeMethod.ping) {
|
|
2493
|
+
if (method === HandshakeMethod.ping || unqueued.has(method)) {
|
|
2445
2494
|
await reply();
|
|
2446
2495
|
return;
|
|
2447
2496
|
}
|
|
@@ -3260,6 +3309,67 @@ var PlayStatsReader = class {
|
|
|
3260
3309
|
};
|
|
3261
3310
|
}
|
|
3262
3311
|
};
|
|
3312
|
+
//#endregion
|
|
3313
|
+
//#region src/scene/json.ts
|
|
3314
|
+
/**
|
|
3315
|
+
* The uid of a referenced entity or component.
|
|
3316
|
+
*
|
|
3317
|
+
* @param target - The field's value.
|
|
3318
|
+
* @returns Its uid, or `null` for anything without one.
|
|
3319
|
+
*/
|
|
3320
|
+
function uidOf(target) {
|
|
3321
|
+
const uid = typeof target === "object" && target !== null ? Reflect.get(target, "uid") : null;
|
|
3322
|
+
return typeof uid === "string" ? uid : null;
|
|
3323
|
+
}
|
|
3324
|
+
/**
|
|
3325
|
+
* Narrows JSON to an object. `Array.isArray` does not remove a readonly array from the union, so the
|
|
3326
|
+
* discrimination lives here once.
|
|
3327
|
+
*
|
|
3328
|
+
* @param value - The JSON.
|
|
3329
|
+
* @returns The object, or `null` for anything else.
|
|
3330
|
+
*/
|
|
3331
|
+
function asJsonObject(value) {
|
|
3332
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return null;
|
|
3333
|
+
return value;
|
|
3334
|
+
}
|
|
3335
|
+
/**
|
|
3336
|
+
* Narrows JSON to an array.
|
|
3337
|
+
*
|
|
3338
|
+
* @param value - The JSON.
|
|
3339
|
+
* @returns The array, or `null`.
|
|
3340
|
+
*/
|
|
3341
|
+
function asJsonArray(value) {
|
|
3342
|
+
return Array.isArray(value) ? value : null;
|
|
3343
|
+
}
|
|
3344
|
+
/**
|
|
3345
|
+
* Tells whether JSON references an entity or component of a set.
|
|
3346
|
+
*
|
|
3347
|
+
* @param value - The JSON.
|
|
3348
|
+
* @param entities - The entity uids.
|
|
3349
|
+
* @param components - The component uids.
|
|
3350
|
+
* @returns True when a `$entity` or `$component` names one of them, or is an instance path that
|
|
3351
|
+
* starts at one of the entities.
|
|
3352
|
+
*/
|
|
3353
|
+
function pointsInto(value, entities, components) {
|
|
3354
|
+
const array = asJsonArray(value);
|
|
3355
|
+
if (array !== null) return array.some((item) => pointsInto(item, entities, components));
|
|
3356
|
+
const object = asJsonObject(value);
|
|
3357
|
+
if (object === null) return false;
|
|
3358
|
+
const entity = object["$entity"];
|
|
3359
|
+
const component = object["$component"];
|
|
3360
|
+
return typeof entity === "string" && (entities.has(entity) || entities.has(pathHead(entity))) || typeof component === "string" && (components.has(component) || entities.has(pathHead(component))) || Object.values(object).some((item) => pointsInto(item, entities, components));
|
|
3361
|
+
}
|
|
3362
|
+
/**
|
|
3363
|
+
* The first segment of an instance path (`"<instanceRootUid>/<uidInThePrefab>"`), the document
|
|
3364
|
+
* entity the path starts at; a plain uid has none.
|
|
3365
|
+
*
|
|
3366
|
+
* @param uid - A reference's uid or instance path.
|
|
3367
|
+
* @returns The instance root's uid, or `""` for a plain uid.
|
|
3368
|
+
*/
|
|
3369
|
+
function pathHead(uid) {
|
|
3370
|
+
const at = uid.indexOf("/");
|
|
3371
|
+
return at <= 0 ? "" : uid.slice(0, at);
|
|
3372
|
+
}
|
|
3263
3373
|
/**
|
|
3264
3374
|
* Copies a JSON value, so the host's settings never share an object with the editor's message.
|
|
3265
3375
|
*
|
|
@@ -3713,9 +3823,25 @@ var DocumentMirror = class {
|
|
|
3713
3823
|
decoder(built) {
|
|
3714
3824
|
const index = this.index();
|
|
3715
3825
|
const assets = this.#app.assets;
|
|
3826
|
+
const rootOf = (uid) => {
|
|
3827
|
+
const head = pathHead(uid);
|
|
3828
|
+
const root = head === "" ? null : index?.entities.get(head) ?? built?.entity(head) ?? null;
|
|
3829
|
+
return root === null ? null : {
|
|
3830
|
+
root,
|
|
3831
|
+
rest: uid.slice(head.length + 1)
|
|
3832
|
+
};
|
|
3833
|
+
};
|
|
3716
3834
|
return {
|
|
3717
|
-
entity: (uid) =>
|
|
3718
|
-
|
|
3835
|
+
entity: (uid) => {
|
|
3836
|
+
const known = index?.entities.get(uid) ?? built?.entity(uid) ?? null;
|
|
3837
|
+
const path = known === null ? rootOf(uid) : null;
|
|
3838
|
+
return path === null ? known : instanceEntityAt(path.root, path.rest);
|
|
3839
|
+
},
|
|
3840
|
+
component: (uid) => {
|
|
3841
|
+
const known = index?.components.get(uid) ?? built?.component(uid) ?? index?.added.get(uid) ?? null;
|
|
3842
|
+
const path = known === null ? rootOf(uid) : null;
|
|
3843
|
+
return path === null ? known : instanceComponentAt(path.root, path.rest);
|
|
3844
|
+
},
|
|
3719
3845
|
asset: (address, type) => {
|
|
3720
3846
|
const handle = assets.get(address);
|
|
3721
3847
|
return handle !== null && handle.state === "loaded" && (type === null || handle.type === type) ? handle : null;
|
|
@@ -4626,6 +4752,107 @@ function sceneViewMode(app, scene) {
|
|
|
4626
4752
|
const has3D = app.world.components(Camera).some(inScene);
|
|
4627
4753
|
return has2D && !has3D ? ViewMode.twoD : ViewMode.threeD;
|
|
4628
4754
|
}
|
|
4755
|
+
/** The view a screen-space layer keeps: no camera at all. */
|
|
4756
|
+
const IDENTITY_LAYER_VIEW = {
|
|
4757
|
+
x: 0,
|
|
4758
|
+
y: 0,
|
|
4759
|
+
zoom: 1,
|
|
4760
|
+
rotation: 0
|
|
4761
|
+
};
|
|
4762
|
+
/**
|
|
4763
|
+
* The view of a world layer centred on a point, as `@ignifx/2d`'s sync writes it: Lite's
|
|
4764
|
+
* `positionPx` is the layer pixel at the top-left corner, so the centre is moved back by half the
|
|
4765
|
+
* image, turned by the view's rotation.
|
|
4766
|
+
*
|
|
4767
|
+
* @param shot - What the camera shows.
|
|
4768
|
+
* @param widthPx - The image width.
|
|
4769
|
+
* @param heightPx - The image height.
|
|
4770
|
+
* @param pixelsPerUnit - Layer pixels per metre.
|
|
4771
|
+
* @returns The layer's view.
|
|
4772
|
+
*/
|
|
4773
|
+
function centredLayerView(shot, widthPx, heightPx, pixelsPerUnit) {
|
|
4774
|
+
const zoom = shot.zoom === 0 ? 1 : shot.zoom;
|
|
4775
|
+
const halfWidth = widthPx * .5 / zoom;
|
|
4776
|
+
const halfHeight = heightPx * .5 / zoom;
|
|
4777
|
+
const cos = Math.cos(shot.rotation);
|
|
4778
|
+
const sin = Math.sin(shot.rotation);
|
|
4779
|
+
const centreXPx = shot.centreX * pixelsPerUnit;
|
|
4780
|
+
const centreYPx = -shot.centreY * pixelsPerUnit;
|
|
4781
|
+
return {
|
|
4782
|
+
x: centreXPx - halfWidth * cos - halfHeight * sin,
|
|
4783
|
+
y: centreYPx + halfWidth * sin - halfHeight * cos,
|
|
4784
|
+
zoom,
|
|
4785
|
+
rotation: shot.rotation
|
|
4786
|
+
};
|
|
4787
|
+
}
|
|
4788
|
+
/**
|
|
4789
|
+
* What a `Camera2D` shows in an image of a size: its own `resolve` (orthographic size, pixel-perfect
|
|
4790
|
+
* snapping, bounds) run against that size, else `zoom = heightPx / (2 · size · PPU)` at its
|
|
4791
|
+
* position.
|
|
4792
|
+
*
|
|
4793
|
+
* @remarks
|
|
4794
|
+
* `resolve` stores the size it was given on the camera. The scene view draws through the editor's
|
|
4795
|
+
* own `Camera2D`, so the level's camera keeps those values only until a frame draws through it.
|
|
4796
|
+
*
|
|
4797
|
+
* @param camera - The level's camera.
|
|
4798
|
+
* @param widthPx - The image width.
|
|
4799
|
+
* @param heightPx - The image height.
|
|
4800
|
+
* @param pixelsPerUnit - Layer pixels per metre.
|
|
4801
|
+
* @returns The centre, zoom and rotation.
|
|
4802
|
+
*/
|
|
4803
|
+
function camera2DShot(camera, widthPx, heightPx, pixelsPerUnit) {
|
|
4804
|
+
const matrix = camera.entity.transform.worldMatrix;
|
|
4805
|
+
const worldX = matrix[12] ?? 0;
|
|
4806
|
+
const worldY = matrix[13] ?? 0;
|
|
4807
|
+
const rotation = Math.atan2(matrix[1] ?? 0, matrix[0] ?? 1);
|
|
4808
|
+
const resolve = Reflect.get(camera, "resolve");
|
|
4809
|
+
const centre = Reflect.get(camera, "centre");
|
|
4810
|
+
if (typeof resolve === "function") {
|
|
4811
|
+
Reflect.apply(resolve, camera, [
|
|
4812
|
+
worldX,
|
|
4813
|
+
worldY,
|
|
4814
|
+
widthPx,
|
|
4815
|
+
heightPx,
|
|
4816
|
+
pixelsPerUnit
|
|
4817
|
+
]);
|
|
4818
|
+
const zoom = Reflect.get(camera, "zoom");
|
|
4819
|
+
const x = typeof centre === "object" && centre !== null ? Reflect.get(centre, "x") : void 0;
|
|
4820
|
+
const y = typeof centre === "object" && centre !== null ? Reflect.get(centre, "y") : void 0;
|
|
4821
|
+
if (typeof zoom === "number" && typeof x === "number" && typeof y === "number") return {
|
|
4822
|
+
centreX: x,
|
|
4823
|
+
centreY: y,
|
|
4824
|
+
zoom,
|
|
4825
|
+
rotation
|
|
4826
|
+
};
|
|
4827
|
+
}
|
|
4828
|
+
return {
|
|
4829
|
+
centreX: worldX,
|
|
4830
|
+
centreY: worldY,
|
|
4831
|
+
zoom: zoomForSize(camera.orthographicSize > 0 ? camera.orthographicSize : 1, heightPx, pixelsPerUnit),
|
|
4832
|
+
rotation
|
|
4833
|
+
};
|
|
4834
|
+
}
|
|
4835
|
+
/**
|
|
4836
|
+
* The project's sprite layers, in draw order, from `app.twoD.layers`.
|
|
4837
|
+
*
|
|
4838
|
+
* @param app - The app.
|
|
4839
|
+
* @returns The layers, or `null` when the project has no 2D toolkit.
|
|
4840
|
+
*/
|
|
4841
|
+
function twoDLayersOf(app) {
|
|
4842
|
+
const service = Reflect.get(app, "twoD");
|
|
4843
|
+
if (typeof service !== "object" || service === null) return null;
|
|
4844
|
+
const layers = Reflect.get(service, "layers");
|
|
4845
|
+
if (!Array.isArray(layers)) return null;
|
|
4846
|
+
const out = [];
|
|
4847
|
+
for (const entry of layers) {
|
|
4848
|
+
const layer = typeof entry === "object" && entry !== null ? Reflect.get(entry, "layer") : null;
|
|
4849
|
+
if (typeof layer === "object" && layer !== null) out.push({
|
|
4850
|
+
layer,
|
|
4851
|
+
screenSpace: Reflect.get(Object(entry), "screenSpace") === true
|
|
4852
|
+
});
|
|
4853
|
+
}
|
|
4854
|
+
return out;
|
|
4855
|
+
}
|
|
4629
4856
|
//#endregion
|
|
4630
4857
|
//#region src/scene/editor-camera-2d.ts
|
|
4631
4858
|
/**
|
|
@@ -5238,10 +5465,19 @@ async function encodeCapture(capture, size, format, quality) {
|
|
|
5238
5465
|
targetContext.imageSmoothingQuality = "high";
|
|
5239
5466
|
targetContext.drawImage(source, 0, 0, size.width, size.height);
|
|
5240
5467
|
const type = format === "png" ? "image/png" : "image/jpeg";
|
|
5241
|
-
|
|
5468
|
+
return encodeBlob(await target.convertToBlob(format === "png" ? { type } : {
|
|
5242
5469
|
type,
|
|
5243
5470
|
quality
|
|
5244
|
-
});
|
|
5471
|
+
}), type);
|
|
5472
|
+
}
|
|
5473
|
+
/**
|
|
5474
|
+
* Writes an encoded image as a data URL.
|
|
5475
|
+
*
|
|
5476
|
+
* @param blob - The PNG or JPEG bytes.
|
|
5477
|
+
* @param type - `"image/png"` or `"image/jpeg"`.
|
|
5478
|
+
* @returns The data URL.
|
|
5479
|
+
*/
|
|
5480
|
+
async function encodeBlob(blob, type) {
|
|
5245
5481
|
return `data:${type};base64,${toBase64(new Uint8Array(await blob.arrayBuffer()))}`;
|
|
5246
5482
|
}
|
|
5247
5483
|
/**
|
|
@@ -5277,12 +5513,6 @@ async function takeScreenshot(app, params) {
|
|
|
5277
5513
|
height: size.height
|
|
5278
5514
|
};
|
|
5279
5515
|
}
|
|
5280
|
-
//#endregion
|
|
5281
|
-
//#region src/scene/game-view.ts
|
|
5282
|
-
/**
|
|
5283
|
-
* The Game panel's view (engine ask E8): the open scene through its own main camera, rendered into
|
|
5284
|
-
* a render texture beside the editor camera's frame (`setGameView`, `gameViewFrame`).
|
|
5285
|
-
*/
|
|
5286
5516
|
/** The JPEG quality when the request gives none, as for `screenshot`. */
|
|
5287
5517
|
const DEFAULT_JPEG_QUALITY$1 = .9;
|
|
5288
5518
|
/**
|
|
@@ -5334,32 +5564,67 @@ var GameView = class {
|
|
|
5334
5564
|
};
|
|
5335
5565
|
}
|
|
5336
5566
|
/**
|
|
5337
|
-
* `gameViewFrame`: renders the document camera into the texture
|
|
5338
|
-
* as an image.
|
|
5567
|
+
* `gameViewFrame`: renders the document camera, a `Camera` into the texture or a `Camera2D`
|
|
5568
|
+
* through the sprite pass, and answers it as an image.
|
|
5339
5569
|
*
|
|
5340
5570
|
* @param app - The scene view's app.
|
|
5341
5571
|
* @param mirror - The open document.
|
|
5342
|
-
* @param params - `{ format, quality? }`.
|
|
5572
|
+
* @param params - `{ format, quality?, width?, height? }`.
|
|
5343
5573
|
* @returns The image and the camera's document uid, or no image when the document has no camera.
|
|
5344
5574
|
*/
|
|
5345
5575
|
async frame(app, mirror, params) {
|
|
5346
|
-
if (!isGameViewFrameParams(params)) throw new InvalidParamsError("gameViewFrame takes { format: \"png\" | \"jpeg\", quality? }.");
|
|
5576
|
+
if (!isGameViewFrameParams(params)) throw new InvalidParamsError("gameViewFrame takes { format: \"png\" | \"jpeg\", quality?, width?, height? } with sides from 1 to 2048.");
|
|
5577
|
+
if (!this.#enabled || this.#texture === null) throw new RpcFailure(RpcErrorCode.invalidRequest, "The game view is off; send \"setGameView\" with enabled: true first.");
|
|
5578
|
+
if (params.width !== void 0 || params.height !== void 0) this.set(app, {
|
|
5579
|
+
enabled: true,
|
|
5580
|
+
width: params.width ?? this.#width,
|
|
5581
|
+
height: params.height ?? this.#height
|
|
5582
|
+
});
|
|
5347
5583
|
const texture = this.#texture;
|
|
5348
|
-
if (!this.#enabled || texture === null) throw new RpcFailure(RpcErrorCode.invalidRequest, "The game view is off; send \"setGameView\" with enabled: true first.");
|
|
5349
5584
|
const size = {
|
|
5350
5585
|
width: this.#width,
|
|
5351
5586
|
height: this.#height
|
|
5352
5587
|
};
|
|
5588
|
+
const quality = params.quality ?? DEFAULT_JPEG_QUALITY$1;
|
|
5353
5589
|
const camera = documentCamera(app, mirror);
|
|
5354
|
-
if (camera
|
|
5590
|
+
if (camera !== null) {
|
|
5591
|
+
const uid = (mirror.documentEntityOf(camera.entity) ?? camera.entity).uid;
|
|
5592
|
+
await app.renderer.renderToTexture(camera, texture, { maxWaitMs: 20 });
|
|
5593
|
+
return {
|
|
5594
|
+
dataUrl: await encodeCapture(await texture.readPixels(), size, params.format, quality),
|
|
5595
|
+
...size,
|
|
5596
|
+
camera: uid
|
|
5597
|
+
};
|
|
5598
|
+
}
|
|
5599
|
+
const camera2D = levelCamera2D(app, mirror.scene);
|
|
5600
|
+
const layers = twoDLayersOf(app);
|
|
5601
|
+
const twoD = twoDServiceOf(app);
|
|
5602
|
+
if (camera2D === null || layers === null || twoD === null) return {
|
|
5355
5603
|
dataUrl: null,
|
|
5356
5604
|
...size,
|
|
5357
5605
|
camera: null
|
|
5358
5606
|
};
|
|
5359
|
-
const uid = (mirror.documentEntityOf(
|
|
5360
|
-
await app.renderer.
|
|
5607
|
+
const uid = (mirror.documentEntityOf(camera2D.entity) ?? camera2D.entity).uid;
|
|
5608
|
+
await app.renderer.nextFrame({ maxWaitMs: 20 });
|
|
5609
|
+
const world = centredLayerView(camera2DShot(camera2D, size.width, size.height, twoD.pixelsPerUnit), size.width, size.height, twoD.pixelsPerUnit);
|
|
5610
|
+
const draws = layers.map(({ layer, screenSpace }) => {
|
|
5611
|
+
const view = screenSpace ? IDENTITY_LAYER_VIEW : world;
|
|
5612
|
+
return {
|
|
5613
|
+
layer,
|
|
5614
|
+
x: view.x,
|
|
5615
|
+
y: view.y,
|
|
5616
|
+
zoom: view.zoom,
|
|
5617
|
+
rotation: view.rotation
|
|
5618
|
+
};
|
|
5619
|
+
});
|
|
5620
|
+
const { renderSpriteGameView } = await import("./sprite-game-view.js");
|
|
5621
|
+
const { clearColor } = app.settings.section(RENDERING_SETTINGS_SECTION);
|
|
5622
|
+
const type = params.format === "png" ? "image/png" : "image/jpeg";
|
|
5361
5623
|
return {
|
|
5362
|
-
dataUrl: await
|
|
5624
|
+
dataUrl: await encodeBlob(await renderSpriteGameView(app.lite.engine, draws, {
|
|
5625
|
+
...size,
|
|
5626
|
+
clear: clearColor
|
|
5627
|
+
}, type, quality), type),
|
|
5363
5628
|
...size,
|
|
5364
5629
|
camera: uid
|
|
5365
5630
|
};
|
|
@@ -5466,20 +5731,24 @@ const GROUND_MIN_REACH_LINES = 100;
|
|
|
5466
5731
|
/** The 2D grid's lines are never closer than this, in screen pixels; denser ones step up tenfold. */
|
|
5467
5732
|
const MIN_LINE_GAP_PX = 8;
|
|
5468
5733
|
/**
|
|
5469
|
-
* The 3D view's ground grid: centred under the eye, coarser the higher the eye is
|
|
5470
|
-
* that it fades out before its edge is in view.
|
|
5734
|
+
* The 3D view's ground grid: centred under the eye, coarser the higher the eye is above the plane,
|
|
5735
|
+
* and large enough that it fades out before its edge is in view.
|
|
5471
5736
|
*
|
|
5472
5737
|
* @param eye - The editor camera's position, in metres.
|
|
5473
5738
|
* @param size - The spacing `setGrid` asked for, in metres.
|
|
5474
5739
|
* @param far - The camera's far plane, in metres; the grid stays inside it.
|
|
5740
|
+
* @param height - The plane's world y, in metres.
|
|
5741
|
+
* @param overlay - Whether the grid draws over the scene.
|
|
5475
5742
|
* @returns The placement.
|
|
5476
5743
|
*/
|
|
5477
|
-
function groundGridPlacement(eye, size, far) {
|
|
5478
|
-
const
|
|
5479
|
-
const step = size * 10 ** Math.max(0, Math.floor(Math.log10(
|
|
5480
|
-
const reach = Math.min(Math.max(
|
|
5744
|
+
function groundGridPlacement(eye, size, far, height = 0, overlay = false) {
|
|
5745
|
+
const above = Math.max(Math.abs(eye.y - height), size);
|
|
5746
|
+
const step = size * 10 ** Math.max(0, Math.floor(Math.log10(above / (size * GROUND_LINES_PER_HEIGHT))));
|
|
5747
|
+
const reach = Math.min(Math.max(above * GROUND_REACH_PER_HEIGHT, step * GROUND_MIN_REACH_LINES), far * .9);
|
|
5481
5748
|
return {
|
|
5482
5749
|
plane: "ground",
|
|
5750
|
+
height,
|
|
5751
|
+
overlay,
|
|
5483
5752
|
centerX: eye.x,
|
|
5484
5753
|
centerY: eye.z,
|
|
5485
5754
|
extent: reach * 2,
|
|
@@ -5501,6 +5770,8 @@ function screenGridPlacement(view, size) {
|
|
|
5501
5770
|
const extent = 2 * Math.max(view.widthPx, view.heightPx) / pixelsPerMetre;
|
|
5502
5771
|
const base = {
|
|
5503
5772
|
plane: "screen",
|
|
5773
|
+
height: 0,
|
|
5774
|
+
overlay: true,
|
|
5504
5775
|
centerX: view.centerX,
|
|
5505
5776
|
centerY: view.centerY,
|
|
5506
5777
|
extent
|
|
@@ -5522,55 +5793,6 @@ function screenGridPlacement(view, size) {
|
|
|
5522
5793
|
};
|
|
5523
5794
|
}
|
|
5524
5795
|
//#endregion
|
|
5525
|
-
//#region src/scene/json.ts
|
|
5526
|
-
/**
|
|
5527
|
-
* The uid of a referenced entity or component.
|
|
5528
|
-
*
|
|
5529
|
-
* @param target - The field's value.
|
|
5530
|
-
* @returns Its uid, or `null` for anything without one.
|
|
5531
|
-
*/
|
|
5532
|
-
function uidOf(target) {
|
|
5533
|
-
const uid = typeof target === "object" && target !== null ? Reflect.get(target, "uid") : null;
|
|
5534
|
-
return typeof uid === "string" ? uid : null;
|
|
5535
|
-
}
|
|
5536
|
-
/**
|
|
5537
|
-
* Narrows JSON to an object. `Array.isArray` does not remove a readonly array from the union, so the
|
|
5538
|
-
* discrimination lives here once.
|
|
5539
|
-
*
|
|
5540
|
-
* @param value - The JSON.
|
|
5541
|
-
* @returns The object, or `null` for anything else.
|
|
5542
|
-
*/
|
|
5543
|
-
function asJsonObject(value) {
|
|
5544
|
-
if (typeof value !== "object" || value === null || Array.isArray(value)) return null;
|
|
5545
|
-
return value;
|
|
5546
|
-
}
|
|
5547
|
-
/**
|
|
5548
|
-
* Narrows JSON to an array.
|
|
5549
|
-
*
|
|
5550
|
-
* @param value - The JSON.
|
|
5551
|
-
* @returns The array, or `null`.
|
|
5552
|
-
*/
|
|
5553
|
-
function asJsonArray(value) {
|
|
5554
|
-
return Array.isArray(value) ? value : null;
|
|
5555
|
-
}
|
|
5556
|
-
/**
|
|
5557
|
-
* Tells whether JSON references an entity or component of a set.
|
|
5558
|
-
*
|
|
5559
|
-
* @param value - The JSON.
|
|
5560
|
-
* @param entities - The entity uids.
|
|
5561
|
-
* @param components - The component uids.
|
|
5562
|
-
* @returns True when a `$entity` or `$component` names one of them.
|
|
5563
|
-
*/
|
|
5564
|
-
function pointsInto(value, entities, components) {
|
|
5565
|
-
const array = asJsonArray(value);
|
|
5566
|
-
if (array !== null) return array.some((item) => pointsInto(item, entities, components));
|
|
5567
|
-
const object = asJsonObject(value);
|
|
5568
|
-
if (object === null) return false;
|
|
5569
|
-
const entity = object["$entity"];
|
|
5570
|
-
const component = object["$component"];
|
|
5571
|
-
return typeof entity === "string" && entities.has(entity) || typeof component === "string" && components.has(component) || Object.values(object).some((item) => pointsInto(item, entities, components));
|
|
5572
|
-
}
|
|
5573
|
-
//#endregion
|
|
5574
5796
|
//#region src/scene/held-references.ts
|
|
5575
5797
|
/**
|
|
5576
5798
|
* What instance members outside a subtree that is about to be rebuilt hold in it: the reference
|
|
@@ -6716,6 +6938,9 @@ function settingsSet(app) {
|
|
|
6716
6938
|
* The stage is a separate app on a 1x1 `OffscreenCanvas`, built from the project's own options, so
|
|
6717
6939
|
* a thumbnail never shows the open document, never lights it, and is never lit by it. It is
|
|
6718
6940
|
* created on the first request and lives until the host is disposed.
|
|
6941
|
+
*
|
|
6942
|
+
* The channel runs `renderThumbnail` beside its one-at-a-time queue, so the frames a thumbnail
|
|
6943
|
+
* waits for hold up no other request; thumbnails queue among themselves here, one stage at a time.
|
|
6719
6944
|
*/
|
|
6720
6945
|
/** The JPEG quality when the request gives none, as for `screenshot`. */
|
|
6721
6946
|
const DEFAULT_JPEG_QUALITY = .9;
|
|
@@ -6727,6 +6952,12 @@ const SUPERSAMPLE = 2;
|
|
|
6727
6952
|
const MAX_SETTLE_FRAMES = 120;
|
|
6728
6953
|
/** How many frames in a row the bounds must hold still before the thumbnail is taken. */
|
|
6729
6954
|
const STILL_FRAMES = 2;
|
|
6955
|
+
/**
|
|
6956
|
+
* How many frames in a row nothing may draw, with no asset of the stage still loading, before the
|
|
6957
|
+
* subject is taken to be empty (a failed model, a prefab without meshes). A loaded model builds its
|
|
6958
|
+
* meshes in the first frame.
|
|
6959
|
+
*/
|
|
6960
|
+
const EMPTY_FRAMES = 4;
|
|
6730
6961
|
/** The direction from the subject to the camera: in front, above and to the right. */
|
|
6731
6962
|
const VIEW_DIRECTION = {
|
|
6732
6963
|
x: .55,
|
|
@@ -6813,6 +7044,10 @@ var ThumbnailRenderer = class {
|
|
|
6813
7044
|
#stage = null;
|
|
6814
7045
|
#texture = null;
|
|
6815
7046
|
#loads = 0;
|
|
7047
|
+
/** The previous thumbnail, which the next waits for: the stage shows one subject at a time. */
|
|
7048
|
+
#queue = Promise.resolve();
|
|
7049
|
+
/** Whether the stage's assets have a load in flight, from their last progress report. */
|
|
7050
|
+
#isLoading = false;
|
|
6816
7051
|
#isDisposed = false;
|
|
6817
7052
|
/**
|
|
6818
7053
|
* Keeps the factory; nothing is created until the first thumbnail.
|
|
@@ -6826,9 +7061,20 @@ var ThumbnailRenderer = class {
|
|
|
6826
7061
|
* `renderThumbnail`: loads the asset alone on the stage, frames it, renders it and encodes it.
|
|
6827
7062
|
*
|
|
6828
7063
|
* @param params - `{ asset, size?, format, quality? }`.
|
|
6829
|
-
* @returns The image.
|
|
7064
|
+
* @returns The image, once the thumbnails asked for before it are done.
|
|
6830
7065
|
*/
|
|
6831
7066
|
async render(params) {
|
|
7067
|
+
const run = this.#queue.then(async () => this.#render(params));
|
|
7068
|
+
this.#queue = run.catch(() => void 0);
|
|
7069
|
+
return run;
|
|
7070
|
+
}
|
|
7071
|
+
/**
|
|
7072
|
+
* Renders one thumbnail; {@link ThumbnailRenderer.render} runs them one at a time.
|
|
7073
|
+
*
|
|
7074
|
+
* @param params - The request's `params`.
|
|
7075
|
+
* @returns The image.
|
|
7076
|
+
*/
|
|
7077
|
+
async #render(params) {
|
|
6832
7078
|
if (!isRenderThumbnailParams(params)) throw new InvalidParamsError("renderThumbnail takes { asset: address | { $asset, type? }, size?: 1 to 1024, format: \"png\" | \"jpeg\", quality? }.");
|
|
6833
7079
|
const { address, kind } = thumbnailSubject(params);
|
|
6834
7080
|
const { app, camera } = await (this.#stage ??= this.#open());
|
|
@@ -6838,11 +7084,11 @@ var ThumbnailRenderer = class {
|
|
|
6838
7084
|
mode: "single"
|
|
6839
7085
|
});
|
|
6840
7086
|
try {
|
|
6841
|
-
frameCamera(camera, await settledBounds(app, instance));
|
|
7087
|
+
frameCamera(camera, await settledBounds(app, instance, () => this.#isLoading));
|
|
6842
7088
|
await nextFrame();
|
|
6843
7089
|
const size = params.size ?? 128;
|
|
6844
7090
|
const texture = this.#textureOf(app, size * SUPERSAMPLE);
|
|
6845
|
-
await app.renderer.renderToTexture(camera, texture);
|
|
7091
|
+
await app.renderer.renderToTexture(camera, texture, { maxWaitMs: 20 });
|
|
6846
7092
|
return {
|
|
6847
7093
|
dataUrl: await encodeCapture(await texture.readPixels(), {
|
|
6848
7094
|
width: size,
|
|
@@ -6870,6 +7116,9 @@ var ThumbnailRenderer = class {
|
|
|
6870
7116
|
*/
|
|
6871
7117
|
async #open() {
|
|
6872
7118
|
const app = await this.#createApp();
|
|
7119
|
+
app.assets.onProgress.connect((progress) => {
|
|
7120
|
+
this.#isLoading = progress.loaded < progress.total;
|
|
7121
|
+
});
|
|
6873
7122
|
const scene = app.world.createScene("thumbnail-stage", { persistent: true });
|
|
6874
7123
|
const camera = app.world.createEntity("Thumbnail Camera", { scene }).addComponent(Camera, {
|
|
6875
7124
|
fov: STAGE_FOV,
|
|
@@ -6927,20 +7176,21 @@ function nextFrame() {
|
|
|
6927
7176
|
});
|
|
6928
7177
|
}
|
|
6929
7178
|
/**
|
|
6930
|
-
* Waits until a loaded subject's meshes exist and hold still, then measures them.
|
|
7179
|
+
* Waits until a loaded subject's meshes exist and hold still, then measures them. It stops early
|
|
7180
|
+
* when nothing has drawn for a few frames and nothing is loading, as nothing will.
|
|
6931
7181
|
*
|
|
6932
7182
|
* @param app - The stage app.
|
|
6933
7183
|
* @param instance - The loaded subject.
|
|
7184
|
+
* @param isLoading - Whether the stage still has an asset load in flight.
|
|
6934
7185
|
* @returns Its world bounds; a unit box at the origin when nothing draws.
|
|
6935
7186
|
*/
|
|
6936
|
-
async function settledBounds(app, instance) {
|
|
7187
|
+
async function settledBounds(app, instance, isLoading) {
|
|
7188
|
+
const settle = boundsSettler();
|
|
6937
7189
|
let last = null;
|
|
6938
|
-
let
|
|
6939
|
-
for (let frame = 0; frame < MAX_SETTLE_FRAMES && still < STILL_FRAMES; frame += 1) {
|
|
7190
|
+
for (let frame = 0; frame < MAX_SETTLE_FRAMES; frame += 1) {
|
|
6940
7191
|
await nextFrame();
|
|
6941
|
-
|
|
6942
|
-
|
|
6943
|
-
last = bounds;
|
|
7192
|
+
last = unionBounds(app, instance.roots);
|
|
7193
|
+
if (settle(last, isLoading())) break;
|
|
6944
7194
|
}
|
|
6945
7195
|
return last ?? {
|
|
6946
7196
|
min: {
|
|
@@ -6956,6 +7206,26 @@ async function settledBounds(app, instance) {
|
|
|
6956
7206
|
};
|
|
6957
7207
|
}
|
|
6958
7208
|
/**
|
|
7209
|
+
* Decides, frame by frame, when a thumbnail's subject has settled: its bounds held still for
|
|
7210
|
+
* `STILL_FRAMES` frames, or nothing has drawn for `EMPTY_FRAMES` frames with nothing loading.
|
|
7211
|
+
*
|
|
7212
|
+
* @returns A function that takes each frame's bounds (`null` when nothing draws) and whether an
|
|
7213
|
+
* asset is loading, and answers true once the subject has settled.
|
|
7214
|
+
*
|
|
7215
|
+
* @internal
|
|
7216
|
+
*/
|
|
7217
|
+
function boundsSettler() {
|
|
7218
|
+
let last = null;
|
|
7219
|
+
let still = 0;
|
|
7220
|
+
let empty = 0;
|
|
7221
|
+
return (bounds, isLoading) => {
|
|
7222
|
+
still = bounds !== null && last !== null && sameBounds(bounds, last) ? still + 1 : 0;
|
|
7223
|
+
empty = bounds === null && !isLoading ? empty + 1 : 0;
|
|
7224
|
+
last = bounds;
|
|
7225
|
+
return still >= STILL_FRAMES || empty >= EMPTY_FRAMES;
|
|
7226
|
+
};
|
|
7227
|
+
}
|
|
7228
|
+
/**
|
|
6959
7229
|
* The union of entities' world bounds.
|
|
6960
7230
|
*
|
|
6961
7231
|
* @param app - The stage app.
|
|
@@ -7115,6 +7385,11 @@ const EDITOR_CAMERA_PRIORITY = 1e6;
|
|
|
7115
7385
|
var SceneHost = class {
|
|
7116
7386
|
/** The scene methods, by name, for the channel. */
|
|
7117
7387
|
methods;
|
|
7388
|
+
/**
|
|
7389
|
+
* The methods the channel runs beside its queue: `renderThumbnail`, which renders on a stage app
|
|
7390
|
+
* of its own, never reads the document, and can take a couple of seconds.
|
|
7391
|
+
*/
|
|
7392
|
+
unqueued = /* @__PURE__ */ new Set([RenderViewMethod.renderThumbnail]);
|
|
7118
7393
|
#notify;
|
|
7119
7394
|
#app = null;
|
|
7120
7395
|
#mirror = null;
|
|
@@ -7140,7 +7415,9 @@ var SceneHost = class {
|
|
|
7140
7415
|
#grid = null;
|
|
7141
7416
|
#gridSettings = {
|
|
7142
7417
|
visible: true,
|
|
7143
|
-
size: 1
|
|
7418
|
+
size: 1,
|
|
7419
|
+
overlay: false,
|
|
7420
|
+
height: 0
|
|
7144
7421
|
};
|
|
7145
7422
|
/** The editor's line sets, as `setEditorLines` last set them, by id; drawn once `#lines` exists. */
|
|
7146
7423
|
#lineSets = /* @__PURE__ */ new Map();
|
|
@@ -7209,7 +7486,7 @@ var SceneHost = class {
|
|
|
7209
7486
|
methods.set(SceneMethod.setEditorLines, (params) => this.#setEditorLines(params));
|
|
7210
7487
|
methods.set(SceneMethod.clearEditorLines, (params) => this.#clearEditorLines(params));
|
|
7211
7488
|
}
|
|
7212
|
-
this.methods = new Map([...methods].map(([name, handler]) => [name, async (params) => this.#serial(() => handler(params))]));
|
|
7489
|
+
this.methods = new Map([...methods].map(([name, handler]) => [name, this.unqueued.has(name) ? handler : async (params) => this.#serial(() => handler(params))]));
|
|
7213
7490
|
}
|
|
7214
7491
|
/**
|
|
7215
7492
|
* The persistent scene instance that holds the host's own objects, such as the editor camera.
|
|
@@ -7643,18 +7920,20 @@ var SceneHost = class {
|
|
|
7643
7920
|
return null;
|
|
7644
7921
|
}
|
|
7645
7922
|
/**
|
|
7646
|
-
* `setGrid`: shows or hides the view's grid and sets its spacing
|
|
7647
|
-
* default.
|
|
7923
|
+
* `setGrid`: shows or hides the view's grid and sets its spacing, and the 3D grid's height and
|
|
7924
|
+
* whether it draws over the scene. A field left out takes its default.
|
|
7648
7925
|
*
|
|
7649
|
-
* @param params - `{ visible?, size? }`.
|
|
7926
|
+
* @param params - `{ visible?, size?, overlay?, height? }`.
|
|
7650
7927
|
* @returns `null`.
|
|
7651
7928
|
*/
|
|
7652
7929
|
#setGrid(params) {
|
|
7653
7930
|
this.#requireMirror(SceneMethod.setGrid);
|
|
7654
|
-
if (!isSetGridParams(params)) throw new InvalidParamsError("setGrid takes { visible?: boolean, size?: number from 0.001 to 1000 }.");
|
|
7931
|
+
if (!isSetGridParams(params)) throw new InvalidParamsError("setGrid takes { visible?: boolean, size?: number from 0.001 to 1000, overlay?: boolean, height?: number from -100000 to 100000 }.");
|
|
7655
7932
|
this.#gridSettings = {
|
|
7656
7933
|
visible: params.visible ?? true,
|
|
7657
|
-
size: params.size ?? 1
|
|
7934
|
+
size: params.size ?? 1,
|
|
7935
|
+
overlay: params.overlay ?? false,
|
|
7936
|
+
height: params.height ?? 0
|
|
7658
7937
|
};
|
|
7659
7938
|
return null;
|
|
7660
7939
|
}
|
|
@@ -7717,12 +7996,12 @@ var SceneHost = class {
|
|
|
7717
7996
|
* @returns The placement, or `null` while the grid is hidden.
|
|
7718
7997
|
*/
|
|
7719
7998
|
#gridPlacement() {
|
|
7720
|
-
const { visible, size } = this.#gridSettings;
|
|
7999
|
+
const { visible, size, overlay, height } = this.#gridSettings;
|
|
7721
8000
|
if (!visible) return null;
|
|
7722
8001
|
const camera2D = this.#camera2D;
|
|
7723
8002
|
if (this.#viewMode === ViewMode.twoD && camera2D !== null) return screenGridPlacement(camera2D.view(), size);
|
|
7724
8003
|
const eye = this.#eye;
|
|
7725
|
-
return eye === null ? null : groundGridPlacement(eye.transform.position, size, eye.far);
|
|
8004
|
+
return eye === null ? null : groundGridPlacement(eye.transform.position, size, eye.far, height, overlay);
|
|
7726
8005
|
}
|
|
7727
8006
|
/**
|
|
7728
8007
|
* `getColliderOutlines`: the world-space outlines of the requested entities' colliders, from the
|
|
@@ -8190,8 +8469,12 @@ async function startEditorHost(options) {
|
|
|
8190
8469
|
HostCapability.logRelay,
|
|
8191
8470
|
HostCapability.hotReloadDefaults,
|
|
8192
8471
|
HostCapability.gameView,
|
|
8472
|
+
HostCapability.gameViewOnDemand,
|
|
8473
|
+
HostCapability.gameViewSize,
|
|
8474
|
+
HostCapability.gameView2d,
|
|
8193
8475
|
...canRenderThumbnails(options) ? [HostCapability.thumbnails] : [],
|
|
8194
8476
|
HostCapability.grid,
|
|
8477
|
+
HostCapability.gridOverlay,
|
|
8195
8478
|
HostCapability.tilemapCells,
|
|
8196
8479
|
HostCapability.editorLines,
|
|
8197
8480
|
HostCapability.spriteAnimation
|
|
@@ -8219,6 +8502,7 @@ async function startEditorHost(options) {
|
|
|
8219
8502
|
hostKind: options.hostKind ?? HostKind.scene
|
|
8220
8503
|
},
|
|
8221
8504
|
methods: scene.methods,
|
|
8505
|
+
unqueued: scene.unqueued,
|
|
8222
8506
|
heartbeatIntervalMs,
|
|
8223
8507
|
onReady: () => {
|
|
8224
8508
|
scene.sendSchemas();
|
|
@@ -9029,6 +9313,6 @@ function listenForEditorPlayControls(options) {
|
|
|
9029
9313
|
};
|
|
9030
9314
|
}
|
|
9031
9315
|
//#endregion
|
|
9032
|
-
export { ApplyOpFailureCode, COLLIDER_OUTLINES_MAX_ENTITIES, COLLIDER_OUTLINES_MAX_NUMBERS, DEFAULT_HEARTBEAT_INTERVAL_MS, EDITOR_CONNECT_MESSAGE_TYPE, EDITOR_LINES_MAX_ID_LENGTH, EDITOR_LINES_MAX_NUMBERS, EDITOR_LINES_MAX_SETS, EditorHostErrorCode, GAME_VIEW_DEFAULT_SIZE, GAME_VIEW_MAX_SIZE, GRID_MAX_SIZE, GRID_MIN_SIZE, GizmoMode, GizmoSpace, HOST_LIST_MAX_LENGTH, HOST_TEXT_MAX_LENGTH, HandshakeMethod, HostCapability, HostKind, HostNotification, JSON_RPC_VERSION, PROTOCOL_VERSION, PickUnit, PlayMethod, PlayNotification, PlayPhase, QUERY_RUNTIME_MAX_COMPONENTS, QUERY_RUNTIME_MAX_JSON_LENGTH, QUERY_RUNTIME_MAX_KEYS, QUERY_RUNTIME_MAX_STRING_LENGTH, RenderViewMethod, RpcErrorCode, SAMPLE_ANIMATION_MAX_NAME_LENGTH, SAMPLE_ANIMATION_MAX_PARAMETERS, SCREENSHOT_MAX_SIZE, SEND_INPUT_MAX_EVENTS, SceneMethod, SceneNotification, SceneOpKind, ScreenshotFormat, THUMBNAIL_DEFAULT_SIZE, THUMBNAIL_MAX_SIZE, TILEMAP_CELLS_MAX_NUMBERS, TRANSFORM_DRAGGING_INTERVAL_MS, ViewMode, isAppErrorData, isApplyOpsParams, isApplyOpsResult, isAssetReloadedParams, isClearEditorLinesParams, isColliderOutlineRecord, isColliderOutlineSet, isEditorConnectMessage, isEditorOrigin, isEntitySelection, isFrameParams, isGameViewFrameParams, isGameViewFrameResult, isGameViewState, isHostErrorParams, isHotReloadedParams, isIncompatibleProtocolData, isInvalidSceneFileData, isJsonObject, isJsonValue, isLogParams, isOpenSceneParams, isOpenSceneResult, isPickParams, isPickResult, isPlayState, isPlayStateReport, isPlayStats, isProtocolVersion, isQueryRuntimeParams, isQueryRuntimeResult, isReadBackParams, isReadBackResult, isReadyResult, isRenderThumbnailParams, isRpcMessage, isSampleAnimationParams, isSampleAnimationResult, isSampleSpriteAnimationParams, isSampleSpriteAnimationResult, isSceneFile, isSceneFileAssetRef, isSceneFileComponent, isSceneFileEntity, isSceneFileInstance, isSceneFileOverride, isSceneFileTransform, isSceneIssue, isSceneOp, isSceneOpenedParams, isSchemaSet, isScreenshotParams, isScreenshotResult, isSendInputEvent, isSendInputParams, isSendInputResult, isSetAnimateMaterialsParams, isSetEditorLinesParams, isSetGameViewParams, isSetGizmoParams, isSetGridParams, isSetTilemapCellsParams, isSetTilemapCellsResult, isSetViewModeParams, isSettingsSet, isThumbnailResult, isTransformDraggedParams, isTransformDraggingParams, listenForEditorPlayControls, protocolVersionIsCompatible, startEditorHost, startEditorPlayControls };
|
|
9316
|
+
export { ApplyOpFailureCode, COLLIDER_OUTLINES_MAX_ENTITIES, COLLIDER_OUTLINES_MAX_NUMBERS, DEFAULT_HEARTBEAT_INTERVAL_MS, EDITOR_CONNECT_MESSAGE_TYPE, EDITOR_LINES_MAX_ID_LENGTH, EDITOR_LINES_MAX_NUMBERS, EDITOR_LINES_MAX_SETS, EditorHostErrorCode, GAME_VIEW_DEFAULT_SIZE, GAME_VIEW_MAX_SIZE, GRID_MAX_HEIGHT, GRID_MAX_SIZE, GRID_MIN_SIZE, GizmoMode, GizmoSpace, HOST_LIST_MAX_LENGTH, HOST_TEXT_MAX_LENGTH, HandshakeMethod, HostCapability, HostKind, HostNotification, JSON_RPC_VERSION, PROTOCOL_VERSION, PickUnit, PlayMethod, PlayNotification, PlayPhase, QUERY_RUNTIME_MAX_COMPONENTS, QUERY_RUNTIME_MAX_JSON_LENGTH, QUERY_RUNTIME_MAX_KEYS, QUERY_RUNTIME_MAX_STRING_LENGTH, RenderViewMethod, RpcErrorCode, SAMPLE_ANIMATION_MAX_NAME_LENGTH, SAMPLE_ANIMATION_MAX_PARAMETERS, SCREENSHOT_MAX_SIZE, SEND_INPUT_MAX_EVENTS, SceneMethod, SceneNotification, SceneOpKind, ScreenshotFormat, THUMBNAIL_DEFAULT_SIZE, THUMBNAIL_MAX_SIZE, TILEMAP_CELLS_MAX_NUMBERS, TRANSFORM_DRAGGING_INTERVAL_MS, ViewMode, isAppErrorData, isApplyOpsParams, isApplyOpsResult, isAssetReloadedParams, isClearEditorLinesParams, isColliderOutlineRecord, isColliderOutlineSet, isEditorConnectMessage, isEditorOrigin, isEntitySelection, isFrameParams, isGameViewFrameParams, isGameViewFrameResult, isGameViewState, isHostErrorParams, isHotReloadedParams, isIncompatibleProtocolData, isInvalidSceneFileData, isJsonObject, isJsonValue, isLogParams, isOpenSceneParams, isOpenSceneResult, isPickParams, isPickResult, isPlayState, isPlayStateReport, isPlayStats, isProtocolVersion, isQueryRuntimeParams, isQueryRuntimeResult, isReadBackParams, isReadBackResult, isReadyResult, isRenderThumbnailParams, isRpcMessage, isSampleAnimationParams, isSampleAnimationResult, isSampleSpriteAnimationParams, isSampleSpriteAnimationResult, isSceneFile, isSceneFileAssetRef, isSceneFileComponent, isSceneFileEntity, isSceneFileInstance, isSceneFileOverride, isSceneFileTransform, isSceneIssue, isSceneOp, isSceneOpenedParams, isSchemaSet, isScreenshotParams, isScreenshotResult, isSendInputEvent, isSendInputParams, isSendInputResult, isSetAnimateMaterialsParams, isSetEditorLinesParams, isSetGameViewParams, isSetGizmoParams, isSetGridParams, isSetTilemapCellsParams, isSetTilemapCellsResult, isSetViewModeParams, isSettingsSet, isThumbnailResult, isTransformDraggedParams, isTransformDraggingParams, listenForEditorPlayControls, protocolVersionIsCompatible, startEditorHost, startEditorPlayControls };
|
|
9033
9317
|
|
|
9034
9318
|
//# sourceMappingURL=index.js.map
|