@playcanvas/web-components 0.11.1 → 0.12.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/pwc.cjs CHANGED
@@ -29,12 +29,13 @@ class AsyncElement extends HTMLElement {
29
29
  return this.parentElement?.closest('pc-app') ?? null;
30
30
  }
31
31
  /**
32
- * The nearest ancestor `<pc-entity>` element, or `null` if this element has no `<pc-entity>`
33
- * ancestor. The search starts at the parent, so an element never resolves to itself.
34
- * @returns The closest entity element, or `null`.
32
+ * The nearest ancestor element that fronts an entity `<pc-entity>` or `<pc-node>` — or
33
+ * `null` if this element has no such ancestor. The search starts at the parent, so an element
34
+ * never resolves to itself.
35
+ * @returns The closest entity-fronting element, or `null`.
35
36
  */
36
37
  get closestEntity() {
37
- return this.parentElement?.closest('pc-entity') ?? null;
38
+ return this.parentElement?.closest('pc-entity, pc-node') ?? null;
38
39
  }
39
40
  /**
40
41
  * Called when the element is fully initialized and ready. Subclasses should call this when
@@ -744,8 +745,9 @@ class AppElement extends AsyncElement {
744
745
  _bootGeneration = 0;
745
746
  /**
746
747
  * The elements backing this application's entities, keyed by the entity itself. Registered
747
- * by EntityElement at creation and removed when an entity is destroyed, this joins engine
748
- * scene nodes back to their owning elements by identity - never by name.
748
+ * by EntityElement at creation (and NodeElement at binding) and removed when an entity is
749
+ * destroyed or unbound, this joins engine scene nodes back to their owning elements by
750
+ * identity - never by name.
749
751
  */
750
752
  _entityElements = new Map();
751
753
  _picker = null;
@@ -1050,7 +1052,7 @@ class AppElement extends AsyncElement {
1050
1052
  // created from onpointer* attributes when their elements were first upgraded, or
1051
1053
  // listeners carried over from before a re-boot)
1052
1054
  pointerEventTypes.forEach((type) => {
1053
- const anyListeners = Array.from(this.querySelectorAll('pc-entity')).some((entity) => entity._hasListeners(type));
1055
+ const anyListeners = Array.from(this.querySelectorAll('pc-entity, pc-node')).some((entity) => entity._hasListeners(type));
1054
1056
  if (anyListeners) {
1055
1057
  this._onPointerListenerAdded(type);
1056
1058
  }
@@ -1080,11 +1082,11 @@ class AppElement extends AsyncElement {
1080
1082
  };
1081
1083
  }
1082
1084
  /**
1083
- * Registers the element that created an entity. Called by EntityElement when it creates its
1084
- * entity.
1085
+ * Registers the element that fronts an entity. Called by EntityElement when it creates its
1086
+ * entity, and by NodeElement when it binds one.
1085
1087
  *
1086
1088
  * @param entity - The entity.
1087
- * @param element - The element that created it.
1089
+ * @param element - The element that fronts it.
1088
1090
  * @internal
1089
1091
  */
1090
1092
  _registerEntityElement(entity, element) {
@@ -1100,21 +1102,22 @@ class AppElement extends AsyncElement {
1100
1102
  this._entityElements.delete(entity);
1101
1103
  }
1102
1104
  /**
1103
- * Returns the `<pc-entity>` element whose backing entity is `entity`, or `null` if the
1104
- * entity was not created by an element of this application - for example, a node inside a
1105
- * model's instantiated hierarchy, or an entity created through the engine API.
1105
+ * Returns the `<pc-entity>` or `<pc-node>` element whose backing entity is `entity`, or
1106
+ * `null` if the entity is not fronted by an element of this application - for example, an
1107
+ * unbound node inside a model's instantiated hierarchy, or an entity created through the
1108
+ * engine API.
1106
1109
  *
1107
1110
  * @param entity - The entity to look up.
1108
- * @returns The element backing the entity, or `null`.
1111
+ * @returns The element fronting the entity, or `null`.
1109
1112
  */
1110
1113
  elementFromEntity(entity) {
1111
1114
  return this._entityElements.get(entity) ?? null;
1112
1115
  }
1113
1116
  /**
1114
1117
  * Resolves the element that owns a picked node: the nearest node up the parent chain -
1115
- * starting with the node itself - that was created by a `<pc-entity>` of this application.
1116
- * A hit inside a model's instantiated hierarchy therefore resolves to the element hosting
1117
- * the model.
1118
+ * starting with the node itself - that is fronted by a `<pc-entity>` or `<pc-node>` of this
1119
+ * application. A hit inside a model's instantiated hierarchy therefore resolves to the
1120
+ * nearest bound `<pc-node>`, or failing that the element hosting the model.
1118
1121
  *
1119
1122
  * @param node - The picked node, or `null`.
1120
1123
  * @returns The owning element, or `null`.
@@ -1246,7 +1249,7 @@ class AppElement extends AsyncElement {
1246
1249
  }
1247
1250
  }
1248
1251
  _onPointerListenerRemoved(type) {
1249
- const hasListeners = Array.from(this.querySelectorAll('pc-entity')).some((entity) => entity._hasListeners(type));
1252
+ const hasListeners = Array.from(this.querySelectorAll('pc-entity, pc-node')).some((entity) => entity._hasListeners(type));
1250
1253
  if (!hasListeners && this._canvas) {
1251
1254
  this._hasPointerListeners[type] = false;
1252
1255
  const handler = type === 'pointerenter' || type === 'pointerleave'
@@ -1424,6 +1427,125 @@ class AppElement extends AsyncElement {
1424
1427
  }
1425
1428
  customElements.define('pc-app', AppElement);
1426
1429
 
1430
+ /**
1431
+ * The attribute names of the inline `onpointer*` event handlers, shared by every element that
1432
+ * fronts an engine entity. Spread into `observedAttributes` by subclasses.
1433
+ * @ignore
1434
+ */
1435
+ const POINTER_ATTRIBUTES = [
1436
+ 'onpointerenter',
1437
+ 'onpointerleave',
1438
+ 'onpointerdown',
1439
+ 'onpointerup',
1440
+ 'onpointermove'
1441
+ ];
1442
+ /**
1443
+ * The base class for elements that front an engine {@link Entity}: `<pc-entity>`, which creates
1444
+ * one, and `<pc-node>`, which binds to one inside a model's instantiated hierarchy. It carries
1445
+ * what both need — the `entity` contract, registration with the owning application (which joins
1446
+ * picked scene nodes back to elements by identity, never by name), and the pointer listener
1447
+ * bookkeeping that lets the application lazily attach its canvas handlers.
1448
+ */
1449
+ class EntityBaseElement extends AsyncElement {
1450
+ _entity = null;
1451
+ /**
1452
+ * The application element this entity is registered with, cached at registration time so the
1453
+ * entity can be unregistered even once this element has left the DOM.
1454
+ */
1455
+ _appElement = null;
1456
+ /**
1457
+ * The pointer event listeners for the entity.
1458
+ */
1459
+ _listeners = {};
1460
+ /**
1461
+ * The event types for which an inline `onpointer*` attribute is currently present.
1462
+ */
1463
+ _inlineHandlerTypes = new Set();
1464
+ /**
1465
+ * The PlayCanvas entity instance. `null` until the element is ready, and again once the
1466
+ * entity is gone — await {@link whenReady} or the element's `ready()` promise before
1467
+ * accessing it.
1468
+ * @returns The entity instance, or `null`.
1469
+ */
1470
+ get entity() {
1471
+ return this._entity;
1472
+ }
1473
+ /**
1474
+ * Registers `entity` as this element's backing entity with the owning application, which
1475
+ * joins engine nodes back to elements by identity (never by name).
1476
+ *
1477
+ * @param entity - The entity to register.
1478
+ */
1479
+ _registerEntity(entity) {
1480
+ this._appElement = this.closestApp;
1481
+ this._appElement?._registerEntityElement(entity, this);
1482
+ }
1483
+ /**
1484
+ * Removes the registration for `entity`.
1485
+ *
1486
+ * @param entity - The entity to unregister.
1487
+ */
1488
+ _unregisterEntity(entity) {
1489
+ this._appElement?._unregisterEntityElement(entity);
1490
+ this._appElement = null;
1491
+ }
1492
+ /**
1493
+ * Tracks whether an inline `onpointer*` attribute is present. The browser itself compiles and
1494
+ * runs these attributes — they are standard `GlobalEventHandlers`, so setting one replaces
1495
+ * the previous handler and removing it removes the handler, exactly like `onclick` on any
1496
+ * HTML element. But because they bypass {@link addEventListener}, the connect/disconnect
1497
+ * bookkeeping that lets the application lazily attach its canvas pointer handlers must be
1498
+ * kept in sync here.
1499
+ *
1500
+ * @param name - The attribute name (e.g. 'onpointerdown').
1501
+ * @param value - The attribute value, or `null` when the attribute has been removed.
1502
+ */
1503
+ _updateInlineHandler(name, value) {
1504
+ const type = name.substring(2);
1505
+ const had = this._inlineHandlerTypes.has(type);
1506
+ const has = value !== null;
1507
+ if (has && !had) {
1508
+ this._inlineHandlerTypes.add(type);
1509
+ this.dispatchEvent(new CustomEvent(`${type}:connect`, { bubbles: true }));
1510
+ }
1511
+ else if (!has && had) {
1512
+ this._inlineHandlerTypes.delete(type);
1513
+ this.dispatchEvent(new CustomEvent(`${type}:disconnect`, { bubbles: true }));
1514
+ }
1515
+ }
1516
+ addEventListener(type, listener, options) {
1517
+ if (!this._listeners[type]) {
1518
+ this._listeners[type] = [];
1519
+ }
1520
+ this._listeners[type].push(listener);
1521
+ super.addEventListener(type, listener, options);
1522
+ if (type.startsWith('pointer')) {
1523
+ this.dispatchEvent(new CustomEvent(`${type}:connect`, { bubbles: true }));
1524
+ }
1525
+ }
1526
+ removeEventListener(type, listener, options) {
1527
+ if (this._listeners[type]) {
1528
+ this._listeners[type] = this._listeners[type].filter((l) => l !== listener);
1529
+ }
1530
+ super.removeEventListener(type, listener, options);
1531
+ if (type.startsWith('pointer')) {
1532
+ this.dispatchEvent(new CustomEvent(`${type}:disconnect`, { bubbles: true }));
1533
+ }
1534
+ }
1535
+ /**
1536
+ * Whether the element has a listener for an event type, registered either with
1537
+ * {@link addEventListener} or with the matching inline `onpointer*` attribute. Read by the
1538
+ * containing `<pc-app>` element to gate pointer event synthesis.
1539
+ *
1540
+ * @param type - The event type.
1541
+ * @returns Whether a listener is registered.
1542
+ * @internal
1543
+ */
1544
+ _hasListeners(type) {
1545
+ return Boolean(this._listeners[type]?.length) || this._inlineHandlerTypes.has(type);
1546
+ }
1547
+ }
1548
+
1427
1549
  /**
1428
1550
  * The EntityElement interface provides properties and methods for manipulating
1429
1551
  * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-entity/ | `<pc-entity>`} elements.
@@ -1448,7 +1570,7 @@ customElements.define('pc-app', AppElement);
1448
1570
  * @fires {PointerEvent} pointerdown - Fired when a pointer button is pressed over the entity.
1449
1571
  * @fires {PointerEvent} pointerup - Fired when a pointer button is released over the entity.
1450
1572
  */
1451
- class EntityElement extends AsyncElement {
1573
+ class EntityElement extends EntityBaseElement {
1452
1574
  /**
1453
1575
  * Whether the entity is enabled.
1454
1576
  */
@@ -1473,33 +1595,10 @@ class EntityElement extends AsyncElement {
1473
1595
  * The tags of the entity.
1474
1596
  */
1475
1597
  _tags = [];
1476
- /**
1477
- * The pointer event listeners for the entity.
1478
- */
1479
- _listeners = {};
1480
- /**
1481
- * The event types for which an inline `onpointer*` attribute is currently present.
1482
- */
1483
- _inlineHandlerTypes = new Set();
1484
1598
  /**
1485
1599
  * Whether the hierarchy has been built for this entity.
1486
1600
  */
1487
1601
  _built = false;
1488
- _entity = null;
1489
- /**
1490
- * The application element this entity is registered with, cached at creation time so the
1491
- * entity can be unregistered even once this element has left the DOM.
1492
- */
1493
- _appElement = null;
1494
- /**
1495
- * The PlayCanvas entity instance. `null` until the element is ready, and again once it has
1496
- * been removed from the document — await {@link whenReady} or the element's `ready()`
1497
- * promise before accessing it.
1498
- * @returns The entity instance, or `null`.
1499
- */
1500
- get entity() {
1501
- return this._entity;
1502
- }
1503
1602
  /**
1504
1603
  * Creates the backing entity. Called by the containing `<pc-app>` element during its boot
1505
1604
  * sweep, and on connection for elements inserted while the application is already running.
@@ -1527,13 +1626,11 @@ class EntityElement extends AsyncElement {
1527
1626
  if (this._tags.length > 0) {
1528
1627
  entity.tags.add(this._tags);
1529
1628
  }
1530
- // Register with the owning application, which joins engine nodes back to elements by
1531
- // identity (never by name), and hook the entity's destruction. The engine fires 'destroy'
1532
- // for every entity in a destroyed subtree, so the element learns of its entity's death no
1533
- // matter who causes it: this element, an ancestor, the whole application, or a user
1534
- // script calling entity.destroy().
1535
- this._appElement = this.closestApp;
1536
- this._appElement?._registerEntityElement(entity, this);
1629
+ // Register with the owning application and hook the entity's destruction. The engine
1630
+ // fires 'destroy' for every entity in a destroyed subtree, so the element learns of its
1631
+ // entity's death no matter who causes it: this element, an ancestor, the whole
1632
+ // application, or a user script calling entity.destroy().
1633
+ this._registerEntity(entity);
1537
1634
  entity.once('destroy', this._onEntityDestroy, this);
1538
1635
  }
1539
1636
  /**
@@ -1546,17 +1643,16 @@ class EntityElement extends AsyncElement {
1546
1643
  * @param entity - The entity that was destroyed.
1547
1644
  */
1548
1645
  _onEntityDestroy(entity) {
1549
- this._appElement?._unregisterEntityElement(entity);
1550
- this._appElement = null;
1646
+ this._unregisterEntity(entity);
1551
1647
  this._entity = null;
1552
1648
  this._built = false;
1553
1649
  this._resetReady();
1554
1650
  }
1555
1651
  /**
1556
- * Parents the backing entity: under the entity of the nearest ancestor `<pc-entity>` when
1557
- * there is one, and under the application root otherwise. Called by the containing `<pc-app>`
1558
- * element once a sweep has created every entity, so a parent's existence never depends on
1559
- * document order.
1652
+ * Parents the backing entity: under the entity of the nearest ancestor `<pc-entity>` or
1653
+ * `<pc-node>` when there is one, and under the application root otherwise. Called by the
1654
+ * containing `<pc-app>` element once a sweep has created every entity, so a parent's
1655
+ * existence never depends on document order.
1560
1656
  *
1561
1657
  * @param app - The application whose root adopts parentless entities.
1562
1658
  * @internal
@@ -1564,8 +1660,14 @@ class EntityElement extends AsyncElement {
1564
1660
  _buildHierarchy(app) {
1565
1661
  if (!this.entity || this._built)
1566
1662
  return;
1567
- this._built = true;
1568
1663
  const closestEntity = this.closestEntity;
1664
+ // A host element without an entity is an unresolved `<pc-node>`: building now would
1665
+ // mis-anchor this entity to the application root while the host is still resolving.
1666
+ // Stay unbuilt - the host drives this subtree itself once it binds.
1667
+ if (closestEntity && !closestEntity.entity) {
1668
+ return;
1669
+ }
1670
+ this._built = true;
1569
1671
  if (closestEntity?.entity) {
1570
1672
  closestEntity.entity.addChild(this.entity);
1571
1673
  }
@@ -1711,44 +1813,8 @@ class EntityElement extends AsyncElement {
1711
1813
  get tags() {
1712
1814
  return this._tags;
1713
1815
  }
1714
- /**
1715
- * Tracks whether an inline `onpointer*` attribute is present. The browser itself compiles and
1716
- * runs these attributes — they are standard `GlobalEventHandlers`, so setting one replaces
1717
- * the previous handler and removing it removes the handler, exactly like `onclick` on any
1718
- * HTML element. But because they bypass {@link addEventListener}, the connect/disconnect
1719
- * bookkeeping that lets the application lazily attach its canvas pointer handlers must be
1720
- * kept in sync here.
1721
- *
1722
- * @param name - The attribute name (e.g. 'onpointerdown').
1723
- * @param value - The attribute value, or `null` when the attribute has been removed.
1724
- */
1725
- _updateInlineHandler(name, value) {
1726
- const type = name.substring(2);
1727
- const had = this._inlineHandlerTypes.has(type);
1728
- const has = value !== null;
1729
- if (has && !had) {
1730
- this._inlineHandlerTypes.add(type);
1731
- this.dispatchEvent(new CustomEvent(`${type}:connect`, { bubbles: true }));
1732
- }
1733
- else if (!has && had) {
1734
- this._inlineHandlerTypes.delete(type);
1735
- this.dispatchEvent(new CustomEvent(`${type}:disconnect`, { bubbles: true }));
1736
- }
1737
- }
1738
1816
  static get observedAttributes() {
1739
- return [
1740
- 'enabled',
1741
- 'name',
1742
- 'position',
1743
- 'rotation',
1744
- 'scale',
1745
- 'tags',
1746
- 'onpointerenter',
1747
- 'onpointerleave',
1748
- 'onpointerdown',
1749
- 'onpointerup',
1750
- 'onpointermove'
1751
- ];
1817
+ return ['enabled', 'name', 'position', 'rotation', 'scale', 'tags', ...POINTER_ATTRIBUTES];
1752
1818
  }
1753
1819
  attributeChangedCallback(name, _oldValue, newValue) {
1754
1820
  switch (name) {
@@ -1779,37 +1845,6 @@ class EntityElement extends AsyncElement {
1779
1845
  break;
1780
1846
  }
1781
1847
  }
1782
- addEventListener(type, listener, options) {
1783
- if (!this._listeners[type]) {
1784
- this._listeners[type] = [];
1785
- }
1786
- this._listeners[type].push(listener);
1787
- super.addEventListener(type, listener, options);
1788
- if (type.startsWith('pointer')) {
1789
- this.dispatchEvent(new CustomEvent(`${type}:connect`, { bubbles: true }));
1790
- }
1791
- }
1792
- removeEventListener(type, listener, options) {
1793
- if (this._listeners[type]) {
1794
- this._listeners[type] = this._listeners[type].filter((l) => l !== listener);
1795
- }
1796
- super.removeEventListener(type, listener, options);
1797
- if (type.startsWith('pointer')) {
1798
- this.dispatchEvent(new CustomEvent(`${type}:disconnect`, { bubbles: true }));
1799
- }
1800
- }
1801
- /**
1802
- * Whether the element has a listener for an event type, registered either with
1803
- * {@link addEventListener} or with the matching inline `onpointer*` attribute. Read by the
1804
- * containing `<pc-app>` element to gate pointer event synthesis.
1805
- *
1806
- * @param type - The event type.
1807
- * @returns Whether a listener is registered.
1808
- * @internal
1809
- */
1810
- _hasListeners(type) {
1811
- return Boolean(this._listeners[type]?.length) || this._inlineHandlerTypes.has(type);
1812
- }
1813
1848
  }
1814
1849
  customElements.define('pc-entity', EntityElement);
1815
1850
 
@@ -1994,6 +2029,48 @@ const renderModes = new Map([
1994
2029
  ['sliced', playcanvas.SPRITE_RENDERMODE_SLICED],
1995
2030
  ['tiled', playcanvas.SPRITE_RENDERMODE_TILED]
1996
2031
  ]);
2032
+ const addressModes = new Map([
2033
+ ['repeat', playcanvas.ADDRESS_REPEAT],
2034
+ ['clamp', playcanvas.ADDRESS_CLAMP_TO_EDGE],
2035
+ ['mirror', playcanvas.ADDRESS_MIRRORED_REPEAT]
2036
+ ]);
2037
+ const minFilterModes = new Map([
2038
+ ['nearest', playcanvas.FILTER_NEAREST],
2039
+ ['linear', playcanvas.FILTER_LINEAR],
2040
+ ['nearest-mip-nearest', playcanvas.FILTER_NEAREST_MIPMAP_NEAREST],
2041
+ ['linear-mip-nearest', playcanvas.FILTER_LINEAR_MIPMAP_NEAREST],
2042
+ ['nearest-mip-linear', playcanvas.FILTER_NEAREST_MIPMAP_LINEAR],
2043
+ ['linear-mip-linear', playcanvas.FILTER_LINEAR_MIPMAP_LINEAR]
2044
+ ]);
2045
+ const magFilterModes = new Map([
2046
+ ['nearest', playcanvas.FILTER_NEAREST],
2047
+ ['linear', playcanvas.FILTER_LINEAR]
2048
+ ]);
2049
+ // The engine's texture JSON spells the filter names with underscores ('linear_mip_linear'); the
2050
+ // attribute values are kebab-case like every other enum attribute in this library. The address
2051
+ // mode names contain no dashes, so for them the rename is the identity.
2052
+ const toTextureJson = (name) => name.replace(/-/g, '_');
2053
+ // Engine Texture constructor defaults, restored on a loaded texture when a texture option
2054
+ // attribute is removed.
2055
+ const textureOptionDefaults = {
2056
+ addressU: playcanvas.ADDRESS_REPEAT,
2057
+ addressV: playcanvas.ADDRESS_REPEAT,
2058
+ anisotropy: 1,
2059
+ flipY: false,
2060
+ magFilter: playcanvas.FILTER_LINEAR,
2061
+ minFilter: playcanvas.FILTER_LINEAR_MIPMAP_LINEAR,
2062
+ mipmaps: true,
2063
+ srgb: false
2064
+ };
2065
+ // Attributes that only apply to certain asset types, used to warn when one is set on an asset of
2066
+ // any other type (where it would otherwise be silently ignored).
2067
+ const typeScopedAttributes = [
2068
+ [
2069
+ ['address-u', 'address-v', 'anisotropy', 'flip-y', 'mag-filter', 'min-filter', 'mipmaps', 'srgb'],
2070
+ ['texture', 'textureatlas']
2071
+ ],
2072
+ [['atlas', 'frame-keys', 'pixels-per-unit', 'render-mode'], ['sprite']]
2073
+ ];
1997
2074
  const extToType = new Map([
1998
2075
  ['bin', 'binary'],
1999
2076
  ['css', 'css'],
@@ -2050,8 +2127,16 @@ const processBufferView = (gltfBuffer, buffers, continuation) => {
2050
2127
  * immediately unless `lazy`. A `pc-asset` must be a direct child of `pc-app` — elements placed
2051
2128
  * elsewhere, or with an unsupported asset type, never become ready.
2052
2129
  *
2053
- * Apart from `lazy`, these attributes are read once when the asset is created, so changing them
2054
- * later has no effect.
2130
+ * For `texture` and `textureatlas` assets, the texture options (`address-u`, `address-v`,
2131
+ * `min-filter`, `mag-filter`, `anisotropy`, `mipmaps`, `srgb`, `flip-y`) apply when the texture is
2132
+ * created and — like `lazy` — are observed: changing one updates a texture that has already
2133
+ * loaded, and removing one restores the engine default. Changing `srgb` or `mipmaps` on a loaded
2134
+ * texture recreates the underlying GPU resource, so prefer declaring those up front. Each option
2135
+ * overrides the matching key in the `data` JSON; options left unset write nothing, leaving the
2136
+ * engine's per-format defaults in force.
2137
+ *
2138
+ * Apart from `lazy` and the texture options, these attributes are read once when the asset is
2139
+ * created, so changing them later has no effect.
2055
2140
  *
2056
2141
  * @attribute {string} id - The identifier used to reference the asset from other elements.
2057
2142
  * @attribute {string} src - The URL of the asset to load.
@@ -2073,7 +2158,15 @@ const processBufferView = (gltfBuffer, buffers, continuation) => {
2073
2158
  * not that it succeeded.
2074
2159
  */
2075
2160
  class AssetElement extends AsyncElement {
2161
+ _addressU = null;
2162
+ _addressV = null;
2163
+ _anisotropy = null;
2164
+ _flipY = null;
2076
2165
  _lazy = false;
2166
+ _magFilter = null;
2167
+ _minFilter = null;
2168
+ _mipmaps = null;
2169
+ _srgb = null;
2077
2170
  /**
2078
2171
  * The asset that is loaded. Available once the element is ready — await
2079
2172
  * {@link whenReady} or the element's `ready()` promise before accessing it.
@@ -2144,6 +2237,15 @@ class AssetElement extends AsyncElement {
2144
2237
  console.warn(`Unsupported asset type: ${src}`);
2145
2238
  return;
2146
2239
  }
2240
+ // Attributes scoped to other asset types have no effect here - say so rather than
2241
+ // failing silently.
2242
+ const inapplicable = typeScopedAttributes
2243
+ .filter(([, types]) => !types.includes(type))
2244
+ .flatMap(([attributes]) => attributes)
2245
+ .filter((attribute) => this.hasAttribute(attribute));
2246
+ if (inapplicable.length > 0) {
2247
+ console.warn(`pc-asset '${id || src}' has attributes that do not apply to asset type '${type}' and are ignored: ${inapplicable.join(', ')}`);
2248
+ }
2147
2249
  // Optional inline asset data, used by data-driven assets such as texture atlases (frame
2148
2250
  // definitions) and sprites (atlas reference, frame keys, etc.).
2149
2251
  const data = this._buildData(type);
@@ -2171,9 +2273,11 @@ class AssetElement extends AsyncElement {
2171
2273
  this.asset.on('error', this._onAssetError, this);
2172
2274
  }
2173
2275
  /**
2174
- * Builds the `data` object for the asset from an optional inline `data` attribute (JSON) and,
2175
- * for sprites, from the convenience attributes (`atlas`, `frame-keys`, `pixels-per-unit`,
2176
- * `render-mode`). Returns `undefined` when there is no data to apply.
2276
+ * Builds the `data` object for the asset from an optional inline `data` attribute (JSON), the
2277
+ * texture option attributes (for `texture` and `textureatlas` assets), and the sprite
2278
+ * convenience attributes (`atlas`, `frame-keys`, `pixels-per-unit`, `render-mode`). An
2279
+ * attribute overrides the matching `data` JSON key. Returns `undefined` when there is no data
2280
+ * to apply.
2177
2281
  * @param type - The resolved asset type.
2178
2282
  * @returns The asset data, or `undefined`.
2179
2283
  */
@@ -2188,6 +2292,37 @@ class AssetElement extends AsyncElement {
2188
2292
  console.warn(`Invalid 'data' JSON on pc-asset: ${dataAttr}`);
2189
2293
  }
2190
2294
  }
2295
+ if (type === 'texture' || type === 'textureatlas') {
2296
+ data = data ?? {};
2297
+ // Only options the user actually set are written: the engine reads these keys with
2298
+ // hasOwnProperty semantics, and an absent key leaves its per-format default (an HDR's
2299
+ // 'rgbe' type, a KTX2's transcoded format) in force.
2300
+ if (this._addressU !== null) {
2301
+ data.addressu = this._addressU;
2302
+ }
2303
+ if (this._addressV !== null) {
2304
+ data.addressv = this._addressV;
2305
+ }
2306
+ if (this._anisotropy !== null) {
2307
+ data.anisotropy = this._anisotropy;
2308
+ }
2309
+ if (this._flipY !== null) {
2310
+ // 'flipY' is the one camelCase key in the engine's texture JSON
2311
+ data.flipY = this._flipY;
2312
+ }
2313
+ if (this._magFilter !== null) {
2314
+ data.magfilter = toTextureJson(this._magFilter);
2315
+ }
2316
+ if (this._minFilter !== null) {
2317
+ data.minfilter = toTextureJson(this._minFilter);
2318
+ }
2319
+ if (this._mipmaps !== null) {
2320
+ data.mipmaps = this._mipmaps;
2321
+ }
2322
+ if (this._srgb !== null) {
2323
+ data.srgb = this._srgb;
2324
+ }
2325
+ }
2191
2326
  if (type === 'sprite') {
2192
2327
  data = data ?? {};
2193
2328
  // Resolve the referenced texture atlas to its (numeric) asset id. The atlas must be
@@ -2221,6 +2356,56 @@ class AssetElement extends AsyncElement {
2221
2356
  }
2222
2357
  return data;
2223
2358
  }
2359
+ /**
2360
+ * Returns the engine texture behind this asset, when there is one: the resource itself for a
2361
+ * `texture` asset, the atlas's texture for a `textureatlas` asset, `null` otherwise
2362
+ * (including before the asset has loaded).
2363
+ * @returns The texture, or `null`.
2364
+ */
2365
+ _texture() {
2366
+ const asset = this.asset;
2367
+ if (!asset?.resource)
2368
+ return null;
2369
+ if (asset.type === 'texture')
2370
+ return asset.resource;
2371
+ if (asset.type === 'textureatlas')
2372
+ return asset.resource.texture ?? null;
2373
+ return null;
2374
+ }
2375
+ /**
2376
+ * Writes one texture option through to the created asset, if any. The engine-JSON key is
2377
+ * written into `asset.data`, mutated in place - replacing the whole object would make the
2378
+ * registry re-patch every key, and a re-patched `srgb` or `mipmaps` recreates the texture
2379
+ * even when unchanged. The in-place key is what a not-yet-started load reads at texture
2380
+ * construction, and what any later reload reads. When the texture already exists, the
2381
+ * corresponding property is assigned directly; `null` (attribute removed) deletes the key
2382
+ * and restores the engine default. Assets of any other type are left untouched.
2383
+ *
2384
+ * @param key - The engine texture JSON key in `asset.data`.
2385
+ * @param property - The Texture property to assign.
2386
+ * @param dataValue - The engine-JSON value for `asset.data`, or `null` to delete the key.
2387
+ * @param textureValue - The value for the Texture property, or `null` for the engine default.
2388
+ */
2389
+ _applyTextureOption(key, property, dataValue, textureValue) {
2390
+ const asset = this.asset;
2391
+ if (!asset || (asset.type !== 'texture' && asset.type !== 'textureatlas'))
2392
+ return;
2393
+ const data = asset.data;
2394
+ if (dataValue === null) {
2395
+ delete data[key];
2396
+ }
2397
+ else {
2398
+ data[key] = dataValue;
2399
+ }
2400
+ const texture = this._texture();
2401
+ if (texture) {
2402
+ // Every option here is a number- or boolean-valued Texture property; the
2403
+ // value/property pairing is fixed by the callers, which TypeScript cannot see
2404
+ // through the union.
2405
+ texture[property] =
2406
+ textureValue ?? textureOptionDefaults[property];
2407
+ }
2408
+ }
2224
2409
  _destroyAsset() {
2225
2410
  if (this.asset) {
2226
2411
  // A caller that keeps the Asset alive must not dispatch on a removed element
@@ -2232,6 +2417,75 @@ class AssetElement extends AsyncElement {
2232
2417
  this.asset = null;
2233
2418
  }
2234
2419
  }
2420
+ /**
2421
+ * Sets the texture's horizontal (U) address mode: how texture coordinates outside the 0 to 1
2422
+ * range sample the texture. Applies to `texture` and `textureatlas` assets, both when the
2423
+ * texture is created and after it has loaded.
2424
+ * @param value - The address mode, or `null` to use the engine default of 'repeat'.
2425
+ */
2426
+ set addressU(value) {
2427
+ this._addressU = value;
2428
+ const constant = value === null ? null : (addressModes.get(value) ?? playcanvas.ADDRESS_REPEAT);
2429
+ this._applyTextureOption('addressu', 'addressU', value, constant);
2430
+ }
2431
+ /**
2432
+ * Gets the texture's horizontal (U) address mode.
2433
+ * @returns The address mode, or `null` when unset.
2434
+ */
2435
+ get addressU() {
2436
+ return this._addressU;
2437
+ }
2438
+ /**
2439
+ * Sets the texture's vertical (V) address mode: how texture coordinates outside the 0 to 1
2440
+ * range sample the texture. Applies to `texture` and `textureatlas` assets, both when the
2441
+ * texture is created and after it has loaded.
2442
+ * @param value - The address mode, or `null` to use the engine default of 'repeat'.
2443
+ */
2444
+ set addressV(value) {
2445
+ this._addressV = value;
2446
+ const constant = value === null ? null : (addressModes.get(value) ?? playcanvas.ADDRESS_REPEAT);
2447
+ this._applyTextureOption('addressv', 'addressV', value, constant);
2448
+ }
2449
+ /**
2450
+ * Gets the texture's vertical (V) address mode.
2451
+ * @returns The address mode, or `null` when unset.
2452
+ */
2453
+ get addressV() {
2454
+ return this._addressV;
2455
+ }
2456
+ /**
2457
+ * Sets the texture's maximum anisotropic filtering level, which improves quality at oblique
2458
+ * viewing angles. Applies to `texture` and `textureatlas` assets, both when the texture is
2459
+ * created and after it has loaded.
2460
+ * @param value - The anisotropy level, or `null` to use the engine default of 1.
2461
+ */
2462
+ set anisotropy(value) {
2463
+ this._anisotropy = value;
2464
+ this._applyTextureOption('anisotropy', 'anisotropy', value, value);
2465
+ }
2466
+ /**
2467
+ * Gets the texture's maximum anisotropic filtering level.
2468
+ * @returns The anisotropy level, or `null` when unset.
2469
+ */
2470
+ get anisotropy() {
2471
+ return this._anisotropy;
2472
+ }
2473
+ /**
2474
+ * Sets whether the texture's image data is flipped vertically at upload. Applies to `texture`
2475
+ * and `textureatlas` assets, both when the texture is created and after it has loaded.
2476
+ * @param value - The flip flag, or `null` to use the engine default of `false`.
2477
+ */
2478
+ set flipY(value) {
2479
+ this._flipY = value;
2480
+ this._applyTextureOption('flipY', 'flipY', value, value);
2481
+ }
2482
+ /**
2483
+ * Gets whether the texture's image data is flipped vertically at upload.
2484
+ * @returns The flip flag, or `null` when unset.
2485
+ */
2486
+ get flipY() {
2487
+ return this._flipY;
2488
+ }
2235
2489
  /**
2236
2490
  * Sets whether the asset should be loaded lazily.
2237
2491
  * @param value - The lazy loading flag.
@@ -2250,37 +2504,200 @@ class AssetElement extends AsyncElement {
2250
2504
  return this._lazy;
2251
2505
  }
2252
2506
  /**
2253
- * Returns the {@link Asset} created by the `<pc-asset>` element with the given `id`, or
2254
- * `undefined` if there is no such element or its asset has not been created yet.
2255
- *
2256
- * @param id - The `id` of the `<pc-asset>` element.
2257
- * @returns The asset, or `undefined`.
2507
+ * Sets the texture's magnification filter, used when the texture is displayed larger than its
2508
+ * source size. Applies to `texture` and `textureatlas` assets, both when the texture is
2509
+ * created and after it has loaded.
2510
+ * @param value - The filter, or `null` to use the engine default of 'linear'.
2258
2511
  */
2259
- static get(id) {
2260
- const assetElement = document.querySelector(`pc-asset[id="${id}"]`);
2261
- return assetElement?.asset;
2512
+ set magFilter(value) {
2513
+ this._magFilter = value;
2514
+ const json = value === null ? null : toTextureJson(value);
2515
+ const constant = value === null ? null : (magFilterModes.get(value) ?? playcanvas.FILTER_LINEAR);
2516
+ this._applyTextureOption('magfilter', 'magFilter', json, constant);
2262
2517
  }
2263
- static get observedAttributes() {
2264
- return ['lazy'];
2518
+ /**
2519
+ * Gets the texture's magnification filter.
2520
+ * @returns The filter, or `null` when unset.
2521
+ */
2522
+ get magFilter() {
2523
+ return this._magFilter;
2265
2524
  }
2266
- attributeChangedCallback(name, _oldValue, newValue) {
2267
- if (name === 'lazy') {
2268
- this.lazy = parseBool(newValue, false);
2269
- }
2525
+ /**
2526
+ * Sets the texture's minification filter, used when the texture is displayed smaller than its
2527
+ * source size. The mip variants blend within (and, for the second `linear`, between) mipmap
2528
+ * levels. Applies to `texture` and `textureatlas` assets, both when the texture is created
2529
+ * and after it has loaded.
2530
+ * @param value - The filter, or `null` to use the engine default of 'linear-mip-linear'.
2531
+ */
2532
+ set minFilter(value) {
2533
+ this._minFilter = value;
2534
+ const json = value === null ? null : toTextureJson(value);
2535
+ const constant = value === null ? null : (minFilterModes.get(value) ?? playcanvas.FILTER_LINEAR_MIPMAP_LINEAR);
2536
+ this._applyTextureOption('minfilter', 'minFilter', json, constant);
2270
2537
  }
2271
- }
2272
- customElements.define('pc-asset', AssetElement);
2273
-
2274
- /**
2275
- * Represents a component in the PlayCanvas engine.
2276
- *
2277
- * @category Components
2278
- */
2538
+ /**
2539
+ * Gets the texture's minification filter.
2540
+ * @returns The filter, or `null` when unset.
2541
+ */
2542
+ get minFilter() {
2543
+ return this._minFilter;
2544
+ }
2545
+ /**
2546
+ * Sets whether the texture generates and uses mipmaps. Changing this on a loaded texture
2547
+ * recreates the underlying GPU resource, so prefer declaring it up front. Applies to
2548
+ * `texture` and `textureatlas` assets.
2549
+ * @param value - The mipmaps flag, or `null` to use the engine default of `true`.
2550
+ */
2551
+ set mipmaps(value) {
2552
+ this._mipmaps = value;
2553
+ this._applyTextureOption('mipmaps', 'mipmaps', value, value);
2554
+ }
2555
+ /**
2556
+ * Gets whether the texture generates and uses mipmaps.
2557
+ * @returns The mipmaps flag, or `null` when unset.
2558
+ */
2559
+ get mipmaps() {
2560
+ return this._mipmaps;
2561
+ }
2562
+ /**
2563
+ * Sets whether the texture holds sRGB (gamma-encoded) color data, enabling hardware gamma
2564
+ * decode. Free when set before the texture loads; changing it on a loaded texture recreates
2565
+ * the underlying GPU resource. Applies to `texture` and `textureatlas` assets.
2566
+ * @param value - The sRGB flag, or `null` to use the engine default of `false`.
2567
+ */
2568
+ set srgb(value) {
2569
+ this._srgb = value;
2570
+ this._applyTextureOption('srgb', 'srgb', value, value);
2571
+ }
2572
+ /**
2573
+ * Gets whether the texture holds sRGB (gamma-encoded) color data.
2574
+ * @returns The sRGB flag, or `null` when unset.
2575
+ */
2576
+ get srgb() {
2577
+ return this._srgb;
2578
+ }
2579
+ /**
2580
+ * Returns the {@link Asset} created by the `<pc-asset>` element with the given `id`, or
2581
+ * `undefined` if there is no such element or its asset has not been created yet.
2582
+ *
2583
+ * @param id - The `id` of the `<pc-asset>` element.
2584
+ * @returns The asset, or `undefined`.
2585
+ */
2586
+ static get(id) {
2587
+ const assetElement = document.querySelector(`pc-asset[id="${id}"]`);
2588
+ return assetElement?.asset;
2589
+ }
2590
+ static get observedAttributes() {
2591
+ return [
2592
+ 'address-u',
2593
+ 'address-v',
2594
+ 'anisotropy',
2595
+ 'flip-y',
2596
+ 'lazy',
2597
+ 'mag-filter',
2598
+ 'min-filter',
2599
+ 'mipmaps',
2600
+ 'srgb'
2601
+ ];
2602
+ }
2603
+ attributeChangedCallback(name, _oldValue, newValue) {
2604
+ // Each texture option keeps its parse* call as the branch's first assignment (the CEM
2605
+ // manifest derives the attribute's type and default from it - a ternary would degrade
2606
+ // both to plain string) and treats a removed attribute (null) as a reset to unset,
2607
+ // which restores the engine default on a loaded texture.
2608
+ switch (name) {
2609
+ case 'address-u':
2610
+ if (newValue !== null) {
2611
+ this.addressU = parseEnum(newValue, addressModes, 'repeat', name);
2612
+ }
2613
+ else {
2614
+ this.addressU = null;
2615
+ }
2616
+ break;
2617
+ case 'address-v':
2618
+ if (newValue !== null) {
2619
+ this.addressV = parseEnum(newValue, addressModes, 'repeat', name);
2620
+ }
2621
+ else {
2622
+ this.addressV = null;
2623
+ }
2624
+ break;
2625
+ case 'anisotropy':
2626
+ if (newValue !== null) {
2627
+ this.anisotropy = parseNumber(newValue, 1, name);
2628
+ }
2629
+ else {
2630
+ this.anisotropy = null;
2631
+ }
2632
+ break;
2633
+ case 'flip-y':
2634
+ if (newValue !== null) {
2635
+ this.flipY = parseBool(newValue, false);
2636
+ }
2637
+ else {
2638
+ this.flipY = null;
2639
+ }
2640
+ break;
2641
+ case 'lazy':
2642
+ this.lazy = parseBool(newValue, false);
2643
+ break;
2644
+ case 'mag-filter':
2645
+ if (newValue !== null) {
2646
+ this.magFilter = parseEnum(newValue, magFilterModes, 'linear', name);
2647
+ }
2648
+ else {
2649
+ this.magFilter = null;
2650
+ }
2651
+ break;
2652
+ case 'min-filter':
2653
+ if (newValue !== null) {
2654
+ this.minFilter = parseEnum(newValue, minFilterModes, 'linear-mip-linear', name);
2655
+ }
2656
+ else {
2657
+ this.minFilter = null;
2658
+ }
2659
+ break;
2660
+ case 'mipmaps':
2661
+ if (newValue !== null) {
2662
+ this.mipmaps = parseBool(newValue, true);
2663
+ }
2664
+ else {
2665
+ this.mipmaps = null;
2666
+ }
2667
+ break;
2668
+ case 'srgb':
2669
+ if (newValue !== null) {
2670
+ this.srgb = parseBool(newValue, false);
2671
+ }
2672
+ else {
2673
+ this.srgb = null;
2674
+ }
2675
+ break;
2676
+ }
2677
+ }
2678
+ }
2679
+ customElements.define('pc-asset', AssetElement);
2680
+
2681
+ /**
2682
+ * Represents a component in the PlayCanvas engine.
2683
+ *
2684
+ * @category Components
2685
+ */
2279
2686
  class ComponentElement extends AsyncElement {
2280
2687
  _componentName;
2281
2688
  _enabled = true;
2282
2689
  _component = null;
2283
2690
  _appElement = null;
2691
+ /**
2692
+ * The element hosting this component, held so the host's readiness cycles can be observed
2693
+ * even after `closestEntity` would no longer resolve (during teardown).
2694
+ */
2695
+ _hostElement = null;
2696
+ /**
2697
+ * The listener re-applying this component when the host's readiness cycles. Held for
2698
+ * removal on disconnect.
2699
+ */
2700
+ _hostReadyListener = null;
2284
2701
  /**
2285
2702
  * Incremented on every connect and disconnect. connectedCallback captures the value on entry
2286
2703
  * and abandons itself wherever it resumes from an await if the value has moved on — so a
@@ -2308,6 +2725,37 @@ class ComponentElement extends AsyncElement {
2308
2725
  getInitialComponentData() {
2309
2726
  return {};
2310
2727
  }
2728
+ /**
2729
+ * Creates the component on the host's current entity, removing it first from a previous
2730
+ * entity that is still alive (a retargeted `<pc-node>` moves its decorations with it). When
2731
+ * the entity already has a component of this type — a glTF node arriving with its authored
2732
+ * `render` component, say — warns and leaves `component` null. The element-level warning is
2733
+ * load-bearing: the engine's own duplicate-addComponent warning is Debug-stripped from
2734
+ * production builds, which would otherwise leave a silent null.
2735
+ */
2736
+ _applyComponent() {
2737
+ const entity = this._hostElement?.entity ?? null;
2738
+ if (this._component && this._component.entity === entity) {
2739
+ return;
2740
+ }
2741
+ // A retarget leaves the previous component on a still-live entity - remove it so the
2742
+ // decoration follows the element, or vanishes with a dissolved binding. A destroyed
2743
+ // entity took its components with it.
2744
+ const previous = this._component;
2745
+ if (previous?.entity && previous.entity.c[this._componentName] === previous) {
2746
+ previous.entity.removeComponent(this._componentName);
2747
+ }
2748
+ this._component = null;
2749
+ if (!entity) {
2750
+ return;
2751
+ }
2752
+ if (entity.c[this._componentName]) {
2753
+ const label = this.id ? ` '${this.id}'` : '';
2754
+ console.warn(`${this.tagName.toLowerCase()}${label} - '${entity.name}' already has a '${this._componentName}' component - component not added`);
2755
+ return;
2756
+ }
2757
+ this._component = entity.addComponent(this._componentName, this.getInitialComponentData());
2758
+ }
2311
2759
  async _addComponent() {
2312
2760
  const generation = this._connectionGeneration;
2313
2761
  const entityElement = this.closestEntity;
@@ -2324,9 +2772,40 @@ class ComponentElement extends AsyncElement {
2324
2772
  if (generation !== this._connectionGeneration) {
2325
2773
  return;
2326
2774
  }
2327
- // Add the component to the entity
2328
- const data = this.getInitialComponentData();
2329
- this._component = entityElement.entity.addComponent(this._componentName, data);
2775
+ this._hostElement = entityElement;
2776
+ this._applyComponent();
2777
+ // Re-apply when the host's readiness cycles without this element disconnecting: a
2778
+ // `<pc-node>` rebinding after its model reloads or retargets, or a re-created entity.
2779
+ // The 'ready' event bubbles, so events from descendants pass through this host - only
2780
+ // the host's own cycles count. Readiness is cycled here too, so decorations one level
2781
+ // down re-apply the same way.
2782
+ this._hostReadyListener = (event) => {
2783
+ if (event.target !== this._hostElement) {
2784
+ return;
2785
+ }
2786
+ if (generation !== this._connectionGeneration) {
2787
+ return;
2788
+ }
2789
+ this._hostCycled();
2790
+ };
2791
+ entityElement.addEventListener('ready', this._hostReadyListener);
2792
+ }
2793
+ /**
2794
+ * Re-evaluates this component against the host's current entity: applied to a new entity,
2795
+ * moved from a still-live old one, or removed when the host no longer fronts an entity at
2796
+ * all. Readiness follows - it cycles with a re-application and stays unresolved while the
2797
+ * host is unbound. Called by the host-ready listener, and directly by a `<pc-node>`
2798
+ * dissolving its binding: the one transition that fires no ready event to ride.
2799
+ *
2800
+ * @internal
2801
+ */
2802
+ _hostCycled() {
2803
+ this._resetReady();
2804
+ this._applyComponent();
2805
+ if (this._hostElement?.entity) {
2806
+ this.initComponent();
2807
+ this._onReady();
2808
+ }
2330
2809
  }
2331
2810
  /**
2332
2811
  * Configures the newly added component. Overridden by subclasses whose setup goes beyond
@@ -2355,6 +2834,11 @@ class ComponentElement extends AsyncElement {
2355
2834
  disconnectedCallback() {
2356
2835
  // Invalidate any connectedCallback still suspended on an await
2357
2836
  this._connectionGeneration++;
2837
+ if (this._hostElement && this._hostReadyListener) {
2838
+ this._hostElement.removeEventListener('ready', this._hostReadyListener);
2839
+ }
2840
+ this._hostElement = null;
2841
+ this._hostReadyListener = null;
2358
2842
  // Remove the component when the element is disconnected. Skip this when the owning
2359
2843
  // application has already been destroyed — removing a <pc-app> disconnects it before
2360
2844
  // its children, taking the component systems with it.
@@ -3314,6 +3798,12 @@ customElements.define('pc-camera', CameraComponentElement);
3314
3798
  * The CollisionComponentElement interface also inherits the properties and methods of the
3315
3799
  * {@link HTMLElement} interface.
3316
3800
  *
3801
+ * For `type="mesh"`, the collision geometry defaults to the host entity's own render component
3802
+ * (its render asset) — a collider matching the visible mesh, which is what a mesh collider on a
3803
+ * glTF node means. The default resolves each time the component applies, so a `pc-node` that
3804
+ * retargets or rebinds picks up the new node's geometry. An entity with no asset-backed render
3805
+ * component warns, and the collider has no shape.
3806
+ *
3317
3807
  * @category Components
3318
3808
  */
3319
3809
  class CollisionComponentElement extends ComponentElement {
@@ -3341,6 +3831,29 @@ class CollisionComponentElement extends ComponentElement {
3341
3831
  type: this._type
3342
3832
  };
3343
3833
  }
3834
+ initComponent() {
3835
+ this._applyMeshGeometryDefault();
3836
+ }
3837
+ /**
3838
+ * Defaults a mesh collider's geometry to the host entity's own render component. The
3839
+ * engine's mesh collider only works with explicitly supplied geometry, and the element has
3840
+ * no attribute to supply it - so the host's visible geometry, the meaning a mesh collider
3841
+ * on a glTF node carries, fills the gap. Runs on every application (so a rebound `pc-node`
3842
+ * recomputes it) and on a runtime switch to `type="mesh"`; an explicitly assigned
3843
+ * `renderAsset` is never overwritten.
3844
+ */
3845
+ _applyMeshGeometryDefault() {
3846
+ const component = this.component;
3847
+ if (!component || this._type !== 'mesh' || component.renderAsset !== null) {
3848
+ return;
3849
+ }
3850
+ const asset = component.entity.render?.asset ?? null;
3851
+ if (asset === null) {
3852
+ console.warn(`pc-collision type="mesh" on '${component.entity.name}' found no asset-backed render component to take geometry from - collider has no shape`);
3853
+ return;
3854
+ }
3855
+ component.renderAsset = asset;
3856
+ }
3344
3857
  /**
3345
3858
  * Gets the underlying PlayCanvas collision component.
3346
3859
  * @returns The collision component.
@@ -3415,6 +3928,7 @@ class CollisionComponentElement extends ComponentElement {
3415
3928
  this._type = value;
3416
3929
  if (this.component) {
3417
3930
  this.component.type = value;
3931
+ this._applyMeshGeometryDefault();
3418
3932
  }
3419
3933
  }
3420
3934
  get type() {
@@ -5585,13 +6099,13 @@ class MaterialElement extends HTMLElement {
5585
6099
  }
5586
6100
  /**
5587
6101
  * @param slot - The material property to write.
5588
- * @param texture - The loaded texture.
6102
+ * @param texture - The loaded texture, applied with its sampler state untouched - anisotropy
6103
+ * and friends belong to the `pc-asset`'s texture options.
5589
6104
  */
5590
6105
  _applyMap(slot, texture) {
5591
6106
  if (!this.material)
5592
6107
  return;
5593
6108
  this.material[slot] = texture;
5594
- texture.anisotropy = 4;
5595
6109
  this._scheduleUpdate();
5596
6110
  }
5597
6111
  /**
@@ -9871,6 +10385,21 @@ customElements.define('pc-gsplat', GSplatComponentElement);
9871
10385
  * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-model/ | `<pc-model>`} elements.
9872
10386
  * The ModelElement interface also inherits the properties and methods of the
9873
10387
  * {@link HTMLElement} interface.
10388
+ *
10389
+ * The element becomes ready once its container asset has loaded and the instantiated hierarchy has
10390
+ * been added to the scene — `entity` is non-null by then. A failed load also settles readiness,
10391
+ * with `entity` remaining `null`: readiness means the load settled, not that it succeeded — listen
10392
+ * for `error`, or check `entity`, to tell the outcomes apart. Changing `asset` re-arms readiness
10393
+ * and instantiates anew, so a `ready()` obtained after the change resolves against the new
10394
+ * hierarchy. A `pc-model` outside a `pc-app`, or referencing an unknown asset id, warns and never
10395
+ * becomes ready.
10396
+ *
10397
+ * @fires {Event} load - Fired each time a container asset finishes instantiating, including
10398
+ * re-instantiation after `asset` changes. Does not bubble — listen on this element, or use a
10399
+ * capture-phase listener on an ancestor.
10400
+ * @fires {ErrorEvent} error - Fired when the container asset fails to load, with the engine's
10401
+ * error in `message`. Does not bubble. The element still becomes ready — readiness means the load
10402
+ * settled, not that it succeeded.
9874
10403
  */
9875
10404
  class ModelElement extends AsyncElement {
9876
10405
  _asset = '';
@@ -9883,11 +10412,12 @@ class ModelElement extends AsyncElement {
9883
10412
  */
9884
10413
  _loadGeneration = 0;
9885
10414
  /**
9886
- * The pending asset-load subscription of the current load, if it is waiting for its asset.
9887
- * Held so that whatever supersedes the load can detach the handler from the asset, rather
9888
- * than leave it registered until the asset loads (or forever, if it never does).
10415
+ * The pending asset subscriptions of the current load, if it is waiting for its asset. Held
10416
+ * so that whatever supersedes the load can detach the handlers from the asset, rather than
10417
+ * leave them registered until the asset settles (or forever, if it never does).
9889
10418
  */
9890
10419
  _loadHandle = null;
10420
+ _errorHandle = null;
9891
10421
  /**
9892
10422
  * The root entity of the instantiated model. `null` until the container asset has loaded
9893
10423
  * and been instantiated, and again once the element has been removed from the document.
@@ -9897,18 +10427,36 @@ class ModelElement extends AsyncElement {
9897
10427
  return this._entity;
9898
10428
  }
9899
10429
  connectedCallback() {
10430
+ // A model outside an application is inert and never becomes ready, so awaiting it hangs.
10431
+ // Warn rather than fail silently, naming the parent it requires, as every other misplaced
10432
+ // element does.
10433
+ if (!this.closestApp) {
10434
+ const label = this._asset ? ` '${this._asset}'` : '';
10435
+ console.warn(`pc-model${label} must be a descendant of pc-app - model not created`);
10436
+ return;
10437
+ }
9900
10438
  this._loadModel();
9901
- this._onReady();
9902
10439
  }
9903
10440
  disconnectedCallback() {
9904
10441
  this._loadGeneration++;
9905
- this._detachLoadHandler();
10442
+ this._detachLoadHandlers();
9906
10443
  this._unloadModel();
9907
10444
  this._resetReady();
9908
10445
  }
9909
- _detachLoadHandler() {
10446
+ _detachLoadHandlers() {
9910
10447
  this._loadHandle?.off();
9911
10448
  this._loadHandle = null;
10449
+ this._errorHandle?.off();
10450
+ this._errorHandle = null;
10451
+ }
10452
+ /**
10453
+ * Resolves readiness and dispatches the `load` event. Called once the instantiated hierarchy
10454
+ * has been parented — readiness means "in the scene graph", matching `pc-entity`, so a ready
10455
+ * model's entity always has world transforms.
10456
+ */
10457
+ _announceLoad() {
10458
+ this._onReady();
10459
+ this.dispatchEvent(new Event('load'));
9912
10460
  }
9913
10461
  _instantiate(container) {
9914
10462
  const generation = this._loadGeneration;
@@ -9930,6 +10478,7 @@ class ModelElement extends AsyncElement {
9930
10478
  return;
9931
10479
  }
9932
10480
  parentEntityElement.entity.addChild(entity);
10481
+ this._announceLoad();
9933
10482
  });
9934
10483
  }
9935
10484
  else {
@@ -9940,6 +10489,7 @@ class ModelElement extends AsyncElement {
9940
10489
  return;
9941
10490
  }
9942
10491
  appElement.app.root.addChild(entity);
10492
+ this._announceLoad();
9943
10493
  });
9944
10494
  }
9945
10495
  }
@@ -9948,15 +10498,29 @@ class ModelElement extends AsyncElement {
9948
10498
  this._unloadModel();
9949
10499
  // Supersede any load already in flight - only the newest load may instantiate
9950
10500
  const generation = ++this._loadGeneration;
9951
- this._detachLoadHandler();
9952
- const appElement = await this.closestApp?.ready();
10501
+ this._detachLoadHandlers();
10502
+ // Re-arm readiness so a waiter obtained after an asset change resolves against the new
10503
+ // hierarchy. A no-op on first connection, where readiness is still pending.
10504
+ this._resetReady();
10505
+ const appElement = this.closestApp;
10506
+ if (!appElement) {
10507
+ // Outside pc-app; connectedCallback already warned. Reached through the asset setter.
10508
+ return;
10509
+ }
10510
+ await appElement.ready();
9953
10511
  // The element may have been removed, or another load started, while we waited
9954
10512
  if (generation !== this._loadGeneration) {
9955
10513
  return;
9956
10514
  }
9957
- const app = appElement?.app;
10515
+ const app = appElement.app;
9958
10516
  const asset = AssetElement.get(this._asset);
9959
10517
  if (!asset) {
10518
+ // An empty id is a legitimate transient (the asset may be assigned later); a
10519
+ // non-empty one that resolves to nothing is a dead end - say so rather than staying
10520
+ // silently pending.
10521
+ if (this._asset) {
10522
+ console.warn(`pc-model could not find asset '${this._asset}' - model not created`);
10523
+ }
9960
10524
  return;
9961
10525
  }
9962
10526
  if (asset.loaded) {
@@ -9965,14 +10529,26 @@ class ModelElement extends AsyncElement {
9965
10529
  else {
9966
10530
  // The generation is re-checked even though a superseded handler is detached: the
9967
10531
  // detach relies on how the engine's event emitter treats removal, while the check
9968
- // holds on its own.
10532
+ // holds on its own. Whichever of load/error fires first detaches the other.
9969
10533
  this._loadHandle = asset.once('load', () => {
9970
- this._loadHandle = null;
10534
+ this._detachLoadHandlers();
9971
10535
  if (generation !== this._loadGeneration) {
9972
10536
  return;
9973
10537
  }
9974
10538
  this._instantiate(asset.resource);
9975
10539
  });
10540
+ this._errorHandle = asset.once('error', (err) => {
10541
+ this._detachLoadHandlers();
10542
+ if (generation !== this._loadGeneration) {
10543
+ return;
10544
+ }
10545
+ // A failed load settles readiness with a null entity, mirroring pc-asset:
10546
+ // readiness means the load settled, not that it succeeded.
10547
+ this.dispatchEvent(new ErrorEvent('error', {
10548
+ message: err instanceof Error ? err.message : String(err)
10549
+ }));
10550
+ this._onReady();
10551
+ });
9976
10552
  app.assets.load(asset);
9977
10553
  }
9978
10554
  }
@@ -10010,6 +10586,625 @@ class ModelElement extends AsyncElement {
10010
10586
  }
10011
10587
  customElements.define('pc-model', ModelElement);
10012
10588
 
10589
+ /**
10590
+ * Computes the Levenshtein distance between two strings, for near-miss suggestions in the
10591
+ * resolution warnings.
10592
+ *
10593
+ * @param a - The first string.
10594
+ * @param b - The second string.
10595
+ * @returns The edit distance.
10596
+ */
10597
+ const levenshtein = (a, b) => {
10598
+ const row = Array.from({ length: b.length + 1 }, (_, i) => i);
10599
+ for (let i = 1; i <= a.length; i++) {
10600
+ let previous = row[0];
10601
+ row[0] = i;
10602
+ for (let j = 1; j <= b.length; j++) {
10603
+ const current = row[j];
10604
+ row[j] = Math.min(row[j] + 1, row[j - 1] + 1, previous + (a[i - 1] === b[j - 1] ? 0 : 1));
10605
+ previous = current;
10606
+ }
10607
+ }
10608
+ return row[b.length];
10609
+ };
10610
+ /**
10611
+ * The NodeElement interface provides properties and methods for manipulating
10612
+ * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-node/ | `<pc-node>`}
10613
+ * elements. The NodeElement interface also inherits the properties and methods of the
10614
+ * {@link HTMLElement} interface.
10615
+ *
10616
+ * A `pc-node` is an override element: where `pc-entity` creates an entity, `pc-node` binds to a
10617
+ * node a `pc-model` loaded and declares overrides against the authored asset — components to
10618
+ * add, properties to change, content to attach. Attributes present apply as overrides; attributes
10619
+ * absent leave authored values untouched, and removing an attribute (or assigning `null` to the
10620
+ * matching property) restores the authored value.
10621
+ *
10622
+ * `name` selects among the host model's nodes (first match in depth-first order), nesting a
10623
+ * `pc-node` inside another scopes the search to that subtree, and `index` picks among identically
10624
+ * named matches. When `name` matches more than one node and no `index` is given, the element
10625
+ * warns and binds nothing.
10626
+ *
10627
+ * The element becomes ready once bound, and never while unresolved — a missing or ambiguous
10628
+ * name warns and records the failure in `state`, readiness stays unresolved, and descendants
10629
+ * wait with it.
10630
+ *
10631
+ * The pointer events below are dispatched by the containing `<pc-app>` element when the pointer
10632
+ * intersects the bound node's geometry, exactly as for `<pc-entity>`.
10633
+ *
10634
+ * @attribute {string} name - The name of the node to bind, resolved within the nearest ancestor
10635
+ * `pc-model` (or `pc-node`) once it has instantiated.
10636
+ * @attribute {number} index - Which match to bind when `name` matches more than one node,
10637
+ * 0-based in depth-first order. Optional for a unique match; required for an ambiguous one.
10638
+ * @attribute {boolean} enabled - Overrides the node's enabled state.
10639
+ * @attribute {string} position - Overrides the node's local position, as an "x y z" triple.
10640
+ * @attribute {string} rotation - Overrides the node's local rotation (Euler angles), as an
10641
+ * "x y z" triple.
10642
+ * @attribute {string} scale - Overrides the node's local scale, as an "x y z" triple.
10643
+ * @attribute {string} tags - Overrides the node's tags, separated by spaces or commas.
10644
+ * @attribute {string} onpointerenter - Script to run when the pointer moves onto the node.
10645
+ * @attribute {string} onpointerleave - Script to run when the pointer moves off the node.
10646
+ * @attribute {string} onpointermove - Script to run when the pointer moves over the node.
10647
+ * @attribute {string} onpointerdown - Script to run when a pointer button is pressed over the
10648
+ * node.
10649
+ * @attribute {string} onpointerup - Script to run when a pointer button is released over the
10650
+ * node.
10651
+ * @fires {PointerEvent} pointerenter - Fired when the pointer moves onto the node.
10652
+ * @fires {PointerEvent} pointerleave - Fired when the pointer moves off the node.
10653
+ * @fires {PointerEvent} pointermove - Fired when the pointer moves over the node.
10654
+ * @fires {PointerEvent} pointerdown - Fired when a pointer button is pressed over the node.
10655
+ * @fires {PointerEvent} pointerup - Fired when a pointer button is released over the node.
10656
+ */
10657
+ class NodeElement extends EntityBaseElement {
10658
+ _name = '';
10659
+ _index = null;
10660
+ _state = 'pending';
10661
+ _path = null;
10662
+ /**
10663
+ * The element whose entity roots this element's search: the nearest ancestor `pc-node`, or
10664
+ * failing that the nearest ancestor `pc-model`. Resolved on connection.
10665
+ */
10666
+ _host = null;
10667
+ /**
10668
+ * The listener following the host's binding cycles. Both host kinds announce each cycle
10669
+ * with a `ready` event — `pc-model` on every instantiation, `pc-node` on every bind.
10670
+ */
10671
+ _hostListener = null;
10672
+ /**
10673
+ * The subscription to the bound entity's destruction, detached on unbind so a retargeted
10674
+ * element cannot be reset by the eventual death of a node it no longer fronts.
10675
+ */
10676
+ _destroyHandle = null;
10677
+ /** The authored values displaced by this element's overrides, captured per property. */
10678
+ _authored = {};
10679
+ // Override values. `null` means "no override": the authored value stays in force.
10680
+ _enabled = null;
10681
+ _position = null;
10682
+ _rotation = null;
10683
+ _scale = null;
10684
+ _tags = null;
10685
+ /**
10686
+ * The binding state: `pending` until the host instantiates and `name` resolves, `bound`
10687
+ * once decorated, `missing`/`ambiguous`/`duplicate` when resolution failed (each also
10688
+ * warns). Useful for asserting a document's bindings programmatically.
10689
+ * @returns The binding state.
10690
+ */
10691
+ get state() {
10692
+ return this._state;
10693
+ }
10694
+ /**
10695
+ * The path of the bound node below the search root, `/`-separated, or `null` while not
10696
+ * bound.
10697
+ * @returns The bound node's path, or `null`.
10698
+ */
10699
+ get path() {
10700
+ return this._path;
10701
+ }
10702
+ connectedCallback() {
10703
+ const host = (this.parentElement?.closest('pc-model, pc-node') ?? null);
10704
+ if (!host) {
10705
+ const label = this._name ? ` '${this._name}'` : '';
10706
+ console.warn(`pc-node${label} must be a descendant of pc-model - node not bound`);
10707
+ return;
10708
+ }
10709
+ this._host = host;
10710
+ // Follow the host's binding cycles. `ready` bubbles, so cycles of elements nested under
10711
+ // the host pass through it - only the host's own count.
10712
+ this._hostListener = (event) => {
10713
+ if (event.target !== this._host) {
10714
+ return;
10715
+ }
10716
+ this._rebind();
10717
+ };
10718
+ host.addEventListener('ready', this._hostListener);
10719
+ // The host may already be instantiated (an element inserted after load binds immediately)
10720
+ this._rebind();
10721
+ }
10722
+ disconnectedCallback() {
10723
+ if (this._host && this._hostListener) {
10724
+ this._host.removeEventListener('ready', this._hostListener);
10725
+ }
10726
+ this._host = null;
10727
+ this._hostListener = null;
10728
+ // Removal reverts: the model owns the node, so the entity is left as authored. Children
10729
+ // clean up through their own disconnect behavior.
10730
+ this._unbind();
10731
+ this._state = 'pending';
10732
+ }
10733
+ /**
10734
+ * Re-resolves the binding against the host's current hierarchy: on connection, on a `name`
10735
+ * or `index` change, and on every host cycle (a model [re]instantiating, an enclosing
10736
+ * `pc-node` [re]binding). When re-resolution yields the entity already bound, the binding
10737
+ * is retained untouched — a redundant edit must not flicker overrides through a revert.
10738
+ */
10739
+ _rebind() {
10740
+ const hostEntity = this._host?.entity ?? null;
10741
+ if (!hostEntity || !this._name) {
10742
+ // Host not instantiated (or nothing to look up yet): return to pending. An assigned
10743
+ // name arriving later, or the host's next cycle, resolves it.
10744
+ this._unbind();
10745
+ this._state = 'pending';
10746
+ return;
10747
+ }
10748
+ const target = this._resolve(hostEntity);
10749
+ if (target && target === this._entity) {
10750
+ this._path = this._pathOf(target, hostEntity);
10751
+ return;
10752
+ }
10753
+ this._unbind();
10754
+ if (!target) {
10755
+ // _resolve warned and set the failure state
10756
+ return;
10757
+ }
10758
+ this._bind(target, hostEntity);
10759
+ }
10760
+ /**
10761
+ * Resolves `name` (and `index`) to an entity under `hostEntity`, warning and recording the
10762
+ * failure state when it cannot.
10763
+ *
10764
+ * @param hostEntity - The root of the search.
10765
+ * @returns The resolved entity, or `null`.
10766
+ */
10767
+ _resolve(hostEntity) {
10768
+ const matches = hostEntity.find((node) => node.name === this._name);
10769
+ if (matches.length === 0) {
10770
+ const closest = this._closestName(hostEntity);
10771
+ const hint = closest ? ` - closest match: '${closest}'` : '';
10772
+ console.warn(`pc-node '${this._name}' not found in ${this._describeHost()}${hint}`);
10773
+ this._state = 'missing';
10774
+ return null;
10775
+ }
10776
+ let target;
10777
+ if (this._index !== null) {
10778
+ if (this._index >= matches.length) {
10779
+ console.warn(`pc-node '${this._name}' index ${this._index} is out of range - ${matches.length} match(es) in ${this._describeHost()}`);
10780
+ this._state = 'missing';
10781
+ return null;
10782
+ }
10783
+ target = matches[this._index];
10784
+ }
10785
+ else if (matches.length > 1) {
10786
+ // Ambiguity binds nothing: a fallback guess performs side effects on the wrong
10787
+ // scene node, and would go wrong silently when a re-export introduces a duplicate
10788
+ // name. The candidates tell the author exactly what to write.
10789
+ const candidates = matches.map((m, i) => `[${i}] ${this._pathOf(m, hostEntity)}`).join(', ');
10790
+ console.warn(`pc-node '${this._name}' is ambiguous in ${this._describeHost()} - specify index: ${candidates}`);
10791
+ this._state = 'ambiguous';
10792
+ return null;
10793
+ }
10794
+ else {
10795
+ target = matches[0];
10796
+ }
10797
+ const owner = this.closestApp?.elementFromEntity(target);
10798
+ if (owner && owner !== this) {
10799
+ console.warn(`pc-node '${this._name}' resolves to a node already bound by another element - element ignored`);
10800
+ this._state = 'duplicate';
10801
+ return null;
10802
+ }
10803
+ return target;
10804
+ }
10805
+ /**
10806
+ * Binds `target`: registers it (making it a pick target), hooks its destruction, applies
10807
+ * this element's overrides, announces readiness and builds the deferred child subtree.
10808
+ *
10809
+ * @param target - The entity to bind.
10810
+ * @param hostEntity - The search root, for the path.
10811
+ */
10812
+ _bind(target, hostEntity) {
10813
+ this._entity = target;
10814
+ this._registerEntity(target);
10815
+ this._destroyHandle = target.once('destroy', this._onEntityDestroy, this);
10816
+ this._state = 'bound';
10817
+ this._path = this._pathOf(target, hostEntity);
10818
+ this._applyOverrides();
10819
+ this._onReady();
10820
+ this._buildChildren();
10821
+ }
10822
+ /**
10823
+ * Dissolves the current binding, restoring every authored value this element's overrides
10824
+ * displaced and removing the decorations this binding hosts: attachment entities are
10825
+ * destroyed (re-created against the next binding) and component decorations are removed
10826
+ * from the abandoned node. Both sweeps are scoped by `closestEntity`, so a still-bound
10827
+ * nested `pc-node` keeps its own decorations. Safe to call in any state.
10828
+ */
10829
+ _unbind() {
10830
+ const entity = this._entity;
10831
+ if (!entity) {
10832
+ return;
10833
+ }
10834
+ this._revertOverrides();
10835
+ // Attachment points anchor to the bound node, so they cannot outlive the binding. Each
10836
+ // destroyed entity resets its element, which the next _buildChildren re-creates.
10837
+ this.querySelectorAll('pc-entity').forEach((child) => {
10838
+ if (child.closestEntity === this) {
10839
+ child.entity?.destroy();
10840
+ }
10841
+ });
10842
+ this._destroyHandle?.off();
10843
+ this._destroyHandle = null;
10844
+ this._unregisterEntity(entity);
10845
+ this._entity = null;
10846
+ this._path = null;
10847
+ this._authored = {};
10848
+ // Component decorations come off through the same hook the host-ready cycle uses. A
10849
+ // dissolve that never rebinds fires no ready event, so the sweep is explicit - after
10850
+ // `_entity` is cleared, so the hook sees a host without an entity.
10851
+ this.querySelectorAll('*').forEach((child) => {
10852
+ if (child instanceof ComponentElement && child.closestEntity === this) {
10853
+ child._hostCycled();
10854
+ }
10855
+ });
10856
+ this._resetReady();
10857
+ }
10858
+ /**
10859
+ * Handles the destruction of the bound entity - its model unloading, reloading, or a script
10860
+ * destroying it. There is nothing to revert on a destroyed entity; the element returns to
10861
+ * pending and the host's next cycle re-resolves it.
10862
+ */
10863
+ _onEntityDestroy(entity) {
10864
+ this._destroyHandle = null;
10865
+ this._unregisterEntity(entity);
10866
+ this._entity = null;
10867
+ this._path = null;
10868
+ this._authored = {};
10869
+ this._state = 'pending';
10870
+ this._resetReady();
10871
+ }
10872
+ /**
10873
+ * Creates and parents the entities of child `pc-entity` elements - the attachment points.
10874
+ * Mirrors the runtime-insertion path in EntityElement.connectedCallback: children were
10875
+ * deferred while this host was unresolved (or reset when a previous binding dissolved), and
10876
+ * build here once it binds.
10877
+ */
10878
+ _buildChildren() {
10879
+ const app = this.closestApp?.app;
10880
+ if (!app) {
10881
+ return;
10882
+ }
10883
+ const childEntities = this.querySelectorAll('pc-entity');
10884
+ childEntities.forEach((child) => {
10885
+ child._createEntity(app);
10886
+ });
10887
+ childEntities.forEach((child) => {
10888
+ child._buildHierarchy(app);
10889
+ });
10890
+ }
10891
+ /**
10892
+ * Applies every override that is explicitly set, capturing the authored value it displaces.
10893
+ */
10894
+ _applyOverrides() {
10895
+ if (this._enabled !== null) {
10896
+ this.enabled = this._enabled;
10897
+ }
10898
+ if (this._position !== null) {
10899
+ this.position = this._position;
10900
+ }
10901
+ if (this._rotation !== null) {
10902
+ this.rotation = this._rotation;
10903
+ }
10904
+ if (this._scale !== null) {
10905
+ this.scale = this._scale;
10906
+ }
10907
+ if (this._tags !== null) {
10908
+ this.tags = this._tags;
10909
+ }
10910
+ }
10911
+ /**
10912
+ * Restores every authored value this element's overrides displaced. The override values
10913
+ * themselves are kept - they re-apply on the next binding.
10914
+ */
10915
+ _revertOverrides() {
10916
+ const entity = this._entity;
10917
+ const authored = this._authored;
10918
+ if (authored.enabled !== undefined) {
10919
+ entity.enabled = authored.enabled;
10920
+ }
10921
+ if (authored.position) {
10922
+ entity.setLocalPosition(authored.position);
10923
+ }
10924
+ if (authored.rotation) {
10925
+ entity.setLocalRotation(authored.rotation);
10926
+ }
10927
+ if (authored.scale) {
10928
+ entity.setLocalScale(authored.scale);
10929
+ }
10930
+ if (authored.tags) {
10931
+ entity.tags.clear();
10932
+ entity.tags.add(authored.tags);
10933
+ }
10934
+ this._authored = {};
10935
+ }
10936
+ /**
10937
+ * Renders the path of `node` below `root`, for the `path` property and the resolution
10938
+ * warnings.
10939
+ *
10940
+ * @param node - The node to describe.
10941
+ * @param root - The search root.
10942
+ * @returns The `/`-separated path.
10943
+ */
10944
+ _pathOf(node, root) {
10945
+ const parts = [];
10946
+ for (let current = node; current && current !== root; current = current.parent) {
10947
+ parts.unshift(current.name);
10948
+ }
10949
+ return parts.join('/') || node.name;
10950
+ }
10951
+ /**
10952
+ * Describes the search root for warnings: the model's asset id, or the enclosing node's
10953
+ * name.
10954
+ * @returns The description.
10955
+ */
10956
+ _describeHost() {
10957
+ if (this._host instanceof ModelElement) {
10958
+ return `model '${this._host.asset}'`;
10959
+ }
10960
+ return `pc-node '${this._host?.name ?? ''}' subtree`;
10961
+ }
10962
+ /**
10963
+ * Finds the node name nearest to the missing `name`, for the miss warning. The names are
10964
+ * already in hand from resolution, so the suggestion is nearly free.
10965
+ *
10966
+ * @param hostEntity - The root of the search.
10967
+ * @returns The closest name within an edit distance of 2, or `null`.
10968
+ */
10969
+ _closestName(hostEntity) {
10970
+ let best = null;
10971
+ let bestDistance = 3;
10972
+ hostEntity.find((node) => {
10973
+ const distance = levenshtein(this._name, node.name);
10974
+ if (distance < bestDistance) {
10975
+ bestDistance = distance;
10976
+ best = node.name;
10977
+ }
10978
+ return false;
10979
+ });
10980
+ return best;
10981
+ }
10982
+ /**
10983
+ * Sets the name of the node to bind. A change retargets: the current binding's overrides
10984
+ * revert and the new name resolves afresh. `name` on a `pc-node` is never a rename of the
10985
+ * authored node - it is only ever a reference.
10986
+ * @param value - The node name.
10987
+ */
10988
+ set name(value) {
10989
+ this._name = value;
10990
+ if (this.isConnected && this._host) {
10991
+ this._rebind();
10992
+ }
10993
+ }
10994
+ /**
10995
+ * Gets the name of the node to bind.
10996
+ * @returns The node name.
10997
+ */
10998
+ get name() {
10999
+ return this._name;
11000
+ }
11001
+ /**
11002
+ * Sets which match to bind when `name` matches more than one node, 0-based in depth-first
11003
+ * order. A change retargets, like `name`. `null` means unset - required when the name is
11004
+ * ambiguous, optional otherwise.
11005
+ * @param value - The match index, or `null`.
11006
+ */
11007
+ set index(value) {
11008
+ this._index = value;
11009
+ if (this.isConnected && this._host) {
11010
+ this._rebind();
11011
+ }
11012
+ }
11013
+ /**
11014
+ * Gets which match to bind.
11015
+ * @returns The match index, or `null` when unset.
11016
+ */
11017
+ get index() {
11018
+ return this._index;
11019
+ }
11020
+ /**
11021
+ * Sets the enabled override. `null` clears it, restoring the authored state.
11022
+ * @param value - The enabled state, or `null`.
11023
+ */
11024
+ set enabled(value) {
11025
+ this._enabled = value;
11026
+ const entity = this._state === 'bound' ? this._entity : null;
11027
+ if (!entity) {
11028
+ return;
11029
+ }
11030
+ if (value !== null) {
11031
+ this._authored.enabled ??= entity.enabled;
11032
+ entity.enabled = value;
11033
+ }
11034
+ else if (this._authored.enabled !== undefined) {
11035
+ entity.enabled = this._authored.enabled;
11036
+ delete this._authored.enabled;
11037
+ }
11038
+ }
11039
+ /**
11040
+ * Gets the enabled override.
11041
+ * @returns The enabled state, or `null` while no override is set.
11042
+ */
11043
+ get enabled() {
11044
+ return this._enabled;
11045
+ }
11046
+ /**
11047
+ * Sets the local position override. `null` clears it, restoring the authored position.
11048
+ * @param value - The position, or `null`.
11049
+ */
11050
+ set position(value) {
11051
+ this._position = value;
11052
+ const entity = this._state === 'bound' ? this._entity : null;
11053
+ if (!entity) {
11054
+ return;
11055
+ }
11056
+ if (value !== null) {
11057
+ this._authored.position ??= entity.getLocalPosition().clone();
11058
+ entity.setLocalPosition(value);
11059
+ }
11060
+ else if (this._authored.position) {
11061
+ entity.setLocalPosition(this._authored.position);
11062
+ delete this._authored.position;
11063
+ }
11064
+ }
11065
+ /**
11066
+ * Gets the local position override.
11067
+ * @returns The position, or `null` while no override is set.
11068
+ */
11069
+ get position() {
11070
+ return this._position;
11071
+ }
11072
+ /**
11073
+ * Sets the local rotation override, as Euler angles in degrees. `null` clears it, restoring
11074
+ * the authored rotation.
11075
+ * @param value - The rotation, or `null`.
11076
+ */
11077
+ set rotation(value) {
11078
+ this._rotation = value;
11079
+ const entity = this._state === 'bound' ? this._entity : null;
11080
+ if (!entity) {
11081
+ return;
11082
+ }
11083
+ if (value !== null) {
11084
+ // The authored rotation is cached as a quaternion: it restores exactly, where a
11085
+ // round trip through Euler angles need not.
11086
+ this._authored.rotation ??= entity.getLocalRotation().clone();
11087
+ entity.setLocalEulerAngles(value);
11088
+ }
11089
+ else if (this._authored.rotation) {
11090
+ entity.setLocalRotation(this._authored.rotation);
11091
+ delete this._authored.rotation;
11092
+ }
11093
+ }
11094
+ /**
11095
+ * Gets the local rotation override.
11096
+ * @returns The rotation, or `null` while no override is set.
11097
+ */
11098
+ get rotation() {
11099
+ return this._rotation;
11100
+ }
11101
+ /**
11102
+ * Sets the local scale override. `null` clears it, restoring the authored scale.
11103
+ * @param value - The scale, or `null`.
11104
+ */
11105
+ set scale(value) {
11106
+ this._scale = value;
11107
+ const entity = this._state === 'bound' ? this._entity : null;
11108
+ if (!entity) {
11109
+ return;
11110
+ }
11111
+ if (value !== null) {
11112
+ this._authored.scale ??= entity.getLocalScale().clone();
11113
+ entity.setLocalScale(value);
11114
+ }
11115
+ else if (this._authored.scale) {
11116
+ entity.setLocalScale(this._authored.scale);
11117
+ delete this._authored.scale;
11118
+ }
11119
+ }
11120
+ /**
11121
+ * Gets the local scale override.
11122
+ * @returns The scale, or `null` while no override is set.
11123
+ */
11124
+ get scale() {
11125
+ return this._scale;
11126
+ }
11127
+ /**
11128
+ * Sets the tags override. `null` clears it, restoring the authored tags.
11129
+ * @param value - The tags, or `null`.
11130
+ */
11131
+ set tags(value) {
11132
+ this._tags = value;
11133
+ const entity = this._state === 'bound' ? this._entity : null;
11134
+ if (!entity) {
11135
+ return;
11136
+ }
11137
+ if (value !== null) {
11138
+ this._authored.tags ??= entity.tags.list().slice();
11139
+ entity.tags.clear();
11140
+ entity.tags.add(value);
11141
+ }
11142
+ else if (this._authored.tags) {
11143
+ entity.tags.clear();
11144
+ entity.tags.add(this._authored.tags);
11145
+ delete this._authored.tags;
11146
+ }
11147
+ }
11148
+ /**
11149
+ * Gets the tags override.
11150
+ * @returns The tags, or `null` while no override is set.
11151
+ */
11152
+ get tags() {
11153
+ return this._tags;
11154
+ }
11155
+ static get observedAttributes() {
11156
+ return ['enabled', 'index', 'name', 'position', 'rotation', 'scale', 'tags', ...POINTER_ATTRIBUTES];
11157
+ }
11158
+ attributeChangedCallback(name, _oldValue, newValue) {
11159
+ switch (name) {
11160
+ case 'enabled':
11161
+ this.enabled = newValue === null ? null : parseBool(newValue, true);
11162
+ break;
11163
+ case 'index':
11164
+ if (newValue === null) {
11165
+ this.index = null;
11166
+ }
11167
+ else {
11168
+ // Number('') is 0, which would make index="" silently mean the first match
11169
+ const index = newValue.trim() === '' ? NaN : Number(newValue);
11170
+ if (!Number.isInteger(index) || index < 0) {
11171
+ // Invalid values are treated as absent: under ambiguity that means
11172
+ // unbound, the fail-safe direction.
11173
+ console.warn(`pc-node index '${newValue}' is not a non-negative integer - treated as absent`);
11174
+ this.index = null;
11175
+ }
11176
+ else {
11177
+ this.index = index;
11178
+ }
11179
+ }
11180
+ break;
11181
+ case 'name':
11182
+ this.name = newValue ?? '';
11183
+ break;
11184
+ case 'position':
11185
+ this.position = newValue === null ? null : parseVec3(newValue, playcanvas.Vec3.ZERO, name);
11186
+ break;
11187
+ case 'rotation':
11188
+ this.rotation = newValue === null ? null : parseVec3(newValue, playcanvas.Vec3.ZERO, name);
11189
+ break;
11190
+ case 'scale':
11191
+ this.scale = newValue === null ? null : parseVec3(newValue, playcanvas.Vec3.ONE, name);
11192
+ break;
11193
+ case 'tags':
11194
+ this.tags = newValue === null ? null : parseTags(newValue);
11195
+ break;
11196
+ case 'onpointerenter':
11197
+ case 'onpointerleave':
11198
+ case 'onpointerdown':
11199
+ case 'onpointerup':
11200
+ case 'onpointermove':
11201
+ this._updateInlineHandler(name, newValue);
11202
+ break;
11203
+ }
11204
+ }
11205
+ }
11206
+ customElements.define('pc-node', NodeElement);
11207
+
10013
11208
  /**
10014
11209
  * The SceneElement interface provides properties and methods for manipulating
10015
11210
  * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-scene/ | `<pc-scene>`} elements.
@@ -10282,7 +11477,6 @@ class SkyElement extends AsyncElement {
10282
11477
  return;
10283
11478
  const source = asset.resource;
10284
11479
  const skybox = playcanvas.EnvLighting.generateSkyboxCubemap(source);
10285
- skybox.anisotropy = 4;
10286
11480
  // This element owns what it generated (see _unloadSkybox) - replacing a skybox from an
10287
11481
  // earlier load must release it, not orphan it on the GPU
10288
11482
  this._scene.skybox?.destroy();
@@ -10539,6 +11733,7 @@ exports.CameraComponentElement = CameraComponentElement;
10539
11733
  exports.CollisionComponentElement = CollisionComponentElement;
10540
11734
  exports.ComponentElement = ComponentElement;
10541
11735
  exports.ElementComponentElement = ElementComponentElement;
11736
+ exports.EntityBaseElement = EntityBaseElement;
10542
11737
  exports.EntityElement = EntityElement;
10543
11738
  exports.GSplatComponentElement = GSplatComponentElement;
10544
11739
  exports.LayoutChildComponentElement = LayoutChildComponentElement;
@@ -10548,6 +11743,7 @@ exports.ListenerComponentElement = ListenerComponentElement;
10548
11743
  exports.MaterialElement = MaterialElement;
10549
11744
  exports.ModelElement = ModelElement;
10550
11745
  exports.ModuleElement = ModuleElement;
11746
+ exports.NodeElement = NodeElement;
10551
11747
  exports.ParticleSystemComponentElement = ParticleSystemComponentElement;
10552
11748
  exports.RenderComponentElement = RenderComponentElement;
10553
11749
  exports.RigidBodyComponentElement = RigidBodyComponentElement;