@vgai/engine 0.5.17 → 0.5.19
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/adapter/renderer-config.d.ts +83 -0
- package/dist/adapter/renderer-config.d.ts.map +1 -0
- package/dist/adapter/renderer-config.js +121 -0
- package/dist/adapter/root-adapter.d.ts +2 -2
- package/dist/adapter/root-adapter.d.ts.map +1 -1
- package/dist/manifest/schema.js +1 -1
- package/dist/pixi/authoring.d.ts.map +1 -1
- package/dist/pixi/authoring.js +134 -26
- package/dist/runtime/mount-manifest.js +1 -1
- package/dist/world3d-react/index.d.ts +1 -1
- package/dist/world3d-react/index.d.ts.map +1 -1
- package/dist/world3d-react/index.js +1 -1
- package/dist/world3d-react/r3f-adapter.d.ts +2 -2
- package/dist/world3d-react/r3f-adapter.d.ts.map +1 -1
- package/dist/world3d-react/r3f-adapter.js +1 -1
- package/dist/world3d-react/renderer-config.d.ts +7 -69
- package/dist/world3d-react/renderer-config.d.ts.map +1 -1
- package/dist/world3d-react/renderer-config.js +7 -108
- package/package.json +1 -1
- package/schemas/engine-capabilities.json +1 -1
- package/schemas/vgai-project.schema.json +1 -1
- package/src/adapter/renderer-config.ts +178 -0
- package/src/adapter/root-adapter.ts +2 -2
- package/src/manifest/schema.ts +1 -1
- package/src/pixi/authoring.ts +137 -27
- package/src/runtime/mount-manifest.ts +1 -1
- package/src/world3d-react/index.ts +4 -4
- package/src/world3d-react/r3f-adapter.tsx +2 -2
- package/src/world3d-react/renderer-config.ts +7 -164
package/src/pixi/authoring.ts
CHANGED
|
@@ -159,43 +159,125 @@ function isPixiDisplay(value: object): boolean {
|
|
|
159
159
|
* never reached `_cannon` inside the budget.
|
|
160
160
|
*/
|
|
161
161
|
function viewOwnerLabel(view: Container): string | undefined {
|
|
162
|
-
const
|
|
162
|
+
const search: OwnerSearch = { seen: new WeakSet<object>(), budget: OWNER_SEARCH_BUDGET };
|
|
163
163
|
let host: unknown = view.parent;
|
|
164
164
|
for (let hops = 0; hops < 8 && host && typeof host === 'object'; hops++) {
|
|
165
|
-
|
|
165
|
+
if (search.budget <= 0) return undefined;
|
|
166
|
+
const found = labelFromHolder(host, view, search) ?? findHeldOwner(host, view, 2, search);
|
|
166
167
|
if (found) return found;
|
|
167
168
|
host = (host as { parent?: unknown }).parent;
|
|
168
169
|
}
|
|
169
170
|
return undefined;
|
|
170
171
|
}
|
|
171
172
|
|
|
173
|
+
/**
|
|
174
|
+
* THE CEILING ON ONE NODE'S OWNER HUNT — what keeps a hierarchy read LINEAR in
|
|
175
|
+
* the size of the tree instead of quadratic in it.
|
|
176
|
+
*
|
|
177
|
+
* The hunt below is a search of the GAME's object graph, and a game's object
|
|
178
|
+
* graph is small: `this._cannon`, `allSystems.get('hud')`, `_decor[3]` are all
|
|
179
|
+
* found within a few dozen examinations. What is not small is anything the
|
|
180
|
+
* search can leak into — Pixi's own live render graph is the measured one, and
|
|
181
|
+
* naming a key blacklist is a fix for the leak you already found, not for the
|
|
182
|
+
* class. So every examination is charged against this budget and the search
|
|
183
|
+
* simply gives up when it runs out: the node then falls through to its texture
|
|
184
|
+
* alias / constructor / kind name, which is the same honest answer it gets
|
|
185
|
+
* today whenever the hunt finds nothing.
|
|
186
|
+
*
|
|
187
|
+
* MEASURED (2026-08-20, `packages/editor/scripts/scale-harness`): entering play
|
|
188
|
+
* on a 20 000-node `@pixi/react` world blocked the main thread for 199.5
|
|
189
|
+
* SECONDS in one synchronous run, 69% of all profiler samples inside this
|
|
190
|
+
* search, because `parentRenderGroup` reaches an array of every node in the
|
|
191
|
+
* tree and the search walked it once per unlabeled node. `vgai play`,
|
|
192
|
+
* `screenshot` and `stop` all timed out against a tab that was heartbeating
|
|
193
|
+
* normally the whole time.
|
|
194
|
+
*/
|
|
195
|
+
const OWNER_SEARCH_BUDGET = 2_000;
|
|
196
|
+
|
|
197
|
+
/** One node's owner hunt: what it has already looked at, and what it has left. */
|
|
198
|
+
interface OwnerSearch {
|
|
199
|
+
readonly seen: WeakSet<object>;
|
|
200
|
+
/** Counts DOWN. Zero ends the hunt for this node, wherever it has reached. */
|
|
201
|
+
budget: number;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/** Charge one examination. `false` means the hunt is over. */
|
|
205
|
+
function spend(search: OwnerSearch): boolean {
|
|
206
|
+
if (search.budget <= 0) return false;
|
|
207
|
+
search.budget -= 1;
|
|
208
|
+
return true;
|
|
209
|
+
}
|
|
210
|
+
|
|
172
211
|
function isGameFieldKey(key: string): boolean {
|
|
173
212
|
// Skip display-list indices (`0`, `1`) and Pixi internals (`children`).
|
|
174
|
-
|
|
213
|
+
// The membership test is on the UNDERSCORED-STRIPPED key because that is how
|
|
214
|
+
// Pixi v8 spells most of them (`_position`, `_bounds`, `_texture`), and a
|
|
215
|
+
// set listing the bare names was silently matching none of those.
|
|
216
|
+
if (!/^_?[A-Za-z][A-Za-zA-Z0-9]*$/.test(key)) return false;
|
|
217
|
+
return !PIXI_INTERNAL_KEY.has(key.replace(/^_+/, ''));
|
|
175
218
|
}
|
|
176
219
|
|
|
220
|
+
/**
|
|
221
|
+
* Field names that belong to Pixi (or to its EventEmitter base), never to the
|
|
222
|
+
* game. Read off a live `pixi.js` v8 `Container`/`Sprite`'s own keys, so this
|
|
223
|
+
* is a transcription rather than a guess — but it is the OPTIMIZATION, not the
|
|
224
|
+
* correctness boundary: {@link OWNER_SEARCH_BUDGET} is what bounds the search
|
|
225
|
+
* on a Pixi version whose internals this list has never heard of. Spending the
|
|
226
|
+
* budget on plausible game fields instead of on the render graph is what keeps
|
|
227
|
+
* the heuristic's hit rate while it is bounded.
|
|
228
|
+
*
|
|
229
|
+
* `view` is deliberately absent: `.view` is the very field the hunt is looking
|
|
230
|
+
* for.
|
|
231
|
+
*/
|
|
177
232
|
const PIXI_INTERNAL_KEY = new Set([
|
|
178
233
|
'parent',
|
|
179
234
|
'children',
|
|
180
235
|
'transform',
|
|
181
236
|
'position',
|
|
237
|
+
'origin',
|
|
182
238
|
'scale',
|
|
183
239
|
'pivot',
|
|
184
240
|
'skew',
|
|
241
|
+
'anchor',
|
|
185
242
|
'worldTransform',
|
|
186
243
|
'localTransform',
|
|
244
|
+
'groupTransform',
|
|
245
|
+
'relativeGroupTransform',
|
|
246
|
+
// The render graph — the measured leak. `parentRenderGroup` is on every
|
|
247
|
+
// container once a world has rendered and reaches every node in the tree.
|
|
248
|
+
'renderGroup',
|
|
249
|
+
'parentRenderGroup',
|
|
250
|
+
'parentRenderGroupIndex',
|
|
251
|
+
'parentRenderLayer',
|
|
252
|
+
'relativeRenderGroupDepth',
|
|
253
|
+
'renderPipeId',
|
|
254
|
+
'instructionSet',
|
|
255
|
+
'childrenToUpdate',
|
|
256
|
+
'childrenRenderablesToUpdate',
|
|
257
|
+
'effects',
|
|
258
|
+
'filters',
|
|
259
|
+
'mask',
|
|
260
|
+
'bounds',
|
|
261
|
+
'boundsArea',
|
|
262
|
+
'visualBounds',
|
|
263
|
+
'gpuData',
|
|
264
|
+
'texture',
|
|
265
|
+
'events',
|
|
266
|
+
'eventsCount',
|
|
267
|
+
'updateFlags',
|
|
187
268
|
]);
|
|
188
269
|
|
|
189
|
-
function labelFromHolder(host: object, view: Container,
|
|
190
|
-
if (seen.has(host)) return undefined;
|
|
191
|
-
seen.add(host);
|
|
192
|
-
const asBag = nameInBag(host, view, undefined,
|
|
270
|
+
function labelFromHolder(host: object, view: Container, search: OwnerSearch): string | undefined {
|
|
271
|
+
if (search.seen.has(host)) return undefined;
|
|
272
|
+
search.seen.add(host);
|
|
273
|
+
const asBag = nameInBag(host, view, undefined, search);
|
|
193
274
|
if (asBag) return asBag;
|
|
194
275
|
for (const [key, value] of Object.entries(host as Record<string, unknown>)) {
|
|
276
|
+
if (!spend(search)) return undefined;
|
|
195
277
|
if (!isGameFieldKey(key)) continue;
|
|
196
278
|
const named = nameIfHoldsView(host, key, value, view);
|
|
197
279
|
if (named) return named;
|
|
198
|
-
const nested = nameInBag(value, view, key,
|
|
280
|
+
const nested = nameInBag(value, view, key, search);
|
|
199
281
|
if (nested) return nested;
|
|
200
282
|
}
|
|
201
283
|
return undefined;
|
|
@@ -205,12 +287,13 @@ function nameInBag(
|
|
|
205
287
|
value: unknown,
|
|
206
288
|
view: Container,
|
|
207
289
|
fieldKey: string | undefined,
|
|
208
|
-
|
|
290
|
+
search: OwnerSearch,
|
|
209
291
|
): string | undefined {
|
|
210
292
|
const entries = bagEntries(value);
|
|
211
293
|
if (!entries) return undefined;
|
|
212
294
|
for (const [itemKey, item] of entries) {
|
|
213
|
-
|
|
295
|
+
if (!spend(search)) return undefined;
|
|
296
|
+
const named = nameBagItem(value, item, usableBagKey(itemKey) ?? fieldKey, view, search);
|
|
214
297
|
if (named) return named;
|
|
215
298
|
}
|
|
216
299
|
return undefined;
|
|
@@ -221,7 +304,7 @@ function nameBagItem(
|
|
|
221
304
|
item: unknown,
|
|
222
305
|
key: string | undefined,
|
|
223
306
|
view: Container,
|
|
224
|
-
|
|
307
|
+
search: OwnerSearch,
|
|
225
308
|
): string | undefined {
|
|
226
309
|
if (key) {
|
|
227
310
|
const named = nameIfHoldsView(
|
|
@@ -236,7 +319,7 @@ function nameBagItem(
|
|
|
236
319
|
if (named) return named;
|
|
237
320
|
}
|
|
238
321
|
if (item && typeof item === 'object' && !isPixiDisplay(item)) {
|
|
239
|
-
return labelFromHolder(item, view,
|
|
322
|
+
return labelFromHolder(item, view, search);
|
|
240
323
|
}
|
|
241
324
|
return undefined;
|
|
242
325
|
}
|
|
@@ -246,22 +329,40 @@ function usableBagKey(key: string): string | undefined {
|
|
|
246
329
|
return isGameFieldKey(key) || key.includes('-') ? (fieldLabel(key) ?? key) : undefined;
|
|
247
330
|
}
|
|
248
331
|
|
|
249
|
-
function
|
|
332
|
+
function* indexedBagEntries(value: ArrayLike<unknown>): Generator<[string, unknown]> {
|
|
333
|
+
for (let index = 0; index < value.length; index++) yield [String(index), value[index]];
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
function* mapBagEntries(value: Map<unknown, unknown>): Generator<[string, unknown]> {
|
|
337
|
+
for (const [key, item] of value.entries()) yield [String(key), item];
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
function* setBagEntries(value: Set<unknown>): Generator<[string, unknown]> {
|
|
341
|
+
let index = 0;
|
|
342
|
+
for (const item of value) {
|
|
343
|
+
yield [String(index), item];
|
|
344
|
+
index += 1;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* A bag's entries, LAZILY.
|
|
350
|
+
*
|
|
351
|
+
* Lazy because the caller is budgeted ({@link OWNER_SEARCH_BUDGET}) and must be
|
|
352
|
+
* able to stop: materializing the pairs first made a 20 000-element array cost
|
|
353
|
+
* 20 000 allocations before the first one was even looked at, which is a cost
|
|
354
|
+
* no budget above it can decline.
|
|
355
|
+
*/
|
|
356
|
+
function bagEntries(value: unknown): Iterable<readonly [string, unknown]> | undefined {
|
|
250
357
|
if (!value || typeof value !== 'object') return undefined;
|
|
251
358
|
// Game arrays are allowed to be exotic subclasses. Do not dispatch through
|
|
252
359
|
// their overridable `map`: one shipped Pixi game returns its elements rather
|
|
253
360
|
// than `[key, value]` pairs there, which made hierarchy labeling throw while
|
|
254
361
|
// destructuring the result. The authoring seam treats game objects as
|
|
255
|
-
// untrusted observations, so normalize with indexed reads
|
|
256
|
-
if (Array.isArray(value))
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
entries.push([String(index), value[index]]);
|
|
260
|
-
}
|
|
261
|
-
return entries;
|
|
262
|
-
}
|
|
263
|
-
if (value instanceof Map) return [...value.entries()].map(([key, item]) => [String(key), item]);
|
|
264
|
-
if (value instanceof Set) return [...value].map((item, index) => [String(index), item]);
|
|
362
|
+
// untrusted observations, so normalize with indexed reads of our own.
|
|
363
|
+
if (Array.isArray(value)) return indexedBagEntries(value as ArrayLike<unknown>);
|
|
364
|
+
if (value instanceof Map) return mapBagEntries(value);
|
|
365
|
+
if (value instanceof Set) return setBagEntries(value);
|
|
265
366
|
if (Object.getPrototypeOf(value) !== Object.prototype) return undefined;
|
|
266
367
|
return Object.entries(value as Record<string, unknown>);
|
|
267
368
|
}
|
|
@@ -289,14 +390,23 @@ function findHeldOwner(
|
|
|
289
390
|
held: object,
|
|
290
391
|
view: Container,
|
|
291
392
|
depth: number,
|
|
292
|
-
|
|
393
|
+
search: OwnerSearch,
|
|
293
394
|
): string | undefined {
|
|
294
|
-
const direct = labelFromHolder(held, view,
|
|
395
|
+
const direct = labelFromHolder(held, view, search);
|
|
295
396
|
if (direct) return direct;
|
|
296
397
|
if (depth <= 0) return undefined;
|
|
297
|
-
|
|
398
|
+
// BY KEY, exactly like `labelFromHolder`'s own scan. Iterating `Object.values`
|
|
399
|
+
// here was the leak that made a hierarchy read quadratic: `parentRenderGroup`
|
|
400
|
+
// sits on EVERY container once a world has rendered, and descending into it
|
|
401
|
+
// reaches `childrenToUpdate[depth].list` — an array of every node in the
|
|
402
|
+
// tree — so the search for one node's owner walked the whole tree, for every
|
|
403
|
+
// unlabeled node. `isGameFieldKey` already knows which keys belong to Pixi
|
|
404
|
+
// rather than to the game; this scan simply has to ask it too.
|
|
405
|
+
for (const [key, value] of Object.entries(held as Record<string, unknown>)) {
|
|
406
|
+
if (!spend(search)) return undefined;
|
|
407
|
+
if (!isGameFieldKey(key)) continue;
|
|
298
408
|
if (!value || typeof value !== 'object' || isPixiDisplay(value)) continue;
|
|
299
|
-
const found = findHeldOwner(value, view, depth - 1,
|
|
409
|
+
const found = findHeldOwner(value, view, depth - 1, search);
|
|
300
410
|
if (found) return found;
|
|
301
411
|
}
|
|
302
412
|
return undefined;
|
|
@@ -412,7 +412,7 @@ export async function mountManifestRoots(opts: MountManifestOptions): Promise<Ga
|
|
|
412
412
|
headless: opts.headless,
|
|
413
413
|
// `rendering.antialias` reaches the WebGL context at CONSTRUCTION and can be honoured
|
|
414
414
|
// nowhere else — see the manifest schema's own `rendering` block and
|
|
415
|
-
// `
|
|
415
|
+
// `adapter/renderer-config.ts`'s header for why it is not a world-level declaration.
|
|
416
416
|
...(manifest.rendering === undefined ? {} : { antialias: manifest.rendering.antialias }),
|
|
417
417
|
seed: resolvedSeed,
|
|
418
418
|
playtest: opts.playtest,
|
|
@@ -40,15 +40,15 @@
|
|
|
40
40
|
* contract to `react`/`@react-three/fiber`/`three` alone.
|
|
41
41
|
*/
|
|
42
42
|
|
|
43
|
-
export { EngineBridge, type EngineBridgeValue, useGameContext } from './engine-bridge';
|
|
44
|
-
export { type CreateR3FAdapterOptions, createR3FAdapter } from './r3f-adapter';
|
|
45
|
-
export { r3fRootFactory, resolveR3FEntryAdapter } from './r3f-root-factory';
|
|
46
43
|
export {
|
|
47
44
|
applyWorldRendererConfig,
|
|
48
45
|
type WorldOutputColorSpace,
|
|
49
46
|
type WorldRendererConfig,
|
|
50
47
|
type WorldToneMapping,
|
|
51
|
-
} from '
|
|
48
|
+
} from '../adapter/renderer-config';
|
|
49
|
+
export { EngineBridge, type EngineBridgeValue, useGameContext } from './engine-bridge';
|
|
50
|
+
export { type CreateR3FAdapterOptions, createR3FAdapter } from './r3f-adapter';
|
|
51
|
+
export { r3fRootFactory, resolveR3FEntryAdapter } from './r3f-root-factory';
|
|
52
52
|
export {
|
|
53
53
|
createR3FRootContext,
|
|
54
54
|
DEFAULT_INPUT_MAP_PATH,
|
|
@@ -30,6 +30,7 @@ import {
|
|
|
30
30
|
} from '@react-three/fiber';
|
|
31
31
|
import { createElement, Fragment, type ReactNode, useEffect, useMemo } from 'react';
|
|
32
32
|
import type { MountedThreeRoot, RootAdapter, ThreeHostContext } from '../adapter';
|
|
33
|
+
import { applyWorldRendererConfig, type WorldRendererConfig } from '../adapter/renderer-config';
|
|
33
34
|
import type { SystemAdapters } from '../adapter/system-adapter';
|
|
34
35
|
import { type RenderVitalsRegistration, registerRenderVitals } from '../dev/register-render-vitals';
|
|
35
36
|
import {
|
|
@@ -45,7 +46,6 @@ import { createSoftParticleDepthPass } from '../render/soft-particle-depth';
|
|
|
45
46
|
import { getDebugRegistry } from '../runtime/debug-registry';
|
|
46
47
|
import { devBuildEnabled } from '../runtime/dev-build';
|
|
47
48
|
import { EngineBridge, type EngineBridgeValue } from './engine-bridge';
|
|
48
|
-
import { applyWorldRendererConfig, type WorldRendererConfig } from './renderer-config';
|
|
49
49
|
import { createR3FRootContext, DEFAULT_INPUT_MAP_PATH, wireGameInputSeams } from './world-context';
|
|
50
50
|
|
|
51
51
|
/** The slice of `WebGLRenderer.info` the vitals reporter reads. Declared
|
|
@@ -117,7 +117,7 @@ export interface CreateR3FAdapterOptions {
|
|
|
117
117
|
/** The colour pipeline this world was AUTHORED for, applied to the host's renderer for the life
|
|
118
118
|
* of the mount and restored on dispose. Omit it (every world here does) to keep the host's own
|
|
119
119
|
* defaults; declare it when the world's colours were picked against a different engine's
|
|
120
|
-
* pipeline — see
|
|
120
|
+
* pipeline — see `../adapter/renderer-config.ts`. */
|
|
121
121
|
readonly renderer?: WorldRendererConfig | undefined;
|
|
122
122
|
}
|
|
123
123
|
|
|
@@ -1,168 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* world3d-react/renderer-config
|
|
2
|
+
* `@engine/world3d-react/renderer-config` — a published entry point.
|
|
3
3
|
*
|
|
4
|
-
* The
|
|
5
|
-
* engine
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* So a world may DECLARE the pipeline it was authored for, and `createR3FAdapter` applies it to the
|
|
11
|
-
* host's renderer for the life of the mount, restoring what it found on dispose. Three properties
|
|
12
|
-
* of that shape are load-bearing:
|
|
13
|
-
*
|
|
14
|
-
* - **It is per-renderer, never engine-wide.** Every field here is a `WebGLRenderer` instance
|
|
15
|
-
* property, and a play root gets its own renderer (`create-runtime.ts`). Nothing here reaches a
|
|
16
|
-
* module-level three global, so one world's declaration cannot change how the editor's own
|
|
17
|
-
* viewport, another root, or a thumbnail bake renders.
|
|
18
|
-
* - **Absent means "leave the host's value alone".** Every field is optional and an omitted one
|
|
19
|
-
* is never written, so declaring a tone mapping does not silently reset the clear colour.
|
|
20
|
-
* - **It is restored on dispose.** The renderer outlives the mount, so a world that did not put
|
|
21
|
-
* back what it found would leak its pipeline into whatever mounts next.
|
|
22
|
-
*
|
|
23
|
-
* This is deliberately NOT a general render-settings system. It carries what a world can honestly
|
|
24
|
-
* state about its own colour pipeline and nothing else; a property the host fixes at CONSTRUCTION
|
|
25
|
-
* (the WebGL context's `antialias` attribute, and therefore the MSAA sample count) cannot be
|
|
26
|
-
* declared here, because there would be no honest moment to apply it.
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
import type * as THREE from 'three';
|
|
30
|
-
|
|
31
|
-
/** The tone-mapping operators three exposes, named as data rather than as three's numeric enum. */
|
|
32
|
-
export type WorldToneMapping =
|
|
33
|
-
| 'none'
|
|
34
|
-
| 'linear'
|
|
35
|
-
| 'reinhard'
|
|
36
|
-
| 'cineon'
|
|
37
|
-
| 'aces'
|
|
38
|
-
| 'agx'
|
|
39
|
-
| 'neutral';
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* The output transfer function the frame is written with.
|
|
43
|
-
*
|
|
44
|
-
* - `srgb` — three's own default and this engine's: linear lighting, sRGB encode on output.
|
|
45
|
-
* - `srgb-linear` — NO output transform. This is what a gamma-space renderer needs: the shading
|
|
46
|
-
* result is already in display space and encoding it a second time washes the frame out.
|
|
47
|
-
*/
|
|
48
|
-
export type WorldOutputColorSpace = 'srgb' | 'srgb-linear';
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* The shadow-map filter, named as data rather than as three's numeric enum.
|
|
52
|
-
*
|
|
53
|
-
* This is a renderer INSTANCE property (`WebGLRenderer.shadowMap.type`), not a context attribute,
|
|
54
|
-
* so unlike MSAA it has an honest moment at which a world can ask for it — which is the whole test
|
|
55
|
-
* this file's header states. A source engine that declares its own shadow filter (Godot 3's
|
|
56
|
-
* `rendering/quality/shadows/filter_mode`) would otherwise inherit whatever the host built with.
|
|
57
|
-
*/
|
|
58
|
-
export type WorldShadowMapType = 'basic' | 'pcf' | 'pcf-soft' | 'vsm';
|
|
59
|
-
|
|
60
|
-
/** What a world may declare about the renderer that draws it. Every field is optional; see header. */
|
|
61
|
-
export interface WorldRendererConfig {
|
|
62
|
-
readonly toneMapping?: WorldToneMapping | undefined;
|
|
63
|
-
readonly toneMappingExposure?: number | undefined;
|
|
64
|
-
readonly outputColorSpace?: WorldOutputColorSpace | undefined;
|
|
65
|
-
/**
|
|
66
|
-
* `WebGLRenderer.shadowMap.type`. Writing it after a shadow map has already been built needs
|
|
67
|
-
* `shadowMap.needsUpdate`, which this function sets — three caches the compiled depth material
|
|
68
|
-
* per type and would otherwise keep filtering with the previous one.
|
|
69
|
-
*/
|
|
70
|
-
readonly shadowMapType?: WorldShadowMapType | undefined;
|
|
71
|
-
/**
|
|
72
|
-
* The colour the frame is cleared to, as a CSS hex string. The renderer's existing clear ALPHA
|
|
73
|
-
* is preserved: a stacked canvas is transparent on purpose (`create-runtime.ts` gives every
|
|
74
|
-
* non-bottom root `alpha: true`), and forcing it opaque here would hide every layer below.
|
|
75
|
-
*/
|
|
76
|
-
readonly clearColor?: string | undefined;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Apply `config` to `renderer`, returning the restore function that puts back what was there.
|
|
81
|
-
*
|
|
82
|
-
* `three` is passed in rather than imported for values so the enum constants come from the HOST's
|
|
83
|
-
* three instance — the same identity rule `r3f-adapter.tsx` follows for the scene and camera.
|
|
4
|
+
* The engine package's export map is the wildcard `"./*"`, so every file under
|
|
5
|
+
* `packages/engine/src/` is an entry point a game outside this repo can import by path. The module
|
|
6
|
+
* itself now lives in the adapter seam (`@engine/adapter/renderer-config`, which its header
|
|
7
|
+
* explains), and this file keeps the path that shipped resolving to it. Import the seam path in
|
|
8
|
+
* new code.
|
|
84
9
|
*/
|
|
85
|
-
export function applyWorldRendererConfig(
|
|
86
|
-
three: typeof THREE,
|
|
87
|
-
renderer: THREE.WebGLRenderer,
|
|
88
|
-
config: WorldRendererConfig,
|
|
89
|
-
): () => void {
|
|
90
|
-
// A host that mounts a world WITHOUT rasterizing it hands the adapter a duck-typed renderer —
|
|
91
|
-
// the editor's design session (`createDesignTimeRenderer`: four members, deliberately never
|
|
92
|
-
// widened) and jsdom test harnesses both do. Such a surface has no colour pipeline to configure:
|
|
93
|
-
// the frame the user sees is drawn by a DIFFERENT renderer (the editor's own), so applying the
|
|
94
|
-
// world's config there is meaningless — and calling `getClearColor` on it is a TypeError that
|
|
95
|
-
// unmounts the whole world at edit time (measured: every Godot port's edit viewport blanked with
|
|
96
|
-
// '"world" failed to mount — renderer.getClearColor is not a function'). Detect the real
|
|
97
|
-
// `WebGLRenderer` surface by the one method this function must call, and no-op otherwise.
|
|
98
|
-
if (typeof renderer.getClearColor !== 'function') {
|
|
99
|
-
return () => {};
|
|
100
|
-
}
|
|
101
|
-
const toneMappings: Record<WorldToneMapping, THREE.ToneMapping> = {
|
|
102
|
-
none: three.NoToneMapping,
|
|
103
|
-
linear: three.LinearToneMapping,
|
|
104
|
-
reinhard: three.ReinhardToneMapping,
|
|
105
|
-
cineon: three.CineonToneMapping,
|
|
106
|
-
aces: three.ACESFilmicToneMapping,
|
|
107
|
-
agx: three.AgXToneMapping,
|
|
108
|
-
neutral: three.NeutralToneMapping,
|
|
109
|
-
};
|
|
110
|
-
const colorSpaces: Record<WorldOutputColorSpace, THREE.ColorSpace> = {
|
|
111
|
-
srgb: three.SRGBColorSpace,
|
|
112
|
-
'srgb-linear': three.LinearSRGBColorSpace,
|
|
113
|
-
};
|
|
114
|
-
const shadowMapTypes: Record<WorldShadowMapType, THREE.ShadowMapType> = {
|
|
115
|
-
basic: three.BasicShadowMap,
|
|
116
|
-
pcf: three.PCFShadowMap,
|
|
117
|
-
'pcf-soft': three.PCFSoftShadowMap,
|
|
118
|
-
vsm: three.VSMShadowMap,
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
const restores: (() => void)[] = [];
|
|
122
|
-
|
|
123
|
-
if (config.toneMapping !== undefined) {
|
|
124
|
-
const previous = renderer.toneMapping;
|
|
125
|
-
renderer.toneMapping = toneMappings[config.toneMapping];
|
|
126
|
-
restores.push(() => {
|
|
127
|
-
renderer.toneMapping = previous;
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
if (config.toneMappingExposure !== undefined) {
|
|
131
|
-
const previous = renderer.toneMappingExposure;
|
|
132
|
-
renderer.toneMappingExposure = config.toneMappingExposure;
|
|
133
|
-
restores.push(() => {
|
|
134
|
-
renderer.toneMappingExposure = previous;
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
if (config.outputColorSpace !== undefined) {
|
|
138
|
-
const previous = renderer.outputColorSpace;
|
|
139
|
-
renderer.outputColorSpace = colorSpaces[config.outputColorSpace];
|
|
140
|
-
restores.push(() => {
|
|
141
|
-
renderer.outputColorSpace = previous;
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
if (config.shadowMapType !== undefined && renderer.shadowMap !== undefined) {
|
|
145
|
-
const previous = renderer.shadowMap.type;
|
|
146
|
-
renderer.shadowMap.type = shadowMapTypes[config.shadowMapType];
|
|
147
|
-
renderer.shadowMap.needsUpdate = true;
|
|
148
|
-
restores.push(() => {
|
|
149
|
-
renderer.shadowMap.type = previous;
|
|
150
|
-
renderer.shadowMap.needsUpdate = true;
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
if (config.clearColor !== undefined) {
|
|
154
|
-
const previousColor = new three.Color();
|
|
155
|
-
renderer.getClearColor(previousColor);
|
|
156
|
-
// Alpha is READ BACK and re-passed, never assumed: see `clearColor`'s doc above.
|
|
157
|
-
const alpha = renderer.getClearAlpha();
|
|
158
|
-
renderer.setClearColor(new three.Color(config.clearColor), alpha);
|
|
159
|
-
restores.push(() => {
|
|
160
|
-
renderer.setClearColor(previousColor, alpha);
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
10
|
|
|
164
|
-
|
|
165
|
-
// Reverse order, so a field written twice (it cannot be, today) unwinds correctly.
|
|
166
|
-
for (let i = restores.length - 1; i >= 0; i--) restores[i]?.();
|
|
167
|
-
};
|
|
168
|
-
}
|
|
11
|
+
export * from '../adapter/renderer-config';
|