@playcanvas/web-components 0.3.0 → 0.6.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/LICENSE +21 -21
- package/README.md +84 -84
- package/dist/components/gsplat-component.d.ts +79 -0
- package/dist/components/light-component.d.ts +48 -0
- package/dist/index.d.ts +2 -2
- package/dist/pwc.cjs +324 -203
- package/dist/pwc.cjs.map +1 -1
- package/dist/pwc.js +324 -203
- 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 +325 -204
- package/dist/pwc.mjs.map +1 -1
- package/package.json +76 -66
- package/src/app.ts +612 -606
- package/src/asset.ts +159 -159
- package/src/async-element.ts +46 -46
- package/src/colors.ts +150 -150
- package/src/components/camera-component.ts +557 -557
- package/src/components/collision-component.ts +183 -183
- package/src/components/component.ts +97 -97
- package/src/components/element-component.ts +367 -367
- package/src/components/gsplat-component.ts +161 -0
- package/src/components/light-component.ts +570 -466
- package/src/components/listener-component.ts +30 -30
- package/src/components/particlesystem-component.ts +155 -155
- package/src/components/render-component.ts +147 -147
- package/src/components/rigidbody-component.ts +227 -227
- package/src/components/screen-component.ts +157 -157
- package/src/components/script-component.ts +270 -270
- package/src/components/script.ts +90 -90
- package/src/components/sound-component.ts +230 -230
- package/src/components/sound-slot.ts +288 -288
- package/src/entity.ts +360 -360
- package/src/index.ts +63 -63
- package/src/material.ts +141 -141
- package/src/model.ts +111 -111
- package/src/module.ts +43 -43
- package/src/scene.ts +217 -217
- package/src/sky.ts +293 -293
- package/src/utils.ts +71 -71
- package/dist/components/splat-component.d.ts +0 -61
- package/src/components/splat-component.ts +0 -133
package/src/utils.ts
CHANGED
|
@@ -1,71 +1,71 @@
|
|
|
1
|
-
import { Color, Quat, Vec2, Vec3, Vec4 } from 'playcanvas';
|
|
2
|
-
|
|
3
|
-
import { CSS_COLORS } from './colors';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Parse a color string into a Color object. String can be in the format of '#rgb', '#rgba',
|
|
7
|
-
* '#rrggbb', '#rrggbbaa', or a string of 3 or 4 comma-delimited numbers.
|
|
8
|
-
*
|
|
9
|
-
* @param value - The color string to parse.
|
|
10
|
-
* @returns The parsed Color object.
|
|
11
|
-
*/
|
|
12
|
-
export const parseColor = (value: string): Color => {
|
|
13
|
-
// Check if it's a CSS color name first
|
|
14
|
-
const hexColor = CSS_COLORS[value.toLowerCase()];
|
|
15
|
-
if (hexColor) {
|
|
16
|
-
return new Color().fromString(hexColor);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
if (value.startsWith('#')) {
|
|
20
|
-
return new Color().fromString(value);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const components = value.split(' ').map(Number);
|
|
24
|
-
return new Color(components);
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Parse an Euler angles string into a Quat object. String can be in the format of 'x,y,z'.
|
|
29
|
-
*
|
|
30
|
-
* @param value - The Euler angles string to parse.
|
|
31
|
-
* @returns The parsed Quat object.
|
|
32
|
-
*/
|
|
33
|
-
export const parseQuat = (value: string): Quat => {
|
|
34
|
-
const [x, y, z] = value.split(' ').map(Number);
|
|
35
|
-
const q = new Quat();
|
|
36
|
-
q.setFromEulerAngles(x, y, z);
|
|
37
|
-
return q;
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Parse a Vec2 string into a Vec2 object. String can be in the format of 'x,y'.
|
|
42
|
-
*
|
|
43
|
-
* @param value - The Vec2 string to parse.
|
|
44
|
-
* @returns The parsed Vec2 object.
|
|
45
|
-
*/
|
|
46
|
-
export const parseVec2 = (value: string): Vec2 => {
|
|
47
|
-
const components = value.split(' ').map(Number);
|
|
48
|
-
return new Vec2(components);
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Parse a Vec3 string into a Vec3 object. String can be in the format of 'x,y,z'.
|
|
53
|
-
*
|
|
54
|
-
* @param value - The Vec3 string to parse.
|
|
55
|
-
* @returns The parsed Vec3 object.
|
|
56
|
-
*/
|
|
57
|
-
export const parseVec3 = (value: string): Vec3 => {
|
|
58
|
-
const components = value.split(' ').map(Number);
|
|
59
|
-
return new Vec3(components);
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Parse a Vec4 string into a Vec4 object. String can be in the format of 'x,y,z,w'.
|
|
64
|
-
*
|
|
65
|
-
* @param value - The Vec4 string to parse.
|
|
66
|
-
* @returns The parsed Vec4 object.
|
|
67
|
-
*/
|
|
68
|
-
export const parseVec4 = (value: string): Vec4 => {
|
|
69
|
-
const components = value.split(' ').map(Number);
|
|
70
|
-
return new Vec4(components);
|
|
71
|
-
};
|
|
1
|
+
import { Color, Quat, Vec2, Vec3, Vec4 } from 'playcanvas';
|
|
2
|
+
|
|
3
|
+
import { CSS_COLORS } from './colors';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Parse a color string into a Color object. String can be in the format of '#rgb', '#rgba',
|
|
7
|
+
* '#rrggbb', '#rrggbbaa', or a string of 3 or 4 comma-delimited numbers.
|
|
8
|
+
*
|
|
9
|
+
* @param value - The color string to parse.
|
|
10
|
+
* @returns The parsed Color object.
|
|
11
|
+
*/
|
|
12
|
+
export const parseColor = (value: string): Color => {
|
|
13
|
+
// Check if it's a CSS color name first
|
|
14
|
+
const hexColor = CSS_COLORS[value.toLowerCase()];
|
|
15
|
+
if (hexColor) {
|
|
16
|
+
return new Color().fromString(hexColor);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (value.startsWith('#')) {
|
|
20
|
+
return new Color().fromString(value);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const components = value.split(' ').map(Number);
|
|
24
|
+
return new Color(components);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Parse an Euler angles string into a Quat object. String can be in the format of 'x,y,z'.
|
|
29
|
+
*
|
|
30
|
+
* @param value - The Euler angles string to parse.
|
|
31
|
+
* @returns The parsed Quat object.
|
|
32
|
+
*/
|
|
33
|
+
export const parseQuat = (value: string): Quat => {
|
|
34
|
+
const [x, y, z] = value.split(' ').map(Number);
|
|
35
|
+
const q = new Quat();
|
|
36
|
+
q.setFromEulerAngles(x, y, z);
|
|
37
|
+
return q;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Parse a Vec2 string into a Vec2 object. String can be in the format of 'x,y'.
|
|
42
|
+
*
|
|
43
|
+
* @param value - The Vec2 string to parse.
|
|
44
|
+
* @returns The parsed Vec2 object.
|
|
45
|
+
*/
|
|
46
|
+
export const parseVec2 = (value: string): Vec2 => {
|
|
47
|
+
const components = value.split(' ').map(Number);
|
|
48
|
+
return new Vec2(components);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Parse a Vec3 string into a Vec3 object. String can be in the format of 'x,y,z'.
|
|
53
|
+
*
|
|
54
|
+
* @param value - The Vec3 string to parse.
|
|
55
|
+
* @returns The parsed Vec3 object.
|
|
56
|
+
*/
|
|
57
|
+
export const parseVec3 = (value: string): Vec3 => {
|
|
58
|
+
const components = value.split(' ').map(Number);
|
|
59
|
+
return new Vec3(components);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Parse a Vec4 string into a Vec4 object. String can be in the format of 'x,y,z,w'.
|
|
64
|
+
*
|
|
65
|
+
* @param value - The Vec4 string to parse.
|
|
66
|
+
* @returns The parsed Vec4 object.
|
|
67
|
+
*/
|
|
68
|
+
export const parseVec4 = (value: string): Vec4 => {
|
|
69
|
+
const components = value.split(' ').map(Number);
|
|
70
|
+
return new Vec4(components);
|
|
71
|
+
};
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { GSplatComponent } from 'playcanvas';
|
|
2
|
-
import { ComponentElement } from './component';
|
|
3
|
-
/**
|
|
4
|
-
* The SplatComponentElement interface provides properties and methods for manipulating
|
|
5
|
-
* {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-splat/ | `<pc-splat>`} elements.
|
|
6
|
-
* The SplatComponentElement interface also inherits the properties and methods of the
|
|
7
|
-
* {@link HTMLElement} interface.
|
|
8
|
-
*
|
|
9
|
-
* @category Components
|
|
10
|
-
*/
|
|
11
|
-
declare class SplatComponentElement extends ComponentElement {
|
|
12
|
-
private _asset;
|
|
13
|
-
private _castShadows;
|
|
14
|
-
private _unified;
|
|
15
|
-
/** @ignore */
|
|
16
|
-
constructor();
|
|
17
|
-
getInitialComponentData(): {
|
|
18
|
-
asset: import("playcanvas").Asset | null | undefined;
|
|
19
|
-
castShadows: boolean;
|
|
20
|
-
unified: boolean;
|
|
21
|
-
};
|
|
22
|
-
/**
|
|
23
|
-
* Gets the underlying PlayCanvas splat component.
|
|
24
|
-
* @returns The splat component.
|
|
25
|
-
*/
|
|
26
|
-
get component(): GSplatComponent | null;
|
|
27
|
-
/**
|
|
28
|
-
* Sets id of the `pc-asset` to use for the splat.
|
|
29
|
-
* @param value - The asset ID.
|
|
30
|
-
*/
|
|
31
|
-
set asset(value: string);
|
|
32
|
-
/**
|
|
33
|
-
* Gets the id of the `pc-asset` to use for the splat.
|
|
34
|
-
* @returns The asset ID.
|
|
35
|
-
*/
|
|
36
|
-
get asset(): string;
|
|
37
|
-
/**
|
|
38
|
-
* Sets whether the splat casts shadows.
|
|
39
|
-
* @param value - Whether the splat casts shadows.
|
|
40
|
-
*/
|
|
41
|
-
set castShadows(value: boolean);
|
|
42
|
-
/**
|
|
43
|
-
* Gets whether the splat casts shadows.
|
|
44
|
-
* @returns Whether the splat casts shadows.
|
|
45
|
-
*/
|
|
46
|
-
get castShadows(): boolean;
|
|
47
|
-
/**
|
|
48
|
-
* Sets whether the splat supports global sorting and LOD streaming. This property can only be
|
|
49
|
-
* changed when the component is disabled.
|
|
50
|
-
* @param value - Whether the splat supports global sorting and LOD streaming.
|
|
51
|
-
*/
|
|
52
|
-
set unified(value: boolean);
|
|
53
|
-
/**
|
|
54
|
-
* Gets whether the splat supports global sorting and LOD streaming.
|
|
55
|
-
* @returns Whether the splat supports global sorting and LOD streaming.
|
|
56
|
-
*/
|
|
57
|
-
get unified(): boolean;
|
|
58
|
-
static get observedAttributes(): string[];
|
|
59
|
-
attributeChangedCallback(name: string, _oldValue: string, newValue: string): void;
|
|
60
|
-
}
|
|
61
|
-
export { SplatComponentElement };
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import { GSplatComponent } from 'playcanvas';
|
|
2
|
-
|
|
3
|
-
import { ComponentElement } from './component';
|
|
4
|
-
import { AssetElement } from '../asset';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* The SplatComponentElement interface provides properties and methods for manipulating
|
|
8
|
-
* {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-splat/ | `<pc-splat>`} elements.
|
|
9
|
-
* The SplatComponentElement interface also inherits the properties and methods of the
|
|
10
|
-
* {@link HTMLElement} interface.
|
|
11
|
-
*
|
|
12
|
-
* @category Components
|
|
13
|
-
*/
|
|
14
|
-
class SplatComponentElement extends ComponentElement {
|
|
15
|
-
private _asset = '';
|
|
16
|
-
|
|
17
|
-
private _castShadows = false;
|
|
18
|
-
|
|
19
|
-
private _unified = false;
|
|
20
|
-
|
|
21
|
-
/** @ignore */
|
|
22
|
-
constructor() {
|
|
23
|
-
super('gsplat');
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
getInitialComponentData() {
|
|
27
|
-
return {
|
|
28
|
-
asset: AssetElement.get(this._asset),
|
|
29
|
-
castShadows: this._castShadows,
|
|
30
|
-
unified: this._unified
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Gets the underlying PlayCanvas splat component.
|
|
36
|
-
* @returns The splat component.
|
|
37
|
-
*/
|
|
38
|
-
get component(): GSplatComponent | null {
|
|
39
|
-
return super.component as GSplatComponent | null;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Sets id of the `pc-asset` to use for the splat.
|
|
44
|
-
* @param value - The asset ID.
|
|
45
|
-
*/
|
|
46
|
-
set asset(value: string) {
|
|
47
|
-
this._asset = value;
|
|
48
|
-
const asset = AssetElement.get(value);
|
|
49
|
-
if (this.component && asset) {
|
|
50
|
-
this.component.asset = asset;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Gets the id of the `pc-asset` to use for the splat.
|
|
56
|
-
* @returns The asset ID.
|
|
57
|
-
*/
|
|
58
|
-
get asset() {
|
|
59
|
-
return this._asset;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Sets whether the splat casts shadows.
|
|
64
|
-
* @param value - Whether the splat casts shadows.
|
|
65
|
-
*/
|
|
66
|
-
set castShadows(value: boolean) {
|
|
67
|
-
this._castShadows = value;
|
|
68
|
-
if (this.component) {
|
|
69
|
-
this.component.castShadows = value;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Gets whether the splat casts shadows.
|
|
75
|
-
* @returns Whether the splat casts shadows.
|
|
76
|
-
*/
|
|
77
|
-
get castShadows() {
|
|
78
|
-
return this._castShadows;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Sets whether the splat supports global sorting and LOD streaming. This property can only be
|
|
83
|
-
* changed when the component is disabled.
|
|
84
|
-
* @param value - Whether the splat supports global sorting and LOD streaming.
|
|
85
|
-
*/
|
|
86
|
-
set unified(value: boolean) {
|
|
87
|
-
if (this.component && this.component.enabled) {
|
|
88
|
-
console.warn('The "unified" property can only be changed when the component is disabled.');
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
this._unified = value;
|
|
92
|
-
if (this.component) {
|
|
93
|
-
this.component.unified = value;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Gets whether the splat supports global sorting and LOD streaming.
|
|
99
|
-
* @returns Whether the splat supports global sorting and LOD streaming.
|
|
100
|
-
*/
|
|
101
|
-
get unified() {
|
|
102
|
-
return this._unified;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
static get observedAttributes() {
|
|
106
|
-
return [
|
|
107
|
-
...super.observedAttributes,
|
|
108
|
-
'asset',
|
|
109
|
-
'cast-shadows',
|
|
110
|
-
'unified'
|
|
111
|
-
];
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
attributeChangedCallback(name: string, _oldValue: string, newValue: string) {
|
|
115
|
-
super.attributeChangedCallback(name, _oldValue, newValue);
|
|
116
|
-
|
|
117
|
-
switch (name) {
|
|
118
|
-
case 'asset':
|
|
119
|
-
this.asset = newValue;
|
|
120
|
-
break;
|
|
121
|
-
case 'cast-shadows':
|
|
122
|
-
this.castShadows = this.hasAttribute('cast-shadows');
|
|
123
|
-
break;
|
|
124
|
-
case 'unified':
|
|
125
|
-
this.unified = this.hasAttribute('unified');
|
|
126
|
-
break;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
customElements.define('pc-splat', SplatComponentElement);
|
|
132
|
-
|
|
133
|
-
export { SplatComponentElement };
|