@ignifx/core 0.18.0 → 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{environment-DZ6WUHbm.js → environment-Bf4aphSb.js} +2 -2
- package/dist/{environment-DZ6WUHbm.js.map → environment-Bf4aphSb.js.map} +1 -1
- package/dist/{gtao-_nr0b6-E.js → gtao-Bpu5-0Ne.js} +2 -2
- package/dist/{gtao-_nr0b6-E.js.map → gtao-Bpu5-0Ne.js.map} +1 -1
- package/dist/{hdr-output-Dbv0lhFl.js → hdr-output-DBQwMphy.js} +2 -2
- package/dist/{hdr-output-Dbv0lhFl.js.map → hdr-output-DBQwMphy.js.map} +1 -1
- package/dist/{ignifx-error-B8ByiSfJ.js → ignifx-error-DwIZKxA2.js} +4 -1
- package/dist/ignifx-error-DwIZKxA2.js.map +1 -0
- package/dist/index.d.ts +218 -696
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2904 -970
- package/dist/index.js.map +1 -1
- package/dist/{instanced-mesh-instance-BMhREEfx.js → instanced-mesh-instance-B-fXKSrY.js} +2 -2
- package/dist/{instanced-mesh-instance-BMhREEfx.js.map → instanced-mesh-instance-B-fXKSrY.js.map} +1 -1
- package/dist/{light-probe-asset-B60_X-yN.js → light-probe-asset-BqfSrJe9.js} +2 -2
- package/dist/{light-probe-asset-B60_X-yN.js.map → light-probe-asset-BqfSrJe9.js.map} +1 -1
- package/dist/{light-probes-DkYN89Qw.js → light-probes-DDojYajw.js} +4 -4
- package/dist/{light-probes-DkYN89Qw.js.map → light-probes-DDojYajw.js.map} +1 -1
- package/dist/lightmaps-BUUIIkt9.js +230 -0
- package/dist/lightmaps-BUUIIkt9.js.map +1 -0
- package/dist/{material-CGk5mAah.js → material-myMbl9mW.js} +37 -2
- package/dist/{material-CGk5mAah.js.map → material-myMbl9mW.js.map} +1 -1
- package/dist/{material-plugin-CiAmriQ_.js → material-plugin-DapJNj04.js} +2 -2
- package/dist/{material-plugin-CiAmriQ_.js.map → material-plugin-DapJNj04.js.map} +1 -1
- package/dist/{post-effect-CQnlX1RH.js → post-effect-Cu3Enpz7.js} +2 -2
- package/dist/{post-effect-CQnlX1RH.js.map → post-effect-Cu3Enpz7.js.map} +1 -1
- package/dist/{post-effect-compiler-C_7HTHZy.js → post-effect-compiler-cCq9lcHt.js} +3 -3
- package/dist/{post-effect-compiler-C_7HTHZy.js.map → post-effect-compiler-cCq9lcHt.js.map} +1 -1
- package/dist/{prefab-overrides-DT-wHHAJ.js → prefab-overrides-C2GsgOQc.js} +467 -30
- package/dist/prefab-overrides-C2GsgOQc.js.map +1 -0
- package/dist/{prefab-overrides-BLQn5yHS.d.ts → prefab-overrides-htDc_5Po.d.ts} +1370 -246
- package/dist/prefab-overrides-htDc_5Po.d.ts.map +1 -0
- package/dist/prefab.d.ts +2 -2
- package/dist/prefab.js +2 -2
- package/dist/{reflection-probe-DlVsl3zJ.js → reflection-probe-QkD1Fo_d.js} +106 -12
- package/dist/{reflection-probe-DlVsl3zJ.js.map → reflection-probe-QkD1Fo_d.js.map} +1 -1
- package/dist/reflection-probes-CAzSuqf8.js +921 -0
- package/dist/reflection-probes-CAzSuqf8.js.map +1 -0
- package/dist/{shader-material-CaAkv5nT.js → shader-material-CJIDFvSb.js} +2 -2
- package/dist/{shader-material-CaAkv5nT.js.map → shader-material-CJIDFvSb.js.map} +1 -1
- package/dist/{shader-material-C2_UCYdO.js → shader-material-TM4f8eKA.js} +4 -4
- package/dist/{shader-material-C2_UCYdO.js.map → shader-material-TM4f8eKA.js.map} +1 -1
- package/dist/{shader-pragma-DmZpxGUo.js → shader-pragma-ljmAbVc2.js} +2 -2
- package/dist/{shader-pragma-DmZpxGUo.js.map → shader-pragma-ljmAbVc2.js.map} +1 -1
- package/dist/{ssgi-Dm-maZrc.js → ssgi-DSnhqotl.js} +2 -2
- package/dist/{ssgi-Dm-maZrc.js.map → ssgi-DSnhqotl.js.map} +1 -1
- package/dist/{surface-shader-BeDRofOV.js → surface-shader-rpPpeosD.js} +6 -6
- package/dist/{surface-shader-BeDRofOV.js.map → surface-shader-rpPpeosD.js.map} +1 -1
- package/dist/{vec3-Cc19wl4r.js → vec3-2C3LBZnt.js} +55 -3
- package/dist/vec3-2C3LBZnt.js.map +1 -0
- package/package.json +1 -1
- package/dist/ignifx-error-B8ByiSfJ.js.map +0 -1
- package/dist/prefab-overrides-BLQn5yHS.d.ts.map +0 -1
- package/dist/prefab-overrides-DT-wHHAJ.js.map +0 -1
- package/dist/reflection-probes-B8S9WnVX.js +0 -551
- package/dist/reflection-probes-B8S9WnVX.js.map +0 -1
- package/dist/vec3-Cc19wl4r.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { a as CORE_ERROR_MESSAGES, c as THIRD_PARTY_ERROR_PREFIX, i as isIgnifxError, l as isValidErrorCode, n as assertNever, o as CoreErrorCode, r as formatErrorMessage, s as ErrorRange, t as IgnifxError } from "./ignifx-error-
|
|
2
|
-
import { A as
|
|
3
|
-
import { A as
|
|
1
|
+
import { a as CORE_ERROR_MESSAGES, c as THIRD_PARTY_ERROR_PREFIX, i as isIgnifxError, l as isValidErrorCode, n as assertNever, o as CoreErrorCode, r as formatErrorMessage, s as ErrorRange, t as IgnifxError } from "./ignifx-error-DwIZKxA2.js";
|
|
2
|
+
import { $ as Signal, A as str, B as readPickedIdentity, C as f64, D as optional, E as map, F as FieldKind, G as componentInternals, H as readPickedTag, I as createPickRay, J as toEntityHandle, K as INVALID_HANDLE, L as raycastScene, M as vec2, N as vec3, O as quat, P as vec4, Q as defineSchema, R as raycastSceneWhere, S as f32, T as layerMask, U as setPickRay, V as readPickedMeshName, W as Component, X as assertNoInheritedFieldNames, Y as applyInit, Z as createDefaults, _ as componentRef, b as entityRef, c as RENDER_TEXTURE_MAX_SIZE, d as bindFrameCameras, f as renderTextureUnusableError, g as color, h as bool, j as u32, k as record, l as RenderTextureImpl, m as asset, n as ReflectionProbe, p as array, q as toComponentHandle, s as EDITOR_ONLY_METADATA_KEY, t as REFLECTION_PROBE_REFRESH_MODES, u as assertRenderTextureSize, v as curve, w as i32, x as enumOf, y as custom, z as readOwnerTag } from "./reflection-probe-QkD1Fo_d.js";
|
|
3
|
+
import { A as childPath, C as canonicalizeNumber, D as encodeValue, E as encodeProps, F as asJsonObject, G as splitFragment, H as joinRoot, I as setOwnJsonProperty, L as SchemaIssueCode, M as isArray, N as isPlainObject, O as COLOR_CHANNELS, P as asJsonArray, R as issue, S as toJsonSchema, T as decodeValue, U as matchExtension, V as isAbsoluteAddress, W as normalizeExtension, _ as describeSceneFileFormat, a as applyOverrides, b as stringifySceneFile, c as remapInstancePath, d as createSceneAsset, f as findSceneDependency, g as SCENE_FORMAT_VERSION, h as SCENE_FILE_FORMAT, i as resolveInstancePath, j as indexPath, k as VECTOR_COMPONENTS, l as SceneAssetToken, m as SCENE_FILE_EXTENSIONS, n as revertOverrides, o as parseOverridePath, p as SCENE_ASSET_TYPE, r as enumerateInstanceTargets, s as instancePathResolver, t as applyOverridesToAsset, u as computeSceneHash, v as isSceneFileHeader, w as decodeProps, x as describeSchema, y as sceneFileJsonSchema } from "./prefab-overrides-C2GsgOQc.js";
|
|
4
4
|
import { _ as smoothStep, a as clamp, c as deltaAngleDegrees, d as lerpAngleDegrees, f as moveTowards, g as sign, h as repeat, i as approximately, l as inverseLerp, m as radToDeg, n as EPSILON, o as clamp01, p as pingPong, r as RAD_TO_DEG, s as degToRad, t as DEG_TO_RAD, u as lerp, v as wrapAngleDegrees } from "./math-utils-BcDnL-gi.js";
|
|
5
5
|
import { n as Mat4, r as basisToQuatToRef, t as MAT4_IDENTITY } from "./mat4-D6exvAuO.js";
|
|
6
6
|
import { a as localRotation, d as setNodeName, f as setNodeSelfVisible, i as localPosition, l as readWorldMatrix, m as worldMatrixVersion, n as disposeNode, o as localScale, p as tagNode, r as linkParent, s as parentNode, t as createNode, u as reparentKeepingWorld } from "./node-DznSvwap.js";
|
|
7
7
|
import { t as Color } from "./color-DrR6GFTd.js";
|
|
8
|
-
import { a as readSceneImageProcessing, c as setSceneEnvironmentRotation, l as setSceneFog, n as installSceneEnvironment, o as setSceneClearColor, r as loadSceneEnvironment, s as setSceneEnvironmentBlur, t as TONE_MAPPING_NAMES, u as setSceneImageProcessingOptions } from "./environment-
|
|
9
|
-
import { a as markMaterialDirty, c as setPbrBaseColor, i as createStandardMaterialFromProps, l as setPbrMetallicRoughness, n as createDefaultMaterial, r as createPbrMaterialFromProps, s as setMaterialAlpha, t as MATERIAL_ALPHA_MODES } from "./material-
|
|
10
|
-
import { A as
|
|
11
|
-
import { a as LightProbeAsset, c as readLightProbeFile, d as writeLightProbeFile, i as LIGHT_PROBE_FORMAT_VERSION, l as readLightProbeGrid, n as LIGHT_PROBE_FILE_EXTENSIONS, o as createLightProbeAsset, r as LIGHT_PROBE_FILE_FORMAT, t as LIGHT_PROBE_ASSET_TYPE, u as sampleLightProbes } from "./light-probe-asset-
|
|
12
|
-
import { a as postEffectValuesCodec, i as declaredTextureBinding, n as POST_EFFECT_FUNCTION, r as customEffect, t as POST_EFFECT_BUILTIN_UNIFORMS } from "./post-effect-
|
|
8
|
+
import { a as readSceneImageProcessing, c as setSceneEnvironmentRotation, i as readSceneEnvironment, l as setSceneFog, n as installSceneEnvironment, o as setSceneClearColor, r as loadSceneEnvironment, s as setSceneEnvironmentBlur, t as TONE_MAPPING_NAMES, u as setSceneImageProcessingOptions } from "./environment-Bf4aphSb.js";
|
|
9
|
+
import { a as markMaterialDirty, c as setPbrBaseColor, i as createStandardMaterialFromProps, l as setPbrMetallicRoughness, n as createDefaultMaterial, r as createPbrMaterialFromProps, s as setMaterialAlpha, t as MATERIAL_ALPHA_MODES } from "./material-myMbl9mW.js";
|
|
10
|
+
import { A as setMeshPickable, C as overrideSubtreeMaterials, D as setMeshBounds, E as removeMeshFromScene, F as updateMeshNormals$1, I as updateMeshPositions$1, L as updateMeshUvs$1, M as setMeshRenderOrder, N as setMeshSubtreeVisible, O as setMeshId, P as updateMeshColors$1, S as disposeMeshTemplate, T as recomputeMeshBounds, _ as createMeshFromGeometry, a as VEC3_ONE, b as createTorusMesh, c as VEC3_ZERO, d as cloneMeshUnderNode, f as collectSubtreeMeshes, g as createGroundMesh, h as createCylinderMesh, i as VEC3_LEFT, j as setMeshReceiveShadows, k as setMeshMaterial, l as Vec3, m as createCapsuleMesh, n as VEC3_DOWN, o as VEC3_RIGHT, p as createBoxMesh, r as VEC3_FORWARD, s as VEC3_UP, t as VEC3_BACKWARD, u as addMeshToScene, v as createPlaneMesh, w as readMeshBakeSurface, x as detachMeshBounds, y as createSphereMesh } from "./vec3-2C3LBZnt.js";
|
|
11
|
+
import { a as LightProbeAsset, c as readLightProbeFile, d as writeLightProbeFile, i as LIGHT_PROBE_FORMAT_VERSION, l as readLightProbeGrid, n as LIGHT_PROBE_FILE_EXTENSIONS, o as createLightProbeAsset, r as LIGHT_PROBE_FILE_FORMAT, t as LIGHT_PROBE_ASSET_TYPE, u as sampleLightProbes } from "./light-probe-asset-BqfSrJe9.js";
|
|
12
|
+
import { a as postEffectValuesCodec, i as declaredTextureBinding, n as POST_EFFECT_FUNCTION, r as customEffect, t as POST_EFFECT_BUILTIN_UNIFORMS } from "./post-effect-Cu3Enpz7.js";
|
|
13
13
|
import { n as installOffscreenRenderPath } from "./render-path-D11i_7X8.js";
|
|
14
14
|
import { a as SHADER_BLEND_MODES, c as SHADER_KINDS, d as SURFACE_HOOK_NAMES, f as SURFACE_UNIFORM_BLOCK, i as SHADER_ATTRIBUTE_NAMES, l as SHADER_TEXTURE_FALLBACKS, o as SHADER_CULL_MODES, r as LITE_SYSTEM_UNIFORM_NAMES, s as SHADER_INSTANCING_MODES, t as IGNIFX_UNIFORM_NAMES, u as SHADER_UNIFORM_TYPES } from "./shader-declaration-5q__jycG.js";
|
|
15
|
-
import { a as defineMaterialPlugin, i as MATERIAL_PLUGIN_SAMPLER_BUDGET, n as MATERIAL_PLUGIN_DEFAULT_PRIORITY, o as isLiteMaterialPluginPoint, r as MATERIAL_PLUGIN_RESERVED_NAMES, t as LITE_MATERIAL_PLUGIN_POINTS } from "./material-plugin-
|
|
15
|
+
import { a as defineMaterialPlugin, i as MATERIAL_PLUGIN_SAMPLER_BUDGET, n as MATERIAL_PLUGIN_DEFAULT_PRIORITY, o as isLiteMaterialPluginPoint, r as MATERIAL_PLUGIN_RESERVED_NAMES, t as LITE_MATERIAL_PLUGIN_POINTS } from "./material-plugin-DapJNj04.js";
|
|
16
16
|
import { acquireTexture, addTask, addToScene, buildFrameGraphTask, captureScreenshot, cloneTransformNode, createBloomPostProcessTask, createCsmDirectionalShadowGenerator, createDirectionalLight, createEngine, createEsmDirectionalShadowGenerator, createFontFromBuffer, createFreeCamera, createGpuPicker, createHemisphericLight, createImageProcessingTask, createMeshFromData, createNullEngine, createPcfDirectionalShadowGenerator, createPcfSpotlightShadowGenerator, createPointLight, createRenderTarget, createSceneContext, createSmaaPostProcessTask, createSpotLight, createStorageBuffer, createTexture2DFromPixels, disableOrthographicCamera, disposeEngine, disposePicker, disposeScene, disposeStorageBuffer, enableBoneControl, enableDeviceLostSceneRecovery, enableMaterialPlugins, enableMaterialStencil, enableOrthographicCamera, enablePbrLightmap, enableSkeletonShadows, enableStandardSkeleton, forceWebGpuDeviceLossForTesting, getEffectiveAspectRatio, getFrameGraph, getProjectionMatrix, getRenderTaskGpuTimings, getViewMatrix, getViewProjectionMatrix, isPbrMaterial, isShaderMaterial, loadTexture2D, onBeforeRender, pickAsync, rebuildSceneRenderables, registerScene, registerSceneWithShadowSupport, releaseTexture, removeFromScene, renderFrame, resizeEngine, resolveCameraViewport, setGpuTimingEnabled, setRenderTaskGpuTimingEnabled, setShadowTaskCasterMeshes, setSubtreeVisible, setSurfaceSize, startEngine, stopEngine, updateStorageBuffer, updateTexture2DFromPixels } from "@babylonjs/lite";
|
|
17
17
|
//#region src/assets/types.ts
|
|
18
18
|
/**
|
|
@@ -3903,7 +3903,7 @@ function createServiceKey(name) {
|
|
|
3903
3903
|
*
|
|
3904
3904
|
* @public
|
|
3905
3905
|
*/
|
|
3906
|
-
const VERSION = "0.
|
|
3906
|
+
const VERSION = "0.20.0";
|
|
3907
3907
|
//#endregion
|
|
3908
3908
|
//#region src/assets/delivery-system.ts
|
|
3909
3909
|
/**
|
|
@@ -5349,7 +5349,7 @@ var Environment = class Environment extends Component {
|
|
|
5349
5349
|
const askedForSize = skybox.size !== SKYBOX_SIZE_DEFAULT && skybox.size !== definition.skyboxSize;
|
|
5350
5350
|
if (!askedForEnabled && !askedForSize) return;
|
|
5351
5351
|
this.#hasWarnedAboutSkybox = true;
|
|
5352
|
-
renderer.app.log.warn(`${CoreErrorCode.skyboxFixedAtLoad}: {entity} asks for skybox {
|
|
5352
|
+
renderer.app.log.warn(`${CoreErrorCode.skyboxFixedAtLoad}: ${JSON.stringify(this.entity.name)} asks for skybox { enabled: ${String(skybox.enabled)}, size: ${String(skybox.size)} }, but ${installed.address} was loaded with { enabled: ${String(definition.skyboxEnabled)}, size: ${String(definition.skyboxSize)} } and Babylon Lite builds the background when the environment loads, with no handle to change it afterwards. Declare skyboxEnabled and skyboxSize in the .environment.json instead.`);
|
|
5353
5353
|
}
|
|
5354
5354
|
/**
|
|
5355
5355
|
* Fires the asynchronous image-processing update, at most one at a time.
|
|
@@ -5466,7 +5466,7 @@ let layer$1 = null;
|
|
|
5466
5466
|
* @internal
|
|
5467
5467
|
*/
|
|
5468
5468
|
async function loadInstancedMeshSupport() {
|
|
5469
|
-
const loaded = layer$1 ?? await import("./instanced-mesh-instance-
|
|
5469
|
+
const loaded = layer$1 ?? await import("./instanced-mesh-instance-B-fXKSrY.js");
|
|
5470
5470
|
layer$1 = loaded;
|
|
5471
5471
|
return loaded;
|
|
5472
5472
|
}
|
|
@@ -5494,7 +5494,7 @@ let surfaceLayer = null;
|
|
|
5494
5494
|
* @internal
|
|
5495
5495
|
*/
|
|
5496
5496
|
async function loadShaderSupport() {
|
|
5497
|
-
const loaded = shaderLayer ?? await import("./shader-material-
|
|
5497
|
+
const loaded = shaderLayer ?? await import("./shader-material-TM4f8eKA.js").then((n) => n.n);
|
|
5498
5498
|
shaderLayer = loaded;
|
|
5499
5499
|
await loaded.loadShaderMaterialAdapter();
|
|
5500
5500
|
return loaded;
|
|
@@ -5517,7 +5517,7 @@ function shaderSupport() {
|
|
|
5517
5517
|
* @internal
|
|
5518
5518
|
*/
|
|
5519
5519
|
async function loadSurfaceShaderSupport() {
|
|
5520
|
-
const loaded = surfaceLayer ?? await import("./surface-shader-
|
|
5520
|
+
const loaded = surfaceLayer ?? await import("./surface-shader-rpPpeosD.js");
|
|
5521
5521
|
surfaceLayer = loaded;
|
|
5522
5522
|
return loaded;
|
|
5523
5523
|
}
|
|
@@ -6653,6 +6653,7 @@ var MeshAsset = class {
|
|
|
6653
6653
|
#scene;
|
|
6654
6654
|
#geometry;
|
|
6655
6655
|
#engine;
|
|
6656
|
+
#primitive;
|
|
6656
6657
|
#mesh;
|
|
6657
6658
|
#isDisposed = false;
|
|
6658
6659
|
/**
|
|
@@ -6666,15 +6667,17 @@ var MeshAsset = class {
|
|
|
6666
6667
|
* {@link MeshAsset.fromData}; `null` for a primitive, whose arrays Lite generated and never
|
|
6667
6668
|
* handed back. It is what makes the `update*` methods legal.
|
|
6668
6669
|
* @param engine - The engine an update writes through, or `null` under a headless app.
|
|
6670
|
+
* @param primitive - The primitive and options it was built from, or `null` for data.
|
|
6669
6671
|
*
|
|
6670
6672
|
* @internal
|
|
6671
6673
|
*/
|
|
6672
|
-
constructor(name, mesh, scene, geometry = null, engine = null) {
|
|
6674
|
+
constructor(name, mesh, scene, geometry = null, engine = null, primitive = null) {
|
|
6673
6675
|
this.name = name;
|
|
6674
6676
|
this.#mesh = mesh;
|
|
6675
6677
|
this.#scene = scene;
|
|
6676
6678
|
this.#geometry = geometry;
|
|
6677
6679
|
this.#engine = engine;
|
|
6680
|
+
this.#primitive = primitive;
|
|
6678
6681
|
}
|
|
6679
6682
|
/**
|
|
6680
6683
|
* The Babylon Lite objects the asset owns. Unstable escape hatch
|
|
@@ -6704,6 +6707,17 @@ var MeshAsset = class {
|
|
|
6704
6707
|
return this.#geometry;
|
|
6705
6708
|
}
|
|
6706
6709
|
/**
|
|
6710
|
+
* The primitive and options the asset was built from, so a light-probe bake can rebuild its
|
|
6711
|
+
* triangles on the CPU.
|
|
6712
|
+
*
|
|
6713
|
+
* @returns The definition, or `null` for a mesh built with {@link MeshAsset.fromData}.
|
|
6714
|
+
*
|
|
6715
|
+
* @internal
|
|
6716
|
+
*/
|
|
6717
|
+
get primitive() {
|
|
6718
|
+
return this.#primitive;
|
|
6719
|
+
}
|
|
6720
|
+
/**
|
|
6707
6721
|
* How many vertices the geometry has.
|
|
6708
6722
|
*
|
|
6709
6723
|
* @remarks
|
|
@@ -7041,7 +7055,7 @@ function copyRange(source, target, components, vertexOffset, count) {
|
|
|
7041
7055
|
*/
|
|
7042
7056
|
function createPrimitiveMeshAsset(app, name, definition) {
|
|
7043
7057
|
const handles = buildMeshTemplate(app.isHeadless, app.lite.scene, app.lite.engine, (engine) => buildPrimitiveTemplate(engine, definition));
|
|
7044
|
-
return new MeshAsset(name, handles.mesh, handles.scene, null, handles.engine);
|
|
7058
|
+
return new MeshAsset(name, handles.mesh, handles.scene, null, handles.engine, definition);
|
|
7045
7059
|
}
|
|
7046
7060
|
/**
|
|
7047
7061
|
* Builds a primitive and registers it as an in-memory asset named after the primitive.
|
|
@@ -8585,7 +8599,7 @@ var LightProbeHost = class {
|
|
|
8585
8599
|
}
|
|
8586
8600
|
if (volumes.length === 0 || this.#isLoading || this.#isDisposed) return;
|
|
8587
8601
|
this.#isLoading = true;
|
|
8588
|
-
import("./light-probes-
|
|
8602
|
+
import("./light-probes-DDojYajw.js").then((module) => module.createLightProbeRuntime(this.#engine, this.#scene)).then((created) => {
|
|
8589
8603
|
if (this.#isDisposed) {
|
|
8590
8604
|
created.dispose();
|
|
8591
8605
|
return;
|
|
@@ -8601,6 +8615,407 @@ var LightProbeHost = class {
|
|
|
8601
8615
|
}
|
|
8602
8616
|
};
|
|
8603
8617
|
//#endregion
|
|
8618
|
+
//#region src/render/lightmap-asset.ts
|
|
8619
|
+
/**
|
|
8620
|
+
* Lightmaps (`docs/plan/2026-11-gi-phase-2-execution-plan.md`, step B3): a baked texture that static
|
|
8621
|
+
* `MeshRenderer`s sample through their second UV set, and the per-entity placement of each renderer
|
|
8622
|
+
* in it. Everything here is plain data and runs in Node; the GPU half is `./gpu/lightmaps.ts`.
|
|
8623
|
+
*/
|
|
8624
|
+
/**
|
|
8625
|
+
* The asset type lightmaps are registered under.
|
|
8626
|
+
*
|
|
8627
|
+
* @public
|
|
8628
|
+
*/
|
|
8629
|
+
const LIGHTMAP_ASSET_TYPE = "lightmap";
|
|
8630
|
+
/**
|
|
8631
|
+
* The address extensions that select the lightmap loader.
|
|
8632
|
+
*
|
|
8633
|
+
* @public
|
|
8634
|
+
*/
|
|
8635
|
+
const LIGHTMAP_FILE_EXTENSIONS = Object.freeze([".lightmap.json"]);
|
|
8636
|
+
/**
|
|
8637
|
+
* The `format` header every `.lightmap.json` carries.
|
|
8638
|
+
*
|
|
8639
|
+
* @public
|
|
8640
|
+
*/
|
|
8641
|
+
const LIGHTMAP_FILE_FORMAT = "ignifx-lightmap";
|
|
8642
|
+
/**
|
|
8643
|
+
* The `formatVersion` this engine reads and writes.
|
|
8644
|
+
*
|
|
8645
|
+
* @public
|
|
8646
|
+
*/
|
|
8647
|
+
const LIGHTMAP_FORMAT_VERSION = 1;
|
|
8648
|
+
/**
|
|
8649
|
+
* The placement every entity without an entry gets: the whole texture.
|
|
8650
|
+
*
|
|
8651
|
+
* @public
|
|
8652
|
+
*/
|
|
8653
|
+
const IDENTITY_LIGHTMAP_PLACEMENT = Object.freeze({
|
|
8654
|
+
scale: Object.freeze({
|
|
8655
|
+
x: 1,
|
|
8656
|
+
y: 1
|
|
8657
|
+
}),
|
|
8658
|
+
offset: Object.freeze({
|
|
8659
|
+
x: 0,
|
|
8660
|
+
y: 0
|
|
8661
|
+
})
|
|
8662
|
+
});
|
|
8663
|
+
/**
|
|
8664
|
+
* A loaded lightmap: a texture and where each entity's UV2 square sits in it.
|
|
8665
|
+
*
|
|
8666
|
+
* @remarks
|
|
8667
|
+
* A `MeshRenderer` names it in its `lightmap` record. Many renderers can share one atlas
|
|
8668
|
+
* texture: each samples it at `uv2 · scale + offset`, with its entity's entry as the placement, in
|
|
8669
|
+
* the same UV space as an entity without one (so a V flip the texture asks for applies to the
|
|
8670
|
+
* placed coordinate too). A placement other than {@link IDENTITY_LIGHTMAP_PLACEMENT} needs the
|
|
8671
|
+
* renderer's `lightmap.uv2` on and a mesh with `uvs2`; otherwise it logs `IGX-0735` once and
|
|
8672
|
+
* samples the whole texture. Each distinct placement compiles its own pipeline variant.
|
|
8673
|
+
*
|
|
8674
|
+
* @example
|
|
8675
|
+
* ```ts
|
|
8676
|
+
* const lightmap = await app.assets.loadAsync<LightmapAsset>("lighting/hall.lightmap.json");
|
|
8677
|
+
* entity.isStatic = true;
|
|
8678
|
+
* entity.addComponent(MeshRenderer, { mesh, lightmap: { asset: lightmap, mode: "add", level: 1, gamma: false, uv2: true } });
|
|
8679
|
+
* ```
|
|
8680
|
+
*
|
|
8681
|
+
* @beta
|
|
8682
|
+
*/
|
|
8683
|
+
var LightmapAsset = class {
|
|
8684
|
+
/** The type name the asset service registers lightmaps under. */
|
|
8685
|
+
static assetType = LIGHTMAP_ASSET_TYPE;
|
|
8686
|
+
/** The baked texture. The asset does not own the handle: its loader or creator does. */
|
|
8687
|
+
texture;
|
|
8688
|
+
/** Per-entity placements, keyed by entity uid. */
|
|
8689
|
+
entries;
|
|
8690
|
+
/**
|
|
8691
|
+
* Wraps a texture and its checked placements. Use the loader or {@link createLightmapAsset}.
|
|
8692
|
+
*
|
|
8693
|
+
* @param texture - The baked texture.
|
|
8694
|
+
* @param entries - Placements already checked by `readLightmapEntries`.
|
|
8695
|
+
*
|
|
8696
|
+
* @internal
|
|
8697
|
+
*/
|
|
8698
|
+
constructor(texture, entries) {
|
|
8699
|
+
this.texture = texture;
|
|
8700
|
+
this.entries = entries;
|
|
8701
|
+
}
|
|
8702
|
+
/**
|
|
8703
|
+
* The placement of one entity's UV2 square.
|
|
8704
|
+
*
|
|
8705
|
+
* @param entityId - The entity's uid.
|
|
8706
|
+
* @returns Its entry, or {@link IDENTITY_LIGHTMAP_PLACEMENT} when it has none.
|
|
8707
|
+
*/
|
|
8708
|
+
placementOf(entityId) {
|
|
8709
|
+
return Object.hasOwn(this.entries, entityId) ? this.entries[entityId] ?? IDENTITY_LIGHTMAP_PLACEMENT : IDENTITY_LIGHTMAP_PLACEMENT;
|
|
8710
|
+
}
|
|
8711
|
+
};
|
|
8712
|
+
/**
|
|
8713
|
+
* Publishes a lightmap built in code, such as a texture from `TextureAsset.fromPixels`.
|
|
8714
|
+
*
|
|
8715
|
+
* @param app - The app.
|
|
8716
|
+
* @param texture - The baked texture; the caller keeps owning the handle.
|
|
8717
|
+
* @param entries - Per-entity placements, keyed by entity uid. Defaults to none.
|
|
8718
|
+
* @returns A handle a `MeshRenderer`'s `lightmap.asset` can take.
|
|
8719
|
+
* @throws IgnifxError with code `IGX-0709` when a placement is malformed.
|
|
8720
|
+
*
|
|
8721
|
+
* @beta
|
|
8722
|
+
*/
|
|
8723
|
+
function createLightmapAsset(app, texture, entries = {}) {
|
|
8724
|
+
return app.assets.register(new LightmapAsset(texture, readLightmapEntries(entries, "lightmap entries")), { type: LIGHTMAP_ASSET_TYPE });
|
|
8725
|
+
}
|
|
8726
|
+
/**
|
|
8727
|
+
* Turns a lightmap description into the JSON a `.lightmap.json` file holds.
|
|
8728
|
+
*
|
|
8729
|
+
* @param data - The texture address and placements.
|
|
8730
|
+
* @returns The file contents, with the format header.
|
|
8731
|
+
*
|
|
8732
|
+
* @beta
|
|
8733
|
+
*/
|
|
8734
|
+
function writeLightmapFile(data) {
|
|
8735
|
+
const entries = {};
|
|
8736
|
+
for (const id of Object.keys(data.entries).toSorted()) {
|
|
8737
|
+
const placement = data.entries[id];
|
|
8738
|
+
if (placement !== void 0) entries[id] = {
|
|
8739
|
+
scale: {
|
|
8740
|
+
x: placement.scale.x,
|
|
8741
|
+
y: placement.scale.y
|
|
8742
|
+
},
|
|
8743
|
+
offset: {
|
|
8744
|
+
x: placement.offset.x,
|
|
8745
|
+
y: placement.offset.y
|
|
8746
|
+
}
|
|
8747
|
+
};
|
|
8748
|
+
}
|
|
8749
|
+
return {
|
|
8750
|
+
format: LIGHTMAP_FILE_FORMAT,
|
|
8751
|
+
formatVersion: 1,
|
|
8752
|
+
texture: data.texture,
|
|
8753
|
+
entries
|
|
8754
|
+
};
|
|
8755
|
+
}
|
|
8756
|
+
/**
|
|
8757
|
+
* Reads a parsed `.lightmap.json`.
|
|
8758
|
+
*
|
|
8759
|
+
* @param parsed - The parsed JSON.
|
|
8760
|
+
* @param address - The file's address, for the error.
|
|
8761
|
+
* @returns The texture address and checked placements.
|
|
8762
|
+
* @throws IgnifxError with code `IGX-0709` when the header, the texture or a placement is wrong.
|
|
8763
|
+
*
|
|
8764
|
+
* @internal
|
|
8765
|
+
*/
|
|
8766
|
+
function readLightmapFile(parsed, address) {
|
|
8767
|
+
const file = asRecord$1(parsed);
|
|
8768
|
+
if (file === null || file["format"] !== "ignifx-lightmap" || file["formatVersion"] !== 1) throw invalid(address, `it must start with { "format": "${LIGHTMAP_FILE_FORMAT}", "formatVersion": 1 }`);
|
|
8769
|
+
const texture = file["texture"];
|
|
8770
|
+
if (typeof texture !== "string" || texture.trim() === "") throw invalid(address, "texture must be the lightmap texture's asset address");
|
|
8771
|
+
return {
|
|
8772
|
+
texture,
|
|
8773
|
+
entries: readLightmapEntries(file["entries"] ?? {}, address)
|
|
8774
|
+
};
|
|
8775
|
+
}
|
|
8776
|
+
/**
|
|
8777
|
+
* Checks a set of per-entity placements.
|
|
8778
|
+
*
|
|
8779
|
+
* @remarks
|
|
8780
|
+
* A placement may leave out `scale` or `offset`; the missing half takes the identity's.
|
|
8781
|
+
*
|
|
8782
|
+
* @param value - The candidate `entries` object.
|
|
8783
|
+
* @param address - Where it came from, for the error.
|
|
8784
|
+
* @returns Checked copies, keyed by entity uid.
|
|
8785
|
+
* @throws IgnifxError with code `IGX-0709` on a malformed placement.
|
|
8786
|
+
*
|
|
8787
|
+
* @internal
|
|
8788
|
+
*/
|
|
8789
|
+
function readLightmapEntries(value, address) {
|
|
8790
|
+
const record = asRecord$1(value);
|
|
8791
|
+
if (record === null) throw invalid(address, "entries must be an object keyed by entity id");
|
|
8792
|
+
const entries = {};
|
|
8793
|
+
for (const id of Object.keys(record)) {
|
|
8794
|
+
const entry = asRecord$1(record[id]);
|
|
8795
|
+
const scale = entry === null ? null : readVec2(entry["scale"], IDENTITY_LIGHTMAP_PLACEMENT.scale, (n) => n > 0 && n <= MAX_PLACEMENT_MAGNITUDE);
|
|
8796
|
+
const offset = entry === null ? null : readVec2(entry["offset"], IDENTITY_LIGHTMAP_PLACEMENT.offset, (n) => Math.abs(n) <= MAX_PLACEMENT_MAGNITUDE);
|
|
8797
|
+
if (id === "" || scale === null || offset === null) throw invalid(address, `entries["${id}"] must be { scale?: { x, y }, offset?: { x, y } } with finite numbers, a scale above 0 and every component within ±${String(MAX_PLACEMENT_MAGNITUDE)}`);
|
|
8798
|
+
entries[id] = {
|
|
8799
|
+
scale,
|
|
8800
|
+
offset
|
|
8801
|
+
};
|
|
8802
|
+
}
|
|
8803
|
+
return entries;
|
|
8804
|
+
}
|
|
8805
|
+
/**
|
|
8806
|
+
* Whether a placement is the identity, which needs no atlas transform.
|
|
8807
|
+
*
|
|
8808
|
+
* @param placement - The placement.
|
|
8809
|
+
* @returns `true` for scale `(1, 1)` and offset `(0, 0)`.
|
|
8810
|
+
*
|
|
8811
|
+
* @internal
|
|
8812
|
+
*/
|
|
8813
|
+
function isIdentityLightmapPlacement(placement) {
|
|
8814
|
+
const { scale, offset } = placement;
|
|
8815
|
+
return scale.x === 1 && scale.y === 1 && offset.x === 0 && offset.y === 0;
|
|
8816
|
+
}
|
|
8817
|
+
/**
|
|
8818
|
+
* The largest magnitude a placement component may have. Atlas coordinates live near `0..1`; the
|
|
8819
|
+
* bound keeps every value well inside `f32`, since the placement is written into WGSL as a constant
|
|
8820
|
+
* and an out-of-range literal fails shader creation.
|
|
8821
|
+
*/
|
|
8822
|
+
const MAX_PLACEMENT_MAGNITUDE = 1e6;
|
|
8823
|
+
/**
|
|
8824
|
+
* Reads `{ x, y }` whose components are finite and pass a check, or takes a default when absent.
|
|
8825
|
+
*
|
|
8826
|
+
* @param value - The candidate, `undefined` when the field is absent.
|
|
8827
|
+
* @param fallback - The value an absent field takes.
|
|
8828
|
+
* @param check - The per-component test beyond finiteness.
|
|
8829
|
+
* @returns A copy, or `null` when it is malformed.
|
|
8830
|
+
*/
|
|
8831
|
+
function readVec2(value, fallback, check) {
|
|
8832
|
+
if (value === void 0) return {
|
|
8833
|
+
x: fallback.x,
|
|
8834
|
+
y: fallback.y
|
|
8835
|
+
};
|
|
8836
|
+
const record = asRecord$1(value);
|
|
8837
|
+
const x = record?.["x"];
|
|
8838
|
+
const y = record?.["y"];
|
|
8839
|
+
if (typeof x !== "number" || typeof y !== "number" || ![x, y].every((n) => Number.isFinite(n) && check(n))) return null;
|
|
8840
|
+
return {
|
|
8841
|
+
x,
|
|
8842
|
+
y
|
|
8843
|
+
};
|
|
8844
|
+
}
|
|
8845
|
+
/**
|
|
8846
|
+
* Narrows a value to a plain record.
|
|
8847
|
+
*
|
|
8848
|
+
* @param value - The candidate.
|
|
8849
|
+
* @returns The record, or `null` for anything else.
|
|
8850
|
+
*/
|
|
8851
|
+
function asRecord$1(value) {
|
|
8852
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return null;
|
|
8853
|
+
return value;
|
|
8854
|
+
}
|
|
8855
|
+
/**
|
|
8856
|
+
* The error for a malformed lightmap.
|
|
8857
|
+
*
|
|
8858
|
+
* @param address - Where it came from.
|
|
8859
|
+
* @param problem - What is wrong.
|
|
8860
|
+
* @returns The error.
|
|
8861
|
+
*/
|
|
8862
|
+
function invalid(address, problem) {
|
|
8863
|
+
return new IgnifxError(CoreErrorCode.invalidAssetFile, `${address} is not an ${LIGHTMAP_FILE_FORMAT} file.`, {
|
|
8864
|
+
context: {
|
|
8865
|
+
file: address,
|
|
8866
|
+
format: LIGHTMAP_FILE_FORMAT
|
|
8867
|
+
},
|
|
8868
|
+
hint: `Fix the file: ${problem}.`
|
|
8869
|
+
});
|
|
8870
|
+
}
|
|
8871
|
+
//#endregion
|
|
8872
|
+
//#region src/render/gpu/lightmap-host.ts
|
|
8873
|
+
/**
|
|
8874
|
+
* The renderer's handle on lightmaps (GI B3): it decides whether a `MeshRenderer` samples its
|
|
8875
|
+
* lightmap, loads the lightmap chunk (`./lightmaps.ts`) the first time one does, and hands the
|
|
8876
|
+
* renderer its lightmapped material. Device-only, like the rest of `src/render/gpu/`: only a
|
|
8877
|
+
* renderer with a clone in the scene asks.
|
|
8878
|
+
*
|
|
8879
|
+
* @internal
|
|
8880
|
+
*/
|
|
8881
|
+
var LightmapHost = class {
|
|
8882
|
+
#app;
|
|
8883
|
+
#scene;
|
|
8884
|
+
#onError;
|
|
8885
|
+
#runtime = null;
|
|
8886
|
+
#isLoading = false;
|
|
8887
|
+
#isDisposed = false;
|
|
8888
|
+
/** The last `IGX-0735` reason reported per renderer, so each is logged once. */
|
|
8889
|
+
#reported = /* @__PURE__ */ new WeakMap();
|
|
8890
|
+
/**
|
|
8891
|
+
* Creates the host; nothing loads until a renderer samples a lightmap.
|
|
8892
|
+
*
|
|
8893
|
+
* @param app - The app, for the clones and the log.
|
|
8894
|
+
* @param scene - The registered render scene.
|
|
8895
|
+
* @param onError - Where a failed chunk load goes.
|
|
8896
|
+
*/
|
|
8897
|
+
constructor(app, scene, onError) {
|
|
8898
|
+
this.#app = app;
|
|
8899
|
+
this.#scene = scene;
|
|
8900
|
+
this.#onError = onError;
|
|
8901
|
+
}
|
|
8902
|
+
/**
|
|
8903
|
+
* How many renderers draw with a lightmap right now.
|
|
8904
|
+
*
|
|
8905
|
+
* @returns The number of lightmapped clones.
|
|
8906
|
+
*/
|
|
8907
|
+
get count() {
|
|
8908
|
+
return this.#runtime?.count ?? 0;
|
|
8909
|
+
}
|
|
8910
|
+
/**
|
|
8911
|
+
* The material a renderer draws with this frame.
|
|
8912
|
+
*
|
|
8913
|
+
* @remarks
|
|
8914
|
+
* A renderer samples its lightmap when its `lightmap.asset` is loaded, its entity is static and its
|
|
8915
|
+
* material is PBR; otherwise it draws with `base`, and a static or PBR mismatch logs `IGX-0735`
|
|
8916
|
+
* once. Its entry's placement (scale and offset) moves its UV2 into its square of the atlas. A
|
|
8917
|
+
* placement other than the identity needs `uv2: true` and a mesh with `uvs2`, since the first UV
|
|
8918
|
+
* set also drives the material's own textures; without them it logs `IGX-0735` once and samples
|
|
8919
|
+
* the whole texture.
|
|
8920
|
+
*
|
|
8921
|
+
* @param owner - The renderer.
|
|
8922
|
+
* @param base - The material it declares (or the default material).
|
|
8923
|
+
* @returns The Lite material to draw with.
|
|
8924
|
+
*/
|
|
8925
|
+
materialFor(owner, base) {
|
|
8926
|
+
const settings = owner.lightmap;
|
|
8927
|
+
const handle = settings?.asset ?? null;
|
|
8928
|
+
const lightmap = handle !== null && handle.state === "loaded" ? handle.value : null;
|
|
8929
|
+
if (settings === null || lightmap === null || this.#isDisposed) {
|
|
8930
|
+
this.release(owner);
|
|
8931
|
+
return base.lite.material;
|
|
8932
|
+
}
|
|
8933
|
+
const entity = owner.entity;
|
|
8934
|
+
let problem = null;
|
|
8935
|
+
if (!entity.isStatic) problem = "its entity is not static (entity.isStatic)";
|
|
8936
|
+
else if (base.kind !== "pbr") problem = `its material is a ${base.kind} material; lightmaps need a pbr one`;
|
|
8937
|
+
if (problem !== null) {
|
|
8938
|
+
this.#report(owner, problem);
|
|
8939
|
+
this.release(owner);
|
|
8940
|
+
return base.lite.material;
|
|
8941
|
+
}
|
|
8942
|
+
const placement = lightmap.placementOf(entity.uid);
|
|
8943
|
+
let atlas = null;
|
|
8944
|
+
if (!isIdentityLightmapPlacement(placement)) {
|
|
8945
|
+
const mesh = owner.mesh;
|
|
8946
|
+
if (mesh === null || mesh.state !== "loaded") {
|
|
8947
|
+
this.release(owner);
|
|
8948
|
+
return base.lite.material;
|
|
8949
|
+
}
|
|
8950
|
+
if (!settings.uv2) this.#report(owner, "its lightmap entry has a scale or offset, which needs uv2: true (the first UV set also maps the material's textures); it samples the whole texture");
|
|
8951
|
+
else if (!hasSecondUvSet(owner)) this.#report(owner, "its lightmap entry has a scale or offset, but its mesh has no uvs2; it samples the whole texture with the first UV set");
|
|
8952
|
+
else atlas = placement;
|
|
8953
|
+
}
|
|
8954
|
+
const runtime = this.#runtime;
|
|
8955
|
+
if (runtime === null) {
|
|
8956
|
+
this.#load();
|
|
8957
|
+
return base.lite.material;
|
|
8958
|
+
}
|
|
8959
|
+
return runtime.materialFor(owner, base, lightmap, settings, atlas);
|
|
8960
|
+
}
|
|
8961
|
+
/**
|
|
8962
|
+
* Drops a renderer's lightmapped clone, if it has one.
|
|
8963
|
+
*
|
|
8964
|
+
* @param owner - The renderer.
|
|
8965
|
+
*/
|
|
8966
|
+
release(owner) {
|
|
8967
|
+
this.#runtime?.release(owner);
|
|
8968
|
+
}
|
|
8969
|
+
/** Rebuilds the clones made this frame; the renderer calls it after every `MeshRenderer` synced. */
|
|
8970
|
+
flush() {
|
|
8971
|
+
this.#runtime?.flush();
|
|
8972
|
+
}
|
|
8973
|
+
/** Drops every clone. Idempotent. */
|
|
8974
|
+
dispose() {
|
|
8975
|
+
this.#isDisposed = true;
|
|
8976
|
+
this.#runtime?.dispose();
|
|
8977
|
+
this.#runtime = null;
|
|
8978
|
+
}
|
|
8979
|
+
/** Loads the chunk once. */
|
|
8980
|
+
#load() {
|
|
8981
|
+
if (this.#isLoading || this.#isDisposed) return;
|
|
8982
|
+
this.#isLoading = true;
|
|
8983
|
+
import("./lightmaps-BUUIIkt9.js").then((module) => module.createLightmapRuntime(this.#app, this.#scene)).then((created) => {
|
|
8984
|
+
if (this.#isDisposed) {
|
|
8985
|
+
created.dispose();
|
|
8986
|
+
return;
|
|
8987
|
+
}
|
|
8988
|
+
this.#runtime = created;
|
|
8989
|
+
}).catch(this.#onError);
|
|
8990
|
+
}
|
|
8991
|
+
/**
|
|
8992
|
+
* Logs `IGX-0735` for a renderer, once per distinct reason.
|
|
8993
|
+
*
|
|
8994
|
+
* @param owner - The renderer.
|
|
8995
|
+
* @param problem - Why its lightmap is not drawn as declared.
|
|
8996
|
+
*/
|
|
8997
|
+
#report(owner, problem) {
|
|
8998
|
+
if (this.#reported.get(owner) === problem) return;
|
|
8999
|
+
this.#reported.set(owner, problem);
|
|
9000
|
+
this.#app.log.warn(`${CoreErrorCode.lightmapNotApplied}: the MeshRenderer lightmap of ${JSON.stringify(owner.entity.name)}: ${problem}.`);
|
|
9001
|
+
}
|
|
9002
|
+
};
|
|
9003
|
+
/**
|
|
9004
|
+
* Whether a renderer's mesh has a second UV set, which Lite turns into the `uv2` varying an atlas
|
|
9005
|
+
* placement rewrites.
|
|
9006
|
+
*
|
|
9007
|
+
* @remarks
|
|
9008
|
+
* Only a mesh built with `MeshAsset.fromData` and `uvs2` has one; Lite's primitives make none.
|
|
9009
|
+
*
|
|
9010
|
+
* @param owner - The renderer.
|
|
9011
|
+
* @returns `true` when its loaded mesh carries `uvs2`.
|
|
9012
|
+
*/
|
|
9013
|
+
function hasSecondUvSet(owner) {
|
|
9014
|
+
const mesh = owner.mesh;
|
|
9015
|
+
const uvs2 = mesh?.state === "loaded" ? mesh.value.cpuGeometry?.uvs2 : void 0;
|
|
9016
|
+
return uvs2 !== void 0 && uvs2.length > 0;
|
|
9017
|
+
}
|
|
9018
|
+
//#endregion
|
|
8604
9019
|
//#region src/render/gpu/reflection-probe-host.ts
|
|
8605
9020
|
/**
|
|
8606
9021
|
* The renderer's handle on reflection probes (GI B1): it loads the probe chunk
|
|
@@ -8613,20 +9028,25 @@ var ReflectionProbeHost = class {
|
|
|
8613
9028
|
#engine;
|
|
8614
9029
|
#scene;
|
|
8615
9030
|
#onError;
|
|
9031
|
+
#warn;
|
|
8616
9032
|
#runtime = null;
|
|
8617
9033
|
#isLoading = false;
|
|
8618
9034
|
#isDisposed = false;
|
|
9035
|
+
/** Set from a device loss until Lite's recovery; no frame work runs in between. */
|
|
9036
|
+
#isDeviceLost = false;
|
|
8619
9037
|
/**
|
|
8620
9038
|
* Creates the host; nothing loads until a probe exists.
|
|
8621
9039
|
*
|
|
8622
9040
|
* @param engine - The engine.
|
|
8623
9041
|
* @param scene - The registered render scene.
|
|
8624
9042
|
* @param onError - Where a failed chunk load goes.
|
|
9043
|
+
* @param warn - Where a probe's warning goes, with the entity's name already in the message.
|
|
8625
9044
|
*/
|
|
8626
|
-
constructor(engine, scene, onError) {
|
|
9045
|
+
constructor(engine, scene, onError, warn) {
|
|
8627
9046
|
this.#engine = engine;
|
|
8628
9047
|
this.#scene = scene;
|
|
8629
9048
|
this.#onError = onError;
|
|
9049
|
+
this.#warn = warn;
|
|
8630
9050
|
}
|
|
8631
9051
|
/**
|
|
8632
9052
|
* Whether the chunk is loaded and running.
|
|
@@ -8642,15 +9062,19 @@ var ReflectionProbeHost = class {
|
|
|
8642
9062
|
* @param world - The world.
|
|
8643
9063
|
* @param probes - Every `ReflectionProbe` in it.
|
|
8644
9064
|
* @param isHdr - Whether `rendering.hdr` is on.
|
|
9065
|
+
* @param tier - The `rendering.quality` preset; `null` for `"custom"`.
|
|
9066
|
+
* @param hasEnvironment - Whether the scene has an environment map; until it has, the chunk is
|
|
9067
|
+
* not even loaded, since a probe needs the map's lighting tables.
|
|
8645
9068
|
*/
|
|
8646
|
-
update(world, probes, isHdr) {
|
|
9069
|
+
update(world, probes, isHdr, tier, hasEnvironment) {
|
|
9070
|
+
if (this.#isDeviceLost) return;
|
|
8647
9071
|
if (this.#runtime !== null) {
|
|
8648
|
-
this.#runtime.update(world, probes, isHdr);
|
|
9072
|
+
this.#runtime.update(world, probes, isHdr, tier, hasEnvironment);
|
|
8649
9073
|
return;
|
|
8650
9074
|
}
|
|
8651
|
-
if (probes.length === 0 || this.#isLoading || this.#isDisposed) return;
|
|
9075
|
+
if (probes.length === 0 || !hasEnvironment || this.#isLoading || this.#isDisposed) return;
|
|
8652
9076
|
this.#isLoading = true;
|
|
8653
|
-
import("./reflection-probes-
|
|
9077
|
+
import("./reflection-probes-CAzSuqf8.js").then(async (module) => module.createReflectionProbeRuntime(this.#engine, this.#scene, this.#warn)).then((created) => {
|
|
8654
9078
|
if (this.#isDisposed) {
|
|
8655
9079
|
created.dispose();
|
|
8656
9080
|
return;
|
|
@@ -8658,6 +9082,19 @@ var ReflectionProbeHost = class {
|
|
|
8658
9082
|
this.#runtime = created;
|
|
8659
9083
|
}).catch(this.#onError);
|
|
8660
9084
|
}
|
|
9085
|
+
/**
|
|
9086
|
+
* Drops the probes' GPU state when the device is lost (`app.events.onDeviceLost`), before Lite's
|
|
9087
|
+
* recovery rebuilds the materials; they capture again once frames resume.
|
|
9088
|
+
*/
|
|
9089
|
+
handleDeviceLost() {
|
|
9090
|
+
this.#isDeviceLost = true;
|
|
9091
|
+
this.#runtime?.handleDeviceLost();
|
|
9092
|
+
}
|
|
9093
|
+
/** Resumes probe work once Lite rebuilt the scene (`app.events.onDeviceRecovered`). */
|
|
9094
|
+
handleDeviceRecovered() {
|
|
9095
|
+
this.#isDeviceLost = false;
|
|
9096
|
+
this.#runtime?.handleDeviceRecovered();
|
|
9097
|
+
}
|
|
8661
9098
|
/** Frees every probe. Idempotent. */
|
|
8662
9099
|
dispose() {
|
|
8663
9100
|
this.#isDisposed = true;
|
|
@@ -9103,9 +9540,14 @@ const AMBIENT_OCCLUSION_QUALITIES = ["half", "full"];
|
|
|
9103
9540
|
*
|
|
9104
9541
|
* @remarks
|
|
9105
9542
|
* - `"custom"` (default): every effect is exactly as the section and the `PostProcessStack`s say.
|
|
9106
|
-
* - `"low"`: GTAO at half resolution; no HDR, TAA, contact shadows or SSGI
|
|
9107
|
-
*
|
|
9108
|
-
* - `"
|
|
9543
|
+
* - `"low"`: GTAO at half resolution; no HDR, TAA, contact shadows or SSGI; reflection probes at
|
|
9544
|
+
* 64 pixels a face at most.
|
|
9545
|
+
* - `"medium"`: adds HDR and TAA, lets a stack run contact shadows, and reflection probes up to 128.
|
|
9546
|
+
* - `"high"`: GTAO at full resolution, lets a stack run SSGI, reflection probes up to 256, and lets
|
|
9547
|
+
* a probe capture every frame.
|
|
9548
|
+
*
|
|
9549
|
+
* Below `"high"`, a `ReflectionProbe` with `refreshMode: "everyFrame"` captures as `"once"`.
|
|
9550
|
+
* Light probes and lightmaps run at every tier.
|
|
9109
9551
|
*
|
|
9110
9552
|
* @public
|
|
9111
9553
|
*/
|
|
@@ -9115,7 +9557,10 @@ const RENDERING_QUALITIES = [
|
|
|
9115
9557
|
"medium",
|
|
9116
9558
|
"high"
|
|
9117
9559
|
];
|
|
9118
|
-
/**
|
|
9560
|
+
/**
|
|
9561
|
+
* The presets of the three named tiers; `"custom"` has none. Bloom and tone mapping stay as authored.
|
|
9562
|
+
* Light probes and lightmaps run at every tier: baked lighting is the low-end path.
|
|
9563
|
+
*/
|
|
9119
9564
|
const QUALITY_PRESETS = {
|
|
9120
9565
|
low: {
|
|
9121
9566
|
hdr: false,
|
|
@@ -9123,7 +9568,9 @@ const QUALITY_PRESETS = {
|
|
|
9123
9568
|
ambientOcclusion: true,
|
|
9124
9569
|
ambientOcclusionQuality: "half",
|
|
9125
9570
|
contactShadows: false,
|
|
9126
|
-
ssgi: false
|
|
9571
|
+
ssgi: false,
|
|
9572
|
+
reflectionProbeMaxSize: 64,
|
|
9573
|
+
reflectionProbeEveryFrame: false
|
|
9127
9574
|
},
|
|
9128
9575
|
medium: {
|
|
9129
9576
|
hdr: true,
|
|
@@ -9131,7 +9578,9 @@ const QUALITY_PRESETS = {
|
|
|
9131
9578
|
ambientOcclusion: true,
|
|
9132
9579
|
ambientOcclusionQuality: "half",
|
|
9133
9580
|
contactShadows: true,
|
|
9134
|
-
ssgi: false
|
|
9581
|
+
ssgi: false,
|
|
9582
|
+
reflectionProbeMaxSize: 128,
|
|
9583
|
+
reflectionProbeEveryFrame: false
|
|
9135
9584
|
},
|
|
9136
9585
|
high: {
|
|
9137
9586
|
hdr: true,
|
|
@@ -9139,7 +9588,9 @@ const QUALITY_PRESETS = {
|
|
|
9139
9588
|
ambientOcclusion: true,
|
|
9140
9589
|
ambientOcclusionQuality: "full",
|
|
9141
9590
|
contactShadows: true,
|
|
9142
|
-
ssgi: true
|
|
9591
|
+
ssgi: true,
|
|
9592
|
+
reflectionProbeMaxSize: 256,
|
|
9593
|
+
reflectionProbeEveryFrame: true
|
|
9143
9594
|
}
|
|
9144
9595
|
};
|
|
9145
9596
|
/**
|
|
@@ -9346,7 +9797,7 @@ function renderingSettingsSchema() {
|
|
|
9346
9797
|
tooltip: "Camera jump per frame, in world units, that resets history."
|
|
9347
9798
|
})
|
|
9348
9799
|
}, { tooltip: "Temporal anti-aliasing (jittered frames accumulated over time). Needs rendering.hdr." }),
|
|
9349
|
-
quality: enumOf(RENDERING_QUALITIES, "custom", { tooltip: "Quality tier. low: half-res GTAO. medium: adds HDR, TAA, contact shadows. high: full-res GTAO, SSGI. custom: as set. Fields you set win." })
|
|
9800
|
+
quality: enumOf(RENDERING_QUALITIES, "custom", { tooltip: "Quality tier. low: half-res GTAO, 64 px reflection probes. medium: adds HDR, TAA, contact shadows, 128 px probes. high: full-res GTAO, SSGI, 256 px probes, everyFrame probes. custom: as set. Fields you set win." })
|
|
9350
9801
|
});
|
|
9351
9802
|
}
|
|
9352
9803
|
/**
|
|
@@ -9717,8 +10168,12 @@ var RendererImpl = class {
|
|
|
9717
10168
|
#ambientOcclusion = null;
|
|
9718
10169
|
/** The reflection probes' host, created on the first frame of a canvas-backed app (GI B1). */
|
|
9719
10170
|
#reflectionProbes = null;
|
|
10171
|
+
/** Detaches the reflection probes' `onDeviceLost` and `onDeviceRecovered` handlers. */
|
|
10172
|
+
#disconnectProbeDeviceLoss = null;
|
|
9720
10173
|
/** The light probes' host, created with the reflection probes' one (GI B2). */
|
|
9721
10174
|
#lightProbes = null;
|
|
10175
|
+
/** The lightmaps' host, created when the first renderer with a clone asks for its material (GI B3). */
|
|
10176
|
+
#lightmaps = null;
|
|
9722
10177
|
/** The TAA passes (`../lite/gpu/taa.ts`), when `rendering.taa` installed them. */
|
|
9723
10178
|
#taa = null;
|
|
9724
10179
|
#defaultMaterial = null;
|
|
@@ -10511,7 +10966,7 @@ var RendererImpl = class {
|
|
|
10511
10966
|
*/
|
|
10512
10967
|
async #installAmbientOcclusion() {
|
|
10513
10968
|
const settings = resolveAmbientOcclusion(this.settings.ambientOcclusion);
|
|
10514
|
-
const [module, inputs] = await Promise.all([import("./gtao-
|
|
10969
|
+
const [module, inputs] = await Promise.all([import("./gtao-Bpu5-0Ne.js"), this.acquireSceneInputs()]);
|
|
10515
10970
|
if (inputs === null) return;
|
|
10516
10971
|
if (this.#isDisposed) {
|
|
10517
10972
|
inputs.release();
|
|
@@ -10550,7 +11005,8 @@ var RendererImpl = class {
|
|
|
10550
11005
|
/**
|
|
10551
11006
|
* The baked-lighting components' per-frame work (GI Phase 2): `ReflectionProbe` (B1) captures
|
|
10552
11007
|
* what is due and points each lit PBR material at its probe; `LightProbeVolume` (B2) keeps the
|
|
10553
|
-
* winning grid on every lit PBR material
|
|
11008
|
+
* winning grid on every lit PBR material; lightmaps (B3) rebuild the material copies the
|
|
11009
|
+
* `MeshRenderer`s took this frame. Each loads its own chunk the first time a world has one
|
|
10554
11010
|
* of its components. The `PreRender` system calls it every frame; it does nothing on a headless
|
|
10555
11011
|
* app.
|
|
10556
11012
|
*
|
|
@@ -10581,10 +11037,69 @@ var RendererImpl = class {
|
|
|
10581
11037
|
component: null
|
|
10582
11038
|
});
|
|
10583
11039
|
};
|
|
10584
|
-
this.#reflectionProbes
|
|
11040
|
+
if (this.#reflectionProbes === null) {
|
|
11041
|
+
const host = new ReflectionProbeHost(this.engine, this.scene, onError, (message) => {
|
|
11042
|
+
this.#app.log.warn(message);
|
|
11043
|
+
});
|
|
11044
|
+
this.#reflectionProbes = host;
|
|
11045
|
+
const disconnectLost = this.#app.events.onDeviceLost.connect(() => {
|
|
11046
|
+
host.handleDeviceLost();
|
|
11047
|
+
});
|
|
11048
|
+
const disconnectRecovered = this.#app.events.onDeviceRecovered.connect(() => {
|
|
11049
|
+
host.handleDeviceRecovered();
|
|
11050
|
+
});
|
|
11051
|
+
this.#disconnectProbeDeviceLoss = () => {
|
|
11052
|
+
disconnectLost();
|
|
11053
|
+
disconnectRecovered();
|
|
11054
|
+
};
|
|
11055
|
+
}
|
|
10585
11056
|
this.#lightProbes ??= new LightProbeHost(this.engine, this.scene, onError);
|
|
10586
|
-
this.#reflectionProbes.update(world, probes, (this.#presenter?.hdr ?? null) !== null);
|
|
11057
|
+
this.#reflectionProbes.update(world, probes, (this.#presenter?.hdr ?? null) !== null, this.qualityPreset, readSceneEnvironment(this.scene) !== null);
|
|
10587
11058
|
this.#lightProbes.update(volumes);
|
|
11059
|
+
this.#lightmaps?.flush();
|
|
11060
|
+
}
|
|
11061
|
+
/**
|
|
11062
|
+
* The material a `MeshRenderer` draws with this frame: its own lightmapped copy of `base` when it
|
|
11063
|
+
* samples a lightmap (GI B3), else `base`'s. Only a renderer with a clone in the scene asks, so
|
|
11064
|
+
* never a headless one.
|
|
11065
|
+
*
|
|
11066
|
+
* @param owner - The renderer.
|
|
11067
|
+
* @param base - The material asset it declares, or the default material.
|
|
11068
|
+
* @returns The Lite material.
|
|
11069
|
+
*
|
|
11070
|
+
* @internal
|
|
11071
|
+
*/
|
|
11072
|
+
lightmapMaterial(owner, base) {
|
|
11073
|
+
this.#lightmaps ??= new LightmapHost(this.#app, this.scene, (error) => {
|
|
11074
|
+
this.#app.onError.emit({
|
|
11075
|
+
error,
|
|
11076
|
+
source: "system",
|
|
11077
|
+
phase: null,
|
|
11078
|
+
entity: null,
|
|
11079
|
+
component: null
|
|
11080
|
+
});
|
|
11081
|
+
});
|
|
11082
|
+
return this.#lightmaps.materialFor(owner, base);
|
|
11083
|
+
}
|
|
11084
|
+
/**
|
|
11085
|
+
* Drops a `MeshRenderer`'s lightmapped material copy, if it has one.
|
|
11086
|
+
*
|
|
11087
|
+
* @param owner - The renderer.
|
|
11088
|
+
*
|
|
11089
|
+
* @internal
|
|
11090
|
+
*/
|
|
11091
|
+
releaseLightmap(owner) {
|
|
11092
|
+
this.#lightmaps?.release(owner);
|
|
11093
|
+
}
|
|
11094
|
+
/**
|
|
11095
|
+
* The lightmaps' host, for tests and diagnostics.
|
|
11096
|
+
*
|
|
11097
|
+
* @returns The host, or `null` before a renderer asked for a material.
|
|
11098
|
+
*
|
|
11099
|
+
* @internal
|
|
11100
|
+
*/
|
|
11101
|
+
get lightmapHost() {
|
|
11102
|
+
return this.#lightmaps;
|
|
10588
11103
|
}
|
|
10589
11104
|
/**
|
|
10590
11105
|
* The light probes' host, for tests and diagnostics.
|
|
@@ -10841,10 +11356,14 @@ var RendererImpl = class {
|
|
|
10841
11356
|
this.#afterRebuild.length = 0;
|
|
10842
11357
|
this.#ambientOcclusion?.dispose();
|
|
10843
11358
|
this.#ambientOcclusion = null;
|
|
11359
|
+
this.#disconnectProbeDeviceLoss?.();
|
|
11360
|
+
this.#disconnectProbeDeviceLoss = null;
|
|
10844
11361
|
this.#reflectionProbes?.dispose();
|
|
10845
11362
|
this.#reflectionProbes = null;
|
|
10846
11363
|
this.#lightProbes?.dispose();
|
|
10847
11364
|
this.#lightProbes = null;
|
|
11365
|
+
this.#lightmaps?.dispose();
|
|
11366
|
+
this.#lightmaps = null;
|
|
10848
11367
|
this.#sceneInputsHost?.dispose();
|
|
10849
11368
|
this.#sceneInputsHost = null;
|
|
10850
11369
|
this.#taa = null;
|
|
@@ -11233,7 +11752,7 @@ var InstancedMeshRenderer = class InstancedMeshRenderer extends Component {
|
|
|
11233
11752
|
#warnAboutLateSetting(field) {
|
|
11234
11753
|
if (this.#hasWarnedAboutLateSetting) return;
|
|
11235
11754
|
this.#hasWarnedAboutLateSetting = true;
|
|
11236
|
-
this.app.log.warn(`${CoreErrorCode.instancingSettingTooLate}: {entity} changed {field} on an InstancedMeshRenderer after the scene was registered; the value in use was kept. Set capacity, gpuCulling and lod.mesh before app.start()
|
|
11755
|
+
this.app.log.warn(`${CoreErrorCode.instancingSettingTooLate}: ${JSON.stringify(this.entity.name)} changed ${field} on an InstancedMeshRenderer after the scene was registered; the value in use was kept. Set capacity, gpuCulling and lod.mesh before app.start().`);
|
|
11237
11756
|
}
|
|
11238
11757
|
/**
|
|
11239
11758
|
* Says once, at warning level, that a LOD partner was declared with GPU culling off. Lite picks
|
|
@@ -11244,7 +11763,7 @@ var InstancedMeshRenderer = class InstancedMeshRenderer extends Component {
|
|
|
11244
11763
|
#warnAboutLodWithoutCulling(lod) {
|
|
11245
11764
|
if (this.#hasWarnedAboutLodWithoutCulling || this.gpuCulling || lod === null || lod.mesh === null) return;
|
|
11246
11765
|
this.#hasWarnedAboutLodWithoutCulling = true;
|
|
11247
|
-
this.app.log.warn(`${CoreErrorCode.instancingLodWithoutCulling}: {entity} declares an InstancedMeshRenderer lod with gpuCulling off; the LOD mesh never draws. Turn gpuCulling on
|
|
11766
|
+
this.app.log.warn(`${CoreErrorCode.instancingLodWithoutCulling}: ${JSON.stringify(this.entity.name)} declares an InstancedMeshRenderer lod with gpuCulling off; the LOD mesh never draws. Turn gpuCulling on.`);
|
|
11248
11767
|
}
|
|
11249
11768
|
/**
|
|
11250
11769
|
* Builds or rebuilds the meshes when the template or a baked setting changed.
|
|
@@ -12113,6 +12632,16 @@ const LIGHT_TYPES = [
|
|
|
12113
12632
|
"spot",
|
|
12114
12633
|
"hemispheric"
|
|
12115
12634
|
];
|
|
12635
|
+
/**
|
|
12636
|
+
* How a light takes part in baked lighting (`docs/architecture/07-rendering.md` §2.15).
|
|
12637
|
+
*
|
|
12638
|
+
* @beta
|
|
12639
|
+
*/
|
|
12640
|
+
const LIGHT_BAKE_MODES = [
|
|
12641
|
+
"realtime",
|
|
12642
|
+
"mixed",
|
|
12643
|
+
"baked"
|
|
12644
|
+
];
|
|
12116
12645
|
/** How many elements a 4x4 matrix has. */
|
|
12117
12646
|
const MATRIX_LENGTH$1 = 16;
|
|
12118
12647
|
/** Where the world-space up axis starts inside a column-major world matrix. */
|
|
@@ -12131,6 +12660,8 @@ const TRANSLATION_COLUMN = 12;
|
|
|
12131
12660
|
*
|
|
12132
12661
|
* A disabled light, or one on an inactive entity, contributes nothing: its intensity reaches Lite
|
|
12133
12662
|
* as `0` and its shadow generator is released. Enabling it again restores both on the next frame.
|
|
12663
|
+
* A light whose `bakeMode` is `"baked"` is dimmed the same way: its light reaches the scene only
|
|
12664
|
+
* through a light-probe bake (`bakeLightProbes`).
|
|
12134
12665
|
*
|
|
12135
12666
|
* @example
|
|
12136
12667
|
* ```ts
|
|
@@ -12308,7 +12839,8 @@ var Light = class Light extends Component {
|
|
|
12308
12839
|
}
|
|
12309
12840
|
}
|
|
12310
12841
|
/**
|
|
12311
|
-
* The intensity Lite should use: the field, or `0` while the component or its entity is disabled
|
|
12842
|
+
* The intensity Lite should use: the field, or `0` while the component or its entity is disabled
|
|
12843
|
+
* or the light is `"baked"`.
|
|
12312
12844
|
*
|
|
12313
12845
|
* @remarks
|
|
12314
12846
|
* Dimming keeps the light in the scene. Removing it would change the light count every compiled
|
|
@@ -12317,7 +12849,7 @@ var Light = class Light extends Component {
|
|
|
12317
12849
|
* @returns The intensity to apply.
|
|
12318
12850
|
*/
|
|
12319
12851
|
#effectiveIntensity() {
|
|
12320
|
-
return this.isEnabledInHierarchy ? this.intensity : 0;
|
|
12852
|
+
return this.isEnabledInHierarchy && this.bakeMode !== "baked" ? this.intensity : 0;
|
|
12321
12853
|
}
|
|
12322
12854
|
/**
|
|
12323
12855
|
* Rebuilds the include and exclude mesh-id sets when either list changed length.
|
|
@@ -12351,7 +12883,7 @@ var Light = class Light extends Component {
|
|
|
12351
12883
|
*/
|
|
12352
12884
|
#applyShadows(renderer) {
|
|
12353
12885
|
const light = this.#light;
|
|
12354
|
-
const wanted = this.shadows.enabled && this.isEnabledInHierarchy && renderer.features.shadows && !renderer.isHeadless;
|
|
12886
|
+
const wanted = this.shadows.enabled && this.isEnabledInHierarchy && this.bakeMode !== "baked" && renderer.features.shadows && !renderer.isHeadless;
|
|
12355
12887
|
const isStale = wanted && !sameShadowSettings(this.#appliedShadowSettings, this.shadows);
|
|
12356
12888
|
if (light === null || wanted === this.#appliedShadows && !isStale) {
|
|
12357
12889
|
this.#warnAboutShadows(renderer);
|
|
@@ -12374,7 +12906,7 @@ var Light = class Light extends Component {
|
|
|
12374
12906
|
#warnAboutShadows(renderer) {
|
|
12375
12907
|
if (this.#hasWarnedAboutShadows || !this.shadows.enabled || renderer.features.shadows) return;
|
|
12376
12908
|
this.#hasWarnedAboutShadows = true;
|
|
12377
|
-
renderer.app.log.warn(
|
|
12909
|
+
renderer.app.log.warn(`${JSON.stringify(this.entity.name)} asks for shadows, but the rendering.features.shadows opt-in is off, so it casts none.`);
|
|
12378
12910
|
}
|
|
12379
12911
|
/**
|
|
12380
12912
|
* Writes the entity's world pose onto the unparented Lite light, in any frame in which the entity
|
|
@@ -12584,7 +13116,8 @@ function lightSchema() {
|
|
|
12584
13116
|
})
|
|
12585
13117
|
}, { tooltip: "Shadow casting; point and hemispheric lights cannot cast (IGX-0703)." }),
|
|
12586
13118
|
includeOnly: array(entityRef(), [], { tooltip: "Light only these entities' renderers." }),
|
|
12587
|
-
exclude: array(entityRef(), [], { tooltip: "Never light these entities' renderers." })
|
|
13119
|
+
exclude: array(entityRef(), [], { tooltip: "Never light these entities' renderers." }),
|
|
13120
|
+
bakeMode: enumOf(LIGHT_BAKE_MODES, "realtime", { tooltip: "Baked lighting: realtime and mixed draw at run time (a probe bake keeps their bounce); baked draws only through the bake." })
|
|
12588
13121
|
});
|
|
12589
13122
|
}
|
|
12590
13123
|
//#endregion
|
|
@@ -12913,6 +13446,623 @@ function createLightProbeLoader() {
|
|
|
12913
13446
|
};
|
|
12914
13447
|
}
|
|
12915
13448
|
//#endregion
|
|
13449
|
+
//#region src/lite/gpu/texture.ts
|
|
13450
|
+
/**
|
|
13451
|
+
* Loads a 2D texture from a URL.
|
|
13452
|
+
*
|
|
13453
|
+
* @param engine - The engine that owns the GPU texture.
|
|
13454
|
+
* @param url - Where to fetch it from.
|
|
13455
|
+
* @param options - Sampler, mipmap, colour-space, and decode options.
|
|
13456
|
+
* @returns The texture. Its reference count starts at an implicit one.
|
|
13457
|
+
*
|
|
13458
|
+
* @example
|
|
13459
|
+
* ```ts
|
|
13460
|
+
* const albedo = await loadTexture(engine, "textures/hero-albedo.png", { srgb: true });
|
|
13461
|
+
* ```
|
|
13462
|
+
*
|
|
13463
|
+
* @internal
|
|
13464
|
+
*/
|
|
13465
|
+
function loadTexture(engine, url, options) {
|
|
13466
|
+
return loadTexture2D(engine, url, options);
|
|
13467
|
+
}
|
|
13468
|
+
/**
|
|
13469
|
+
* Loads a KTX2 (Basis Universal) texture from a URL, transcoded to the device's best compressed
|
|
13470
|
+
* format.
|
|
13471
|
+
*
|
|
13472
|
+
* @remarks
|
|
13473
|
+
* Lite's KTX2 glue is imported on first use (`./decoders.ts`), so a game that never loads a `.ktx2`
|
|
13474
|
+
* does not carry it. The decoder script and its transcoders load from wherever
|
|
13475
|
+
* `applyLiteDecoderUrls` last pointed Lite, or from `cdn.babylonjs.com` when nothing did. Sampler and
|
|
13476
|
+
* sRGB options apply; `mipMaps`, `invertY` and `premultiplyAlpha` do not — the file's rows and mips
|
|
13477
|
+
* are uploaded as stored (`./decoders.ts` explains the orientation).
|
|
13478
|
+
*
|
|
13479
|
+
* @param engine - The engine that owns the GPU texture.
|
|
13480
|
+
* @param url - Where to fetch it from.
|
|
13481
|
+
* @param options - Colour space and sampler.
|
|
13482
|
+
* @returns The texture. Its reference count starts at an implicit one.
|
|
13483
|
+
*
|
|
13484
|
+
* @example
|
|
13485
|
+
* ```ts
|
|
13486
|
+
* const albedo = await loadKtx2Texture(engine, "textures/hero-albedo.ktx2", { srgb: true });
|
|
13487
|
+
* ```
|
|
13488
|
+
*
|
|
13489
|
+
* @internal
|
|
13490
|
+
*/
|
|
13491
|
+
async function loadKtx2Texture(engine, url, options = {}) {
|
|
13492
|
+
return (await import("./decoders-BUQrlS8U.js")).loadKtx2TextureWithOptions(engine, url, options);
|
|
13493
|
+
}
|
|
13494
|
+
/**
|
|
13495
|
+
* Loads a Basis Universal (`.basis`) texture from a URL.
|
|
13496
|
+
*
|
|
13497
|
+
* @remarks
|
|
13498
|
+
* Babylon Lite 1.34 always fetches the Basis transcoder from `cdn.babylonjs.com` and offers no
|
|
13499
|
+
* setter for it, so this works only where the page may load scripts from that origin. Prefer
|
|
13500
|
+
* `.ktx2`, which carries the same Basis payloads and whose decoder is served locally.
|
|
13501
|
+
*
|
|
13502
|
+
* @param engine - The engine that owns the GPU texture.
|
|
13503
|
+
* @param url - Where to fetch it from.
|
|
13504
|
+
* @param options - Colour space and sampler.
|
|
13505
|
+
* @returns The texture.
|
|
13506
|
+
*
|
|
13507
|
+
* @internal
|
|
13508
|
+
*/
|
|
13509
|
+
async function loadBasisTexture(engine, url, options = {}) {
|
|
13510
|
+
return (await import("./decoders-BUQrlS8U.js")).loadBasisTextureWithOptions(engine, url, options);
|
|
13511
|
+
}
|
|
13512
|
+
/**
|
|
13513
|
+
* Creates a 2D texture from tightly packed RGBA8 bytes.
|
|
13514
|
+
*
|
|
13515
|
+
* @param engine - The engine that owns the GPU texture.
|
|
13516
|
+
* @param data - `width * height * 4` bytes, row-major, top row first, straight alpha.
|
|
13517
|
+
* @param width - The width in texels, at least 1.
|
|
13518
|
+
* @param height - The height in texels, at least 1.
|
|
13519
|
+
* @param options - Sampler and colour-space overrides.
|
|
13520
|
+
* @returns The texture, created with `COPY_DST` so {@link updateTextureFromPixels} can write to it.
|
|
13521
|
+
* Its reference count starts at an implicit one.
|
|
13522
|
+
*
|
|
13523
|
+
* @internal
|
|
13524
|
+
*/
|
|
13525
|
+
function createTextureFromPixels(engine, data, width, height, options) {
|
|
13526
|
+
return createTexture2DFromPixels(engine, data, width, height, {
|
|
13527
|
+
addressModeU: options.addressModeU,
|
|
13528
|
+
addressModeV: options.addressModeV,
|
|
13529
|
+
minFilter: options.minFilter,
|
|
13530
|
+
magFilter: options.magFilter,
|
|
13531
|
+
srgb: options.srgb
|
|
13532
|
+
});
|
|
13533
|
+
}
|
|
13534
|
+
/**
|
|
13535
|
+
* Writes a rectangular region of a pixel texture.
|
|
13536
|
+
*
|
|
13537
|
+
* @remarks
|
|
13538
|
+
* Only legal on a texture from {@link createTextureFromPixels}: any other `Texture2D` was created
|
|
13539
|
+
* without `COPY_DST` usage and WebGPU rejects the write.
|
|
13540
|
+
*
|
|
13541
|
+
* @param engine - The engine that owns the texture.
|
|
13542
|
+
* @param texture - The target.
|
|
13543
|
+
* @param data - `width * height * 4` bytes for the region, row-major.
|
|
13544
|
+
* @param x - The destination origin's column, in texels.
|
|
13545
|
+
* @param y - The destination origin's row, in texels.
|
|
13546
|
+
* @param width - The region's width, in texels.
|
|
13547
|
+
* @param height - The region's height, in texels.
|
|
13548
|
+
*
|
|
13549
|
+
* @internal
|
|
13550
|
+
*/
|
|
13551
|
+
function updateTextureFromPixels(engine, texture, data, x, y, width, height) {
|
|
13552
|
+
updateTexture2DFromPixels(engine, texture, data, x, y, width, height);
|
|
13553
|
+
}
|
|
13554
|
+
/**
|
|
13555
|
+
* Claims a share of a texture, so a later {@link releaseTextureHandle} by someone else does not
|
|
13556
|
+
* destroy it.
|
|
13557
|
+
*
|
|
13558
|
+
* @param texture - The texture to retain.
|
|
13559
|
+
*
|
|
13560
|
+
* @internal
|
|
13561
|
+
*/
|
|
13562
|
+
function retainTexture(texture) {
|
|
13563
|
+
acquireTexture(texture);
|
|
13564
|
+
}
|
|
13565
|
+
/**
|
|
13566
|
+
* Gives up a share of a texture, destroying it when the last share goes.
|
|
13567
|
+
*
|
|
13568
|
+
* @param texture - The texture to release.
|
|
13569
|
+
* @returns `true` when this call destroyed the underlying `GPUTexture`.
|
|
13570
|
+
*
|
|
13571
|
+
* @internal
|
|
13572
|
+
*/
|
|
13573
|
+
function releaseTextureHandle(texture) {
|
|
13574
|
+
return releaseTexture(texture);
|
|
13575
|
+
}
|
|
13576
|
+
//#endregion
|
|
13577
|
+
//#region src/render/gpu/texture-pixels.ts
|
|
13578
|
+
/**
|
|
13579
|
+
* The device-only half of `TextureAsset` (`docs/architecture/07-rendering.md` §6).
|
|
13580
|
+
*
|
|
13581
|
+
* Each function takes the engine or the texture as a nullable and returns early when it is `null`,
|
|
13582
|
+
* so the asset keeps no headless branch of its own.
|
|
13583
|
+
*/
|
|
13584
|
+
/**
|
|
13585
|
+
* Creates a texture from tightly packed RGBA8 bytes, or nothing under a headless app.
|
|
13586
|
+
*
|
|
13587
|
+
* @param isHeadless - Whether the app has a device.
|
|
13588
|
+
* @param engine - The engine that uploads it.
|
|
13589
|
+
* @param data - `width * height * 4` bytes, row-major, top row first, straight alpha.
|
|
13590
|
+
* @param width - The width in texels.
|
|
13591
|
+
* @param height - The height in texels.
|
|
13592
|
+
* @param options - The resolved import options; only the sampler subset reaches Lite.
|
|
13593
|
+
* @returns The texture, or `null`.
|
|
13594
|
+
*
|
|
13595
|
+
* @internal
|
|
13596
|
+
*/
|
|
13597
|
+
function createPixelTexture(isHeadless, engine, data, width, height, options) {
|
|
13598
|
+
if (isHeadless) return null;
|
|
13599
|
+
return createTextureFromPixels(engine, data, width, height, {
|
|
13600
|
+
addressModeU: options.addressModeU,
|
|
13601
|
+
addressModeV: options.addressModeV,
|
|
13602
|
+
minFilter: options.minFilter,
|
|
13603
|
+
magFilter: options.magFilter,
|
|
13604
|
+
srgb: options.srgb
|
|
13605
|
+
});
|
|
13606
|
+
}
|
|
13607
|
+
/**
|
|
13608
|
+
* Writes a rectangular region of a pixel texture, when it still has one.
|
|
13609
|
+
*
|
|
13610
|
+
* @param engine - The engine that owns the queue.
|
|
13611
|
+
* @param texture - The target, or `null` when the app is headless or the share was released.
|
|
13612
|
+
* @param data - The region's RGBA8 bytes.
|
|
13613
|
+
* @param x - The destination column.
|
|
13614
|
+
* @param y - The destination row.
|
|
13615
|
+
* @param width - The region width.
|
|
13616
|
+
* @param height - The region height.
|
|
13617
|
+
*
|
|
13618
|
+
* @internal
|
|
13619
|
+
*/
|
|
13620
|
+
function writePixelTexture(engine, texture, data, x, y, width, height) {
|
|
13621
|
+
if (texture === null) return;
|
|
13622
|
+
updateTextureFromPixels(engine, texture, data, x, y, width, height);
|
|
13623
|
+
}
|
|
13624
|
+
/**
|
|
13625
|
+
* Claims an extra share of a texture, when there is one.
|
|
13626
|
+
*
|
|
13627
|
+
* @param texture - The texture, or `null`.
|
|
13628
|
+
*
|
|
13629
|
+
* @internal
|
|
13630
|
+
*/
|
|
13631
|
+
function retainTextureShare(texture) {
|
|
13632
|
+
if (texture === null) return;
|
|
13633
|
+
retainTexture(texture);
|
|
13634
|
+
}
|
|
13635
|
+
/**
|
|
13636
|
+
* Gives up a share of a texture, when there is one.
|
|
13637
|
+
*
|
|
13638
|
+
* @param texture - The texture, or `null`.
|
|
13639
|
+
* @returns `true` when this call destroyed the underlying `GPUTexture`.
|
|
13640
|
+
*
|
|
13641
|
+
* @internal
|
|
13642
|
+
*/
|
|
13643
|
+
function releaseTextureShare(texture) {
|
|
13644
|
+
return texture === null ? false : releaseTextureHandle(texture);
|
|
13645
|
+
}
|
|
13646
|
+
//#endregion
|
|
13647
|
+
//#region src/render/texture-asset.ts
|
|
13648
|
+
/**
|
|
13649
|
+
* `TextureAsset` (`docs/architecture/05-assets-and-loading.md` §5, `07-rendering.md` §7): a GPU
|
|
13650
|
+
* texture plus the import options the build recorded for it.
|
|
13651
|
+
*
|
|
13652
|
+
* ## Lifetime, and why the loader does not `acquireTexture`
|
|
13653
|
+
*
|
|
13654
|
+
* Lite reference-counts `GPUTexture`s in a process-wide pool keyed by the underlying texture
|
|
13655
|
+
* (`lib/resource/gpu-pool.js`): `acquireTexture` increments, `releaseTexture` decrements and
|
|
13656
|
+
* destroys at zero, and **a texture that was never acquired starts at an implicit count of one**.
|
|
13657
|
+
* A freshly loaded texture is therefore already owned once, by the asset that loaded it. Calling
|
|
13658
|
+
* `acquireTexture` in the loader — which `07-rendering.md` §7 could be read as asking for — would
|
|
13659
|
+
* put the count at two and make the matching `releaseTexture` on unload free nothing: a leak, not a
|
|
13660
|
+
* safety net. So the loader acquires nothing and {@link TextureAsset.releaseGpu} releases the one
|
|
13661
|
+
* implicit share when the asset is unloaded.
|
|
13662
|
+
*
|
|
13663
|
+
* Sharing is expressed one level up instead. A `MaterialAsset` that samples a texture pulls it in
|
|
13664
|
+
* with `ctx.loadDependency`, which retains the *asset handle*; the texture's GPU share is released
|
|
13665
|
+
* only when the last asset holding that handle is collected. That is the same rule every other
|
|
13666
|
+
* dependency follows, and it is observable through `handle.refCount`.
|
|
13667
|
+
* {@link TextureAsset.retainGpu} exists for the rare case where a Lite object outlives its asset.
|
|
13668
|
+
*
|
|
13669
|
+
* {@link TextureAsset.fromPixels} is the other way in: RGBA8 bytes, no file, published at a
|
|
13670
|
+
* `memory:texture/<ulid>` address the way `MeshAsset`'s primitive factories are. It is the **only**
|
|
13671
|
+
* kind of texture {@link TextureAsset.update} accepts, because `createTexture2DFromPixels` is what
|
|
13672
|
+
* asks WebGPU for `COPY_DST` usage (`index.d.ts` 13400). The bytes are copied at creation and not
|
|
13673
|
+
* retained; the asset keeps only the size, which is what `update` validates against.
|
|
13674
|
+
*
|
|
13675
|
+
* ## Headless
|
|
13676
|
+
*
|
|
13677
|
+
* `loadTexture2D` uploads through `engine._device`, which the null engine has none of, so a
|
|
13678
|
+
* headless load produces an asset with `lite.texture === null` — the `gpu: null` shape
|
|
13679
|
+
* `05-assets-and-loading.md` §5 requires of every GPU loader. `fromPixels` behaves the same way and
|
|
13680
|
+
* still validates and records the size, so a Node test can assert that a generator wrote the right
|
|
13681
|
+
* number of bytes without a device.
|
|
13682
|
+
*/
|
|
13683
|
+
/**
|
|
13684
|
+
* The asset type textures are registered under.
|
|
13685
|
+
*
|
|
13686
|
+
* @public
|
|
13687
|
+
*/
|
|
13688
|
+
const TEXTURE_ASSET_TYPE = "texture";
|
|
13689
|
+
/**
|
|
13690
|
+
* A loaded 2D texture (`docs/architecture/05-assets-and-loading.md` §5).
|
|
13691
|
+
*
|
|
13692
|
+
* @example
|
|
13693
|
+
* ```ts
|
|
13694
|
+
* const albedo = await app.assets.loadAsync<TextureAsset>("textures/hero-albedo.png");
|
|
13695
|
+
* albedo.value.options.srgb; // what the .meta.json sidecar asked for
|
|
13696
|
+
* ```
|
|
13697
|
+
*
|
|
13698
|
+
* @public
|
|
13699
|
+
*/
|
|
13700
|
+
var TextureAsset = class TextureAsset {
|
|
13701
|
+
/** The type name the asset service registers textures under. */
|
|
13702
|
+
static assetType = TEXTURE_ASSET_TYPE;
|
|
13703
|
+
/** The address the texture was loaded from. */
|
|
13704
|
+
address;
|
|
13705
|
+
/** The resolved import options, sidecar values merged onto the defaults. */
|
|
13706
|
+
options;
|
|
13707
|
+
#texture;
|
|
13708
|
+
#pixelSource;
|
|
13709
|
+
/**
|
|
13710
|
+
* Wraps a loaded texture. The `texture` loader and {@link TextureAsset.fromPixels} construct
|
|
13711
|
+
* these.
|
|
13712
|
+
*
|
|
13713
|
+
* @param address - The address it was loaded from, or the `memory:` address it was published at.
|
|
13714
|
+
* @param texture - The GPU texture, or `null` when the app is headless.
|
|
13715
|
+
* @param options - The resolved import options.
|
|
13716
|
+
* @param pixelSource - The engine and size of a texture built from raw pixels, or `null` for a
|
|
13717
|
+
* texture that came from a file. It is what makes {@link TextureAsset.update} legal.
|
|
13718
|
+
*
|
|
13719
|
+
* @internal
|
|
13720
|
+
*/
|
|
13721
|
+
constructor(address, texture, options, pixelSource = null) {
|
|
13722
|
+
this.address = address;
|
|
13723
|
+
this.#texture = texture;
|
|
13724
|
+
this.options = options;
|
|
13725
|
+
this.#pixelSource = pixelSource;
|
|
13726
|
+
}
|
|
13727
|
+
/**
|
|
13728
|
+
* The Babylon Lite objects the asset owns. Unstable escape hatch.
|
|
13729
|
+
*
|
|
13730
|
+
* @returns The GPU texture, or `null` under a headless app.
|
|
13731
|
+
*/
|
|
13732
|
+
get lite() {
|
|
13733
|
+
return { texture: this.#texture };
|
|
13734
|
+
}
|
|
13735
|
+
/**
|
|
13736
|
+
* The texture's width, in texels.
|
|
13737
|
+
*
|
|
13738
|
+
* @remarks
|
|
13739
|
+
* Known for every texture that reached the GPU — Lite records it on the texture handle
|
|
13740
|
+
* (`index.d.ts` 12876) — and for a headless {@link TextureAsset.fromPixels} texture, which
|
|
13741
|
+
* remembers the size it was asked for. A texture **loaded** from a file under a headless app
|
|
13742
|
+
* decoded nothing, so it reports `0`.
|
|
13743
|
+
*
|
|
13744
|
+
* @returns The width, or `0` when nothing knows it.
|
|
13745
|
+
*/
|
|
13746
|
+
get width() {
|
|
13747
|
+
return this.#texture?.width ?? this.#pixelSource?.width ?? 0;
|
|
13748
|
+
}
|
|
13749
|
+
/**
|
|
13750
|
+
* The texture's height, in texels.
|
|
13751
|
+
*
|
|
13752
|
+
* @returns The height, or `0`; see {@link TextureAsset.width}.
|
|
13753
|
+
*/
|
|
13754
|
+
get height() {
|
|
13755
|
+
return this.#texture?.height ?? this.#pixelSource?.height ?? 0;
|
|
13756
|
+
}
|
|
13757
|
+
/**
|
|
13758
|
+
* Whether the GPU texture has been given up.
|
|
13759
|
+
*
|
|
13760
|
+
* @returns `true` once {@link TextureAsset.releaseGpu} has run.
|
|
13761
|
+
*/
|
|
13762
|
+
get isReleased() {
|
|
13763
|
+
return this.#texture === null;
|
|
13764
|
+
}
|
|
13765
|
+
/**
|
|
13766
|
+
* Claims an extra share of the GPU texture, so releasing the asset does not destroy it.
|
|
13767
|
+
*
|
|
13768
|
+
* @remarks
|
|
13769
|
+
* Only needed when a Lite object has to outlive the asset that loaded it. Ordinary sharing goes
|
|
13770
|
+
* through `ctx.loadDependency`, which counts the asset handle instead.
|
|
13771
|
+
*/
|
|
13772
|
+
retainGpu() {
|
|
13773
|
+
retainTextureShare(this.#texture);
|
|
13774
|
+
}
|
|
13775
|
+
/**
|
|
13776
|
+
* Gives up the asset's share of the GPU texture, destroying it when it was the last one. Calling
|
|
13777
|
+
* it twice is a no-op, and it is a no-op under a headless app.
|
|
13778
|
+
*
|
|
13779
|
+
* @returns `true` when this call destroyed the underlying `GPUTexture`.
|
|
13780
|
+
*/
|
|
13781
|
+
releaseGpu() {
|
|
13782
|
+
const texture = this.#texture;
|
|
13783
|
+
this.#texture = null;
|
|
13784
|
+
return releaseTextureShare(texture);
|
|
13785
|
+
}
|
|
13786
|
+
/**
|
|
13787
|
+
* Writes a rectangular region of the texture from RGBA8 bytes.
|
|
13788
|
+
*
|
|
13789
|
+
* @remarks
|
|
13790
|
+
* Only a texture from {@link TextureAsset.fromPixels} can be written to: that is the factory that
|
|
13791
|
+
* asks WebGPU for `COPY_DST` usage. The region defaults to the whole texture. Nothing is uploaded
|
|
13792
|
+
* under a headless app, but the size check still runs, so a generator's arithmetic is testable
|
|
13793
|
+
* without a device.
|
|
13794
|
+
*
|
|
13795
|
+
* The texture has one mip level, so there is no chain to regenerate and an update is complete the
|
|
13796
|
+
* moment the queue drains.
|
|
13797
|
+
*
|
|
13798
|
+
* @param data - `width * height * 4` bytes for the region, row-major, top row first.
|
|
13799
|
+
* @param x - The destination origin's column. Defaults to `0`.
|
|
13800
|
+
* @param y - The destination origin's row. Defaults to `0`.
|
|
13801
|
+
* @param width - The region's width. Defaults to the texture's width.
|
|
13802
|
+
* @param height - The region's height. Defaults to the texture's height.
|
|
13803
|
+
* @throws IgnifxError with code `IGX-0702` when the texture did not come from
|
|
13804
|
+
* {@link TextureAsset.fromPixels}.
|
|
13805
|
+
* @throws IgnifxError with code `IGX-0722` when the region falls outside the texture or `data` is
|
|
13806
|
+
* not exactly `width * height * 4` bytes long.
|
|
13807
|
+
*
|
|
13808
|
+
* @example
|
|
13809
|
+
* ```ts
|
|
13810
|
+
* const splat = TextureAsset.fromPixels(app, "splat", pixels, 256, 256);
|
|
13811
|
+
* pixels[0] = 255;
|
|
13812
|
+
* splat.value.update(pixels.subarray(0, 4), 0, 0, 1, 1); // one texel
|
|
13813
|
+
* ```
|
|
13814
|
+
*/
|
|
13815
|
+
update(data, x = 0, y = 0, width, height) {
|
|
13816
|
+
const source = this.#pixelSource;
|
|
13817
|
+
if (source === null) throw new IgnifxError(CoreErrorCode.invalidRuntime, `${this.address} was not created by TextureAsset.fromPixels, so it cannot be updated.`, {
|
|
13818
|
+
context: {
|
|
13819
|
+
asset: this.address,
|
|
13820
|
+
member: "TextureAsset.update()"
|
|
13821
|
+
},
|
|
13822
|
+
hint: "Only a texture built with TextureAsset.fromPixels carries the COPY_DST usage an update needs."
|
|
13823
|
+
});
|
|
13824
|
+
const regionWidth = width ?? source.width;
|
|
13825
|
+
const regionHeight = height ?? source.height;
|
|
13826
|
+
assertPixelRegion(this.address, data, source, x, y, regionWidth, regionHeight);
|
|
13827
|
+
writePixelTexture(source.engine, this.#texture, data, x, y, regionWidth, regionHeight);
|
|
13828
|
+
}
|
|
13829
|
+
/**
|
|
13830
|
+
* Creates a texture from tightly packed RGBA8 bytes and publishes it as an in-memory asset.
|
|
13831
|
+
*
|
|
13832
|
+
* @remarks
|
|
13833
|
+
* The bytes are `width * height * 4` long, row-major, **top row first**, with straight (not
|
|
13834
|
+
* premultiplied) alpha. They are copied into the GPU texture and not retained.
|
|
13835
|
+
*
|
|
13836
|
+
* The result is the only kind of texture {@link TextureAsset.update} accepts. Ownership follows
|
|
13837
|
+
* the rule every in-code asset follows: the caller holds the handle, releasing it (or letting a
|
|
13838
|
+
* `using` block do it) runs the `texture` type's unload, which releases the GPU share.
|
|
13839
|
+
*
|
|
13840
|
+
* @param app - The app whose engine uploads the texture and whose asset service holds the handle.
|
|
13841
|
+
* @param name - A human-readable name. It becomes the asset's `address` — the string diagnostics
|
|
13842
|
+
* and the `IGX-0722` message name it by — while the handle's own address is the generated
|
|
13843
|
+
* `memory:texture/<ulid>` the asset service published it at.
|
|
13844
|
+
* @param data - `width * height * 4` bytes.
|
|
13845
|
+
* @param width - The width in texels, at least 1.
|
|
13846
|
+
* @param height - The height in texels, at least 1.
|
|
13847
|
+
* @param options - Sampler and colour-space overrides; `nearest`, `clamp`, no sRGB by default.
|
|
13848
|
+
* @returns The handle, already loaded, with one holder — the caller.
|
|
13849
|
+
* @throws IgnifxError with code `IGX-0722` when `width` or `height` is not a positive integer, or
|
|
13850
|
+
* `data` is not exactly `width * height * 4` bytes long.
|
|
13851
|
+
*
|
|
13852
|
+
* @example
|
|
13853
|
+
* ```ts
|
|
13854
|
+
* const pixels = new Uint8Array(2 * 2 * 4);
|
|
13855
|
+
* pixels.fill(255);
|
|
13856
|
+
* using ramp = TextureAsset.fromPixels(app, "ramp", pixels, 2, 2, { filter: "nearest" });
|
|
13857
|
+
* ```
|
|
13858
|
+
*/
|
|
13859
|
+
static fromPixels(app, name, data, width, height, options) {
|
|
13860
|
+
assertPixelSize(name, data, width, height);
|
|
13861
|
+
const resolved = resolvePixelOptions(options);
|
|
13862
|
+
const engine = app.lite.engine;
|
|
13863
|
+
const texture = createPixelTexture(app.isHeadless, engine, data, width, height, resolved);
|
|
13864
|
+
const asset = new TextureAsset(name, texture, resolved, {
|
|
13865
|
+
engine,
|
|
13866
|
+
width,
|
|
13867
|
+
height
|
|
13868
|
+
});
|
|
13869
|
+
return app.assets.register(asset, { type: TEXTURE_ASSET_TYPE });
|
|
13870
|
+
}
|
|
13871
|
+
};
|
|
13872
|
+
/**
|
|
13873
|
+
* How many bytes one RGBA8 texel occupies.
|
|
13874
|
+
*/
|
|
13875
|
+
const BYTES_PER_TEXEL = 4;
|
|
13876
|
+
/**
|
|
13877
|
+
* Checks that a byte count matches a texture size.
|
|
13878
|
+
*
|
|
13879
|
+
* @param asset - The name or address named in the error.
|
|
13880
|
+
* @param data - The pixel bytes.
|
|
13881
|
+
* @param width - The width in texels.
|
|
13882
|
+
* @param height - The height in texels.
|
|
13883
|
+
* @throws IgnifxError with code `IGX-0722` when the size is not a positive integer pair or the byte
|
|
13884
|
+
* count does not match.
|
|
13885
|
+
*/
|
|
13886
|
+
function assertPixelSize(asset, data, width, height) {
|
|
13887
|
+
const valid = Number.isInteger(width) && Number.isInteger(height) && width > 0 && height > 0;
|
|
13888
|
+
const expected = width * height * BYTES_PER_TEXEL;
|
|
13889
|
+
if (valid && data.length === expected) return;
|
|
13890
|
+
throw new IgnifxError(CoreErrorCode.invalidPixelData, `${asset}: ${String(data.length)} bytes of pixel data do not match ${String(width)}x${String(height)} RGBA.`, {
|
|
13891
|
+
context: {
|
|
13892
|
+
asset,
|
|
13893
|
+
bytes: data.length,
|
|
13894
|
+
width,
|
|
13895
|
+
height
|
|
13896
|
+
},
|
|
13897
|
+
hint: "RGBA8 pixel data is exactly width * height * 4 bytes, row-major with the top row first."
|
|
13898
|
+
});
|
|
13899
|
+
}
|
|
13900
|
+
/**
|
|
13901
|
+
* Checks that an update's region lies inside the texture and that the byte count matches it.
|
|
13902
|
+
*
|
|
13903
|
+
* @param asset - The address named in the error.
|
|
13904
|
+
* @param data - The pixel bytes.
|
|
13905
|
+
* @param source - The texture's recorded size.
|
|
13906
|
+
* @param x - The region's origin column.
|
|
13907
|
+
* @param y - The region's origin row.
|
|
13908
|
+
* @param width - The region's width.
|
|
13909
|
+
* @param height - The region's height.
|
|
13910
|
+
* @throws IgnifxError with code `IGX-0722` when the region does not fit or the byte count is wrong.
|
|
13911
|
+
*/
|
|
13912
|
+
function assertPixelRegion(asset, data, source, x, y, width, height) {
|
|
13913
|
+
if (!(Number.isInteger(x) && Number.isInteger(y) && x >= 0 && y >= 0 && x + width <= source.width && y + height <= source.height)) throw new IgnifxError(CoreErrorCode.invalidPixelData, `${asset}: the region ${String(width)}x${String(height)} at (${String(x)}, ${String(y)}) falls outside a ${String(source.width)}x${String(source.height)} texture.`, {
|
|
13914
|
+
context: {
|
|
13915
|
+
asset,
|
|
13916
|
+
bytes: data.length,
|
|
13917
|
+
x,
|
|
13918
|
+
y,
|
|
13919
|
+
width,
|
|
13920
|
+
height
|
|
13921
|
+
},
|
|
13922
|
+
hint: "An update writes inside the texture it was created with; recreate it to change its size."
|
|
13923
|
+
});
|
|
13924
|
+
assertPixelSize(asset, data, width, height);
|
|
13925
|
+
}
|
|
13926
|
+
/**
|
|
13927
|
+
* Fills in {@link PixelTextureOptions}'s defaults as a complete {@link TextureImportOptions}, so a
|
|
13928
|
+
* pixel texture reports its sampler state the way a loaded one does.
|
|
13929
|
+
*
|
|
13930
|
+
* @param options - What the caller named.
|
|
13931
|
+
* @returns The resolved options.
|
|
13932
|
+
*/
|
|
13933
|
+
function resolvePixelOptions(options) {
|
|
13934
|
+
const filter = options?.filter ?? "nearest";
|
|
13935
|
+
const wrap = options?.wrap === "repeat" ? "repeat" : "clamp-to-edge";
|
|
13936
|
+
return {
|
|
13937
|
+
srgb: options?.srgb ?? false,
|
|
13938
|
+
mipMaps: false,
|
|
13939
|
+
addressModeU: wrap,
|
|
13940
|
+
addressModeV: wrap,
|
|
13941
|
+
minFilter: filter,
|
|
13942
|
+
magFilter: filter,
|
|
13943
|
+
invertY: false,
|
|
13944
|
+
premultiplyAlpha: false
|
|
13945
|
+
};
|
|
13946
|
+
}
|
|
13947
|
+
/**
|
|
13948
|
+
* The import options a texture gets when its sidecar names none: Lite's own defaults, with `srgb`
|
|
13949
|
+
* off so that a data map is never silently decoded.
|
|
13950
|
+
*
|
|
13951
|
+
* @returns A fresh option set.
|
|
13952
|
+
*
|
|
13953
|
+
* @internal
|
|
13954
|
+
*/
|
|
13955
|
+
function defaultTextureImportOptions() {
|
|
13956
|
+
return {
|
|
13957
|
+
srgb: false,
|
|
13958
|
+
mipMaps: true,
|
|
13959
|
+
addressModeU: "repeat",
|
|
13960
|
+
addressModeV: "repeat",
|
|
13961
|
+
minFilter: "linear",
|
|
13962
|
+
magFilter: "linear",
|
|
13963
|
+
invertY: true,
|
|
13964
|
+
premultiplyAlpha: false
|
|
13965
|
+
};
|
|
13966
|
+
}
|
|
13967
|
+
/**
|
|
13968
|
+
* Reads the `texture` block of a `.meta.json` sidecar over the defaults.
|
|
13969
|
+
*
|
|
13970
|
+
* @remarks
|
|
13971
|
+
* Unknown keys and values of the wrong type are ignored rather than rejected: a sidecar is written
|
|
13972
|
+
* by hand and shared with other tools, and a typo in an optional import hint must not stop a game
|
|
13973
|
+
* from starting (`CONSTITUTION.md` §3.9 — the asset still loads, with the documented default).
|
|
13974
|
+
*
|
|
13975
|
+
* @param meta - The whole sidecar, or `null` when the manifest recorded none.
|
|
13976
|
+
* @returns The resolved options.
|
|
13977
|
+
*
|
|
13978
|
+
* @internal
|
|
13979
|
+
*/
|
|
13980
|
+
function readTextureImportOptions(meta) {
|
|
13981
|
+
const defaults = defaultTextureImportOptions();
|
|
13982
|
+
const raw = meta === null ? void 0 : meta[TEXTURE_ASSET_TYPE];
|
|
13983
|
+
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) return defaults;
|
|
13984
|
+
const block = raw;
|
|
13985
|
+
return {
|
|
13986
|
+
srgb: readBoolean$1(block, "srgb", defaults.srgb),
|
|
13987
|
+
mipMaps: readBoolean$1(block, "mipMaps", defaults.mipMaps),
|
|
13988
|
+
addressModeU: readString$2(block, "addressModeU", defaults.addressModeU),
|
|
13989
|
+
addressModeV: readString$2(block, "addressModeV", defaults.addressModeV),
|
|
13990
|
+
minFilter: readString$2(block, "minFilter", defaults.minFilter),
|
|
13991
|
+
magFilter: readString$2(block, "magFilter", defaults.magFilter),
|
|
13992
|
+
invertY: readBoolean$1(block, "invertY", defaults.invertY),
|
|
13993
|
+
premultiplyAlpha: readBoolean$1(block, "premultiplyAlpha", defaults.premultiplyAlpha)
|
|
13994
|
+
};
|
|
13995
|
+
}
|
|
13996
|
+
/**
|
|
13997
|
+
* Turns the resolved options into the shape `loadTexture2D` takes.
|
|
13998
|
+
*
|
|
13999
|
+
* @remarks
|
|
14000
|
+
* The sampler strings are handed to Lite as declared; WebGPU rejects a mode or filter it does not
|
|
14001
|
+
* know, and that failure is a clearer signal than an ignored option would be.
|
|
14002
|
+
*
|
|
14003
|
+
* @param options - The resolved import options.
|
|
14004
|
+
* @returns Lite's options.
|
|
14005
|
+
*
|
|
14006
|
+
* @internal
|
|
14007
|
+
*/
|
|
14008
|
+
function toLiteTextureOptions(options) {
|
|
14009
|
+
return {
|
|
14010
|
+
srgb: options.srgb,
|
|
14011
|
+
mipMaps: options.mipMaps,
|
|
14012
|
+
addressModeU: options.addressModeU,
|
|
14013
|
+
addressModeV: options.addressModeV,
|
|
14014
|
+
minFilter: options.minFilter,
|
|
14015
|
+
magFilter: options.magFilter,
|
|
14016
|
+
invertY: options.invertY,
|
|
14017
|
+
premultiplyAlpha: options.premultiplyAlpha
|
|
14018
|
+
};
|
|
14019
|
+
}
|
|
14020
|
+
/**
|
|
14021
|
+
* Reads a boolean out of a sidecar block.
|
|
14022
|
+
*
|
|
14023
|
+
* @param block - The sidecar sub-object.
|
|
14024
|
+
* @param key - The property name.
|
|
14025
|
+
* @param fallback - What to use when the property is absent or not a boolean.
|
|
14026
|
+
* @returns The value.
|
|
14027
|
+
*/
|
|
14028
|
+
function readBoolean$1(block, key, fallback) {
|
|
14029
|
+
const value = block[key];
|
|
14030
|
+
return typeof value === "boolean" ? value : fallback;
|
|
14031
|
+
}
|
|
14032
|
+
/**
|
|
14033
|
+
* Reads a string out of a sidecar block.
|
|
14034
|
+
*
|
|
14035
|
+
* @param block - The sidecar sub-object.
|
|
14036
|
+
* @param key - The property name.
|
|
14037
|
+
* @param fallback - What to use when the property is absent or not a string.
|
|
14038
|
+
* @returns The value.
|
|
14039
|
+
*/
|
|
14040
|
+
function readString$2(block, key, fallback) {
|
|
14041
|
+
const value = block[key];
|
|
14042
|
+
return typeof value === "string" ? value : fallback;
|
|
14043
|
+
}
|
|
14044
|
+
//#endregion
|
|
14045
|
+
//#region src/render/loaders/lightmap-loader.ts
|
|
14046
|
+
/**
|
|
14047
|
+
* Builds the loader for `.lightmap.json` lightmaps (GI Phase 2, step B3). The texture the file names
|
|
14048
|
+
* loads as a dependency, so it is released with the lightmap; a texture that fails to load fails
|
|
14049
|
+
* the lightmap.
|
|
14050
|
+
*
|
|
14051
|
+
* @returns The loader to register with `ctx.registerAssetLoader`.
|
|
14052
|
+
*
|
|
14053
|
+
* @beta
|
|
14054
|
+
*/
|
|
14055
|
+
function createLightmapLoader() {
|
|
14056
|
+
return {
|
|
14057
|
+
type: LIGHTMAP_ASSET_TYPE,
|
|
14058
|
+
extensions: LIGHTMAP_FILE_EXTENSIONS,
|
|
14059
|
+
async load(ctx) {
|
|
14060
|
+
const file = readLightmapFile(await ctx.fetchJson(), ctx.address);
|
|
14061
|
+
return new LightmapAsset(await ctx.loadDependency(file.texture, { type: TEXTURE_ASSET_TYPE }), file.entries);
|
|
14062
|
+
}
|
|
14063
|
+
};
|
|
14064
|
+
}
|
|
14065
|
+
//#endregion
|
|
12916
14066
|
//#region src/render/shader-material-definition.ts
|
|
12917
14067
|
/**
|
|
12918
14068
|
* Builds a `"shader"` material declaration, recording the addresses of the handles it is given.
|
|
@@ -13155,7 +14305,7 @@ async function loadTextures(ctx, addresses) {
|
|
|
13155
14305
|
*/
|
|
13156
14306
|
function readPbr(file, textures, surfaces) {
|
|
13157
14307
|
return pbrMaterialDefinition({
|
|
13158
|
-
name: readString$
|
|
14308
|
+
name: readString$1(file, "name", ""),
|
|
13159
14309
|
baseColor: readColor(file, "baseColor", {
|
|
13160
14310
|
r: 1,
|
|
13161
14311
|
g: 1,
|
|
@@ -13175,8 +14325,8 @@ function readPbr(file, textures, surfaces) {
|
|
|
13175
14325
|
alphaMode: readAlphaMode(file),
|
|
13176
14326
|
alphaCutoff: readNumber(file, "alphaCutoff", .5),
|
|
13177
14327
|
alpha: readNumber(file, "alpha", 1),
|
|
13178
|
-
doubleSided: readBoolean
|
|
13179
|
-
unlit: readBoolean
|
|
14328
|
+
doubleSided: readBoolean(file, "doubleSided", false),
|
|
14329
|
+
unlit: readBoolean(file, "unlit", false),
|
|
13180
14330
|
environmentIntensity: readNumber(file, "environmentIntensity", 1),
|
|
13181
14331
|
textures,
|
|
13182
14332
|
surfaces
|
|
@@ -13192,7 +14342,7 @@ function readPbr(file, textures, surfaces) {
|
|
|
13192
14342
|
*/
|
|
13193
14343
|
function readStandard(file, textures, surfaces) {
|
|
13194
14344
|
return standardMaterialDefinition({
|
|
13195
|
-
name: readString$
|
|
14345
|
+
name: readString$1(file, "name", ""),
|
|
13196
14346
|
diffuse: readColor(file, "diffuse", {
|
|
13197
14347
|
r: 1,
|
|
13198
14348
|
g: 1,
|
|
@@ -13214,8 +14364,8 @@ function readStandard(file, textures, surfaces) {
|
|
|
13214
14364
|
}),
|
|
13215
14365
|
alpha: readNumber(file, "alpha", 1),
|
|
13216
14366
|
alphaCutoff: readNumber(file, "alphaCutoff", 0),
|
|
13217
|
-
doubleSided: readBoolean
|
|
13218
|
-
unlit: readBoolean
|
|
14367
|
+
doubleSided: readBoolean(file, "doubleSided", false),
|
|
14368
|
+
unlit: readBoolean(file, "unlit", false),
|
|
13219
14369
|
textures,
|
|
13220
14370
|
surfaces
|
|
13221
14371
|
});
|
|
@@ -13257,10 +14407,10 @@ function readSurfaceReferences(file, address) {
|
|
|
13257
14407
|
const record = entry;
|
|
13258
14408
|
references.push({
|
|
13259
14409
|
shader,
|
|
13260
|
-
name: readString$
|
|
14410
|
+
name: readString$1(record, "name", ""),
|
|
13261
14411
|
values: readValues(record),
|
|
13262
14412
|
textures: readTextureRecord(record),
|
|
13263
|
-
enabled: readBoolean
|
|
14413
|
+
enabled: readBoolean(record, "enabled", true),
|
|
13264
14414
|
priority: readNumber(record, "priority", SURFACE_PRIORITY)
|
|
13265
14415
|
});
|
|
13266
14416
|
}
|
|
@@ -13346,7 +14496,7 @@ function readNumber(file, key, fallback) {
|
|
|
13346
14496
|
* @param fallback - What to use when it is absent or not a boolean.
|
|
13347
14497
|
* @returns The value.
|
|
13348
14498
|
*/
|
|
13349
|
-
function readBoolean
|
|
14499
|
+
function readBoolean(file, key, fallback) {
|
|
13350
14500
|
const value = file[key];
|
|
13351
14501
|
return typeof value === "boolean" ? value : fallback;
|
|
13352
14502
|
}
|
|
@@ -13358,7 +14508,7 @@ function readBoolean$1(file, key, fallback) {
|
|
|
13358
14508
|
* @param fallback - What to use when it is absent or not a string.
|
|
13359
14509
|
* @returns The value.
|
|
13360
14510
|
*/
|
|
13361
|
-
function readString$
|
|
14511
|
+
function readString$1(file, key, fallback) {
|
|
13362
14512
|
const value = file[key];
|
|
13363
14513
|
return typeof value === "string" ? value : fallback;
|
|
13364
14514
|
}
|
|
@@ -13403,7 +14553,7 @@ function channel(value, fallback) {
|
|
|
13403
14553
|
* value of the wrong shape.
|
|
13404
14554
|
*/
|
|
13405
14555
|
async function loadShaderMaterial(ctx, file) {
|
|
13406
|
-
const address = readString$
|
|
14556
|
+
const address = readString$1(file, "shader", "");
|
|
13407
14557
|
if (address === "") throw new IgnifxError(CoreErrorCode.invalidAssetFile, `${ctx.address} declares no shader.`, {
|
|
13408
14558
|
context: {
|
|
13409
14559
|
file: ctx.address,
|
|
@@ -13416,7 +14566,7 @@ async function loadShaderMaterial(ctx, file) {
|
|
|
13416
14566
|
const [resolved] = await Promise.all([loadNamedTextures(ctx, requested), loadShaderSupport()]);
|
|
13417
14567
|
return buildMaterialAsset(shaderMaterialDefinition({
|
|
13418
14568
|
shader: address,
|
|
13419
|
-
name: readString$
|
|
14569
|
+
name: readString$1(file, "name", address),
|
|
13420
14570
|
values: readValues(file),
|
|
13421
14571
|
textures: resolved.addresses,
|
|
13422
14572
|
defines: readDefines(file)
|
|
@@ -13644,7 +14794,7 @@ function readMeshFile(parsed, address) {
|
|
|
13644
14794
|
for (const key of Object.keys(file)) if (!Object.hasOwn(MESH_FILE_FIELDS, key)) throw invalidMesh(address, `"${key}" is not a mesh file field`);
|
|
13645
14795
|
const name = file["name"];
|
|
13646
14796
|
if (name !== void 0 && typeof name !== "string") throw invalidMesh(address, "\"name\" must be a string");
|
|
13647
|
-
const primitive = readPrimitive(file["primitive"], address);
|
|
14797
|
+
const primitive = readPrimitive$1(file["primitive"], address);
|
|
13648
14798
|
const definition = {
|
|
13649
14799
|
primitive,
|
|
13650
14800
|
options: readOptions(file["options"], primitive, address)
|
|
@@ -13737,7 +14887,7 @@ function asObject(value) {
|
|
|
13737
14887
|
* @returns The primitive.
|
|
13738
14888
|
* @throws IgnifxError with code `IGX-0507` when it is not one of {@link MESH_PRIMITIVES}.
|
|
13739
14889
|
*/
|
|
13740
|
-
function readPrimitive(value, address) {
|
|
14890
|
+
function readPrimitive$1(value, address) {
|
|
13741
14891
|
for (const primitive of MESH_PRIMITIVES) if (value === primitive) return primitive;
|
|
13742
14892
|
throw invalidMesh(address, `"primitive" is ${JSON.stringify(value ?? null)}; expected one of ${MESH_PRIMITIVES.join(", ")}`);
|
|
13743
14893
|
}
|
|
@@ -14208,9 +15358,9 @@ function decoderLeftOut(address, group) {
|
|
|
14208
15358
|
});
|
|
14209
15359
|
}
|
|
14210
15360
|
/** `glTF` in ASCII, little-endian: the first four bytes of a `.glb`. */
|
|
14211
|
-
const GLB_MAGIC = 1179937895;
|
|
15361
|
+
const GLB_MAGIC$1 = 1179937895;
|
|
14212
15362
|
/** `JSON` in ASCII, little-endian: the type of a `.glb`'s first chunk. */
|
|
14213
|
-
const GLB_JSON_CHUNK = 1313821514;
|
|
15363
|
+
const GLB_JSON_CHUNK$1 = 1313821514;
|
|
14214
15364
|
/**
|
|
14215
15365
|
* The extension names a glTF file declares in `extensionsUsed` and `extensionsRequired`.
|
|
14216
15366
|
*
|
|
@@ -14222,9 +15372,9 @@ const GLB_JSON_CHUNK = 1313821514;
|
|
|
14222
15372
|
function gltfExtensionsUsed(bytes) {
|
|
14223
15373
|
let text;
|
|
14224
15374
|
const view = new DataView(bytes);
|
|
14225
|
-
if (bytes.byteLength >= 20 && view.getUint32(0, true) === GLB_MAGIC) {
|
|
15375
|
+
if (bytes.byteLength >= 20 && view.getUint32(0, true) === GLB_MAGIC$1) {
|
|
14226
15376
|
const length = view.getUint32(12, true);
|
|
14227
|
-
if (view.getUint32(16, true) !== GLB_JSON_CHUNK || 20 + length > bytes.byteLength) return [];
|
|
15377
|
+
if (view.getUint32(16, true) !== GLB_JSON_CHUNK$1 || 20 + length > bytes.byteLength) return [];
|
|
14228
15378
|
text = new TextDecoder().decode(new Uint8Array(bytes, 20, length));
|
|
14229
15379
|
} else text = new TextDecoder().decode(bytes);
|
|
14230
15380
|
let document;
|
|
@@ -14244,6 +15394,445 @@ function gltfExtensionsUsed(bytes) {
|
|
|
14244
15394
|
return names;
|
|
14245
15395
|
}
|
|
14246
15396
|
//#endregion
|
|
15397
|
+
//#region src/render/light-probe-bake-gltf.ts
|
|
15398
|
+
/**
|
|
15399
|
+
* A minimal glTF 2.0 reader for the light-probe bake (`docs/architecture/07-rendering.md` §2.15):
|
|
15400
|
+
* the triangles of every mesh the default scene places, in the model's own space, with each
|
|
15401
|
+
* primitive's flat base colour. No device, no Lite.
|
|
15402
|
+
*
|
|
15403
|
+
* - **Containers.** A `.glb` (its JSON and BIN chunks) or a `.gltf` whose buffers are embedded as
|
|
15404
|
+
* `data:` URIs. A buffer at any other URI cannot be read from the bytes alone, so its primitives
|
|
15405
|
+
* are skipped with a reason.
|
|
15406
|
+
* - **Geometry.** `POSITION` (float, or the integer types `KHR_mesh_quantization` allows) and the
|
|
15407
|
+
* indices (or none) of every primitive drawn as triangles, strips or fans; points and lines draw no
|
|
15408
|
+
* surface. Node transforms (matrix or TRS) are composed down the default scene, and then X is
|
|
15409
|
+
* mirrored, as Babylon Lite 1.34.0's loader does with its `__root__` node (scale `(-1, 1, 1)`,
|
|
15410
|
+
* `lib/loader-gltf/load-gltf.js`), so the triangles land where the model draws. Skinned meshes
|
|
15411
|
+
* are read in their bind pose and morph targets are ignored.
|
|
15412
|
+
* - **Compression.** `KHR_draco_mesh_compression` primitives and `EXT_meshopt_compression` buffer
|
|
15413
|
+
* views need Lite's decoders; they are skipped with a reason. Sparse accessors are skipped too.
|
|
15414
|
+
* - **Colour.** `pbrMetallicRoughness.baseColorFactor` (linear) times `1 − metallicFactor` when no
|
|
15415
|
+
* metallic-roughness texture overrides the factor; textures are not sampled.
|
|
15416
|
+
*/
|
|
15417
|
+
/** `glTF` in ASCII, little-endian: a `.glb`'s magic. */
|
|
15418
|
+
const GLB_MAGIC = 1179937895;
|
|
15419
|
+
/** `JSON` in ASCII, little-endian: the type of a `.glb`'s first chunk. */
|
|
15420
|
+
const GLB_JSON_CHUNK = 1313821514;
|
|
15421
|
+
/** `BIN\0` in ASCII, little-endian: the type of a `.glb`'s binary chunk. */
|
|
15422
|
+
const GLB_BIN_CHUNK = 5130562;
|
|
15423
|
+
/** Primitive modes the bake can turn into triangles. */
|
|
15424
|
+
const MODE_TRIANGLES = 4;
|
|
15425
|
+
const MODE_TRIANGLE_STRIP = 5;
|
|
15426
|
+
const MODE_TRIANGLE_FAN = 6;
|
|
15427
|
+
/** The largest `byteStride` glTF allows. */
|
|
15428
|
+
const MAX_BYTE_STRIDE = 252;
|
|
15429
|
+
/** The most node visits one file may cost; a strict tree visits each node once. */
|
|
15430
|
+
const MAX_NODE_VISITS = 65536;
|
|
15431
|
+
/** A failure to read one primitive, carried as a reason rather than thrown to the caller. */
|
|
15432
|
+
var SkipPrimitive = class extends Error {};
|
|
15433
|
+
/**
|
|
15434
|
+
* Reads the triangles of a `.glb` or self-contained `.gltf`.
|
|
15435
|
+
*
|
|
15436
|
+
* @param bytes - The file.
|
|
15437
|
+
* @returns The primitives and the reasons for those left out.
|
|
15438
|
+
* @throws Error when the bytes are not a glTF document at all; the bake reports it as the model's
|
|
15439
|
+
* skip reason.
|
|
15440
|
+
*
|
|
15441
|
+
* @internal
|
|
15442
|
+
*/
|
|
15443
|
+
function readGltfTriangles(bytes) {
|
|
15444
|
+
const { json, bin } = splitContainer(bytes);
|
|
15445
|
+
const buffers = (json.buffers ?? []).map((buffer, index) => resolveBuffer(buffer.uri, index, bin));
|
|
15446
|
+
const primitives = [];
|
|
15447
|
+
const skipped = [];
|
|
15448
|
+
const mirror = [
|
|
15449
|
+
-1,
|
|
15450
|
+
0,
|
|
15451
|
+
0,
|
|
15452
|
+
0,
|
|
15453
|
+
0,
|
|
15454
|
+
1,
|
|
15455
|
+
0,
|
|
15456
|
+
0,
|
|
15457
|
+
0,
|
|
15458
|
+
0,
|
|
15459
|
+
1,
|
|
15460
|
+
0,
|
|
15461
|
+
0,
|
|
15462
|
+
0,
|
|
15463
|
+
0,
|
|
15464
|
+
1
|
|
15465
|
+
];
|
|
15466
|
+
const roots = item(item(json.scenes, json.scene ?? 0)?.nodes, "all") ?? [];
|
|
15467
|
+
const visited = /* @__PURE__ */ new Set();
|
|
15468
|
+
const visit = (nodeIndex, parent, depth) => {
|
|
15469
|
+
const node = item(json.nodes, nodeIndex);
|
|
15470
|
+
if (node === void 0 || typeof nodeIndex !== "number" || depth > 256) return;
|
|
15471
|
+
if (visited.has(nodeIndex) || visited.size >= MAX_NODE_VISITS) {
|
|
15472
|
+
skipped.push(`node ${String(nodeIndex)} is reached twice or past the node budget; glTF nodes form a tree`);
|
|
15473
|
+
return;
|
|
15474
|
+
}
|
|
15475
|
+
visited.add(nodeIndex);
|
|
15476
|
+
const world = multiply(parent, localMatrix(node));
|
|
15477
|
+
const mesh = node.mesh === void 0 ? void 0 : item(json.meshes, node.mesh);
|
|
15478
|
+
for (const [index, primitive] of (item(mesh?.primitives, "all") ?? []).entries()) try {
|
|
15479
|
+
const read = readPrimitive(json, buffers, primitive, world);
|
|
15480
|
+
if (read !== null) primitives.push(read);
|
|
15481
|
+
} catch (error) {
|
|
15482
|
+
const reason = error instanceof SkipPrimitive ? error.message : String(error);
|
|
15483
|
+
skipped.push(`mesh ${String(node.mesh)} primitive ${String(index)}: ${reason}`);
|
|
15484
|
+
}
|
|
15485
|
+
for (const child of item(node.children, "all") ?? []) visit(child, world, depth + 1);
|
|
15486
|
+
};
|
|
15487
|
+
for (const root of roots) visit(root, mirror, 0);
|
|
15488
|
+
return {
|
|
15489
|
+
primitives,
|
|
15490
|
+
skipped
|
|
15491
|
+
};
|
|
15492
|
+
}
|
|
15493
|
+
/**
|
|
15494
|
+
* The flat linear albedo of each named material of a `.glb` or `.gltf`, as the bake reads
|
|
15495
|
+
* materials. Only the JSON is parsed.
|
|
15496
|
+
*
|
|
15497
|
+
* @param bytes - The file.
|
|
15498
|
+
* @returns The albedos by material name; empty when the file cannot be read or names none.
|
|
15499
|
+
*
|
|
15500
|
+
* @internal
|
|
15501
|
+
*/
|
|
15502
|
+
function readGltfMaterialAlbedos(bytes) {
|
|
15503
|
+
const out = /* @__PURE__ */ new Map();
|
|
15504
|
+
try {
|
|
15505
|
+
const { json } = splitContainer(bytes);
|
|
15506
|
+
for (const material of item(json.materials, "all") ?? []) if (typeof material.name === "string" && !out.has(material.name)) out.set(material.name, materialAlbedo$1(material));
|
|
15507
|
+
} catch {}
|
|
15508
|
+
return out;
|
|
15509
|
+
}
|
|
15510
|
+
/**
|
|
15511
|
+
* Splits a `.glb` into its JSON and BIN chunks, or parses a `.gltf`.
|
|
15512
|
+
*
|
|
15513
|
+
* @param bytes - The file.
|
|
15514
|
+
* @returns The document and the binary chunk, if any.
|
|
15515
|
+
* @throws Error for anything else.
|
|
15516
|
+
*/
|
|
15517
|
+
function splitContainer(bytes) {
|
|
15518
|
+
const view = new DataView(bytes);
|
|
15519
|
+
if (bytes.byteLength >= 20 && view.getUint32(0, true) === GLB_MAGIC) {
|
|
15520
|
+
const jsonLength = view.getUint32(12, true);
|
|
15521
|
+
if (view.getUint32(16, true) !== GLB_JSON_CHUNK || 20 + jsonLength > bytes.byteLength) throw new Error("the .glb has no JSON chunk");
|
|
15522
|
+
const json = parseJson(new Uint8Array(bytes, 20, jsonLength));
|
|
15523
|
+
let bin = null;
|
|
15524
|
+
const binStart = 20 + jsonLength;
|
|
15525
|
+
if (binStart + 8 <= bytes.byteLength && view.getUint32(binStart + 4, true) === GLB_BIN_CHUNK) {
|
|
15526
|
+
const binLength = Math.min(view.getUint32(binStart, true), bytes.byteLength - binStart - 8);
|
|
15527
|
+
bin = new Uint8Array(bytes, binStart + 8, binLength);
|
|
15528
|
+
}
|
|
15529
|
+
return {
|
|
15530
|
+
json,
|
|
15531
|
+
bin
|
|
15532
|
+
};
|
|
15533
|
+
}
|
|
15534
|
+
return {
|
|
15535
|
+
json: parseJson(new Uint8Array(bytes)),
|
|
15536
|
+
bin: null
|
|
15537
|
+
};
|
|
15538
|
+
}
|
|
15539
|
+
/**
|
|
15540
|
+
* Parses a glTF JSON document.
|
|
15541
|
+
*
|
|
15542
|
+
* @param text - Its UTF-8 bytes.
|
|
15543
|
+
* @returns The document.
|
|
15544
|
+
* @throws Error when it is not a JSON object.
|
|
15545
|
+
*/
|
|
15546
|
+
function parseJson(text) {
|
|
15547
|
+
const value = JSON.parse(new TextDecoder().decode(text));
|
|
15548
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) throw new Error("the glTF document is not a JSON object");
|
|
15549
|
+
return value;
|
|
15550
|
+
}
|
|
15551
|
+
/**
|
|
15552
|
+
* The bytes of one buffer, or why there are none.
|
|
15553
|
+
*
|
|
15554
|
+
* @param uri - The buffer's URI, or `undefined` for the `.glb` chunk.
|
|
15555
|
+
* @param index - The buffer's index.
|
|
15556
|
+
* @param bin - The `.glb`'s binary chunk.
|
|
15557
|
+
* @returns The bytes, or the reason as a string.
|
|
15558
|
+
*/
|
|
15559
|
+
function resolveBuffer(uri, index, bin) {
|
|
15560
|
+
if (uri === void 0) return index === 0 && bin !== null ? bin : `buffer ${String(index)} has no data`;
|
|
15561
|
+
const comma = uri.indexOf(",");
|
|
15562
|
+
if (uri.startsWith("data:") && comma > 0 && uri.slice(0, comma).endsWith(";base64")) {
|
|
15563
|
+
const text = atob(uri.slice(comma + 1));
|
|
15564
|
+
const out = new Uint8Array(text.length);
|
|
15565
|
+
for (let i = 0; i < text.length; i += 1) out[i] = text.charCodeAt(i);
|
|
15566
|
+
return out;
|
|
15567
|
+
}
|
|
15568
|
+
return `buffer ${String(index)} is a separate file (${uri.slice(0, 80)}), which the bake cannot read`;
|
|
15569
|
+
}
|
|
15570
|
+
/**
|
|
15571
|
+
* Reads one primitive into model space.
|
|
15572
|
+
*
|
|
15573
|
+
* @param json - The document.
|
|
15574
|
+
* @param buffers - The resolved buffers.
|
|
15575
|
+
* @param primitive - The primitive.
|
|
15576
|
+
* @param world - Its node's transform, mirror included.
|
|
15577
|
+
* @returns The triangles, or `null` for points and lines.
|
|
15578
|
+
* @throws SkipPrimitive with the reason it cannot be read.
|
|
15579
|
+
*/
|
|
15580
|
+
function readPrimitive(json, buffers, primitive, world) {
|
|
15581
|
+
if (primitive.extensions?.["KHR_draco_mesh_compression"] !== void 0) throw new SkipPrimitive("Draco-compressed (KHR_draco_mesh_compression)");
|
|
15582
|
+
const mode = primitive.mode ?? MODE_TRIANGLES;
|
|
15583
|
+
if (mode !== MODE_TRIANGLES && mode !== MODE_TRIANGLE_STRIP && mode !== MODE_TRIANGLE_FAN) return null;
|
|
15584
|
+
const positionIndex = primitive.attributes?.["POSITION"];
|
|
15585
|
+
if (positionIndex === void 0) throw new SkipPrimitive("no POSITION attribute");
|
|
15586
|
+
const local = readAccessor(json, buffers, positionIndex, 3);
|
|
15587
|
+
const vertexCount = local.length / 3;
|
|
15588
|
+
const positions = new Float32Array(local.length);
|
|
15589
|
+
for (let v = 0; v < vertexCount; v += 1) {
|
|
15590
|
+
const x = local[v * 3] ?? 0;
|
|
15591
|
+
const y = local[v * 3 + 1] ?? 0;
|
|
15592
|
+
const z = local[v * 3 + 2] ?? 0;
|
|
15593
|
+
positions[v * 3] = at(world, 0) * x + at(world, 4) * y + at(world, 8) * z + at(world, 12);
|
|
15594
|
+
positions[v * 3 + 1] = at(world, 1) * x + at(world, 5) * y + at(world, 9) * z + at(world, 13);
|
|
15595
|
+
positions[v * 3 + 2] = at(world, 2) * x + at(world, 6) * y + at(world, 10) * z + at(world, 14);
|
|
15596
|
+
}
|
|
15597
|
+
const raw = primitive.indices === void 0 ? Uint32Array.from({ length: vertexCount }, (_, index) => index) : Uint32Array.from(readAccessor(json, buffers, primitive.indices, 1));
|
|
15598
|
+
for (const index of raw) if (index >= vertexCount) throw new SkipPrimitive("an index past the last vertex");
|
|
15599
|
+
const material = primitive.material === void 0 ? void 0 : item(json.materials, primitive.material);
|
|
15600
|
+
return {
|
|
15601
|
+
positions,
|
|
15602
|
+
indices: toTriangleList(raw, mode),
|
|
15603
|
+
albedo: materialAlbedo$1(material),
|
|
15604
|
+
materialName: material?.name ?? null
|
|
15605
|
+
};
|
|
15606
|
+
}
|
|
15607
|
+
/**
|
|
15608
|
+
* Reads an accessor's elements as plain numbers, normalised when it says so.
|
|
15609
|
+
*
|
|
15610
|
+
* @param json - The document.
|
|
15611
|
+
* @param buffers - The resolved buffers.
|
|
15612
|
+
* @param index - The accessor's index.
|
|
15613
|
+
* @param components - The components per element the caller needs.
|
|
15614
|
+
* @returns `count × components` numbers.
|
|
15615
|
+
* @throws SkipPrimitive when it cannot be read.
|
|
15616
|
+
*/
|
|
15617
|
+
function readAccessor(json, buffers, index, components) {
|
|
15618
|
+
const accessor = item(json.accessors, index);
|
|
15619
|
+
if (accessor === void 0) throw new SkipPrimitive(`accessor ${String(index)} does not exist`);
|
|
15620
|
+
if (accessor.sparse !== void 0) throw new SkipPrimitive("a sparse accessor");
|
|
15621
|
+
const width = typeComponents(accessor.type);
|
|
15622
|
+
const size = componentBytes(accessor.componentType);
|
|
15623
|
+
const count = accessor.count ?? 0;
|
|
15624
|
+
if (width !== components || size === void 0 || !isWhole(count)) throw new SkipPrimitive(`accessor ${String(index)} is not a ${String(components)}-component number array`);
|
|
15625
|
+
const view = accessor.bufferView === void 0 ? void 0 : item(json.bufferViews, accessor.bufferView);
|
|
15626
|
+
if (view === void 0) throw new SkipPrimitive(`accessor ${String(index)} has no buffer view`);
|
|
15627
|
+
if (view.extensions?.["EXT_meshopt_compression"] !== void 0) throw new SkipPrimitive("meshopt-compressed (EXT_meshopt_compression)");
|
|
15628
|
+
const buffer = item(buffers, view.buffer ?? 0);
|
|
15629
|
+
if (buffer === void 0 || typeof buffer === "string") throw new SkipPrimitive(buffer ?? `buffer ${String(view.buffer)} does not exist`);
|
|
15630
|
+
const elementBytes = size * width;
|
|
15631
|
+
const stride = view.byteStride ?? elementBytes;
|
|
15632
|
+
const viewOffset = view.byteOffset ?? 0;
|
|
15633
|
+
const viewLength = view.byteLength;
|
|
15634
|
+
const accessorOffset = accessor.byteOffset ?? 0;
|
|
15635
|
+
if (!isWhole(stride) || stride < elementBytes || stride > Math.max(MAX_BYTE_STRIDE, elementBytes)) throw new SkipPrimitive(`buffer view ${String(accessor.bufferView)} has a byteStride outside ${String(elementBytes)}–252`);
|
|
15636
|
+
if (!isWhole(viewOffset) || !isWhole(viewLength) || !isWhole(accessorOffset)) throw new SkipPrimitive(`accessor ${String(index)} or its view has a negative or fractional offset or length`);
|
|
15637
|
+
if (viewOffset + viewLength > buffer.byteLength) throw new SkipPrimitive(`buffer view ${String(accessor.bufferView)} runs past its buffer`);
|
|
15638
|
+
if (count > 0 && accessorOffset + stride * (count - 1) + elementBytes > viewLength) throw new SkipPrimitive(`accessor ${String(index)} runs past its buffer view`);
|
|
15639
|
+
const start = buffer.byteOffset + viewOffset + accessorOffset;
|
|
15640
|
+
const data = new DataView(buffer.buffer, 0, buffer.byteOffset + buffer.byteLength);
|
|
15641
|
+
const out = new Float64Array(count * width);
|
|
15642
|
+
const type = accessor.componentType ?? 0;
|
|
15643
|
+
const normalized = accessor.normalized === true;
|
|
15644
|
+
for (let element = 0; element < count; element += 1) for (let c = 0; c < width; c += 1) out[element * width + c] = readComponent(data, start + element * stride + c * size, type, normalized);
|
|
15645
|
+
return out;
|
|
15646
|
+
}
|
|
15647
|
+
/**
|
|
15648
|
+
* Reads one component.
|
|
15649
|
+
*
|
|
15650
|
+
* @param data - The buffer.
|
|
15651
|
+
* @param offset - Its byte offset.
|
|
15652
|
+
* @param type - The glTF component type.
|
|
15653
|
+
* @param normalized - Whether an integer maps to `[-1, 1]` or `[0, 1]`.
|
|
15654
|
+
* @returns The number.
|
|
15655
|
+
*/
|
|
15656
|
+
function readComponent(data, offset, type, normalized) {
|
|
15657
|
+
switch (type) {
|
|
15658
|
+
case 5120: return normalized ? Math.max(data.getInt8(offset) / 127, -1) : data.getInt8(offset);
|
|
15659
|
+
case 5121: return normalized ? data.getUint8(offset) / 255 : data.getUint8(offset);
|
|
15660
|
+
case 5122: return normalized ? Math.max(data.getInt16(offset, true) / 32767, -1) : data.getInt16(offset, true);
|
|
15661
|
+
case 5123: return normalized ? data.getUint16(offset, true) / 65535 : data.getUint16(offset, true);
|
|
15662
|
+
case 5125: return data.getUint32(offset, true);
|
|
15663
|
+
default: return data.getFloat32(offset, true);
|
|
15664
|
+
}
|
|
15665
|
+
}
|
|
15666
|
+
/**
|
|
15667
|
+
* Turns strip or fan indices into a triangle list.
|
|
15668
|
+
*
|
|
15669
|
+
* @param indices - The primitive's indices.
|
|
15670
|
+
* @param mode - Its mode.
|
|
15671
|
+
* @returns Three indices per triangle.
|
|
15672
|
+
*/
|
|
15673
|
+
function toTriangleList(indices, mode) {
|
|
15674
|
+
if (mode === MODE_TRIANGLES) return indices.length % 3 === 0 ? indices : indices.slice(0, indices.length - indices.length % 3);
|
|
15675
|
+
const out = [];
|
|
15676
|
+
for (let i = 2; i < indices.length; i += 1) {
|
|
15677
|
+
const a = indices[i - 2] ?? 0;
|
|
15678
|
+
const b = indices[i - 1] ?? 0;
|
|
15679
|
+
const c = indices[i] ?? 0;
|
|
15680
|
+
if (mode === MODE_TRIANGLE_FAN) out.push(indices[0] ?? 0, b, c);
|
|
15681
|
+
else if (i % 2 === 0) out.push(a, b, c);
|
|
15682
|
+
else out.push(b, a, c);
|
|
15683
|
+
}
|
|
15684
|
+
return Uint32Array.from(out);
|
|
15685
|
+
}
|
|
15686
|
+
/**
|
|
15687
|
+
* A material's flat diffuse colour.
|
|
15688
|
+
*
|
|
15689
|
+
* @param material - The material, or `undefined` for glTF's default (white, metallic 1 — which
|
|
15690
|
+
* the bake reads as white, since an untextured default material is meant as plain white).
|
|
15691
|
+
* @returns Linear RGB.
|
|
15692
|
+
*/
|
|
15693
|
+
function materialAlbedo$1(material) {
|
|
15694
|
+
const pbr = material?.pbrMetallicRoughness;
|
|
15695
|
+
if (material === void 0) return [
|
|
15696
|
+
1,
|
|
15697
|
+
1,
|
|
15698
|
+
1
|
|
15699
|
+
];
|
|
15700
|
+
const base = pbr?.baseColorFactor ?? [
|
|
15701
|
+
1,
|
|
15702
|
+
1,
|
|
15703
|
+
1,
|
|
15704
|
+
1
|
|
15705
|
+
];
|
|
15706
|
+
const keep = 1 - (pbr?.metallicRoughnessTexture === void 0 ? clamp01$1(pbr?.metallicFactor ?? 1) : 0);
|
|
15707
|
+
return [
|
|
15708
|
+
clamp01$1(base[0] ?? 1) * keep,
|
|
15709
|
+
clamp01$1(base[1] ?? 1) * keep,
|
|
15710
|
+
clamp01$1(base[2] ?? 1) * keep
|
|
15711
|
+
];
|
|
15712
|
+
}
|
|
15713
|
+
/**
|
|
15714
|
+
* Clamps a number to `[0, 1]`, `NaN` to 0.
|
|
15715
|
+
*
|
|
15716
|
+
* @param value - The number.
|
|
15717
|
+
* @returns It, clamped.
|
|
15718
|
+
*/
|
|
15719
|
+
function clamp01$1(value) {
|
|
15720
|
+
return Number.isFinite(value) ? Math.min(1, Math.max(0, value)) : 0;
|
|
15721
|
+
}
|
|
15722
|
+
/**
|
|
15723
|
+
* A node's local transform, column-major.
|
|
15724
|
+
*
|
|
15725
|
+
* @param node - The node.
|
|
15726
|
+
* @returns Sixteen numbers.
|
|
15727
|
+
*/
|
|
15728
|
+
function localMatrix(node) {
|
|
15729
|
+
if (node.matrix?.length === 16) return [...node.matrix];
|
|
15730
|
+
const [tx = 0, ty = 0, tz = 0] = node.translation ?? [];
|
|
15731
|
+
const [qx = 0, qy = 0, qz = 0, qw = 1] = node.rotation ?? [];
|
|
15732
|
+
const [sx = 1, sy = 1, sz = 1] = node.scale ?? [];
|
|
15733
|
+
const xx = qx * qx;
|
|
15734
|
+
const yy = qy * qy;
|
|
15735
|
+
const zz = qz * qz;
|
|
15736
|
+
const xy = qx * qy;
|
|
15737
|
+
const xz = qx * qz;
|
|
15738
|
+
const yz = qy * qz;
|
|
15739
|
+
const wx = qw * qx;
|
|
15740
|
+
const wy = qw * qy;
|
|
15741
|
+
const wz = qw * qz;
|
|
15742
|
+
return [
|
|
15743
|
+
(1 - 2 * (yy + zz)) * sx,
|
|
15744
|
+
2 * (xy + wz) * sx,
|
|
15745
|
+
2 * (xz - wy) * sx,
|
|
15746
|
+
0,
|
|
15747
|
+
2 * (xy - wz) * sy,
|
|
15748
|
+
(1 - 2 * (xx + zz)) * sy,
|
|
15749
|
+
2 * (yz + wx) * sy,
|
|
15750
|
+
0,
|
|
15751
|
+
2 * (xz + wy) * sz,
|
|
15752
|
+
2 * (yz - wx) * sz,
|
|
15753
|
+
(1 - 2 * (xx + yy)) * sz,
|
|
15754
|
+
0,
|
|
15755
|
+
tx,
|
|
15756
|
+
ty,
|
|
15757
|
+
tz,
|
|
15758
|
+
1
|
|
15759
|
+
];
|
|
15760
|
+
}
|
|
15761
|
+
/**
|
|
15762
|
+
* Multiplies two column-major 4×4 matrices: `a · b`.
|
|
15763
|
+
*
|
|
15764
|
+
* @param a - The parent.
|
|
15765
|
+
* @param b - The child.
|
|
15766
|
+
* @returns The product.
|
|
15767
|
+
*/
|
|
15768
|
+
function multiply(a, b) {
|
|
15769
|
+
const out = Array.from({ length: 16 }, () => 0);
|
|
15770
|
+
for (let column = 0; column < 4; column += 1) for (let row = 0; row < 4; row += 1) {
|
|
15771
|
+
let sum = 0;
|
|
15772
|
+
for (let k = 0; k < 4; k += 1) sum += at(a, k * 4 + row) * at(b, column * 4 + k);
|
|
15773
|
+
out[column * 4 + row] = sum;
|
|
15774
|
+
}
|
|
15775
|
+
return out;
|
|
15776
|
+
}
|
|
15777
|
+
/**
|
|
15778
|
+
* Reads one number of an array, `0` past its end.
|
|
15779
|
+
*
|
|
15780
|
+
* @param values - The array.
|
|
15781
|
+
* @param index - The index.
|
|
15782
|
+
* @returns The number.
|
|
15783
|
+
*/
|
|
15784
|
+
function at(values, index) {
|
|
15785
|
+
return values[index] ?? 0;
|
|
15786
|
+
}
|
|
15787
|
+
/**
|
|
15788
|
+
* Whether a value is a whole, non-negative, safe number: what glTF offsets, lengths and counts are.
|
|
15789
|
+
*
|
|
15790
|
+
* @param value - The value.
|
|
15791
|
+
* @returns `true` for 0, 1, 2…
|
|
15792
|
+
*/
|
|
15793
|
+
function isWhole(value) {
|
|
15794
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
|
|
15795
|
+
}
|
|
15796
|
+
function item(list, index) {
|
|
15797
|
+
const given = list;
|
|
15798
|
+
if (list === void 0 || !Array.isArray(given)) return;
|
|
15799
|
+
if (index === "all") return list;
|
|
15800
|
+
return isWhole(index) && index < list.length ? list[index] : void 0;
|
|
15801
|
+
}
|
|
15802
|
+
/**
|
|
15803
|
+
* Bytes per component of a glTF `componentType`, compared by value so that no inherited key of a
|
|
15804
|
+
* lookup object (`"toString"`) can match.
|
|
15805
|
+
*
|
|
15806
|
+
* @param type - The document's value.
|
|
15807
|
+
* @returns 1, 2 or 4, or `undefined` for anything else.
|
|
15808
|
+
*/
|
|
15809
|
+
function componentBytes(type) {
|
|
15810
|
+
switch (type) {
|
|
15811
|
+
case 5120:
|
|
15812
|
+
case 5121: return 1;
|
|
15813
|
+
case 5122:
|
|
15814
|
+
case 5123: return 2;
|
|
15815
|
+
case 5125:
|
|
15816
|
+
case 5126: return 4;
|
|
15817
|
+
default: return;
|
|
15818
|
+
}
|
|
15819
|
+
}
|
|
15820
|
+
/**
|
|
15821
|
+
* Components per element of a glTF accessor `type`, compared by value.
|
|
15822
|
+
*
|
|
15823
|
+
* @param type - The document's value.
|
|
15824
|
+
* @returns 1 to 4, or `undefined` for anything else.
|
|
15825
|
+
*/
|
|
15826
|
+
function typeComponents(type) {
|
|
15827
|
+
switch (type) {
|
|
15828
|
+
case "SCALAR": return 1;
|
|
15829
|
+
case "VEC2": return 2;
|
|
15830
|
+
case "VEC3": return 3;
|
|
15831
|
+
case "VEC4": return 4;
|
|
15832
|
+
default: return;
|
|
15833
|
+
}
|
|
15834
|
+
}
|
|
15835
|
+
//#endregion
|
|
14247
15836
|
//#region src/render/model-asset.ts
|
|
14248
15837
|
/**
|
|
14249
15838
|
* `ModelAsset` (`docs/architecture/05-assets-and-loading.md` §5 and §6,
|
|
@@ -14329,6 +15918,8 @@ var ModelAsset = class {
|
|
|
14329
15918
|
#scene;
|
|
14330
15919
|
#container;
|
|
14331
15920
|
#instances = 0;
|
|
15921
|
+
#sourceBytes;
|
|
15922
|
+
#bakeAlbedos = null;
|
|
14332
15923
|
/**
|
|
14333
15924
|
* Wraps a loaded container. The `model` loader constructs these.
|
|
14334
15925
|
*
|
|
@@ -14337,15 +15928,52 @@ var ModelAsset = class {
|
|
|
14337
15928
|
* @param animations - The clips taken off the container.
|
|
14338
15929
|
* @param skeletons - The skeletons the loader found.
|
|
14339
15930
|
* @param scene - The scene the container is released through, or `null` when headless.
|
|
15931
|
+
* @param sourceBytes - The file's bytes, kept by a headless load for the light-probe bake; `null`
|
|
15932
|
+
* otherwise.
|
|
14340
15933
|
*
|
|
14341
15934
|
* @internal
|
|
14342
15935
|
*/
|
|
14343
|
-
constructor(address, container, animations, skeletons, scene) {
|
|
15936
|
+
constructor(address, container, animations, skeletons, scene, sourceBytes = null) {
|
|
14344
15937
|
this.address = address;
|
|
14345
15938
|
this.#container = container;
|
|
14346
15939
|
this.animations = animations;
|
|
14347
15940
|
this.skeletons = skeletons;
|
|
14348
15941
|
this.#scene = scene;
|
|
15942
|
+
this.#sourceBytes = sourceBytes;
|
|
15943
|
+
}
|
|
15944
|
+
/**
|
|
15945
|
+
* The `.glb` or `.gltf` bytes a headless load kept, which `bakeLightProbes` reads its triangles
|
|
15946
|
+
* from. A load with a device keeps none: the container already holds the model, and holding the
|
|
15947
|
+
* file as well would double what a game keeps in memory.
|
|
15948
|
+
*
|
|
15949
|
+
* @returns The bytes, or `null`.
|
|
15950
|
+
*
|
|
15951
|
+
* @internal
|
|
15952
|
+
*/
|
|
15953
|
+
get sourceBytes() {
|
|
15954
|
+
return this.#sourceBytes;
|
|
15955
|
+
}
|
|
15956
|
+
/**
|
|
15957
|
+
* The flat linear albedo of each named glTF material, which a load with a device records for the
|
|
15958
|
+
* light-probe bake: Lite bakes an untextured material's `baseColorFactor` into a 1×1 texture
|
|
15959
|
+
* (`lib/loader-gltf/gltf-pbr-builder.js`), so the drawn material cannot tell its colour.
|
|
15960
|
+
*
|
|
15961
|
+
* @returns The albedos by material name, or `null` when none were recorded.
|
|
15962
|
+
*
|
|
15963
|
+
* @internal
|
|
15964
|
+
*/
|
|
15965
|
+
get bakeAlbedos() {
|
|
15966
|
+
return this.#bakeAlbedos;
|
|
15967
|
+
}
|
|
15968
|
+
/**
|
|
15969
|
+
* Records {@link ModelAsset.bakeAlbedos}. The `model` loader calls it.
|
|
15970
|
+
*
|
|
15971
|
+
* @param albedos - The albedos by material name.
|
|
15972
|
+
*
|
|
15973
|
+
* @internal
|
|
15974
|
+
*/
|
|
15975
|
+
recordBakeAlbedos(albedos) {
|
|
15976
|
+
this.#bakeAlbedos = albedos;
|
|
14349
15977
|
}
|
|
14350
15978
|
/**
|
|
14351
15979
|
* The Babylon Lite objects the asset owns. Unstable escape hatch.
|
|
@@ -14401,6 +16029,7 @@ var ModelAsset = class {
|
|
|
14401
16029
|
const container = this.#container;
|
|
14402
16030
|
const scene = this.#scene;
|
|
14403
16031
|
this.#container = null;
|
|
16032
|
+
this.#sourceBytes = null;
|
|
14404
16033
|
if (container !== null && scene !== null) removeContainerFromScene(scene, container);
|
|
14405
16034
|
}
|
|
14406
16035
|
/** Releases the template when the asset leaves a `using` block. */
|
|
@@ -14414,12 +16043,13 @@ var ModelAsset = class {
|
|
|
14414
16043
|
* @param address - The address it was loaded from.
|
|
14415
16044
|
* @param container - The container, or `null` when the app is headless.
|
|
14416
16045
|
* @param scene - The scene the container is released through, or `null` when headless.
|
|
16046
|
+
* @param sourceBytes - The file's bytes, kept only by a headless load (see `ModelAsset.sourceBytes`).
|
|
14417
16047
|
* @returns The asset.
|
|
14418
16048
|
*
|
|
14419
16049
|
* @internal
|
|
14420
16050
|
*/
|
|
14421
|
-
function createModelAsset(address, container, scene) {
|
|
14422
|
-
if (container === null) return new ModelAsset(address, null, [], [], null);
|
|
16051
|
+
function createModelAsset(address, container, scene, sourceBytes = null) {
|
|
16052
|
+
if (container === null) return new ModelAsset(address, null, [], [], null, sourceBytes);
|
|
14423
16053
|
return new ModelAsset(address, container, takeAnimationGroups(container), container.skeletons ?? [], scene);
|
|
14424
16054
|
}
|
|
14425
16055
|
//#endregion
|
|
@@ -14455,7 +16085,8 @@ function createModelAsset(address, container, scene) {
|
|
|
14455
16085
|
* `engine._device` (ADR-0002 Validation). So a headless load skips it entirely and produces an
|
|
14456
16086
|
* asset with no container — the `gpu: null` shape §5 requires — rather than failing. The bytes are
|
|
14457
16087
|
* still fetched, so a headless test still exercises the address, the manifest, and the byte
|
|
14458
|
-
* counters
|
|
16088
|
+
* counters, and the asset keeps them for `bakeLightProbes`, which reads a model's triangles from
|
|
16089
|
+
* the file because a headless app has no container to read them from.
|
|
14459
16090
|
*/
|
|
14460
16091
|
/**
|
|
14461
16092
|
* Builds the loader for `.glb` and `.gltf` addresses.
|
|
@@ -14476,10 +16107,12 @@ function createModelLoader() {
|
|
|
14476
16107
|
async load(ctx) {
|
|
14477
16108
|
const bytes = await ctx.fetchBytes();
|
|
14478
16109
|
assertModelDecodersIncluded(ctx.app, ctx.address, bytes);
|
|
14479
|
-
if (ctx.app.isHeadless) return createModelAsset(ctx.address, null, null);
|
|
16110
|
+
if (ctx.app.isHeadless) return createModelAsset(ctx.address, null, null, bytes);
|
|
14480
16111
|
await configureDecoders(ctx.app);
|
|
14481
16112
|
const container = await loadGltfFromBytes(ctx.lite.engine, bytes);
|
|
14482
|
-
|
|
16113
|
+
const asset = createModelAsset(ctx.address, container, ctx.app.lite.scene);
|
|
16114
|
+
asset.recordBakeAlbedos(readGltfMaterialAlbedos(bytes));
|
|
16115
|
+
return asset;
|
|
14483
16116
|
},
|
|
14484
16117
|
unload(value) {
|
|
14485
16118
|
value.dispose();
|
|
@@ -14493,756 +16126,160 @@ let compilerLayer = null;
|
|
|
14493
16126
|
/** The dynamically imported Babylon Lite effect adapter, memoised for the process. */
|
|
14494
16127
|
let effectLayer = null;
|
|
14495
16128
|
/**
|
|
14496
|
-
* Loads the post-effect compiler and the Babylon Lite effect adapter, once per process.
|
|
14497
|
-
*
|
|
14498
|
-
* @returns A promise that settles once both are in place.
|
|
14499
|
-
*
|
|
14500
|
-
* @internal
|
|
14501
|
-
*/
|
|
14502
|
-
async function loadPostEffectSupport() {
|
|
14503
|
-
const [compiler, effects] = await Promise.all([compilerLayer ?? import("./post-effect-compiler-C_7HTHZy.js"), effectLayer ?? import("./effect-task-CMbuO6Kb.js")]);
|
|
14504
|
-
compilerLayer = compiler;
|
|
14505
|
-
effectLayer = effects;
|
|
14506
|
-
}
|
|
14507
|
-
/**
|
|
14508
|
-
* The post-effect compiler, if it has been loaded.
|
|
14509
|
-
*
|
|
14510
|
-
* @returns The module, or `null` before any `.post.wgsl` has been loaded.
|
|
14511
|
-
*
|
|
14512
|
-
* @internal
|
|
14513
|
-
*/
|
|
14514
|
-
function postEffectCompiler() {
|
|
14515
|
-
return compilerLayer;
|
|
14516
|
-
}
|
|
14517
|
-
/**
|
|
14518
|
-
* The Babylon Lite effect adapter, if it has been loaded.
|
|
14519
|
-
*
|
|
14520
|
-
* @returns The module, or `null` before any `.post.wgsl` has been loaded.
|
|
14521
|
-
*
|
|
14522
|
-
* @internal
|
|
14523
|
-
*/
|
|
14524
|
-
function effectTaskSupport() {
|
|
14525
|
-
return effectLayer;
|
|
14526
|
-
}
|
|
14527
|
-
//#endregion
|
|
14528
|
-
//#region src/render/shader-asset.ts
|
|
14529
|
-
/**
|
|
14530
|
-
* One `.wgsl` file: its text and the declaration its `// @ignifx` pragmas carry
|
|
14531
|
-
* (`docs/plan/2026-09-terrain-particles-shaders.md` §3.1, ADR-0024).
|
|
14532
|
-
*
|
|
14533
|
-
* The asset is the program plus the schema of what a material may set on it, never the values. It
|
|
14534
|
-
* needs no device, so a `.wgsl` loads completely in Node. Two facts an author has to know:
|
|
14535
|
-
*
|
|
14536
|
-
* - The whole file is handed to Babylon Lite as **both** the vertex and the fragment source
|
|
14537
|
-
* (`lib/material/shader/shader-pipeline.js` 66–79), so structs and helpers are shared and the file
|
|
14538
|
-
* must compile in both stages — `textureSample` is fragment-only; vertex code uses
|
|
14539
|
-
* `textureSampleLevel` or `textureLoad`.
|
|
14540
|
-
* - Lite's system uniforms are read as `shaderSystem.<name>`; everything else, including the
|
|
14541
|
-
* uniforms ignifx supplies, as `shaderUniforms.<name>`.
|
|
14542
|
-
*/
|
|
14543
|
-
/**
|
|
14544
|
-
* The asset type shaders are registered under.
|
|
14545
|
-
*
|
|
14546
|
-
* @public
|
|
14547
|
-
*/
|
|
14548
|
-
const SHADER_ASSET_TYPE = "shader";
|
|
14549
|
-
/**
|
|
14550
|
-
* The address extensions that select the shader loader.
|
|
14551
|
-
*
|
|
14552
|
-
* @remarks
|
|
14553
|
-
* `.surface.wgsl` and `.post.wgsl` both end in `.wgsl`, so one extension covers all three forms.
|
|
14554
|
-
*
|
|
14555
|
-
* @public
|
|
14556
|
-
*/
|
|
14557
|
-
const SHADER_FILE_EXTENSIONS = Object.freeze([".wgsl"]);
|
|
14558
|
-
/**
|
|
14559
|
-
* A loaded `.wgsl` file: its source and what its pragmas declare
|
|
14560
|
-
* (`docs/plan/2026-09-terrain-particles-shaders.md` §3.1).
|
|
14561
|
-
*
|
|
14562
|
-
* @remarks
|
|
14563
|
-
* Shaders are shared: many materials reference one shader asset, and each material holds its own
|
|
14564
|
-
* values. Editing the file in development re-parses the declaration and rebuilds every material
|
|
14565
|
-
* built from it in place (`docs/architecture/05-assets-and-loading.md` §7).
|
|
14566
|
-
*
|
|
14567
|
-
* @example
|
|
14568
|
-
* ```ts
|
|
14569
|
-
* const dissolve = await app.assets.loadAsync<ShaderAsset>("shaders/dissolve.wgsl");
|
|
14570
|
-
* dissolve.value.declaration.uniforms.map((uniform) => uniform.name); // ["progress", "edgeColor"]
|
|
14571
|
-
* ```
|
|
14572
|
-
*
|
|
14573
|
-
* @public
|
|
14574
|
-
*/
|
|
14575
|
-
var ShaderAsset = class {
|
|
14576
|
-
/** The type name the asset service registers shaders under. */
|
|
14577
|
-
static assetType = SHADER_ASSET_TYPE;
|
|
14578
|
-
/** The address the shader was loaded from. */
|
|
14579
|
-
address;
|
|
14580
|
-
/** The whole file, as written. It is handed to Babylon Lite as both the vertex and the fragment source. */
|
|
14581
|
-
source;
|
|
14582
|
-
/** What the file's `// @ignifx` pragmas declare. */
|
|
14583
|
-
declaration;
|
|
14584
|
-
/**
|
|
14585
|
-
* Wraps a parsed shader file. The `shader` loader constructs these.
|
|
14586
|
-
*
|
|
14587
|
-
* @param address - The address it was loaded from.
|
|
14588
|
-
* @param source - The whole file.
|
|
14589
|
-
* @param declaration - The parsed pragmas.
|
|
14590
|
-
*
|
|
14591
|
-
* @internal
|
|
14592
|
-
*/
|
|
14593
|
-
constructor(address, source, declaration) {
|
|
14594
|
-
this.address = address;
|
|
14595
|
-
this.source = source;
|
|
14596
|
-
this.declaration = declaration;
|
|
14597
|
-
}
|
|
14598
|
-
/**
|
|
14599
|
-
* Which of the three authoring forms the file declared.
|
|
14600
|
-
*
|
|
14601
|
-
* @returns `"shader"`, `"surface"`, or `"post"`.
|
|
14602
|
-
*/
|
|
14603
|
-
get kind() {
|
|
14604
|
-
return this.declaration.kind;
|
|
14605
|
-
}
|
|
14606
|
-
};
|
|
14607
|
-
//#endregion
|
|
14608
|
-
//#region src/render/loaders/shader-loader.ts
|
|
14609
|
-
/**
|
|
14610
|
-
* The `shader` asset loader: `.wgsl` to `ShaderAsset`
|
|
14611
|
-
* (`docs/plan/2026-09-terrain-particles-shaders.md` §3.1).
|
|
14612
|
-
*
|
|
14613
|
-
* One loader covers all three forms, because `.surface.wgsl` and `.post.wgsl` both end in `.wgsl`;
|
|
14614
|
-
* the `@ignifx shader|surface|post` pragma is what says which form a file is.
|
|
14615
|
-
*/
|
|
14616
|
-
/**
|
|
14617
|
-
* Builds the loader for `.wgsl` addresses.
|
|
14618
|
-
*
|
|
14619
|
-
* @remarks
|
|
14620
|
-
* A parse failure fails the load, unlike a malformed `.material.json` property: a shader whose
|
|
14621
|
-
* declaration cannot be read has no usable fallback (`CONSTITUTION.md` §3.9).
|
|
14622
|
-
*
|
|
14623
|
-
* The loader is also where the custom-shader layers are pulled into memory. A `ShaderAsset` can only
|
|
14624
|
-
* come from here, so awaiting them here is what lets `createMaterialAsset` and the `.material.json`
|
|
14625
|
-
* loader build a shader material synchronously (`../shader-support.ts`).
|
|
14626
|
-
*
|
|
14627
|
-
* @returns The loader to register with `ctx.registerAssetLoader`.
|
|
14628
|
-
*
|
|
14629
|
-
* @example
|
|
14630
|
-
* ```ts
|
|
14631
|
-
* ctx.registerAssetLoader(createShaderLoader());
|
|
14632
|
-
* ```
|
|
14633
|
-
*
|
|
14634
|
-
* @public
|
|
14635
|
-
*/
|
|
14636
|
-
function createShaderLoader() {
|
|
14637
|
-
return {
|
|
14638
|
-
type: SHADER_ASSET_TYPE,
|
|
14639
|
-
extensions: SHADER_FILE_EXTENSIONS,
|
|
14640
|
-
async load(ctx) {
|
|
14641
|
-
const [source, pragma] = await Promise.all([ctx.fetchText(), import("./shader-pragma-DmZpxGUo.js")]);
|
|
14642
|
-
const declaration = pragma.parseShaderDeclaration(source, ctx.address);
|
|
14643
|
-
await loadShaderSupport();
|
|
14644
|
-
if (declaration.kind === "surface") await loadSurfaceShaderSupport();
|
|
14645
|
-
else if (declaration.kind === "post") await loadPostEffectSupport();
|
|
14646
|
-
return new ShaderAsset(ctx.address, source, declaration);
|
|
14647
|
-
}
|
|
14648
|
-
};
|
|
14649
|
-
}
|
|
14650
|
-
//#endregion
|
|
14651
|
-
//#region src/lite/gpu/texture.ts
|
|
14652
|
-
/**
|
|
14653
|
-
* Loads a 2D texture from a URL.
|
|
14654
|
-
*
|
|
14655
|
-
* @param engine - The engine that owns the GPU texture.
|
|
14656
|
-
* @param url - Where to fetch it from.
|
|
14657
|
-
* @param options - Sampler, mipmap, colour-space, and decode options.
|
|
14658
|
-
* @returns The texture. Its reference count starts at an implicit one.
|
|
14659
|
-
*
|
|
14660
|
-
* @example
|
|
14661
|
-
* ```ts
|
|
14662
|
-
* const albedo = await loadTexture(engine, "textures/hero-albedo.png", { srgb: true });
|
|
14663
|
-
* ```
|
|
14664
|
-
*
|
|
14665
|
-
* @internal
|
|
14666
|
-
*/
|
|
14667
|
-
function loadTexture(engine, url, options) {
|
|
14668
|
-
return loadTexture2D(engine, url, options);
|
|
14669
|
-
}
|
|
14670
|
-
/**
|
|
14671
|
-
* Loads a KTX2 (Basis Universal) texture from a URL, transcoded to the device's best compressed
|
|
14672
|
-
* format.
|
|
14673
|
-
*
|
|
14674
|
-
* @remarks
|
|
14675
|
-
* Lite's KTX2 glue is imported on first use (`./decoders.ts`), so a game that never loads a `.ktx2`
|
|
14676
|
-
* does not carry it. The decoder script and its transcoders load from wherever
|
|
14677
|
-
* `applyLiteDecoderUrls` last pointed Lite, or from `cdn.babylonjs.com` when nothing did. Sampler and
|
|
14678
|
-
* sRGB options apply; `mipMaps`, `invertY` and `premultiplyAlpha` do not — the file's rows and mips
|
|
14679
|
-
* are uploaded as stored (`./decoders.ts` explains the orientation).
|
|
14680
|
-
*
|
|
14681
|
-
* @param engine - The engine that owns the GPU texture.
|
|
14682
|
-
* @param url - Where to fetch it from.
|
|
14683
|
-
* @param options - Colour space and sampler.
|
|
14684
|
-
* @returns The texture. Its reference count starts at an implicit one.
|
|
14685
|
-
*
|
|
14686
|
-
* @example
|
|
14687
|
-
* ```ts
|
|
14688
|
-
* const albedo = await loadKtx2Texture(engine, "textures/hero-albedo.ktx2", { srgb: true });
|
|
14689
|
-
* ```
|
|
14690
|
-
*
|
|
14691
|
-
* @internal
|
|
14692
|
-
*/
|
|
14693
|
-
async function loadKtx2Texture(engine, url, options = {}) {
|
|
14694
|
-
return (await import("./decoders-BUQrlS8U.js")).loadKtx2TextureWithOptions(engine, url, options);
|
|
14695
|
-
}
|
|
14696
|
-
/**
|
|
14697
|
-
* Loads a Basis Universal (`.basis`) texture from a URL.
|
|
14698
|
-
*
|
|
14699
|
-
* @remarks
|
|
14700
|
-
* Babylon Lite 1.34 always fetches the Basis transcoder from `cdn.babylonjs.com` and offers no
|
|
14701
|
-
* setter for it, so this works only where the page may load scripts from that origin. Prefer
|
|
14702
|
-
* `.ktx2`, which carries the same Basis payloads and whose decoder is served locally.
|
|
14703
|
-
*
|
|
14704
|
-
* @param engine - The engine that owns the GPU texture.
|
|
14705
|
-
* @param url - Where to fetch it from.
|
|
14706
|
-
* @param options - Colour space and sampler.
|
|
14707
|
-
* @returns The texture.
|
|
14708
|
-
*
|
|
14709
|
-
* @internal
|
|
14710
|
-
*/
|
|
14711
|
-
async function loadBasisTexture(engine, url, options = {}) {
|
|
14712
|
-
return (await import("./decoders-BUQrlS8U.js")).loadBasisTextureWithOptions(engine, url, options);
|
|
14713
|
-
}
|
|
14714
|
-
/**
|
|
14715
|
-
* Creates a 2D texture from tightly packed RGBA8 bytes.
|
|
14716
|
-
*
|
|
14717
|
-
* @param engine - The engine that owns the GPU texture.
|
|
14718
|
-
* @param data - `width * height * 4` bytes, row-major, top row first, straight alpha.
|
|
14719
|
-
* @param width - The width in texels, at least 1.
|
|
14720
|
-
* @param height - The height in texels, at least 1.
|
|
14721
|
-
* @param options - Sampler and colour-space overrides.
|
|
14722
|
-
* @returns The texture, created with `COPY_DST` so {@link updateTextureFromPixels} can write to it.
|
|
14723
|
-
* Its reference count starts at an implicit one.
|
|
14724
|
-
*
|
|
14725
|
-
* @internal
|
|
14726
|
-
*/
|
|
14727
|
-
function createTextureFromPixels(engine, data, width, height, options) {
|
|
14728
|
-
return createTexture2DFromPixels(engine, data, width, height, {
|
|
14729
|
-
addressModeU: options.addressModeU,
|
|
14730
|
-
addressModeV: options.addressModeV,
|
|
14731
|
-
minFilter: options.minFilter,
|
|
14732
|
-
magFilter: options.magFilter,
|
|
14733
|
-
srgb: options.srgb
|
|
14734
|
-
});
|
|
14735
|
-
}
|
|
14736
|
-
/**
|
|
14737
|
-
* Writes a rectangular region of a pixel texture.
|
|
14738
|
-
*
|
|
14739
|
-
* @remarks
|
|
14740
|
-
* Only legal on a texture from {@link createTextureFromPixels}: any other `Texture2D` was created
|
|
14741
|
-
* without `COPY_DST` usage and WebGPU rejects the write.
|
|
14742
|
-
*
|
|
14743
|
-
* @param engine - The engine that owns the texture.
|
|
14744
|
-
* @param texture - The target.
|
|
14745
|
-
* @param data - `width * height * 4` bytes for the region, row-major.
|
|
14746
|
-
* @param x - The destination origin's column, in texels.
|
|
14747
|
-
* @param y - The destination origin's row, in texels.
|
|
14748
|
-
* @param width - The region's width, in texels.
|
|
14749
|
-
* @param height - The region's height, in texels.
|
|
14750
|
-
*
|
|
14751
|
-
* @internal
|
|
14752
|
-
*/
|
|
14753
|
-
function updateTextureFromPixels(engine, texture, data, x, y, width, height) {
|
|
14754
|
-
updateTexture2DFromPixels(engine, texture, data, x, y, width, height);
|
|
14755
|
-
}
|
|
14756
|
-
/**
|
|
14757
|
-
* Claims a share of a texture, so a later {@link releaseTextureHandle} by someone else does not
|
|
14758
|
-
* destroy it.
|
|
14759
|
-
*
|
|
14760
|
-
* @param texture - The texture to retain.
|
|
14761
|
-
*
|
|
14762
|
-
* @internal
|
|
14763
|
-
*/
|
|
14764
|
-
function retainTexture(texture) {
|
|
14765
|
-
acquireTexture(texture);
|
|
14766
|
-
}
|
|
14767
|
-
/**
|
|
14768
|
-
* Gives up a share of a texture, destroying it when the last share goes.
|
|
14769
|
-
*
|
|
14770
|
-
* @param texture - The texture to release.
|
|
14771
|
-
* @returns `true` when this call destroyed the underlying `GPUTexture`.
|
|
14772
|
-
*
|
|
14773
|
-
* @internal
|
|
14774
|
-
*/
|
|
14775
|
-
function releaseTextureHandle(texture) {
|
|
14776
|
-
return releaseTexture(texture);
|
|
14777
|
-
}
|
|
14778
|
-
//#endregion
|
|
14779
|
-
//#region src/render/gpu/texture-pixels.ts
|
|
14780
|
-
/**
|
|
14781
|
-
* The device-only half of `TextureAsset` (`docs/architecture/07-rendering.md` §6).
|
|
14782
|
-
*
|
|
14783
|
-
* Each function takes the engine or the texture as a nullable and returns early when it is `null`,
|
|
14784
|
-
* so the asset keeps no headless branch of its own.
|
|
14785
|
-
*/
|
|
14786
|
-
/**
|
|
14787
|
-
* Creates a texture from tightly packed RGBA8 bytes, or nothing under a headless app.
|
|
14788
|
-
*
|
|
14789
|
-
* @param isHeadless - Whether the app has a device.
|
|
14790
|
-
* @param engine - The engine that uploads it.
|
|
14791
|
-
* @param data - `width * height * 4` bytes, row-major, top row first, straight alpha.
|
|
14792
|
-
* @param width - The width in texels.
|
|
14793
|
-
* @param height - The height in texels.
|
|
14794
|
-
* @param options - The resolved import options; only the sampler subset reaches Lite.
|
|
14795
|
-
* @returns The texture, or `null`.
|
|
14796
|
-
*
|
|
14797
|
-
* @internal
|
|
14798
|
-
*/
|
|
14799
|
-
function createPixelTexture(isHeadless, engine, data, width, height, options) {
|
|
14800
|
-
if (isHeadless) return null;
|
|
14801
|
-
return createTextureFromPixels(engine, data, width, height, {
|
|
14802
|
-
addressModeU: options.addressModeU,
|
|
14803
|
-
addressModeV: options.addressModeV,
|
|
14804
|
-
minFilter: options.minFilter,
|
|
14805
|
-
magFilter: options.magFilter,
|
|
14806
|
-
srgb: options.srgb
|
|
14807
|
-
});
|
|
14808
|
-
}
|
|
14809
|
-
/**
|
|
14810
|
-
* Writes a rectangular region of a pixel texture, when it still has one.
|
|
16129
|
+
* Loads the post-effect compiler and the Babylon Lite effect adapter, once per process.
|
|
14811
16130
|
*
|
|
14812
|
-
* @
|
|
14813
|
-
* @param texture - The target, or `null` when the app is headless or the share was released.
|
|
14814
|
-
* @param data - The region's RGBA8 bytes.
|
|
14815
|
-
* @param x - The destination column.
|
|
14816
|
-
* @param y - The destination row.
|
|
14817
|
-
* @param width - The region width.
|
|
14818
|
-
* @param height - The region height.
|
|
16131
|
+
* @returns A promise that settles once both are in place.
|
|
14819
16132
|
*
|
|
14820
16133
|
* @internal
|
|
14821
16134
|
*/
|
|
14822
|
-
function
|
|
14823
|
-
|
|
14824
|
-
|
|
16135
|
+
async function loadPostEffectSupport() {
|
|
16136
|
+
const [compiler, effects] = await Promise.all([compilerLayer ?? import("./post-effect-compiler-cCq9lcHt.js"), effectLayer ?? import("./effect-task-CMbuO6Kb.js")]);
|
|
16137
|
+
compilerLayer = compiler;
|
|
16138
|
+
effectLayer = effects;
|
|
14825
16139
|
}
|
|
14826
16140
|
/**
|
|
14827
|
-
*
|
|
16141
|
+
* The post-effect compiler, if it has been loaded.
|
|
14828
16142
|
*
|
|
14829
|
-
* @
|
|
16143
|
+
* @returns The module, or `null` before any `.post.wgsl` has been loaded.
|
|
14830
16144
|
*
|
|
14831
16145
|
* @internal
|
|
14832
16146
|
*/
|
|
14833
|
-
function
|
|
14834
|
-
|
|
14835
|
-
retainTexture(texture);
|
|
16147
|
+
function postEffectCompiler() {
|
|
16148
|
+
return compilerLayer;
|
|
14836
16149
|
}
|
|
14837
16150
|
/**
|
|
14838
|
-
*
|
|
16151
|
+
* The Babylon Lite effect adapter, if it has been loaded.
|
|
14839
16152
|
*
|
|
14840
|
-
* @
|
|
14841
|
-
* @returns `true` when this call destroyed the underlying `GPUTexture`.
|
|
16153
|
+
* @returns The module, or `null` before any `.post.wgsl` has been loaded.
|
|
14842
16154
|
*
|
|
14843
16155
|
* @internal
|
|
14844
16156
|
*/
|
|
14845
|
-
function
|
|
14846
|
-
return
|
|
16157
|
+
function effectTaskSupport() {
|
|
16158
|
+
return effectLayer;
|
|
14847
16159
|
}
|
|
14848
16160
|
//#endregion
|
|
14849
|
-
//#region src/render/
|
|
16161
|
+
//#region src/render/shader-asset.ts
|
|
14850
16162
|
/**
|
|
14851
|
-
* `
|
|
14852
|
-
*
|
|
14853
|
-
*
|
|
14854
|
-
* ## Lifetime, and why the loader does not `acquireTexture`
|
|
14855
|
-
*
|
|
14856
|
-
* Lite reference-counts `GPUTexture`s in a process-wide pool keyed by the underlying texture
|
|
14857
|
-
* (`lib/resource/gpu-pool.js`): `acquireTexture` increments, `releaseTexture` decrements and
|
|
14858
|
-
* destroys at zero, and **a texture that was never acquired starts at an implicit count of one**.
|
|
14859
|
-
* A freshly loaded texture is therefore already owned once, by the asset that loaded it. Calling
|
|
14860
|
-
* `acquireTexture` in the loader — which `07-rendering.md` §7 could be read as asking for — would
|
|
14861
|
-
* put the count at two and make the matching `releaseTexture` on unload free nothing: a leak, not a
|
|
14862
|
-
* safety net. So the loader acquires nothing and {@link TextureAsset.releaseGpu} releases the one
|
|
14863
|
-
* implicit share when the asset is unloaded.
|
|
14864
|
-
*
|
|
14865
|
-
* Sharing is expressed one level up instead. A `MaterialAsset` that samples a texture pulls it in
|
|
14866
|
-
* with `ctx.loadDependency`, which retains the *asset handle*; the texture's GPU share is released
|
|
14867
|
-
* only when the last asset holding that handle is collected. That is the same rule every other
|
|
14868
|
-
* dependency follows, and it is observable through `handle.refCount`.
|
|
14869
|
-
* {@link TextureAsset.retainGpu} exists for the rare case where a Lite object outlives its asset.
|
|
16163
|
+
* One `.wgsl` file: its text and the declaration its `// @ignifx` pragmas carry
|
|
16164
|
+
* (`docs/plan/2026-09-terrain-particles-shaders.md` §3.1, ADR-0024).
|
|
14870
16165
|
*
|
|
14871
|
-
*
|
|
14872
|
-
*
|
|
14873
|
-
* kind of texture {@link TextureAsset.update} accepts, because `createTexture2DFromPixels` is what
|
|
14874
|
-
* asks WebGPU for `COPY_DST` usage (`index.d.ts` 13400). The bytes are copied at creation and not
|
|
14875
|
-
* retained; the asset keeps only the size, which is what `update` validates against.
|
|
16166
|
+
* The asset is the program plus the schema of what a material may set on it, never the values. It
|
|
16167
|
+
* needs no device, so a `.wgsl` loads completely in Node. Two facts an author has to know:
|
|
14876
16168
|
*
|
|
14877
|
-
*
|
|
16169
|
+
* - The whole file is handed to Babylon Lite as **both** the vertex and the fragment source
|
|
16170
|
+
* (`lib/material/shader/shader-pipeline.js` 66–79), so structs and helpers are shared and the file
|
|
16171
|
+
* must compile in both stages — `textureSample` is fragment-only; vertex code uses
|
|
16172
|
+
* `textureSampleLevel` or `textureLoad`.
|
|
16173
|
+
* - Lite's system uniforms are read as `shaderSystem.<name>`; everything else, including the
|
|
16174
|
+
* uniforms ignifx supplies, as `shaderUniforms.<name>`.
|
|
16175
|
+
*/
|
|
16176
|
+
/**
|
|
16177
|
+
* The asset type shaders are registered under.
|
|
14878
16178
|
*
|
|
14879
|
-
*
|
|
14880
|
-
* headless load produces an asset with `lite.texture === null` — the `gpu: null` shape
|
|
14881
|
-
* `05-assets-and-loading.md` §5 requires of every GPU loader. `fromPixels` behaves the same way and
|
|
14882
|
-
* still validates and records the size, so a Node test can assert that a generator wrote the right
|
|
14883
|
-
* number of bytes without a device.
|
|
16179
|
+
* @public
|
|
14884
16180
|
*/
|
|
16181
|
+
const SHADER_ASSET_TYPE = "shader";
|
|
14885
16182
|
/**
|
|
14886
|
-
* The
|
|
16183
|
+
* The address extensions that select the shader loader.
|
|
16184
|
+
*
|
|
16185
|
+
* @remarks
|
|
16186
|
+
* `.surface.wgsl` and `.post.wgsl` both end in `.wgsl`, so one extension covers all three forms.
|
|
14887
16187
|
*
|
|
14888
16188
|
* @public
|
|
14889
16189
|
*/
|
|
14890
|
-
const
|
|
16190
|
+
const SHADER_FILE_EXTENSIONS = Object.freeze([".wgsl"]);
|
|
14891
16191
|
/**
|
|
14892
|
-
* A loaded
|
|
16192
|
+
* A loaded `.wgsl` file: its source and what its pragmas declare
|
|
16193
|
+
* (`docs/plan/2026-09-terrain-particles-shaders.md` §3.1).
|
|
16194
|
+
*
|
|
16195
|
+
* @remarks
|
|
16196
|
+
* Shaders are shared: many materials reference one shader asset, and each material holds its own
|
|
16197
|
+
* values. Editing the file in development re-parses the declaration and rebuilds every material
|
|
16198
|
+
* built from it in place (`docs/architecture/05-assets-and-loading.md` §7).
|
|
14893
16199
|
*
|
|
14894
16200
|
* @example
|
|
14895
16201
|
* ```ts
|
|
14896
|
-
* const
|
|
14897
|
-
*
|
|
16202
|
+
* const dissolve = await app.assets.loadAsync<ShaderAsset>("shaders/dissolve.wgsl");
|
|
16203
|
+
* dissolve.value.declaration.uniforms.map((uniform) => uniform.name); // ["progress", "edgeColor"]
|
|
14898
16204
|
* ```
|
|
14899
16205
|
*
|
|
14900
16206
|
* @public
|
|
14901
16207
|
*/
|
|
14902
|
-
var
|
|
14903
|
-
/** The type name the asset service registers
|
|
14904
|
-
static assetType =
|
|
14905
|
-
/** The address the
|
|
16208
|
+
var ShaderAsset = class {
|
|
16209
|
+
/** The type name the asset service registers shaders under. */
|
|
16210
|
+
static assetType = SHADER_ASSET_TYPE;
|
|
16211
|
+
/** The address the shader was loaded from. */
|
|
14906
16212
|
address;
|
|
14907
|
-
/** The
|
|
14908
|
-
|
|
14909
|
-
|
|
14910
|
-
|
|
16213
|
+
/** The whole file, as written. It is handed to Babylon Lite as both the vertex and the fragment source. */
|
|
16214
|
+
source;
|
|
16215
|
+
/** What the file's `// @ignifx` pragmas declare. */
|
|
16216
|
+
declaration;
|
|
14911
16217
|
/**
|
|
14912
|
-
* Wraps a
|
|
14913
|
-
* these.
|
|
16218
|
+
* Wraps a parsed shader file. The `shader` loader constructs these.
|
|
14914
16219
|
*
|
|
14915
|
-
* @param address - The address it was loaded from
|
|
14916
|
-
* @param
|
|
14917
|
-
* @param
|
|
14918
|
-
* @param pixelSource - The engine and size of a texture built from raw pixels, or `null` for a
|
|
14919
|
-
* texture that came from a file. It is what makes {@link TextureAsset.update} legal.
|
|
16220
|
+
* @param address - The address it was loaded from.
|
|
16221
|
+
* @param source - The whole file.
|
|
16222
|
+
* @param declaration - The parsed pragmas.
|
|
14920
16223
|
*
|
|
14921
16224
|
* @internal
|
|
14922
16225
|
*/
|
|
14923
|
-
constructor(address,
|
|
16226
|
+
constructor(address, source, declaration) {
|
|
14924
16227
|
this.address = address;
|
|
14925
|
-
this
|
|
14926
|
-
this.
|
|
14927
|
-
this.#pixelSource = pixelSource;
|
|
14928
|
-
}
|
|
14929
|
-
/**
|
|
14930
|
-
* The Babylon Lite objects the asset owns. Unstable escape hatch.
|
|
14931
|
-
*
|
|
14932
|
-
* @returns The GPU texture, or `null` under a headless app.
|
|
14933
|
-
*/
|
|
14934
|
-
get lite() {
|
|
14935
|
-
return { texture: this.#texture };
|
|
14936
|
-
}
|
|
14937
|
-
/**
|
|
14938
|
-
* The texture's width, in texels.
|
|
14939
|
-
*
|
|
14940
|
-
* @remarks
|
|
14941
|
-
* Known for every texture that reached the GPU — Lite records it on the texture handle
|
|
14942
|
-
* (`index.d.ts` 12876) — and for a headless {@link TextureAsset.fromPixels} texture, which
|
|
14943
|
-
* remembers the size it was asked for. A texture **loaded** from a file under a headless app
|
|
14944
|
-
* decoded nothing, so it reports `0`.
|
|
14945
|
-
*
|
|
14946
|
-
* @returns The width, or `0` when nothing knows it.
|
|
14947
|
-
*/
|
|
14948
|
-
get width() {
|
|
14949
|
-
return this.#texture?.width ?? this.#pixelSource?.width ?? 0;
|
|
14950
|
-
}
|
|
14951
|
-
/**
|
|
14952
|
-
* The texture's height, in texels.
|
|
14953
|
-
*
|
|
14954
|
-
* @returns The height, or `0`; see {@link TextureAsset.width}.
|
|
14955
|
-
*/
|
|
14956
|
-
get height() {
|
|
14957
|
-
return this.#texture?.height ?? this.#pixelSource?.height ?? 0;
|
|
14958
|
-
}
|
|
14959
|
-
/**
|
|
14960
|
-
* Whether the GPU texture has been given up.
|
|
14961
|
-
*
|
|
14962
|
-
* @returns `true` once {@link TextureAsset.releaseGpu} has run.
|
|
14963
|
-
*/
|
|
14964
|
-
get isReleased() {
|
|
14965
|
-
return this.#texture === null;
|
|
14966
|
-
}
|
|
14967
|
-
/**
|
|
14968
|
-
* Claims an extra share of the GPU texture, so releasing the asset does not destroy it.
|
|
14969
|
-
*
|
|
14970
|
-
* @remarks
|
|
14971
|
-
* Only needed when a Lite object has to outlive the asset that loaded it. Ordinary sharing goes
|
|
14972
|
-
* through `ctx.loadDependency`, which counts the asset handle instead.
|
|
14973
|
-
*/
|
|
14974
|
-
retainGpu() {
|
|
14975
|
-
retainTextureShare(this.#texture);
|
|
14976
|
-
}
|
|
14977
|
-
/**
|
|
14978
|
-
* Gives up the asset's share of the GPU texture, destroying it when it was the last one. Calling
|
|
14979
|
-
* it twice is a no-op, and it is a no-op under a headless app.
|
|
14980
|
-
*
|
|
14981
|
-
* @returns `true` when this call destroyed the underlying `GPUTexture`.
|
|
14982
|
-
*/
|
|
14983
|
-
releaseGpu() {
|
|
14984
|
-
const texture = this.#texture;
|
|
14985
|
-
this.#texture = null;
|
|
14986
|
-
return releaseTextureShare(texture);
|
|
14987
|
-
}
|
|
14988
|
-
/**
|
|
14989
|
-
* Writes a rectangular region of the texture from RGBA8 bytes.
|
|
14990
|
-
*
|
|
14991
|
-
* @remarks
|
|
14992
|
-
* Only a texture from {@link TextureAsset.fromPixels} can be written to: that is the factory that
|
|
14993
|
-
* asks WebGPU for `COPY_DST` usage. The region defaults to the whole texture. Nothing is uploaded
|
|
14994
|
-
* under a headless app, but the size check still runs, so a generator's arithmetic is testable
|
|
14995
|
-
* without a device.
|
|
14996
|
-
*
|
|
14997
|
-
* The texture has one mip level, so there is no chain to regenerate and an update is complete the
|
|
14998
|
-
* moment the queue drains.
|
|
14999
|
-
*
|
|
15000
|
-
* @param data - `width * height * 4` bytes for the region, row-major, top row first.
|
|
15001
|
-
* @param x - The destination origin's column. Defaults to `0`.
|
|
15002
|
-
* @param y - The destination origin's row. Defaults to `0`.
|
|
15003
|
-
* @param width - The region's width. Defaults to the texture's width.
|
|
15004
|
-
* @param height - The region's height. Defaults to the texture's height.
|
|
15005
|
-
* @throws IgnifxError with code `IGX-0702` when the texture did not come from
|
|
15006
|
-
* {@link TextureAsset.fromPixels}.
|
|
15007
|
-
* @throws IgnifxError with code `IGX-0722` when the region falls outside the texture or `data` is
|
|
15008
|
-
* not exactly `width * height * 4` bytes long.
|
|
15009
|
-
*
|
|
15010
|
-
* @example
|
|
15011
|
-
* ```ts
|
|
15012
|
-
* const splat = TextureAsset.fromPixels(app, "splat", pixels, 256, 256);
|
|
15013
|
-
* pixels[0] = 255;
|
|
15014
|
-
* splat.value.update(pixels.subarray(0, 4), 0, 0, 1, 1); // one texel
|
|
15015
|
-
* ```
|
|
15016
|
-
*/
|
|
15017
|
-
update(data, x = 0, y = 0, width, height) {
|
|
15018
|
-
const source = this.#pixelSource;
|
|
15019
|
-
if (source === null) throw new IgnifxError(CoreErrorCode.invalidRuntime, `${this.address} was not created by TextureAsset.fromPixels, so it cannot be updated.`, {
|
|
15020
|
-
context: {
|
|
15021
|
-
asset: this.address,
|
|
15022
|
-
member: "TextureAsset.update()"
|
|
15023
|
-
},
|
|
15024
|
-
hint: "Only a texture built with TextureAsset.fromPixels carries the COPY_DST usage an update needs."
|
|
15025
|
-
});
|
|
15026
|
-
const regionWidth = width ?? source.width;
|
|
15027
|
-
const regionHeight = height ?? source.height;
|
|
15028
|
-
assertPixelRegion(this.address, data, source, x, y, regionWidth, regionHeight);
|
|
15029
|
-
writePixelTexture(source.engine, this.#texture, data, x, y, regionWidth, regionHeight);
|
|
16228
|
+
this.source = source;
|
|
16229
|
+
this.declaration = declaration;
|
|
15030
16230
|
}
|
|
15031
16231
|
/**
|
|
15032
|
-
*
|
|
15033
|
-
*
|
|
15034
|
-
* @remarks
|
|
15035
|
-
* The bytes are `width * height * 4` long, row-major, **top row first**, with straight (not
|
|
15036
|
-
* premultiplied) alpha. They are copied into the GPU texture and not retained.
|
|
15037
|
-
*
|
|
15038
|
-
* The result is the only kind of texture {@link TextureAsset.update} accepts. Ownership follows
|
|
15039
|
-
* the rule every in-code asset follows: the caller holds the handle, releasing it (or letting a
|
|
15040
|
-
* `using` block do it) runs the `texture` type's unload, which releases the GPU share.
|
|
15041
|
-
*
|
|
15042
|
-
* @param app - The app whose engine uploads the texture and whose asset service holds the handle.
|
|
15043
|
-
* @param name - A human-readable name. It becomes the asset's `address` — the string diagnostics
|
|
15044
|
-
* and the `IGX-0722` message name it by — while the handle's own address is the generated
|
|
15045
|
-
* `memory:texture/<ulid>` the asset service published it at.
|
|
15046
|
-
* @param data - `width * height * 4` bytes.
|
|
15047
|
-
* @param width - The width in texels, at least 1.
|
|
15048
|
-
* @param height - The height in texels, at least 1.
|
|
15049
|
-
* @param options - Sampler and colour-space overrides; `nearest`, `clamp`, no sRGB by default.
|
|
15050
|
-
* @returns The handle, already loaded, with one holder — the caller.
|
|
15051
|
-
* @throws IgnifxError with code `IGX-0722` when `width` or `height` is not a positive integer, or
|
|
15052
|
-
* `data` is not exactly `width * height * 4` bytes long.
|
|
16232
|
+
* Which of the three authoring forms the file declared.
|
|
15053
16233
|
*
|
|
15054
|
-
* @
|
|
15055
|
-
* ```ts
|
|
15056
|
-
* const pixels = new Uint8Array(2 * 2 * 4);
|
|
15057
|
-
* pixels.fill(255);
|
|
15058
|
-
* using ramp = TextureAsset.fromPixels(app, "ramp", pixels, 2, 2, { filter: "nearest" });
|
|
15059
|
-
* ```
|
|
16234
|
+
* @returns `"shader"`, `"surface"`, or `"post"`.
|
|
15060
16235
|
*/
|
|
15061
|
-
|
|
15062
|
-
|
|
15063
|
-
const resolved = resolvePixelOptions(options);
|
|
15064
|
-
const engine = app.lite.engine;
|
|
15065
|
-
const texture = createPixelTexture(app.isHeadless, engine, data, width, height, resolved);
|
|
15066
|
-
const asset = new TextureAsset(name, texture, resolved, {
|
|
15067
|
-
engine,
|
|
15068
|
-
width,
|
|
15069
|
-
height
|
|
15070
|
-
});
|
|
15071
|
-
return app.assets.register(asset, { type: TEXTURE_ASSET_TYPE });
|
|
16236
|
+
get kind() {
|
|
16237
|
+
return this.declaration.kind;
|
|
15072
16238
|
}
|
|
15073
16239
|
};
|
|
16240
|
+
//#endregion
|
|
16241
|
+
//#region src/render/loaders/shader-loader.ts
|
|
15074
16242
|
/**
|
|
15075
|
-
*
|
|
15076
|
-
|
|
15077
|
-
const BYTES_PER_TEXEL = 4;
|
|
15078
|
-
/**
|
|
15079
|
-
* Checks that a byte count matches a texture size.
|
|
15080
|
-
*
|
|
15081
|
-
* @param asset - The name or address named in the error.
|
|
15082
|
-
* @param data - The pixel bytes.
|
|
15083
|
-
* @param width - The width in texels.
|
|
15084
|
-
* @param height - The height in texels.
|
|
15085
|
-
* @throws IgnifxError with code `IGX-0722` when the size is not a positive integer pair or the byte
|
|
15086
|
-
* count does not match.
|
|
15087
|
-
*/
|
|
15088
|
-
function assertPixelSize(asset, data, width, height) {
|
|
15089
|
-
const valid = Number.isInteger(width) && Number.isInteger(height) && width > 0 && height > 0;
|
|
15090
|
-
const expected = width * height * BYTES_PER_TEXEL;
|
|
15091
|
-
if (valid && data.length === expected) return;
|
|
15092
|
-
throw new IgnifxError(CoreErrorCode.invalidPixelData, `${asset}: ${String(data.length)} bytes of pixel data do not match ${String(width)}x${String(height)} RGBA.`, {
|
|
15093
|
-
context: {
|
|
15094
|
-
asset,
|
|
15095
|
-
bytes: data.length,
|
|
15096
|
-
width,
|
|
15097
|
-
height
|
|
15098
|
-
},
|
|
15099
|
-
hint: "RGBA8 pixel data is exactly width * height * 4 bytes, row-major with the top row first."
|
|
15100
|
-
});
|
|
15101
|
-
}
|
|
15102
|
-
/**
|
|
15103
|
-
* Checks that an update's region lies inside the texture and that the byte count matches it.
|
|
15104
|
-
*
|
|
15105
|
-
* @param asset - The address named in the error.
|
|
15106
|
-
* @param data - The pixel bytes.
|
|
15107
|
-
* @param source - The texture's recorded size.
|
|
15108
|
-
* @param x - The region's origin column.
|
|
15109
|
-
* @param y - The region's origin row.
|
|
15110
|
-
* @param width - The region's width.
|
|
15111
|
-
* @param height - The region's height.
|
|
15112
|
-
* @throws IgnifxError with code `IGX-0722` when the region does not fit or the byte count is wrong.
|
|
15113
|
-
*/
|
|
15114
|
-
function assertPixelRegion(asset, data, source, x, y, width, height) {
|
|
15115
|
-
if (!(Number.isInteger(x) && Number.isInteger(y) && x >= 0 && y >= 0 && x + width <= source.width && y + height <= source.height)) throw new IgnifxError(CoreErrorCode.invalidPixelData, `${asset}: the region ${String(width)}x${String(height)} at (${String(x)}, ${String(y)}) falls outside a ${String(source.width)}x${String(source.height)} texture.`, {
|
|
15116
|
-
context: {
|
|
15117
|
-
asset,
|
|
15118
|
-
bytes: data.length,
|
|
15119
|
-
x,
|
|
15120
|
-
y,
|
|
15121
|
-
width,
|
|
15122
|
-
height
|
|
15123
|
-
},
|
|
15124
|
-
hint: "An update writes inside the texture it was created with; recreate it to change its size."
|
|
15125
|
-
});
|
|
15126
|
-
assertPixelSize(asset, data, width, height);
|
|
15127
|
-
}
|
|
15128
|
-
/**
|
|
15129
|
-
* Fills in {@link PixelTextureOptions}'s defaults as a complete {@link TextureImportOptions}, so a
|
|
15130
|
-
* pixel texture reports its sampler state the way a loaded one does.
|
|
15131
|
-
*
|
|
15132
|
-
* @param options - What the caller named.
|
|
15133
|
-
* @returns The resolved options.
|
|
15134
|
-
*/
|
|
15135
|
-
function resolvePixelOptions(options) {
|
|
15136
|
-
const filter = options?.filter ?? "nearest";
|
|
15137
|
-
const wrap = options?.wrap === "repeat" ? "repeat" : "clamp-to-edge";
|
|
15138
|
-
return {
|
|
15139
|
-
srgb: options?.srgb ?? false,
|
|
15140
|
-
mipMaps: false,
|
|
15141
|
-
addressModeU: wrap,
|
|
15142
|
-
addressModeV: wrap,
|
|
15143
|
-
minFilter: filter,
|
|
15144
|
-
magFilter: filter,
|
|
15145
|
-
invertY: false,
|
|
15146
|
-
premultiplyAlpha: false
|
|
15147
|
-
};
|
|
15148
|
-
}
|
|
15149
|
-
/**
|
|
15150
|
-
* The import options a texture gets when its sidecar names none: Lite's own defaults, with `srgb`
|
|
15151
|
-
* off so that a data map is never silently decoded.
|
|
15152
|
-
*
|
|
15153
|
-
* @returns A fresh option set.
|
|
16243
|
+
* The `shader` asset loader: `.wgsl` to `ShaderAsset`
|
|
16244
|
+
* (`docs/plan/2026-09-terrain-particles-shaders.md` §3.1).
|
|
15154
16245
|
*
|
|
15155
|
-
*
|
|
16246
|
+
* One loader covers all three forms, because `.surface.wgsl` and `.post.wgsl` both end in `.wgsl`;
|
|
16247
|
+
* the `@ignifx shader|surface|post` pragma is what says which form a file is.
|
|
15156
16248
|
*/
|
|
15157
|
-
function defaultTextureImportOptions() {
|
|
15158
|
-
return {
|
|
15159
|
-
srgb: false,
|
|
15160
|
-
mipMaps: true,
|
|
15161
|
-
addressModeU: "repeat",
|
|
15162
|
-
addressModeV: "repeat",
|
|
15163
|
-
minFilter: "linear",
|
|
15164
|
-
magFilter: "linear",
|
|
15165
|
-
invertY: true,
|
|
15166
|
-
premultiplyAlpha: false
|
|
15167
|
-
};
|
|
15168
|
-
}
|
|
15169
16249
|
/**
|
|
15170
|
-
*
|
|
16250
|
+
* Builds the loader for `.wgsl` addresses.
|
|
15171
16251
|
*
|
|
15172
16252
|
* @remarks
|
|
15173
|
-
*
|
|
15174
|
-
*
|
|
15175
|
-
* from starting (`CONSTITUTION.md` §3.9 — the asset still loads, with the documented default).
|
|
15176
|
-
*
|
|
15177
|
-
* @param meta - The whole sidecar, or `null` when the manifest recorded none.
|
|
15178
|
-
* @returns The resolved options.
|
|
16253
|
+
* A parse failure fails the load, unlike a malformed `.material.json` property: a shader whose
|
|
16254
|
+
* declaration cannot be read has no usable fallback (`CONSTITUTION.md` §3.9).
|
|
15179
16255
|
*
|
|
15180
|
-
*
|
|
15181
|
-
|
|
15182
|
-
|
|
15183
|
-
const defaults = defaultTextureImportOptions();
|
|
15184
|
-
const raw = meta === null ? void 0 : meta[TEXTURE_ASSET_TYPE];
|
|
15185
|
-
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) return defaults;
|
|
15186
|
-
const block = raw;
|
|
15187
|
-
return {
|
|
15188
|
-
srgb: readBoolean(block, "srgb", defaults.srgb),
|
|
15189
|
-
mipMaps: readBoolean(block, "mipMaps", defaults.mipMaps),
|
|
15190
|
-
addressModeU: readString$1(block, "addressModeU", defaults.addressModeU),
|
|
15191
|
-
addressModeV: readString$1(block, "addressModeV", defaults.addressModeV),
|
|
15192
|
-
minFilter: readString$1(block, "minFilter", defaults.minFilter),
|
|
15193
|
-
magFilter: readString$1(block, "magFilter", defaults.magFilter),
|
|
15194
|
-
invertY: readBoolean(block, "invertY", defaults.invertY),
|
|
15195
|
-
premultiplyAlpha: readBoolean(block, "premultiplyAlpha", defaults.premultiplyAlpha)
|
|
15196
|
-
};
|
|
15197
|
-
}
|
|
15198
|
-
/**
|
|
15199
|
-
* Turns the resolved options into the shape `loadTexture2D` takes.
|
|
16256
|
+
* The loader is also where the custom-shader layers are pulled into memory. A `ShaderAsset` can only
|
|
16257
|
+
* come from here, so awaiting them here is what lets `createMaterialAsset` and the `.material.json`
|
|
16258
|
+
* loader build a shader material synchronously (`../shader-support.ts`).
|
|
15200
16259
|
*
|
|
15201
|
-
* @
|
|
15202
|
-
* The sampler strings are handed to Lite as declared; WebGPU rejects a mode or filter it does not
|
|
15203
|
-
* know, and that failure is a clearer signal than an ignored option would be.
|
|
16260
|
+
* @returns The loader to register with `ctx.registerAssetLoader`.
|
|
15204
16261
|
*
|
|
15205
|
-
* @
|
|
15206
|
-
*
|
|
16262
|
+
* @example
|
|
16263
|
+
* ```ts
|
|
16264
|
+
* ctx.registerAssetLoader(createShaderLoader());
|
|
16265
|
+
* ```
|
|
15207
16266
|
*
|
|
15208
|
-
* @
|
|
16267
|
+
* @public
|
|
15209
16268
|
*/
|
|
15210
|
-
function
|
|
16269
|
+
function createShaderLoader() {
|
|
15211
16270
|
return {
|
|
15212
|
-
|
|
15213
|
-
|
|
15214
|
-
|
|
15215
|
-
|
|
15216
|
-
|
|
15217
|
-
|
|
15218
|
-
|
|
15219
|
-
|
|
16271
|
+
type: SHADER_ASSET_TYPE,
|
|
16272
|
+
extensions: SHADER_FILE_EXTENSIONS,
|
|
16273
|
+
async load(ctx) {
|
|
16274
|
+
const [source, pragma] = await Promise.all([ctx.fetchText(), import("./shader-pragma-ljmAbVc2.js")]);
|
|
16275
|
+
const declaration = pragma.parseShaderDeclaration(source, ctx.address);
|
|
16276
|
+
await loadShaderSupport();
|
|
16277
|
+
if (declaration.kind === "surface") await loadSurfaceShaderSupport();
|
|
16278
|
+
else if (declaration.kind === "post") await loadPostEffectSupport();
|
|
16279
|
+
return new ShaderAsset(ctx.address, source, declaration);
|
|
16280
|
+
}
|
|
15220
16281
|
};
|
|
15221
16282
|
}
|
|
15222
|
-
/**
|
|
15223
|
-
* Reads a boolean out of a sidecar block.
|
|
15224
|
-
*
|
|
15225
|
-
* @param block - The sidecar sub-object.
|
|
15226
|
-
* @param key - The property name.
|
|
15227
|
-
* @param fallback - What to use when the property is absent or not a boolean.
|
|
15228
|
-
* @returns The value.
|
|
15229
|
-
*/
|
|
15230
|
-
function readBoolean(block, key, fallback) {
|
|
15231
|
-
const value = block[key];
|
|
15232
|
-
return typeof value === "boolean" ? value : fallback;
|
|
15233
|
-
}
|
|
15234
|
-
/**
|
|
15235
|
-
* Reads a string out of a sidecar block.
|
|
15236
|
-
*
|
|
15237
|
-
* @param block - The sidecar sub-object.
|
|
15238
|
-
* @param key - The property name.
|
|
15239
|
-
* @param fallback - What to use when the property is absent or not a string.
|
|
15240
|
-
* @returns The value.
|
|
15241
|
-
*/
|
|
15242
|
-
function readString$1(block, key, fallback) {
|
|
15243
|
-
const value = block[key];
|
|
15244
|
-
return typeof value === "string" ? value : fallback;
|
|
15245
|
-
}
|
|
15246
16283
|
//#endregion
|
|
15247
16284
|
//#region src/render/loaders/texture-loader.ts
|
|
15248
16285
|
/**
|
|
@@ -15617,6 +16654,13 @@ function asMesh(node) {
|
|
|
15617
16654
|
* fields, reports `lite.mesh === null`, and touches no scene (`07-rendering.md` §6).
|
|
15618
16655
|
*/
|
|
15619
16656
|
/**
|
|
16657
|
+
* How a lightmap combines with a material's shading: `"add"` adds the baked light to it,
|
|
16658
|
+
* `"shadowmap"` multiplies it (Babylon Lite's `useAsShadowmap`).
|
|
16659
|
+
*
|
|
16660
|
+
* @beta
|
|
16661
|
+
*/
|
|
16662
|
+
const LIGHTMAP_MODES = ["add", "shadowmap"];
|
|
16663
|
+
/**
|
|
15620
16664
|
* Draws a mesh asset with a material (`docs/architecture/07-rendering.md` §2.3).
|
|
15621
16665
|
*
|
|
15622
16666
|
* @example
|
|
@@ -15707,7 +16751,9 @@ var MeshRenderer = class MeshRenderer extends Component {
|
|
|
15707
16751
|
}
|
|
15708
16752
|
/** Removes the clone from the scene, releasing its share of the template's buffers. */
|
|
15709
16753
|
onDetach() {
|
|
15710
|
-
|
|
16754
|
+
const renderer = rendererInternals(this.app.renderer);
|
|
16755
|
+
renderer.releaseLightmap(this);
|
|
16756
|
+
this.#releaseClone(renderer);
|
|
15711
16757
|
}
|
|
15712
16758
|
/**
|
|
15713
16759
|
* Rebuilds the clone when `mesh` changed, then writes every other field that changed. The
|
|
@@ -15722,8 +16768,11 @@ var MeshRenderer = class MeshRenderer extends Component {
|
|
|
15722
16768
|
sync(renderer) {
|
|
15723
16769
|
const changed = this.#ensureClone(renderer);
|
|
15724
16770
|
const instance = this.#instance;
|
|
15725
|
-
if (instance === null)
|
|
15726
|
-
|
|
16771
|
+
if (instance === null) {
|
|
16772
|
+
renderer.releaseLightmap(this);
|
|
16773
|
+
return changed;
|
|
16774
|
+
}
|
|
16775
|
+
instance.applyMaterial(renderer.lightmapMaterial(this, this.#materialAsset(renderer)));
|
|
15727
16776
|
instance.applyDisplacement(this.#displacement(), this.entity.transform);
|
|
15728
16777
|
instance.applyFlags(this.receiveShadows, this.renderOrder, this.pickable && !this.#displayHidden);
|
|
15729
16778
|
instance.applyVisible(this.isEnabledInHierarchy && !this.#displayHidden);
|
|
@@ -15796,8 +16845,17 @@ var MeshRenderer = class MeshRenderer extends Component {
|
|
|
15796
16845
|
* @returns The Lite material.
|
|
15797
16846
|
*/
|
|
15798
16847
|
#material(renderer) {
|
|
16848
|
+
return this.#materialAsset(renderer).lite.material;
|
|
16849
|
+
}
|
|
16850
|
+
/**
|
|
16851
|
+
* The material asset this renderer draws with: the first it declares, or the app's default.
|
|
16852
|
+
*
|
|
16853
|
+
* @param renderer - The rendering service, for the default material.
|
|
16854
|
+
* @returns The material asset.
|
|
16855
|
+
*/
|
|
16856
|
+
#materialAsset(renderer) {
|
|
15799
16857
|
const declared = this.materials[0];
|
|
15800
|
-
return declared?.state === "loaded" ? declared.value
|
|
16858
|
+
return declared?.state === "loaded" ? declared.value : renderer.defaultMaterial();
|
|
15801
16859
|
}
|
|
15802
16860
|
/**
|
|
15803
16861
|
* How far the material's vertex stage may move a vertex: its shaders' `// @ignifx displace`.
|
|
@@ -15834,7 +16892,17 @@ function meshRendererSchema() {
|
|
|
15834
16892
|
castShadows: bool(true, { tooltip: "Whether this mesh is rendered into shadow maps." }),
|
|
15835
16893
|
receiveShadows: bool(true, { tooltip: "Whether shadow maps darken this mesh." }),
|
|
15836
16894
|
renderOrder: i32(0, { tooltip: "Sort key within the opaque or transparent phase; lower draws first." }),
|
|
15837
|
-
pickable: bool(true, { tooltip: "Whether picking considers this mesh at all." })
|
|
16895
|
+
pickable: bool(true, { tooltip: "Whether picking considers this mesh at all." }),
|
|
16896
|
+
lightmap: optional(record({
|
|
16897
|
+
asset: asset(LightmapAsset, { tooltip: "The baked .lightmap.json to sample." }),
|
|
16898
|
+
mode: enumOf(LIGHTMAP_MODES, "add", { tooltip: "add adds the baked light to the shading; shadowmap multiplies the shading by it." }),
|
|
16899
|
+
level: f32(1, {
|
|
16900
|
+
min: 0,
|
|
16901
|
+
tooltip: "A multiplier on the lightmap sample."
|
|
16902
|
+
}),
|
|
16903
|
+
gamma: bool(false, { tooltip: "Decode the sample from sRGB to linear; off for a texture already decoded." }),
|
|
16904
|
+
uv2: bool(true, { tooltip: "Sample with the mesh's second UV set; off uses the first." })
|
|
16905
|
+
}), { tooltip: "A baked lightmap; drawn only on a static entity with a PBR material." })
|
|
15838
16906
|
});
|
|
15839
16907
|
}
|
|
15840
16908
|
//#endregion
|
|
@@ -16118,6 +17186,16 @@ var Model = class Model extends Component {
|
|
|
16118
17186
|
return { root: this.#instance?.root ?? null };
|
|
16119
17187
|
}
|
|
16120
17188
|
/**
|
|
17189
|
+
* The meshes of the instantiated subtree, for the light-probe bake under an app with a device.
|
|
17190
|
+
*
|
|
17191
|
+
* @returns The meshes, or `null` while nothing is instantiated (headless, or not synced yet).
|
|
17192
|
+
*
|
|
17193
|
+
* @internal
|
|
17194
|
+
*/
|
|
17195
|
+
get instanceMeshes() {
|
|
17196
|
+
return this.#instance?.meshes ?? null;
|
|
17197
|
+
}
|
|
17198
|
+
/**
|
|
16121
17199
|
* Parents an entity under one of the model's glTF nodes — the "weapon in hand" case
|
|
16122
17200
|
* (`docs/architecture/07-rendering.md` §2.4).
|
|
16123
17201
|
*
|
|
@@ -17121,7 +18199,7 @@ var ScreenSpaceEffects = class {
|
|
|
17121
18199
|
renderer.acquireSceneInputs(),
|
|
17122
18200
|
import("./scene-color-passes-B93qTOka.js"),
|
|
17123
18201
|
contact === null ? null : import("./contact-shadows-T523EXaP.js"),
|
|
17124
|
-
ssgi === null ? null : import("./ssgi-
|
|
18202
|
+
ssgi === null ? null : import("./ssgi-DSnhqotl.js")
|
|
17125
18203
|
]);
|
|
17126
18204
|
const presenter = renderer.presenter;
|
|
17127
18205
|
const camera = renderer.isHeadless ? null : renderer.scene.camera;
|
|
@@ -17344,7 +18422,7 @@ var PostProcessStack = class PostProcessStack extends Component {
|
|
|
17344
18422
|
#reportHdrBloomFailure(renderer, failure) {
|
|
17345
18423
|
if (this.#hdrBloomFailed) return;
|
|
17346
18424
|
this.#hdrBloomFailed = true;
|
|
17347
|
-
renderer.app.log.error(`HDR bloom could not be loaded, so {entity} renders without it. ${String(failure)}
|
|
18425
|
+
renderer.app.log.error(`HDR bloom could not be loaded, so ${JSON.stringify(this.entity.name)} renders without it. ${String(failure)}`);
|
|
17348
18426
|
}
|
|
17349
18427
|
/**
|
|
17350
18428
|
* Replaces the chain with one that holds the effects the fields currently ask for.
|
|
@@ -17390,7 +18468,7 @@ var PostProcessStack = class PostProcessStack extends Component {
|
|
|
17390
18468
|
#warnAboutFeature(renderer, requestedEffects) {
|
|
17391
18469
|
if (this.#hasWarnedAboutFeature || requestedEffects === 0 || renderer.features.postProcessing) return;
|
|
17392
18470
|
this.#hasWarnedAboutFeature = true;
|
|
17393
|
-
renderer.app.log.warn(`${CoreErrorCode.postProcessingFeatureOff}: {entity} asks for post-processing, but the rendering.features.postProcessing opt-in is off, so the stack is inert. Declare it in the rendering.features block of createApp() or ignifx.config.ts
|
|
18471
|
+
renderer.app.log.warn(`${CoreErrorCode.postProcessingFeatureOff}: ${JSON.stringify(this.entity.name)} asks for post-processing, but the rendering.features.postProcessing opt-in is off, so the stack is inert. Declare it in the rendering.features block of createApp() or ignifx.config.ts.`);
|
|
17394
18472
|
}
|
|
17395
18473
|
/**
|
|
17396
18474
|
* The enabled effects, first to last, with the tuning each one needs.
|
|
@@ -17464,7 +18542,7 @@ var PostProcessStack = class PostProcessStack extends Component {
|
|
|
17464
18542
|
if (!this.#failedShaders.has(shader.address)) {
|
|
17465
18543
|
this.#failedShaders.add(shader.address);
|
|
17466
18544
|
const message = isIgnifxError(failure) ? failure.message : String(failure);
|
|
17467
|
-
renderer.app.log.error(`${CoreErrorCode.shaderCompileFailed}: {
|
|
18545
|
+
renderer.app.log.error(`${CoreErrorCode.shaderCompileFailed}: ${shader.address} could not be recorded as a custom post effect. ${message}`);
|
|
17468
18546
|
}
|
|
17469
18547
|
return null;
|
|
17470
18548
|
}
|
|
@@ -17902,7 +18980,7 @@ var RenderSyncSystem = class {
|
|
|
17902
18980
|
}
|
|
17903
18981
|
if (enabledCount > 1 && !this.#hasLoggedMultipleEnvironments) {
|
|
17904
18982
|
this.#hasLoggedMultipleEnvironments = true;
|
|
17905
|
-
world.app.log.warn(
|
|
18983
|
+
world.app.log.warn(`IGX-0705: ${String(enabledCount)} Environment components are enabled in this world; the most recent one wins.`);
|
|
17906
18984
|
}
|
|
17907
18985
|
if (enabledCount <= 1) this.#hasLoggedMultipleEnvironments = false;
|
|
17908
18986
|
if (winner !== null && winner !== (this.#lastEnvironment.get(world) ?? null)) winner.reclaim();
|
|
@@ -18005,7 +19083,7 @@ var RenderSyncSystem = class {
|
|
|
18005
19083
|
}
|
|
18006
19084
|
if (hasEsmLight && !this.#esmSkipReported.has(renderer)) {
|
|
18007
19085
|
this.#esmSkipReported.add(renderer);
|
|
18008
|
-
renderer.entity.world.app.log.warn(`${CoreErrorCode.shaderMaterialEsmCasterSkipped}: {entity} uses a shader material under ESM shadows; Babylon Lite 1.27.0 cannot render it into an ESM map, so it casts no shadow there. Use pcf shadows or castShadows: false
|
|
19086
|
+
renderer.entity.world.app.log.warn(`${CoreErrorCode.shaderMaterialEsmCasterSkipped}: ${JSON.stringify(renderer.entity.name)} uses a shader material under ESM shadows; Babylon Lite 1.27.0 cannot render it into an ESM map, so it casts no shadow there. Use pcf shadows or castShadows: false.`);
|
|
18009
19087
|
}
|
|
18010
19088
|
}
|
|
18011
19089
|
/**
|
|
@@ -19625,7 +20703,7 @@ var SettingsStore = class {
|
|
|
19625
20703
|
},
|
|
19626
20704
|
hint: "Check the section against the schema the owning extension registered."
|
|
19627
20705
|
});
|
|
19628
|
-
this.#log.warn(
|
|
20706
|
+
this.#log.warn(`The ${name} settings section is invalid and was replaced by its defaults: ${detail}`);
|
|
19629
20707
|
return defaults;
|
|
19630
20708
|
}
|
|
19631
20709
|
};
|
|
@@ -22341,6 +23419,7 @@ function registerRendering(ctx) {
|
|
|
22341
23419
|
ctx.registerAssetLoader(createFontLoader());
|
|
22342
23420
|
ctx.registerAssetLoader(createShaderLoader());
|
|
22343
23421
|
ctx.registerAssetLoader(createLightProbeLoader());
|
|
23422
|
+
ctx.registerAssetLoader(createLightmapLoader());
|
|
22344
23423
|
ctx.registerAssetLoader({
|
|
22345
23424
|
type: STORAGE_BUFFER_ASSET_TYPE,
|
|
22346
23425
|
extensions: [],
|
|
@@ -23189,7 +24268,7 @@ var ExtensionHost = class {
|
|
|
23189
24268
|
const dependency = byName.get(name);
|
|
23190
24269
|
if (dependency === void 0) continue;
|
|
23191
24270
|
if (state.get(name) === Visit.visiting) {
|
|
23192
|
-
if (this.#options.mode === "development") this.#options.log.debug(
|
|
24271
|
+
if (this.#options.mode === "development") this.#options.log.debug(`Dropped the optional dependency ${extension.name} -> ${name} because it would form a cycle.`);
|
|
23193
24272
|
continue;
|
|
23194
24273
|
}
|
|
23195
24274
|
this.#visit(dependency, byName, state, stack, sorted);
|
|
@@ -24516,7 +25595,7 @@ async function createRenderEngine(canvas, options, features) {
|
|
|
24516
25595
|
if (hdr) {
|
|
24517
25596
|
const knobs = features.autoExposure ?? null;
|
|
24518
25597
|
const exposure = knobs === null ? null : await import("./auto-exposure-uzPn0beO.js");
|
|
24519
|
-
presenter = (await import("./hdr-output-
|
|
25598
|
+
presenter = (await import("./hdr-output-DBQwMphy.js")).installHdrRenderPath(engine, scene, exposure === null || knobs === null ? void 0 : (hdrTexture) => exposure.installAutoExposure(engine, scene, hdrTexture, knobs));
|
|
24520
25599
|
} else if (offscreen) presenter = installOffscreenRenderPath(engine, scene);
|
|
24521
25600
|
return {
|
|
24522
25601
|
engine,
|
|
@@ -29732,95 +30811,6 @@ var SceneInstance = class {
|
|
|
29732
30811
|
if (index >= 0) this.#roots.splice(index, 1);
|
|
29733
30812
|
}
|
|
29734
30813
|
};
|
|
29735
|
-
/**
|
|
29736
|
-
* Builds the instance path tables of an expansion.
|
|
29737
|
-
*
|
|
29738
|
-
* @param expanded - The expansion.
|
|
29739
|
-
* @returns The resolver.
|
|
29740
|
-
*
|
|
29741
|
-
* @internal
|
|
29742
|
-
*/
|
|
29743
|
-
function instancePathResolver(expanded) {
|
|
29744
|
-
const keysOfRoot = /* @__PURE__ */ new Map();
|
|
29745
|
-
const entities = /* @__PURE__ */ new Map();
|
|
29746
|
-
const components = /* @__PURE__ */ new Map();
|
|
29747
|
-
for (const instance of expanded.instances) {
|
|
29748
|
-
if (instance.rootUid === null) continue;
|
|
29749
|
-
const keys = keysOfRoot.get(instance.rootUid) ?? [];
|
|
29750
|
-
keys.push(instance.key);
|
|
29751
|
-
keysOfRoot.set(instance.rootUid, keys);
|
|
29752
|
-
if (instance.root !== null) {
|
|
29753
|
-
tableOf(entities, instance.key).set(instance.root.sourceUid, instance.rootUid);
|
|
29754
|
-
fillComponents(tableOf(components, instance.key), instance.root.componentSourceUids);
|
|
29755
|
-
}
|
|
29756
|
-
}
|
|
29757
|
-
for (const entity of expanded.entities) {
|
|
29758
|
-
if (entity.instanceKey === null) continue;
|
|
29759
|
-
tableOf(entities, entity.instanceKey).set(entity.sourceUid, entity.data.uid);
|
|
29760
|
-
fillComponents(tableOf(components, entity.instanceKey), entity.componentSourceUids);
|
|
29761
|
-
}
|
|
29762
|
-
const lookup = (tables, root, uid) => {
|
|
29763
|
-
for (const key of keysOfRoot.get(root) ?? []) {
|
|
29764
|
-
const found = tables.get(key)?.get(uid);
|
|
29765
|
-
if (found !== void 0) return found;
|
|
29766
|
-
}
|
|
29767
|
-
return null;
|
|
29768
|
-
};
|
|
29769
|
-
const resolve = (path, last) => {
|
|
29770
|
-
const segments = path.split("/");
|
|
29771
|
-
if (segments.length < 2) return null;
|
|
29772
|
-
let root = segments[0] ?? null;
|
|
29773
|
-
for (let index = 1; index < segments.length && root !== null; index += 1) {
|
|
29774
|
-
const segment = segments[index] ?? "";
|
|
29775
|
-
root = lookup(index === segments.length - 1 ? last : entities, root, segment);
|
|
29776
|
-
}
|
|
29777
|
-
return root;
|
|
29778
|
-
};
|
|
29779
|
-
return {
|
|
29780
|
-
entity: (path) => resolve(path, entities),
|
|
29781
|
-
component: (path) => resolve(path, components)
|
|
29782
|
-
};
|
|
29783
|
-
}
|
|
29784
|
-
/**
|
|
29785
|
-
* Rewrites the first segment of an instance path, which names an entity of the file the path is
|
|
29786
|
-
* written in, through that file's uid table.
|
|
29787
|
-
*
|
|
29788
|
-
* @param path - The path, or a plain uid.
|
|
29789
|
-
* @param keys - Source uid to expanded uid for the file.
|
|
29790
|
-
* @returns The rewritten path, or `null` when `path` is not a path.
|
|
29791
|
-
*
|
|
29792
|
-
* @internal
|
|
29793
|
-
*/
|
|
29794
|
-
function remapInstancePath(path, keys) {
|
|
29795
|
-
const at = path.indexOf("/");
|
|
29796
|
-
if (at <= 0) return null;
|
|
29797
|
-
const head = path.slice(0, at);
|
|
29798
|
-
return `${keys.get(head) ?? head}${path.slice(at)}`;
|
|
29799
|
-
}
|
|
29800
|
-
/**
|
|
29801
|
-
* The table of one instance key, created on first use.
|
|
29802
|
-
*
|
|
29803
|
-
* @param tables - The tables by instance key.
|
|
29804
|
-
* @param key - The instance key.
|
|
29805
|
-
* @returns The table.
|
|
29806
|
-
*/
|
|
29807
|
-
function tableOf(tables, key) {
|
|
29808
|
-
let table = tables.get(key);
|
|
29809
|
-
if (table === void 0) {
|
|
29810
|
-
table = /* @__PURE__ */ new Map();
|
|
29811
|
-
tables.set(key, table);
|
|
29812
|
-
}
|
|
29813
|
-
return table;
|
|
29814
|
-
}
|
|
29815
|
-
/**
|
|
29816
|
-
* Adds an expanded-to-source component table, inverted, to an instance's component table.
|
|
29817
|
-
*
|
|
29818
|
-
* @param into - Source component uid to expanded uid.
|
|
29819
|
-
* @param sourceUids - Expanded component uid to source component uid.
|
|
29820
|
-
*/
|
|
29821
|
-
function fillComponents(into, sourceUids) {
|
|
29822
|
-
for (const [expanded, source] of sourceUids) into.set(source, expanded);
|
|
29823
|
-
}
|
|
29824
30814
|
//#endregion
|
|
29825
30815
|
//#region src/serialization/expand.ts
|
|
29826
30816
|
/**
|
|
@@ -29848,15 +30838,23 @@ function expandScene(asset, options) {
|
|
|
29848
30838
|
};
|
|
29849
30839
|
if (options.asInstance === true) {
|
|
29850
30840
|
const key = nextInstanceKey(state);
|
|
29851
|
-
|
|
30841
|
+
const entry = {
|
|
29852
30842
|
key,
|
|
29853
30843
|
address: asset.address,
|
|
29854
30844
|
asset: null,
|
|
29855
30845
|
scene: asset,
|
|
29856
30846
|
rootUid: null,
|
|
29857
|
-
root: null
|
|
29858
|
-
|
|
30847
|
+
root: null,
|
|
30848
|
+
nestedBaseline: null,
|
|
30849
|
+
nestedRootSourceUids: null
|
|
30850
|
+
};
|
|
30851
|
+
instances.push(entry);
|
|
30852
|
+
const start = entities.length;
|
|
29859
30853
|
expandFile(asset, null, key, true, [asset.address], state, null);
|
|
30854
|
+
entry.nestedBaseline = nestedBaseline(state, start, key, null);
|
|
30855
|
+
const rootUid = singleRoot(asset)?.uid;
|
|
30856
|
+
const rootEntity = entities.find((entity, index) => index >= start && entity.instanceKey === key && entity.sourceUid === rootUid);
|
|
30857
|
+
entry.nestedRootSourceUids = rootEntity === void 0 ? null : nestedRootSources(state, 1, rootEntity.data.uid);
|
|
29860
30858
|
return {
|
|
29861
30859
|
entities,
|
|
29862
30860
|
instances,
|
|
@@ -30009,19 +31007,113 @@ function expandInstance(asset, instance, carrier, chain, state) {
|
|
|
30009
31007
|
componentSourceUids: merge.componentSourceUids
|
|
30010
31008
|
};
|
|
30011
31009
|
}
|
|
30012
|
-
|
|
31010
|
+
const entry = {
|
|
30013
31011
|
key,
|
|
30014
31012
|
address,
|
|
30015
31013
|
asset: resolved.handle,
|
|
30016
31014
|
scene: resolved.value,
|
|
30017
31015
|
rootUid,
|
|
30018
|
-
root
|
|
30019
|
-
|
|
31016
|
+
root,
|
|
31017
|
+
nestedBaseline: null,
|
|
31018
|
+
nestedRootSourceUids: null
|
|
31019
|
+
};
|
|
31020
|
+
const at = state.instances.length;
|
|
31021
|
+
state.instances.push(entry);
|
|
31022
|
+
const start = state.entities.length;
|
|
30020
31023
|
const produced = expandFile(resolved.value, rootUid, key, true, [...chain, address], state, merge);
|
|
31024
|
+
entry.nestedRootSourceUids = single === null ? null : nestedRootSources(state, at + 1, rootUid);
|
|
31025
|
+
entry.nestedBaseline = nestedBaseline(state, start, key, entry.nestedRootSourceUids === null ? null : {
|
|
31026
|
+
carrier,
|
|
31027
|
+
uids: entry.nestedRootSourceUids
|
|
31028
|
+
});
|
|
30021
31029
|
const overrides = instance.overrides;
|
|
30022
31030
|
if (overrides !== void 0 && overrides.length > 0) applyOverrides(overrides, produced, (message) => {
|
|
30023
31031
|
state.options.report(CoreErrorCode.instanceHashMismatch, `${asset.address}: ${message}`);
|
|
30024
|
-
});
|
|
31032
|
+
}, nestedResolver(produced, state));
|
|
31033
|
+
}
|
|
31034
|
+
/**
|
|
31035
|
+
* Resolves the override component segments that are instance paths into the prefabs an instanced
|
|
31036
|
+
* file itself instances. Their copies are already expanded, with fresh uids, when the outer
|
|
31037
|
+
* overrides run, so the path is read through the expansion's instance path tables: the first
|
|
31038
|
+
* segment is a uid of the instanced file, which `produced` maps to its copy.
|
|
31039
|
+
*
|
|
31040
|
+
* @param produced - The instanced file's override targets, by the uid the file gives each entity.
|
|
31041
|
+
* @param state - The expansion so far.
|
|
31042
|
+
* @returns The resolver; it builds its tables on first use, so overrides without such a path cost
|
|
31043
|
+
* nothing.
|
|
31044
|
+
*/
|
|
31045
|
+
function nestedResolver(produced, state) {
|
|
31046
|
+
let paths = null;
|
|
31047
|
+
return (path) => {
|
|
31048
|
+
const at = path.indexOf("/");
|
|
31049
|
+
const head = produced.get(path.slice(0, at));
|
|
31050
|
+
if (head === void 0) return null;
|
|
31051
|
+
paths ??= instancePathResolver(state);
|
|
31052
|
+
const uid = paths.component(`${head.data.uid}${path.slice(at)}`);
|
|
31053
|
+
if (uid === null) return null;
|
|
31054
|
+
for (const entity of state.entities) if (entity.data.components.some((component) => component.uid === uid)) return {
|
|
31055
|
+
data: entity.data,
|
|
31056
|
+
uid
|
|
31057
|
+
};
|
|
31058
|
+
return null;
|
|
31059
|
+
};
|
|
31060
|
+
}
|
|
31061
|
+
/**
|
|
31062
|
+
* Collects the component records an instance's nested prefabs produced, before the instance's own
|
|
31063
|
+
* overrides run: every component of an entity a deeper instance produced, and every component a
|
|
31064
|
+
* nested single root merged into an entity of the instanced file.
|
|
31065
|
+
*
|
|
31066
|
+
* @param state - The expansion so far.
|
|
31067
|
+
* @param start - The index of the instance's first entity in `state.entities`.
|
|
31068
|
+
* @param key - The instance's key.
|
|
31069
|
+
* @param root - The carrier and the components the instanced root's own nested instances merged
|
|
31070
|
+
* into it, or `null` when there are none.
|
|
31071
|
+
* @returns Expanded component uid to its record, or `null` when there is none.
|
|
31072
|
+
*/
|
|
31073
|
+
function nestedBaseline(state, start, key, root) {
|
|
31074
|
+
let baseline = null;
|
|
31075
|
+
if (root !== null) {
|
|
31076
|
+
for (const component of root.carrier.components) if (root.uids.has(component.uid)) {
|
|
31077
|
+
baseline ??= /* @__PURE__ */ new Map();
|
|
31078
|
+
baseline.set(component.uid, component);
|
|
31079
|
+
}
|
|
31080
|
+
}
|
|
31081
|
+
for (let index = start; index < state.entities.length; index += 1) {
|
|
31082
|
+
const entity = state.entities[index];
|
|
31083
|
+
if (entity === void 0) continue;
|
|
31084
|
+
const merged = entity.instanceKey === key ? state.merged.get(entity.data.uid) : void 0;
|
|
31085
|
+
if (entity.instanceKey === key && merged === void 0) continue;
|
|
31086
|
+
const components = entity.data.components;
|
|
31087
|
+
for (let inner = 0; inner < components.length; inner += 1) {
|
|
31088
|
+
const component = components[inner];
|
|
31089
|
+
if (component !== void 0 && (merged === void 0 || merged.has(component.uid))) {
|
|
31090
|
+
baseline ??= /* @__PURE__ */ new Map();
|
|
31091
|
+
baseline.set(component.uid, component);
|
|
31092
|
+
}
|
|
31093
|
+
}
|
|
31094
|
+
}
|
|
31095
|
+
return baseline;
|
|
31096
|
+
}
|
|
31097
|
+
/**
|
|
31098
|
+
* The components the scenes a single root instances merged into the same carrier: every instance
|
|
31099
|
+
* expanded after `from` whose root is the carrier and merged a single root into it.
|
|
31100
|
+
*
|
|
31101
|
+
* @param state - The expansion so far.
|
|
31102
|
+
* @param from - The index in `state.instances` of the first instance the root's file produced.
|
|
31103
|
+
* @param carrierUid - The carrier's expanded uid.
|
|
31104
|
+
* @returns Expanded component uid to the uid its own file gives it, or `null` when there is none.
|
|
31105
|
+
*/
|
|
31106
|
+
function nestedRootSources(state, from, carrierUid) {
|
|
31107
|
+
let found = null;
|
|
31108
|
+
for (let index = from; index < state.instances.length; index += 1) {
|
|
31109
|
+
const instance = state.instances[index];
|
|
31110
|
+
if (instance?.rootUid !== carrierUid || instance.root === null) continue;
|
|
31111
|
+
for (const [uid, sourceUid] of instance.root.componentSourceUids) {
|
|
31112
|
+
found ??= /* @__PURE__ */ new Map();
|
|
31113
|
+
found.set(uid, sourceUid);
|
|
31114
|
+
}
|
|
31115
|
+
}
|
|
31116
|
+
return found;
|
|
30025
31117
|
}
|
|
30026
31118
|
/**
|
|
30027
31119
|
* Reports, or throws, an `IGX-0604` hash mismatch.
|
|
@@ -30608,7 +31700,9 @@ function ownedInstance(context, entity, source, rootOfInstance, handle) {
|
|
|
30608
31700
|
address: instance.address,
|
|
30609
31701
|
asset: instance.rootUid === null ? handle : instance.asset,
|
|
30610
31702
|
scene: instance.scene,
|
|
30611
|
-
root: instancedRoot(context, instance, source)
|
|
31703
|
+
root: instancedRoot(context, instance, source),
|
|
31704
|
+
nestedBaseline: instance.nestedBaseline,
|
|
31705
|
+
nestedRootSourceUids: instance.nestedRootSourceUids
|
|
30612
31706
|
};
|
|
30613
31707
|
}
|
|
30614
31708
|
return null;
|
|
@@ -33080,22 +34174,350 @@ var Vec4 = class Vec4 {
|
|
|
33080
34174
|
}
|
|
33081
34175
|
};
|
|
33082
34176
|
//#endregion
|
|
34177
|
+
//#region src/render/gpu/light-probe-bake-model.ts
|
|
34178
|
+
/** The albedo of a mesh whose material says nothing usable. */
|
|
34179
|
+
const MID_GREY = Object.freeze([
|
|
34180
|
+
.5,
|
|
34181
|
+
.5,
|
|
34182
|
+
.5
|
|
34183
|
+
]);
|
|
34184
|
+
/**
|
|
34185
|
+
* Adds the triangles of a model's live instance, when the bake should read it: the asset kept no
|
|
34186
|
+
* file bytes and the instance exists. Each mesh is coloured by its material, or by the model's
|
|
34187
|
+
* override for that material's name.
|
|
34188
|
+
*
|
|
34189
|
+
* @param model - The model.
|
|
34190
|
+
* @param sink - Where the triangles go.
|
|
34191
|
+
* @param albedo - Reads an override's albedo.
|
|
34192
|
+
* @param skip - Records a mesh left out, or a model that gave nothing.
|
|
34193
|
+
* @param signal - Stops the collection between meshes.
|
|
34194
|
+
* @returns `null` when the model is read from its file instead (or has no instance to read), else
|
|
34195
|
+
* `1` when it gave no triangles at all and `0` when it gave some.
|
|
34196
|
+
*
|
|
34197
|
+
* @internal
|
|
34198
|
+
*/
|
|
34199
|
+
function traceLiveModel(model, sink, albedo, skip, signal) {
|
|
34200
|
+
const handle = model.model;
|
|
34201
|
+
const asset = handle === null || handle.state !== "loaded" ? null : handle.value;
|
|
34202
|
+
const meshes = asset === null || asset.sourceBytes !== null ? null : model.instanceMeshes;
|
|
34203
|
+
if (asset === null || meshes === null) return null;
|
|
34204
|
+
const fileAlbedos = asset.bakeAlbedos;
|
|
34205
|
+
const matrix = Array.from({ length: 16 }, () => 0);
|
|
34206
|
+
let traced = 0;
|
|
34207
|
+
let reasons = 0;
|
|
34208
|
+
for (const mesh of meshes) {
|
|
34209
|
+
signal?.throwIfAborted();
|
|
34210
|
+
const surface = readMeshBakeSurface(mesh);
|
|
34211
|
+
if (surface === null) {
|
|
34212
|
+
reasons += 1;
|
|
34213
|
+
skip(model.entity, Model.typeId, `mesh "${mesh.name}" keeps no CPU triangles`);
|
|
34214
|
+
continue;
|
|
34215
|
+
}
|
|
34216
|
+
const override = surface.materialName === null ? void 0 : model.materialOverrides[surface.materialName];
|
|
34217
|
+
const fromFile = surface.materialName === null ? void 0 : fileAlbedos?.get(surface.materialName);
|
|
34218
|
+
const rgb = override !== void 0 && override !== null ? albedo(override) : fromFile ?? surface.albedo ?? MID_GREY;
|
|
34219
|
+
traced += sink.add(surface.positions, surface.indices, readWorldMatrix(mesh, matrix), rgb);
|
|
34220
|
+
}
|
|
34221
|
+
if (traced > 0) return 0;
|
|
34222
|
+
if (reasons === 0) skip(model.entity, Model.typeId, "the model's instance draws no triangles");
|
|
34223
|
+
return 1;
|
|
34224
|
+
}
|
|
34225
|
+
/**
|
|
34226
|
+
* Builds the triangles of a primitive as Lite would size and place it.
|
|
34227
|
+
*
|
|
34228
|
+
* @param definition - The primitive and its options, as `MeshAsset`'s factories and `.mesh.json` take them.
|
|
34229
|
+
* @returns Its local-space triangles.
|
|
34230
|
+
*
|
|
34231
|
+
* @internal
|
|
34232
|
+
*/
|
|
34233
|
+
function primitiveTriangles(definition) {
|
|
34234
|
+
switch (definition.primitive) {
|
|
34235
|
+
case "box": {
|
|
34236
|
+
const size = definition.options.size ?? 1;
|
|
34237
|
+
return boxTriangles(definition.options.width ?? size, definition.options.height ?? size, definition.options.depth ?? size);
|
|
34238
|
+
}
|
|
34239
|
+
case "sphere": {
|
|
34240
|
+
const radius = (definition.options.diameter ?? 1) / 2;
|
|
34241
|
+
const rings = clampSegments(Math.max(3, definition.options.segments ?? 32));
|
|
34242
|
+
const profile = [];
|
|
34243
|
+
for (let ring = 0; ring <= rings; ring += 1) {
|
|
34244
|
+
const angle = Math.PI * (1 - ring / rings);
|
|
34245
|
+
profile.push([Math.sin(angle) * radius, Math.cos(angle) * radius]);
|
|
34246
|
+
}
|
|
34247
|
+
return revolve(profile, rings * 2);
|
|
34248
|
+
}
|
|
34249
|
+
case "plane": {
|
|
34250
|
+
const size = definition.options.size ?? 1;
|
|
34251
|
+
const hw = (definition.options.width ?? size) / 2;
|
|
34252
|
+
const hh = (definition.options.height ?? size) / 2;
|
|
34253
|
+
return quad([
|
|
34254
|
+
-hw,
|
|
34255
|
+
-hh,
|
|
34256
|
+
0,
|
|
34257
|
+
hw,
|
|
34258
|
+
-hh,
|
|
34259
|
+
0,
|
|
34260
|
+
hw,
|
|
34261
|
+
hh,
|
|
34262
|
+
0,
|
|
34263
|
+
-hw,
|
|
34264
|
+
hh,
|
|
34265
|
+
0
|
|
34266
|
+
]);
|
|
34267
|
+
}
|
|
34268
|
+
case "ground": {
|
|
34269
|
+
const hw = (definition.options.width ?? 1) / 2;
|
|
34270
|
+
const hd = (definition.options.height ?? 1) / 2;
|
|
34271
|
+
return quad([
|
|
34272
|
+
-hw,
|
|
34273
|
+
0,
|
|
34274
|
+
-hd,
|
|
34275
|
+
hw,
|
|
34276
|
+
0,
|
|
34277
|
+
-hd,
|
|
34278
|
+
hw,
|
|
34279
|
+
0,
|
|
34280
|
+
hd,
|
|
34281
|
+
-hw,
|
|
34282
|
+
0,
|
|
34283
|
+
hd
|
|
34284
|
+
]);
|
|
34285
|
+
}
|
|
34286
|
+
case "cylinder": {
|
|
34287
|
+
const options = definition.options;
|
|
34288
|
+
const height = options.height ?? 2;
|
|
34289
|
+
const top = (options.diameterTop ?? options.diameter ?? 1) / 2;
|
|
34290
|
+
const bottom = (options.diameterBottom ?? options.diameter ?? 1) / 2;
|
|
34291
|
+
return revolve([
|
|
34292
|
+
[0, -height / 2],
|
|
34293
|
+
[bottom, -height / 2],
|
|
34294
|
+
[top, height / 2],
|
|
34295
|
+
[0, height / 2]
|
|
34296
|
+
], clampSegments(Math.max(3, options.tessellation ?? 24)));
|
|
34297
|
+
}
|
|
34298
|
+
case "capsule": {
|
|
34299
|
+
const options = definition.options;
|
|
34300
|
+
const height = Math.max(orDefault(options.height, 1), 0);
|
|
34301
|
+
const radius = Math.max(orDefault(options.radius, .25), 0);
|
|
34302
|
+
const half = Math.max(height / 2 - radius, 0);
|
|
34303
|
+
const arc = 8;
|
|
34304
|
+
const profile = [];
|
|
34305
|
+
for (let step = 0; step <= arc; step += 1) {
|
|
34306
|
+
const angle = Math.PI / 2 * (step / arc);
|
|
34307
|
+
profile.push([Math.sin(angle) * radius, -half - Math.cos(angle) * radius]);
|
|
34308
|
+
}
|
|
34309
|
+
for (let step = 0; step <= arc; step += 1) {
|
|
34310
|
+
const angle = Math.PI / 2 * (step / arc);
|
|
34311
|
+
profile.push([Math.cos(angle) * radius, half + Math.sin(angle) * radius]);
|
|
34312
|
+
}
|
|
34313
|
+
return revolve(profile, clampSegments(Math.max(3, orDefault(options.tessellation, 16))));
|
|
34314
|
+
}
|
|
34315
|
+
case "torus": {
|
|
34316
|
+
const options = definition.options;
|
|
34317
|
+
return torusTriangles((options.diameter ?? 1) / 2, (options.thickness ?? .5) / 2, clampSegments(Math.max(3, options.tessellation ?? 16)));
|
|
34318
|
+
}
|
|
34319
|
+
default: return assertNever(definition, "mesh primitive");
|
|
34320
|
+
}
|
|
34321
|
+
}
|
|
34322
|
+
/**
|
|
34323
|
+
* An option Lite reads with `||`: missing or `0` takes the default.
|
|
34324
|
+
*
|
|
34325
|
+
* @param value - The option.
|
|
34326
|
+
* @param fallback - Lite's default.
|
|
34327
|
+
* @returns The value to use.
|
|
34328
|
+
*/
|
|
34329
|
+
function orDefault(value, fallback) {
|
|
34330
|
+
return value === void 0 || value === 0 || Number.isNaN(value) ? fallback : value;
|
|
34331
|
+
}
|
|
34332
|
+
/**
|
|
34333
|
+
* Caps a segment count at {@link MAX_BAKE_SEGMENTS}.
|
|
34334
|
+
*
|
|
34335
|
+
* @param segments - What the options asked for.
|
|
34336
|
+
* @returns A whole count from 3 to the cap.
|
|
34337
|
+
*/
|
|
34338
|
+
function clampSegments(segments) {
|
|
34339
|
+
return Math.min(16, Math.max(3, Math.floor(segments)));
|
|
34340
|
+
}
|
|
34341
|
+
/**
|
|
34342
|
+
* An axis-aligned box centred on the origin.
|
|
34343
|
+
*
|
|
34344
|
+
* @param width - Its size along X.
|
|
34345
|
+
* @param height - Its size along Y.
|
|
34346
|
+
* @param depth - Its size along Z.
|
|
34347
|
+
* @returns Twelve triangles.
|
|
34348
|
+
*/
|
|
34349
|
+
function boxTriangles(width, height, depth) {
|
|
34350
|
+
const x = width / 2;
|
|
34351
|
+
const y = height / 2;
|
|
34352
|
+
const z = depth / 2;
|
|
34353
|
+
return {
|
|
34354
|
+
positions: Float32Array.from([
|
|
34355
|
+
-x,
|
|
34356
|
+
-y,
|
|
34357
|
+
-z,
|
|
34358
|
+
x,
|
|
34359
|
+
-y,
|
|
34360
|
+
-z,
|
|
34361
|
+
x,
|
|
34362
|
+
y,
|
|
34363
|
+
-z,
|
|
34364
|
+
-x,
|
|
34365
|
+
y,
|
|
34366
|
+
-z,
|
|
34367
|
+
-x,
|
|
34368
|
+
-y,
|
|
34369
|
+
z,
|
|
34370
|
+
x,
|
|
34371
|
+
-y,
|
|
34372
|
+
z,
|
|
34373
|
+
x,
|
|
34374
|
+
y,
|
|
34375
|
+
z,
|
|
34376
|
+
-x,
|
|
34377
|
+
y,
|
|
34378
|
+
z
|
|
34379
|
+
]),
|
|
34380
|
+
indices: Uint32Array.from([
|
|
34381
|
+
0,
|
|
34382
|
+
1,
|
|
34383
|
+
2,
|
|
34384
|
+
0,
|
|
34385
|
+
2,
|
|
34386
|
+
3,
|
|
34387
|
+
4,
|
|
34388
|
+
6,
|
|
34389
|
+
5,
|
|
34390
|
+
4,
|
|
34391
|
+
7,
|
|
34392
|
+
6,
|
|
34393
|
+
0,
|
|
34394
|
+
4,
|
|
34395
|
+
5,
|
|
34396
|
+
0,
|
|
34397
|
+
5,
|
|
34398
|
+
1,
|
|
34399
|
+
3,
|
|
34400
|
+
2,
|
|
34401
|
+
6,
|
|
34402
|
+
3,
|
|
34403
|
+
6,
|
|
34404
|
+
7,
|
|
34405
|
+
0,
|
|
34406
|
+
3,
|
|
34407
|
+
7,
|
|
34408
|
+
0,
|
|
34409
|
+
7,
|
|
34410
|
+
4,
|
|
34411
|
+
1,
|
|
34412
|
+
5,
|
|
34413
|
+
6,
|
|
34414
|
+
1,
|
|
34415
|
+
6,
|
|
34416
|
+
2
|
|
34417
|
+
])
|
|
34418
|
+
};
|
|
34419
|
+
}
|
|
34420
|
+
/**
|
|
34421
|
+
* Two triangles over four corners given in order around the quad.
|
|
34422
|
+
*
|
|
34423
|
+
* @param corners - Twelve floats.
|
|
34424
|
+
* @returns The quad.
|
|
34425
|
+
*/
|
|
34426
|
+
function quad(corners) {
|
|
34427
|
+
return {
|
|
34428
|
+
positions: Float32Array.from(corners),
|
|
34429
|
+
indices: Uint32Array.from([
|
|
34430
|
+
0,
|
|
34431
|
+
1,
|
|
34432
|
+
2,
|
|
34433
|
+
0,
|
|
34434
|
+
2,
|
|
34435
|
+
3
|
|
34436
|
+
])
|
|
34437
|
+
};
|
|
34438
|
+
}
|
|
34439
|
+
/**
|
|
34440
|
+
* Revolves a `(radius, y)` profile around the Y axis.
|
|
34441
|
+
*
|
|
34442
|
+
* @param profile - The profile, bottom to top.
|
|
34443
|
+
* @param slices - Segments around the axis.
|
|
34444
|
+
* @returns The surface; a zero radius makes degenerate triangles, which the trace skips.
|
|
34445
|
+
*/
|
|
34446
|
+
function revolve(profile, slices) {
|
|
34447
|
+
const positions = [];
|
|
34448
|
+
for (const [radius, y] of profile) for (let slice = 0; slice <= slices; slice += 1) {
|
|
34449
|
+
const angle = 2 * Math.PI * slice / slices;
|
|
34450
|
+
positions.push(Math.cos(angle) * radius, y, Math.sin(angle) * radius);
|
|
34451
|
+
}
|
|
34452
|
+
return {
|
|
34453
|
+
positions: Float32Array.from(positions),
|
|
34454
|
+
indices: gridIndices(profile.length - 1, slices)
|
|
34455
|
+
};
|
|
34456
|
+
}
|
|
34457
|
+
/**
|
|
34458
|
+
* A torus in the XZ plane.
|
|
34459
|
+
*
|
|
34460
|
+
* @param ring - The distance from the centre to the tube's centre.
|
|
34461
|
+
* @param tube - The tube's radius.
|
|
34462
|
+
* @param segments - Segments around the ring and around the tube.
|
|
34463
|
+
* @returns The surface.
|
|
34464
|
+
*/
|
|
34465
|
+
function torusTriangles(ring, tube, segments) {
|
|
34466
|
+
const positions = [];
|
|
34467
|
+
for (let i = 0; i <= segments; i += 1) {
|
|
34468
|
+
const outer = 2 * Math.PI * i / segments;
|
|
34469
|
+
for (let j = 0; j <= segments; j += 1) {
|
|
34470
|
+
const inner = 2 * Math.PI * j / segments;
|
|
34471
|
+
const distance = ring + Math.cos(inner) * tube;
|
|
34472
|
+
positions.push(Math.cos(outer) * distance, Math.sin(inner) * tube, -Math.sin(outer) * distance);
|
|
34473
|
+
}
|
|
34474
|
+
}
|
|
34475
|
+
return {
|
|
34476
|
+
positions: Float32Array.from(positions),
|
|
34477
|
+
indices: gridIndices(segments, segments)
|
|
34478
|
+
};
|
|
34479
|
+
}
|
|
34480
|
+
/**
|
|
34481
|
+
* The triangles of a `(rows + 1) × (columns + 1)` vertex grid.
|
|
34482
|
+
*
|
|
34483
|
+
* @param rows - Quads along the first axis.
|
|
34484
|
+
* @param columns - Quads along the second.
|
|
34485
|
+
* @returns Six indices per quad.
|
|
34486
|
+
*/
|
|
34487
|
+
function gridIndices(rows, columns) {
|
|
34488
|
+
const indices = [];
|
|
34489
|
+
const stride = columns + 1;
|
|
34490
|
+
for (let row = 0; row < rows; row += 1) for (let column = 0; column < columns; column += 1) {
|
|
34491
|
+
const a = row * stride + column;
|
|
34492
|
+
const b = a + stride;
|
|
34493
|
+
indices.push(a, b, a + 1, a + 1, b, b + 1);
|
|
34494
|
+
}
|
|
34495
|
+
return Uint32Array.from(indices);
|
|
34496
|
+
}
|
|
34497
|
+
//#endregion
|
|
33083
34498
|
//#region src/render/light-probe-bake.ts
|
|
33084
34499
|
/**
|
|
33085
34500
|
* The CPU light-probe bake (`docs/plan/2026-11-gi-phase-2-execution-plan.md`, step B4): one bounce
|
|
33086
34501
|
* of diffuse light, needing no device, so it runs headless, in a tool, or in a test.
|
|
33087
34502
|
*
|
|
33088
|
-
* - **Geometry.** Triangles of every enabled `MeshRenderer`
|
|
33089
|
-
*
|
|
33090
|
-
* the
|
|
34503
|
+
* - **Geometry.** Triangles of every enabled `MeshRenderer` (a `MeshAsset.fromData` mesh's own
|
|
34504
|
+
* arrays, or a primitive rebuilt on the CPU by `light-probe-bake-primitives.ts`) and every enabled
|
|
34505
|
+
* `Model` — read from the glTF file a headless app loaded (`light-probe-bake-gltf.ts`), or, under
|
|
34506
|
+
* an app with a device, from its instance's meshes (Lite's `getMeshTriangles`) — moved to world
|
|
34507
|
+
* space. What
|
|
34508
|
+
* cannot be read is listed in {@link LightProbeBakeResult.skips}. Each mesh keeps a world bounding
|
|
34509
|
+
* box, so a ray tests the triangles of the meshes it passes through only.
|
|
33091
34510
|
* - **Per probe.** `rays` directions on a Fibonacci sphere. A hit returns the surface's albedo (the
|
|
33092
34511
|
* material's base or diffuse colour, decoded to linear) times the direct light there, with a
|
|
33093
|
-
* shadow ray per directional, point or spot light and the hemispheric lights unshadowed
|
|
33094
|
-
*
|
|
33095
|
-
* added
|
|
34512
|
+
* shadow ray per directional, point or spot light and the hemispheric lights unshadowed: every
|
|
34513
|
+
* light bounces. A miss returns the sky. The light a probe receives straight from a light is
|
|
34514
|
+
* added only for a light whose rule says so ({@link lightBakeTerms}): a `"baked"` light always, a
|
|
34515
|
+
* `"mixed"` light never, a `"realtime"` light only with `directLight: "include"` — a hemispheric
|
|
34516
|
+
* light as part of what a miss sees, the others exactly, as clamped-cosine lobes. Spot cones are
|
|
34517
|
+
* ignored.
|
|
33096
34518
|
* - **Units.** Lite's: a white surface lit by the result shows `c0 + c1·n.y + c2·n.z + c3·n.x`, so a
|
|
33097
|
-
* uniform sky of radiance `L` bakes to `c0 = L`, and
|
|
33098
|
-
* `c0 = I/4` and a first-order term of `I/2` along its direction.
|
|
34519
|
+
* uniform sky of radiance `L` bakes to `c0 = L`, and an included directional light of intensity
|
|
34520
|
+
* `I` to `c0 = I/4` and a first-order term of `I/2` along its direction.
|
|
33099
34521
|
*/
|
|
33100
34522
|
/** The basis factors: `Y00² · 4π` is 1 and `(2/3) · Y1m² · 4π` is 2, per sample. */
|
|
33101
34523
|
const BAND1_PER_SAMPLE = 2;
|
|
@@ -33105,24 +34527,67 @@ const SURFACE_OFFSET = .001;
|
|
|
33105
34527
|
const GOLDEN_ANGLE = 2.399963229728653;
|
|
33106
34528
|
/** The most rays one probe may trace. */
|
|
33107
34529
|
const MAX_RAYS = 4096;
|
|
34530
|
+
/** How long the bake works before it yields to the host, in milliseconds (half a 60 Hz frame). */
|
|
34531
|
+
const YIELD_BUDGET_MS = 8;
|
|
34532
|
+
/** Floats per mesh in {@link TraceScene.meshes}. */
|
|
34533
|
+
const MESH_STRIDE = 8;
|
|
33108
34534
|
/**
|
|
33109
|
-
*
|
|
34535
|
+
* What one light gives a light-probe bake, by its `bakeMode` and the bake's `directLight`.
|
|
33110
34536
|
*
|
|
33111
34537
|
* @remarks
|
|
33112
|
-
*
|
|
33113
|
-
*
|
|
33114
|
-
*
|
|
34538
|
+
* Every light bounces: the light it puts on surfaces is traced back to the probes. Whether a probe
|
|
34539
|
+
* also stores the light it receives straight from it depends on who draws that light at run time:
|
|
34540
|
+
* a `"baked"` light is not drawn, so the probe holds it; a `"mixed"` light is drawn, so the probe
|
|
34541
|
+
* never does; a `"realtime"` light is drawn too, and `directLight: "include"` is how a bake asks
|
|
34542
|
+
* for its direct light anyway (to read a probe's total light).
|
|
33115
34543
|
*
|
|
33116
|
-
*
|
|
33117
|
-
*
|
|
34544
|
+
* @param bakeMode - The light's `bakeMode`.
|
|
34545
|
+
* @param directLight - The bake's `directLight` option.
|
|
34546
|
+
* @returns Whether the probes store its direct light, and whether its bounce is baked.
|
|
34547
|
+
*
|
|
34548
|
+
* @beta
|
|
34549
|
+
*/
|
|
34550
|
+
function lightBakeTerms(bakeMode, directLight) {
|
|
34551
|
+
if (bakeMode === "baked") return {
|
|
34552
|
+
direct: true,
|
|
34553
|
+
bounce: true
|
|
34554
|
+
};
|
|
34555
|
+
if (bakeMode === "mixed") return {
|
|
34556
|
+
direct: false,
|
|
34557
|
+
bounce: true
|
|
34558
|
+
};
|
|
34559
|
+
return {
|
|
34560
|
+
direct: directLight === "include",
|
|
34561
|
+
bounce: true
|
|
34562
|
+
};
|
|
34563
|
+
}
|
|
34564
|
+
/**
|
|
34565
|
+
* Bakes a light-probe grid from a world's mesh renderers and lights, on the CPU.
|
|
34566
|
+
*
|
|
34567
|
+
* @remarks
|
|
34568
|
+
* One bounce, first-order harmonics, deterministic. `MeshRenderer` meshes (built from data, or
|
|
34569
|
+
* primitives) and `Model` glTF files cast and bounce light; a model is read from the file a
|
|
34570
|
+
* headless app loaded, or, under an app with a device, from the CPU triangles Lite keeps on its
|
|
34571
|
+
* instance's meshes once the model has been drawn (a model not instantiated yet is listed in
|
|
34572
|
+
* {@link LightProbeBakeResult.skips}). Draco- and meshopt-compressed glTF primitives are skipped
|
|
34573
|
+
* headless. By
|
|
34574
|
+
* default a probe holds every light's bounce but the direct light of `"baked"` lights only, since
|
|
34575
|
+
* the others keep lighting the scene in real time (see {@link LightProbeBakeOptions.directLight} and
|
|
34576
|
+
* `Light.bakeMode`). Cost grows with probes × rays × triangles (each mesh's bounding box culls its
|
|
34577
|
+
* triangles); it is meant for tools, not for every frame.
|
|
34578
|
+
*
|
|
34579
|
+
* The bake is asynchronous: it yields to the host after every ~8 ms of work, reports progress
|
|
34580
|
+
* through `onProgress` after each probe, and stops at the next probe once `signal` aborts.
|
|
33118
34581
|
*
|
|
33119
34582
|
* @param world - The world to bake. Its meshes and lights are read once, when the bake starts.
|
|
33120
34583
|
* @param options - The grid, the quality, and the cancellation and progress hooks.
|
|
33121
34584
|
* @returns The grid and what was traced.
|
|
33122
34585
|
* @throws IgnifxError with code `IGX-0734`, before tracing anything, for a grid the `.probes.json`
|
|
33123
34586
|
* format cannot hold (whole counts, `counts.x` ≤ 1024, `counts.y × counts.z` ≤ 4096, finite
|
|
33124
|
-
* `origin` and positive `cellSize`), `rays` outside 1–4096,
|
|
33125
|
-
* and positive
|
|
34587
|
+
* `origin` and positive `cellSize`), `rays` outside 1–4096, a `maxDistance` that is not finite
|
|
34588
|
+
* and positive, a `directLight` other than `"include"` or `"exclude"`, or a `sky` that is not a
|
|
34589
|
+
* finite colour, gradient or 27 finite harmonics. The promise rejects with `signal.reason` when the
|
|
34590
|
+
* bake is aborted.
|
|
33126
34591
|
*
|
|
33127
34592
|
* @example
|
|
33128
34593
|
* ```ts
|
|
@@ -33139,19 +34604,25 @@ const MAX_RAYS = 4096;
|
|
|
33139
34604
|
async function bakeLightProbes(world, options) {
|
|
33140
34605
|
const settings = readBakeOptions(options);
|
|
33141
34606
|
options.signal?.throwIfAborted();
|
|
33142
|
-
const { scene, skipped } = collectTriangles(world);
|
|
33143
|
-
const lights = collectLights(world);
|
|
34607
|
+
const { scene, skipped, skips } = collectTriangles(world, options.signal);
|
|
34608
|
+
const lights = collectLights(world, settings.includeDirect ? "include" : "exclude");
|
|
33144
34609
|
const { origin, cellSize, counts } = settings.grid;
|
|
33145
34610
|
const total = counts.x * counts.y * counts.z;
|
|
33146
34611
|
const coefficients = [];
|
|
34612
|
+
const clock = createPerformanceClock();
|
|
34613
|
+
let sliceStart = clock.nowMs();
|
|
33147
34614
|
for (let probe = 0; probe < total; probe += 1) {
|
|
33148
34615
|
const i = probe % counts.x;
|
|
33149
34616
|
const j = Math.floor(probe / counts.x) % counts.y;
|
|
33150
34617
|
const k = Math.floor(probe / (counts.x * counts.y));
|
|
33151
34618
|
coefficients.push(...bakeProbe(scene, lights, origin.x + i * cellSize.x, origin.y + j * cellSize.y, origin.z + k * cellSize.z, settings));
|
|
33152
34619
|
options.onProgress?.(probe + 1, total);
|
|
33153
|
-
await yieldToHost();
|
|
33154
34620
|
options.signal?.throwIfAborted();
|
|
34621
|
+
if (clock.nowMs() - sliceStart >= YIELD_BUDGET_MS && probe + 1 < total) {
|
|
34622
|
+
await yieldToHost();
|
|
34623
|
+
options.signal?.throwIfAborted();
|
|
34624
|
+
sliceStart = clock.nowMs();
|
|
34625
|
+
}
|
|
33155
34626
|
}
|
|
33156
34627
|
return {
|
|
33157
34628
|
data: {
|
|
@@ -33161,7 +34632,8 @@ async function bakeLightProbes(world, options) {
|
|
|
33161
34632
|
coefficients
|
|
33162
34633
|
},
|
|
33163
34634
|
triangles: scene.count,
|
|
33164
|
-
skipped
|
|
34635
|
+
skipped,
|
|
34636
|
+
skips
|
|
33165
34637
|
};
|
|
33166
34638
|
}
|
|
33167
34639
|
/**
|
|
@@ -33182,17 +34654,90 @@ function readBakeOptions(options) {
|
|
|
33182
34654
|
if (!Number.isSafeInteger(rays) || rays < 1 || rays > MAX_RAYS) throw fail(`rays must be a whole number from 1 to ${String(MAX_RAYS)}`);
|
|
33183
34655
|
const maxDistance = options.maxDistance ?? 100;
|
|
33184
34656
|
if (!Number.isFinite(maxDistance) || maxDistance <= 0) throw fail("maxDistance must be a finite number above 0");
|
|
34657
|
+
const directLight = options.directLight ?? "exclude";
|
|
34658
|
+
if (directLight !== "include" && directLight !== "exclude") throw fail("directLight must be \"include\" or \"exclude\"");
|
|
33185
34659
|
return {
|
|
33186
34660
|
grid,
|
|
33187
34661
|
rays,
|
|
33188
34662
|
maxDistance,
|
|
33189
|
-
sky:
|
|
33190
|
-
|
|
33191
|
-
|
|
33192
|
-
|
|
33193
|
-
|
|
33194
|
-
|
|
34663
|
+
sky: readSky(options.sky),
|
|
34664
|
+
includeDirect: directLight === "include"
|
|
34665
|
+
};
|
|
34666
|
+
}
|
|
34667
|
+
/** The real SH basis constants for bands 0–2. */
|
|
34668
|
+
const SH_C0 = .2820947917738781;
|
|
34669
|
+
const SH_C1 = .4886025119029199;
|
|
34670
|
+
const SH_C2 = 1.0925484305920792;
|
|
34671
|
+
const SH_C3 = .31539156525252005;
|
|
34672
|
+
const SH_C4 = .5462742152960396;
|
|
34673
|
+
/**
|
|
34674
|
+
* Checks the `sky` option and turns it into a radiance function.
|
|
34675
|
+
*
|
|
34676
|
+
* @param sky - The option.
|
|
34677
|
+
* @returns The function.
|
|
34678
|
+
* @throws IgnifxError with code `IGX-0734` for a non-finite colour or the wrong harmonics.
|
|
34679
|
+
*/
|
|
34680
|
+
function readSky(sky) {
|
|
34681
|
+
if (sky === void 0) return (_dx, _dy, _dz, out) => {
|
|
34682
|
+
out.fill(0);
|
|
33195
34683
|
};
|
|
34684
|
+
const given = sky;
|
|
34685
|
+
if (typeof given !== "object" || given === null) throw fail("sky must be a colour, a gradient or harmonics");
|
|
34686
|
+
if (!("kind" in sky)) {
|
|
34687
|
+
const flat = checkedColor(sky, "sky");
|
|
34688
|
+
return (_dx, _dy, _dz, out) => {
|
|
34689
|
+
for (let channel = 0; channel < 3; channel += 1) out[channel] = read(flat, channel);
|
|
34690
|
+
};
|
|
34691
|
+
}
|
|
34692
|
+
const kind = sky.kind;
|
|
34693
|
+
if (kind === "gradient" && sky.kind === "gradient") {
|
|
34694
|
+
const up = checkedColor(sky.sky, "sky.sky");
|
|
34695
|
+
const horizon = checkedColor(sky.horizon, "sky.horizon");
|
|
34696
|
+
const down = checkedColor(sky.ground, "sky.ground");
|
|
34697
|
+
return (_dx, dy, _dz, out) => {
|
|
34698
|
+
const end = dy >= 0 ? up : down;
|
|
34699
|
+
const t = Math.min(1, Math.abs(dy));
|
|
34700
|
+
for (let channel = 0; channel < 3; channel += 1) out[channel] = read(horizon, channel) * (1 - t) + read(end, channel) * t;
|
|
34701
|
+
};
|
|
34702
|
+
}
|
|
34703
|
+
if (kind === "sh9" && sky.kind === "sh9") {
|
|
34704
|
+
const c = sky.coefficients;
|
|
34705
|
+
if (!Array.isArray(c) || c.length !== 27 || !c.every((value) => Number.isFinite(value))) throw fail("sky.coefficients must be 27 finite numbers (nine RGB triples)");
|
|
34706
|
+
return (x, y, z, out) => {
|
|
34707
|
+
const basis = [
|
|
34708
|
+
SH_C0,
|
|
34709
|
+
SH_C1 * y,
|
|
34710
|
+
SH_C1 * z,
|
|
34711
|
+
SH_C1 * x,
|
|
34712
|
+
SH_C2 * x * y,
|
|
34713
|
+
SH_C2 * y * z,
|
|
34714
|
+
SH_C3 * (3 * z * z - 1),
|
|
34715
|
+
SH_C2 * x * z,
|
|
34716
|
+
SH_C4 * (x * x - y * y)
|
|
34717
|
+
];
|
|
34718
|
+
for (let channel = 0; channel < 3; channel += 1) {
|
|
34719
|
+
let sum = 0;
|
|
34720
|
+
for (let term = 0; term < 9; term += 1) sum += read(c, term * 3 + channel) * read(basis, term);
|
|
34721
|
+
out[channel] = Math.max(0, sum);
|
|
34722
|
+
}
|
|
34723
|
+
};
|
|
34724
|
+
}
|
|
34725
|
+
throw fail("sky.kind must be \"gradient\" or \"sh9\"");
|
|
34726
|
+
}
|
|
34727
|
+
/**
|
|
34728
|
+
* A linear colour option's three channels, checked.
|
|
34729
|
+
*
|
|
34730
|
+
* @param colour - The colour.
|
|
34731
|
+
* @param name - The option's name, for the error.
|
|
34732
|
+
* @returns Linear RGB.
|
|
34733
|
+
* @throws IgnifxError with code `IGX-0734` when a channel is not finite.
|
|
34734
|
+
*/
|
|
34735
|
+
function checkedColor(colour, name) {
|
|
34736
|
+
const given = colour;
|
|
34737
|
+
if (typeof given !== "object" || given === null) throw fail(`${name} must be a colour with finite channels`);
|
|
34738
|
+
const rgb = linearRgb(colour, false);
|
|
34739
|
+
if (!rgb.every((channel) => Number.isFinite(channel))) throw fail(`${name} must be a colour with finite channels`);
|
|
34740
|
+
return rgb;
|
|
33196
34741
|
}
|
|
33197
34742
|
/**
|
|
33198
34743
|
* The error for a bake option.
|
|
@@ -33204,7 +34749,7 @@ function fail(problem) {
|
|
|
33204
34749
|
return new IgnifxError(CoreErrorCode.invalidLightProbeBake, `bakeLightProbes(): ${problem}.`, { context: { problem } });
|
|
33205
34750
|
}
|
|
33206
34751
|
/**
|
|
33207
|
-
* Lets the host run before the next
|
|
34752
|
+
* Lets the host run before the next slice of probes.
|
|
33208
34753
|
*
|
|
33209
34754
|
* @returns A promise that settles on a later task.
|
|
33210
34755
|
*/
|
|
@@ -33271,53 +34816,175 @@ function fibonacciDirection(index, count) {
|
|
|
33271
34816
|
Math.sin(angle) * radius
|
|
33272
34817
|
];
|
|
33273
34818
|
}
|
|
34819
|
+
/** Collects world-space meshes into a {@link TraceScene}. */
|
|
34820
|
+
var SceneBuilder = class {
|
|
34821
|
+
vertices = [];
|
|
34822
|
+
albedo = [];
|
|
34823
|
+
meshes = [];
|
|
34824
|
+
/**
|
|
34825
|
+
* Adds one mesh.
|
|
34826
|
+
*
|
|
34827
|
+
* @param positions - Three floats per vertex, in the space `matrix` maps from.
|
|
34828
|
+
* @param indices - Three indices per triangle.
|
|
34829
|
+
* @param matrix - A column-major world matrix.
|
|
34830
|
+
* @param rgb - The mesh's linear albedo.
|
|
34831
|
+
* @returns How many triangles it added.
|
|
34832
|
+
*/
|
|
34833
|
+
add(positions, indices, matrix, rgb) {
|
|
34834
|
+
const first = this.albedo.length / 3;
|
|
34835
|
+
const min = [
|
|
34836
|
+
Number.POSITIVE_INFINITY,
|
|
34837
|
+
Number.POSITIVE_INFINITY,
|
|
34838
|
+
Number.POSITIVE_INFINITY
|
|
34839
|
+
];
|
|
34840
|
+
const max = [
|
|
34841
|
+
Number.NEGATIVE_INFINITY,
|
|
34842
|
+
Number.NEGATIVE_INFINITY,
|
|
34843
|
+
Number.NEGATIVE_INFINITY
|
|
34844
|
+
];
|
|
34845
|
+
const m = matrix;
|
|
34846
|
+
const triangles = Math.floor(indices.length / 3);
|
|
34847
|
+
for (let index = 0; index < triangles * 3; index += 1) {
|
|
34848
|
+
const vertex = read(indices, index) * 3;
|
|
34849
|
+
const x = read(positions, vertex);
|
|
34850
|
+
const y = read(positions, vertex + 1);
|
|
34851
|
+
const z = read(positions, vertex + 2);
|
|
34852
|
+
const world = [
|
|
34853
|
+
read(m, 0) * x + read(m, 4) * y + read(m, 8) * z + read(m, 12),
|
|
34854
|
+
read(m, 1) * x + read(m, 5) * y + read(m, 9) * z + read(m, 13),
|
|
34855
|
+
read(m, 2) * x + read(m, 6) * y + read(m, 10) * z + read(m, 14)
|
|
34856
|
+
];
|
|
34857
|
+
for (let axis = 0; axis < 3; axis += 1) {
|
|
34858
|
+
const value = read(world, axis);
|
|
34859
|
+
this.vertices.push(value);
|
|
34860
|
+
min[axis] = Math.min(read(min, axis), value);
|
|
34861
|
+
max[axis] = Math.max(read(max, axis), value);
|
|
34862
|
+
}
|
|
34863
|
+
if (index % 3 === 2) this.albedo.push(...rgb);
|
|
34864
|
+
}
|
|
34865
|
+
if (triangles > 0) this.meshes.push(first, triangles, ...min, ...max);
|
|
34866
|
+
return triangles;
|
|
34867
|
+
}
|
|
34868
|
+
/**
|
|
34869
|
+
* The finished scene.
|
|
34870
|
+
*
|
|
34871
|
+
* @returns It.
|
|
34872
|
+
*/
|
|
34873
|
+
build() {
|
|
34874
|
+
return {
|
|
34875
|
+
vertices: Float64Array.from(this.vertices),
|
|
34876
|
+
albedo: Float64Array.from(this.albedo),
|
|
34877
|
+
count: this.albedo.length / 3,
|
|
34878
|
+
meshes: Float64Array.from(this.meshes),
|
|
34879
|
+
meshCount: this.meshes.length / MESH_STRIDE
|
|
34880
|
+
};
|
|
34881
|
+
}
|
|
34882
|
+
};
|
|
33274
34883
|
/**
|
|
33275
|
-
* Gathers the world-space triangles of every enabled mesh renderer
|
|
34884
|
+
* Gathers the world-space triangles of every enabled mesh renderer and model the bake can read.
|
|
33276
34885
|
*
|
|
33277
34886
|
* @param world - The world.
|
|
33278
|
-
* @
|
|
34887
|
+
* @param signal - Stops the collection between meshes, models and glTF primitives.
|
|
34888
|
+
* @returns The triangles, how many components gave none, and why each part was left out.
|
|
33279
34889
|
*/
|
|
33280
|
-
function collectTriangles(world) {
|
|
33281
|
-
const
|
|
33282
|
-
const
|
|
34890
|
+
function collectTriangles(world, signal) {
|
|
34891
|
+
const builder = new SceneBuilder();
|
|
34892
|
+
const skips = [];
|
|
33283
34893
|
let skipped = 0;
|
|
34894
|
+
const gltfCache = /* @__PURE__ */ new Map();
|
|
34895
|
+
const skip = (entity, component, reason) => {
|
|
34896
|
+
skips.push({
|
|
34897
|
+
entity: entity.name,
|
|
34898
|
+
uid: entity.uid,
|
|
34899
|
+
component,
|
|
34900
|
+
reason
|
|
34901
|
+
});
|
|
34902
|
+
};
|
|
33284
34903
|
for (const renderer of world.components(MeshRenderer)) {
|
|
34904
|
+
signal?.throwIfAborted();
|
|
33285
34905
|
if (!renderer.isEnabledInHierarchy) continue;
|
|
33286
34906
|
const handle = renderer.mesh;
|
|
33287
|
-
const
|
|
34907
|
+
const mesh = handle !== null && handle.state === "loaded" ? handle.value : null;
|
|
34908
|
+
const geometry = mesh === null ? null : mesh.cpuGeometry ?? primitiveOrNull(mesh.primitive);
|
|
33288
34909
|
if (geometry === null) {
|
|
33289
34910
|
skipped += 1;
|
|
34911
|
+
skip(renderer.entity, MeshRenderer.typeId, mesh === null ? "its mesh is not loaded" : "its mesh has no CPU triangles");
|
|
33290
34912
|
continue;
|
|
33291
34913
|
}
|
|
33292
|
-
|
|
33293
|
-
|
|
33294
|
-
|
|
33295
|
-
|
|
33296
|
-
|
|
33297
|
-
|
|
33298
|
-
|
|
33299
|
-
|
|
33300
|
-
|
|
33301
|
-
|
|
34914
|
+
builder.add(geometry.positions, geometry.indices, renderer.entity.transform.worldMatrix, materialAlbedo(renderer.materials[0] ?? null));
|
|
34915
|
+
}
|
|
34916
|
+
for (const model of world.components(Model)) {
|
|
34917
|
+
signal?.throwIfAborted();
|
|
34918
|
+
if (!model.isEnabledInHierarchy) continue;
|
|
34919
|
+
const live = traceLiveModel(model, builder, materialAlbedo, skip, signal);
|
|
34920
|
+
if (live !== null) {
|
|
34921
|
+
skipped += live;
|
|
34922
|
+
continue;
|
|
34923
|
+
}
|
|
34924
|
+
const gltf = readModel(model.model, gltfCache);
|
|
34925
|
+
if (typeof gltf === "string") {
|
|
34926
|
+
skipped += 1;
|
|
34927
|
+
skip(model.entity, Model.typeId, gltf);
|
|
34928
|
+
continue;
|
|
34929
|
+
}
|
|
34930
|
+
let traced = 0;
|
|
34931
|
+
for (const primitive of gltf.primitives) {
|
|
34932
|
+
signal?.throwIfAborted();
|
|
34933
|
+
const override = primitive.materialName === null ? void 0 : model.materialOverrides[primitive.materialName];
|
|
34934
|
+
const rgb = override === void 0 || override === null ? primitive.albedo : materialAlbedo(override);
|
|
34935
|
+
traced += builder.add(primitive.positions, primitive.indices, model.entity.transform.worldMatrix, rgb);
|
|
34936
|
+
}
|
|
34937
|
+
for (const reason of gltf.skipped) skip(model.entity, Model.typeId, reason);
|
|
34938
|
+
if (traced === 0) {
|
|
34939
|
+
skipped += 1;
|
|
34940
|
+
if (gltf.skipped.length === 0) skip(model.entity, Model.typeId, "the model's default scene draws no triangles");
|
|
33302
34941
|
}
|
|
33303
34942
|
}
|
|
33304
34943
|
return {
|
|
33305
|
-
scene:
|
|
33306
|
-
|
|
33307
|
-
|
|
33308
|
-
count: albedo.length / 3
|
|
33309
|
-
},
|
|
33310
|
-
skipped
|
|
34944
|
+
scene: builder.build(),
|
|
34945
|
+
skipped,
|
|
34946
|
+
skips
|
|
33311
34947
|
};
|
|
33312
34948
|
}
|
|
33313
34949
|
/**
|
|
33314
|
-
* A
|
|
34950
|
+
* A primitive's CPU triangles.
|
|
33315
34951
|
*
|
|
33316
|
-
* @param
|
|
34952
|
+
* @param definition - The primitive, or `null`.
|
|
34953
|
+
* @returns The triangles, or `null`.
|
|
34954
|
+
*/
|
|
34955
|
+
function primitiveOrNull(definition) {
|
|
34956
|
+
return definition === null ? null : primitiveTriangles(definition);
|
|
34957
|
+
}
|
|
34958
|
+
/**
|
|
34959
|
+
* A model's glTF triangles, read once per asset.
|
|
34960
|
+
*
|
|
34961
|
+
* @param handle - The `Model.model` field.
|
|
34962
|
+
* @param gltfCache - What this bake already read, by asset.
|
|
34963
|
+
* @returns The geometry, or why there is none.
|
|
34964
|
+
*/
|
|
34965
|
+
function readModel(handle, gltfCache) {
|
|
34966
|
+
if (handle === null || handle.state !== "loaded") return "its model is not loaded";
|
|
34967
|
+
const asset = handle.value;
|
|
34968
|
+
const cached = gltfCache.get(asset);
|
|
34969
|
+
if (cached !== void 0) return cached;
|
|
34970
|
+
const bytes = asset.sourceBytes;
|
|
34971
|
+
let result;
|
|
34972
|
+
if (bytes === null) result = "its model has no instance to read yet (it is read once a frame has drawn it)";
|
|
34973
|
+
else try {
|
|
34974
|
+
result = readGltfTriangles(bytes);
|
|
34975
|
+
} catch (error) {
|
|
34976
|
+
result = `its glTF could not be read: ${error instanceof Error ? error.message : String(error)}`;
|
|
34977
|
+
}
|
|
34978
|
+
gltfCache.set(asset, result);
|
|
34979
|
+
return result;
|
|
34980
|
+
}
|
|
34981
|
+
/**
|
|
34982
|
+
* A material's diffuse colour: its base (PBR, times `1 − metallic`) or diffuse (Standard) colour.
|
|
34983
|
+
*
|
|
34984
|
+
* @param handle - The material, or `null`.
|
|
33317
34985
|
* @returns Linear RGB; mid grey when the material says nothing usable.
|
|
33318
34986
|
*/
|
|
33319
|
-
function
|
|
33320
|
-
const handle = renderer.materials[0] ?? null;
|
|
34987
|
+
function materialAlbedo(handle) {
|
|
33321
34988
|
const definition = handle !== null && handle.state === "loaded" ? handle.value.definition : null;
|
|
33322
34989
|
if (definition?.kind === "pbr") return linearRgb(definition.baseColor, true).map((channel) => channel * (1 - definition.metallic));
|
|
33323
34990
|
if (definition?.kind === "standard") return linearRgb(definition.diffuse, true);
|
|
@@ -33328,15 +34995,17 @@ function surfaceAlbedo(renderer) {
|
|
|
33328
34995
|
];
|
|
33329
34996
|
}
|
|
33330
34997
|
/**
|
|
33331
|
-
* Collects the enabled lights, in linear RGB times intensity.
|
|
34998
|
+
* Collects the enabled lights, in linear RGB times intensity, with what each gives the bake.
|
|
33332
34999
|
*
|
|
33333
35000
|
* @param world - The world.
|
|
35001
|
+
* @param directLight - The bake's `directLight` option.
|
|
33334
35002
|
* @returns The lights.
|
|
33335
35003
|
*/
|
|
33336
|
-
function collectLights(world) {
|
|
35004
|
+
function collectLights(world, directLight) {
|
|
33337
35005
|
const out = [];
|
|
33338
35006
|
for (const light of world.components(Light)) {
|
|
33339
35007
|
if (!light.isEnabledInHierarchy || light.intensity <= 0) continue;
|
|
35008
|
+
const { direct } = lightBakeTerms(light.bakeMode, directLight);
|
|
33340
35009
|
const rgb = linearRgb(light.color, true).map((channel) => channel * light.intensity);
|
|
33341
35010
|
const transform = light.entity.transform;
|
|
33342
35011
|
if (light.type === "directional") {
|
|
@@ -33348,7 +35017,8 @@ function collectLights(world) {
|
|
|
33348
35017
|
-forward.y,
|
|
33349
35018
|
-forward.z
|
|
33350
35019
|
],
|
|
33351
|
-
rgb
|
|
35020
|
+
rgb,
|
|
35021
|
+
direct
|
|
33352
35022
|
});
|
|
33353
35023
|
} else if (light.type === "hemispheric") {
|
|
33354
35024
|
const up = transform.up;
|
|
@@ -33361,7 +35031,8 @@ function collectLights(world) {
|
|
|
33361
35031
|
up.z
|
|
33362
35032
|
],
|
|
33363
35033
|
sky: rgb,
|
|
33364
|
-
ground
|
|
35034
|
+
ground,
|
|
35035
|
+
direct
|
|
33365
35036
|
});
|
|
33366
35037
|
} else {
|
|
33367
35038
|
const at = transform.position;
|
|
@@ -33373,14 +35044,15 @@ function collectLights(world) {
|
|
|
33373
35044
|
at.z
|
|
33374
35045
|
],
|
|
33375
35046
|
range: light.range,
|
|
33376
|
-
rgb
|
|
35047
|
+
rgb,
|
|
35048
|
+
direct
|
|
33377
35049
|
});
|
|
33378
35050
|
}
|
|
33379
35051
|
}
|
|
33380
35052
|
return out;
|
|
33381
35053
|
}
|
|
33382
35054
|
/**
|
|
33383
|
-
* The radiance a surface hit sends back: albedo times the direct light there.
|
|
35055
|
+
* The radiance a surface hit sends back: albedo times the direct light there, from every light.
|
|
33384
35056
|
*
|
|
33385
35057
|
* @param scene - The triangles.
|
|
33386
35058
|
* @param lights - The lights.
|
|
@@ -33419,24 +35091,26 @@ function shadeHit(scene, lights, hit, x, y, z, out) {
|
|
|
33419
35091
|
for (let channel = 0; channel < 3; channel += 1) out[channel] = read(out, channel) * read(scene.albedo, base + channel);
|
|
33420
35092
|
}
|
|
33421
35093
|
/**
|
|
33422
|
-
* The radiance of a ray that hit nothing: the sky
|
|
35094
|
+
* The radiance of a ray that hit nothing: the sky, plus the hemispheric lights whose direct light
|
|
35095
|
+
* the probes store.
|
|
33423
35096
|
*
|
|
33424
35097
|
* @param lights - The lights.
|
|
33425
|
-
* @param sky - The sky
|
|
35098
|
+
* @param sky - The sky.
|
|
33426
35099
|
* @param dx - The ray's X.
|
|
33427
35100
|
* @param dy - The ray's Y.
|
|
33428
35101
|
* @param dz - The ray's Z.
|
|
33429
35102
|
* @param out - Receives linear RGB.
|
|
33430
35103
|
*/
|
|
33431
35104
|
function missRadiance(lights, sky, dx, dy, dz, out) {
|
|
33432
|
-
|
|
33433
|
-
for (const light of lights) if (light.kind === "hemispheric") {
|
|
35105
|
+
sky(dx, dy, dz, out);
|
|
35106
|
+
for (const light of lights) if (light.kind === "hemispheric" && light.direct) {
|
|
33434
35107
|
const above = dx * light.up[0] + dy * light.up[1] + dz * light.up[2] >= 0;
|
|
33435
35108
|
for (let channel = 0; channel < 3; channel += 1) out[channel] = read(out, channel) + read(above ? light.sky : light.ground, channel);
|
|
33436
35109
|
}
|
|
33437
35110
|
}
|
|
33438
35111
|
/**
|
|
33439
|
-
* Adds the directional, point and spot lights
|
|
35112
|
+
* Adds the directional, point and spot lights whose direct light the probes store, as
|
|
35113
|
+
* clamped-cosine lobes.
|
|
33440
35114
|
*
|
|
33441
35115
|
* @param scene - The triangles.
|
|
33442
35116
|
* @param lights - The lights.
|
|
@@ -33454,7 +35128,7 @@ function addDirectLobes(scene, lights, x, y, z, sh) {
|
|
|
33454
35128
|
triangle: -1
|
|
33455
35129
|
};
|
|
33456
35130
|
for (const light of lights) {
|
|
33457
|
-
if (light.kind === "hemispheric") continue;
|
|
35131
|
+
if (light.kind === "hemispheric" || !light.direct) continue;
|
|
33458
35132
|
const toward = towardLight(light, x, y, z);
|
|
33459
35133
|
if (toward === null) continue;
|
|
33460
35134
|
const [lx, ly, lz, distance, falloff] = toward;
|
|
@@ -33499,7 +35173,53 @@ function towardLight(light, x, y, z) {
|
|
|
33499
35173
|
];
|
|
33500
35174
|
}
|
|
33501
35175
|
/**
|
|
33502
|
-
*
|
|
35176
|
+
* The distance at which a ray enters an axis-aligned box (slab test).
|
|
35177
|
+
*
|
|
35178
|
+
* @param meshes - The scene's mesh table.
|
|
35179
|
+
* @param base - The mesh's first float in it.
|
|
35180
|
+
* @param ox - The ray origin's X.
|
|
35181
|
+
* @param oy - The ray origin's Y.
|
|
35182
|
+
* @param oz - The ray origin's Z.
|
|
35183
|
+
* @param ix - `1 / dx`.
|
|
35184
|
+
* @param iy - `1 / dy`.
|
|
35185
|
+
* @param iz - `1 / dz`.
|
|
35186
|
+
* @param nearest - How far the nearest hit so far is.
|
|
35187
|
+
* @returns Whether the ray meets the box before `nearest`.
|
|
35188
|
+
*/
|
|
35189
|
+
function meetsBox(meshes, base, ox, oy, oz, ix, iy, iz, nearest) {
|
|
35190
|
+
let near = 0;
|
|
35191
|
+
let far = nearest;
|
|
35192
|
+
const origin = [
|
|
35193
|
+
ox,
|
|
35194
|
+
oy,
|
|
35195
|
+
oz
|
|
35196
|
+
];
|
|
35197
|
+
const inverse = [
|
|
35198
|
+
ix,
|
|
35199
|
+
iy,
|
|
35200
|
+
iz
|
|
35201
|
+
];
|
|
35202
|
+
for (let axis = 0; axis < 3; axis += 1) {
|
|
35203
|
+
const o = read(origin, axis);
|
|
35204
|
+
const inv = read(inverse, axis);
|
|
35205
|
+
const lo = read(meshes, base + 2 + axis) - 1e-6;
|
|
35206
|
+
const hi = read(meshes, base + 5 + axis) + 1e-6;
|
|
35207
|
+
let t0 = (lo - o) * inv;
|
|
35208
|
+
let t1 = (hi - o) * inv;
|
|
35209
|
+
if (Number.isNaN(t0) || Number.isNaN(t1)) {
|
|
35210
|
+
if (o < lo || o > hi) return false;
|
|
35211
|
+
continue;
|
|
35212
|
+
}
|
|
35213
|
+
if (t0 > t1) [t0, t1] = [t1, t0];
|
|
35214
|
+
near = Math.max(near, t0);
|
|
35215
|
+
far = Math.min(far, t1);
|
|
35216
|
+
if (near > far) return false;
|
|
35217
|
+
}
|
|
35218
|
+
return true;
|
|
35219
|
+
}
|
|
35220
|
+
/**
|
|
35221
|
+
* Finds the nearest triangle a ray hits (Möller–Trumbore, both faces), testing only the meshes
|
|
35222
|
+
* whose world box it passes through.
|
|
33503
35223
|
*
|
|
33504
35224
|
* @param scene - The triangles.
|
|
33505
35225
|
* @param ox - The ray origin's X.
|
|
@@ -33514,39 +35234,49 @@ function towardLight(light, x, y, z) {
|
|
|
33514
35234
|
*/
|
|
33515
35235
|
function trace(scene, ox, oy, oz, dx, dy, dz, maxDistance, out) {
|
|
33516
35236
|
const v = scene.vertices;
|
|
35237
|
+
const meshes = scene.meshes;
|
|
35238
|
+
const ix = 1 / dx;
|
|
35239
|
+
const iy = 1 / dy;
|
|
35240
|
+
const iz = 1 / dz;
|
|
33517
35241
|
let nearest = maxDistance;
|
|
33518
35242
|
let found = -1;
|
|
33519
|
-
for (let
|
|
33520
|
-
const
|
|
33521
|
-
|
|
33522
|
-
const
|
|
33523
|
-
const
|
|
33524
|
-
|
|
33525
|
-
|
|
33526
|
-
|
|
33527
|
-
|
|
33528
|
-
|
|
33529
|
-
|
|
33530
|
-
|
|
33531
|
-
|
|
33532
|
-
|
|
33533
|
-
|
|
33534
|
-
|
|
33535
|
-
|
|
33536
|
-
|
|
33537
|
-
|
|
33538
|
-
|
|
33539
|
-
|
|
33540
|
-
|
|
33541
|
-
|
|
33542
|
-
|
|
33543
|
-
|
|
33544
|
-
|
|
33545
|
-
|
|
33546
|
-
|
|
33547
|
-
|
|
33548
|
-
|
|
33549
|
-
|
|
35243
|
+
for (let mesh = 0; mesh < scene.meshCount; mesh += 1) {
|
|
35244
|
+
const base = mesh * MESH_STRIDE;
|
|
35245
|
+
if (!meetsBox(meshes, base, ox, oy, oz, ix, iy, iz, nearest)) continue;
|
|
35246
|
+
const first = read(meshes, base);
|
|
35247
|
+
const end = first + read(meshes, base + 1);
|
|
35248
|
+
for (let triangle = first; triangle < end; triangle += 1) {
|
|
35249
|
+
const b = triangle * 9;
|
|
35250
|
+
const ax = read(v, b);
|
|
35251
|
+
const ay = read(v, b + 1);
|
|
35252
|
+
const az = read(v, b + 2);
|
|
35253
|
+
const e1x = read(v, b + 3) - ax;
|
|
35254
|
+
const e1y = read(v, b + 4) - ay;
|
|
35255
|
+
const e1z = read(v, b + 5) - az;
|
|
35256
|
+
const e2x = read(v, b + 6) - ax;
|
|
35257
|
+
const e2y = read(v, b + 7) - ay;
|
|
35258
|
+
const e2z = read(v, b + 8) - az;
|
|
35259
|
+
const px = dy * e2z - dz * e2y;
|
|
35260
|
+
const py = dz * e2x - dx * e2z;
|
|
35261
|
+
const pz = dx * e2y - dy * e2x;
|
|
35262
|
+
const det = e1x * px + e1y * py + e1z * pz;
|
|
35263
|
+
if (Math.abs(det) < 1e-12) continue;
|
|
35264
|
+
const inv = 1 / det;
|
|
35265
|
+
const tx = ox - ax;
|
|
35266
|
+
const ty = oy - ay;
|
|
35267
|
+
const tz = oz - az;
|
|
35268
|
+
const u = (tx * px + ty * py + tz * pz) * inv;
|
|
35269
|
+
if (u < 0 || u > 1) continue;
|
|
35270
|
+
const qx = ty * e1z - tz * e1y;
|
|
35271
|
+
const qy = tz * e1x - tx * e1z;
|
|
35272
|
+
const qz = tx * e1y - ty * e1x;
|
|
35273
|
+
const w = (dx * qx + dy * qy + dz * qz) * inv;
|
|
35274
|
+
if (w < 0 || u + w > 1) continue;
|
|
35275
|
+
const distance = (e2x * qx + e2y * qy + e2z * qz) * inv;
|
|
35276
|
+
if (distance > 1e-6 && distance < nearest) {
|
|
35277
|
+
nearest = distance;
|
|
35278
|
+
found = triangle;
|
|
35279
|
+
}
|
|
33550
35280
|
}
|
|
33551
35281
|
}
|
|
33552
35282
|
if (found < 0) return false;
|
|
@@ -33720,6 +35450,7 @@ function describeSchemas() {
|
|
|
33720
35450
|
"ignifx/material-file": describeMaterialFileFormat(),
|
|
33721
35451
|
"ignifx/environment-file": describeEnvironmentFileFormat(),
|
|
33722
35452
|
"ignifx/light-probe-file": describeLightProbeFileFormat(),
|
|
35453
|
+
"ignifx/lightmap-file": describeLightmapFileFormat(),
|
|
33723
35454
|
"ignifx/mesh-file": describeMeshFileFormat()
|
|
33724
35455
|
};
|
|
33725
35456
|
}
|
|
@@ -34082,6 +35813,42 @@ function describeLightProbeFileFormat() {
|
|
|
34082
35813
|
}
|
|
34083
35814
|
};
|
|
34084
35815
|
}
|
|
35816
|
+
/**
|
|
35817
|
+
* Describes the `.lightmap.json` lightmap format (GI Phase 2, step B3).
|
|
35818
|
+
*
|
|
35819
|
+
* @returns The description of the top-level file fields.
|
|
35820
|
+
*
|
|
35821
|
+
* @beta
|
|
35822
|
+
*/
|
|
35823
|
+
function describeLightmapFileFormat() {
|
|
35824
|
+
return {
|
|
35825
|
+
title: "Lightmap file",
|
|
35826
|
+
format: LIGHTMAP_FILE_FORMAT,
|
|
35827
|
+
description: "A baked lightmap texture that static MeshRenderers sample through their second UV set, and where each entity's UV2 square sits in it.",
|
|
35828
|
+
fields: {
|
|
35829
|
+
format: {
|
|
35830
|
+
kind: "str",
|
|
35831
|
+
default: LIGHTMAP_FILE_FORMAT,
|
|
35832
|
+
description: `Always "${LIGHTMAP_FILE_FORMAT}".`
|
|
35833
|
+
},
|
|
35834
|
+
formatVersion: {
|
|
35835
|
+
kind: "u32",
|
|
35836
|
+
default: 1,
|
|
35837
|
+
description: "The file format version; 1 before ignifx 1.0."
|
|
35838
|
+
},
|
|
35839
|
+
texture: {
|
|
35840
|
+
kind: "str",
|
|
35841
|
+
default: "",
|
|
35842
|
+
description: "The lightmap texture's asset address (a .png, .ktx2 or other texture); required."
|
|
35843
|
+
},
|
|
35844
|
+
entries: {
|
|
35845
|
+
kind: "map",
|
|
35846
|
+
default: {},
|
|
35847
|
+
description: "Per entity uid, { scale: { x, y }, offset: { x, y } }: the entity's UV2 square in the texture (sampled at uv2 · scale + offset; scale above 0). Missing halves and missing entities take scale 1, offset 0. A placement other than the identity needs the renderer's lightmap.uv2 on and a mesh with uvs2; each distinct placement is its own pipeline variant."
|
|
35848
|
+
}
|
|
35849
|
+
}
|
|
35850
|
+
};
|
|
35851
|
+
}
|
|
34085
35852
|
//#endregion
|
|
34086
35853
|
//#region src/serialization/instance-lookup.ts
|
|
34087
35854
|
/**
|
|
@@ -34554,10 +36321,14 @@ function writeInstance(root, origin, references, report) {
|
|
|
34554
36321
|
* Diffs every direct member of an instance against the record the instanced file holds for it.
|
|
34555
36322
|
*
|
|
34556
36323
|
* @remarks
|
|
34557
|
-
*
|
|
34558
|
-
* the instanced scene itself instanced
|
|
34559
|
-
*
|
|
34560
|
-
*
|
|
36324
|
+
* Entities the instanced file itself declares are diffed field by field. Components that came
|
|
36325
|
+
* from a scene the instanced scene itself instanced are diffed against the records the expansion
|
|
36326
|
+
* kept for them (`EntityInstanceLink.nestedBaseline`: the nested file with the outer prefab's own
|
|
36327
|
+
* overrides applied), and a changed prop or `enabled` flag, or a removed component, is written as
|
|
36328
|
+
* an override whose component segment is an instance path; so are the components a scene the
|
|
36329
|
+
* instanced single root itself instances merged into the instance root. Nested entities' own
|
|
36330
|
+
* fields are not written back; a component added to a nested entity and a nested entity destroyed
|
|
36331
|
+
* at run time cannot be, and are reported (`IGX-0609`). `flatten: true` is the escape hatch.
|
|
34561
36332
|
*
|
|
34562
36333
|
* An instance root that stands for its scene's single root is diffed against that root's record
|
|
34563
36334
|
* too, but only for the components the scene put on it: its name, transform, and other entity
|
|
@@ -34594,9 +36365,167 @@ function computeOverrides(root, link, references, report) {
|
|
|
34594
36365
|
}
|
|
34595
36366
|
diffEntity(entity, record, overrides, references, report, localize);
|
|
34596
36367
|
}
|
|
36368
|
+
const baseline = link.nestedBaseline;
|
|
36369
|
+
if (baseline !== null) {
|
|
36370
|
+
const nested = {
|
|
36371
|
+
root,
|
|
36372
|
+
baseline,
|
|
36373
|
+
overrides,
|
|
36374
|
+
references,
|
|
36375
|
+
report,
|
|
36376
|
+
covered: /* @__PURE__ */ new Set()
|
|
36377
|
+
};
|
|
36378
|
+
if (single !== null && link.nestedRootSourceUids !== null) diffNestedComponents(root, single.sourceUid, link.nestedRootSourceUids, nested);
|
|
36379
|
+
markLive(root, nested);
|
|
36380
|
+
diffNestedMembers(root, nested);
|
|
36381
|
+
reportLostNestedComponents(root, nested);
|
|
36382
|
+
}
|
|
34597
36383
|
return overrides;
|
|
34598
36384
|
}
|
|
34599
36385
|
/**
|
|
36386
|
+
* Reports the nested-prefab components no live entity of the instance accounts for: their entity
|
|
36387
|
+
* was destroyed at run time (or sits where an override cannot address it), and an override cannot
|
|
36388
|
+
* say so, so the saved file brings them back.
|
|
36389
|
+
*
|
|
36390
|
+
* @param root - The instance root.
|
|
36391
|
+
* @param nested - The diff state.
|
|
36392
|
+
*/
|
|
36393
|
+
function reportLostNestedComponents(root, nested) {
|
|
36394
|
+
let lost = 0;
|
|
36395
|
+
for (const uid of nested.baseline.keys()) if (!nested.covered.has(uid)) lost += 1;
|
|
36396
|
+
if (lost > 0) nested.report(CoreErrorCode.invalidOverridePath, `${String(lost)} component(s) of a prefab nested in the instance ${JSON.stringify(root.name)} belong to an entity destroyed at run time; an override cannot remove a nested entity, so the saved file keeps it. Destroy it in the nested prefab, or save with flatten: true.`);
|
|
36397
|
+
}
|
|
36398
|
+
/**
|
|
36399
|
+
* Diffs the components an instance's nested prefabs produced against their baseline records, below
|
|
36400
|
+
* one entity of the instance, and reports the components added at run time to an entity a nested
|
|
36401
|
+
* prefab declares, which an override cannot add.
|
|
36402
|
+
*
|
|
36403
|
+
* @param entity - Where to walk from.
|
|
36404
|
+
* @param nested - The diff state.
|
|
36405
|
+
*/
|
|
36406
|
+
function diffNestedMembers(entity, nested) {
|
|
36407
|
+
const root = nested.root;
|
|
36408
|
+
const children = entity.children;
|
|
36409
|
+
for (let index = 0; index < children.length; index += 1) {
|
|
36410
|
+
const child = children[index];
|
|
36411
|
+
if (child === void 0 || child.isDestroyed || !belongsToInstance(child, root)) continue;
|
|
36412
|
+
markLive(child, nested);
|
|
36413
|
+
const origin = entityInternals(child).origin;
|
|
36414
|
+
const inside = origin?.instanceRoot ?? null;
|
|
36415
|
+
if (origin !== null && inside !== null && inside !== root) {
|
|
36416
|
+
const prefix = nestedPathOf(inside, root);
|
|
36417
|
+
if (prefix !== null) diffNestedComponents(child, prefix, origin.componentSourceUids, nested);
|
|
36418
|
+
reportAddedToNested(child, origin, nested);
|
|
36419
|
+
}
|
|
36420
|
+
const link = origin?.instanced ?? null;
|
|
36421
|
+
const merged = link?.root ?? null;
|
|
36422
|
+
if (link !== null && merged !== null) {
|
|
36423
|
+
const prefix = nestedPathOf(child, root);
|
|
36424
|
+
if (prefix !== null) {
|
|
36425
|
+
diffNestedComponents(child, prefix, merged.componentSourceUids, nested);
|
|
36426
|
+
if (link.nestedRootSourceUids !== null) diffNestedComponents(child, prefix, link.nestedRootSourceUids, nested);
|
|
36427
|
+
}
|
|
36428
|
+
}
|
|
36429
|
+
diffNestedMembers(child, nested);
|
|
36430
|
+
}
|
|
36431
|
+
}
|
|
36432
|
+
/**
|
|
36433
|
+
* Counts an entity's live components that have a baseline record as accounted for, so only the
|
|
36434
|
+
* components of a destroyed entity are reported lost.
|
|
36435
|
+
*
|
|
36436
|
+
* @param entity - The entity.
|
|
36437
|
+
* @param nested - The diff state.
|
|
36438
|
+
*/
|
|
36439
|
+
function markLive(entity, nested) {
|
|
36440
|
+
const components = entity.components;
|
|
36441
|
+
for (let index = 0; index < components.length; index += 1) {
|
|
36442
|
+
const component = components[index];
|
|
36443
|
+
if (component !== void 0 && !component.isDestroyed && nested.baseline.has(component.uid)) nested.covered.add(component.uid);
|
|
36444
|
+
}
|
|
36445
|
+
}
|
|
36446
|
+
/**
|
|
36447
|
+
* Reports the components added at run time to an entity a nested prefab declares: an override
|
|
36448
|
+
* reaches a nested entity's components only by instance path, which an added component has none
|
|
36449
|
+
* of, so the saved file drops it.
|
|
36450
|
+
*
|
|
36451
|
+
* @param entity - The nested entity.
|
|
36452
|
+
* @param origin - Its origin.
|
|
36453
|
+
* @param nested - The diff state.
|
|
36454
|
+
*/
|
|
36455
|
+
function reportAddedToNested(entity, origin, nested) {
|
|
36456
|
+
const fromFiles = origin.instanced?.root?.components;
|
|
36457
|
+
const components = entity.components;
|
|
36458
|
+
for (let index = 0; index < components.length; index += 1) {
|
|
36459
|
+
const component = components[index];
|
|
36460
|
+
if (component === void 0 || component === entity.transform || component.isDestroyed || origin.componentSourceUids.has(component.uid) || fromFiles?.has(component.uid) === true || nested.baseline.has(component.uid)) continue;
|
|
36461
|
+
const typeId = component.world.registry.describe(component.constructor).typeId ?? component.constructor.name;
|
|
36462
|
+
nested.report(CoreErrorCode.invalidOverridePath, `${typeId} was added at run time to ${JSON.stringify(entity.name)}, which a prefab nested in the instance ${JSON.stringify(nested.root.name)} declares; an override cannot add a component there, so it is not saved. Add it in the nested prefab, or save with flatten: true.`);
|
|
36463
|
+
}
|
|
36464
|
+
}
|
|
36465
|
+
/**
|
|
36466
|
+
* The instance path, from an outer instance, of a nested instance root inside it: the uids each
|
|
36467
|
+
* enclosing file gives the entities carrying the nested `instance` entries.
|
|
36468
|
+
*
|
|
36469
|
+
* @param entity - The nested instance root.
|
|
36470
|
+
* @param root - The outer instance root.
|
|
36471
|
+
* @returns `"<uidInTheOuterFile>/…/<uid>"`, or `null` when the entity is not inside `root`.
|
|
36472
|
+
*/
|
|
36473
|
+
function nestedPathOf(entity, root) {
|
|
36474
|
+
const segments = [];
|
|
36475
|
+
let current = entity;
|
|
36476
|
+
const limit = 64;
|
|
36477
|
+
while (current !== null && segments.length < limit) {
|
|
36478
|
+
const origin = entityInternals(current).origin;
|
|
36479
|
+
if (origin === null) return null;
|
|
36480
|
+
segments.push(origin.sourceUid);
|
|
36481
|
+
if (origin.instanceRoot === root) return segments.toReversed().join("/");
|
|
36482
|
+
current = origin.instanceRoot;
|
|
36483
|
+
}
|
|
36484
|
+
return null;
|
|
36485
|
+
}
|
|
36486
|
+
/**
|
|
36487
|
+
* Diffs one entity's nested-prefab components against their baseline records.
|
|
36488
|
+
*
|
|
36489
|
+
* @param entity - The entity; a baseline component it no longer has is written as a `remove`.
|
|
36490
|
+
* @param prefix - The instance path of the nested instance the components' uids are local to.
|
|
36491
|
+
* @param sourceUids - Runtime component uid to the uid that nested file gives it.
|
|
36492
|
+
* @param nested - The diff state.
|
|
36493
|
+
*/
|
|
36494
|
+
function diffNestedComponents(entity, prefix, sourceUids, nested) {
|
|
36495
|
+
const { baseline, overrides, references, report } = nested;
|
|
36496
|
+
const head = prefix.split("/")[0] ?? prefix;
|
|
36497
|
+
for (const [uid, sourceUid] of sourceUids) {
|
|
36498
|
+
const before = baseline.get(uid);
|
|
36499
|
+
if (before === void 0) continue;
|
|
36500
|
+
nested.covered.add(uid);
|
|
36501
|
+
const component = entity.components.find((candidate) => candidate.uid === uid && !candidate.isDestroyed);
|
|
36502
|
+
if (component === void 0) {
|
|
36503
|
+
overrides.push({
|
|
36504
|
+
op: "remove",
|
|
36505
|
+
path: `${head}/components/${prefix}/${sourceUid}`
|
|
36506
|
+
});
|
|
36507
|
+
continue;
|
|
36508
|
+
}
|
|
36509
|
+
const registry = component.world.registry;
|
|
36510
|
+
if (registry.describe(component.constructor).typeId === null) continue;
|
|
36511
|
+
const comparable = serializeComponent(component, ownUidEncoder());
|
|
36512
|
+
const written = serializeComponent(component, references, (issue) => {
|
|
36513
|
+
report(issue.code, issue.message);
|
|
36514
|
+
});
|
|
36515
|
+
const schema = registry.describe(component.constructor).schema;
|
|
36516
|
+
diffProps(head, `${prefix}/${sourceUid}`, before, comparable, schema, overrides, identity, written);
|
|
36517
|
+
}
|
|
36518
|
+
}
|
|
36519
|
+
/**
|
|
36520
|
+
* Returns its argument, for a diff whose two sides already share one uid space.
|
|
36521
|
+
*
|
|
36522
|
+
* @param value - The JSON.
|
|
36523
|
+
* @returns `value`.
|
|
36524
|
+
*/
|
|
36525
|
+
function identity(value) {
|
|
36526
|
+
return value;
|
|
36527
|
+
}
|
|
36528
|
+
/**
|
|
34600
36529
|
* Collects the entities of an instance that the instanced file itself declared, keyed by the uid it
|
|
34601
36530
|
* gave them.
|
|
34602
36531
|
*
|
|
@@ -34774,21 +36703,24 @@ function diffComponents(entity, record, diff, overrides, references, report) {
|
|
|
34774
36703
|
* @param schema - The component's declared fields, so an omitted prop compares against its default.
|
|
34775
36704
|
* @param overrides - Where patches are appended.
|
|
34776
36705
|
* @param localize - Rewrites `after`'s references into the instanced file's uids for the comparison.
|
|
36706
|
+
* @param emitted - What the overrides' values are taken from, when it is not `after` (the same
|
|
36707
|
+
* component written with other references).
|
|
34777
36708
|
*/
|
|
34778
|
-
function diffProps(entityUid, componentUid, before, after, schema, overrides, localize) {
|
|
36709
|
+
function diffProps(entityUid, componentUid, before, after, schema, overrides, localize, emitted = after) {
|
|
34779
36710
|
if ((before.enabled ?? true) !== (after.enabled ?? true)) overrides.push({
|
|
34780
36711
|
path: `${entityUid}/components/${componentUid}/enabled`,
|
|
34781
36712
|
value: after.enabled ?? true
|
|
34782
36713
|
});
|
|
34783
36714
|
const beforeProps = before.props ?? {};
|
|
34784
36715
|
const afterProps = after.props ?? {};
|
|
36716
|
+
const emittedProps = emitted.props ?? {};
|
|
34785
36717
|
const references = ownUidEncoder();
|
|
34786
36718
|
for (const name of Object.keys(afterProps)) {
|
|
34787
36719
|
const next = afterProps[name] ?? null;
|
|
34788
36720
|
const field = schema?.[name];
|
|
34789
36721
|
if (!sameJson(beforeProps[name] ?? (field === void 0 ? null : encodeValue(field, field.createDefault(), references)), localize(next))) overrides.push({
|
|
34790
36722
|
path: `${entityUid}/components/${componentUid}/props/${name}`,
|
|
34791
|
-
value: next
|
|
36723
|
+
value: emittedProps[name] ?? next
|
|
34792
36724
|
});
|
|
34793
36725
|
}
|
|
34794
36726
|
}
|
|
@@ -34950,7 +36882,9 @@ function componentPackage(registry, typeId) {
|
|
|
34950
36882
|
* Describes every component an app has registered, the engine's, its extensions' and the game's,
|
|
34951
36883
|
* the way {@link describeSchema} describes one, plus what only the registry knows: whether an
|
|
34952
36884
|
* entity may hold more than one (`allowMultiple`), which package registered it (`package`), and
|
|
34953
|
-
* which components it adds when they are missing (`requires`, its classes' type ids
|
|
36885
|
+
* which components it adds when they are missing (`requires`, its classes' type ids; `null` for a
|
|
36886
|
+
* class that declares no `typeId` of its own, such as an unregistered subclass that only inherits
|
|
36887
|
+
* its parent's, because naming the parent would describe a different component).
|
|
34954
36888
|
* This is what an external inspector, such as the ignifx editor, is generated from.
|
|
34955
36889
|
*
|
|
34956
36890
|
* @remarks
|
|
@@ -34998,7 +36932,7 @@ function describeRegisteredSchemas(registry, curated) {
|
|
|
34998
36932
|
allowMultiple: info.allowMultiple,
|
|
34999
36933
|
package: componentPackage(registry, typeId),
|
|
35000
36934
|
...builtIn ? { builtIn } : {},
|
|
35001
|
-
...info.requires.length === 0 ? {} : { requires: info.requires.map((required) => required.typeId ?? null) }
|
|
36935
|
+
...info.requires.length === 0 ? {} : { requires: info.requires.map((required) => Object.hasOwn(required, "typeId") ? required.typeId ?? null : null) }
|
|
35002
36936
|
});
|
|
35003
36937
|
}
|
|
35004
36938
|
return described;
|
|
@@ -35546,6 +37480,6 @@ function settingsJsonSchema(app) {
|
|
|
35546
37480
|
};
|
|
35547
37481
|
}
|
|
35548
37482
|
//#endregion
|
|
35549
|
-
export { AMBIENT_OCCLUSION_QUALITIES, ASSET_DIAGNOSTICS_COUNTERS, ASSET_DIAGNOSTICS_GROUP, ASSET_MANIFEST_FORMAT, ASSET_MANIFEST_VERSION, AssetLoadError, CANVAS_ALPHA_MODES, CORE_ERROR_MESSAGES, Camera, Color, Component, ComponentRegistry, CoreErrorCode, DEFAULT_ASSET_CONCURRENCY, DEFAULT_ASSET_ROOT, DEFAULT_BRDF_LUT_ADDRESS, DEFAULT_LAYER, DEFAULT_MEMORY_SINK_LIMIT, DEFAULT_STORAGE_NAMESPACE, DEG_TO_RAD, Diagnostics, EASINGS, EASING_NAMES, EDITOR_ONLY_METADATA_KEY, EMPTY_ASSET_MANIFEST, ENVIRONMENT_ASSET_TYPE, ENVIRONMENT_FILE_EXTENSION, ENVIRONMENT_FILE_EXTENSIONS, ENVIRONMENT_FILE_FORMAT, ENVIRONMENT_FORMAT_VERSION, EPSILON, Entity, Environment, EnvironmentAsset, ErrorRange, FOG_MODE_NAMES, FONT_ASSET_TYPE, FONT_FILE_EXTENSIONS, FRAME_HISTORY_LENGTH, FieldKind, FontAsset, IGNIFX_UNIFORM_NAMES, INVALID_HANDLE, IgnifxError, IndexedDbStorageBackend, InstancedMeshRenderer, LIGHT_PROBE_ASSET_TYPE, LIGHT_PROBE_FILE_EXTENSIONS, LIGHT_PROBE_FILE_FORMAT, LIGHT_PROBE_FORMAT_VERSION, LIGHT_TYPES, LITE_MATERIAL_PLUGIN_POINTS, LITE_SYSTEM_UNIFORM_NAMES, LOG_LEVEL_SEVERITY, LayerMask, LayerTable, Light, LightProbeAsset, LightProbeVolume, LogLevel, MAT4_IDENTITY, MATERIAL_ALPHA_MODES, MATERIAL_ASSET_TYPE, MATERIAL_FILE_EXTENSION, MATERIAL_FILE_FORMAT, MATERIAL_FORMAT_VERSION, MATERIAL_KINDS, MATERIAL_PLUGIN_DEFAULT_PRIORITY, MATERIAL_PLUGIN_RESERVED_NAMES, MATERIAL_PLUGIN_SAMPLER_BUDGET, MAX_LAYERS, MAX_ULID_TIME_MS, MESH_ASSET_TYPE, MESH_FILE_EXTENSION, MESH_FILE_FORMAT, MESH_FORMAT_VERSION, MESH_PRIMITIVES, MESH_PRIMITIVE_OPTIONS, MODEL_ASSET_TYPE, MODEL_FILE_EXTENSIONS, Mat4, MaterialAsset, MemoryStorageBackend, MeshAsset, MeshRenderer, Model, ModelAsset, NAMESPACE_SEGMENT_MAX_LENGTH, PBR_TEXTURE_SLOTS, PHASES, PHASE_COUNT, PHASE_NAMES, POST_EFFECT_BUILTIN_UNIFORMS, POST_EFFECT_FUNCTION, PROJECTIONS, Phase, PhysicsCallbackName, PostProcessStack, QUAT_IDENTITY, Quat, RAD_TO_DEG, REFLECTION_PROBE_REFRESH_MODES, RENDERING_QUALITIES, RENDERING_SETTINGS_SECTION, RENDER_DIAGNOSTICS_COUNTERS, RENDER_DIAGNOSTICS_GROUP, RENDER_TEXTURE_MAX_SIZE, RESERVED_LAYER_NAMES, ReflectionProbe, SCENE_ASSET_TYPE, SCENE_FILE_EXTENSIONS, SCENE_FILE_FORMAT, SCENE_FORMAT_VERSION, SETTINGS_DESCRIPTION_FORMAT, SHADER_ASSET_TYPE, SHADER_ATTRIBUTE_NAMES, SHADER_BLEND_MODES, SHADER_CULL_MODES, SHADER_FILE_EXTENSIONS, SHADER_INSTANCING_MODES, SHADER_KINDS, SHADER_TEXTURE_FALLBACKS, SHADER_UNIFORM_TYPES, SHADOW_TECHNIQUES, STANDARD_TEXTURE_SLOTS, STORAGE_BUFFER_ASSET_TYPE, STORAGE_KEY_MAX_LENGTH, SURFACE_HOOK_NAMES, SURFACE_UNIFORM_BLOCK, SceneAssetToken, SceneInstance, SchemaIssueCode, Script, ScriptCallbackKind, ShaderAsset, Signal, StorageBufferAsset, TEXTURE_ASSET_TYPE, THIRD_PARTY_ERROR_PREFIX, TONE_MAPPING_NAMES, TWEEN_LOOP_FOREVER, TWEEN_SYSTEM_ORDER, TWEEN_VALUE_KINDS, TagSet, TextureAsset, Transform, Tween, UidRemap, VEC2_ONE, VEC2_ZERO, VEC3_BACKWARD, VEC3_DOWN, VEC3_FORWARD, VEC3_LEFT, VEC3_ONE, VEC3_RIGHT, VEC3_UP, VEC3_ZERO, VERSION, Vec2, Vec3, Vec4, World, addComponentFromRecord, applyInit, applyOverridesToAsset, approximately, array, assertNever, assertSceneDependenciesLoaded, asset, assetRef, bakeLightProbes, binaryAssetLoader, bool, canonicalizeNumber, clamp, clamp01, color, componentRef, computeSceneHash, coreExtension, createApp, createAssetManifest, createConsoleSink, createCryptoRandom, createDefaults, createDiagnosticsGroup, createEnvironmentLoader, createErrorCodeRegistry, createFileStorageBackend, createFontLoader, createFrameSample, createLayerTable, createLightProbeAsset, createLightProbeLoader, createLogger, createManualClock, createMaterialAsset, createMaterialLoader, createMemorySink, createMeshLoader, createModelLoader, createPerformanceClock, createRay, createSceneAsset, createSceneLoader, createSeededRandom, createServiceKey, createShaderLoader, createStorageBufferAsset, createTextureLoader, createUlidFactory, curve, custom, customEffect, decodeProps, decodeValue, defaultAutoExposureSettings, defaultRenderingSettings, defineExtension, defineMaterialPlugin, defineSchema, degToRad, deltaAngleDegrees, describeEnvironmentFileFormat, describeLightProbeFileFormat, describeMaterialFileFormat, describeMeshFileFormat, describeRegisteredSchemas, describeSceneFileFormat, describeSchema, describeSchemas, describeSettings, encodeProps, encodeValue, entityRef, enumOf, environmentDefinition, f32, f64, forceRendererDeviceLossForTesting, formatErrorMessage, generateUlid, i32, instanceComponentAt, instanceEntityAt, instantiateScene, inverseLerp, isAssetRef, isIgnifxError, isLiteMaterialPluginPoint, isSceneFileHeader, isUlid, isValidErrorCode, isWebGpuAvailable, jsonAssetLoader, layerMask, lerp, lerpAngleDegrees, loadSceneDependencies, map, meshFileJsonSchema, moveTowards, optional, parseOverridePath, pbrMaterialDefinition, pingPong, platformInternals, quat, radToDeg, record, repeat, resetFrameSample, resolveEase, revertOverrides, sampleLightProbes, sceneFileJsonSchema, serializeComponent, serializeEntity, serializeScene, settingsJsonSchema, shaderMaterialDefinition, sign, smoothStep, standardMaterialDefinition, storageInternals, str, stringifySceneFile, textAssetLoader, toJsonSchema, transformSchema, u32, validateProps, validateSceneFile, validateValue, vec2, vec3, vec4, waitFixedUpdate, waitSeconds, waitSecondsRealtime, waitUntil, waitWhile, wrapAngleDegrees, writeLightProbeFile };
|
|
37483
|
+
export { AMBIENT_OCCLUSION_QUALITIES, ASSET_DIAGNOSTICS_COUNTERS, ASSET_DIAGNOSTICS_GROUP, ASSET_MANIFEST_FORMAT, ASSET_MANIFEST_VERSION, AssetLoadError, CANVAS_ALPHA_MODES, CORE_ERROR_MESSAGES, Camera, Color, Component, ComponentRegistry, CoreErrorCode, DEFAULT_ASSET_CONCURRENCY, DEFAULT_ASSET_ROOT, DEFAULT_BRDF_LUT_ADDRESS, DEFAULT_LAYER, DEFAULT_MEMORY_SINK_LIMIT, DEFAULT_STORAGE_NAMESPACE, DEG_TO_RAD, Diagnostics, EASINGS, EASING_NAMES, EDITOR_ONLY_METADATA_KEY, EMPTY_ASSET_MANIFEST, ENVIRONMENT_ASSET_TYPE, ENVIRONMENT_FILE_EXTENSION, ENVIRONMENT_FILE_EXTENSIONS, ENVIRONMENT_FILE_FORMAT, ENVIRONMENT_FORMAT_VERSION, EPSILON, Entity, Environment, EnvironmentAsset, ErrorRange, FOG_MODE_NAMES, FONT_ASSET_TYPE, FONT_FILE_EXTENSIONS, FRAME_HISTORY_LENGTH, FieldKind, FontAsset, IDENTITY_LIGHTMAP_PLACEMENT, IGNIFX_UNIFORM_NAMES, INVALID_HANDLE, IgnifxError, IndexedDbStorageBackend, InstancedMeshRenderer, LIGHTMAP_ASSET_TYPE, LIGHTMAP_FILE_EXTENSIONS, LIGHTMAP_FILE_FORMAT, LIGHTMAP_FORMAT_VERSION, LIGHTMAP_MODES, LIGHT_BAKE_MODES, LIGHT_PROBE_ASSET_TYPE, LIGHT_PROBE_FILE_EXTENSIONS, LIGHT_PROBE_FILE_FORMAT, LIGHT_PROBE_FORMAT_VERSION, LIGHT_TYPES, LITE_MATERIAL_PLUGIN_POINTS, LITE_SYSTEM_UNIFORM_NAMES, LOG_LEVEL_SEVERITY, LayerMask, LayerTable, Light, LightProbeAsset, LightProbeVolume, LightmapAsset, LogLevel, MAT4_IDENTITY, MATERIAL_ALPHA_MODES, MATERIAL_ASSET_TYPE, MATERIAL_FILE_EXTENSION, MATERIAL_FILE_FORMAT, MATERIAL_FORMAT_VERSION, MATERIAL_KINDS, MATERIAL_PLUGIN_DEFAULT_PRIORITY, MATERIAL_PLUGIN_RESERVED_NAMES, MATERIAL_PLUGIN_SAMPLER_BUDGET, MAX_LAYERS, MAX_ULID_TIME_MS, MESH_ASSET_TYPE, MESH_FILE_EXTENSION, MESH_FILE_FORMAT, MESH_FORMAT_VERSION, MESH_PRIMITIVES, MESH_PRIMITIVE_OPTIONS, MODEL_ASSET_TYPE, MODEL_FILE_EXTENSIONS, Mat4, MaterialAsset, MemoryStorageBackend, MeshAsset, MeshRenderer, Model, ModelAsset, NAMESPACE_SEGMENT_MAX_LENGTH, PBR_TEXTURE_SLOTS, PHASES, PHASE_COUNT, PHASE_NAMES, POST_EFFECT_BUILTIN_UNIFORMS, POST_EFFECT_FUNCTION, PROJECTIONS, Phase, PhysicsCallbackName, PostProcessStack, QUAT_IDENTITY, Quat, RAD_TO_DEG, REFLECTION_PROBE_REFRESH_MODES, RENDERING_QUALITIES, RENDERING_SETTINGS_SECTION, RENDER_DIAGNOSTICS_COUNTERS, RENDER_DIAGNOSTICS_GROUP, RENDER_TEXTURE_MAX_SIZE, RESERVED_LAYER_NAMES, ReflectionProbe, SCENE_ASSET_TYPE, SCENE_FILE_EXTENSIONS, SCENE_FILE_FORMAT, SCENE_FORMAT_VERSION, SETTINGS_DESCRIPTION_FORMAT, SHADER_ASSET_TYPE, SHADER_ATTRIBUTE_NAMES, SHADER_BLEND_MODES, SHADER_CULL_MODES, SHADER_FILE_EXTENSIONS, SHADER_INSTANCING_MODES, SHADER_KINDS, SHADER_TEXTURE_FALLBACKS, SHADER_UNIFORM_TYPES, SHADOW_TECHNIQUES, STANDARD_TEXTURE_SLOTS, STORAGE_BUFFER_ASSET_TYPE, STORAGE_KEY_MAX_LENGTH, SURFACE_HOOK_NAMES, SURFACE_UNIFORM_BLOCK, SceneAssetToken, SceneInstance, SchemaIssueCode, Script, ScriptCallbackKind, ShaderAsset, Signal, StorageBufferAsset, TEXTURE_ASSET_TYPE, THIRD_PARTY_ERROR_PREFIX, TONE_MAPPING_NAMES, TWEEN_LOOP_FOREVER, TWEEN_SYSTEM_ORDER, TWEEN_VALUE_KINDS, TagSet, TextureAsset, Transform, Tween, UidRemap, VEC2_ONE, VEC2_ZERO, VEC3_BACKWARD, VEC3_DOWN, VEC3_FORWARD, VEC3_LEFT, VEC3_ONE, VEC3_RIGHT, VEC3_UP, VEC3_ZERO, VERSION, Vec2, Vec3, Vec4, World, addComponentFromRecord, applyInit, applyOverridesToAsset, approximately, array, assertNever, assertSceneDependenciesLoaded, asset, assetRef, bakeLightProbes, binaryAssetLoader, bool, canonicalizeNumber, clamp, clamp01, color, componentRef, computeSceneHash, coreExtension, createApp, createAssetManifest, createConsoleSink, createCryptoRandom, createDefaults, createDiagnosticsGroup, createEnvironmentLoader, createErrorCodeRegistry, createFileStorageBackend, createFontLoader, createFrameSample, createLayerTable, createLightProbeAsset, createLightProbeLoader, createLightmapAsset, createLightmapLoader, createLogger, createManualClock, createMaterialAsset, createMaterialLoader, createMemorySink, createMeshLoader, createModelLoader, createPerformanceClock, createRay, createSceneAsset, createSceneLoader, createSeededRandom, createServiceKey, createShaderLoader, createStorageBufferAsset, createTextureLoader, createUlidFactory, curve, custom, customEffect, decodeProps, decodeValue, defaultAutoExposureSettings, defaultRenderingSettings, defineExtension, defineMaterialPlugin, defineSchema, degToRad, deltaAngleDegrees, describeEnvironmentFileFormat, describeLightProbeFileFormat, describeLightmapFileFormat, describeMaterialFileFormat, describeMeshFileFormat, describeRegisteredSchemas, describeSceneFileFormat, describeSchema, describeSchemas, describeSettings, encodeProps, encodeValue, entityRef, enumOf, enumerateInstanceTargets, environmentDefinition, f32, f64, forceRendererDeviceLossForTesting, formatErrorMessage, generateUlid, i32, instanceComponentAt, instanceEntityAt, instantiateScene, inverseLerp, isAssetRef, isIgnifxError, isLiteMaterialPluginPoint, isSceneFileHeader, isUlid, isValidErrorCode, isWebGpuAvailable, jsonAssetLoader, layerMask, lerp, lerpAngleDegrees, lightBakeTerms, loadSceneDependencies, map, meshFileJsonSchema, moveTowards, optional, parseOverridePath, pbrMaterialDefinition, pingPong, platformInternals, quat, radToDeg, record, repeat, resetFrameSample, resolveEase, resolveInstancePath, revertOverrides, sampleLightProbes, sceneFileJsonSchema, serializeComponent, serializeEntity, serializeScene, settingsJsonSchema, shaderMaterialDefinition, sign, smoothStep, standardMaterialDefinition, storageInternals, str, stringifySceneFile, textAssetLoader, toJsonSchema, transformSchema, u32, validateProps, validateSceneFile, validateValue, vec2, vec3, vec4, waitFixedUpdate, waitSeconds, waitSecondsRealtime, waitUntil, waitWhile, wrapAngleDegrees, writeLightProbeFile, writeLightmapFile };
|
|
35550
37484
|
|
|
35551
37485
|
//# sourceMappingURL=index.js.map
|