@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/src/entity.ts
CHANGED
|
@@ -39,6 +39,11 @@ class EntityElement extends AsyncElement {
|
|
|
39
39
|
*/
|
|
40
40
|
private _tags: string[] = [];
|
|
41
41
|
|
|
42
|
+
/**
|
|
43
|
+
* The pointer event listeners for the entity.
|
|
44
|
+
*/
|
|
45
|
+
private _listeners: { [key: string]: EventListener[] } = {};
|
|
46
|
+
|
|
42
47
|
/**
|
|
43
48
|
* The PlayCanvas entity instance.
|
|
44
49
|
*/
|
|
@@ -72,6 +77,31 @@ class EntityElement extends AsyncElement {
|
|
|
72
77
|
if (tags) {
|
|
73
78
|
this.entity.tags.add(tags.split(',').map(tag => tag.trim()));
|
|
74
79
|
}
|
|
80
|
+
|
|
81
|
+
// Handle pointer events
|
|
82
|
+
const pointerEvents = [
|
|
83
|
+
'onpointerenter',
|
|
84
|
+
'onpointerleave',
|
|
85
|
+
'onpointerdown',
|
|
86
|
+
'onpointerup',
|
|
87
|
+
'onpointermove'
|
|
88
|
+
];
|
|
89
|
+
|
|
90
|
+
pointerEvents.forEach((eventName) => {
|
|
91
|
+
const handler = this.getAttribute(eventName);
|
|
92
|
+
if (handler) {
|
|
93
|
+
const eventType = eventName.substring(2); // remove 'on' prefix
|
|
94
|
+
const eventHandler = (event: Event) => {
|
|
95
|
+
try {
|
|
96
|
+
/* eslint-disable-next-line no-new-func */
|
|
97
|
+
new Function('event', handler).call(this, event);
|
|
98
|
+
} catch (e) {
|
|
99
|
+
console.error('Error in event handler:', e);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
this.addEventListener(eventType, eventHandler);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
75
105
|
}
|
|
76
106
|
|
|
77
107
|
buildHierarchy(app: Application) {
|
|
@@ -240,7 +270,19 @@ class EntityElement extends AsyncElement {
|
|
|
240
270
|
}
|
|
241
271
|
|
|
242
272
|
static get observedAttributes() {
|
|
243
|
-
return [
|
|
273
|
+
return [
|
|
274
|
+
'enabled',
|
|
275
|
+
'name',
|
|
276
|
+
'position',
|
|
277
|
+
'rotation',
|
|
278
|
+
'scale',
|
|
279
|
+
'tags',
|
|
280
|
+
'onpointerenter',
|
|
281
|
+
'onpointerleave',
|
|
282
|
+
'onpointerdown',
|
|
283
|
+
'onpointerup',
|
|
284
|
+
'onpointermove'
|
|
285
|
+
];
|
|
244
286
|
}
|
|
245
287
|
|
|
246
288
|
attributeChangedCallback(name: string, _oldValue: string, newValue: string) {
|
|
@@ -263,7 +305,52 @@ class EntityElement extends AsyncElement {
|
|
|
263
305
|
case 'tags':
|
|
264
306
|
this.tags = newValue.split(',').map(tag => tag.trim());
|
|
265
307
|
break;
|
|
308
|
+
case 'onpointerenter':
|
|
309
|
+
case 'onpointerleave':
|
|
310
|
+
case 'onpointerdown':
|
|
311
|
+
case 'onpointerup':
|
|
312
|
+
case 'onpointermove':
|
|
313
|
+
if (newValue) {
|
|
314
|
+
const eventName = name.substring(2);
|
|
315
|
+
// Use Function.prototype.bind to avoid new Function
|
|
316
|
+
const handler = (event: Event) => {
|
|
317
|
+
try {
|
|
318
|
+
const handlerStr = this.getAttribute(eventName) || '';
|
|
319
|
+
/* eslint-disable-next-line no-new-func */
|
|
320
|
+
new Function('event', handlerStr).call(this, event);
|
|
321
|
+
} catch (e) {
|
|
322
|
+
console.error('Error in event handler:', e);
|
|
323
|
+
}
|
|
324
|
+
};
|
|
325
|
+
this.addEventListener(eventName, handler);
|
|
326
|
+
}
|
|
327
|
+
break;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
addEventListener(type: string, listener: EventListener, options?: boolean | AddEventListenerOptions) {
|
|
332
|
+
if (!this._listeners[type]) {
|
|
333
|
+
this._listeners[type] = [];
|
|
266
334
|
}
|
|
335
|
+
this._listeners[type].push(listener);
|
|
336
|
+
super.addEventListener(type, listener, options);
|
|
337
|
+
if (type.startsWith('pointer')) {
|
|
338
|
+
this.dispatchEvent(new CustomEvent(`${type}:connect`, { bubbles: true }));
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
removeEventListener(type: string, listener: EventListener, options?: boolean | EventListenerOptions) {
|
|
343
|
+
if (this._listeners[type]) {
|
|
344
|
+
this._listeners[type] = this._listeners[type].filter(l => l !== listener);
|
|
345
|
+
}
|
|
346
|
+
super.removeEventListener(type, listener, options);
|
|
347
|
+
if (type.startsWith('pointer')) {
|
|
348
|
+
this.dispatchEvent(new CustomEvent(`${type}:disconnect`, { bubbles: true }));
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
hasListeners(type: string): boolean {
|
|
353
|
+
return Boolean(this._listeners[type]?.length);
|
|
267
354
|
}
|
|
268
355
|
}
|
|
269
356
|
|
package/src/fog.ts
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { Color } from 'playcanvas';
|
|
2
|
+
|
|
3
|
+
import { parseColor } from './utils';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The FogElement interface provides properties and methods for manipulating
|
|
7
|
+
* `<pc-fog>` elements. The FogElement interface also inherits the properties and
|
|
8
|
+
* methods of the {@link HTMLElement} interface.
|
|
9
|
+
*/
|
|
10
|
+
class FogElement extends HTMLElement {
|
|
11
|
+
private _color = new Color(0.5, 0.5, 0.5);
|
|
12
|
+
|
|
13
|
+
private _density = 0.001;
|
|
14
|
+
|
|
15
|
+
private _end = 100;
|
|
16
|
+
|
|
17
|
+
private _start = 0;
|
|
18
|
+
|
|
19
|
+
private _type: 'linear' | 'exp' | 'exp2' = 'linear';
|
|
20
|
+
|
|
21
|
+
private dispatchFogUpdate() {
|
|
22
|
+
const event = new CustomEvent('fogupdate', {
|
|
23
|
+
bubbles: true,
|
|
24
|
+
detail: {
|
|
25
|
+
color: this._color,
|
|
26
|
+
density: this._density,
|
|
27
|
+
end: this._end,
|
|
28
|
+
start: this._start,
|
|
29
|
+
type: this._type
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
this.dispatchEvent(event);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
set color(value: Color) {
|
|
36
|
+
this._color = value;
|
|
37
|
+
this.dispatchFogUpdate();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
get color(): Color {
|
|
41
|
+
return this._color;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
set density(value: number) {
|
|
45
|
+
this._density = value;
|
|
46
|
+
this.dispatchFogUpdate();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
get density(): number {
|
|
50
|
+
return this._density;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
set end(value: number) {
|
|
54
|
+
this._end = value;
|
|
55
|
+
this.dispatchFogUpdate();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
get end(): number {
|
|
59
|
+
return this._end;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
set start(value: number) {
|
|
63
|
+
this._start = value;
|
|
64
|
+
this.dispatchFogUpdate();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
get start(): number {
|
|
68
|
+
return this._start;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
set type(value: 'linear' | 'exp' | 'exp2') {
|
|
72
|
+
this._type = value;
|
|
73
|
+
this.dispatchFogUpdate();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
get type(): 'linear' | 'exp' | 'exp2' {
|
|
77
|
+
return this._type;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
static get observedAttributes() {
|
|
81
|
+
return [
|
|
82
|
+
'color',
|
|
83
|
+
'density',
|
|
84
|
+
'end',
|
|
85
|
+
'start',
|
|
86
|
+
'type'
|
|
87
|
+
];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
attributeChangedCallback(name: string, _oldValue: string, newValue: string) {
|
|
91
|
+
switch (name) {
|
|
92
|
+
case 'color':
|
|
93
|
+
this.color = parseColor(newValue);
|
|
94
|
+
break;
|
|
95
|
+
case 'density':
|
|
96
|
+
this.density = parseFloat(newValue);
|
|
97
|
+
break;
|
|
98
|
+
case 'end':
|
|
99
|
+
this.end = parseFloat(newValue);
|
|
100
|
+
break;
|
|
101
|
+
case 'start':
|
|
102
|
+
this.start = parseFloat(newValue);
|
|
103
|
+
break;
|
|
104
|
+
case 'type':
|
|
105
|
+
if (newValue === 'linear' || newValue === 'exp' || newValue === 'exp2') {
|
|
106
|
+
this.type = newValue;
|
|
107
|
+
}
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
constructor() {
|
|
113
|
+
super();
|
|
114
|
+
// Dispatch initial fog state
|
|
115
|
+
this.dispatchFogUpdate();
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
customElements.define('pc-fog', FogElement);
|
|
120
|
+
|
|
121
|
+
export { FogElement };
|
package/src/material.ts
CHANGED
|
@@ -23,8 +23,8 @@ class MaterialElement extends HTMLElement {
|
|
|
23
23
|
|
|
24
24
|
createMaterial() {
|
|
25
25
|
this.material = new StandardMaterial();
|
|
26
|
-
this.material.glossInvert =
|
|
27
|
-
this.material.useMetalness =
|
|
26
|
+
this.material.glossInvert = false;
|
|
27
|
+
this.material.useMetalness = false;
|
|
28
28
|
this.material.diffuse = this._diffuse;
|
|
29
29
|
this.diffuseMap = this._diffuseMap;
|
|
30
30
|
this.metalnessMap = this._metalnessMap;
|