@playcanvas/web-components 0.1.9 → 0.1.11
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/LICENSE +1 -1
- package/README.md +38 -6
- package/dist/app.d.ts +11 -0
- package/dist/components/camera-component.d.ts +37 -0
- package/dist/components/light-component.d.ts +46 -0
- package/dist/components/sound-component.d.ts +1 -1
- package/dist/entity.d.ts +7 -0
- package/dist/fog.d.ts +28 -0
- package/dist/pwc.cjs +451 -38
- package/dist/pwc.cjs.map +1 -1
- package/dist/pwc.js +451 -38
- 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.mjs +452 -39
- package/dist/pwc.mjs.map +1 -1
- package/package.json +16 -15
- package/src/app.ts +180 -1
- package/src/components/camera-component.ts +92 -3
- package/src/components/light-component.ts +103 -3
- package/src/components/script-component.ts +22 -13
- package/src/entity.ts +88 -1
- package/src/fog.ts +121 -0
- package/src/material.ts +2 -2
package/dist/pwc.js
CHANGED
|
@@ -17,11 +17,11 @@
|
|
|
17
17
|
}
|
|
18
18
|
get closestApp() {
|
|
19
19
|
var _a;
|
|
20
|
-
return (_a = this.parentElement) === null || _a ===
|
|
20
|
+
return (_a = this.parentElement) === null || _a === undefined ? undefined : _a.closest('pc-app');
|
|
21
21
|
}
|
|
22
22
|
get closestEntity() {
|
|
23
23
|
var _a;
|
|
24
|
-
return (_a = this.parentElement) === null || _a ===
|
|
24
|
+
return (_a = this.parentElement) === null || _a === undefined ? undefined : _a.closest('pc-entity');
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
27
27
|
* Called when the element is fully initialized and ready.
|
|
@@ -101,6 +101,20 @@
|
|
|
101
101
|
this._stencil = true;
|
|
102
102
|
this._highResolution = false;
|
|
103
103
|
this._hierarchyReady = false;
|
|
104
|
+
this._picker = null;
|
|
105
|
+
this._hasPointerListeners = {
|
|
106
|
+
pointerenter: false,
|
|
107
|
+
pointerleave: false,
|
|
108
|
+
pointerdown: false,
|
|
109
|
+
pointerup: false,
|
|
110
|
+
pointermove: false
|
|
111
|
+
};
|
|
112
|
+
this._hoveredEntity = null;
|
|
113
|
+
this._pointerHandlers = {
|
|
114
|
+
pointermove: null,
|
|
115
|
+
pointerdown: null,
|
|
116
|
+
pointerup: null
|
|
117
|
+
};
|
|
104
118
|
/**
|
|
105
119
|
* The PlayCanvas application instance.
|
|
106
120
|
*/
|
|
@@ -130,6 +144,7 @@
|
|
|
130
144
|
this.app.graphicsDevice.maxPixelRatio = this._highResolution ? window.devicePixelRatio : 1;
|
|
131
145
|
this.app.setCanvasFillMode(playcanvas.FILLMODE_FILL_WINDOW);
|
|
132
146
|
this.app.setCanvasResolution(playcanvas.RESOLUTION_AUTO);
|
|
147
|
+
this._pickerCreate();
|
|
133
148
|
// Get all pc-asset elements that are direct children of the pc-app element
|
|
134
149
|
const assetElements = this.querySelectorAll(':scope > pc-asset');
|
|
135
150
|
Array.from(assetElements).forEach((assetElement) => {
|
|
@@ -164,6 +179,7 @@
|
|
|
164
179
|
});
|
|
165
180
|
}
|
|
166
181
|
disconnectedCallback() {
|
|
182
|
+
this._pickerDestroy();
|
|
167
183
|
// Clean up the application
|
|
168
184
|
if (this.app) {
|
|
169
185
|
this.app.destroy();
|
|
@@ -182,6 +198,139 @@
|
|
|
182
198
|
this.app.resizeCanvas();
|
|
183
199
|
}
|
|
184
200
|
}
|
|
201
|
+
_pickerCreate() {
|
|
202
|
+
const { width, height } = this.app.graphicsDevice;
|
|
203
|
+
this._picker = new playcanvas.Picker(this.app, width, height);
|
|
204
|
+
// Create bound handlers but don't attach them yet
|
|
205
|
+
this._pointerHandlers.pointermove = this._onPointerMove.bind(this);
|
|
206
|
+
this._pointerHandlers.pointerdown = this._onPointerDown.bind(this);
|
|
207
|
+
this._pointerHandlers.pointerup = this._onPointerUp.bind(this);
|
|
208
|
+
// Listen for pointer listeners being added/removed
|
|
209
|
+
['pointermove', 'pointerdown', 'pointerup', 'pointerenter', 'pointerleave'].forEach((type) => {
|
|
210
|
+
this.addEventListener(`${type}:connect`, () => this._onPointerListenerAdded(type));
|
|
211
|
+
this.addEventListener(`${type}:disconnect`, () => this._onPointerListenerRemoved(type));
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
_pickerDestroy() {
|
|
215
|
+
if (this._canvas) {
|
|
216
|
+
Object.entries(this._pointerHandlers).forEach(([type, handler]) => {
|
|
217
|
+
if (handler) {
|
|
218
|
+
this._canvas.removeEventListener(type, handler);
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
this._picker = null;
|
|
223
|
+
this._pointerHandlers = {
|
|
224
|
+
pointermove: null,
|
|
225
|
+
pointerdown: null,
|
|
226
|
+
pointerup: null
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
_onPointerMove(event) {
|
|
230
|
+
if (!this._picker || !this.app)
|
|
231
|
+
return;
|
|
232
|
+
const camera = this.app.root.findComponent('camera');
|
|
233
|
+
if (!camera)
|
|
234
|
+
return;
|
|
235
|
+
const canvasRect = this._canvas.getBoundingClientRect();
|
|
236
|
+
const x = event.clientX - canvasRect.left;
|
|
237
|
+
const y = event.clientY - canvasRect.top;
|
|
238
|
+
this._picker.prepare(camera, this.app.scene);
|
|
239
|
+
const selection = this._picker.getSelection(x, y);
|
|
240
|
+
// Get the currently hovered entity by walking up the hierarchy
|
|
241
|
+
let newHoverEntity = null;
|
|
242
|
+
if (selection.length > 0) {
|
|
243
|
+
let node = selection[0].node;
|
|
244
|
+
while (node && !newHoverEntity) {
|
|
245
|
+
const entityElement = this.querySelector(`pc-entity[name="${node.name}"]`);
|
|
246
|
+
if (entityElement) {
|
|
247
|
+
newHoverEntity = entityElement;
|
|
248
|
+
}
|
|
249
|
+
node = node.parent;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
// Handle enter/leave events
|
|
253
|
+
if (this._hoveredEntity !== newHoverEntity) {
|
|
254
|
+
if (this._hoveredEntity && this._hoveredEntity.hasListeners('pointerleave')) {
|
|
255
|
+
this._hoveredEntity.dispatchEvent(new PointerEvent('pointerleave', event));
|
|
256
|
+
}
|
|
257
|
+
if (newHoverEntity && newHoverEntity.hasListeners('pointerenter')) {
|
|
258
|
+
newHoverEntity.dispatchEvent(new PointerEvent('pointerenter', event));
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
// Update hover state
|
|
262
|
+
this._hoveredEntity = newHoverEntity;
|
|
263
|
+
// Handle pointermove event
|
|
264
|
+
if (newHoverEntity && newHoverEntity.hasListeners('pointermove')) {
|
|
265
|
+
newHoverEntity.dispatchEvent(new PointerEvent('pointermove', event));
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
_onPointerDown(event) {
|
|
269
|
+
if (!this._picker || !this.app)
|
|
270
|
+
return;
|
|
271
|
+
const camera = this.app.root.findComponent('camera');
|
|
272
|
+
if (!camera)
|
|
273
|
+
return;
|
|
274
|
+
const canvasRect = this._canvas.getBoundingClientRect();
|
|
275
|
+
const x = event.clientX - canvasRect.left;
|
|
276
|
+
const y = event.clientY - canvasRect.top;
|
|
277
|
+
this._picker.prepare(camera, this.app.scene);
|
|
278
|
+
const selection = this._picker.getSelection(x, y);
|
|
279
|
+
if (selection.length > 0) {
|
|
280
|
+
let node = selection[0].node;
|
|
281
|
+
while (node) {
|
|
282
|
+
const entityElement = this.querySelector(`pc-entity[name="${node.name}"]`);
|
|
283
|
+
if (entityElement && entityElement.hasListeners('pointerdown')) {
|
|
284
|
+
entityElement.dispatchEvent(new PointerEvent('pointerdown', event));
|
|
285
|
+
break;
|
|
286
|
+
}
|
|
287
|
+
node = node.parent;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
_onPointerUp(event) {
|
|
292
|
+
if (!this._picker || !this.app)
|
|
293
|
+
return;
|
|
294
|
+
const camera = this.app.root.findComponent('camera');
|
|
295
|
+
if (!camera)
|
|
296
|
+
return;
|
|
297
|
+
const canvasRect = this._canvas.getBoundingClientRect();
|
|
298
|
+
const x = event.clientX - canvasRect.left;
|
|
299
|
+
const y = event.clientY - canvasRect.top;
|
|
300
|
+
this._picker.prepare(camera, this.app.scene);
|
|
301
|
+
const selection = this._picker.getSelection(x, y);
|
|
302
|
+
if (selection.length > 0) {
|
|
303
|
+
const entityElement = this.querySelector(`pc-entity[name="${selection[0].node.name}"]`);
|
|
304
|
+
if (entityElement && entityElement.hasListeners('pointerup')) {
|
|
305
|
+
entityElement.dispatchEvent(new PointerEvent('pointerup', event));
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
_onPointerListenerAdded(type) {
|
|
310
|
+
if (!this._hasPointerListeners[type] && this._canvas) {
|
|
311
|
+
this._hasPointerListeners[type] = true;
|
|
312
|
+
// For enter/leave events, we need the move handler
|
|
313
|
+
const handler = (type === 'pointerenter' || type === 'pointerleave') ?
|
|
314
|
+
this._pointerHandlers.pointermove :
|
|
315
|
+
this._pointerHandlers[type];
|
|
316
|
+
if (handler) {
|
|
317
|
+
this._canvas.addEventListener(type === 'pointerenter' || type === 'pointerleave' ? 'pointermove' : type, handler);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
_onPointerListenerRemoved(type) {
|
|
322
|
+
const hasListeners = Array.from(this.querySelectorAll('pc-entity'))
|
|
323
|
+
.some(entity => entity.hasListeners(type));
|
|
324
|
+
if (!hasListeners && this._canvas) {
|
|
325
|
+
this._hasPointerListeners[type] = false;
|
|
326
|
+
const handler = (type === 'pointerenter' || type === 'pointerleave') ?
|
|
327
|
+
this._pointerHandlers.pointermove :
|
|
328
|
+
this._pointerHandlers[type];
|
|
329
|
+
if (handler) {
|
|
330
|
+
this._canvas.removeEventListener(type === 'pointerenter' || type === 'pointerleave' ? 'pointermove' : type, handler);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
185
334
|
/**
|
|
186
335
|
* Sets the alpha flag.
|
|
187
336
|
* @param value - The alpha flag.
|
|
@@ -534,6 +683,10 @@
|
|
|
534
683
|
* The tags of the entity.
|
|
535
684
|
*/
|
|
536
685
|
this._tags = [];
|
|
686
|
+
/**
|
|
687
|
+
* The pointer event listeners for the entity.
|
|
688
|
+
*/
|
|
689
|
+
this._listeners = {};
|
|
537
690
|
/**
|
|
538
691
|
* The PlayCanvas entity instance.
|
|
539
692
|
*/
|
|
@@ -562,12 +715,36 @@
|
|
|
562
715
|
if (tags) {
|
|
563
716
|
this.entity.tags.add(tags.split(',').map(tag => tag.trim()));
|
|
564
717
|
}
|
|
718
|
+
// Handle pointer events
|
|
719
|
+
const pointerEvents = [
|
|
720
|
+
'onpointerenter',
|
|
721
|
+
'onpointerleave',
|
|
722
|
+
'onpointerdown',
|
|
723
|
+
'onpointerup',
|
|
724
|
+
'onpointermove'
|
|
725
|
+
];
|
|
726
|
+
pointerEvents.forEach((eventName) => {
|
|
727
|
+
const handler = this.getAttribute(eventName);
|
|
728
|
+
if (handler) {
|
|
729
|
+
const eventType = eventName.substring(2); // remove 'on' prefix
|
|
730
|
+
const eventHandler = (event) => {
|
|
731
|
+
try {
|
|
732
|
+
/* eslint-disable-next-line no-new-func */
|
|
733
|
+
new Function('event', handler).call(this, event);
|
|
734
|
+
}
|
|
735
|
+
catch (e) {
|
|
736
|
+
console.error('Error in event handler:', e);
|
|
737
|
+
}
|
|
738
|
+
};
|
|
739
|
+
this.addEventListener(eventType, eventHandler);
|
|
740
|
+
}
|
|
741
|
+
});
|
|
565
742
|
}
|
|
566
743
|
buildHierarchy(app) {
|
|
567
744
|
if (!this.entity)
|
|
568
745
|
return;
|
|
569
746
|
const closestEntity = this.closestEntity;
|
|
570
|
-
if (closestEntity === null || closestEntity ===
|
|
747
|
+
if (closestEntity === null || closestEntity === undefined ? undefined : closestEntity.entity) {
|
|
571
748
|
closestEntity.entity.addChild(this.entity);
|
|
572
749
|
}
|
|
573
750
|
else {
|
|
@@ -711,7 +888,19 @@
|
|
|
711
888
|
return this._tags;
|
|
712
889
|
}
|
|
713
890
|
static get observedAttributes() {
|
|
714
|
-
return [
|
|
891
|
+
return [
|
|
892
|
+
'enabled',
|
|
893
|
+
'name',
|
|
894
|
+
'position',
|
|
895
|
+
'rotation',
|
|
896
|
+
'scale',
|
|
897
|
+
'tags',
|
|
898
|
+
'onpointerenter',
|
|
899
|
+
'onpointerleave',
|
|
900
|
+
'onpointerdown',
|
|
901
|
+
'onpointerup',
|
|
902
|
+
'onpointermove'
|
|
903
|
+
];
|
|
715
904
|
}
|
|
716
905
|
attributeChangedCallback(name, _oldValue, newValue) {
|
|
717
906
|
switch (name) {
|
|
@@ -733,7 +922,51 @@
|
|
|
733
922
|
case 'tags':
|
|
734
923
|
this.tags = newValue.split(',').map(tag => tag.trim());
|
|
735
924
|
break;
|
|
925
|
+
case 'onpointerenter':
|
|
926
|
+
case 'onpointerleave':
|
|
927
|
+
case 'onpointerdown':
|
|
928
|
+
case 'onpointerup':
|
|
929
|
+
case 'onpointermove':
|
|
930
|
+
if (newValue) {
|
|
931
|
+
const eventName = name.substring(2);
|
|
932
|
+
// Use Function.prototype.bind to avoid new Function
|
|
933
|
+
const handler = (event) => {
|
|
934
|
+
try {
|
|
935
|
+
const handlerStr = this.getAttribute(eventName) || '';
|
|
936
|
+
/* eslint-disable-next-line no-new-func */
|
|
937
|
+
new Function('event', handlerStr).call(this, event);
|
|
938
|
+
}
|
|
939
|
+
catch (e) {
|
|
940
|
+
console.error('Error in event handler:', e);
|
|
941
|
+
}
|
|
942
|
+
};
|
|
943
|
+
this.addEventListener(eventName, handler);
|
|
944
|
+
}
|
|
945
|
+
break;
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
addEventListener(type, listener, options) {
|
|
949
|
+
if (!this._listeners[type]) {
|
|
950
|
+
this._listeners[type] = [];
|
|
951
|
+
}
|
|
952
|
+
this._listeners[type].push(listener);
|
|
953
|
+
super.addEventListener(type, listener, options);
|
|
954
|
+
if (type.startsWith('pointer')) {
|
|
955
|
+
this.dispatchEvent(new CustomEvent(`${type}:connect`, { bubbles: true }));
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
removeEventListener(type, listener, options) {
|
|
959
|
+
if (this._listeners[type]) {
|
|
960
|
+
this._listeners[type] = this._listeners[type].filter(l => l !== listener);
|
|
736
961
|
}
|
|
962
|
+
super.removeEventListener(type, listener, options);
|
|
963
|
+
if (type.startsWith('pointer')) {
|
|
964
|
+
this.dispatchEvent(new CustomEvent(`${type}:disconnect`, { bubbles: true }));
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
hasListeners(type) {
|
|
968
|
+
var _a;
|
|
969
|
+
return Boolean((_a = this._listeners[type]) === null || _a === undefined ? undefined : _a.length);
|
|
737
970
|
}
|
|
738
971
|
}
|
|
739
972
|
customElements.define('pc-entity', EntityElement);
|
|
@@ -782,7 +1015,7 @@
|
|
|
782
1015
|
// If no type is specified, try to infer it from the file extension.
|
|
783
1016
|
if (!type) {
|
|
784
1017
|
const ext = src.split('.').pop();
|
|
785
|
-
type = (_a = extToType.get(ext || '')) !== null && _a !==
|
|
1018
|
+
type = (_a = extToType.get(ext || '')) !== null && _a !== undefined ? _a : null;
|
|
786
1019
|
}
|
|
787
1020
|
if (!type) {
|
|
788
1021
|
console.warn(`Unsupported asset type: ${src}`);
|
|
@@ -816,7 +1049,7 @@
|
|
|
816
1049
|
}
|
|
817
1050
|
static get(id) {
|
|
818
1051
|
const assetElement = document.querySelector(`pc-asset[id="${id}"]`);
|
|
819
|
-
return assetElement === null || assetElement ===
|
|
1052
|
+
return assetElement === null || assetElement === undefined ? undefined : assetElement.asset;
|
|
820
1053
|
}
|
|
821
1054
|
static get observedAttributes() {
|
|
822
1055
|
return ['preload'];
|
|
@@ -863,7 +1096,7 @@
|
|
|
863
1096
|
initComponent() { }
|
|
864
1097
|
async connectedCallback() {
|
|
865
1098
|
var _a;
|
|
866
|
-
await ((_a = this.closestApp) === null || _a ===
|
|
1099
|
+
await ((_a = this.closestApp) === null || _a === undefined ? undefined : _a.ready());
|
|
867
1100
|
await this.addComponent();
|
|
868
1101
|
this.initComponent();
|
|
869
1102
|
this._onReady();
|
|
@@ -929,6 +1162,15 @@
|
|
|
929
1162
|
}
|
|
930
1163
|
customElements.define('pc-listener', ListenerComponentElement);
|
|
931
1164
|
|
|
1165
|
+
const tonemaps = new Map([
|
|
1166
|
+
['none', playcanvas.TONEMAP_NONE],
|
|
1167
|
+
['linear', playcanvas.TONEMAP_LINEAR],
|
|
1168
|
+
['filmic', playcanvas.TONEMAP_FILMIC],
|
|
1169
|
+
['hejl', playcanvas.TONEMAP_HEJL],
|
|
1170
|
+
['aces', playcanvas.TONEMAP_ACES],
|
|
1171
|
+
['aces2', playcanvas.TONEMAP_ACES2],
|
|
1172
|
+
['neutral', playcanvas.TONEMAP_NEUTRAL]
|
|
1173
|
+
]);
|
|
932
1174
|
/**
|
|
933
1175
|
* The CameraComponentElement interface provides properties and methods for manipulating
|
|
934
1176
|
* `<pc-camera>` elements. The CameraComponentElement interface also inherits the properties and
|
|
@@ -949,12 +1191,15 @@
|
|
|
949
1191
|
this._flipFaces = false;
|
|
950
1192
|
this._fov = 45;
|
|
951
1193
|
this._frustumCulling = true;
|
|
1194
|
+
this._gamma = 'srgb';
|
|
1195
|
+
this._horizontalFov = false;
|
|
952
1196
|
this._nearClip = 0.1;
|
|
953
1197
|
this._orthographic = false;
|
|
954
1198
|
this._orthoHeight = 10;
|
|
955
1199
|
this._priority = 0;
|
|
956
1200
|
this._rect = new playcanvas.Vec4(0, 0, 1, 1);
|
|
957
1201
|
this._scissorRect = new playcanvas.Vec4(0, 0, 1, 1);
|
|
1202
|
+
this._tonemap = 'none';
|
|
958
1203
|
}
|
|
959
1204
|
getInitialComponentData() {
|
|
960
1205
|
return {
|
|
@@ -967,17 +1212,20 @@
|
|
|
967
1212
|
flipFaces: this._flipFaces,
|
|
968
1213
|
fov: this._fov,
|
|
969
1214
|
frustumCulling: this._frustumCulling,
|
|
1215
|
+
gammaCorrection: this._gamma === 'srgb' ? playcanvas.GAMMA_SRGB : playcanvas.GAMMA_NONE,
|
|
1216
|
+
horizontalFov: this._horizontalFov,
|
|
970
1217
|
nearClip: this._nearClip,
|
|
971
1218
|
orthographic: this._orthographic,
|
|
972
1219
|
orthoHeight: this._orthoHeight,
|
|
973
1220
|
priority: this._priority,
|
|
974
1221
|
rect: this._rect,
|
|
975
|
-
scissorRect: this._scissorRect
|
|
1222
|
+
scissorRect: this._scissorRect,
|
|
1223
|
+
toneMapping: tonemaps.get(this._tonemap)
|
|
976
1224
|
};
|
|
977
1225
|
}
|
|
978
1226
|
get xrAvailable() {
|
|
979
1227
|
var _a;
|
|
980
|
-
const xrManager = (_a = this.component) === null || _a ===
|
|
1228
|
+
const xrManager = (_a = this.component) === null || _a === undefined ? undefined : _a.system.app.xr;
|
|
981
1229
|
return xrManager && xrManager.supported && xrManager.isAvailable(playcanvas.XRTYPE_VR);
|
|
982
1230
|
}
|
|
983
1231
|
startXr(type, space) {
|
|
@@ -1155,6 +1403,41 @@
|
|
|
1155
1403
|
get frustumCulling() {
|
|
1156
1404
|
return this._frustumCulling;
|
|
1157
1405
|
}
|
|
1406
|
+
/**
|
|
1407
|
+
* Sets the gamma correction of the camera.
|
|
1408
|
+
* @param value - The gamma correction.
|
|
1409
|
+
*/
|
|
1410
|
+
set gamma(value) {
|
|
1411
|
+
this._gamma = value;
|
|
1412
|
+
if (this.component) {
|
|
1413
|
+
this.component.gammaCorrection = value === 'srgb' ? playcanvas.GAMMA_SRGB : playcanvas.GAMMA_NONE;
|
|
1414
|
+
}
|
|
1415
|
+
}
|
|
1416
|
+
/**
|
|
1417
|
+
* Gets the gamma correction of the camera.
|
|
1418
|
+
* @returns The gamma correction.
|
|
1419
|
+
*/
|
|
1420
|
+
get gamma() {
|
|
1421
|
+
return this._gamma;
|
|
1422
|
+
}
|
|
1423
|
+
/**
|
|
1424
|
+
* Sets whether the camera's field of view (fov) is horizontal or vertical. Defaults to false
|
|
1425
|
+
* (meaning it is vertical be default).
|
|
1426
|
+
* @param value - Whether the camera's field of view is horizontal.
|
|
1427
|
+
*/
|
|
1428
|
+
set horizontalFov(value) {
|
|
1429
|
+
this._horizontalFov = value;
|
|
1430
|
+
if (this.component) {
|
|
1431
|
+
this.component.horizontalFov = value;
|
|
1432
|
+
}
|
|
1433
|
+
}
|
|
1434
|
+
/**
|
|
1435
|
+
* Gets whether the camera's field of view (fov) is horizontal or vertical.
|
|
1436
|
+
* @returns Whether the camera's field of view is horizontal.
|
|
1437
|
+
*/
|
|
1438
|
+
get horizontalFov() {
|
|
1439
|
+
return this._horizontalFov;
|
|
1440
|
+
}
|
|
1158
1441
|
/**
|
|
1159
1442
|
* Sets the near clip distance of the camera.
|
|
1160
1443
|
* @param value - The near clip distance.
|
|
@@ -1257,6 +1540,24 @@
|
|
|
1257
1540
|
get scissorRect() {
|
|
1258
1541
|
return this._scissorRect;
|
|
1259
1542
|
}
|
|
1543
|
+
/**
|
|
1544
|
+
* Sets the tone mapping of the camera.
|
|
1545
|
+
* @param value - The tone mapping.
|
|
1546
|
+
*/
|
|
1547
|
+
set tonemap(value) {
|
|
1548
|
+
var _a;
|
|
1549
|
+
this._tonemap = value;
|
|
1550
|
+
if (this.component) {
|
|
1551
|
+
this.component.toneMapping = (_a = tonemaps.get(value)) !== null && _a !== undefined ? _a : playcanvas.TONEMAP_NONE;
|
|
1552
|
+
}
|
|
1553
|
+
}
|
|
1554
|
+
/**
|
|
1555
|
+
* Gets the tone mapping of the camera.
|
|
1556
|
+
* @returns The tone mapping.
|
|
1557
|
+
*/
|
|
1558
|
+
get tonemap() {
|
|
1559
|
+
return this._tonemap;
|
|
1560
|
+
}
|
|
1260
1561
|
static get observedAttributes() {
|
|
1261
1562
|
return [
|
|
1262
1563
|
...super.observedAttributes,
|
|
@@ -1269,12 +1570,15 @@
|
|
|
1269
1570
|
'flip-faces',
|
|
1270
1571
|
'fov',
|
|
1271
1572
|
'frustum-culling',
|
|
1573
|
+
'gamma',
|
|
1574
|
+
'horizontal-fov',
|
|
1272
1575
|
'near-clip',
|
|
1273
1576
|
'orthographic',
|
|
1274
1577
|
'ortho-height',
|
|
1275
1578
|
'priority',
|
|
1276
1579
|
'rect',
|
|
1277
|
-
'scissor-rect'
|
|
1580
|
+
'scissor-rect',
|
|
1581
|
+
'tonemap'
|
|
1278
1582
|
];
|
|
1279
1583
|
}
|
|
1280
1584
|
attributeChangedCallback(name, _oldValue, newValue) {
|
|
@@ -1307,6 +1611,12 @@
|
|
|
1307
1611
|
case 'frustum-culling':
|
|
1308
1612
|
this.frustumCulling = newValue !== 'false';
|
|
1309
1613
|
break;
|
|
1614
|
+
case 'gamma':
|
|
1615
|
+
this.gamma = newValue;
|
|
1616
|
+
break;
|
|
1617
|
+
case 'horizontal-fov':
|
|
1618
|
+
this.horizontalFov = this.hasAttribute('horizontal-fov');
|
|
1619
|
+
break;
|
|
1310
1620
|
case 'near-clip':
|
|
1311
1621
|
this.nearClip = parseFloat(newValue);
|
|
1312
1622
|
break;
|
|
@@ -1325,6 +1635,9 @@
|
|
|
1325
1635
|
case 'scissor-rect':
|
|
1326
1636
|
this.scissorRect = parseVec4(newValue);
|
|
1327
1637
|
break;
|
|
1638
|
+
case 'tonemap':
|
|
1639
|
+
this.tonemap = newValue;
|
|
1640
|
+
break;
|
|
1328
1641
|
}
|
|
1329
1642
|
}
|
|
1330
1643
|
}
|
|
@@ -1738,6 +2051,17 @@
|
|
|
1738
2051
|
}
|
|
1739
2052
|
customElements.define('pc-splat', GSplatComponentElement);
|
|
1740
2053
|
|
|
2054
|
+
const shadowTypes = new Map([
|
|
2055
|
+
['pcf1-16f', playcanvas.SHADOW_PCF1_16F],
|
|
2056
|
+
['pcf1-32f', playcanvas.SHADOW_PCF1_32F],
|
|
2057
|
+
['pcf3-16f', playcanvas.SHADOW_PCF3_16F],
|
|
2058
|
+
['pcf3-32f', playcanvas.SHADOW_PCF3_32F],
|
|
2059
|
+
['pcf5-16f', playcanvas.SHADOW_PCF5_16F],
|
|
2060
|
+
['pcf5-32f', playcanvas.SHADOW_PCF5_32F],
|
|
2061
|
+
['vsm-16f', playcanvas.SHADOW_VSM_16F],
|
|
2062
|
+
['vsm-32f', playcanvas.SHADOW_VSM_32F],
|
|
2063
|
+
['pcss-32f', playcanvas.SHADOW_PCSS_32F]
|
|
2064
|
+
]);
|
|
1741
2065
|
/**
|
|
1742
2066
|
* The LightComponentElement interface provides properties and methods for manipulating
|
|
1743
2067
|
* `<pc-light>` elements. The LightComponentElement interface also inherits the properties and
|
|
@@ -1758,8 +2082,11 @@
|
|
|
1758
2082
|
this._range = 10;
|
|
1759
2083
|
this._shadowBias = 0.2;
|
|
1760
2084
|
this._shadowDistance = 16;
|
|
2085
|
+
this._shadowIntensity = 1;
|
|
1761
2086
|
this._shadowResolution = 1024;
|
|
2087
|
+
this._shadowType = 'pcf3-32f';
|
|
1762
2088
|
this._type = 'directional';
|
|
2089
|
+
this._vsmBias = 0.01;
|
|
1763
2090
|
}
|
|
1764
2091
|
getInitialComponentData() {
|
|
1765
2092
|
return {
|
|
@@ -1772,8 +2099,11 @@
|
|
|
1772
2099
|
range: this._range,
|
|
1773
2100
|
shadowBias: this._shadowBias,
|
|
1774
2101
|
shadowDistance: this._shadowDistance,
|
|
2102
|
+
shadowIntensity: this._shadowIntensity,
|
|
1775
2103
|
shadowResolution: this._shadowResolution,
|
|
1776
|
-
|
|
2104
|
+
shadowType: shadowTypes.get(this._shadowType),
|
|
2105
|
+
type: this._type,
|
|
2106
|
+
vsmBias: this._vsmBias
|
|
1777
2107
|
};
|
|
1778
2108
|
}
|
|
1779
2109
|
/**
|
|
@@ -1936,6 +2266,23 @@
|
|
|
1936
2266
|
get shadowDistance() {
|
|
1937
2267
|
return this._shadowDistance;
|
|
1938
2268
|
}
|
|
2269
|
+
/**
|
|
2270
|
+
* Sets the shadow intensity of the light.
|
|
2271
|
+
* @param value - The shadow intensity.
|
|
2272
|
+
*/
|
|
2273
|
+
set shadowIntensity(value) {
|
|
2274
|
+
this._shadowIntensity = value;
|
|
2275
|
+
if (this.component) {
|
|
2276
|
+
this.component.shadowIntensity = value;
|
|
2277
|
+
}
|
|
2278
|
+
}
|
|
2279
|
+
/**
|
|
2280
|
+
* Gets the shadow intensity of the light.
|
|
2281
|
+
* @returns The shadow intensity.
|
|
2282
|
+
*/
|
|
2283
|
+
get shadowIntensity() {
|
|
2284
|
+
return this._shadowIntensity;
|
|
2285
|
+
}
|
|
1939
2286
|
/**
|
|
1940
2287
|
* Sets the shadow resolution of the light.
|
|
1941
2288
|
* @param value - The shadow resolution.
|
|
@@ -1953,6 +2300,34 @@
|
|
|
1953
2300
|
get shadowResolution() {
|
|
1954
2301
|
return this._shadowResolution;
|
|
1955
2302
|
}
|
|
2303
|
+
/**
|
|
2304
|
+
* Sets the shadow type of the light.
|
|
2305
|
+
* @param value - The shadow type. Can be:
|
|
2306
|
+
*
|
|
2307
|
+
* - `pcf1-16f` - 1-tap percentage-closer filtered shadow map with 16-bit depth.
|
|
2308
|
+
* - `pcf1-32f` - 1-tap percentage-closer filtered shadow map with 32-bit depth.
|
|
2309
|
+
* - `pcf3-16f` - 3-tap percentage-closer filtered shadow map with 16-bit depth.
|
|
2310
|
+
* - `pcf3-32f` - 3-tap percentage-closer filtered shadow map with 32-bit depth.
|
|
2311
|
+
* - `pcf5-16f` - 5-tap percentage-closer filtered shadow map with 16-bit depth.
|
|
2312
|
+
* - `pcf5-32f` - 5-tap percentage-closer filtered shadow map with 32-bit depth.
|
|
2313
|
+
* - `vsm-16f` - Variance shadow map with 16-bit depth.
|
|
2314
|
+
* - `vsm-32f` - Variance shadow map with 32-bit depth.
|
|
2315
|
+
* - `pcss-32f` - Percentage-closer soft shadow with 32-bit depth.
|
|
2316
|
+
*/
|
|
2317
|
+
set shadowType(value) {
|
|
2318
|
+
var _a;
|
|
2319
|
+
this._shadowType = value;
|
|
2320
|
+
if (this.component) {
|
|
2321
|
+
this.component.shadowType = (_a = shadowTypes.get(value)) !== null && _a !== undefined ? _a : playcanvas.SHADOW_PCF3_32F;
|
|
2322
|
+
}
|
|
2323
|
+
}
|
|
2324
|
+
/**
|
|
2325
|
+
* Gets the shadow type of the light.
|
|
2326
|
+
* @returns The shadow type.
|
|
2327
|
+
*/
|
|
2328
|
+
get shadowType() {
|
|
2329
|
+
return this._shadowType;
|
|
2330
|
+
}
|
|
1956
2331
|
/**
|
|
1957
2332
|
* Sets the type of the light.
|
|
1958
2333
|
* @param value - The type.
|
|
@@ -1974,6 +2349,23 @@
|
|
|
1974
2349
|
get type() {
|
|
1975
2350
|
return this._type;
|
|
1976
2351
|
}
|
|
2352
|
+
/**
|
|
2353
|
+
* Sets the VSM bias of the light.
|
|
2354
|
+
* @param value - The VSM bias.
|
|
2355
|
+
*/
|
|
2356
|
+
set vsmBias(value) {
|
|
2357
|
+
this._vsmBias = value;
|
|
2358
|
+
if (this.component) {
|
|
2359
|
+
this.component.vsmBias = value;
|
|
2360
|
+
}
|
|
2361
|
+
}
|
|
2362
|
+
/**
|
|
2363
|
+
* Gets the VSM bias of the light.
|
|
2364
|
+
* @returns The VSM bias.
|
|
2365
|
+
*/
|
|
2366
|
+
get vsmBias() {
|
|
2367
|
+
return this._vsmBias;
|
|
2368
|
+
}
|
|
1977
2369
|
static get observedAttributes() {
|
|
1978
2370
|
return [
|
|
1979
2371
|
...super.observedAttributes,
|
|
@@ -1986,8 +2378,11 @@
|
|
|
1986
2378
|
'range',
|
|
1987
2379
|
'shadow-bias',
|
|
1988
2380
|
'shadow-distance',
|
|
2381
|
+
'shadow-intensity',
|
|
1989
2382
|
'shadow-resolution',
|
|
1990
|
-
'type'
|
|
2383
|
+
'shadow-type',
|
|
2384
|
+
'type',
|
|
2385
|
+
'vsm-bias'
|
|
1991
2386
|
];
|
|
1992
2387
|
}
|
|
1993
2388
|
attributeChangedCallback(name, _oldValue, newValue) {
|
|
@@ -2023,9 +2418,18 @@
|
|
|
2023
2418
|
case 'shadow-resolution':
|
|
2024
2419
|
this.shadowResolution = Number(newValue);
|
|
2025
2420
|
break;
|
|
2421
|
+
case 'shadow-intensity':
|
|
2422
|
+
this.shadowIntensity = Number(newValue);
|
|
2423
|
+
break;
|
|
2424
|
+
case 'shadow-type':
|
|
2425
|
+
this.shadowType = newValue;
|
|
2426
|
+
break;
|
|
2026
2427
|
case 'type':
|
|
2027
2428
|
this.type = newValue;
|
|
2028
2429
|
break;
|
|
2430
|
+
case 'vsm-bias':
|
|
2431
|
+
this.vsmBias = Number(newValue);
|
|
2432
|
+
break;
|
|
2029
2433
|
}
|
|
2030
2434
|
}
|
|
2031
2435
|
}
|
|
@@ -2048,8 +2452,8 @@
|
|
|
2048
2452
|
}
|
|
2049
2453
|
createMaterial() {
|
|
2050
2454
|
this.material = new playcanvas.StandardMaterial();
|
|
2051
|
-
this.material.glossInvert =
|
|
2052
|
-
this.material.useMetalness =
|
|
2455
|
+
this.material.glossInvert = false;
|
|
2456
|
+
this.material.useMetalness = false;
|
|
2053
2457
|
this.material.diffuse = this._diffuse;
|
|
2054
2458
|
this.diffuseMap = this._diffuseMap;
|
|
2055
2459
|
this.metalnessMap = this._metalnessMap;
|
|
@@ -2120,7 +2524,7 @@
|
|
|
2120
2524
|
}
|
|
2121
2525
|
static get(id) {
|
|
2122
2526
|
const materialElement = document.querySelector(`pc-material[id="${id}"]`);
|
|
2123
|
-
return materialElement === null || materialElement ===
|
|
2527
|
+
return materialElement === null || materialElement === undefined ? undefined : materialElement.material;
|
|
2124
2528
|
}
|
|
2125
2529
|
static get observedAttributes() {
|
|
2126
2530
|
return ['diffuse', 'diffuse-map', 'metalness-map', 'normal-map', 'roughness-map'];
|
|
@@ -2582,9 +2986,6 @@
|
|
|
2582
2986
|
}
|
|
2583
2987
|
customElements.define('pc-screen', ScreenComponentElement);
|
|
2584
2988
|
|
|
2585
|
-
const tmpV2 = new playcanvas.Vec2();
|
|
2586
|
-
const tmpV3 = new playcanvas.Vec3();
|
|
2587
|
-
const tmpV4 = new playcanvas.Vec4();
|
|
2588
2989
|
/**
|
|
2589
2990
|
* The ScriptComponentElement interface provides properties and methods for manipulating
|
|
2590
2991
|
* `<pc-scripts>` elements. The ScriptComponentElement interface also inherits the properties and
|
|
@@ -2628,22 +3029,34 @@
|
|
|
2628
3029
|
return;
|
|
2629
3030
|
}
|
|
2630
3031
|
}
|
|
2631
|
-
// Handle
|
|
2632
|
-
if (Array.isArray(value)) {
|
|
2633
|
-
|
|
2634
|
-
|
|
3032
|
+
// Handle arrays
|
|
3033
|
+
if (value && typeof value === 'object' && Array.isArray(value)) {
|
|
3034
|
+
// If it's an array of objects, recursively apply to each object
|
|
3035
|
+
if (value.length > 0 && typeof value[0] === 'object') {
|
|
3036
|
+
target[key] = value.map((item) => {
|
|
3037
|
+
const obj = {};
|
|
3038
|
+
for (const itemKey in item) {
|
|
3039
|
+
applyValue(obj, itemKey, item[itemKey]);
|
|
3040
|
+
}
|
|
3041
|
+
return obj;
|
|
3042
|
+
});
|
|
3043
|
+
return;
|
|
3044
|
+
}
|
|
3045
|
+
// Handle vectors
|
|
3046
|
+
if (value.length === 2 && typeof value[0] === 'number') {
|
|
3047
|
+
target[key] = new playcanvas.Vec2(value[0], value[1]);
|
|
2635
3048
|
return;
|
|
2636
3049
|
}
|
|
2637
|
-
if (
|
|
2638
|
-
target[key] =
|
|
3050
|
+
if (value.length === 3 && typeof value[0] === 'number') {
|
|
3051
|
+
target[key] = new playcanvas.Vec3(value[0], value[1], value[2]);
|
|
2639
3052
|
return;
|
|
2640
3053
|
}
|
|
2641
|
-
if (
|
|
2642
|
-
target[key] =
|
|
3054
|
+
if (value.length === 4 && typeof value[0] === 'number') {
|
|
3055
|
+
target[key] = new playcanvas.Vec4(value[0], value[1], value[2], value[3]);
|
|
2643
3056
|
return;
|
|
2644
3057
|
}
|
|
2645
3058
|
}
|
|
2646
|
-
// Handle nested objects
|
|
3059
|
+
// Handle nested objects (non-array)
|
|
2647
3060
|
if (value && typeof value === 'object' && !Array.isArray(value)) {
|
|
2648
3061
|
if (!target[key] || typeof target[key] !== 'object') {
|
|
2649
3062
|
target[key] = {};
|
|
@@ -2723,7 +3136,7 @@
|
|
|
2723
3136
|
disconnectedCallback() {
|
|
2724
3137
|
var _a;
|
|
2725
3138
|
this.observer.disconnect();
|
|
2726
|
-
(_a = super.disconnectedCallback) === null || _a ===
|
|
3139
|
+
(_a = super.disconnectedCallback) === null || _a === undefined ? undefined : _a.call(this);
|
|
2727
3140
|
}
|
|
2728
3141
|
/**
|
|
2729
3142
|
* Gets the script component.
|
|
@@ -3037,7 +3450,7 @@
|
|
|
3037
3450
|
}
|
|
3038
3451
|
async connectedCallback() {
|
|
3039
3452
|
var _a;
|
|
3040
|
-
await ((_a = this.soundElement) === null || _a ===
|
|
3453
|
+
await ((_a = this.soundElement) === null || _a === undefined ? undefined : _a.ready());
|
|
3041
3454
|
const options = {
|
|
3042
3455
|
autoPlay: this._autoPlay,
|
|
3043
3456
|
loop: this._loop,
|
|
@@ -3073,7 +3486,7 @@
|
|
|
3073
3486
|
var _a;
|
|
3074
3487
|
this._asset = value;
|
|
3075
3488
|
if (this.soundSlot) {
|
|
3076
|
-
const id = (_a = AssetElement.get(value)) === null || _a ===
|
|
3489
|
+
const id = (_a = AssetElement.get(value)) === null || _a === undefined ? undefined : _a.id;
|
|
3077
3490
|
if (id) {
|
|
3078
3491
|
this.soundSlot.asset = id;
|
|
3079
3492
|
}
|
|
@@ -3300,8 +3713,8 @@
|
|
|
3300
3713
|
async _loadModel() {
|
|
3301
3714
|
var _a;
|
|
3302
3715
|
this._unloadModel();
|
|
3303
|
-
const appElement = await ((_a = this.closestApp) === null || _a ===
|
|
3304
|
-
const app = appElement === null || appElement ===
|
|
3716
|
+
const appElement = await ((_a = this.closestApp) === null || _a === undefined ? undefined : _a.ready());
|
|
3717
|
+
const app = appElement === null || appElement === undefined ? undefined : appElement.app;
|
|
3305
3718
|
const asset = AssetElement.get(this._asset);
|
|
3306
3719
|
if (!asset) {
|
|
3307
3720
|
return;
|
|
@@ -3318,7 +3731,7 @@
|
|
|
3318
3731
|
}
|
|
3319
3732
|
_unloadModel() {
|
|
3320
3733
|
var _a;
|
|
3321
|
-
(_a = this._entity) === null || _a ===
|
|
3734
|
+
(_a = this._entity) === null || _a === undefined ? undefined : _a.destroy();
|
|
3322
3735
|
this._entity = null;
|
|
3323
3736
|
}
|
|
3324
3737
|
/**
|
|
@@ -3386,7 +3799,7 @@
|
|
|
3386
3799
|
}
|
|
3387
3800
|
async connectedCallback() {
|
|
3388
3801
|
var _a;
|
|
3389
|
-
await ((_a = this.closestApp) === null || _a ===
|
|
3802
|
+
await ((_a = this.closestApp) === null || _a === undefined ? undefined : _a.ready());
|
|
3390
3803
|
this.scene = this.closestApp.app.scene;
|
|
3391
3804
|
this.updateSceneSettings();
|
|
3392
3805
|
this._onReady();
|
|
@@ -3560,8 +3973,8 @@
|
|
|
3560
3973
|
}
|
|
3561
3974
|
async _loadSkybox() {
|
|
3562
3975
|
var _a;
|
|
3563
|
-
const appElement = await ((_a = this.closestApp) === null || _a ===
|
|
3564
|
-
const app = appElement === null || appElement ===
|
|
3976
|
+
const appElement = await ((_a = this.closestApp) === null || _a === undefined ? undefined : _a.ready());
|
|
3977
|
+
const app = appElement === null || appElement === undefined ? undefined : appElement.app;
|
|
3565
3978
|
if (!app) {
|
|
3566
3979
|
return;
|
|
3567
3980
|
}
|
|
@@ -3584,10 +3997,10 @@
|
|
|
3584
3997
|
var _a, _b;
|
|
3585
3998
|
if (!this._scene)
|
|
3586
3999
|
return;
|
|
3587
|
-
(_a = this._scene.skybox) === null || _a ===
|
|
4000
|
+
(_a = this._scene.skybox) === null || _a === undefined ? undefined : _a.destroy();
|
|
3588
4001
|
// @ts-ignore
|
|
3589
4002
|
this._scene.skybox = null;
|
|
3590
|
-
(_b = this._scene.envAtlas) === null || _b ===
|
|
4003
|
+
(_b = this._scene.envAtlas) === null || _b === undefined ? undefined : _b.destroy();
|
|
3591
4004
|
// @ts-ignore
|
|
3592
4005
|
this._scene.envAtlas = null;
|
|
3593
4006
|
this._scene = null;
|