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