@babylonjs/lite-compat 1.39.1 → 1.39.3

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.
@@ -1,4 +1,4 @@
1
- import { addToScene, adoptMeshMorphTargets, cloneTransformNode, computeAabb, createBox, createCylinder, createDashedLines, createDisc, createExtrudeShape, createGround, createGroundFromHeightMap, createLineMaterial, createLineSystem, createMeshFromData, createMorphTargets, createPbrMaterial, createPlane, createPolyhedron, createQuatFromRotationMat4, createRibbon, createSolidTexture2D, createSphere, createStandardMaterial, createTorus, createTorusKnot, createTransformNode, createTube, getMaterialFamily, getMeshOpacity, markMaterialUboDirty, maximizeMat4InPlace, normalizeVec2ToRef, projectPointToViewportToRef, rebuildMaterial, releaseMorphTargets, removeFromScene, resizeMeshGeometry, retainMorphTargets, scaleBoundsFromCenterToRef, setAccessibilityTag, setLineMaterialColor, setMat4Translation, setMeshOpacity, setMeshVisible, setMorphTargetWeight, setMorphTargetWeights, setParent, setPbrAnisotropy, setPbrClearCoat, setPbrEmissive, setPbrGammaAlbedo, setPbrIridescence, setPbrSheen, setStandardBumpTexture, setStandardEmissiveTexture, setThinInstanceColors, setThinInstances, shareMeshMorphTargets, updateDashedLines, updateLineSystem, updateMeshGeometry, updateMeshUvs, writeMat4FromLookDirectionLHIntoBuffer, writeMat4FromLookDirectionRHIntoBuffer, writeMat4FromQuatIntoBuffer, writeQuatFromRotationMat4IntoRef } from "@babylonjs/lite";
1
+ import { addToScene, adoptMeshMorphTargets, cloneTransformNode, computeAabb, createBox, createCylinder, createDashedLines, createDisc, createExtrudeShape, createGround, createGroundFromHeightMap, createLineMaterial, createLineSystem, createMeshFromData, createMorphTargets, createPbrMaterial, createPlane, createPolyhedron, createQuatFromRotationMat4, createRibbon, createSolidTexture2D, createSphere, createStandardMaterial, createTorus, createTorusKnot, createTransformNode, createTube, enableBentNormals, getMaterialFamily, getMeshOpacity, markMaterialUboDirty, maximizeMat4InPlace, normalizeVec2ToRef, projectPointToViewportToRef, rebuildMaterial, releaseMorphTargets, removeFromScene, resizeMeshGeometry, retainMorphTargets, scaleBoundsFromCenterToRef, setAccessibilityTag, setLineMaterialColor, setMat4Translation, setMeshOpacity, setMeshVisible, setMorphTargetWeight, setMorphTargetWeights, setParent, setPbrAnisotropy, setPbrClearCoat, setPbrEmissive, setPbrGammaAlbedo, setPbrIridescence, setPbrSheen, setStandardBumpTexture, setStandardEmissiveTexture, setThinInstanceColors, setThinInstances, shareMeshMorphTargets, updateDashedLines, updateLineSystem, updateMeshGeometry, updateMeshUvs, writeMat4FromLookDirectionLHIntoBuffer, writeMat4FromLookDirectionRHIntoBuffer, writeMat4FromQuatIntoBuffer, writeQuatFromRotationMat4IntoRef } from "@babylonjs/lite";
2
2
  // src/error.ts
3
3
  /**
4
4
  * Error thrown when Babylon.js code reaches an API surface that the Babylon Lite
@@ -1825,6 +1825,10 @@ var Material = class {
1825
1825
  target.wireframe = this.wireframe;
1826
1826
  target.backFaceCulling = this._backFaceCulling;
1827
1827
  }
1828
+ /** @internal Initialize facade culling state for a loaded material without mutating its Lite source. */
1829
+ _initializeBackFaceCulling(value) {
1830
+ this._backFaceCulling = value;
1831
+ }
1828
1832
  /** The scene this material was constructed against (Babylon.js `Material.getScene`). */
1829
1833
  getScene() {
1830
1834
  return this._scene;
@@ -1914,7 +1918,7 @@ function copyLiteMaterialData(src, dst) {
1914
1918
  const s = src;
1915
1919
  const d = dst;
1916
1920
  for (const key of Object.keys(s)) {
1917
- if (key.startsWith("_")) continue;
1921
+ if (key === "_buildGroup" || key === "_uboVersion" || key === "_renderFeatures" || key === "_pi" || key === "_preparedPlugins" || key === "_csmGen" || key === "_uvTxExt") continue;
1918
1922
  const value = s[key];
1919
1923
  d[key] = Array.isArray(value) ? value.slice() : value;
1920
1924
  }
@@ -1948,6 +1952,16 @@ var StandardMaterial = class StandardMaterial extends PushMaterial {
1948
1952
  super(name, scene);
1949
1953
  this._lite = createStandardMaterial();
1950
1954
  }
1955
+ /** @internal Wrap a loader-produced Lite Standard material without replacing its GPU state. */
1956
+ static _fromLite(name, lite, scene) {
1957
+ const material = new StandardMaterial(name);
1958
+ material._lite = lite;
1959
+ material._diffuse = [...lite.diffuseColor];
1960
+ material._initializeBackFaceCulling(lite.backFaceCulling);
1961
+ material._scene = scene;
1962
+ scene._registerMaterial(material);
1963
+ return material;
1964
+ }
1951
1965
  /**
1952
1966
  * Babylon.js shades an unlit StandardMaterial as `emissive + ambient`: the diffuse colour only scales
1953
1967
  * the accumulated light, and there is none. Lite's unlit path is `emissive × diffuse`, so the usual
@@ -2133,6 +2147,9 @@ var StandardMaterial = class StandardMaterial extends PushMaterial {
2133
2147
  cloned._diffuseTexture = this._diffuseTexture;
2134
2148
  cloned._bumpTexture = this._bumpTexture;
2135
2149
  cloned._emissiveTexture = this._emissiveTexture;
2150
+ cloned._watchTexture(cloned._diffuseTexture);
2151
+ cloned._watchTexture(cloned._bumpTexture);
2152
+ cloned._watchTexture(cloned._emissiveTexture);
2136
2153
  return cloned;
2137
2154
  }
2138
2155
  };
@@ -2180,9 +2197,11 @@ var PBRClearCoatConfiguration = class {
2180
2197
  var PBRSheenConfiguration = class {
2181
2198
  _props;
2182
2199
  _markDirty;
2183
- constructor(_props, _markDirty) {
2200
+ _watchTexture;
2201
+ constructor(_props, _markDirty, _watchTexture) {
2184
2202
  this._props = _props;
2185
2203
  this._markDirty = _markDirty;
2204
+ this._watchTexture = _watchTexture;
2186
2205
  }
2187
2206
  get isEnabled() {
2188
2207
  return this._props.isEnabled;
@@ -2226,16 +2245,29 @@ var PBRSheenConfiguration = class {
2226
2245
  return this._texture;
2227
2246
  }
2228
2247
  set texture(value) {
2248
+ this._textureAssigned = true;
2229
2249
  this._texture = value;
2230
2250
  if (value?._lite) this._props.texture = value._lite;
2231
2251
  else delete this._props.texture;
2252
+ this._watchTexture(value);
2232
2253
  this._markDirty();
2233
2254
  }
2234
2255
  _texture = null;
2256
+ _textureAssigned = false;
2235
2257
  /** Enumerate the sheen texture slot for `Material.getActiveTextures`. */
2236
2258
  getActiveTextures() {
2237
2259
  return this._texture ? [this._texture] : [];
2238
2260
  }
2261
+ /** @internal Rebind a replaced or newly-ready texture handle. */
2262
+ _ensureRenderable() {
2263
+ if (!this._textureAssigned) return;
2264
+ if (this._texture?._lite) this._props.texture = this._texture._lite;
2265
+ else delete this._props.texture;
2266
+ }
2267
+ /** @internal Copy an explicit facade texture assignment without disturbing loader-owned state. */
2268
+ _copyTextureTo(target) {
2269
+ if (this._textureAssigned) target.texture = this._texture;
2270
+ }
2239
2271
  };
2240
2272
  /** Babylon.js `PBRAnisotropicConfiguration` — the `pbr.anisotropy` sub-object over Lite `AnisotropyProps`. */
2241
2273
  var PBRAnisotropicConfiguration = class {
@@ -2337,6 +2369,27 @@ var PBRMaterial = class PBRMaterial extends PushMaterial {
2337
2369
  getClassName() {
2338
2370
  return "PBRMaterial";
2339
2371
  }
2372
+ /** @internal Wrap a loader-produced Lite PBR material without replacing its GPU state. */
2373
+ static _fromLite(name, lite, scene) {
2374
+ const material = new PBRMaterial(name);
2375
+ material._lite = lite;
2376
+ const factor = lite.baseColorFactor ?? [
2377
+ 1,
2378
+ 1,
2379
+ 1,
2380
+ 1
2381
+ ];
2382
+ material._albedoFactor = [
2383
+ factor[0],
2384
+ factor[1],
2385
+ factor[2],
2386
+ factor[3]
2387
+ ];
2388
+ material._initializeBackFaceCulling(!lite.doubleSided);
2389
+ material._scene = scene;
2390
+ scene._registerMaterial(material);
2391
+ return material;
2392
+ }
2340
2393
  get albedoColor() {
2341
2394
  return new Color3(this._albedoFactor[0], this._albedoFactor[1], this._albedoFactor[2]);
2342
2395
  }
@@ -2364,6 +2417,32 @@ var PBRMaterial = class PBRMaterial extends PushMaterial {
2364
2417
  this._markDirty();
2365
2418
  }
2366
2419
  _albedoTexture = null;
2420
+ _bentNormalTexture = null;
2421
+ _bentNormalLevelUnsubscribe;
2422
+ /** Babylon.js `PBRMaterial.bentNormalTexture` over Lite's native IBL occlusion extension. */
2423
+ get bentNormalTexture() {
2424
+ return this._bentNormalTexture;
2425
+ }
2426
+ set bentNormalTexture(texture) {
2427
+ const featureWasEnabled = !!this._lite.bentNormalTexture;
2428
+ this._bentNormalLevelUnsubscribe?.();
2429
+ this._bentNormalLevelUnsubscribe = void 0;
2430
+ this._bentNormalTexture = texture;
2431
+ if (texture) {
2432
+ enableBentNormals();
2433
+ this._bentNormalLevelUnsubscribe = texture._onLevelChanged?.((level) => {
2434
+ if (this._bentNormalTexture === texture) {
2435
+ this._lite.bentNormalStrength = level;
2436
+ this._markDirty();
2437
+ }
2438
+ });
2439
+ }
2440
+ this._lite.bentNormalTexture = texture?._lite ?? void 0;
2441
+ this._lite.bentNormalStrength = texture?.level ?? 1;
2442
+ this._watchTexture(texture);
2443
+ this._markDirty();
2444
+ if (featureWasEnabled && !this._lite.bentNormalTexture) this._refreshInScene();
2445
+ }
2367
2446
  /**
2368
2447
  * Enumerate every bound PBR texture slot, including extension sub-configurations
2369
2448
  * (Babylon.js `PBRMaterial.getActiveTextures`).
@@ -2371,6 +2450,7 @@ var PBRMaterial = class PBRMaterial extends PushMaterial {
2371
2450
  getActiveTextures() {
2372
2451
  const textures = [];
2373
2452
  if (this._albedoTexture) textures.push(this._albedoTexture);
2453
+ if (this._bentNormalTexture) textures.push(this._bentNormalTexture);
2374
2454
  const environmentTexture = this.environmentTexture;
2375
2455
  if (environmentTexture) textures.push(environmentTexture);
2376
2456
  if (this._sheen) textures.push(...this._sheen.getActiveTextures());
@@ -2445,7 +2525,7 @@ var PBRMaterial = class PBRMaterial extends PushMaterial {
2445
2525
  get sheen() {
2446
2526
  if (!this._sheen) {
2447
2527
  setPbrSheen(this._lite, this._lite._sheen ?? { isEnabled: false });
2448
- this._sheen = new PBRSheenConfiguration(this._lite._sheen, () => this._markDirty());
2528
+ this._sheen = new PBRSheenConfiguration(this._lite._sheen, () => this._markDirty(), (texture) => this._watchTexture(texture));
2449
2529
  }
2450
2530
  return this._sheen;
2451
2531
  }
@@ -2498,6 +2578,13 @@ var PBRMaterial = class PBRMaterial extends PushMaterial {
2498
2578
  if (albedo.gammaSpace ?? true) setPbrGammaAlbedo(lite);
2499
2579
  else lite._gammaAlbedo = false;
2500
2580
  }
2581
+ const bent = this._bentNormalTexture;
2582
+ if (bent?._lite) {
2583
+ enableBentNormals();
2584
+ lite.bentNormalTexture = bent._lite;
2585
+ lite.bentNormalStrength = bent.level ?? 1;
2586
+ }
2587
+ this._sheen?._ensureRenderable();
2501
2588
  if (!lite.baseColorTexture) {
2502
2589
  lite.baseColorTexture = createSolidTexture2D(engine, 1, 1, 1, 1);
2503
2590
  lite.baseColorFactor = [...this._albedoFactor];
@@ -2527,13 +2614,28 @@ var PBRMaterial = class PBRMaterial extends PushMaterial {
2527
2614
  target.forceIrradianceInFragment = this.forceIrradianceInFragment;
2528
2615
  target._albedoFactor = [...this._albedoFactor];
2529
2616
  target._albedoTexture = this._albedoTexture;
2617
+ target._watchTexture(target._albedoTexture);
2618
+ target.bentNormalTexture = this._bentNormalTexture;
2530
2619
  const src = this._lite;
2531
2620
  const dst = target._lite;
2532
2621
  if (src._emissiveColor) setPbrEmissive(dst, [...src._emissiveColor]);
2533
2622
  if (src._clearCoat) setPbrClearCoat(dst, { ...src._clearCoat });
2534
- if (src._sheen) setPbrSheen(dst, { ...src._sheen });
2623
+ if (src._sheen) {
2624
+ setPbrSheen(dst, { ...src._sheen });
2625
+ if (this._sheen) this._sheen._copyTextureTo(target.sheen);
2626
+ }
2535
2627
  if (src._anisotropy) setPbrAnisotropy(dst, { ...src._anisotropy });
2536
2628
  if (src._iridescence) setPbrIridescence(dst, { ...src._iridescence });
2629
+ if (src.bentNormalTexture) {
2630
+ enableBentNormals();
2631
+ dst.bentNormalTexture = src.bentNormalTexture;
2632
+ dst.bentNormalStrength = src.bentNormalStrength;
2633
+ }
2634
+ }
2635
+ dispose() {
2636
+ this._bentNormalLevelUnsubscribe?.();
2637
+ this._bentNormalLevelUnsubscribe = void 0;
2638
+ super.dispose();
2537
2639
  }
2538
2640
  };
2539
2641
  /**
@@ -3103,6 +3205,7 @@ var TransformNode = class TransformNode extends Node {
3103
3205
  _nativeRotationValues;
3104
3206
  _isSyncingRotationFromNative = false;
3105
3207
  _sceneDisposeObserver;
3208
+ _loadedSceneRegistered = false;
3106
3209
  /**
3107
3210
  * @internal The Lite asset container this node was loaded from, when produced
3108
3211
  * by a loader. Used by the `KHR_materials_variants` helpers (which key off the
@@ -3110,16 +3213,27 @@ var TransformNode = class TransformNode extends Node {
3110
3213
  */
3111
3214
  _container;
3112
3215
  /**
3113
- * @internal Bind a loader-produced wrapper to the scene the container was added
3114
- * to. The loader already inserted the underlying Lite node (via
3115
- * `addToScene(container)`), so this only wires the compat-side scene reference
3116
- * and lists the wrapper in `scene.meshes` — it never re-inserts into Lite.
3216
+ * @internal Bind a loader-produced wrapper to its owning scene. Detached
3217
+ * containers retain scene-aware material adaptation without registry membership;
3218
+ * adoption later lists the wrapper in `scene.meshes`. The underlying Lite node is
3219
+ * never re-inserted here.
3117
3220
  */
3118
- _bindLoadedScene(scene) {
3119
- if (this._scene === scene) return;
3120
- this._scene = scene;
3121
- scene._registerMesh(this, this._node);
3122
- this._bindRotationSceneDisposal(scene);
3221
+ _bindLoadedScene(scene, register = true) {
3222
+ if (this._scene !== scene) {
3223
+ if (this._sceneDisposeObserver) {
3224
+ this._scene?.onDisposeObservable?.remove(this._sceneDisposeObserver);
3225
+ this._sceneDisposeObserver = void 0;
3226
+ }
3227
+ this._scene = scene;
3228
+ this._loadedSceneRegistered = false;
3229
+ this._bindRotationSceneDisposal(scene);
3230
+ }
3231
+ if (register && !this._loadedSceneRegistered) {
3232
+ scene._registerMesh(this, this._node);
3233
+ this._loadedSceneRegistered = true;
3234
+ return true;
3235
+ }
3236
+ return false;
3123
3237
  }
3124
3238
  /** @internal Link an already-parented Lite node without mutating its Lite hierarchy. */
3125
3239
  _adoptLoadedParent(parent) {
@@ -3325,6 +3439,8 @@ var AbstractMesh = class extends TransformNode {
3325
3439
  /** @internal Underlying Babylon Lite mesh. */
3326
3440
  _lite;
3327
3441
  _material = null;
3442
+ /** @internal Lite material identity currently represented by `_material`. */
3443
+ _wrappedLiteMaterial;
3328
3444
  /**
3329
3445
  * @internal The mesh renders a material that exists only on its Lite node: a natively loaded glTF
3330
3446
  * material has no compat wrapper, so `material` reads `null`. Clones keep that Lite material, and the
@@ -3360,6 +3476,16 @@ var AbstractMesh = class extends TransformNode {
3360
3476
  for (const light of this._scene?.lights ?? []) light._pruneDisposedMesh(this);
3361
3477
  }
3362
3478
  get material() {
3479
+ const liteMaterial = this._lite.material;
3480
+ if (this._scene && liteMaterial && (this._liteOnlyMaterial || !!this._wrappedLiteMaterial && liteMaterial !== this._wrappedLiteMaterial)) {
3481
+ if (this._material?._lite === liteMaterial) this._liteOnlyMaterial = false;
3482
+ else {
3483
+ const loaded = this._scene._wrapLoadedMaterial(liteMaterial);
3484
+ this._material = loaded;
3485
+ this._liteOnlyMaterial = !loaded;
3486
+ }
3487
+ this._wrappedLiteMaterial = liteMaterial;
3488
+ }
3363
3489
  return this._material;
3364
3490
  }
3365
3491
  set material(value) {
@@ -3367,6 +3493,7 @@ var AbstractMesh = class extends TransformNode {
3367
3493
  const renderMaterial = value ?? scene?.defaultMaterial;
3368
3494
  if (renderMaterial && (this._visibilityValue < 1 || this._opacityTargets().some((target) => getMeshOpacity(target) < 1))) this._validateCompatOpacityMaterial("Mesh.material", renderMaterial);
3369
3495
  this._material = value;
3496
+ this._wrappedLiteMaterial = renderMaterial?._lite;
3370
3497
  this._liteOnlyMaterial = false;
3371
3498
  if (renderMaterial && scene) {
3372
3499
  if (scene._hasStarted) attachMaterialToScene(renderMaterial, scene);
@@ -3686,31 +3813,32 @@ var Mesh = class Mesh extends AbstractMesh {
3686
3813
  * adopts the existing Lite node. Used by the loader to give
3687
3814
  * `AssetContainer.meshes` real, stable-identity mesh handles.
3688
3815
  */
3689
- static _fromLite(lite, container, scene) {
3816
+ static _fromLite(lite, container, scene, register = true) {
3690
3817
  const mesh = new Mesh(lite.name ?? "", lite);
3691
3818
  mesh._container = container;
3692
3819
  mesh._liteOnlyMaterial = !!lite.material;
3693
3820
  mesh._visible = lite.visible !== false;
3694
- if (scene) mesh._bindLoadedScene(scene);
3821
+ if (scene) mesh._bindLoadedScene(scene, register);
3695
3822
  return mesh;
3696
3823
  }
3697
3824
  /** @internal Bind a loaded mesh and its discovered morph manager to the owning scene. */
3698
- _bindLoadedScene(scene) {
3699
- super._bindLoadedScene(scene);
3825
+ _bindLoadedScene(scene, register = true) {
3826
+ if (!super._bindLoadedScene(scene, register)) return false;
3700
3827
  for (const manager of this._ownedMorphTargetManagers) scene._retainMorphTargetManagerOwnership(manager);
3701
3828
  if (this._morphTargetManager?._lite) this._morphTargetManager._adoptEngine(scene._getLiteEngine());
3702
3829
  else if (this._morphTargetManager) scene._registerMorphTargetManager(this, this._morphTargetManager);
3830
+ return true;
3703
3831
  }
3704
3832
  /** @internal Wrap and link a complete Lite hierarchy, registering every wrapper. */
3705
- static _fromLiteHierarchy(lite, container, scene, registry = /* @__PURE__ */ new Map(), parent = null) {
3833
+ static _fromLiteHierarchy(lite, container, scene, registry = /* @__PURE__ */ new Map(), parent = null, register = true) {
3706
3834
  let wrapper = registry.get(lite);
3707
3835
  if (!wrapper) {
3708
- wrapper = Mesh._fromLite(lite, container, scene);
3836
+ wrapper = Mesh._fromLite(lite, container, scene, register);
3709
3837
  registry.set(lite, wrapper);
3710
- } else if (scene) wrapper._bindLoadedScene(scene);
3838
+ } else if (scene) wrapper._bindLoadedScene(scene, register);
3711
3839
  wrapper._adoptLoadedParent(parent);
3712
3840
  const children = lite.children;
3713
- if (children) for (const child of children) Mesh._fromLiteHierarchy(child, container, scene, registry, wrapper);
3841
+ if (children) for (const child of children) Mesh._fromLiteHierarchy(child, container, scene, registry, wrapper, register);
3714
3842
  return wrapper;
3715
3843
  }
3716
3844
  _morphTargetManager = null;
@@ -4371,4 +4499,4 @@ var PolygonBuilder = {
4371
4499
  function RegisterPolygonBuilder() {}
4372
4500
  export { Vector2 as $, Material as A, attachMaterialToScene as B, RegisterPolygonBuilder as C, registerMeshAtStart as D, VertexData as E, PBRMetallicRoughnessMaterial as F, BoundingSphere as G, Observable as H, PBRSheenConfiguration as I, transformNormal as J, Matrix as K, PBRSpecularGlossinessMaterial as L, PBRClearCoatConfiguration as M, PBRIridescenceConfiguration as N, MorphTarget as O, PBRMaterial as P, liteBackedColor3 as Q, PushMaterial as R, PolygonBuilder as S, VertexBuffer as T, BoundingBox as U, Node as V, BoundingInfo as W, Color3 as X, Quaternion as Y, Color4 as Z, GroundMesh as _, CreateDisc as a, Mesh as b, CreateLines as c, CreatePolygonVertexData as d, Vector3 as et, CreateSphere as f, ExtrudePolygon as g, CreateTorus as h, CreateDashedLines as i, unsupported as it, PBRAnisotropicConfiguration as j, MorphTargetManager as k, CreatePlane as l, CreateTiledPlane as m, CreateBox as n, liteBackedVector3 as nt, CreateGround as o, CreateTiledBox as p, transformCoordinates as q, CreateCylinder as r, LiteCompatError as rt, CreateLineSystem as s, AbstractMesh as t, Vector4 as tt, CreatePolygon as u, InstancedMesh as v, TransformNode as w, MeshBuilder as x, LinesMesh as y, StandardMaterial as z };
4373
4501
 
4374
- //# sourceMappingURL=meshes-C-PkzbPM.js.map
4502
+ //# sourceMappingURL=meshes-FwqJpX7D.js.map