@ignifx/core 0.17.0 → 0.19.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.
Files changed (50) hide show
  1. package/dist/{environment-CMpzGXTz.js → environment-Bf4aphSb.js} +2 -2
  2. package/dist/{environment-CMpzGXTz.js.map → environment-Bf4aphSb.js.map} +1 -1
  3. package/dist/{hdr-output-BrUvpAsE.js → hdr-output-Dbv0lhFl.js} +4 -3
  4. package/dist/{hdr-output-BrUvpAsE.js.map → hdr-output-Dbv0lhFl.js.map} +1 -1
  5. package/dist/{ignifx-error-Der0bpHK.js → ignifx-error-DwIZKxA2.js} +13 -1
  6. package/dist/ignifx-error-DwIZKxA2.js.map +1 -0
  7. package/dist/index.d.ts +144 -675
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +3242 -1949
  10. package/dist/index.js.map +1 -1
  11. package/dist/light-probe-asset-BqfSrJe9.js +331 -0
  12. package/dist/light-probe-asset-BqfSrJe9.js.map +1 -0
  13. package/dist/light-probes-DyLapYX9.js +284 -0
  14. package/dist/light-probes-DyLapYX9.js.map +1 -0
  15. package/dist/lightmaps-LO6Ygtwe.js +137 -0
  16. package/dist/lightmaps-LO6Ygtwe.js.map +1 -0
  17. package/dist/{material-plugin-B-hartHR.js → material-plugin-DapJNj04.js} +2 -2
  18. package/dist/{material-plugin-B-hartHR.js.map → material-plugin-DapJNj04.js.map} +1 -1
  19. package/dist/{post-effect-CuoYvrhb.js → post-effect-CaiqDlhW.js} +2 -2
  20. package/dist/{post-effect-CuoYvrhb.js.map → post-effect-CaiqDlhW.js.map} +1 -1
  21. package/dist/{post-effect-compiler-Bps8QbiJ.js → post-effect-compiler-jSvOVe0U.js} +3 -3
  22. package/dist/{post-effect-compiler-Bps8QbiJ.js.map → post-effect-compiler-jSvOVe0U.js.map} +1 -1
  23. package/dist/{prefab-overrides-76IhcF-e.d.ts → prefab-overrides-CS8_cG66.d.ts} +1559 -252
  24. package/dist/prefab-overrides-CS8_cG66.d.ts.map +1 -0
  25. package/dist/{prefab-overrides-DGiGTSN-.js → prefab-overrides-DRP2DcnC.js} +450 -30
  26. package/dist/prefab-overrides-DRP2DcnC.js.map +1 -0
  27. package/dist/prefab.d.ts +2 -2
  28. package/dist/prefab.js +2 -2
  29. package/dist/{reflection-probe-C0pzGrG_.js → reflection-probe-AS8d4uKv.js} +30 -12
  30. package/dist/{reflection-probe-C0pzGrG_.js.map → reflection-probe-AS8d4uKv.js.map} +1 -1
  31. package/dist/{reflection-probes-B8_vK9YR.js → reflection-probes-CUZcOjNW.js} +115 -22
  32. package/dist/reflection-probes-CUZcOjNW.js.map +1 -0
  33. package/dist/{render-path-Be7WgN7r.js → render-path-D11i_7X8.js} +3 -2
  34. package/dist/{render-path-Be7WgN7r.js.map → render-path-D11i_7X8.js.map} +1 -1
  35. package/dist/{scene-color-passes-DlNr-qyZ.js → scene-color-passes-B93qTOka.js} +35 -12
  36. package/dist/scene-color-passes-B93qTOka.js.map +1 -0
  37. package/dist/{shader-material-DCjYDdkh.js → shader-material-CJIDFvSb.js} +2 -2
  38. package/dist/{shader-material-DCjYDdkh.js.map → shader-material-CJIDFvSb.js.map} +1 -1
  39. package/dist/{shader-material-Cjfq7nFS.js → shader-material-CuwK9tWC.js} +5 -5
  40. package/dist/{shader-material-Cjfq7nFS.js.map → shader-material-CuwK9tWC.js.map} +1 -1
  41. package/dist/{shader-pragma-cjEC-EPK.js → shader-pragma-ljmAbVc2.js} +2 -2
  42. package/dist/{shader-pragma-cjEC-EPK.js.map → shader-pragma-ljmAbVc2.js.map} +1 -1
  43. package/dist/{surface-shader-D40hXQ8c.js → surface-shader-DY9_aC9L.js} +4 -4
  44. package/dist/{surface-shader-D40hXQ8c.js.map → surface-shader-DY9_aC9L.js.map} +1 -1
  45. package/package.json +1 -1
  46. package/dist/ignifx-error-Der0bpHK.js.map +0 -1
  47. package/dist/prefab-overrides-76IhcF-e.d.ts.map +0 -1
  48. package/dist/prefab-overrides-DGiGTSN-.js.map +0 -1
  49. package/dist/reflection-probes-B8_vK9YR.js.map +0 -1
  50. package/dist/scene-color-passes-DlNr-qyZ.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"reflection-probe-C0pzGrG_.js","names":[],"sources":["../src/signal/signal.ts","../src/schema/schema.ts","../src/handles/handle.ts","../src/component/internals.ts","../src/component/component.ts","../src/lite/picking.ts","../src/schema/types.ts","../src/schema/field-kinds.ts","../src/render/render-texture.ts","../src/render/reflection-probe.ts"],"sourcesContent":["import { CoreErrorCode } from \"../errors/error-codes.js\";\nimport { IgnifxError } from \"../errors/ignifx-error.js\";\n\n/**\n * A listener attached to a {@link Signal}.\n *\n * @public\n */\nexport type SignalHandler<T> = (value: T) => void;\n\n/**\n * Detaches a handler from a {@link Signal}. Calling it more than once is a no-op.\n *\n * @public\n */\nexport type Disconnect = () => void;\n\n/**\n * Anything whose destruction should take its signal connections with it: an `Entity`, a\n * `Component`, a `SceneInstance`. Connecting with an `owner` is how scripts avoid leaking handlers,\n * and the `ignifx/signal-connect-owner` lint rule requires it inside a `Script`\n * (`docs/architecture/02-scene-graph.md` §8).\n *\n * @public\n */\nexport interface SignalOwner {\n /** Whether the owner has already been destroyed. */\n readonly isDestroyed: boolean;\n /**\n * Emitted once when the owner is destroyed; the signal uses it to detach the handler.\n *\n * @remarks\n * Typed as {@link SignalLike} rather than {@link Signal} so that an owner may expose a precisely\n * typed signal — `Entity.onDestroyed` is a `Signal<Entity>` per\n * `docs/architecture/02-scene-graph.md` §4. `Signal` carries private state, which makes it\n * invariant in `T`; the read-only interface is not, and `connect` is all this contract needs.\n */\n readonly onDestroyed: SignalLike<unknown>;\n}\n\n/**\n * The scheduler that runs deferred deliveries. The core frame loop implements it on the\n * `EndOfFrame` phase; tests can pass a queue that runs callbacks on demand.\n *\n * @public\n */\nexport interface DeferredQueue {\n /**\n * Schedules a callback to run at the next flush point.\n *\n * @param callback - The delivery to run.\n */\n enqueue(callback: () => void): void;\n}\n\n/**\n * Options for {@link Signal.connect}.\n *\n * @public\n */\nexport interface ConnectOptions {\n /** Disconnect the handler after its first delivery. */\n readonly once?: boolean;\n /**\n * Queue the delivery on the signal's {@link DeferredQueue} instead of calling the handler inside\n * `emit` (Godot's `CONNECT_DEFERRED`).\n */\n readonly deferred?: boolean;\n /** Disconnect the handler automatically when this object is destroyed. */\n readonly owner?: SignalOwner;\n}\n\n/**\n * Options for the {@link Signal} constructor, where `T` is the payload the signal emits.\n *\n * @public\n */\nexport interface SignalOptions<T> {\n /** The scheduler used by `deferred` connections. Without it, `deferred: true` throws. */\n readonly deferredQueue?: DeferredQueue;\n /**\n * Where handler exceptions go. When set, every exception is reported here and delivery continues;\n * when absent, the first exception is rethrown as `IGX-0104` once every handler has run. The app\n * passes a reporter that routes to `app.onError`. It must not throw.\n */\n readonly onHandlerError?: (error: unknown, signal: Signal<T>) => void;\n}\n\n/**\n * The read-only half of a {@link Signal}: what a public API exposes when callers may subscribe but\n * must not emit, where `T` is the payload the signal emits.\n *\n * @example\n * ```ts\n * interface Assets {\n * readonly onLoaded: SignalLike<AssetHandle>;\n * }\n * ```\n *\n * @public\n */\nexport interface SignalLike<T = void> {\n /** How many handlers are currently attached. */\n readonly connectionCount: number;\n\n /**\n * Attaches a handler.\n *\n * @param handler - The listener.\n * @param options - `once`, `deferred`, and `owner`.\n * @returns A function that detaches the handler.\n */\n connect(handler: SignalHandler<T>, options?: ConnectOptions): Disconnect;\n}\n\n/** One attached handler. `handler === null` marks the entry dead and awaiting compaction. */\nclass Connection<T> {\n handler: SignalHandler<T> | null;\n readonly once: boolean;\n readonly deferred: boolean;\n /** Index into the owning signal's connection list; kept current by swap-remove. */\n index: number;\n /** Detaches the auto-disconnect handler from `owner.onDestroyed`. */\n ownerDisconnect: Disconnect | null = null;\n\n constructor(handler: SignalHandler<T>, once: boolean, deferred: boolean, index: number) {\n this.handler = handler;\n this.once = once;\n this.deferred = deferred;\n this.index = index;\n }\n}\n\n/** Returned when connecting to a signal on behalf of an already-destroyed owner. */\nfunction noopDisconnect(): void {\n // Nothing was connected, so nothing has to be detached.\n}\n\n/**\n * A typed, synchronous, many-listener event (`docs/architecture/02-scene-graph.md` §8). Signals are\n * the \"signal up\" half of the engine's *call down, signal up* convention: a parent calls methods on\n * the children it owns, a child announces what happened and lets interested parties subscribe.\n *\n * @remarks\n * Delivery guarantees:\n *\n * - Handlers run in connection order, synchronously, inside {@link Signal.emit}.\n * - A handler connected *during* an emit runs on the next emit, never the one in flight.\n * - A handler disconnected during an emit never runs again, including in the emit in flight.\n * - One handler throwing does not stop delivery to the others.\n * - Nothing is allocated per emit on the non-deferred path (coding standards §7).\n *\n * The payload type `T` defaults to `void`, so `signal.emit()` takes no argument.\n *\n * @example\n * ```ts\n * class Health extends Script {\n * readonly onDied = new Signal<Entity>();\n * damage(amount: number): void {\n * this.hp -= amount;\n * if (this.hp <= 0) {\n * this.onDied.emit(this.entity);\n * }\n * }\n * }\n *\n * health.onDied.connect((entity) => this.spawnLoot(entity), { owner: this, once: true });\n * ```\n *\n * @public\n */\nexport class Signal<T = void> implements SignalLike<T> {\n readonly #connections: Connection<T>[] = [];\n readonly #deferredQueue: DeferredQueue | null;\n readonly #onHandlerError: ((error: unknown, signal: Signal<T>) => void) | null;\n #liveCount = 0;\n #deadCount = 0;\n #emitDepth = 0;\n\n /**\n * Creates a signal.\n *\n * @param options - The deferred-delivery scheduler and the handler-error reporter. Both are\n * supplied by the app for engine signals; a signal a script owns usually needs neither.\n */\n constructor(options?: SignalOptions<T>) {\n this.#deferredQueue = options?.deferredQueue ?? null;\n this.#onHandlerError = options?.onHandlerError ?? null;\n }\n\n /**\n * How many handlers are currently attached.\n *\n * @returns The live connection count.\n */\n get connectionCount(): number {\n return this.#liveCount;\n }\n\n /**\n * Attaches a handler.\n *\n * @param handler - The listener.\n * @param options - `once` to detach after the first delivery, `deferred` to queue delivery on the\n * signal's {@link DeferredQueue}, and `owner` to detach when the owner is destroyed.\n * @returns A function that detaches the handler; calling it twice is a no-op.\n * @throws IgnifxError with code `IGX-0103` when `deferred` is requested and the signal was\n * constructed without a {@link DeferredQueue}.\n *\n * @example\n * ```ts\n * const stop = app.events.onSceneLoaded.connect((scene) => this.spawn(scene), { owner: this });\n * stop();\n * ```\n */\n connect(handler: SignalHandler<T>, options?: ConnectOptions): Disconnect {\n const deferred = options?.deferred ?? false;\n if (deferred && this.#deferredQueue === null) {\n throw new IgnifxError(\n CoreErrorCode.deferredSignalWithoutScheduler,\n \"Deferred signal delivery needs a scheduler; construct the signal with a deferred queue.\",\n { hint: \"Engine signals reached through the app already have one; a signal you own does not.\" },\n );\n }\n const owner = options?.owner;\n if (owner !== undefined && owner.isDestroyed) {\n // Connecting on behalf of a destroyed owner is a no-op rather than an error: teardown order\n // between two destroyed objects is not something game code should have to reason about.\n return noopDisconnect;\n }\n const connection = new Connection<T>(handler, options?.once ?? false, deferred, this.#connections.length);\n this.#connections.push(connection);\n this.#liveCount += 1;\n if (owner !== undefined) {\n connection.ownerDisconnect = owner.onDestroyed.connect(() => {\n this.#remove(connection);\n });\n }\n return () => {\n this.#remove(connection);\n };\n }\n\n /**\n * Delivers a value to every attached handler, in connection order.\n *\n * @param value - The payload. Omitted for `Signal<void>`.\n * @throws IgnifxError with code `IGX-0104` wrapping the first handler exception, when the signal\n * was constructed without an `onHandlerError` reporter.\n */\n emit(value: T): void {\n const connections = this.#connections;\n // Snapshotting the length — not the array — is what makes a handler connected during this emit\n // run on the *next* emit, with no per-emit allocation.\n const count = connections.length;\n if (count === 0) {\n return;\n }\n this.#emitDepth += 1;\n let firstError: unknown = null;\n let errorCount = 0;\n for (let index = 0; index < count; index += 1) {\n const connection = connections[index];\n if (connection === undefined) {\n continue;\n }\n const handler = connection.handler;\n if (handler === null) {\n continue;\n }\n const isOnce = connection.once;\n if (isOnce) {\n this.#remove(connection);\n }\n try {\n if (connection.deferred && this.#deferredQueue !== null) {\n this.#deferredQueue.enqueue(() => {\n // A `once` connection is already detached; any other must still be attached at flush\n // time, so disconnecting before the queue drains cancels the delivery.\n if (isOnce || connection.handler !== null) {\n handler(value);\n }\n });\n } else {\n handler(value);\n }\n } catch (error) {\n errorCount += 1;\n if (this.#onHandlerError === null) {\n if (errorCount === 1) {\n firstError = error;\n }\n } else {\n this.#onHandlerError(error, this);\n }\n }\n }\n this.#emitDepth -= 1;\n if (this.#emitDepth === 0 && this.#deadCount > 0) {\n this.#compact();\n }\n if (errorCount > 0 && this.#onHandlerError === null) {\n throw new IgnifxError(CoreErrorCode.signalHandlerThrew, \"A signal handler threw.\", {\n cause: firstError,\n context: { errorCount, handlerCount: count },\n hint: \"Handle the failure in the handler, or give the signal an onHandlerError reporter.\",\n });\n }\n }\n\n /**\n * Detaches the first connection made with this handler. Detaching a handler that is not connected\n * is a no-op.\n *\n * @param handler - The listener to detach.\n */\n disconnect(handler: SignalHandler<T>): void {\n for (const connection of this.#connections) {\n if (connection.handler === handler) {\n this.#remove(connection);\n return;\n }\n }\n }\n\n /** Detaches every handler, including the auto-disconnect hooks held on owners. */\n clear(): void {\n // Iterating a copy keeps `#remove`'s swap-remove from shifting entries out from under the loop.\n // `clear` is a teardown operation, never a per-frame one, so the copy costs nothing that matters.\n for (const connection of this.#connections.slice()) {\n this.#remove(connection);\n }\n }\n\n /**\n * Marks a connection dead and, when no emit is in flight, removes it by swapping the last entry\n * into its slot. During an emit the entry is left as a tombstone so indices stay stable, and the\n * outermost emit compacts.\n *\n * @param connection - The connection to detach.\n */\n #remove(connection: Connection<T>): void {\n if (connection.handler === null) {\n return;\n }\n connection.handler = null;\n this.#liveCount -= 1;\n const ownerDisconnect = connection.ownerDisconnect;\n if (ownerDisconnect !== null) {\n connection.ownerDisconnect = null;\n ownerDisconnect();\n }\n if (this.#emitDepth > 0) {\n this.#deadCount += 1;\n return;\n }\n this.#swapRemove(connection.index);\n }\n\n /** Removes every tombstone left behind by an emit. */\n #compact(): void {\n const connections = this.#connections;\n for (let index = connections.length - 1; index >= 0; index -= 1) {\n const connection = connections[index];\n if (connection !== undefined && connection.handler === null) {\n this.#swapRemove(index);\n }\n }\n this.#deadCount = 0;\n }\n\n /**\n * Removes the entry at an index by moving the last entry into its place.\n *\n * @param index - The slot to vacate.\n */\n #swapRemove(index: number): void {\n const connections = this.#connections;\n const last = connections.length - 1;\n if (index !== last) {\n const moved = connections[last];\n if (moved !== undefined) {\n connections[index] = moved;\n moved.index = index;\n }\n }\n connections.pop();\n }\n}\n","import { SchemaIssueCode, throwSchemaError } from \"./issues.js\";\nimport type { FieldsOf, PartialFieldsOf, Schema } from \"./types.js\";\n\n/**\n * Property names a schema may not use, because `Component`/`Script` already define them\n * (`docs/architecture/03-scripting-and-components.md` §1 and §2). A schema field becomes a property\n * on the generated base class, so reusing one of these would shadow engine state and break the\n * lifecycle silently.\n *\n * @internal\n */\n// A module-scope `new Set(...)` allocates at import time, which `ignifx/no-module-side-effects` and\n// `CONSTITUTION.md` §3.5 forbid; schemas are declared once per class, so a linear scan is not hot.\n// oxlint-disable-next-line unicorn/prefer-set-has\nconst RESERVED_FIELD_NAMES: readonly string[] = [\n \"uid\",\n \"entity\",\n \"transform\",\n \"world\",\n \"app\",\n \"enabled\",\n \"isDestroyed\",\n \"isEnabledInHierarchy\",\n \"destroy\",\n \"getComponent\",\n \"requireComponent\",\n \"awake\",\n \"onEnable\",\n \"start\",\n \"fixedUpdate\",\n \"update\",\n \"lateUpdate\",\n \"onDisable\",\n \"onDestroy\",\n \"startCoroutine\",\n \"stopCoroutine\",\n \"stopAllCoroutines\",\n];\n\n/**\n * A field name must read like a plain JavaScript identifier so that `this.<name>` works without\n * bracket syntax, and must not start with `_`, which the standards reserve for adapter-internal\n * mirrors (coding standards §5.1).\n *\n * @internal\n */\nconst FIELD_NAME_PATTERN = /^[A-Za-z][A-Za-z0-9]*$/u;\n\n/**\n * Refuses a field name that every plain object already has through `Object.prototype`:\n * `constructor`, `toString`, `valueOf`, `hasOwnProperty`, `__proto__` and the rest. Encoders,\n * decoders, and the inspector walk a schema and read each field as `values[name]`, so a value that\n * omits such a field yields the inherited member instead of `undefined`; and they write it as\n * `out[name] = …`, which for `__proto__` replaces the object's prototype instead of adding a key.\n * Refusing the name once, where the schema is declared, keeps every one of those sites correct.\n * `prototype` is not inherited by plain objects, so it stays a legal name.\n *\n * A literal `{ __proto__: f32(1) }` (not computed) never makes a key at all: it sets the object's\n * prototype, so the field would vanish without a word. The fields object must therefore be a plain\n * object (its prototype `Object.prototype`, or `null`).\n *\n * @param fields - The field definitions being declared.\n * @param where - What declares them, for the message: `\"schema\"` or `\"record\"`.\n * @throws IgnifxError with code `IGX-0607` when a name is an `Object.prototype` member, or the\n * fields object is not a plain object.\n *\n * @internal\n */\nexport function assertNoInheritedFieldNames(fields: Schema, where: string): void {\n const prototype: unknown = Object.getPrototypeOf(fields);\n if (prototype !== Object.prototype && prototype !== null) {\n throwSchemaError(\n SchemaIssueCode.unknownField,\n `${where} fields are not a plain object, so a field is hidden in its prototype; a literal ` +\n `\"__proto__: …\" key sets the prototype instead of declaring a field. Rename the field.`,\n );\n }\n for (const name of Object.keys(fields)) {\n if (Object.hasOwn(Object.prototype, name)) {\n throwSchemaError(\n SchemaIssueCode.unknownField,\n `${where} field \"${name}\" names a member every object inherits (Object.prototype.${name}); rename the field.`,\n );\n }\n }\n}\n\n/**\n * Rewrites a JavaScript value into a mutable string-keyed view. Schema-shaped objects are always\n * plain records built by this module, so the assertion holds by construction; it exists because a\n * mapped type such as `FieldsOf<S>` cannot be indexed generically (coding standards §5.2 permits\n * assertions at boundaries like this one, with the invariant stated).\n *\n * @param value - The object to view.\n * @returns The same object, typed as a mutable record.\n *\n * @internal\n */\nfunction mutableView(value: unknown): Record<string, unknown> {\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- invariant stated above.\n return value as Record<string, unknown>;\n}\n\n/**\n * Rewrites a plain record into the field object a schema describes. Safe because `createDefaults`\n * fills exactly the schema's keys with values built by that key's own field definition.\n *\n * @param value - The record to view.\n * @returns The same object, typed as the schema's field object.\n *\n * @internal\n */\nfunction fieldsView<S extends Schema>(value: Record<string, unknown>): FieldsOf<S> {\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- invariant stated above.\n return value as FieldsOf<S>;\n}\n\n/**\n * Declares a component's serialized fields. The helper is an identity function at runtime — it\n * returns the object it was given — but it checks every field name and, because it is generic,\n * preserves the exact literal type of the schema so `FieldsOf` can project it.\n *\n * `Script.define` and `Component.define` call this before they build a base class.\n *\n * @param fields - The field definitions, keyed by the property name they become.\n * @returns The same object, with its precise type preserved.\n * @throws IgnifxError with code `IGX-0607` when a field name is not identifier-like, starts with\n * `_`, collides with a `Component`/`Script` member such as `enabled` or `update`, or names an\n * `Object.prototype` member such as `constructor` or `toString`, or when `fields` is not a plain\n * object (a literal `__proto__: …` key sets its prototype rather than declaring a field).\n *\n * @example\n * ```ts\n * const moverSchema = defineSchema({\n * speed: f32(5, { min: 0, max: 50 }),\n * waypoints: array(vec3()),\n * });\n * ```\n *\n * @public\n */\nexport function defineSchema<S extends Schema>(fields: S): S {\n assertNoInheritedFieldNames(fields, \"schema\");\n for (const name of Object.keys(fields)) {\n if (!FIELD_NAME_PATTERN.test(name)) {\n throwSchemaError(\n SchemaIssueCode.unknownField,\n `schema field \"${name}\" is not a valid field name: use a letter followed by letters or digits, and do not start with \"_\".`,\n );\n }\n if (RESERVED_FIELD_NAMES.includes(name)) {\n throwSchemaError(\n SchemaIssueCode.unknownField,\n `schema field \"${name}\" collides with a Component or Script member; rename the field.`,\n );\n }\n }\n return fields;\n}\n\n/**\n * Builds the initial field object for a schema. Every value is freshly allocated by its field's\n * own `createDefault`, so two components declared from the same schema never share a mutable\n * default such as a `vec3` or an `array`.\n *\n * @param schema - The schema to instantiate.\n * @returns A new object holding one default per declared field.\n *\n * @example\n * ```ts\n * const a = createDefaults(moverSchema);\n * const b = createDefaults(moverSchema);\n * a.offset === b.offset; // false — each call allocates\n * ```\n *\n * @public\n */\nexport function createDefaults<S extends Schema>(schema: S): FieldsOf<S> {\n const defaults: Record<string, unknown> = {};\n for (const [name, field] of Object.entries(schema)) {\n defaults[name] = field.createDefault();\n }\n return fieldsView<S>(defaults);\n}\n\n/**\n * Overwrites defaults with caller-supplied values. Only names the schema declares are copied, and\n * a value of `undefined` leaves the default in place — matching the loader's rule that omitted\n * props take schema defaults (`docs/architecture/06-serialization-and-scene-format.md` §2).\n *\n * @param target - The field object to write into, normally the result of `createDefaults`.\n * @param schema - The schema that says which names are legal.\n * @param init - The values to apply.\n * @returns The same `target` object, for chaining.\n *\n * @example\n * ```ts\n * const fields = applyInit(createDefaults(moverSchema), moverSchema, { speed: 12 });\n * ```\n *\n * @public\n */\nexport function applyInit<S extends Schema>(target: FieldsOf<S>, schema: S, init: PartialFieldsOf<S>): FieldsOf<S> {\n const writable = mutableView(target);\n const supplied = mutableView(init);\n for (const name of Object.keys(schema)) {\n const value = supplied[name];\n if (value !== undefined) {\n writable[name] = value;\n }\n }\n return target;\n}\n","/**\n * Dense runtime identity (`docs/architecture/00-overview.md` §5). A handle is a plain number so it\n * costs nothing to store, pass, or put in a typed array, and it is branded so that an entity handle\n * and a component handle can never be confused at compile time.\n */\n\n/**\n * The dense runtime id of an entity. Valid until the entity is destroyed; a handle that outlives\n * its entity resolves to `null` through `world.getEntityByHandle` rather than to whatever object\n * recycled the slot.\n *\n * @remarks\n * The `__brand` property exists only in the type system — a handle is a `number` at runtime — so a\n * handle can be stored in a `Float64Array` or written into Lite's node metadata unchanged.\n *\n * @example\n * ```ts\n * const handle: EntityHandle = entity.handle;\n * world.getEntityByHandle(handle)?.destroy();\n * ```\n *\n * @public\n */\nexport type EntityHandle = number & { readonly __brand: \"EntityHandle\" };\n\n/**\n * The dense runtime id of a component, with the same lifetime rules as {@link EntityHandle}.\n *\n * @public\n */\nexport type ComponentHandle = number & { readonly __brand: \"ComponentHandle\" };\n\n/**\n * The handle value that never resolves. Allocated handles always carry a generation of at least\n * one, so zero is unreachable and doubles as \"no handle\".\n *\n * @public\n */\nexport const INVALID_HANDLE = 0;\n\n/**\n * Brands a raw allocator handle as an entity handle.\n *\n * @param value - The number {@link HandleAllocator.allocate} returned.\n * @returns The same number, typed as an entity handle.\n *\n * @internal\n */\nexport function toEntityHandle(value: number): EntityHandle {\n // The brand is a compile-time marker with no runtime\n // representation, so branding is the identity function and this is the one place it happens.\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion\n return value as EntityHandle;\n}\n\n/**\n * Brands a raw allocator handle as a component handle.\n *\n * @param value - The number {@link HandleAllocator.allocate} returned.\n * @returns The same number, typed as a component handle.\n *\n * @internal\n */\nexport function toComponentHandle(value: number): ComponentHandle {\n // Boundary assertion (coding standards §5.2); see `toEntityHandle`.\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion\n return value as ComponentHandle;\n}\n","import { toComponentHandle, type ComponentHandle } from \"../handles/handle.js\";\nimport type { ComponentClassInfo } from \"./component-registry.js\";\nimport type { Component } from \"./component.js\";\nimport type { Entity } from \"../entity/entity.js\";\nimport type { Signal } from \"../signal/signal.js\";\n\n/**\n * The engine-owned state of a component, kept off the public type.\n *\n * @remarks\n * Components are constructed with `new Type()` and only *then* handed their entity, uid, and\n * handle, so the state cannot live in constructor parameters. It lives behind a module symbol\n * instead: the property is unreachable by name, invisible to `Object.keys`, and impossible to\n * collide with a schema field — while staying fully typed, with no `any` and no assertion\n * (coding standards §5.2).\n */\n\n/**\n * The key the engine state hangs off. Exported so that `Entity`, the lifecycle queue, and the world\n * can reach it; unreachable from game code, which has no way to name the symbol.\n *\n * @internal\n */\nexport const COMPONENT_INTERNALS: unique symbol = Symbol(\"ignifx.component.internals\");\n\n/**\n * The engine-owned state of one component.\n *\n * @internal\n */\nexport interface ComponentInternals {\n /** The owning entity, or `null` between construction and attachment. */\n entity: Entity | null;\n /** The stable ULID, assigned at attachment. */\n uid: string;\n /** The dense runtime handle, assigned at attachment. */\n handle: ComponentHandle;\n /** What the registry worked out about this component's class, assigned at attachment. */\n info: ComponentClassInfo | null;\n /** Monotonic creation serial; the tie-breaker for `start` and dispatch ordering. */\n serial: number;\n /** The component's own enabled flag. */\n enabled: boolean;\n /** `true` between the `onEnable` that ran and the `onDisable` that has not yet. */\n isEnabledNow: boolean;\n /** `true` while an enable transition is waiting for lifecycle flush A. */\n isEnableQueued: boolean;\n /** `true` while a `start` is waiting for lifecycle flush B. */\n isStartQueued: boolean;\n /** `true` once `awake` has run. Never runs twice. */\n hasAwoken: boolean;\n /** `true` once `start` has run. Never runs twice, across any number of enable cycles. */\n hasStarted: boolean;\n /** `true` from the moment `destroy()` is called, long before the destroy flush. */\n isDestroyed: boolean;\n /** `true` once the destroy flush has finished with this component. */\n isReleased: boolean;\n /** `true` while the component sits in the destroy queue, so it is queued at most once. */\n isDestroyQueued: boolean;\n /** Index of this component in each of its class's per-type registry buckets. */\n storeSlots: number[];\n /** Lazily created; `null` until something connects to it. */\n onDestroyed: Signal<Component> | null;\n}\n\n/**\n * Reads a component's engine-owned state.\n *\n * @param component - The component.\n * @returns Its internal state.\n *\n * @internal\n */\nexport function componentInternals(component: Component): ComponentInternals {\n return component[COMPONENT_INTERNALS];\n}\n\n/**\n * Builds the initial engine state of a freshly constructed, not yet attached component.\n *\n * @returns The state, with no entity and no identity yet.\n *\n * @internal\n */\nexport function createComponentInternals(): ComponentInternals {\n return {\n entity: null,\n uid: \"\",\n handle: toComponentHandle(0),\n info: null,\n serial: 0,\n enabled: true,\n isEnabledNow: false,\n isEnableQueued: false,\n isStartQueued: false,\n hasAwoken: false,\n hasStarted: false,\n isDestroyed: false,\n isReleased: false,\n isDestroyQueued: false,\n storeSlots: [],\n onDestroyed: null,\n };\n}\n","import { CoreErrorCode } from \"../errors/error-codes.js\";\nimport { IgnifxError } from \"../errors/ignifx-error.js\";\nimport { createDefaults, defineSchema } from \"../schema/schema.js\";\nimport { Signal } from \"../signal/signal.js\";\nimport { COMPONENT_INTERNALS, componentInternals, createComponentInternals } from \"./internals.js\";\nimport type { ComponentType } from \"./component-type.js\";\nimport type { ComponentInternals } from \"./internals.js\";\nimport type { App } from \"../app/types.js\";\nimport type { Entity } from \"../entity/entity.js\";\nimport type { ComponentHandle } from \"../handles/handle.js\";\nimport type { FieldsOf, Schema } from \"../schema/types.js\";\nimport type { SignalOwner } from \"../signal/signal.js\";\nimport type { Transform } from \"../transform/transform.js\";\nimport type { World } from \"../world/world.js\";\n\n/**\n * Typed data and behaviour attached to an entity\n * (`docs/architecture/03-scripting-and-components.md` §1). Engine-owned components\n * (`MeshRenderer`, `Rigidbody`, `AudioSource`) are plain `Component`s driven by systems; game\n * behaviour extends `Script`, which adds the frame lifecycle.\n *\n * @remarks\n * A component class must have a no-argument constructor: the engine constructs it, then assigns\n * `entity`, `uid`, and `handle`, then applies schema defaults and the `init` object, then calls\n * `onAttach`. Reading `this.entity` from a constructor therefore throws `IGX-0206`; cache lookups\n * in `onAttach` or `awake` instead.\n *\n * **Where the statics are declared.** `typeId`, `schema`, `requires`, and `allowMultiple` are not\n * members of this class. Declaring them here would make every `static typeId = \"mygame/Mover\"` an\n * override and force the `override` keyword on it under `noImplicitOverride` (coding standards §3)\n * — the same reasoning that keeps the callbacks on {@link ComponentHooks}. The shape lives on\n * {@link ComponentStatics} instead, and `ComponentRegistry` reads it once per class and supplies\n * the defaults (`allowMultiple` is `true` when the class declares nothing).\n *\n * @example\n * ```ts\n * class Health extends Component.define({ maximum: f32(100) }) {\n * static typeId = \"mygame/Health\";\n * current = 0;\n * onAttach(): void {\n * this.current = this.maximum;\n * }\n * }\n * ```\n *\n * @public\n */\n// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging -- the merged interface below declares one engine-owned property that the constructor always assigns.\nexport abstract class Component implements SignalOwner {\n /** Creates a component. The engine constructs components; game code never calls `new`. */\n constructor() {\n this[COMPONENT_INTERNALS] = createComponentInternals();\n }\n\n /**\n * Declares a component's serialized fields and returns the base class to extend (ADR-0004,\n * `docs/architecture/03-scripting-and-components.md` §3). The returned class exposes every field\n * as a typed instance property, applies the defaults in its constructor, and carries the schema\n * for the serializer, the inspector, and the docs harness.\n *\n * @typeParam S - The schema being declared.\n * @param schema - The field definitions, keyed by the property name they become.\n * @returns An abstract class to extend.\n * @throws IgnifxError with code `IGX-0607` when a field name is not identifier-like, collides\n * with a `Component`/`Script` member, or names an `Object.prototype` member such as `constructor`.\n *\n * @example\n * ```ts\n * class Spinner extends Component.define({\n * degreesPerSecond: f32(90, { min: -360, max: 360 }),\n * axis: vec3({ x: 0, y: 1, z: 0 }),\n * }) {\n * static typeId = \"mygame/Spinner\";\n * }\n * ```\n */\n static define<const S extends Schema>(schema: S): ComponentDefinition<S> {\n const fields = defineSchema(schema);\n abstract class Defined extends Component {\n static schema: Schema = fields;\n\n constructor() {\n super();\n Object.assign(this, createDefaults(fields));\n }\n }\n // Boundary assertion (coding standards §5.2). The invariant: `Defined`'s constructor assigns\n // exactly the schema's keys with values built by each field's own `createDefault`, so an\n // instance really does have `FieldsOf<S>`. TypeScript cannot express \"this class gains the\n // properties of a value known only at run time\", so the shape is asserted once, here.\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion\n return Defined as unknown as ComponentDefinition<S>;\n }\n\n /**\n * The stable ULID; the key files use to reference this component.\n *\n * @returns The identifier.\n */\n get uid(): string {\n return this.#attached().uid;\n }\n\n /**\n * The dense runtime handle; invalid after destruction.\n *\n * @returns The handle.\n */\n get handle(): ComponentHandle {\n return this.#attached().handle;\n }\n\n /**\n * The entity this component is attached to.\n *\n * @returns The owning entity.\n */\n get entity(): Entity {\n const entity = this.#attached().entity;\n if (entity === null) {\n throw notAttached(this);\n }\n return entity;\n }\n\n /**\n * The entity's transform — sugar for `this.entity.transform`, the most-used lookup there is.\n *\n * @returns The entity's transform.\n */\n get transform(): Transform {\n return this.entity.transform;\n }\n\n /**\n * The world the entity belongs to.\n *\n * @returns The world.\n */\n get world(): World {\n return this.entity.world;\n }\n\n /**\n * The app that owns the world.\n *\n * @returns The app.\n */\n get app(): App {\n return this.entity.world.app;\n }\n\n /**\n * The component's own enabled flag; `true` by default. Setting it runs the enable or disable\n * transition (`docs/architecture/01-lifecycle-and-time.md` §6): `onDisable` runs immediately,\n * `awake`/`onEnable` run in the next lifecycle flush — or immediately and nested when the change\n * happens inside a callback.\n *\n * @returns `true` when the component's own flag is set.\n */\n get enabled(): boolean {\n return componentInternals(this).enabled;\n }\n\n set enabled(value: boolean) {\n const internals = componentInternals(this);\n if (internals.enabled === value) {\n return;\n }\n if (internals.isDestroyed) {\n throw new IgnifxError(CoreErrorCode.mutationAfterDestroy, \"This component has been destroyed.\", {\n context: { target: \"component\", uid: internals.uid, operation: \"enabled\" },\n });\n }\n internals.enabled = value;\n const entity = internals.entity;\n if (entity !== null) {\n entity.world.lifecycle.refreshEnabled(this);\n }\n }\n\n /**\n * `true` when the component's own flag is set **and** its entity is active in the hierarchy.\n *\n * @returns `true` when the component is effectively enabled.\n */\n get isEnabledInHierarchy(): boolean {\n const internals = componentInternals(this);\n const entity = internals.entity;\n return internals.enabled && !internals.isDestroyed && entity !== null && entity.activeInHierarchy;\n }\n\n /**\n * `true` from the moment `destroy()` is called, long before the destroy flush runs.\n *\n * @returns `true` once the component has been queued for destruction.\n */\n get isDestroyed(): boolean {\n return componentInternals(this).isDestroyed;\n }\n\n /**\n * Emitted once when the component is destroyed, in the destroy flush. Connecting with\n * `{ owner: this }` elsewhere uses it to detach handlers automatically\n * (`docs/architecture/02-scene-graph.md` §8).\n *\n * @returns The signal. It is created on first access, so a component nobody listens to allocates\n * nothing.\n */\n get onDestroyed(): Signal<Component> {\n const internals = componentInternals(this);\n internals.onDestroyed ??= new Signal<Component>();\n return internals.onDestroyed;\n }\n\n /**\n * Queues this component for destruction. It stays usable until the destroy flush of the current\n * frame, but reports `isDestroyed === true` immediately\n * (`docs/architecture/01-lifecycle-and-time.md` §6). Calling it twice is a no-op.\n */\n destroy(): void {\n const internals = componentInternals(this);\n const entity = internals.entity;\n if (entity === null) {\n internals.isDestroyed = true;\n return;\n }\n entity.removeComponent(this);\n }\n\n /**\n * Finds another component on the same entity — sugar for `this.entity.getComponent`.\n *\n * @typeParam T - The component type to look for.\n * @param type - The component class; matching is by class identity **and** inheritance.\n * @returns The first match in attach order, or `null`.\n */\n getComponent<T extends Component>(type: ComponentType<T>): T | null {\n return this.entity.getComponent(type);\n }\n\n /**\n * Finds another component on the same entity, requiring it to be there — the supported way to\n * link components (`docs/architecture/03-scripting-and-components.md` §8).\n *\n * @typeParam T - The component type to look for.\n * @param type - The component class.\n * @returns The first match in attach order.\n * @throws IgnifxError with code `IGX-0201` when the entity has no such component.\n */\n requireComponent<T extends Component>(type: ComponentType<T>): T {\n return this.entity.requireComponent(type);\n }\n\n /**\n * The engine state, with the \"attached\" invariant checked once.\n *\n * @returns The internals.\n */\n #attached(): ComponentInternals {\n const internals = componentInternals(this);\n if (internals.entity === null) {\n throw notAttached(this);\n }\n return internals;\n }\n}\n\n/**\n * The engine-owned state of a component, declared through interface merging.\n *\n * @remarks\n * A symbol-keyed *class field* is rejected by `isolatedDeclarations` (coding standards §3), which\n * cannot infer a computed property name; declaring it on the merged interface states the type\n * explicitly and emits cleanly. The property is unreachable from game code, which has no way to\n * name the symbol, and cannot collide with a schema field.\n *\n * @public\n */\n// Merging is deliberate and safe here: the class constructor assigns the one property the\n// interface declares, so it is always initialised. A symbol-keyed class field would be cleaner\n// still, but `isolatedDeclarations` rejects computed property names on classes.\n// oxlint-disable-next-line typescript/no-unsafe-declaration-merging\n// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging -- see the note above\nexport interface Component {\n /**\n * The engine-owned state.\n *\n * @internal\n */\n [COMPONENT_INTERNALS]: ComponentInternals;\n}\n\n/**\n * The optional hooks every component may implement\n * (`docs/architecture/03-scripting-and-components.md` §1).\n *\n * @remarks\n * They are declared here rather than on `Component` for the reason spelled out on\n * `ScriptCallbacks`: a member declared on the base class would force every implementation to carry\n * an `override` modifier under `noImplicitOverride` (coding standards §3). Write\n * `implements ComponentHooks` to have the signatures checked.\n *\n * @public\n */\nexport interface ComponentHooks {\n /**\n * Runs after the component's fields are assigned and before `awake`. It may run while the entity\n * is inactive, so it must not assume the component is enabled.\n */\n onAttach?(): void;\n /** Runs just before the component is removed, after `onDestroy`. */\n onDetach?(): void;\n /**\n * Runs after a tool changed the component's serialized fields from outside it: an editor's\n * inspector or document op, or a hot reload that gave a field its new default. The engine's own\n * loads and a script's assignments do not call it. A component that builds something from its\n * fields (a physics shape, say) rebuilds it here. Not gated in edit mode (ADR-0028).\n *\n * @param fields - The names of the fields that changed.\n */\n onValidate?(fields: readonly string[]): void;\n}\n\n/**\n * The abstract base class `Component.define` returns: a `Component` that also carries every\n * field the schema declares, typed.\n *\n * @typeParam S - The schema the class was defined from.\n *\n * @public\n */\nexport type ComponentDefinition<S extends Schema> = (abstract new () => Component & FieldsOf<S>) & {\n /** The instance shape, so the class satisfies `ComponentType`. */\n readonly prototype: Component & FieldsOf<S>;\n /**\n * The schema the class was defined from, carried as a value on the returned class. The other\n * statics ({@link ComponentStatics}) are deliberately *not* declared here: a subclass must be\n * able to write a plain `static typeId` without the `override` keyword.\n */\n readonly schema: S;\n};\n\n/**\n * Builds the \"used before the engine attached it\" error.\n *\n * @param component - The component that was read too early.\n * @returns The error to throw.\n */\nfunction notAttached(component: Component): IgnifxError {\n return new IgnifxError(\n CoreErrorCode.componentNotAttached,\n `${component.constructor.name} is not attached to an entity yet.`,\n {\n context: { component: component.constructor.name },\n hint: \"The engine assigns entity, uid, and handle after construction; read them in onAttach or awake.\",\n },\n );\n}\n","import { pickMeshesWithRay, pickWithRay } from \"@babylonjs/lite\";\nimport { parentNode, readNodeTag } from \"./node.js\";\nimport type { NodeTag } from \"./node.js\";\nimport type { Mesh, PickingInfo, Ray, RayPickOptions, SceneContext, SceneNode } from \"@babylonjs/lite\";\n\n/**\n * CPU picking half of the Babylon Lite adapter (`docs/architecture/07-rendering.md` §3): the\n * synchronous ray tests behind `world.raycastRender`, and the mapping from a Lite hit back to the\n * ignifx entity that owns the mesh. The GPU picker lives in `./gpu/picker.ts` because it needs a\n * device and a rendered frame.\n *\n * Everything here is `@internal`.\n *\n * ## What Lite's ray pick does (verified against `@babylonjs/lite@1.27.0` `lib/picking/ray-pick.js`)\n *\n * - It walks `scene.meshes`, skips anything with `pickable === false` unless `skipPickableCheck` is\n * set, then applies the caller's `predicate`, and tests the ray against each candidate's local\n * AABB before its triangles.\n * - The triangle test reads `mesh._cpuPositions`, the CPU copy every mesh factory retains\n * (`lib/mesh/mesh-factories.js`, `retainMeshGeometry`). A mesh with no CPU positions — one built\n * from a GPU-only path — is silently skipped, so a CPU pick can miss a mesh a GPU pick would hit.\n * - **Visibility is ignored.** `mesh.visible === false` still occludes and still returns a hit; only\n * `pickable` and the predicate filter. That is Lite's documented behaviour, and it is why the\n * component layer passes a predicate rather than relying on hiding.\n */\n\n/**\n * The result of a Babylon Lite pick — CPU ray or GPU picker — re-exported under an ignifx name so\n * feature code can name the type without importing `@babylonjs/lite` (coding standards §4).\n *\n * @internal\n */\nexport type LitePickInfo = PickingInfo;\n\n/**\n * A ray in the shape Lite expects: three-element tuples that can be rewritten in place, so a\n * picking loop reuses one ray and allocates nothing (coding standards §7).\n *\n * @internal\n */\nexport type PickRay = Ray;\n\n/**\n * Creates a reusable ray, pointing along `+Z` from the origin.\n *\n * @returns A fresh ray. **Allocates** — create one per picking site, not per pick.\n *\n * @example\n * ```ts\n * const ray = createPickRay();\n * screenToRay(camera, x, y, width, height, ray);\n * const hit = raycastScene(scene, ray);\n * ```\n *\n * @internal\n */\nexport function createPickRay(): PickRay {\n return { origin: [0, 0, 0], direction: [0, 0, 1], length: Number.MAX_VALUE };\n}\n\n/**\n * Points a ray at a world-space origin and direction, in place.\n *\n * @param ray - The ray to rewrite.\n * @param originX - The world-space origin x.\n * @param originY - The world-space origin y.\n * @param originZ - The world-space origin z.\n * @param directionX - The direction x; it need not be normalized.\n * @param directionY - The direction y.\n * @param directionZ - The direction z.\n * @param length - How far the ray reaches, in metres.\n *\n * @internal\n */\nexport function setPickRay(\n ray: PickRay,\n originX: number,\n originY: number,\n originZ: number,\n directionX: number,\n directionY: number,\n directionZ: number,\n length: number,\n): void {\n const origin = ray.origin;\n origin[0] = originX;\n origin[1] = originY;\n origin[2] = originZ;\n const magnitude = Math.hypot(directionX, directionY, directionZ);\n const scale = magnitude > 0 ? 1 / magnitude : 0;\n const direction = ray.direction;\n direction[0] = directionX * scale;\n direction[1] = directionY * scale;\n direction[2] = directionZ * scale;\n ray.length = length;\n}\n\n/**\n * Casts a ray against every renderable mesh in a scene, on the CPU.\n *\n * @remarks\n * This is `world.raycastRender`. It is distinct from a physics raycast\n * (`docs/architecture/09-physics.md` §5): it hits render geometry, including meshes that carry no\n * collider.\n *\n * @param scene - The render scene.\n * @param ray - The ray to cast.\n * @param options - An optional mesh predicate.\n * @returns Lite's picking info. Check `hit` before reading anything else. **Allocates** one result\n * object per call — Lite builds it.\n *\n * @internal\n */\nexport function raycastScene(scene: SceneContext, ray: PickRay, options?: RayPickOptions): PickingInfo {\n return pickWithRay(scene, ray, options);\n}\n\n/**\n * Casts a ray against an explicit list of meshes, on the CPU.\n *\n * @param meshes - The meshes to test.\n * @param ray - The ray to cast.\n * @param options - An optional mesh predicate.\n * @returns Lite's picking info.\n *\n * @internal\n */\nexport function raycastMeshes(meshes: Iterable<Mesh>, ray: PickRay, options?: RayPickOptions): PickingInfo {\n return pickMeshesWithRay(meshes, ray, options);\n}\n\n/**\n * Decides whether a mesh may be picked, from the ignifx tag that owns it and the mesh itself.\n *\n * @remarks\n * The tag is the one {@link readOwnerTag} finds, so a glTF mesh inside a `Model` is judged by the\n * model's entity. The mesh is passed only so a caller can compare it by identity against an earlier\n * hit; nothing outside `src/lite/**` reads it.\n *\n * @internal\n */\nexport type PickAccept = (tag: NodeTag | null, mesh: Mesh) => boolean;\n\n/**\n * The ignifx tag that owns a node: its own, or the nearest tagged ancestor's.\n *\n * @remarks\n * A `MeshRenderer` tags the mesh it clones, but a `Model` tags only the cloned glTF root, and the\n * meshes Lite draws are that root's descendants (`render/gpu/model-instance.ts`). Walking up to the\n * nearest tag resolves both, and any other renderable that parents several Lite nodes under one\n * tagged node, to the entity and component that created them (editor spike S0.2 §6.1). The walk\n * stops at the first tag, so an entity parented under a model's bone still owns its own meshes.\n *\n * @param node - The picked node, usually a mesh.\n * @returns The nearest tag, or `null` when no node on the way to the root carries one.\n *\n * @internal\n */\nexport function readOwnerTag(node: SceneNode): NodeTag | null {\n for (let current: SceneNode | null = node; current !== null; current = parentNode(current)) {\n const tag = readNodeTag(current);\n if (tag !== null) {\n return tag;\n }\n }\n return null;\n}\n\n/**\n * Casts a ray against a scene's renderable meshes, considering only the meshes a predicate accepts.\n *\n * @remarks\n * The predicate is stated over the owning *tag* rather than over Lite's `Mesh` so the component\n * layer can filter by entity without naming a Lite type (`CONSTITUTION.md` §3.4). Lite's own\n * `pickable === false` exclusion still runs first.\n *\n * @param scene - The render scene.\n * @param ray - The ray to cast.\n * @param accept - Decides whether a mesh may be picked, from the ignifx tag that owns it.\n * @returns Lite's picking info.\n *\n * @internal\n */\nexport function raycastSceneWhere(scene: SceneContext, ray: PickRay, accept: PickAccept): PickingInfo {\n const options: RayPickOptions = { predicate: (mesh: Mesh): boolean => accept(readOwnerTag(mesh), mesh) };\n return pickWithRay(scene, ray, options);\n}\n\n/**\n * Resolves a hit back to the ignifx entity and component that own the mesh.\n *\n * @param info - A result from {@link raycastScene}, {@link raycastMeshes}, or the GPU picker.\n * @returns The owning tag — the picked mesh's own or its nearest tagged ancestor's, so a glTF mesh\n * inside a `Model` resolves to the model — or `null` when the ray missed or no node on the way to\n * the root is one ignifx created.\n *\n * @internal\n */\nexport function readPickedTag(info: PickingInfo): NodeTag | null {\n const mesh = info.pickedMesh;\n if (mesh === null) {\n return null;\n }\n return readOwnerTag(mesh);\n}\n\n/**\n * The name of the mesh a hit landed on.\n *\n * @param info - A hit.\n * @returns The Lite mesh's name — for a glTF model, the name the file gives the node or primitive —\n * or `\"\"` for a miss or an unnamed mesh.\n *\n * @internal\n */\nexport function readPickedMeshName(info: PickingInfo): string {\n const name: unknown = info.pickedMesh?.name;\n return typeof name === \"string\" ? name : \"\";\n}\n\n/**\n * The identity of one earlier hit, which a pick can be told to look through.\n *\n * @internal\n */\nexport interface PickedIdentity {\n /** The mesh that was hit. */\n readonly mesh: Mesh;\n /** The thin instance that was hit, or `-1` when the mesh has none. */\n readonly thinInstanceIndex: number;\n}\n\n/**\n * Reads the identity of a hit, for a later pick to ignore.\n *\n * @param info - A hit.\n * @returns The mesh and thin instance, or `null` for a miss or a hit on something other than a\n * regular Lite mesh (a Gaussian-splatting mesh, which Lite's `ignore` cannot name).\n *\n * @internal\n */\nexport function readPickedIdentity(info: PickingInfo): PickedIdentity | null {\n const mesh = info.pickedMesh;\n if (mesh === null || !(\"material\" in mesh)) {\n return null;\n }\n return { mesh, thinInstanceIndex: info.thinInstanceIndex };\n}\n","import type { JsonObject, JsonValue } from \"./json.js\";\n\n/**\n * Field kinds supported by component schemas.\n *\n * @public\n */\nexport const FieldKind = {\n /** A 32-bit-ranged floating point number. */\n f32: \"f32\",\n /** A double-precision floating point number. */\n f64: \"f64\",\n /** A signed 32-bit integer. */\n i32: \"i32\",\n /** An unsigned 32-bit integer. */\n u32: \"u32\",\n /** A boolean toggle. */\n bool: \"bool\",\n /** A UTF-8 string. */\n str: \"str\",\n /** A 2D vector. */\n vec2: \"vec2\",\n /** A 3D vector. */\n vec3: \"vec3\",\n /** A 4D vector. */\n vec4: \"vec4\",\n /** A rotation quaternion. */\n quat: \"quat\",\n /** An RGBA color. */\n color: \"color\",\n /** One of a fixed set of string values. */\n enum: \"enum\",\n /** A reference to another entity in the same scene file. */\n entityRef: \"entityRef\",\n /** A reference to a component on an entity in the same scene file. */\n componentRef: \"componentRef\",\n /** A reference to an addressable asset. */\n asset: \"asset\",\n /** A list of values of one kind. */\n array: \"array\",\n /** A fixed group of named sub-fields. */\n record: \"record\",\n /** A string-keyed dictionary of values of one kind. */\n map: \"map\",\n /** A value that may also be `null`. */\n optional: \"optional\",\n /** A set of layer names. */\n layerMask: \"layerMask\",\n /** An animation curve. */\n curve: \"curve\",\n /** A value with a hand-written encoder and decoder. */\n custom: \"custom\",\n} as const;\n\n/**\n * The union of every field kind.\n *\n * @public\n */\nexport type FieldKind = (typeof FieldKind)[keyof typeof FieldKind];\n\n/**\n * Inspector and serializer metadata carried by every field\n * (`docs/architecture/03-scripting-and-components.md` §3,\n * `docs/architecture/06-serialization-and-scene-format.md` §5). Options never change a field's\n * value type; they constrain and present it.\n *\n * @public\n */\nexport interface FieldOptions {\n /** Help text shown next to the field in the inspector. */\n readonly tooltip?: string;\n /** Lowest accepted value for numeric kinds; validation reports `IGX-0606` below it. */\n readonly min?: number;\n /** Highest accepted value for numeric kinds; validation reports `IGX-0606` above it. */\n readonly max?: number;\n /**\n * Increment used by the inspector's drag and spinner controls. A `quat` field is edited as\n * intrinsic XYZ Euler angles, so its step is in degrees.\n */\n readonly step?: number;\n /** Hides the field from the inspector while still serializing it. */\n readonly hidden?: boolean;\n /** Shows the field in the inspector but forbids editing it there. */\n readonly readonly?: boolean;\n /** Name of the inspector group the field is folded into. */\n readonly group?: string;\n /** Excludes the field from saved games and scene files; it always takes its default on load. */\n readonly transient?: boolean;\n}\n\n/**\n * How a component class is named in a schema. A class satisfies it structurally through its\n * `prototype`, so `componentRef(Camera)` infers `Camera` without the class having to implement\n * anything. The optional `typeId` is the namespaced registration id from\n * `docs/architecture/03-scripting-and-components.md` §4 when the class carries one.\n *\n * @typeParam C - The component instance type the token stands for.\n *\n * @public\n */\nexport interface ComponentTypeToken<C> {\n /** The component's namespaced registration id, when it declares one. */\n readonly typeId?: string;\n /** The instance shape the token names. */\n readonly prototype: C;\n}\n\n/**\n * How an asset class is named in a schema. Like {@link ComponentTypeToken}, a class satisfies it\n * structurally; `assetType` supplies the `type` discriminator written into `{ \"$asset\": … }` when\n * the loader cannot infer it from the address extension\n * (`docs/architecture/05-assets-and-loading.md` §2).\n *\n * @typeParam A - The asset value type the token stands for.\n *\n * @public\n */\nexport interface AssetTypeToken<A> {\n /** The asset type name written into files when the extension is ambiguous. */\n readonly assetType?: string;\n /**\n * The instance shape the token names. A class token carries it for free; a plain token for an\n * asset that has no class (a scene, a prefab) leaves it out and fixes `A` through its annotation —\n * see `SceneAssetToken`. Nothing reads it at runtime.\n */\n readonly prototype?: A;\n}\n\n/**\n * A serializable asset reference used by scene tools before an app resolves it.\n * Runtime `asset()` fields hold `AssetHandle<A> | null`; the encoder accepts both forms through\n * their shared address and optional type.\n *\n * @typeParam A - The asset value type this reference points at. It is a compile-time marker only:\n * `assetOf` is never assigned at runtime and is never serialized. It exists so that\n * `AssetRefValue<Texture>` and `AssetRefValue<Mesh>` are different types.\n *\n * @public\n */\nexport interface AssetRefValue<A> {\n /** The address the asset is registered under, for example `models/hero.glb#mesh:Body`. */\n readonly address: string;\n /** The asset type name, when the address alone does not identify it. */\n readonly type?: string;\n /** Compile-time marker for the asset type; never present at runtime. */\n readonly assetOf?: A;\n}\n\n/**\n * One key of an animation curve: time, value, incoming tangent, outgoing tangent\n * (`docs/architecture/06-serialization-and-scene-format.md` §3).\n *\n * @public\n */\nexport type CurveKey = readonly [time: number, value: number, inTangent: number, outTangent: number];\n\n/**\n * The value a `curve()` field holds.\n *\n * @public\n */\nexport interface CurveValue {\n /** The curve's keys, ordered by time. */\n readonly keys: readonly CurveKey[];\n}\n\n/**\n * The hand-written encoder and decoder behind a `custom()` field. The codec owns both the default\n * value and the JSON representation, so `custom` is the escape hatch for value types the built-in\n * kinds cannot express.\n *\n * @typeParam T - The runtime value type.\n *\n * @public\n */\nexport interface CustomFieldCodec<T> {\n /**\n * Builds a fresh default value. It is a factory, not a constant, so two components never share\n * one mutable default object.\n *\n * @returns A newly allocated default value.\n */\n createDefault(): T;\n /**\n * Converts a runtime value into JSON.\n *\n * @param value - The value to serialize.\n * @returns The JSON representation written into the file.\n */\n serialize(value: T): JsonValue;\n /**\n * Rebuilds a runtime value from JSON.\n *\n * @param json - The JSON previously produced by `serialize`.\n * @returns The runtime value.\n */\n deserialize(json: JsonValue): T;\n /** A JSON Schema fragment describing the encoded form, merged into the generated document. */\n readonly jsonSchema?: JsonObject;\n}\n\n/**\n * Kind-specific data for the numeric kinds.\n *\n * @public\n */\nexport interface NumberFieldSpec {\n /** The numeric kind. */\n readonly kind: \"f32\" | \"f64\" | \"i32\" | \"u32\";\n}\n\n/**\n * Kind-specific data for `bool`.\n *\n * @public\n */\nexport interface BoolFieldSpec {\n /** The boolean kind. */\n readonly kind: \"bool\";\n}\n\n/**\n * Kind-specific data for `str`.\n *\n * @public\n */\nexport interface StringFieldSpec {\n /** The string kind. */\n readonly kind: \"str\";\n}\n\n/**\n * Kind-specific data for the vector kinds. `components` says how many numbers the encoded array\n * holds, so encoders do not have to re-derive it from the kind.\n *\n * @public\n */\nexport interface VectorFieldSpec {\n /** The vector kind. */\n readonly kind: \"vec2\" | \"vec3\" | \"vec4\" | \"quat\";\n /** How many components the value has: 2, 3, or 4. */\n readonly components: 2 | 3 | 4;\n}\n\n/**\n * Kind-specific data for `color`.\n *\n * @public\n */\nexport interface ColorFieldSpec {\n /** The color kind. */\n readonly kind: \"color\";\n}\n\n/**\n * Kind-specific data for `enumOf`.\n *\n * @public\n */\nexport interface EnumFieldSpec {\n /** The enumeration kind. */\n readonly kind: \"enum\";\n /** Every accepted string value, in declaration order. */\n readonly values: readonly string[];\n}\n\n/**\n * Kind-specific data for `entityRef`.\n *\n * @public\n */\nexport interface EntityRefFieldSpec {\n /** The entity-reference kind. */\n readonly kind: \"entityRef\";\n}\n\n/**\n * Kind-specific data for `componentRef`.\n *\n * @public\n */\nexport interface ComponentRefFieldSpec {\n /** The component-reference kind. */\n readonly kind: \"componentRef\";\n /** The component class the field may point at. */\n readonly componentType: ComponentTypeToken<unknown>;\n}\n\n/**\n * Kind-specific data for `asset`.\n *\n * @public\n */\nexport interface AssetFieldSpec {\n /** The asset-reference kind. */\n readonly kind: \"asset\";\n /** The asset class the field may point at. */\n readonly assetType: AssetTypeToken<unknown>;\n /** The `type` discriminator written into files, or `null` when the address is unambiguous. */\n readonly typeName: string | null;\n}\n\n/**\n * Kind-specific data for `array`.\n *\n * @public\n */\nexport interface ArrayFieldSpec {\n /** The array kind. */\n readonly kind: \"array\";\n /** The field definition every element follows. */\n readonly item: FieldDefinition<unknown>;\n}\n\n/**\n * Kind-specific data for `record`.\n *\n * @public\n */\nexport interface RecordFieldSpec {\n /** The record kind. */\n readonly kind: \"record\";\n /** The sub-fields, in declaration order. */\n readonly fields: Schema;\n}\n\n/**\n * Kind-specific data for `map`.\n *\n * @public\n */\nexport interface MapFieldSpec {\n /** The map kind. */\n readonly kind: \"map\";\n /** The field definition every entry's value follows. */\n readonly value: FieldDefinition<unknown>;\n}\n\n/**\n * Kind-specific data for `optional`.\n *\n * @public\n */\nexport interface OptionalFieldSpec {\n /** The optional kind. */\n readonly kind: \"optional\";\n /** The field definition a non-`null` value follows. */\n readonly inner: FieldDefinition<unknown>;\n}\n\n/**\n * Kind-specific data for `layerMask`.\n *\n * @public\n */\nexport interface LayerMaskFieldSpec {\n /** The layer-mask kind. */\n readonly kind: \"layerMask\";\n}\n\n/**\n * Kind-specific data for `curve`.\n *\n * @public\n */\nexport interface CurveFieldSpec {\n /** The curve kind. */\n readonly kind: \"curve\";\n}\n\n/**\n * Kind-specific data for `custom`.\n *\n * @public\n */\nexport interface CustomFieldSpec {\n /** The custom kind. */\n readonly kind: \"custom\";\n /** The hand-written codec that owns the value's default and JSON form. */\n readonly codec: CustomFieldCodec<unknown>;\n}\n\n/**\n * The discriminated union of kind-specific field data. Switching on `spec.kind` narrows to the\n * member that carries the extra information that kind needs — the enumeration's values, an array's\n * item definition, a component reference's class token — so no branch has to guess.\n *\n * @public\n */\nexport type FieldSpec =\n | NumberFieldSpec\n | BoolFieldSpec\n | StringFieldSpec\n | VectorFieldSpec\n | ColorFieldSpec\n | EnumFieldSpec\n | EntityRefFieldSpec\n | ComponentRefFieldSpec\n | AssetFieldSpec\n | ArrayFieldSpec\n | RecordFieldSpec\n | MapFieldSpec\n | OptionalFieldSpec\n | LayerMaskFieldSpec\n | CurveFieldSpec\n | CustomFieldSpec;\n\n/**\n * One declared field of a component schema. Field definitions are plain, immutable data built by\n * the constructors in this module; nothing about them is reflective and nothing runs at import\n * time (ADR-0004, `CONSTITUTION.md` §3.5).\n *\n * The type parameter is the field's *runtime* value type, which is what\n * `Script.define({ … })` uses to type the generated properties.\n *\n * @typeParam T - The runtime value type of the field.\n *\n * @example\n * ```ts\n * const speed = f32(5, { min: 0, max: 50, tooltip: \"Units per second\" });\n * speed.kind; // \"f32\"\n * speed.createDefault(); // 5\n * ```\n *\n * @public\n */\nexport interface FieldDefinition<T> {\n /** The field kind, mirroring `spec.kind` for quick reads by tooling and the docs harness. */\n readonly kind: FieldKind;\n /** The kind-specific data, discriminated by `spec.kind`. */\n readonly spec: FieldSpec;\n /** Inspector and serializer metadata. */\n readonly options: FieldOptions;\n /**\n * Builds a fresh default value. Object-valued kinds allocate on every call, so two components\n * never share one mutable default.\n *\n * @returns A newly allocated default value.\n */\n createDefault(): T;\n}\n\n/**\n * A component's declared fields, keyed by property name and ordered by declaration. Declaration\n * order is the canonical key order used when writing files\n * (`docs/architecture/06-serialization-and-scene-format.md` §1).\n *\n * @public\n */\nexport type Schema = Readonly<Record<string, FieldDefinition<unknown>>>;\n\n/**\n * The object type a schema describes: every field name mapped to its runtime value type. This is\n * what gives `this.speed` its `number` type inside a component declared with\n * `Script.define({ speed: f32(5) })`.\n *\n * @typeParam S - The schema to project.\n *\n * @example\n * ```ts\n * const schema = { speed: f32(5), label: str(\"\") };\n * type Fields = FieldsOf<typeof schema>; // { speed: number; label: string }\n * ```\n *\n * @public\n */\nexport type FieldsOf<S extends Schema> = {\n -readonly [K in keyof S]: S[K] extends FieldDefinition<infer T> ? T : never;\n};\n\n/**\n * The field object of a schema with every property optional, and an explicit `undefined` allowed.\n * `exactOptionalPropertyTypes` normally separates \"absent\" from \"present and `undefined`\"; both\n * mean \"take the schema default\" here, so both are accepted (`applyInit`, `encodeProps`).\n *\n * @typeParam S - The schema to project.\n *\n * @public\n */\nexport type PartialFieldsOf<S extends Schema> = {\n [K in keyof FieldsOf<S>]?: FieldsOf<S>[K] | undefined;\n};\n","import { SchemaIssueCode, throwSchemaError } from \"./issues.js\";\nimport { assertNoInheritedFieldNames, createDefaults } from \"./schema.js\";\nimport { FieldKind } from \"./types.js\";\nimport type {\n AssetTypeToken,\n ComponentTypeToken,\n CurveKey,\n CurveValue,\n CustomFieldCodec,\n FieldDefinition,\n FieldOptions,\n FieldSpec,\n FieldsOf,\n Schema,\n} from \"./types.js\";\nimport type { AssetHandle } from \"../assets/types.js\";\nimport type { ColorLike, QuatLike, Vec2Like, Vec3Like, Vec4Like } from \"../math/types.js\";\n\n/**\n * The default a `vec2()` field takes when none is given.\n *\n * @internal\n */\nconst ZERO2: Vec2Like = { x: 0, y: 0 };\n/**\n * The default a `vec3()` field takes when none is given.\n *\n * @internal\n */\nconst ZERO3: Vec3Like = { x: 0, y: 0, z: 0 };\n/**\n * The default a `vec4()` field takes when none is given.\n *\n * @internal\n */\nconst ZERO4: Vec4Like = { x: 0, y: 0, z: 0, w: 0 };\n/**\n * The identity rotation, the default a `quat()` field takes when none is given.\n *\n * @internal\n */\nconst IDENTITY_QUAT: QuatLike = { x: 0, y: 0, z: 0, w: 1 };\n/**\n * Opaque white, the default a `color()` field takes when none is given.\n *\n * @internal\n */\nconst WHITE: ColorLike = { r: 1, g: 1, b: 1, a: 1 };\n/**\n * The default a `curve()` field takes when none is given.\n *\n * @internal\n */\nconst EMPTY_CURVE: CurveValue = { keys: [] };\n/**\n * Matches `#rgb`, `#rgba`, `#rrggbb`, and `#rrggbbaa`.\n *\n * @internal\n */\nconst HEX_COLOR_PATTERN = /^#(?:[0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/u;\n\n/**\n * Assembles a field definition. Centralising construction keeps `kind` and `spec.kind` in step and\n * keeps every field a plain, frozen-by-convention data object.\n *\n * @param spec - The kind-specific data, which also supplies the discriminant.\n * @param options - Inspector and serializer metadata, if any.\n * @param createDefault - Factory for a fresh default value.\n * @returns The field definition.\n *\n * @internal\n */\nfunction field<T>(spec: FieldSpec, options: FieldOptions | undefined, createDefault: () => T): FieldDefinition<T> {\n return { kind: spec.kind, spec, options: options ?? {}, createDefault };\n}\n\n/**\n * Parses a CSS-style hexadecimal color into normalized sRGB channels.\n *\n * @param hex - `#rgb`, `#rgba`, `#rrggbb`, or `#rrggbbaa`.\n * @returns The parsed color with channels in the 0–1 range.\n * @throws A `TypeError` when the string is not one of the accepted forms.\n *\n * @internal\n */\nfunction parseHexColor(hex: string): ColorLike {\n if (!HEX_COLOR_PATTERN.test(hex)) {\n throwSchemaError(\n SchemaIssueCode.typeMismatch,\n `color(\"${hex}\") is not a hexadecimal color; use #rgb, #rgba, #rrggbb, or #rrggbbaa.`,\n );\n }\n const digits = hex.slice(1);\n const short = digits.length <= 4;\n const size = short ? 1 : 2;\n const scale = short ? 15 : 255;\n const channel = (index: number): number => {\n const start = index * size;\n if (start >= digits.length) {\n return 1;\n }\n return Number.parseInt(digits.slice(start, start + size), 16) / scale;\n };\n return { r: channel(0), g: channel(1), b: channel(2), a: channel(3) };\n}\n\n/**\n * Declares a single-precision floating point field.\n *\n * @param defaultValue - The value a new component starts with.\n * @param options - Inspector and serializer metadata.\n * @returns The field definition.\n *\n * @example\n * ```ts\n * speed: f32(5, { min: 0, max: 50, tooltip: \"Units per second\" });\n * ```\n *\n * @public\n */\nexport function f32(defaultValue: number = 0, options?: FieldOptions): FieldDefinition<number> {\n return field({ kind: FieldKind.f32 }, options, () => defaultValue);\n}\n\n/**\n * Declares a double-precision floating point field.\n *\n * @param defaultValue - The value a new component starts with.\n * @param options - Inspector and serializer metadata.\n * @returns The field definition.\n *\n * @public\n */\nexport function f64(defaultValue: number = 0, options?: FieldOptions): FieldDefinition<number> {\n return field({ kind: FieldKind.f64 }, options, () => defaultValue);\n}\n\n/**\n * Declares a signed 32-bit integer field. Validation rejects fractional values and values outside\n * the signed 32-bit range with `IGX-0606`.\n *\n * @param defaultValue - The value a new component starts with.\n * @param options - Inspector and serializer metadata.\n * @returns The field definition.\n *\n * @public\n */\nexport function i32(defaultValue: number = 0, options?: FieldOptions): FieldDefinition<number> {\n return field({ kind: FieldKind.i32 }, options, () => defaultValue);\n}\n\n/**\n * Declares an unsigned 32-bit integer field. Validation rejects fractional and negative values, and\n * values above 4294967295, with `IGX-0606`.\n *\n * @param defaultValue - The value a new component starts with.\n * @param options - Inspector and serializer metadata.\n * @returns The field definition.\n *\n * @public\n */\nexport function u32(defaultValue: number = 0, options?: FieldOptions): FieldDefinition<number> {\n return field({ kind: FieldKind.u32 }, options, () => defaultValue);\n}\n\n/**\n * Declares a boolean field.\n *\n * @param defaultValue - The value a new component starts with.\n * @param options - Inspector and serializer metadata.\n * @returns The field definition.\n *\n * @public\n */\nexport function bool(defaultValue: boolean = false, options?: FieldOptions): FieldDefinition<boolean> {\n return field({ kind: FieldKind.bool }, options, () => defaultValue);\n}\n\n/**\n * Declares a string field.\n *\n * @param defaultValue - The value a new component starts with.\n * @param options - Inspector and serializer metadata.\n * @returns The field definition.\n *\n * @public\n */\nexport function str(defaultValue: string = \"\", options?: FieldOptions): FieldDefinition<string> {\n return field({ kind: FieldKind.str }, options, () => defaultValue);\n}\n\n/**\n * Declares a 2D vector field. The runtime value type is the structural `Vec2Like`, so the engine's\n * `Vec2` class and plain object literals are both accepted.\n *\n * @param defaultValue - The value a new component starts with; defaults to the origin.\n * @param options - Inspector and serializer metadata.\n * @returns The field definition.\n *\n * @public\n */\nexport function vec2(defaultValue: Vec2Like = ZERO2, options?: FieldOptions): FieldDefinition<Vec2Like> {\n const { x, y } = defaultValue;\n return field({ kind: FieldKind.vec2, components: 2 }, options, (): Vec2Like => ({ x, y }));\n}\n\n/**\n * Declares a 3D vector field.\n *\n * @param defaultValue - The value a new component starts with; defaults to the origin.\n * @param options - Inspector and serializer metadata.\n * @returns The field definition.\n *\n * @example\n * ```ts\n * offset: vec3({ x: 0, y: 1, z: 0 });\n * ```\n *\n * @public\n */\nexport function vec3(defaultValue: Vec3Like = ZERO3, options?: FieldOptions): FieldDefinition<Vec3Like> {\n const { x, y, z } = defaultValue;\n return field({ kind: FieldKind.vec3, components: 3 }, options, (): Vec3Like => ({ x, y, z }));\n}\n\n/**\n * Declares a 4D vector field.\n *\n * @param defaultValue - The value a new component starts with; defaults to all zeroes.\n * @param options - Inspector and serializer metadata.\n * @returns The field definition.\n *\n * @public\n */\nexport function vec4(defaultValue: Vec4Like = ZERO4, options?: FieldOptions): FieldDefinition<Vec4Like> {\n const { x, y, z, w } = defaultValue;\n return field({ kind: FieldKind.vec4, components: 4 }, options, (): Vec4Like => ({ x, y, z, w }));\n}\n\n/**\n * Declares a rotation field.\n *\n * @param defaultValue - The value a new component starts with; defaults to the identity rotation.\n * @param options - Inspector and serializer metadata.\n * @returns The field definition.\n *\n * @public\n */\nexport function quat(defaultValue: QuatLike = IDENTITY_QUAT, options?: FieldOptions): FieldDefinition<QuatLike> {\n const { x, y, z, w } = defaultValue;\n return field({ kind: FieldKind.quat, components: 4 }, options, (): QuatLike => ({ x, y, z, w }));\n}\n\n/**\n * Declares an RGBA color field. Channels are sRGB in the 0–1 range, in memory and in files alike:\n * conversion to linear space belongs to the renderer, not the schema\n * (`docs/architecture/06-serialization-and-scene-format.md` §3).\n *\n * @param defaultValue - The starting color, either as channels or as a `#rgb`/`#rgba`/`#rrggbb`/\n * `#rrggbbaa` string; defaults to opaque white.\n * @param options - Inspector and serializer metadata.\n * @returns The field definition.\n * @throws A `TypeError` when a string default is not a valid hexadecimal color.\n *\n * @example\n * ```ts\n * tint: color(\"#ffffff\");\n * ```\n *\n * @public\n */\nexport function color(defaultValue: ColorLike | string = WHITE, options?: FieldOptions): FieldDefinition<ColorLike> {\n const { r, g, b, a } = typeof defaultValue === \"string\" ? parseHexColor(defaultValue) : defaultValue;\n return field({ kind: FieldKind.color }, options, (): ColorLike => ({ r, g, b, a }));\n}\n\n/**\n * Declares a field restricted to a fixed set of string values.\n *\n * @param values - Every accepted value, in the order the inspector should list them.\n * @param defaultValue - The value a new component starts with; `NoInfer` keeps it out of the\n * inference for `T`, so passing a value `values` does not contain is a compile error as well as a\n * runtime one.\n * @param options - Inspector and serializer metadata.\n * @returns The field definition.\n * @throws A `TypeError` when `defaultValue` is not one of `values`.\n *\n * @example\n * ```ts\n * mode: enumOf([\"walk\", \"run\"] as const, \"walk\");\n * ```\n *\n * @public\n */\nexport function enumOf<const T extends string>(\n values: readonly T[],\n defaultValue: NoInfer<T>,\n options?: FieldOptions,\n): FieldDefinition<T> {\n if (!values.includes(defaultValue)) {\n throwSchemaError(\n SchemaIssueCode.outOfRange,\n `enumOf default \"${defaultValue}\" is not one of [${values.join(\", \")}].`,\n );\n }\n return field({ kind: FieldKind.enum, values: [...values] }, options, () => defaultValue);\n}\n\n/**\n * Declares a reference to another entity in the same scene file. The value is `null` until the\n * scene is fully constructed and is nulled again when the target is destroyed\n * (`docs/architecture/03-scripting-and-components.md` §3).\n *\n * The entity type is supplied by the caller because `Entity` lives in the kernel, which is layered\n * above this module.\n *\n * @typeParam E - The entity type the reference resolves to.\n * @param options - Inspector and serializer metadata.\n * @returns The field definition.\n *\n * @example\n * ```ts\n * target: entityRef<Entity>();\n * ```\n *\n * @public\n */\nexport function entityRef<E = unknown>(options?: FieldOptions): FieldDefinition<E | null> {\n return field({ kind: FieldKind.entityRef }, options, (): E | null => null);\n}\n\n/**\n * Declares a reference to a component on an entity in the same scene file.\n *\n * @typeParam C - The component type the reference resolves to, inferred from the class.\n * @param type - The component class the field may point at.\n * @param options - Inspector and serializer metadata.\n * @returns The field definition.\n *\n * @example\n * ```ts\n * follow: componentRef(Camera); // Camera | null\n * ```\n *\n * @public\n */\nexport function componentRef<C>(type: ComponentTypeToken<C>, options?: FieldOptions): FieldDefinition<C | null> {\n return field({ kind: FieldKind.componentRef, componentType: type }, options, (): C | null => null);\n}\n\n/**\n * Declares a reference to an addressable asset. The **runtime** value is the loaded\n * {@link AssetHandle}, not an address: a component's `asset()` fields are resolved before its props\n * are written, so `awake` can already read `this.mesh.value`\n * (`docs/architecture/05-assets-and-loading.md` §3).\n *\n * @remarks\n * Files store the address instead — `{ \"$asset\": \"models/hero.glb\", \"type\"?: \"model\" }`\n * (`06-serialization-and-scene-format.md` §3). Encoding reads `handle.address`; decoding hands that\n * address to the `asset` resolver of the `ReferenceDecoder` the scene loader supplies, which answers\n * with the handle the scene already retains. Two consequences game code sees:\n *\n * - An address the resolver cannot answer decodes to `null` and reports `IGX-0602`; the component\n * keeps working with a missing asset rather than failing the whole scene.\n * - An **in-code** asset — anything from `Assets.register`, which includes `MeshAsset.box(…)` and\n * `createMaterialAsset(app, pbrMaterialDefinition({ … }))` — lives at a `memory:` address that names no file, so serializing a\n * component that holds one writes `null` and reports the loss. Save the asset as a file when it\n * has to survive a round trip.\n *\n * The field does **not** retain the handle: the scene instance that loaded it owns the reference\n * count and releases it on unload.\n *\n * @typeParam A - The asset type the reference points at, inferred from the class.\n * @param type - The asset class the field may point at.\n * @param options - Inspector and serializer metadata.\n * @returns The field definition.\n *\n * @example\n * ```ts\n * class Hero extends Component.define({ clip: asset(AudioClip) }) {\n * static typeId = \"mygame/Hero\";\n * awake(): void {\n * this.clip?.value.play();\n * }\n * }\n * ```\n *\n * @public\n */\nexport function asset<A>(type: AssetTypeToken<A>, options?: FieldOptions): FieldDefinition<AssetHandle<A> | null> {\n const typeName = type.assetType ?? null;\n return field({ kind: FieldKind.asset, assetType: type, typeName }, options, (): AssetHandle<A> | null => null);\n}\n\n/**\n * Declares a list field. The runtime value type is a *mutable* array because game code is expected\n * to push to it (`this.waypoints.push(p)`); the default is copied on every instantiation, shallowly,\n * so element objects supplied as defaults are shared and should be treated as immutable.\n *\n * @typeParam T - The element value type, inferred from `item`.\n * @param item - The field definition every element follows.\n * @param defaultValue - The list a new component starts with; defaults to empty.\n * @param options - Inspector and serializer metadata.\n * @returns The field definition.\n *\n * @example\n * ```ts\n * waypoints: array(vec3()); // Vec3Like[]\n * ```\n *\n * @public\n */\nexport function array<T>(\n item: FieldDefinition<T>,\n defaultValue: readonly T[] = [],\n options?: FieldOptions,\n): FieldDefinition<T[]> {\n const snapshot = [...defaultValue];\n return field({ kind: FieldKind.array, item }, options, (): T[] => [...snapshot]);\n}\n\n/**\n * Declares a fixed group of named sub-fields. Sub-fields are serialized as a nested JSON object in\n * declaration order and validated recursively.\n *\n * @typeParam S - The sub-schema, inferred from `fields`.\n * @param fields - The sub-fields.\n * @param options - Inspector and serializer metadata.\n * @returns The field definition.\n * @throws IgnifxError with code `IGX-0607` when a sub-field name is an `Object.prototype` member\n * such as `__proto__`, `constructor`, or `toString`.\n *\n * @example\n * ```ts\n * stats: record({ hp: i32(10), armor: f32(0) }); // { hp: number; armor: number }\n * ```\n *\n * @public\n */\nexport function record<S extends Schema>(fields: S, options?: FieldOptions): FieldDefinition<FieldsOf<S>> {\n assertNoInheritedFieldNames(fields, \"record\");\n return field({ kind: FieldKind.record, fields }, options, () => createDefaults(fields));\n}\n\n/**\n * Declares a string-keyed dictionary field. Keys are written in lexicographic order so that two\n * saves of the same state are byte-identical\n * (`docs/architecture/06-serialization-and-scene-format.md` §1).\n *\n * @typeParam T - The entry value type, inferred from `value`.\n * @param value - The field definition every entry's value follows.\n * @param options - Inspector and serializer metadata.\n * @returns The field definition.\n *\n * @example\n * ```ts\n * ammo: map(i32(0)); // Record<string, number>\n * ```\n *\n * @public\n */\nexport function map<T>(value: FieldDefinition<T>, options?: FieldOptions): FieldDefinition<Record<string, T>> {\n return field({ kind: FieldKind.map, value }, options, (): Record<string, T> => ({}));\n}\n\n/**\n * Declares a field that may also be `null`, defaulting to `null` (coding standards §5.5: `null` is\n * \"absent value\", `undefined` never reaches a file).\n *\n * @typeParam T - The value type when present, inferred from `inner`.\n * @param inner - The field definition a non-`null` value follows.\n * @param options - Inspector and serializer metadata.\n * @returns The field definition.\n *\n * @example\n * ```ts\n * nickname: optional(str()); // string | null\n * ```\n *\n * @public\n */\nexport function optional<T>(inner: FieldDefinition<T>, options?: FieldOptions): FieldDefinition<T | null> {\n return field({ kind: FieldKind.optional, inner }, options, (): T | null => null);\n}\n\n/**\n * Declares a set of layers. Layers are stored by *name*, not by bit value, so renaming a layer in\n * project settings does not silently repoint existing files\n * (`docs/architecture/06-serialization-and-scene-format.md` §3).\n *\n * The field's value is a read-only array of names. The kernel's `LayerMask` satisfies the same\n * structural shape, so a component may hold either.\n *\n * @param defaultValue - The names a new component starts with; defaults to empty.\n * @param options - Inspector and serializer metadata.\n * @returns The field definition.\n *\n * @example\n * ```ts\n * collidesWith: layerMask([\"Default\", \"Enemy\"]);\n * ```\n *\n * @public\n */\nexport function layerMask(\n defaultValue: readonly string[] = [],\n options?: FieldOptions,\n): FieldDefinition<readonly string[]> {\n const snapshot = [...defaultValue];\n return field({ kind: FieldKind.layerMask }, options, (): readonly string[] => [...snapshot]);\n}\n\n/**\n * Declares an animation curve field.\n *\n * @param defaultValue - The curve a new component starts with; defaults to no keys.\n * @param options - Inspector and serializer metadata.\n * @returns The field definition.\n *\n * @example\n * ```ts\n * falloff: curve({ keys: [[0, 1, 0, 0], [1, 0, 0, 0]] });\n * ```\n *\n * @public\n */\nexport function curve(defaultValue: CurveValue = EMPTY_CURVE, options?: FieldOptions): FieldDefinition<CurveValue> {\n const keys = defaultValue.keys.map((key): CurveKey => [key[0], key[1], key[2], key[3]]);\n return field({ kind: FieldKind.curve }, options, (): CurveValue => ({ keys: [...keys] }));\n}\n\n/**\n * Declares a field whose JSON form is written by hand. Use it for value types the built-in kinds\n * cannot express; the codec owns the default, the encoding, and the generated JSON Schema fragment.\n *\n * @typeParam T - The runtime value type.\n * @param codec - The default factory, `serialize`, `deserialize`, and optional `jsonSchema`.\n * @param options - Inspector and serializer metadata.\n * @returns The field definition.\n *\n * @example\n * ```ts\n * grid: custom({\n * createDefault: () => new Uint8Array(16),\n * serialize: (value) => [...value],\n * deserialize: (json) => Uint8Array.from(Array.isArray(json) ? json.map(Number) : []),\n * jsonSchema: { type: \"array\", items: { type: \"integer\" } },\n * });\n * ```\n *\n * @public\n */\nexport function custom<T>(codec: CustomFieldCodec<T>, options?: FieldOptions): FieldDefinition<T> {\n return field({ kind: FieldKind.custom, codec }, options, () => codec.createDefault());\n}\n","import { CoreErrorCode } from \"../errors/error-codes.js\";\nimport { IgnifxError } from \"../errors/ignifx-error.js\";\nimport type { RenderCapture } from \"./renderer.js\";\nimport type { LiteCamera } from \"../lite/camera.js\";\nimport type { LiteRenderTexture } from \"../lite/gpu/render-texture.js\";\n\n/**\n * The largest side of a render texture, in pixels.\n *\n * @public\n */\nexport const RENDER_TEXTURE_MAX_SIZE = 4096;\n\n/**\n * The Babylon Lite `metadata` key that keeps a render-scene mesh out of every render texture.\n *\n * @remarks\n * A mesh whose `metadata[EDITOR_ONLY_METADATA_KEY]` is `true` draws in the main view but never in\n * a {@link RenderTexture}: an editor's grid or helper that must not show in its game view or\n * thumbnails. Set it on a mesh reached through a `.lite` escape hatch, such as\n * `RenderOverlay.lite.mainScene` (no stability guarantee, `CONSTITUTION.md` §3.4).\n *\n * @beta\n */\nexport const EDITOR_ONLY_METADATA_KEY = \"ignifxEditorOnly\";\n\n/**\n * An offscreen colour target a camera renders into (`docs/architecture/07-rendering.md` §2.11).\n *\n * @remarks\n * Create one with `app.renderer.createRenderTexture(width, height)`. Fill it once with\n * `app.renderer.renderToTexture(camera, texture)`, or every frame by setting a camera's\n * `renderTarget`. It holds a GPU pass of the render scene and its target from the first render\n * on; `dispose()` frees both, and `app.dispose()` disposes every texture still open.\n *\n * @example\n * ```ts\n * const texture = app.renderer.createRenderTexture(256, 256);\n * await app.renderer.renderToTexture(minimapCamera, texture);\n * const pixels = await texture.readPixels();\n * texture.dispose();\n * ```\n *\n * @beta\n */\nexport interface RenderTexture {\n /** The width, in pixels. */\n readonly width: number;\n /** The height, in pixels. */\n readonly height: number;\n /** Whether `dispose()` has run. */\n readonly isDisposed: boolean;\n /**\n * Reads the texture as the last rendered frame left it.\n *\n * @returns Tightly packed RGBA8, top row first. All zeros before anything was rendered into it.\n * @throws IgnifxError with code `IGX-0729` on a headless app or while no render loop runs, and\n * `IGX-0731` once the texture is disposed.\n */\n readPixels(): Promise<RenderCapture>;\n /** Frees the texture's GPU pass and target. Idempotent; a camera rendering into it stops. */\n dispose(): void;\n}\n\n/**\n * What a render texture needs from the renderer that made it.\n *\n * @internal\n */\nexport interface RenderTextureOwner {\n /**\n * Creates the texture's GPU pass, or throws why it cannot.\n *\n * @param width - The width.\n * @param height - The height.\n * @param member - The API member asking, for the error.\n * @returns The pass.\n */\n createPass(width: number, height: number, member: string): Promise<LiteRenderTexture>;\n /**\n * Forgets a disposed texture.\n *\n * @param texture - The texture.\n */\n release(texture: RenderTextureImpl): void;\n}\n\n/** A pending one-frame render. */\ninterface RenderRequest {\n /** The camera to render through. */\n readonly camera: LiteCamera;\n /** Settles the request once its frame has been submitted. */\n readonly resolve: () => void;\n}\n\n/**\n * Checks a render texture's size.\n *\n * @param width - The requested width.\n * @param height - The requested height.\n * @throws IgnifxError with code `IGX-0730` for a side that is not a whole number from 1 to\n * {@link RENDER_TEXTURE_MAX_SIZE}.\n *\n * @internal\n */\nexport function assertRenderTextureSize(width: number, height: number): void {\n const isSide = (side: number): boolean => Number.isSafeInteger(side) && side >= 1 && side <= RENDER_TEXTURE_MAX_SIZE;\n if (!isSide(width) || !isSide(height)) {\n throw new IgnifxError(\n CoreErrorCode.invalidRenderTextureSize,\n `A render texture of ${String(width)}x${String(height)}: each side must be a whole number from 1 to ${String(RENDER_TEXTURE_MAX_SIZE)}.`,\n { context: { member: \"app.renderer.createRenderTexture()\", width, height, max: RENDER_TEXTURE_MAX_SIZE } },\n );\n }\n}\n\n/**\n * What {@link bindFrameCameras} reads of a camera: a structural slice of `Camera`.\n *\n * @internal\n */\nexport interface FrameCameraSource {\n /** The camera's render target, or `null` for the canvas. */\n readonly renderTarget: RenderTexture | null;\n /** The Lite camera, `null` while detached. */\n readonly lite: { readonly camera: LiteCamera | null };\n /** Whether the camera and its entity are enabled. */\n readonly isEnabledInHierarchy: boolean;\n}\n\n/**\n * Tells each live texture which enabled, attached camera renders into it this frame.\n *\n * @param cameras - Every camera in the world, in creation order; the last one per texture wins.\n * @param live - The renderer's live textures; a camera aiming at any other is ignored.\n *\n * @internal\n */\nexport function bindFrameCameras(cameras: readonly FrameCameraSource[], live: ReadonlySet<RenderTextureImpl>): void {\n for (const camera of cameras) {\n const target = camera.renderTarget;\n const lite = camera.lite.camera;\n if (target instanceof RenderTextureImpl && live.has(target) && lite !== null && camera.isEnabledInHierarchy) {\n target.setFrameCamera(lite);\n }\n }\n}\n\n/**\n * The renderer's render texture: the per-frame camera choice and the one-frame requests.\n *\n * @internal\n */\nexport class RenderTextureImpl implements RenderTexture {\n readonly width: number;\n\n readonly height: number;\n\n readonly #owner: RenderTextureOwner;\n\n #pass: LiteRenderTexture | null = null;\n\n #creating: Promise<LiteRenderTexture> | null = null;\n\n /** The camera whose `renderTarget` this is, as the current frame's sync found it. */\n #frameCamera: LiteCamera | null = null;\n\n readonly #requests: RenderRequest[] = [];\n\n #isDisposed = false;\n\n /**\n * Creates the texture; its GPU pass is created on first use.\n *\n * @param owner - The renderer.\n * @param width - The checked width.\n * @param height - The checked height.\n */\n constructor(owner: RenderTextureOwner, width: number, height: number) {\n this.#owner = owner;\n this.width = width;\n this.height = height;\n }\n\n get isDisposed(): boolean {\n return this.#isDisposed;\n }\n\n /**\n * Resolves the texture's GPU pass, creating it once.\n *\n * @param member - The API member asking, for the error.\n * @returns The pass.\n */\n async pass(member: string): Promise<LiteRenderTexture> {\n this.assertUsable(member);\n this.#creating ??= this.#owner.createPass(this.width, this.height, member).then(\n (pass) => {\n if (this.#isDisposed) {\n pass.dispose();\n } else {\n this.#pass = pass;\n }\n return pass;\n },\n (error: unknown) => {\n this.#creating = null;\n throw error;\n },\n );\n const pass = await this.#creating;\n this.assertUsable(member);\n return pass;\n }\n\n /**\n * Queues a render through a camera on the next frame.\n *\n * @param camera - The Lite camera.\n * @returns A promise that settles once that frame has been submitted.\n */\n request(camera: LiteCamera): Promise<void> {\n return new Promise((resolve) => {\n this.#requests.push({ camera, resolve });\n });\n }\n\n /**\n * Notes the camera that renders into this texture every frame. The render sync system calls it\n * for every enabled camera whose `renderTarget` this is, before {@link RenderTextureImpl.flush}.\n *\n * @param camera - The Lite camera.\n */\n setFrameCamera(camera: LiteCamera): void {\n this.#frameCamera = camera;\n if (this.#pass === null && this.#creating === null) {\n // The first frame only starts the pass; a failure leaves it for the next frame to retry.\n this.pass(\"Camera.renderTarget\").catch(() => null);\n }\n }\n\n /**\n * Points the pass at this frame's camera: the oldest request's, else the `renderTarget` one's,\n * else none. Requests for that camera settle once the frame is submitted.\n */\n flush(): void {\n const pass = this.#pass;\n const requested = this.#requests[0]?.camera ?? null;\n const camera = requested ?? this.#frameCamera;\n this.#frameCamera = null;\n if (pass === null) {\n return;\n }\n pass.setCamera(camera);\n if (requested === null) {\n return;\n }\n const served: RenderRequest[] = [];\n for (let index = this.#requests.length - 1; index >= 0; index -= 1) {\n const pending = this.#requests[index];\n if (pending !== undefined && pending.camera === requested) {\n served.push(pending);\n this.#requests.splice(index, 1);\n }\n }\n // The frame graph executes after this frame callback and submits in the same task; a microtask\n // runs once it has.\n queueMicrotask(() => {\n for (const pending of served) {\n pending.resolve();\n }\n });\n }\n\n async readPixels(): Promise<RenderCapture> {\n const pass = await this.pass(\"RenderTexture.readPixels()\");\n const data = await pass.read();\n return { width: this.width, height: this.height, data };\n }\n\n dispose(): void {\n if (this.#isDisposed) {\n return;\n }\n this.#isDisposed = true;\n this.#pass?.dispose();\n this.#pass = null;\n this.#owner.release(this);\n // Nothing will render them now; settling beats leaving the caller waiting forever.\n for (const pending of this.#requests.splice(0)) {\n pending.resolve();\n }\n }\n\n /**\n * Refuses a disposed texture.\n *\n * @param member - The API member asking.\n * @throws IgnifxError with code `IGX-0731` once disposed.\n */\n assertUsable(member: string): void {\n if (this.#isDisposed) {\n throw renderTextureUnusableError(member);\n }\n }\n}\n\n/**\n * The error for a disposed or foreign render texture.\n *\n * @param member - The API member asking.\n * @returns The error.\n *\n * @internal\n */\nexport function renderTextureUnusableError(member: string): IgnifxError {\n return new IgnifxError(\n CoreErrorCode.renderTextureUnusable,\n `${member}: the render texture is disposed or belongs to another app.`,\n {\n context: { member },\n hint: \"Create a render texture with this app's app.renderer.createRenderTexture() and keep it until you dispose it.\",\n },\n );\n}\n","import { Component } from \"../component/component.js\";\nimport { enumOf, f32, layerMask, optional, u32, vec3 } from \"../schema/field-kinds.js\";\nimport { createDefaults, defineSchema } from \"../schema/schema.js\";\nimport type { Vec3Like } from \"../math/types.js\";\nimport type { Schema } from \"../schema/types.js\";\n\n/**\n * The `ReflectionProbe` component (`docs/plan/2026-11-gi-phase-2-execution-plan.md`, step B1).\n *\n * The component only holds settings and the \"capture again\" request. The renderer loads the probe's\n * GPU code (`./gpu/reflection-probes.ts`, `../lite/gpu/reflection-probe.ts`) only once a world has\n * a probe, so a project without one pays nothing for it (`CONSTITUTION.md` §2.5). Headless, a probe\n * captures nothing.\n */\n\n/**\n * The `as const` name table behind {@link ReflectionProbeRefreshMode}.\n *\n * @public\n */\nexport const REFLECTION_PROBE_REFRESH_MODES = [\"once\", \"onDemand\", \"everyFrame\"] as const;\n\n/**\n * When a reflection probe renders its cube map again.\n *\n * @remarks\n * - `\"once\"` (default): when the probe is first ready, and again on {@link ReflectionProbe.refresh}.\n * - `\"onDemand\"`: only on {@link ReflectionProbe.refresh}; until then the probe reflects nothing.\n * - `\"everyFrame\"`: every frame, six extra scene passes each frame. Use it for one probe at most, and\n * only on desktop at the `high` quality tier (nothing caps it yet).\n *\n * @public\n */\nexport type ReflectionProbeRefreshMode = (typeof REFLECTION_PROBE_REFRESH_MODES)[number];\n\n/** The smallest and largest cube face, in pixels. */\nconst MIN_SIZE = 16;\nconst MAX_SIZE = 1024;\n\n/**\n * A point that captures the scene around it into a cube map, which nearby shiny PBR materials then\n * reflect instead of the scene environment.\n *\n * @remarks\n * Each lit PBR material reflects the nearest enabled probe that has captured: a probe whose\n * `boxProjection` box holds the mesh wins over one that does not, then the closer probe wins. With no\n * probe, materials reflect the `Environment` again. A material shared by several meshes follows the\n * first of them. Diffuse lighting still comes from the scene environment.\n *\n * The probe needs a loaded `Environment` (it reuses its lighting tables) and a canvas-backed app.\n * Mip levels are box-filtered, so very rough materials look blurrier than with a prefiltered `.env`.\n *\n * @example\n * ```ts\n * const probe = world.createEntity(\"Room probe\", { position: { x: 0, y: 1.5, z: 0 } });\n * probe.addComponent(ReflectionProbe, { size: 128, boxProjection: { x: 8, y: 3, z: 8 } });\n * ```\n *\n * @beta\n */\nexport class ReflectionProbe extends Component {\n /** The namespaced registration id. */\n static typeId = \"ignifx/ReflectionProbe\";\n\n /** What the component does, in one line, for an inspector. */\n static description = \"Captures the scene around it into a cube map that nearby PBR materials reflect.\";\n\n /** One probe per entity. */\n static allowMultiple = false;\n\n /** The serialized field declarations (ADR-0004). */\n static schema: Schema = reflectionProbeSchema();\n\n /** Cube face size in pixels, rounded down to a power of two from 16 to 1024. Defaults to `128`. */\n declare size: number;\n\n /** When the probe captures again. Defaults to `\"once\"`. */\n declare refreshMode: ReflectionProbeRefreshMode;\n\n /**\n * The full size, in metres, of the box (centred on the probe) that reflections are projected onto,\n * or `null` (default) for no box: reflections then look infinitely far away.\n */\n declare boxProjection: Vec3Like | null;\n\n /** The layer names the probe captures; empty (default) captures every layer. */\n declare cullingMask: readonly string[];\n\n /** The near clip distance of the capture, in metres. Defaults to `0.1`. */\n declare near: number;\n\n /** The far clip distance of the capture, in metres. Defaults to `1000`. */\n declare far: number;\n\n /** Applies the schema defaults, exactly as `Component.define` would. */\n constructor() {\n super();\n Object.assign(this, createDefaults(ReflectionProbe.schema));\n }\n\n #isRefreshRequested = false;\n\n /**\n * Asks the probe to capture again from the next frame, whatever its `refreshMode`.\n *\n * @remarks\n * Call it after the static scene around the probe changed, such as a door opening. A capture\n * repeats over a few frames, so meshes whose materials are still compiling are caught.\n */\n refresh(): void {\n this.#isRefreshRequested = true;\n }\n\n /**\n * Reads and clears the request {@link ReflectionProbe.refresh} made.\n *\n * @returns Whether a capture was requested since the last call.\n *\n * @internal\n */\n consumeRefreshRequest(): boolean {\n const requested = this.#isRefreshRequested;\n this.#isRefreshRequested = false;\n return requested;\n }\n}\n\n/**\n * The cube face size a probe captures at.\n *\n * @param size - The authored size.\n * @returns `size` rounded down to a power of two and clamped to 16..1024; 128 for a value that is not\n * a finite number.\n *\n * @internal\n */\nexport function resolveReflectionProbeSize(size: number): number {\n if (!Number.isFinite(size)) {\n return 128;\n }\n const clamped = Math.min(MAX_SIZE, Math.max(MIN_SIZE, Math.floor(size)));\n return 2 ** Math.floor(Math.log2(clamped));\n}\n\n/**\n * A probe as {@link selectReflectionProbe} sees it.\n *\n * @internal\n */\nexport interface ReflectionProbeCandidate {\n /** The probe's world position. */\n readonly x: number;\n readonly y: number;\n readonly z: number;\n /** The full size of its projection box, or `null`. */\n readonly box: Vec3Like | null;\n}\n\n/**\n * Picks the probe a point reflects.\n *\n * @remarks\n * A probe whose box holds the point wins, the smallest such box first; with none, the closest\n * probe centre wins. Ties keep the earlier probe.\n *\n * @param x - The point's world X.\n * @param y - The point's world Y.\n * @param z - The point's world Z.\n * @param candidates - The enabled probes that have captured.\n * @returns The index of the chosen probe, or `-1` when there is none.\n *\n * @internal\n */\nexport function selectReflectionProbe(\n x: number,\n y: number,\n z: number,\n candidates: readonly ReflectionProbeCandidate[],\n): number {\n let inside = -1;\n let insideVolume = Number.POSITIVE_INFINITY;\n let nearest = -1;\n let nearestDistance = Number.POSITIVE_INFINITY;\n for (let index = 0; index < candidates.length; index += 1) {\n const probe = candidates[index];\n if (probe === undefined) {\n continue;\n }\n const dx = x - probe.x;\n const dy = y - probe.y;\n const dz = z - probe.z;\n const box = probe.box;\n if (box !== null && Math.abs(dx) <= box.x / 2 && Math.abs(dy) <= box.y / 2 && Math.abs(dz) <= box.z / 2) {\n const volume = box.x * box.y * box.z;\n if (volume < insideVolume) {\n inside = index;\n insideVolume = volume;\n }\n }\n const distance = dx * dx + dy * dy + dz * dz;\n if (distance < nearestDistance) {\n nearest = index;\n nearestDistance = distance;\n }\n }\n return inside >= 0 ? inside : nearest;\n}\n\n/**\n * Builds the component's declared fields.\n *\n * @returns The schema. Built inside a function: module scope holds declarations and immutable\n * constants only (`CONSTITUTION.md` §3.5).\n */\nfunction reflectionProbeSchema(): Schema {\n return defineSchema({\n size: u32(128, {\n min: MIN_SIZE,\n max: MAX_SIZE,\n tooltip: \"Cube face size in pixels, rounded down to a power of two. Larger is sharper and slower to capture.\",\n }),\n refreshMode: enumOf(REFLECTION_PROBE_REFRESH_MODES, \"once\", {\n tooltip:\n \"once: capture when ready and on refresh(); onDemand: only on refresh(); everyFrame: every frame (costly; one probe, desktop high tier only).\",\n }),\n boxProjection: optional(vec3({ x: 10, y: 10, z: 10 }), {\n tooltip:\n \"Full size in metres of the box, centred on the probe, that reflections are projected onto; null for none.\",\n }),\n cullingMask: layerMask([], { tooltip: \"The layers the probe captures; empty captures every layer.\" }),\n near: f32(0.1, { min: 0.001, tooltip: \"Near clip distance of the capture, in metres.\" }),\n far: f32(1000, { min: 0.01, tooltip: \"Far clip distance of the capture, in metres.\" }),\n });\n}\n"],"mappings":";;;;;;AAoHA,IAAM,aAAN,MAAoB;CAClB;CACA;CACA;;CAEA;;CAEA,kBAAqC;CAErC,YAAY,SAA2B,MAAe,UAAmB,OAAe;EACtF,KAAK,UAAU;EACf,KAAK,OAAO;EACZ,KAAK,WAAW;EAChB,KAAK,QAAQ;CACf;AACF;;AAGA,SAAS,iBAAuB,CAEhC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA,IAAa,SAAb,MAAuD;CACrD,eAAyC,CAAC;CAC1C;CACA;CACA,aAAa;CACb,aAAa;CACb,aAAa;;;;;;;CAQb,YAAY,SAA4B;EACtC,KAAK,i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AI,WAAW,iBAAiB;GAC9B,UAAU;GACV,kBAAkB;EACpB;CACF;CACA,OAAO,UAAU,IAAI,SAAS;AAChC;;;;;;;AAQA,SAAS,wBAAgC;CACvC,OAAO,aAAa;EAClB,MAAM,IAAI,KAAK;GACb,KAAK;GACL,KAAK;GACL,SAAS;EACX,CAAC;EACD,aAAa,OAAO,gCAAgC,QAAQ,EAC1D,SACE,+IACJ,CAAC;EACD,eAAe,SAAS,KAAK;GAAE,GAAG;GAAI,GAAG;GAAI,GAAG;EAAG,CAAC,GAAG,EACrD,SACE,4GACJ,CAAC;EACD,aAAa,UAAU,CAAC,GAAG,EAAE,SAAS,6DAA6D,CAAC;EACpG,MAAM,IAAI,IAAK;GAAE,KAAK;GAAO,SAAS;EAAgD,CAAC;EACvF,KAAK,IAAI,KAAM;GAAE,KAAK;GAAM,SAAS;EAA+C,CAAC;CACvF,CAAC;AACH"}
1
+ {"version":3,"file":"reflection-probe-AS8d4uKv.js","names":[],"sources":["../src/signal/signal.ts","../src/schema/schema.ts","../src/handles/handle.ts","../src/component/internals.ts","../src/component/component.ts","../src/lite/picking.ts","../src/schema/types.ts","../src/schema/field-kinds.ts","../src/render/render-texture.ts","../src/render/reflection-probe.ts"],"sourcesContent":["import { CoreErrorCode } from \"../errors/error-codes.js\";\nimport { IgnifxError } from \"../errors/ignifx-error.js\";\n\n/**\n * A listener attached to a {@link Signal}.\n *\n * @public\n */\nexport type SignalHandler<T> = (value: T) => void;\n\n/**\n * Detaches a handler from a {@link Signal}. Calling it more than once is a no-op.\n *\n * @public\n */\nexport type Disconnect = () => void;\n\n/**\n * Anything whose destruction should take its signal connections with it: an `Entity`, a\n * `Component`, a `SceneInstance`. Connecting with an `owner` is how scripts avoid leaking handlers,\n * and the `ignifx/signal-connect-owner` lint rule requires it inside a `Script`\n * (`docs/architecture/02-scene-graph.md` §8).\n *\n * @public\n */\nexport interface SignalOwner {\n /** Whether the owner has already been destroyed. */\n readonly isDestroyed: boolean;\n /**\n * Emitted once when the owner is destroyed; the signal uses it to detach the handler.\n *\n * @remarks\n * Typed as {@link SignalLike} rather than {@link Signal} so that an owner may expose a precisely\n * typed signal — `Entity.onDestroyed` is a `Signal<Entity>` per\n * `docs/architecture/02-scene-graph.md` §4. `Signal` carries private state, which makes it\n * invariant in `T`; the read-only interface is not, and `connect` is all this contract needs.\n */\n readonly onDestroyed: SignalLike<unknown>;\n}\n\n/**\n * The scheduler that runs deferred deliveries. The core frame loop implements it on the\n * `EndOfFrame` phase; tests can pass a queue that runs callbacks on demand.\n *\n * @public\n */\nexport interface DeferredQueue {\n /**\n * Schedules a callback to run at the next flush point.\n *\n * @param callback - The delivery to run.\n */\n enqueue(callback: () => void): void;\n}\n\n/**\n * Options for {@link Signal.connect}.\n *\n * @public\n */\nexport interface ConnectOptions {\n /** Disconnect the handler after its first delivery. */\n readonly once?: boolean;\n /**\n * Queue the delivery on the signal's {@link DeferredQueue} instead of calling the handler inside\n * `emit` (Godot's `CONNECT_DEFERRED`).\n */\n readonly deferred?: boolean;\n /** Disconnect the handler automatically when this object is destroyed. */\n readonly owner?: SignalOwner;\n}\n\n/**\n * Options for the {@link Signal} constructor, where `T` is the payload the signal emits.\n *\n * @public\n */\nexport interface SignalOptions<T> {\n /** The scheduler used by `deferred` connections. Without it, `deferred: true` throws. */\n readonly deferredQueue?: DeferredQueue;\n /**\n * Where handler exceptions go. When set, every exception is reported here and delivery continues;\n * when absent, the first exception is rethrown as `IGX-0104` once every handler has run. The app\n * passes a reporter that routes to `app.onError`. It must not throw.\n */\n readonly onHandlerError?: (error: unknown, signal: Signal<T>) => void;\n}\n\n/**\n * The read-only half of a {@link Signal}: what a public API exposes when callers may subscribe but\n * must not emit, where `T` is the payload the signal emits.\n *\n * @example\n * ```ts\n * interface Assets {\n * readonly onLoaded: SignalLike<AssetHandle>;\n * }\n * ```\n *\n * @public\n */\nexport interface SignalLike<T = void> {\n /** How many handlers are currently attached. */\n readonly connectionCount: number;\n\n /**\n * Attaches a handler.\n *\n * @param handler - The listener.\n * @param options - `once`, `deferred`, and `owner`.\n * @returns A function that detaches the handler.\n */\n connect(handler: SignalHandler<T>, options?: ConnectOptions): Disconnect;\n}\n\n/** One attached handler. `handler === null` marks the entry dead and awaiting compaction. */\nclass Connection<T> {\n handler: SignalHandler<T> | null;\n readonly once: boolean;\n readonly deferred: boolean;\n /** Index into the owning signal's connection list; kept current by swap-remove. */\n index: number;\n /** Detaches the auto-disconnect handler from `owner.onDestroyed`. */\n ownerDisconnect: Disconnect | null = null;\n\n constructor(handler: SignalHandler<T>, once: boolean, deferred: boolean, index: number) {\n this.handler = handler;\n this.once = once;\n this.deferred = deferred;\n this.index = index;\n }\n}\n\n/** Returned when connecting to a signal on behalf of an already-destroyed owner. */\nfunction noopDisconnect(): void {\n // Nothing was connected, so nothing has to be detached.\n}\n\n/**\n * A typed, synchronous, many-listener event (`docs/architecture/02-scene-graph.md` §8). Signals are\n * the \"signal up\" half of the engine's *call down, signal up* convention: a parent calls methods on\n * the children it owns, a child announces what happened and lets interested parties subscribe.\n *\n * @remarks\n * Delivery guarantees:\n *\n * - Handlers run in connection order, synchronously, inside {@link Signal.emit}.\n * - A handler connected *during* an emit runs on the next emit, never the one in flight.\n * - A handler disconnected during an emit never runs again, including in the emit in flight.\n * - One handler throwing does not stop delivery to the others.\n * - Nothing is allocated per emit on the non-deferred path (coding standards §7).\n *\n * The payload type `T` defaults to `void`, so `signal.emit()` takes no argument.\n *\n * @example\n * ```ts\n * class Health extends Script {\n * readonly onDied = new Signal<Entity>();\n * damage(amount: number): void {\n * this.hp -= amount;\n * if (this.hp <= 0) {\n * this.onDied.emit(this.entity);\n * }\n * }\n * }\n *\n * health.onDied.connect((entity) => this.spawnLoot(entity), { owner: this, once: true });\n * ```\n *\n * @public\n */\nexport class Signal<T = void> implements SignalLike<T> {\n readonly #connections: Connection<T>[] = [];\n readonly #deferredQueue: DeferredQueue | null;\n readonly #onHandlerError: ((error: unknown, signal: Signal<T>) => void) | null;\n #liveCount = 0;\n #deadCount = 0;\n #emitDepth = 0;\n\n /**\n * Creates a signal.\n *\n * @param options - The deferred-delivery scheduler and the handler-error reporter. Both are\n * supplied by the app for engine signals; a signal a script owns usually needs neither.\n */\n constructor(options?: SignalOptions<T>) {\n this.#deferredQueue = options?.deferredQueue ?? null;\n this.#onHandlerError = options?.onHandlerError ?? null;\n }\n\n /**\n * How many handlers are currently attached.\n *\n * @returns The live connection count.\n */\n get connectionCount(): number {\n return this.#liveCount;\n }\n\n /**\n * Attaches a handler.\n *\n * @param handler - The listener.\n * @param options - `once` to detach after the first delivery, `deferred` to queue delivery on the\n * signal's {@link DeferredQueue}, and `owner` to detach when the owner is destroyed.\n * @returns A function that detaches the handler; calling it twice is a no-op.\n * @throws IgnifxError with code `IGX-0103` when `deferred` is requested and the signal was\n * constructed without a {@link DeferredQueue}.\n *\n * @example\n * ```ts\n * const stop = app.events.onSceneLoaded.connect((scene) => this.spawn(scene), { owner: this });\n * stop();\n * ```\n */\n connect(handler: SignalHandler<T>, options?: ConnectOptions): Disconnect {\n const deferred = options?.deferred ?? false;\n if (deferred && this.#deferredQueue === null) {\n throw new IgnifxError(\n CoreErrorCode.deferredSignalWithoutScheduler,\n \"Deferred signal delivery needs a scheduler; construct the signal with a deferred queue.\",\n { hint: \"Engine signals reached through the app already have one; a signal you own does not.\" },\n );\n }\n const owner = options?.owner;\n if (owner !== undefined && owner.isDestroyed) {\n // Connecting on behalf of a destroyed owner is a no-op rather than an error: teardown order\n // between two destroyed objects is not something game code should have to reason about.\n return noopDisconnect;\n }\n const connection = new Connection<T>(handler, options?.once ?? false, deferred, this.#connections.length);\n this.#connections.push(connection);\n this.#liveCount += 1;\n if (owner !== undefined) {\n connection.ownerDisconnect = owner.onDestroyed.connect(() => {\n this.#remove(connection);\n });\n }\n return () => {\n this.#remove(connection);\n };\n }\n\n /**\n * Delivers a value to every attached handler, in connection order.\n *\n * @param value - The payload. Omitted for `Signal<void>`.\n * @throws IgnifxError with code `IGX-0104` wrapping the first handler exception, when the signal\n * was constructed without an `onHandlerError` reporter.\n */\n emit(value: T): void {\n const connections = this.#connections;\n // Snapshotting the length — not the array — is what makes a handler connected during this emit\n // run on the *next* emit, with no per-emit allocation.\n const count = connections.length;\n if (count === 0) {\n return;\n }\n this.#emitDepth += 1;\n let firstError: unknown = null;\n let errorCount = 0;\n for (let index = 0; index < count; index += 1) {\n const connection = connections[index];\n if (connection === undefined) {\n continue;\n }\n const handler = connection.handler;\n if (handler === null) {\n continue;\n }\n const isOnce = connection.once;\n if (isOnce) {\n this.#remove(connection);\n }\n try {\n if (connection.deferred && this.#deferredQueue !== null) {\n this.#deferredQueue.enqueue(() => {\n // A `once` connection is already detached; any other must still be attached at flush\n // time, so disconnecting before the queue drains cancels the delivery.\n if (isOnce || connection.handler !== null) {\n handler(value);\n }\n });\n } else {\n handler(value);\n }\n } catch (error) {\n errorCount += 1;\n if (this.#onHandlerError === null) {\n if (errorCount === 1) {\n firstError = error;\n }\n } else {\n this.#onHandlerError(error, this);\n }\n }\n }\n this.#emitDepth -= 1;\n if (this.#emitDepth === 0 && this.#deadCount > 0) {\n this.#compact();\n }\n if (errorCount > 0 && this.#onHandlerError === null) {\n throw new IgnifxError(CoreErrorCode.signalHandlerThrew, \"A signal handler threw.\", {\n cause: firstError,\n context: { errorCount, handlerCount: count },\n hint: \"Handle the failure in the handler, or give the signal an onHandlerError reporter.\",\n });\n }\n }\n\n /**\n * Detaches the first connection made with this handler. Detaching a handler that is not connected\n * is a no-op.\n *\n * @param handler - The listener to detach.\n */\n disconnect(handler: SignalHandler<T>): void {\n for (const connection of this.#connections) {\n if (connection.handler === handler) {\n this.#remove(connection);\n return;\n }\n }\n }\n\n /** Detaches every handler, including the auto-disconnect hooks held on owners. */\n clear(): void {\n // Iterating a copy keeps `#remove`'s swap-remove from shifting entries out from under the loop.\n // `clear` is a teardown operation, never a per-frame one, so the copy costs nothing that matters.\n for (const connection of this.#connections.slice()) {\n this.#remove(connection);\n }\n }\n\n /**\n * Marks a connection dead and, when no emit is in flight, removes it by swapping the last entry\n * into its slot. During an emit the entry is left as a tombstone so indices stay stable, and the\n * outermost emit compacts.\n *\n * @param connection - The connection to detach.\n */\n #remove(connection: Connection<T>): void {\n if (connection.handler === null) {\n return;\n }\n connection.handler = null;\n this.#liveCount -= 1;\n const ownerDisconnect = connection.ownerDisconnect;\n if (ownerDisconnect !== null) {\n connection.ownerDisconnect = null;\n ownerDisconnect();\n }\n if (this.#emitDepth > 0) {\n this.#deadCount += 1;\n return;\n }\n this.#swapRemove(connection.index);\n }\n\n /** Removes every tombstone left behind by an emit. */\n #compact(): void {\n const connections = this.#connections;\n for (let index = connections.length - 1; index >= 0; index -= 1) {\n const connection = connections[index];\n if (connection !== undefined && connection.handler === null) {\n this.#swapRemove(index);\n }\n }\n this.#deadCount = 0;\n }\n\n /**\n * Removes the entry at an index by moving the last entry into its place.\n *\n * @param index - The slot to vacate.\n */\n #swapRemove(index: number): void {\n const connections = this.#connections;\n const last = connections.length - 1;\n if (index !== last) {\n const moved = connections[last];\n if (moved !== undefined) {\n connections[index] = moved;\n moved.index = index;\n }\n }\n connections.pop();\n }\n}\n","import { SchemaIssueCode, throwSchemaError } from \"./issues.js\";\nimport type { FieldsOf, PartialFieldsOf, Schema } from \"./types.js\";\n\n/**\n * Property names a schema may not use, because `Component`/`Script` already define them\n * (`docs/architecture/03-scripting-and-components.md` §1 and §2). A schema field becomes a property\n * on the generated base class, so reusing one of these would shadow engine state and break the\n * lifecycle silently.\n *\n * @internal\n */\n// A module-scope `new Set(...)` allocates at import time, which `ignifx/no-module-side-effects` and\n// `CONSTITUTION.md` §3.5 forbid; schemas are declared once per class, so a linear scan is not hot.\n// oxlint-disable-next-line unicorn/prefer-set-has\nconst RESERVED_FIELD_NAMES: readonly string[] = [\n \"uid\",\n \"entity\",\n \"transform\",\n \"world\",\n \"app\",\n \"enabled\",\n \"isDestroyed\",\n \"isEnabledInHierarchy\",\n \"destroy\",\n \"getComponent\",\n \"requireComponent\",\n \"awake\",\n \"onEnable\",\n \"start\",\n \"fixedUpdate\",\n \"update\",\n \"lateUpdate\",\n \"onDisable\",\n \"onDestroy\",\n \"startCoroutine\",\n \"stopCoroutine\",\n \"stopAllCoroutines\",\n];\n\n/**\n * A field name must read like a plain JavaScript identifier so that `this.<name>` works without\n * bracket syntax, and must not start with `_`, which the standards reserve for adapter-internal\n * mirrors (coding standards §5.1).\n *\n * @internal\n */\nconst FIELD_NAME_PATTERN = /^[A-Za-z][A-Za-z0-9]*$/u;\n\n/**\n * Refuses a field name that every plain object already has through `Object.prototype`:\n * `constructor`, `toString`, `valueOf`, `hasOwnProperty`, `__proto__` and the rest. Encoders,\n * decoders, and the inspector walk a schema and read each field as `values[name]`, so a value that\n * omits such a field yields the inherited member instead of `undefined`; and they write it as\n * `out[name] = …`, which for `__proto__` replaces the object's prototype instead of adding a key.\n * Refusing the name once, where the schema is declared, keeps every one of those sites correct.\n * `prototype` is not inherited by plain objects, so it stays a legal name.\n *\n * A literal `{ __proto__: f32(1) }` (not computed) never makes a key at all: it sets the object's\n * prototype, so the field would vanish without a word. The fields object must therefore be a plain\n * object (its prototype `Object.prototype`, or `null`).\n *\n * @param fields - The field definitions being declared.\n * @param where - What declares them, for the message: `\"schema\"` or `\"record\"`.\n * @throws IgnifxError with code `IGX-0607` when a name is an `Object.prototype` member, or the\n * fields object is not a plain object.\n *\n * @internal\n */\nexport function assertNoInheritedFieldNames(fields: Schema, where: string): void {\n const prototype: unknown = Object.getPrototypeOf(fields);\n if (prototype !== Object.prototype && prototype !== null) {\n throwSchemaError(\n SchemaIssueCode.unknownField,\n `${where} fields are not a plain object, so a field is hidden in its prototype; a literal ` +\n `\"__proto__: …\" key sets the prototype instead of declaring a field. Rename the field.`,\n );\n }\n for (const name of Object.keys(fields)) {\n if (Object.hasOwn(Object.prototype, name)) {\n throwSchemaError(\n SchemaIssueCode.unknownField,\n `${where} field \"${name}\" names a member every object inherits (Object.prototype.${name}); rename the field.`,\n );\n }\n }\n}\n\n/**\n * Rewrites a JavaScript value into a mutable string-keyed view. Schema-shaped objects are always\n * plain records built by this module, so the assertion holds by construction; it exists because a\n * mapped type such as `FieldsOf<S>` cannot be indexed generically (coding standards §5.2 permits\n * assertions at boundaries like this one, with the invariant stated).\n *\n * @param value - The object to view.\n * @returns The same object, typed as a mutable record.\n *\n * @internal\n */\nfunction mutableView(value: unknown): Record<string, unknown> {\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- invariant stated above.\n return value as Record<string, unknown>;\n}\n\n/**\n * Rewrites a plain record into the field object a schema describes. Safe because `createDefaults`\n * fills exactly the schema's keys with values built by that key's own field definition.\n *\n * @param value - The record to view.\n * @returns The same object, typed as the schema's field object.\n *\n * @internal\n */\nfunction fieldsView<S extends Schema>(value: Record<string, unknown>): FieldsOf<S> {\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- invariant stated above.\n return value as FieldsOf<S>;\n}\n\n/**\n * Declares a component's serialized fields. The helper is an identity function at runtime — it\n * returns the object it was given — but it checks every field name and, because it is generic,\n * preserves the exact literal type of the schema so `FieldsOf` can project it.\n *\n * `Script.define` and `Component.define` call this before they build a base class.\n *\n * @param fields - The field definitions, keyed by the property name they become.\n * @returns The same object, with its precise type preserved.\n * @throws IgnifxError with code `IGX-0607` when a field name is not identifier-like, starts with\n * `_`, collides with a `Component`/`Script` member such as `enabled` or `update`, or names an\n * `Object.prototype` member such as `constructor` or `toString`, or when `fields` is not a plain\n * object (a literal `__proto__: …` key sets its prototype rather than declaring a field).\n *\n * @example\n * ```ts\n * const moverSchema = defineSchema({\n * speed: f32(5, { min: 0, max: 50 }),\n * waypoints: array(vec3()),\n * });\n * ```\n *\n * @public\n */\nexport function defineSchema<S extends Schema>(fields: S): S {\n assertNoInheritedFieldNames(fields, \"schema\");\n for (const name of Object.keys(fields)) {\n if (!FIELD_NAME_PATTERN.test(name)) {\n throwSchemaError(\n SchemaIssueCode.unknownField,\n `schema field \"${name}\" is not a valid field name: use a letter followed by letters or digits, and do not start with \"_\".`,\n );\n }\n if (RESERVED_FIELD_NAMES.includes(name)) {\n throwSchemaError(\n SchemaIssueCode.unknownField,\n `schema field \"${name}\" collides with a Component or Script member; rename the field.`,\n );\n }\n }\n return fields;\n}\n\n/**\n * Builds the initial field object for a schema. Every value is freshly allocated by its field's\n * own `createDefault`, so two components declared from the same schema never share a mutable\n * default such as a `vec3` or an `array`.\n *\n * @param schema - The schema to instantiate.\n * @returns A new object holding one default per declared field.\n *\n * @example\n * ```ts\n * const a = createDefaults(moverSchema);\n * const b = createDefaults(moverSchema);\n * a.offset === b.offset; // false — each call allocates\n * ```\n *\n * @public\n */\nexport function createDefaults<S extends Schema>(schema: S): FieldsOf<S> {\n const defaults: Record<string, unknown> = {};\n for (const [name, field] of Object.entries(schema)) {\n defaults[name] = field.createDefault();\n }\n return fieldsView<S>(defaults);\n}\n\n/**\n * Overwrites defaults with caller-supplied values. Only names the schema declares are copied, and\n * a value of `undefined` leaves the default in place — matching the loader's rule that omitted\n * props take schema defaults (`docs/architecture/06-serialization-and-scene-format.md` §2).\n *\n * @param target - The field object to write into, normally the result of `createDefaults`.\n * @param schema - The schema that says which names are legal.\n * @param init - The values to apply.\n * @returns The same `target` object, for chaining.\n *\n * @example\n * ```ts\n * const fields = applyInit(createDefaults(moverSchema), moverSchema, { speed: 12 });\n * ```\n *\n * @public\n */\nexport function applyInit<S extends Schema>(target: FieldsOf<S>, schema: S, init: PartialFieldsOf<S>): FieldsOf<S> {\n const writable = mutableView(target);\n const supplied = mutableView(init);\n for (const name of Object.keys(schema)) {\n const value = supplied[name];\n if (value !== undefined) {\n writable[name] = value;\n }\n }\n return target;\n}\n","/**\n * Dense runtime identity (`docs/architecture/00-overview.md` §5). A handle is a plain number so it\n * costs nothing to store, pass, or put in a typed array, and it is branded so that an entity handle\n * and a component handle can never be confused at compile time.\n */\n\n/**\n * The dense runtime id of an entity. Valid until the entity is destroyed; a handle that outlives\n * its entity resolves to `null` through `world.getEntityByHandle` rather than to whatever object\n * recycled the slot.\n *\n * @remarks\n * The `__brand` property exists only in the type system — a handle is a `number` at runtime — so a\n * handle can be stored in a `Float64Array` or written into Lite's node metadata unchanged.\n *\n * @example\n * ```ts\n * const handle: EntityHandle = entity.handle;\n * world.getEntityByHandle(handle)?.destroy();\n * ```\n *\n * @public\n */\nexport type EntityHandle = number & { readonly __brand: \"EntityHandle\" };\n\n/**\n * The dense runtime id of a component, with the same lifetime rules as {@link EntityHandle}.\n *\n * @public\n */\nexport type ComponentHandle = number & { readonly __brand: \"ComponentHandle\" };\n\n/**\n * The handle value that never resolves. Allocated handles always carry a generation of at least\n * one, so zero is unreachable and doubles as \"no handle\".\n *\n * @public\n */\nexport const INVALID_HANDLE = 0;\n\n/**\n * Brands a raw allocator handle as an entity handle.\n *\n * @param value - The number {@link HandleAllocator.allocate} returned.\n * @returns The same number, typed as an entity handle.\n *\n * @internal\n */\nexport function toEntityHandle(value: number): EntityHandle {\n // The brand is a compile-time marker with no runtime\n // representation, so branding is the identity function and this is the one place it happens.\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion\n return value as EntityHandle;\n}\n\n/**\n * Brands a raw allocator handle as a component handle.\n *\n * @param value - The number {@link HandleAllocator.allocate} returned.\n * @returns The same number, typed as a component handle.\n *\n * @internal\n */\nexport function toComponentHandle(value: number): ComponentHandle {\n // Boundary assertion (coding standards §5.2); see `toEntityHandle`.\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion\n return value as ComponentHandle;\n}\n","import { toComponentHandle, type ComponentHandle } from \"../handles/handle.js\";\nimport type { ComponentClassInfo } from \"./component-registry.js\";\nimport type { Component } from \"./component.js\";\nimport type { Entity } from \"../entity/entity.js\";\nimport type { Signal } from \"../signal/signal.js\";\n\n/**\n * The engine-owned state of a component, kept off the public type.\n *\n * @remarks\n * Components are constructed with `new Type()` and only *then* handed their entity, uid, and\n * handle, so the state cannot live in constructor parameters. It lives behind a module symbol\n * instead: the property is unreachable by name, invisible to `Object.keys`, and impossible to\n * collide with a schema field — while staying fully typed, with no `any` and no assertion\n * (coding standards §5.2).\n */\n\n/**\n * The key the engine state hangs off. Exported so that `Entity`, the lifecycle queue, and the world\n * can reach it; unreachable from game code, which has no way to name the symbol.\n *\n * @internal\n */\nexport const COMPONENT_INTERNALS: unique symbol = Symbol(\"ignifx.component.internals\");\n\n/**\n * The engine-owned state of one component.\n *\n * @internal\n */\nexport interface ComponentInternals {\n /** The owning entity, or `null` between construction and attachment. */\n entity: Entity | null;\n /** The stable ULID, assigned at attachment. */\n uid: string;\n /** The dense runtime handle, assigned at attachment. */\n handle: ComponentHandle;\n /** What the registry worked out about this component's class, assigned at attachment. */\n info: ComponentClassInfo | null;\n /** Monotonic creation serial; the tie-breaker for `start` and dispatch ordering. */\n serial: number;\n /** The component's own enabled flag. */\n enabled: boolean;\n /** `true` between the `onEnable` that ran and the `onDisable` that has not yet. */\n isEnabledNow: boolean;\n /** `true` while an enable transition is waiting for lifecycle flush A. */\n isEnableQueued: boolean;\n /** `true` while a `start` is waiting for lifecycle flush B. */\n isStartQueued: boolean;\n /** `true` once `awake` has run. Never runs twice. */\n hasAwoken: boolean;\n /** `true` once `start` has run. Never runs twice, across any number of enable cycles. */\n hasStarted: boolean;\n /** `true` from the moment `destroy()` is called, long before the destroy flush. */\n isDestroyed: boolean;\n /** `true` once the destroy flush has finished with this component. */\n isReleased: boolean;\n /** `true` while the component sits in the destroy queue, so it is queued at most once. */\n isDestroyQueued: boolean;\n /** Index of this component in each of its class's per-type registry buckets. */\n storeSlots: number[];\n /** Lazily created; `null` until something connects to it. */\n onDestroyed: Signal<Component> | null;\n}\n\n/**\n * Reads a component's engine-owned state.\n *\n * @param component - The component.\n * @returns Its internal state.\n *\n * @internal\n */\nexport function componentInternals(component: Component): ComponentInternals {\n return component[COMPONENT_INTERNALS];\n}\n\n/**\n * Builds the initial engine state of a freshly constructed, not yet attached component.\n *\n * @returns The state, with no entity and no identity yet.\n *\n * @internal\n */\nexport function createComponentInternals(): ComponentInternals {\n return {\n entity: null,\n uid: \"\",\n handle: toComponentHandle(0),\n info: null,\n serial: 0,\n enabled: true,\n isEnabledNow: false,\n isEnableQueued: false,\n isStartQueued: false,\n hasAwoken: false,\n hasStarted: false,\n isDestroyed: false,\n isReleased: false,\n isDestroyQueued: false,\n storeSlots: [],\n onDestroyed: null,\n };\n}\n","import { CoreErrorCode } from \"../errors/error-codes.js\";\nimport { IgnifxError } from \"../errors/ignifx-error.js\";\nimport { createDefaults, defineSchema } from \"../schema/schema.js\";\nimport { Signal } from \"../signal/signal.js\";\nimport { COMPONENT_INTERNALS, componentInternals, createComponentInternals } from \"./internals.js\";\nimport type { ComponentType } from \"./component-type.js\";\nimport type { ComponentInternals } from \"./internals.js\";\nimport type { App } from \"../app/types.js\";\nimport type { Entity } from \"../entity/entity.js\";\nimport type { ComponentHandle } from \"../handles/handle.js\";\nimport type { FieldsOf, Schema } from \"../schema/types.js\";\nimport type { SignalOwner } from \"../signal/signal.js\";\nimport type { Transform } from \"../transform/transform.js\";\nimport type { World } from \"../world/world.js\";\n\n/**\n * Typed data and behaviour attached to an entity\n * (`docs/architecture/03-scripting-and-components.md` §1). Engine-owned components\n * (`MeshRenderer`, `Rigidbody`, `AudioSource`) are plain `Component`s driven by systems; game\n * behaviour extends `Script`, which adds the frame lifecycle.\n *\n * @remarks\n * A component class must have a no-argument constructor: the engine constructs it, then assigns\n * `entity`, `uid`, and `handle`, then applies schema defaults and the `init` object, then calls\n * `onAttach`. Reading `this.entity` from a constructor therefore throws `IGX-0206`; cache lookups\n * in `onAttach` or `awake` instead.\n *\n * **Where the statics are declared.** `typeId`, `schema`, `requires`, and `allowMultiple` are not\n * members of this class. Declaring them here would make every `static typeId = \"mygame/Mover\"` an\n * override and force the `override` keyword on it under `noImplicitOverride` (coding standards §3)\n * — the same reasoning that keeps the callbacks on {@link ComponentHooks}. The shape lives on\n * {@link ComponentStatics} instead, and `ComponentRegistry` reads it once per class and supplies\n * the defaults (`allowMultiple` is `true` when the class declares nothing).\n *\n * @example\n * ```ts\n * class Health extends Component.define({ maximum: f32(100) }) {\n * static typeId = \"mygame/Health\";\n * current = 0;\n * onAttach(): void {\n * this.current = this.maximum;\n * }\n * }\n * ```\n *\n * @public\n */\n// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging -- the merged interface below declares one engine-owned property that the constructor always assigns.\nexport abstract class Component implements SignalOwner {\n /** Creates a component. The engine constructs components; game code never calls `new`. */\n constructor() {\n this[COMPONENT_INTERNALS] = createComponentInternals();\n }\n\n /**\n * Declares a component's serialized fields and returns the base class to extend (ADR-0004,\n * `docs/architecture/03-scripting-and-components.md` §3). The returned class exposes every field\n * as a typed instance property, applies the defaults in its constructor, and carries the schema\n * for the serializer, the inspector, and the docs harness.\n *\n * @typeParam S - The schema being declared.\n * @param schema - The field definitions, keyed by the property name they become.\n * @returns An abstract class to extend.\n * @throws IgnifxError with code `IGX-0607` when a field name is not identifier-like, collides\n * with a `Component`/`Script` member, or names an `Object.prototype` member such as `constructor`.\n *\n * @example\n * ```ts\n * class Spinner extends Component.define({\n * degreesPerSecond: f32(90, { min: -360, max: 360 }),\n * axis: vec3({ x: 0, y: 1, z: 0 }),\n * }) {\n * static typeId = \"mygame/Spinner\";\n * }\n * ```\n */\n static define<const S extends Schema>(schema: S): ComponentDefinition<S> {\n const fields = defineSchema(schema);\n abstract class Defined extends Component {\n static schema: Schema = fields;\n\n constructor() {\n super();\n Object.assign(this, createDefaults(fields));\n }\n }\n // Boundary assertion (coding standards §5.2). The invariant: `Defined`'s constructor assigns\n // exactly the schema's keys with values built by each field's own `createDefault`, so an\n // instance really does have `FieldsOf<S>`. TypeScript cannot express \"this class gains the\n // properties of a value known only at run time\", so the shape is asserted once, here.\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion\n return Defined as unknown as ComponentDefinition<S>;\n }\n\n /**\n * The stable ULID; the key files use to reference this component.\n *\n * @returns The identifier.\n */\n get uid(): string {\n return this.#attached().uid;\n }\n\n /**\n * The dense runtime handle; invalid after destruction.\n *\n * @returns The handle.\n */\n get handle(): ComponentHandle {\n return this.#attached().handle;\n }\n\n /**\n * The entity this component is attached to.\n *\n * @returns The owning entity.\n */\n get entity(): Entity {\n const entity = this.#attached().entity;\n if (entity === null) {\n throw notAttached(this);\n }\n return entity;\n }\n\n /**\n * The entity's transform — sugar for `this.entity.transform`, the most-used lookup there is.\n *\n * @returns The entity's transform.\n */\n get transform(): Transform {\n return this.entity.transform;\n }\n\n /**\n * The world the entity belongs to.\n *\n * @returns The world.\n */\n get world(): World {\n return this.entity.world;\n }\n\n /**\n * The app that owns the world.\n *\n * @returns The app.\n */\n get app(): App {\n return this.entity.world.app;\n }\n\n /**\n * The component's own enabled flag; `true` by default. Setting it runs the enable or disable\n * transition (`docs/architecture/01-lifecycle-and-time.md` §6): `onDisable` runs immediately,\n * `awake`/`onEnable` run in the next lifecycle flush — or immediately and nested when the change\n * happens inside a callback.\n *\n * @returns `true` when the component's own flag is set.\n */\n get enabled(): boolean {\n return componentInternals(this).enabled;\n }\n\n set enabled(value: boolean) {\n const internals = componentInternals(this);\n if (internals.enabled === value) {\n return;\n }\n if (internals.isDestroyed) {\n throw new IgnifxError(CoreErrorCode.mutationAfterDestroy, \"This component has been destroyed.\", {\n context: { target: \"component\", uid: internals.uid, operation: \"enabled\" },\n });\n }\n internals.enabled = value;\n const entity = internals.entity;\n if (entity !== null) {\n entity.world.lifecycle.refreshEnabled(this);\n }\n }\n\n /**\n * `true` when the component's own flag is set **and** its entity is active in the hierarchy.\n *\n * @returns `true` when the component is effectively enabled.\n */\n get isEnabledInHierarchy(): boolean {\n const internals = componentInternals(this);\n const entity = internals.entity;\n return internals.enabled && !internals.isDestroyed && entity !== null && entity.activeInHierarchy;\n }\n\n /**\n * `true` from the moment `destroy()` is called, long before the destroy flush runs.\n *\n * @returns `true` once the component has been queued for destruction.\n */\n get isDestroyed(): boolean {\n return componentInternals(this).isDestroyed;\n }\n\n /**\n * Emitted once when the component is destroyed, in the destroy flush. Connecting with\n * `{ owner: this }` elsewhere uses it to detach handlers automatically\n * (`docs/architecture/02-scene-graph.md` §8).\n *\n * @returns The signal. It is created on first access, so a component nobody listens to allocates\n * nothing.\n */\n get onDestroyed(): Signal<Component> {\n const internals = componentInternals(this);\n internals.onDestroyed ??= new Signal<Component>();\n return internals.onDestroyed;\n }\n\n /**\n * Queues this component for destruction. It stays usable until the destroy flush of the current\n * frame, but reports `isDestroyed === true` immediately\n * (`docs/architecture/01-lifecycle-and-time.md` §6). Calling it twice is a no-op.\n */\n destroy(): void {\n const internals = componentInternals(this);\n const entity = internals.entity;\n if (entity === null) {\n internals.isDestroyed = true;\n return;\n }\n entity.removeComponent(this);\n }\n\n /**\n * Finds another component on the same entity — sugar for `this.entity.getComponent`.\n *\n * @typeParam T - The component type to look for.\n * @param type - The component class; matching is by class identity **and** inheritance.\n * @returns The first match in attach order, or `null`.\n */\n getComponent<T extends Component>(type: ComponentType<T>): T | null {\n return this.entity.getComponent(type);\n }\n\n /**\n * Finds another component on the same entity, requiring it to be there — the supported way to\n * link components (`docs/architecture/03-scripting-and-components.md` §8).\n *\n * @typeParam T - The component type to look for.\n * @param type - The component class.\n * @returns The first match in attach order.\n * @throws IgnifxError with code `IGX-0201` when the entity has no such component.\n */\n requireComponent<T extends Component>(type: ComponentType<T>): T {\n return this.entity.requireComponent(type);\n }\n\n /**\n * The engine state, with the \"attached\" invariant checked once.\n *\n * @returns The internals.\n */\n #attached(): ComponentInternals {\n const internals = componentInternals(this);\n if (internals.entity === null) {\n throw notAttached(this);\n }\n return internals;\n }\n}\n\n/**\n * The engine-owned state of a component, declared through interface merging.\n *\n * @remarks\n * A symbol-keyed *class field* is rejected by `isolatedDeclarations` (coding standards §3), which\n * cannot infer a computed property name; declaring it on the merged interface states the type\n * explicitly and emits cleanly. The property is unreachable from game code, which has no way to\n * name the symbol, and cannot collide with a schema field.\n *\n * @public\n */\n// Merging is deliberate and safe here: the class constructor assigns the one property the\n// interface declares, so it is always initialised. A symbol-keyed class field would be cleaner\n// still, but `isolatedDeclarations` rejects computed property names on classes.\n// oxlint-disable-next-line typescript/no-unsafe-declaration-merging\n// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging -- see the note above\nexport interface Component {\n /**\n * The engine-owned state.\n *\n * @internal\n */\n [COMPONENT_INTERNALS]: ComponentInternals;\n}\n\n/**\n * The optional hooks every component may implement\n * (`docs/architecture/03-scripting-and-components.md` §1).\n *\n * @remarks\n * They are declared here rather than on `Component` for the reason spelled out on\n * `ScriptCallbacks`: a member declared on the base class would force every implementation to carry\n * an `override` modifier under `noImplicitOverride` (coding standards §3). Write\n * `implements ComponentHooks` to have the signatures checked.\n *\n * @public\n */\nexport interface ComponentHooks {\n /**\n * Runs after the component's fields are assigned and before `awake`. It may run while the entity\n * is inactive, so it must not assume the component is enabled.\n */\n onAttach?(): void;\n /** Runs just before the component is removed, after `onDestroy`. */\n onDetach?(): void;\n /**\n * Runs after a tool changed the component's serialized fields from outside it: an editor's\n * inspector or document op, or a hot reload that gave a field its new default. The engine's own\n * loads and a script's assignments do not call it. A component that builds something from its\n * fields (a physics shape, say) rebuilds it here. Not gated in edit mode (ADR-0028).\n *\n * @param fields - The names of the fields that changed.\n */\n onValidate?(fields: readonly string[]): void;\n}\n\n/**\n * The abstract base class `Component.define` returns: a `Component` that also carries every\n * field the schema declares, typed.\n *\n * @typeParam S - The schema the class was defined from.\n *\n * @public\n */\nexport type ComponentDefinition<S extends Schema> = (abstract new () => Component & FieldsOf<S>) & {\n /** The instance shape, so the class satisfies `ComponentType`. */\n readonly prototype: Component & FieldsOf<S>;\n /**\n * The schema the class was defined from, carried as a value on the returned class. The other\n * statics ({@link ComponentStatics}) are deliberately *not* declared here: a subclass must be\n * able to write a plain `static typeId` without the `override` keyword.\n */\n readonly schema: S;\n};\n\n/**\n * Builds the \"used before the engine attached it\" error.\n *\n * @param component - The component that was read too early.\n * @returns The error to throw.\n */\nfunction notAttached(component: Component): IgnifxError {\n return new IgnifxError(\n CoreErrorCode.componentNotAttached,\n `${component.constructor.name} is not attached to an entity yet.`,\n {\n context: { component: component.constructor.name },\n hint: \"The engine assigns entity, uid, and handle after construction; read them in onAttach or awake.\",\n },\n );\n}\n","import { pickMeshesWithRay, pickWithRay } from \"@babylonjs/lite\";\nimport { parentNode, readNodeTag } from \"./node.js\";\nimport type { NodeTag } from \"./node.js\";\nimport type { Mesh, PickingInfo, Ray, RayPickOptions, SceneContext, SceneNode } from \"@babylonjs/lite\";\n\n/**\n * CPU picking half of the Babylon Lite adapter (`docs/architecture/07-rendering.md` §3): the\n * synchronous ray tests behind `world.raycastRender`, and the mapping from a Lite hit back to the\n * ignifx entity that owns the mesh. The GPU picker lives in `./gpu/picker.ts` because it needs a\n * device and a rendered frame.\n *\n * Everything here is `@internal`.\n *\n * ## What Lite's ray pick does (verified against `@babylonjs/lite@1.27.0` `lib/picking/ray-pick.js`)\n *\n * - It walks `scene.meshes`, skips anything with `pickable === false` unless `skipPickableCheck` is\n * set, then applies the caller's `predicate`, and tests the ray against each candidate's local\n * AABB before its triangles.\n * - The triangle test reads `mesh._cpuPositions`, the CPU copy every mesh factory retains\n * (`lib/mesh/mesh-factories.js`, `retainMeshGeometry`). A mesh with no CPU positions — one built\n * from a GPU-only path — is silently skipped, so a CPU pick can miss a mesh a GPU pick would hit.\n * - **Visibility is ignored.** `mesh.visible === false` still occludes and still returns a hit; only\n * `pickable` and the predicate filter. That is Lite's documented behaviour, and it is why the\n * component layer passes a predicate rather than relying on hiding.\n */\n\n/**\n * The result of a Babylon Lite pick — CPU ray or GPU picker — re-exported under an ignifx name so\n * feature code can name the type without importing `@babylonjs/lite` (coding standards §4).\n *\n * @internal\n */\nexport type LitePickInfo = PickingInfo;\n\n/**\n * A ray in the shape Lite expects: three-element tuples that can be rewritten in place, so a\n * picking loop reuses one ray and allocates nothing (coding standards §7).\n *\n * @internal\n */\nexport type PickRay = Ray;\n\n/**\n * Creates a reusable ray, pointing along `+Z` from the origin.\n *\n * @returns A fresh ray. **Allocates** — create one per picking site, not per pick.\n *\n * @example\n * ```ts\n * const ray = createPickRay();\n * screenToRay(camera, x, y, width, height, ray);\n * const hit = raycastScene(scene, ray);\n * ```\n *\n * @internal\n */\nexport function createPickRay(): PickRay {\n return { origin: [0, 0, 0], direction: [0, 0, 1], length: Number.MAX_VALUE };\n}\n\n/**\n * Points a ray at a world-space origin and direction, in place.\n *\n * @param ray - The ray to rewrite.\n * @param originX - The world-space origin x.\n * @param originY - The world-space origin y.\n * @param originZ - The world-space origin z.\n * @param directionX - The direction x; it need not be normalized.\n * @param directionY - The direction y.\n * @param directionZ - The direction z.\n * @param length - How far the ray reaches, in metres.\n *\n * @internal\n */\nexport function setPickRay(\n ray: PickRay,\n originX: number,\n originY: number,\n originZ: number,\n directionX: number,\n directionY: number,\n directionZ: number,\n length: number,\n): void {\n const origin = ray.origin;\n origin[0] = originX;\n origin[1] = originY;\n origin[2] = originZ;\n const magnitude = Math.hypot(directionX, directionY, directionZ);\n const scale = magnitude > 0 ? 1 / magnitude : 0;\n const direction = ray.direction;\n direction[0] = directionX * scale;\n direction[1] = directionY * scale;\n direction[2] = directionZ * scale;\n ray.length = length;\n}\n\n/**\n * Casts a ray against every renderable mesh in a scene, on the CPU.\n *\n * @remarks\n * This is `world.raycastRender`. It is distinct from a physics raycast\n * (`docs/architecture/09-physics.md` §5): it hits render geometry, including meshes that carry no\n * collider.\n *\n * @param scene - The render scene.\n * @param ray - The ray to cast.\n * @param options - An optional mesh predicate.\n * @returns Lite's picking info. Check `hit` before reading anything else. **Allocates** one result\n * object per call — Lite builds it.\n *\n * @internal\n */\nexport function raycastScene(scene: SceneContext, ray: PickRay, options?: RayPickOptions): PickingInfo {\n return pickWithRay(scene, ray, options);\n}\n\n/**\n * Casts a ray against an explicit list of meshes, on the CPU.\n *\n * @param meshes - The meshes to test.\n * @param ray - The ray to cast.\n * @param options - An optional mesh predicate.\n * @returns Lite's picking info.\n *\n * @internal\n */\nexport function raycastMeshes(meshes: Iterable<Mesh>, ray: PickRay, options?: RayPickOptions): PickingInfo {\n return pickMeshesWithRay(meshes, ray, options);\n}\n\n/**\n * Decides whether a mesh may be picked, from the ignifx tag that owns it and the mesh itself.\n *\n * @remarks\n * The tag is the one {@link readOwnerTag} finds, so a glTF mesh inside a `Model` is judged by the\n * model's entity. The mesh is passed only so a caller can compare it by identity against an earlier\n * hit; nothing outside `src/lite/**` reads it.\n *\n * @internal\n */\nexport type PickAccept = (tag: NodeTag | null, mesh: Mesh) => boolean;\n\n/**\n * The ignifx tag that owns a node: its own, or the nearest tagged ancestor's.\n *\n * @remarks\n * A `MeshRenderer` tags the mesh it clones, but a `Model` tags only the cloned glTF root, and the\n * meshes Lite draws are that root's descendants (`render/gpu/model-instance.ts`). Walking up to the\n * nearest tag resolves both, and any other renderable that parents several Lite nodes under one\n * tagged node, to the entity and component that created them (editor spike S0.2 §6.1). The walk\n * stops at the first tag, so an entity parented under a model's bone still owns its own meshes.\n *\n * @param node - The picked node, usually a mesh.\n * @returns The nearest tag, or `null` when no node on the way to the root carries one.\n *\n * @internal\n */\nexport function readOwnerTag(node: SceneNode): NodeTag | null {\n for (let current: SceneNode | null = node; current !== null; current = parentNode(current)) {\n const tag = readNodeTag(current);\n if (tag !== null) {\n return tag;\n }\n }\n return null;\n}\n\n/**\n * Casts a ray against a scene's renderable meshes, considering only the meshes a predicate accepts.\n *\n * @remarks\n * The predicate is stated over the owning *tag* rather than over Lite's `Mesh` so the component\n * layer can filter by entity without naming a Lite type (`CONSTITUTION.md` §3.4). Lite's own\n * `pickable === false` exclusion still runs first.\n *\n * @param scene - The render scene.\n * @param ray - The ray to cast.\n * @param accept - Decides whether a mesh may be picked, from the ignifx tag that owns it.\n * @returns Lite's picking info.\n *\n * @internal\n */\nexport function raycastSceneWhere(scene: SceneContext, ray: PickRay, accept: PickAccept): PickingInfo {\n const options: RayPickOptions = { predicate: (mesh: Mesh): boolean => accept(readOwnerTag(mesh), mesh) };\n return pickWithRay(scene, ray, options);\n}\n\n/**\n * Resolves a hit back to the ignifx entity and component that own the mesh.\n *\n * @param info - A result from {@link raycastScene}, {@link raycastMeshes}, or the GPU picker.\n * @returns The owning tag — the picked mesh's own or its nearest tagged ancestor's, so a glTF mesh\n * inside a `Model` resolves to the model — or `null` when the ray missed or no node on the way to\n * the root is one ignifx created.\n *\n * @internal\n */\nexport function readPickedTag(info: PickingInfo): NodeTag | null {\n const mesh = info.pickedMesh;\n if (mesh === null) {\n return null;\n }\n return readOwnerTag(mesh);\n}\n\n/**\n * The name of the mesh a hit landed on.\n *\n * @param info - A hit.\n * @returns The Lite mesh's name — for a glTF model, the name the file gives the node or primitive —\n * or `\"\"` for a miss or an unnamed mesh.\n *\n * @internal\n */\nexport function readPickedMeshName(info: PickingInfo): string {\n const name: unknown = info.pickedMesh?.name;\n return typeof name === \"string\" ? name : \"\";\n}\n\n/**\n * The identity of one earlier hit, which a pick can be told to look through.\n *\n * @internal\n */\nexport interface PickedIdentity {\n /** The mesh that was hit. */\n readonly mesh: Mesh;\n /** The thin instance that was hit, or `-1` when the mesh has none. */\n readonly thinInstanceIndex: number;\n}\n\n/**\n * Reads the identity of a hit, for a later pick to ignore.\n *\n * @param info - A hit.\n * @returns The mesh and thin instance, or `null` for a miss or a hit on something other than a\n * regular Lite mesh (a Gaussian-splatting mesh, which Lite's `ignore` cannot name).\n *\n * @internal\n */\nexport function readPickedIdentity(info: PickingInfo): PickedIdentity | null {\n const mesh = info.pickedMesh;\n if (mesh === null || !(\"material\" in mesh)) {\n return null;\n }\n return { mesh, thinInstanceIndex: info.thinInstanceIndex };\n}\n","import type { JsonObject, JsonValue } from \"./json.js\";\n\n/**\n * Field kinds supported by component schemas.\n *\n * @public\n */\nexport const FieldKind = {\n /** A 32-bit-ranged floating point number. */\n f32: \"f32\",\n /** A double-precision floating point number. */\n f64: \"f64\",\n /** A signed 32-bit integer. */\n i32: \"i32\",\n /** An unsigned 32-bit integer. */\n u32: \"u32\",\n /** A boolean toggle. */\n bool: \"bool\",\n /** A UTF-8 string. */\n str: \"str\",\n /** A 2D vector. */\n vec2: \"vec2\",\n /** A 3D vector. */\n vec3: \"vec3\",\n /** A 4D vector. */\n vec4: \"vec4\",\n /** A rotation quaternion. */\n quat: \"quat\",\n /** An RGBA color. */\n color: \"color\",\n /** One of a fixed set of string values. */\n enum: \"enum\",\n /** A reference to another entity in the same scene file. */\n entityRef: \"entityRef\",\n /** A reference to a component on an entity in the same scene file. */\n componentRef: \"componentRef\",\n /** A reference to an addressable asset. */\n asset: \"asset\",\n /** A list of values of one kind. */\n array: \"array\",\n /** A fixed group of named sub-fields. */\n record: \"record\",\n /** A string-keyed dictionary of values of one kind. */\n map: \"map\",\n /** A value that may also be `null`. */\n optional: \"optional\",\n /** A set of layer names. */\n layerMask: \"layerMask\",\n /** An animation curve. */\n curve: \"curve\",\n /** A value with a hand-written encoder and decoder. */\n custom: \"custom\",\n} as const;\n\n/**\n * The union of every field kind.\n *\n * @public\n */\nexport type FieldKind = (typeof FieldKind)[keyof typeof FieldKind];\n\n/**\n * Inspector and serializer metadata carried by every field\n * (`docs/architecture/03-scripting-and-components.md` §3,\n * `docs/architecture/06-serialization-and-scene-format.md` §5). Options never change a field's\n * value type; they constrain and present it.\n *\n * @public\n */\nexport interface FieldOptions {\n /** Help text shown next to the field in the inspector. */\n readonly tooltip?: string;\n /** Lowest accepted value for numeric kinds; validation reports `IGX-0606` below it. */\n readonly min?: number;\n /** Highest accepted value for numeric kinds; validation reports `IGX-0606` above it. */\n readonly max?: number;\n /**\n * Increment used by the inspector's drag and spinner controls. A `quat` field is edited as\n * intrinsic XYZ Euler angles, so its step is in degrees.\n */\n readonly step?: number;\n /** Hides the field from the inspector while still serializing it. */\n readonly hidden?: boolean;\n /** Shows the field in the inspector but forbids editing it there. */\n readonly readonly?: boolean;\n /** Name of the inspector group the field is folded into. */\n readonly group?: string;\n /** Excludes the field from saved games and scene files; it always takes its default on load. */\n readonly transient?: boolean;\n}\n\n/**\n * How a component class is named in a schema. A class satisfies it structurally through its\n * `prototype`, so `componentRef(Camera)` infers `Camera` without the class having to implement\n * anything. The optional `typeId` is the namespaced registration id from\n * `docs/architecture/03-scripting-and-components.md` §4 when the class carries one.\n *\n * @typeParam C - The component instance type the token stands for.\n *\n * @public\n */\nexport interface ComponentTypeToken<C> {\n /** The component's namespaced registration id, when it declares one. */\n readonly typeId?: string;\n /** The instance shape the token names. */\n readonly prototype: C;\n}\n\n/**\n * How an asset class is named in a schema. Like {@link ComponentTypeToken}, a class satisfies it\n * structurally; `assetType` supplies the `type` discriminator written into `{ \"$asset\": … }` when\n * the loader cannot infer it from the address extension\n * (`docs/architecture/05-assets-and-loading.md` §2).\n *\n * @typeParam A - The asset value type the token stands for.\n *\n * @public\n */\nexport interface AssetTypeToken<A> {\n /** The asset type name written into files when the extension is ambiguous. */\n readonly assetType?: string;\n /**\n * The instance shape the token names. A class token carries it for free; a plain token for an\n * asset that has no class (a scene, a prefab) leaves it out and fixes `A` through its annotation —\n * see `SceneAssetToken`. Nothing reads it at runtime.\n */\n readonly prototype?: A;\n}\n\n/**\n * A serializable asset reference used by scene tools before an app resolves it.\n * Runtime `asset()` fields hold `AssetHandle<A> | null`; the encoder accepts both forms through\n * their shared address and optional type.\n *\n * @typeParam A - The asset value type this reference points at. It is a compile-time marker only:\n * `assetOf` is never assigned at runtime and is never serialized. It exists so that\n * `AssetRefValue<Texture>` and `AssetRefValue<Mesh>` are different types.\n *\n * @public\n */\nexport interface AssetRefValue<A> {\n /** The address the asset is registered under, for example `models/hero.glb#mesh:Body`. */\n readonly address: string;\n /** The asset type name, when the address alone does not identify it. */\n readonly type?: string;\n /** Compile-time marker for the asset type; never present at runtime. */\n readonly assetOf?: A;\n}\n\n/**\n * One key of an animation curve: time, value, incoming tangent, outgoing tangent\n * (`docs/architecture/06-serialization-and-scene-format.md` §3).\n *\n * @public\n */\nexport type CurveKey = readonly [time: number, value: number, inTangent: number, outTangent: number];\n\n/**\n * The value a `curve()` field holds.\n *\n * @public\n */\nexport interface CurveValue {\n /** The curve's keys, ordered by time. */\n readonly keys: readonly CurveKey[];\n}\n\n/**\n * The hand-written encoder and decoder behind a `custom()` field. The codec owns both the default\n * value and the JSON representation, so `custom` is the escape hatch for value types the built-in\n * kinds cannot express.\n *\n * @typeParam T - The runtime value type.\n *\n * @public\n */\nexport interface CustomFieldCodec<T> {\n /**\n * Builds a fresh default value. It is a factory, not a constant, so two components never share\n * one mutable default object.\n *\n * @returns A newly allocated default value.\n */\n createDefault(): T;\n /**\n * Converts a runtime value into JSON.\n *\n * @param value - The value to serialize.\n * @returns The JSON representation written into the file.\n */\n serialize(value: T): JsonValue;\n /**\n * Rebuilds a runtime value from JSON.\n *\n * @param json - The JSON previously produced by `serialize`.\n * @returns The runtime value.\n */\n deserialize(json: JsonValue): T;\n /** A JSON Schema fragment describing the encoded form, merged into the generated document. */\n readonly jsonSchema?: JsonObject;\n}\n\n/**\n * Kind-specific data for the numeric kinds.\n *\n * @public\n */\nexport interface NumberFieldSpec {\n /** The numeric kind. */\n readonly kind: \"f32\" | \"f64\" | \"i32\" | \"u32\";\n}\n\n/**\n * Kind-specific data for `bool`.\n *\n * @public\n */\nexport interface BoolFieldSpec {\n /** The boolean kind. */\n readonly kind: \"bool\";\n}\n\n/**\n * Kind-specific data for `str`.\n *\n * @public\n */\nexport interface StringFieldSpec {\n /** The string kind. */\n readonly kind: \"str\";\n}\n\n/**\n * Kind-specific data for the vector kinds. `components` says how many numbers the encoded array\n * holds, so encoders do not have to re-derive it from the kind.\n *\n * @public\n */\nexport interface VectorFieldSpec {\n /** The vector kind. */\n readonly kind: \"vec2\" | \"vec3\" | \"vec4\" | \"quat\";\n /** How many components the value has: 2, 3, or 4. */\n readonly components: 2 | 3 | 4;\n}\n\n/**\n * Kind-specific data for `color`.\n *\n * @public\n */\nexport interface ColorFieldSpec {\n /** The color kind. */\n readonly kind: \"color\";\n}\n\n/**\n * Kind-specific data for `enumOf`.\n *\n * @public\n */\nexport interface EnumFieldSpec {\n /** The enumeration kind. */\n readonly kind: \"enum\";\n /** Every accepted string value, in declaration order. */\n readonly values: readonly string[];\n}\n\n/**\n * Kind-specific data for `entityRef`.\n *\n * @public\n */\nexport interface EntityRefFieldSpec {\n /** The entity-reference kind. */\n readonly kind: \"entityRef\";\n}\n\n/**\n * Kind-specific data for `componentRef`.\n *\n * @public\n */\nexport interface ComponentRefFieldSpec {\n /** The component-reference kind. */\n readonly kind: \"componentRef\";\n /** The component class the field may point at. */\n readonly componentType: ComponentTypeToken<unknown>;\n}\n\n/**\n * Kind-specific data for `asset`.\n *\n * @public\n */\nexport interface AssetFieldSpec {\n /** The asset-reference kind. */\n readonly kind: \"asset\";\n /** The asset class the field may point at. */\n readonly assetType: AssetTypeToken<unknown>;\n /** The `type` discriminator written into files, or `null` when the address is unambiguous. */\n readonly typeName: string | null;\n}\n\n/**\n * Kind-specific data for `array`.\n *\n * @public\n */\nexport interface ArrayFieldSpec {\n /** The array kind. */\n readonly kind: \"array\";\n /** The field definition every element follows. */\n readonly item: FieldDefinition<unknown>;\n}\n\n/**\n * Kind-specific data for `record`.\n *\n * @public\n */\nexport interface RecordFieldSpec {\n /** The record kind. */\n readonly kind: \"record\";\n /** The sub-fields, in declaration order. */\n readonly fields: Schema;\n}\n\n/**\n * Kind-specific data for `map`.\n *\n * @public\n */\nexport interface MapFieldSpec {\n /** The map kind. */\n readonly kind: \"map\";\n /** The field definition every entry's value follows. */\n readonly value: FieldDefinition<unknown>;\n}\n\n/**\n * Kind-specific data for `optional`.\n *\n * @public\n */\nexport interface OptionalFieldSpec {\n /** The optional kind. */\n readonly kind: \"optional\";\n /** The field definition a non-`null` value follows. */\n readonly inner: FieldDefinition<unknown>;\n}\n\n/**\n * Kind-specific data for `layerMask`.\n *\n * @public\n */\nexport interface LayerMaskFieldSpec {\n /** The layer-mask kind. */\n readonly kind: \"layerMask\";\n}\n\n/**\n * Kind-specific data for `curve`.\n *\n * @public\n */\nexport interface CurveFieldSpec {\n /** The curve kind. */\n readonly kind: \"curve\";\n}\n\n/**\n * Kind-specific data for `custom`.\n *\n * @public\n */\nexport interface CustomFieldSpec {\n /** The custom kind. */\n readonly kind: \"custom\";\n /** The hand-written codec that owns the value's default and JSON form. */\n readonly codec: CustomFieldCodec<unknown>;\n}\n\n/**\n * The discriminated union of kind-specific field data. Switching on `spec.kind` narrows to the\n * member that carries the extra information that kind needs — the enumeration's values, an array's\n * item definition, a component reference's class token — so no branch has to guess.\n *\n * @public\n */\nexport type FieldSpec =\n | NumberFieldSpec\n | BoolFieldSpec\n | StringFieldSpec\n | VectorFieldSpec\n | ColorFieldSpec\n | EnumFieldSpec\n | EntityRefFieldSpec\n | ComponentRefFieldSpec\n | AssetFieldSpec\n | ArrayFieldSpec\n | RecordFieldSpec\n | MapFieldSpec\n | OptionalFieldSpec\n | LayerMaskFieldSpec\n | CurveFieldSpec\n | CustomFieldSpec;\n\n/**\n * One declared field of a component schema. Field definitions are plain, immutable data built by\n * the constructors in this module; nothing about them is reflective and nothing runs at import\n * time (ADR-0004, `CONSTITUTION.md` §3.5).\n *\n * The type parameter is the field's *runtime* value type, which is what\n * `Script.define({ … })` uses to type the generated properties.\n *\n * @typeParam T - The runtime value type of the field.\n *\n * @example\n * ```ts\n * const speed = f32(5, { min: 0, max: 50, tooltip: \"Units per second\" });\n * speed.kind; // \"f32\"\n * speed.createDefault(); // 5\n * ```\n *\n * @public\n */\nexport interface FieldDefinition<T> {\n /** The field kind, mirroring `spec.kind` for quick reads by tooling and the docs harness. */\n readonly kind: FieldKind;\n /** The kind-specific data, discriminated by `spec.kind`. */\n readonly spec: FieldSpec;\n /** Inspector and serializer metadata. */\n readonly options: FieldOptions;\n /**\n * Builds a fresh default value. Object-valued kinds allocate on every call, so two components\n * never share one mutable default.\n *\n * @returns A newly allocated default value.\n */\n createDefault(): T;\n}\n\n/**\n * A component's declared fields, keyed by property name and ordered by declaration. Declaration\n * order is the canonical key order used when writing files\n * (`docs/architecture/06-serialization-and-scene-format.md` §1).\n *\n * @public\n */\nexport type Schema = Readonly<Record<string, FieldDefinition<unknown>>>;\n\n/**\n * The object type a schema describes: every field name mapped to its runtime value type. This is\n * what gives `this.speed` its `number` type inside a component declared with\n * `Script.define({ speed: f32(5) })`.\n *\n * @typeParam S - The schema to project.\n *\n * @example\n * ```ts\n * const schema = { speed: f32(5), label: str(\"\") };\n * type Fields = FieldsOf<typeof schema>; // { speed: number; label: string }\n * ```\n *\n * @public\n */\nexport type FieldsOf<S extends Schema> = {\n -readonly [K in keyof S]: S[K] extends FieldDefinition<infer T> ? T : never;\n};\n\n/**\n * The field object of a schema with every property optional, and an explicit `undefined` allowed.\n * `exactOptionalPropertyTypes` normally separates \"absent\" from \"present and `undefined`\"; both\n * mean \"take the schema default\" here, so both are accepted (`applyInit`, `encodeProps`).\n *\n * @typeParam S - The schema to project.\n *\n * @public\n */\nexport type PartialFieldsOf<S extends Schema> = {\n [K in keyof FieldsOf<S>]?: FieldsOf<S>[K] | undefined;\n};\n","import { SchemaIssueCode, throwSchemaError } from \"./issues.js\";\nimport { assertNoInheritedFieldNames, createDefaults } from \"./schema.js\";\nimport { FieldKind } from \"./types.js\";\nimport type {\n AssetTypeToken,\n ComponentTypeToken,\n CurveKey,\n CurveValue,\n CustomFieldCodec,\n FieldDefinition,\n FieldOptions,\n FieldSpec,\n FieldsOf,\n Schema,\n} from \"./types.js\";\nimport type { AssetHandle } from \"../assets/types.js\";\nimport type { ColorLike, QuatLike, Vec2Like, Vec3Like, Vec4Like } from \"../math/types.js\";\n\n/**\n * The default a `vec2()` field takes when none is given.\n *\n * @internal\n */\nconst ZERO2: Vec2Like = { x: 0, y: 0 };\n/**\n * The default a `vec3()` field takes when none is given.\n *\n * @internal\n */\nconst ZERO3: Vec3Like = { x: 0, y: 0, z: 0 };\n/**\n * The default a `vec4()` field takes when none is given.\n *\n * @internal\n */\nconst ZERO4: Vec4Like = { x: 0, y: 0, z: 0, w: 0 };\n/**\n * The identity rotation, the default a `quat()` field takes when none is given.\n *\n * @internal\n */\nconst IDENTITY_QUAT: QuatLike = { x: 0, y: 0, z: 0, w: 1 };\n/**\n * Opaque white, the default a `color()` field takes when none is given.\n *\n * @internal\n */\nconst WHITE: ColorLike = { r: 1, g: 1, b: 1, a: 1 };\n/**\n * The default a `curve()` field takes when none is given.\n *\n * @internal\n */\nconst EMPTY_CURVE: CurveValue = { keys: [] };\n/**\n * Matches `#rgb`, `#rgba`, `#rrggbb`, and `#rrggbbaa`.\n *\n * @internal\n */\nconst HEX_COLOR_PATTERN = /^#(?:[0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/u;\n\n/**\n * Assembles a field definition. Centralising construction keeps `kind` and `spec.kind` in step and\n * keeps every field a plain, frozen-by-convention data object.\n *\n * @param spec - The kind-specific data, which also supplies the discriminant.\n * @param options - Inspector and serializer metadata, if any.\n * @param createDefault - Factory for a fresh default value.\n * @returns The field definition.\n *\n * @internal\n */\nfunction field<T>(spec: FieldSpec, options: FieldOptions | undefined, createDefault: () => T): FieldDefinition<T> {\n return { kind: spec.kind, spec, options: options ?? {}, createDefault };\n}\n\n/**\n * Parses a CSS-style hexadecimal color into normalized sRGB channels.\n *\n * @param hex - `#rgb`, `#rgba`, `#rrggbb`, or `#rrggbbaa`.\n * @returns The parsed color with channels in the 0–1 range.\n * @throws A `TypeError` when the string is not one of the accepted forms.\n *\n * @internal\n */\nfunction parseHexColor(hex: string): ColorLike {\n if (!HEX_COLOR_PATTERN.test(hex)) {\n throwSchemaError(\n SchemaIssueCode.typeMismatch,\n `color(\"${hex}\") is not a hexadecimal color; use #rgb, #rgba, #rrggbb, or #rrggbbaa.`,\n );\n }\n const digits = hex.slice(1);\n const short = digits.length <= 4;\n const size = short ? 1 : 2;\n const scale = short ? 15 : 255;\n const channel = (index: number): number => {\n const start = index * size;\n if (start >= digits.length) {\n return 1;\n }\n return Number.parseInt(digits.slice(start, start + size), 16) / scale;\n };\n return { r: channel(0), g: channel(1), b: channel(2), a: channel(3) };\n}\n\n/**\n * Declares a single-precision floating point field.\n *\n * @param defaultValue - The value a new component starts with.\n * @param options - Inspector and serializer metadata.\n * @returns The field definition.\n *\n * @example\n * ```ts\n * speed: f32(5, { min: 0, max: 50, tooltip: \"Units per second\" });\n * ```\n *\n * @public\n */\nexport function f32(defaultValue: number = 0, options?: FieldOptions): FieldDefinition<number> {\n return field({ kind: FieldKind.f32 }, options, () => defaultValue);\n}\n\n/**\n * Declares a double-precision floating point field.\n *\n * @param defaultValue - The value a new component starts with.\n * @param options - Inspector and serializer metadata.\n * @returns The field definition.\n *\n * @public\n */\nexport function f64(defaultValue: number = 0, options?: FieldOptions): FieldDefinition<number> {\n return field({ kind: FieldKind.f64 }, options, () => defaultValue);\n}\n\n/**\n * Declares a signed 32-bit integer field. Validation rejects fractional values and values outside\n * the signed 32-bit range with `IGX-0606`.\n *\n * @param defaultValue - The value a new component starts with.\n * @param options - Inspector and serializer metadata.\n * @returns The field definition.\n *\n * @public\n */\nexport function i32(defaultValue: number = 0, options?: FieldOptions): FieldDefinition<number> {\n return field({ kind: FieldKind.i32 }, options, () => defaultValue);\n}\n\n/**\n * Declares an unsigned 32-bit integer field. Validation rejects fractional and negative values, and\n * values above 4294967295, with `IGX-0606`.\n *\n * @param defaultValue - The value a new component starts with.\n * @param options - Inspector and serializer metadata.\n * @returns The field definition.\n *\n * @public\n */\nexport function u32(defaultValue: number = 0, options?: FieldOptions): FieldDefinition<number> {\n return field({ kind: FieldKind.u32 }, options, () => defaultValue);\n}\n\n/**\n * Declares a boolean field.\n *\n * @param defaultValue - The value a new component starts with.\n * @param options - Inspector and serializer metadata.\n * @returns The field definition.\n *\n * @public\n */\nexport function bool(defaultValue: boolean = false, options?: FieldOptions): FieldDefinition<boolean> {\n return field({ kind: FieldKind.bool }, options, () => defaultValue);\n}\n\n/**\n * Declares a string field.\n *\n * @param defaultValue - The value a new component starts with.\n * @param options - Inspector and serializer metadata.\n * @returns The field definition.\n *\n * @public\n */\nexport function str(defaultValue: string = \"\", options?: FieldOptions): FieldDefinition<string> {\n return field({ kind: FieldKind.str }, options, () => defaultValue);\n}\n\n/**\n * Declares a 2D vector field. The runtime value type is the structural `Vec2Like`, so the engine's\n * `Vec2` class and plain object literals are both accepted.\n *\n * @param defaultValue - The value a new component starts with; defaults to the origin.\n * @param options - Inspector and serializer metadata.\n * @returns The field definition.\n *\n * @public\n */\nexport function vec2(defaultValue: Vec2Like = ZERO2, options?: FieldOptions): FieldDefinition<Vec2Like> {\n const { x, y } = defaultValue;\n return field({ kind: FieldKind.vec2, components: 2 }, options, (): Vec2Like => ({ x, y }));\n}\n\n/**\n * Declares a 3D vector field.\n *\n * @param defaultValue - The value a new component starts with; defaults to the origin.\n * @param options - Inspector and serializer metadata.\n * @returns The field definition.\n *\n * @example\n * ```ts\n * offset: vec3({ x: 0, y: 1, z: 0 });\n * ```\n *\n * @public\n */\nexport function vec3(defaultValue: Vec3Like = ZERO3, options?: FieldOptions): FieldDefinition<Vec3Like> {\n const { x, y, z } = defaultValue;\n return field({ kind: FieldKind.vec3, components: 3 }, options, (): Vec3Like => ({ x, y, z }));\n}\n\n/**\n * Declares a 4D vector field.\n *\n * @param defaultValue - The value a new component starts with; defaults to all zeroes.\n * @param options - Inspector and serializer metadata.\n * @returns The field definition.\n *\n * @public\n */\nexport function vec4(defaultValue: Vec4Like = ZERO4, options?: FieldOptions): FieldDefinition<Vec4Like> {\n const { x, y, z, w } = defaultValue;\n return field({ kind: FieldKind.vec4, components: 4 }, options, (): Vec4Like => ({ x, y, z, w }));\n}\n\n/**\n * Declares a rotation field.\n *\n * @param defaultValue - The value a new component starts with; defaults to the identity rotation.\n * @param options - Inspector and serializer metadata.\n * @returns The field definition.\n *\n * @public\n */\nexport function quat(defaultValue: QuatLike = IDENTITY_QUAT, options?: FieldOptions): FieldDefinition<QuatLike> {\n const { x, y, z, w } = defaultValue;\n return field({ kind: FieldKind.quat, components: 4 }, options, (): QuatLike => ({ x, y, z, w }));\n}\n\n/**\n * Declares an RGBA color field. Channels are sRGB in the 0–1 range, in memory and in files alike:\n * conversion to linear space belongs to the renderer, not the schema\n * (`docs/architecture/06-serialization-and-scene-format.md` §3).\n *\n * @param defaultValue - The starting color, either as channels or as a `#rgb`/`#rgba`/`#rrggbb`/\n * `#rrggbbaa` string; defaults to opaque white.\n * @param options - Inspector and serializer metadata.\n * @returns The field definition.\n * @throws A `TypeError` when a string default is not a valid hexadecimal color.\n *\n * @example\n * ```ts\n * tint: color(\"#ffffff\");\n * ```\n *\n * @public\n */\nexport function color(defaultValue: ColorLike | string = WHITE, options?: FieldOptions): FieldDefinition<ColorLike> {\n const { r, g, b, a } = typeof defaultValue === \"string\" ? parseHexColor(defaultValue) : defaultValue;\n return field({ kind: FieldKind.color }, options, (): ColorLike => ({ r, g, b, a }));\n}\n\n/**\n * Declares a field restricted to a fixed set of string values.\n *\n * @param values - Every accepted value, in the order the inspector should list them.\n * @param defaultValue - The value a new component starts with; `NoInfer` keeps it out of the\n * inference for `T`, so passing a value `values` does not contain is a compile error as well as a\n * runtime one.\n * @param options - Inspector and serializer metadata.\n * @returns The field definition.\n * @throws A `TypeError` when `defaultValue` is not one of `values`.\n *\n * @example\n * ```ts\n * mode: enumOf([\"walk\", \"run\"] as const, \"walk\");\n * ```\n *\n * @public\n */\nexport function enumOf<const T extends string>(\n values: readonly T[],\n defaultValue: NoInfer<T>,\n options?: FieldOptions,\n): FieldDefinition<T> {\n if (!values.includes(defaultValue)) {\n throwSchemaError(\n SchemaIssueCode.outOfRange,\n `enumOf default \"${defaultValue}\" is not one of [${values.join(\", \")}].`,\n );\n }\n return field({ kind: FieldKind.enum, values: [...values] }, options, () => defaultValue);\n}\n\n/**\n * Declares a reference to another entity in the same scene file. The value is `null` until the\n * scene is fully constructed and is nulled again when the target is destroyed\n * (`docs/architecture/03-scripting-and-components.md` §3).\n *\n * The entity type is supplied by the caller because `Entity` lives in the kernel, which is layered\n * above this module.\n *\n * @typeParam E - The entity type the reference resolves to.\n * @param options - Inspector and serializer metadata.\n * @returns The field definition.\n *\n * @example\n * ```ts\n * target: entityRef<Entity>();\n * ```\n *\n * @public\n */\nexport function entityRef<E = unknown>(options?: FieldOptions): FieldDefinition<E | null> {\n return field({ kind: FieldKind.entityRef }, options, (): E | null => null);\n}\n\n/**\n * Declares a reference to a component on an entity in the same scene file.\n *\n * @typeParam C - The component type the reference resolves to, inferred from the class.\n * @param type - The component class the field may point at.\n * @param options - Inspector and serializer metadata.\n * @returns The field definition.\n *\n * @example\n * ```ts\n * follow: componentRef(Camera); // Camera | null\n * ```\n *\n * @public\n */\nexport function componentRef<C>(type: ComponentTypeToken<C>, options?: FieldOptions): FieldDefinition<C | null> {\n return field({ kind: FieldKind.componentRef, componentType: type }, options, (): C | null => null);\n}\n\n/**\n * Declares a reference to an addressable asset. The **runtime** value is the loaded\n * {@link AssetHandle}, not an address: a component's `asset()` fields are resolved before its props\n * are written, so `awake` can already read `this.mesh.value`\n * (`docs/architecture/05-assets-and-loading.md` §3).\n *\n * @remarks\n * Files store the address instead — `{ \"$asset\": \"models/hero.glb\", \"type\"?: \"model\" }`\n * (`06-serialization-and-scene-format.md` §3). Encoding reads `handle.address`; decoding hands that\n * address to the `asset` resolver of the `ReferenceDecoder` the scene loader supplies, which answers\n * with the handle the scene already retains. Two consequences game code sees:\n *\n * - An address the resolver cannot answer decodes to `null` and reports `IGX-0602`; the component\n * keeps working with a missing asset rather than failing the whole scene.\n * - An **in-code** asset — anything from `Assets.register`, which includes `MeshAsset.box(…)` and\n * `createMaterialAsset(app, pbrMaterialDefinition({ … }))` — lives at a `memory:` address that names no file, so serializing a\n * component that holds one writes `null` and reports the loss. Save the asset as a file when it\n * has to survive a round trip.\n *\n * The field does **not** retain the handle: the scene instance that loaded it owns the reference\n * count and releases it on unload.\n *\n * @typeParam A - The asset type the reference points at, inferred from the class.\n * @param type - The asset class the field may point at.\n * @param options - Inspector and serializer metadata.\n * @returns The field definition.\n *\n * @example\n * ```ts\n * class Hero extends Component.define({ clip: asset(AudioClip) }) {\n * static typeId = \"mygame/Hero\";\n * awake(): void {\n * this.clip?.value.play();\n * }\n * }\n * ```\n *\n * @public\n */\nexport function asset<A>(type: AssetTypeToken<A>, options?: FieldOptions): FieldDefinition<AssetHandle<A> | null> {\n const typeName = type.assetType ?? null;\n return field({ kind: FieldKind.asset, assetType: type, typeName }, options, (): AssetHandle<A> | null => null);\n}\n\n/**\n * Declares a list field. The runtime value type is a *mutable* array because game code is expected\n * to push to it (`this.waypoints.push(p)`); the default is copied on every instantiation, shallowly,\n * so element objects supplied as defaults are shared and should be treated as immutable.\n *\n * @typeParam T - The element value type, inferred from `item`.\n * @param item - The field definition every element follows.\n * @param defaultValue - The list a new component starts with; defaults to empty.\n * @param options - Inspector and serializer metadata.\n * @returns The field definition.\n *\n * @example\n * ```ts\n * waypoints: array(vec3()); // Vec3Like[]\n * ```\n *\n * @public\n */\nexport function array<T>(\n item: FieldDefinition<T>,\n defaultValue: readonly T[] = [],\n options?: FieldOptions,\n): FieldDefinition<T[]> {\n const snapshot = [...defaultValue];\n return field({ kind: FieldKind.array, item }, options, (): T[] => [...snapshot]);\n}\n\n/**\n * Declares a fixed group of named sub-fields. Sub-fields are serialized as a nested JSON object in\n * declaration order and validated recursively.\n *\n * @typeParam S - The sub-schema, inferred from `fields`.\n * @param fields - The sub-fields.\n * @param options - Inspector and serializer metadata.\n * @returns The field definition.\n * @throws IgnifxError with code `IGX-0607` when a sub-field name is an `Object.prototype` member\n * such as `__proto__`, `constructor`, or `toString`.\n *\n * @example\n * ```ts\n * stats: record({ hp: i32(10), armor: f32(0) }); // { hp: number; armor: number }\n * ```\n *\n * @public\n */\nexport function record<S extends Schema>(fields: S, options?: FieldOptions): FieldDefinition<FieldsOf<S>> {\n assertNoInheritedFieldNames(fields, \"record\");\n return field({ kind: FieldKind.record, fields }, options, () => createDefaults(fields));\n}\n\n/**\n * Declares a string-keyed dictionary field. Keys are written in lexicographic order so that two\n * saves of the same state are byte-identical\n * (`docs/architecture/06-serialization-and-scene-format.md` §1).\n *\n * @typeParam T - The entry value type, inferred from `value`.\n * @param value - The field definition every entry's value follows.\n * @param options - Inspector and serializer metadata.\n * @returns The field definition.\n *\n * @example\n * ```ts\n * ammo: map(i32(0)); // Record<string, number>\n * ```\n *\n * @public\n */\nexport function map<T>(value: FieldDefinition<T>, options?: FieldOptions): FieldDefinition<Record<string, T>> {\n return field({ kind: FieldKind.map, value }, options, (): Record<string, T> => ({}));\n}\n\n/**\n * Declares a field that may also be `null`, defaulting to `null` (coding standards §5.5: `null` is\n * \"absent value\", `undefined` never reaches a file).\n *\n * @typeParam T - The value type when present, inferred from `inner`.\n * @param inner - The field definition a non-`null` value follows.\n * @param options - Inspector and serializer metadata.\n * @returns The field definition.\n *\n * @example\n * ```ts\n * nickname: optional(str()); // string | null\n * ```\n *\n * @public\n */\nexport function optional<T>(inner: FieldDefinition<T>, options?: FieldOptions): FieldDefinition<T | null> {\n return field({ kind: FieldKind.optional, inner }, options, (): T | null => null);\n}\n\n/**\n * Declares a set of layers. Layers are stored by *name*, not by bit value, so renaming a layer in\n * project settings does not silently repoint existing files\n * (`docs/architecture/06-serialization-and-scene-format.md` §3).\n *\n * The field's value is a read-only array of names. The kernel's `LayerMask` satisfies the same\n * structural shape, so a component may hold either.\n *\n * @param defaultValue - The names a new component starts with; defaults to empty.\n * @param options - Inspector and serializer metadata.\n * @returns The field definition.\n *\n * @example\n * ```ts\n * collidesWith: layerMask([\"Default\", \"Enemy\"]);\n * ```\n *\n * @public\n */\nexport function layerMask(\n defaultValue: readonly string[] = [],\n options?: FieldOptions,\n): FieldDefinition<readonly string[]> {\n const snapshot = [...defaultValue];\n return field({ kind: FieldKind.layerMask }, options, (): readonly string[] => [...snapshot]);\n}\n\n/**\n * Declares an animation curve field.\n *\n * @param defaultValue - The curve a new component starts with; defaults to no keys.\n * @param options - Inspector and serializer metadata.\n * @returns The field definition.\n *\n * @example\n * ```ts\n * falloff: curve({ keys: [[0, 1, 0, 0], [1, 0, 0, 0]] });\n * ```\n *\n * @public\n */\nexport function curve(defaultValue: CurveValue = EMPTY_CURVE, options?: FieldOptions): FieldDefinition<CurveValue> {\n const keys = defaultValue.keys.map((key): CurveKey => [key[0], key[1], key[2], key[3]]);\n return field({ kind: FieldKind.curve }, options, (): CurveValue => ({ keys: [...keys] }));\n}\n\n/**\n * Declares a field whose JSON form is written by hand. Use it for value types the built-in kinds\n * cannot express; the codec owns the default, the encoding, and the generated JSON Schema fragment.\n *\n * @typeParam T - The runtime value type.\n * @param codec - The default factory, `serialize`, `deserialize`, and optional `jsonSchema`.\n * @param options - Inspector and serializer metadata.\n * @returns The field definition.\n *\n * @example\n * ```ts\n * grid: custom({\n * createDefault: () => new Uint8Array(16),\n * serialize: (value) => [...value],\n * deserialize: (json) => Uint8Array.from(Array.isArray(json) ? json.map(Number) : []),\n * jsonSchema: { type: \"array\", items: { type: \"integer\" } },\n * });\n * ```\n *\n * @public\n */\nexport function custom<T>(codec: CustomFieldCodec<T>, options?: FieldOptions): FieldDefinition<T> {\n return field({ kind: FieldKind.custom, codec }, options, () => codec.createDefault());\n}\n","import { CoreErrorCode } from \"../errors/error-codes.js\";\nimport { IgnifxError } from \"../errors/ignifx-error.js\";\nimport type { RenderCapture } from \"./renderer.js\";\nimport type { LiteCamera } from \"../lite/camera.js\";\nimport type { LiteRenderTexture } from \"../lite/gpu/render-texture.js\";\n\n/**\n * The largest side of a render texture, in pixels.\n *\n * @public\n */\nexport const RENDER_TEXTURE_MAX_SIZE = 4096;\n\n/**\n * The Babylon Lite `metadata` key that keeps a render-scene mesh out of every render texture.\n *\n * @remarks\n * A mesh whose `metadata[EDITOR_ONLY_METADATA_KEY]` is `true` draws in the main view but never in\n * a {@link RenderTexture}: an editor's grid or helper that must not show in its game view or\n * thumbnails. Set it on a mesh reached through a `.lite` escape hatch, such as\n * `RenderOverlay.lite.mainScene` (no stability guarantee, `CONSTITUTION.md` §3.4).\n *\n * @beta\n */\nexport const EDITOR_ONLY_METADATA_KEY = \"ignifxEditorOnly\";\n\n/**\n * An offscreen colour target a camera renders into (`docs/architecture/07-rendering.md` §2.11).\n *\n * @remarks\n * Create one with `app.renderer.createRenderTexture(width, height)`. Fill it once with\n * `app.renderer.renderToTexture(camera, texture)`, or every frame by setting a camera's\n * `renderTarget`. It holds a GPU pass of the render scene and its target from the first render\n * on; `dispose()` frees both, and `app.dispose()` disposes every texture still open.\n *\n * @example\n * ```ts\n * const texture = app.renderer.createRenderTexture(256, 256);\n * await app.renderer.renderToTexture(minimapCamera, texture);\n * const pixels = await texture.readPixels();\n * texture.dispose();\n * ```\n *\n * @beta\n */\nexport interface RenderTexture {\n /** The width, in pixels. */\n readonly width: number;\n /** The height, in pixels. */\n readonly height: number;\n /** Whether `dispose()` has run. */\n readonly isDisposed: boolean;\n /**\n * Reads the texture as the last rendered frame left it.\n *\n * @returns Tightly packed RGBA8, top row first. All zeros before anything was rendered into it.\n * @throws IgnifxError with code `IGX-0729` on a headless app or while no render loop runs, and\n * `IGX-0731` once the texture is disposed.\n */\n readPixels(): Promise<RenderCapture>;\n /** Frees the texture's GPU pass and target. Idempotent; a camera rendering into it stops. */\n dispose(): void;\n}\n\n/**\n * What a render texture needs from the renderer that made it.\n *\n * @internal\n */\nexport interface RenderTextureOwner {\n /**\n * Creates the texture's GPU pass, or throws why it cannot.\n *\n * @param width - The width.\n * @param height - The height.\n * @param member - The API member asking, for the error.\n * @returns The pass.\n */\n createPass(width: number, height: number, member: string): Promise<LiteRenderTexture>;\n /**\n * Forgets a disposed texture.\n *\n * @param texture - The texture.\n */\n release(texture: RenderTextureImpl): void;\n}\n\n/** A pending one-frame render. */\ninterface RenderRequest {\n /** The camera to render through. */\n readonly camera: LiteCamera;\n /** Settles the request once its frame has been submitted. */\n readonly resolve: () => void;\n}\n\n/**\n * Checks a render texture's size.\n *\n * @param width - The requested width.\n * @param height - The requested height.\n * @throws IgnifxError with code `IGX-0730` for a side that is not a whole number from 1 to\n * {@link RENDER_TEXTURE_MAX_SIZE}.\n *\n * @internal\n */\nexport function assertRenderTextureSize(width: number, height: number): void {\n const isSide = (side: number): boolean => Number.isSafeInteger(side) && side >= 1 && side <= RENDER_TEXTURE_MAX_SIZE;\n if (!isSide(width) || !isSide(height)) {\n throw new IgnifxError(\n CoreErrorCode.invalidRenderTextureSize,\n `A render texture of ${String(width)}x${String(height)}: each side must be a whole number from 1 to ${String(RENDER_TEXTURE_MAX_SIZE)}.`,\n { context: { member: \"app.renderer.createRenderTexture()\", width, height, max: RENDER_TEXTURE_MAX_SIZE } },\n );\n }\n}\n\n/**\n * What {@link bindFrameCameras} reads of a camera: a structural slice of `Camera`.\n *\n * @internal\n */\nexport interface FrameCameraSource {\n /** The camera's render target, or `null` for the canvas. */\n readonly renderTarget: RenderTexture | null;\n /** The Lite camera, `null` while detached. */\n readonly lite: { readonly camera: LiteCamera | null };\n /** Whether the camera and its entity are enabled. */\n readonly isEnabledInHierarchy: boolean;\n}\n\n/**\n * Tells each live texture which enabled, attached camera renders into it this frame.\n *\n * @param cameras - Every camera in the world, in creation order; the last one per texture wins.\n * @param live - The renderer's live textures; a camera aiming at any other is ignored.\n *\n * @internal\n */\nexport function bindFrameCameras(cameras: readonly FrameCameraSource[], live: ReadonlySet<RenderTextureImpl>): void {\n for (const camera of cameras) {\n const target = camera.renderTarget;\n const lite = camera.lite.camera;\n if (target instanceof RenderTextureImpl && live.has(target) && lite !== null && camera.isEnabledInHierarchy) {\n target.setFrameCamera(lite);\n }\n }\n}\n\n/**\n * The renderer's render texture: the per-frame camera choice and the one-frame requests.\n *\n * @internal\n */\nexport class RenderTextureImpl implements RenderTexture {\n readonly width: number;\n\n readonly height: number;\n\n readonly #owner: RenderTextureOwner;\n\n #pass: LiteRenderTexture | null = null;\n\n #creating: Promise<LiteRenderTexture> | null = null;\n\n /** The camera whose `renderTarget` this is, as the current frame's sync found it. */\n #frameCamera: LiteCamera | null = null;\n\n readonly #requests: RenderRequest[] = [];\n\n #isDisposed = false;\n\n /**\n * Creates the texture; its GPU pass is created on first use.\n *\n * @param owner - The renderer.\n * @param width - The checked width.\n * @param height - The checked height.\n */\n constructor(owner: RenderTextureOwner, width: number, height: number) {\n this.#owner = owner;\n this.width = width;\n this.height = height;\n }\n\n get isDisposed(): boolean {\n return this.#isDisposed;\n }\n\n /**\n * Resolves the texture's GPU pass, creating it once.\n *\n * @param member - The API member asking, for the error.\n * @returns The pass.\n */\n async pass(member: string): Promise<LiteRenderTexture> {\n this.assertUsable(member);\n this.#creating ??= this.#owner.createPass(this.width, this.height, member).then(\n (pass) => {\n if (this.#isDisposed) {\n pass.dispose();\n } else {\n this.#pass = pass;\n }\n return pass;\n },\n (error: unknown) => {\n this.#creating = null;\n throw error;\n },\n );\n const pass = await this.#creating;\n this.assertUsable(member);\n return pass;\n }\n\n /**\n * Queues a render through a camera on the next frame.\n *\n * @param camera - The Lite camera.\n * @returns A promise that settles once that frame has been submitted.\n */\n request(camera: LiteCamera): Promise<void> {\n return new Promise((resolve) => {\n this.#requests.push({ camera, resolve });\n });\n }\n\n /**\n * Notes the camera that renders into this texture every frame. The render sync system calls it\n * for every enabled camera whose `renderTarget` this is, before {@link RenderTextureImpl.flush}.\n *\n * @param camera - The Lite camera.\n */\n setFrameCamera(camera: LiteCamera): void {\n this.#frameCamera = camera;\n if (this.#pass === null && this.#creating === null) {\n // The first frame only starts the pass; a failure leaves it for the next frame to retry.\n this.pass(\"Camera.renderTarget\").catch(() => null);\n }\n }\n\n /**\n * Points the pass at this frame's camera: the oldest request's, else the `renderTarget` one's,\n * else none. Requests for that camera settle once the frame is submitted.\n */\n flush(): void {\n const pass = this.#pass;\n const requested = this.#requests[0]?.camera ?? null;\n const camera = requested ?? this.#frameCamera;\n this.#frameCamera = null;\n if (pass === null) {\n return;\n }\n pass.setCamera(camera);\n if (requested === null) {\n return;\n }\n const served: RenderRequest[] = [];\n for (let index = this.#requests.length - 1; index >= 0; index -= 1) {\n const pending = this.#requests[index];\n if (pending !== undefined && pending.camera === requested) {\n served.push(pending);\n this.#requests.splice(index, 1);\n }\n }\n // The frame graph executes after this frame callback and submits in the same task; a microtask\n // runs once it has.\n queueMicrotask(() => {\n for (const pending of served) {\n pending.resolve();\n }\n });\n }\n\n async readPixels(): Promise<RenderCapture> {\n const pass = await this.pass(\"RenderTexture.readPixels()\");\n const data = await pass.read();\n return { width: this.width, height: this.height, data };\n }\n\n dispose(): void {\n if (this.#isDisposed) {\n return;\n }\n this.#isDisposed = true;\n this.#pass?.dispose();\n this.#pass = null;\n this.#owner.release(this);\n // Nothing will render them now; settling beats leaving the caller waiting forever.\n for (const pending of this.#requests.splice(0)) {\n pending.resolve();\n }\n }\n\n /**\n * Refuses a disposed texture.\n *\n * @param member - The API member asking.\n * @throws IgnifxError with code `IGX-0731` once disposed.\n */\n assertUsable(member: string): void {\n if (this.#isDisposed) {\n throw renderTextureUnusableError(member);\n }\n }\n}\n\n/**\n * The error for a disposed or foreign render texture.\n *\n * @param member - The API member asking.\n * @returns The error.\n *\n * @internal\n */\nexport function renderTextureUnusableError(member: string): IgnifxError {\n return new IgnifxError(\n CoreErrorCode.renderTextureUnusable,\n `${member}: the render texture is disposed or belongs to another app.`,\n {\n context: { member },\n hint: \"Create a render texture with this app's app.renderer.createRenderTexture() and keep it until you dispose it.\",\n },\n );\n}\n","import { Component } from \"../component/component.js\";\nimport { enumOf, f32, layerMask, optional, u32, vec3 } from \"../schema/field-kinds.js\";\nimport { createDefaults, defineSchema } from \"../schema/schema.js\";\nimport type { Vec3Like } from \"../math/types.js\";\nimport type { Schema } from \"../schema/types.js\";\n\n/**\n * The `ReflectionProbe` component (`docs/plan/2026-11-gi-phase-2-execution-plan.md`, step B1).\n *\n * The component only holds settings and the \"capture again\" request. The renderer loads the probe's\n * GPU code (`./gpu/reflection-probes.ts`, `../lite/gpu/reflection-probe.ts`) only once a world has\n * a probe, so a project without one pays nothing for it (`CONSTITUTION.md` §2.5). Headless, a probe\n * captures nothing.\n */\n\n/**\n * The `as const` name table behind {@link ReflectionProbeRefreshMode}.\n *\n * @public\n */\nexport const REFLECTION_PROBE_REFRESH_MODES = [\"once\", \"onDemand\", \"everyFrame\"] as const;\n\n/**\n * When a reflection probe renders its cube map again.\n *\n * @remarks\n * - `\"once\"` (default): when the probe is first ready, and again on {@link ReflectionProbe.refresh}.\n * - `\"onDemand\"`: only on {@link ReflectionProbe.refresh}; until then the probe reflects nothing.\n * - `\"everyFrame\"`: every frame, six extra scene passes each frame. Use it for one probe at most, on\n * desktop. The `low` and `medium` quality tiers (`rendering.quality`) treat it as `\"once\"`.\n *\n * @public\n */\nexport type ReflectionProbeRefreshMode = (typeof REFLECTION_PROBE_REFRESH_MODES)[number];\n\n/** The smallest and largest cube face, in pixels. */\nconst MIN_SIZE = 16;\nconst MAX_SIZE = 1024;\n\n/**\n * A point that captures the scene around it into a cube map, which nearby shiny PBR materials then\n * reflect instead of the scene environment.\n *\n * @remarks\n * Each lit PBR material reflects the nearest enabled probe that has captured: a probe whose\n * `boxProjection` box holds the mesh wins over one that does not, then the closer probe wins. With no\n * probe, materials reflect the `Environment` again. A material shared by several meshes follows the\n * first of them. Diffuse lighting still comes from the scene environment.\n *\n * The probe needs a loaded `Environment` (it reuses its lighting tables) and a canvas-backed app;\n * until an environment map is loaded it waits, holding no GPU memory and costing no frame time. A\n * `rendering.quality` tier caps `size` and allows `\"everyFrame\"` only at `high` (below, the probe\n * captures as `\"once\"`); with the `custom` tier nothing is capped.\n * Mip levels are box-filtered, so very rough materials look blurrier than with a prefiltered `.env`.\n *\n * @example\n * ```ts\n * const probe = world.createEntity(\"Room probe\", { position: { x: 0, y: 1.5, z: 0 } });\n * probe.addComponent(ReflectionProbe, { size: 128, boxProjection: { x: 8, y: 3, z: 8 } });\n * ```\n *\n * @beta\n */\nexport class ReflectionProbe extends Component {\n /** The namespaced registration id. */\n static typeId = \"ignifx/ReflectionProbe\";\n\n /** What the component does, in one line, for an inspector. */\n static description = \"Captures the scene around it into a cube map that nearby PBR materials reflect.\";\n\n /** One probe per entity. */\n static allowMultiple = false;\n\n /** The serialized field declarations (ADR-0004). */\n static schema: Schema = reflectionProbeSchema();\n\n /**\n * Cube face size in pixels, rounded down to a power of two from 16 to 1024. Defaults to `128`. A\n * `rendering.quality` tier caps it: 64 at `low`, 128 at `medium`, 256 at `high`.\n */\n declare size: number;\n\n /** When the probe captures again. Defaults to `\"once\"`. */\n declare refreshMode: ReflectionProbeRefreshMode;\n\n /**\n * The full size, in metres, of the box (centred on the probe) that reflections are projected onto,\n * or `null` (default) for no box: reflections then look infinitely far away.\n */\n declare boxProjection: Vec3Like | null;\n\n /** The layer names the probe captures; empty (default) captures every layer. */\n declare cullingMask: readonly string[];\n\n /** The near clip distance of the capture, in metres. Defaults to `0.1`. */\n declare near: number;\n\n /** The far clip distance of the capture, in metres. Defaults to `1000`. */\n declare far: number;\n\n /** Applies the schema defaults, exactly as `Component.define` would. */\n constructor() {\n super();\n Object.assign(this, createDefaults(ReflectionProbe.schema));\n }\n\n #isRefreshRequested = false;\n\n /**\n * Asks the probe to capture again from the next frame, whatever its `refreshMode`.\n *\n * @remarks\n * Call it after the static scene around the probe changed, such as a door opening. A capture\n * repeats over a few frames, so meshes whose materials are still compiling are caught.\n */\n refresh(): void {\n this.#isRefreshRequested = true;\n }\n\n /**\n * Reads and clears the request {@link ReflectionProbe.refresh} made.\n *\n * @returns Whether a capture was requested since the last call.\n *\n * @internal\n */\n consumeRefreshRequest(): boolean {\n const requested = this.#isRefreshRequested;\n this.#isRefreshRequested = false;\n return requested;\n }\n}\n\n/**\n * The cube face size a probe captures at.\n *\n * @param size - The authored size.\n * @param maxSize - The quality tier's cap (`RenderingQualityPreset.reflectionProbeMaxSize`); 1024\n * when no tier applies.\n * @returns `size` rounded down to a power of two and clamped to 16..`maxSize`; 128 (or `maxSize` if\n * smaller) for a value that is not a finite number.\n *\n * @internal\n */\nexport function resolveReflectionProbeSize(size: number, maxSize: number = MAX_SIZE): number {\n const upper = Math.min(MAX_SIZE, Math.max(MIN_SIZE, Math.floor(maxSize)));\n const clamped = Number.isFinite(size) ? Math.min(upper, Math.max(MIN_SIZE, Math.floor(size))) : Math.min(upper, 128);\n return 2 ** Math.floor(Math.log2(clamped));\n}\n\n/**\n * The refresh mode a probe runs with under a quality tier.\n *\n * @param mode - The authored mode.\n * @param allowsEveryFrame - Whether the tier lets a probe capture every frame\n * (`RenderingQualityPreset.reflectionProbeEveryFrame`; `true` when no tier applies).\n * @returns `mode`, except `\"everyFrame\"` reads as `\"once\"` when the tier forbids it.\n *\n * @internal\n */\nexport function resolveReflectionProbeRefreshMode(\n mode: ReflectionProbeRefreshMode,\n allowsEveryFrame: boolean,\n): ReflectionProbeRefreshMode {\n return mode === \"everyFrame\" && !allowsEveryFrame ? \"once\" : mode;\n}\n\n/**\n * A probe as {@link selectReflectionProbe} sees it.\n *\n * @internal\n */\nexport interface ReflectionProbeCandidate {\n /** The probe's world position. */\n readonly x: number;\n readonly y: number;\n readonly z: number;\n /** The full size of its projection box, or `null`. */\n readonly box: Vec3Like | null;\n}\n\n/**\n * Picks the probe a point reflects.\n *\n * @remarks\n * A probe whose box holds the point wins, the smallest such box first; with none, the closest\n * probe centre wins. Ties keep the earlier probe.\n *\n * @param x - The point's world X.\n * @param y - The point's world Y.\n * @param z - The point's world Z.\n * @param candidates - The enabled probes that have captured.\n * @returns The index of the chosen probe, or `-1` when there is none.\n *\n * @internal\n */\nexport function selectReflectionProbe(\n x: number,\n y: number,\n z: number,\n candidates: readonly ReflectionProbeCandidate[],\n): number {\n let inside = -1;\n let insideVolume = Number.POSITIVE_INFINITY;\n let nearest = -1;\n let nearestDistance = Number.POSITIVE_INFINITY;\n for (let index = 0; index < candidates.length; index += 1) {\n const probe = candidates[index];\n if (probe === undefined) {\n continue;\n }\n const dx = x - probe.x;\n const dy = y - probe.y;\n const dz = z - probe.z;\n const box = probe.box;\n if (box !== null && Math.abs(dx) <= box.x / 2 && Math.abs(dy) <= box.y / 2 && Math.abs(dz) <= box.z / 2) {\n const volume = box.x * box.y * box.z;\n if (volume < insideVolume) {\n inside = index;\n insideVolume = volume;\n }\n }\n const distance = dx * dx + dy * dy + dz * dz;\n if (distance < nearestDistance) {\n nearest = index;\n nearestDistance = distance;\n }\n }\n return inside >= 0 ? inside : nearest;\n}\n\n/**\n * Builds the component's declared fields.\n *\n * @returns The schema. Built inside a function: module scope holds declarations and immutable\n * constants only (`CONSTITUTION.md` §3.5).\n */\nfunction reflectionProbeSchema(): Schema {\n return defineSchema({\n size: u32(128, {\n min: MIN_SIZE,\n max: MAX_SIZE,\n tooltip:\n \"Cube face size in pixels, rounded down to a power of two. Larger is sharper and slower to capture. Quality tiers cap it (low 64, medium 128, high 256).\",\n }),\n refreshMode: enumOf(REFLECTION_PROBE_REFRESH_MODES, \"once\", {\n tooltip:\n \"once: capture when ready and on refresh(); onDemand: only on refresh(); everyFrame: every frame (costly; one probe; the low and medium quality tiers treat it as once).\",\n }),\n boxProjection: optional(vec3({ x: 10, y: 10, z: 10 }), {\n tooltip:\n \"Full size in metres of the box, centred on the probe, that reflections are projected onto; null for none.\",\n }),\n cullingMask: layerMask([], { tooltip: \"The layers the probe captures; empty captures every layer.\" }),\n near: f32(0.1, { min: 0.001, tooltip: \"Near clip distance of the capture, in metres.\" }),\n far: f32(1000, { min: 0.01, tooltip: \"Far clip distance of the capture, in metres.\" }),\n });\n}\n"],"mappings":";;;;;;AAoHA,IAAM,aAAN,MAAoB;CAClB;CACA;CACA;;CAEA;;CAEA,kBAAqC;CAErC,YAAY,SAA2B,MAAe,UAAmB,OAAe;EACtF,KAAK,UAAU;EACf,KAAK,OAAO;EACZ,KAAK,WAAW;EAChB,KAAK,QAAQ;CACf;AACF;;AAGA,SAAS,iBAAuB,CAEhC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA,IAAa,SAAb,MAAuD;CACrD,eAAyC,CAAC;CAC1C;CACA;CACA,aAAa;CACb,aAAa;CACb,aAAa;;;;;;;CAQb,YAAY,SAA4B;EACtC,KAAK,iBAAiB,SAAS,iBAAiB;EAChD,KAAK,kBAAkB,SA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