@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
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import { AudioListenerComponent } from 'playcanvas';
|
|
2
|
-
|
|
3
|
-
import { ComponentElement } from './component';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* The ListenerComponentElement interface provides properties and methods for manipulating
|
|
7
|
-
* {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-listener/ | `<pc-listener>`} elements.
|
|
8
|
-
* The ListenerComponentElement interface also inherits the properties and methods of the
|
|
9
|
-
* {@link HTMLElement} interface.
|
|
10
|
-
*
|
|
11
|
-
* @category Components
|
|
12
|
-
*/
|
|
13
|
-
class ListenerComponentElement extends ComponentElement {
|
|
14
|
-
/** @ignore */
|
|
15
|
-
constructor() {
|
|
16
|
-
super('audiolistener');
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Gets the underlying PlayCanvas audio listener component.
|
|
21
|
-
* @returns The audio listener component.
|
|
22
|
-
*/
|
|
23
|
-
get component(): AudioListenerComponent | null {
|
|
24
|
-
return super.component as AudioListenerComponent | null;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
customElements.define('pc-listener', ListenerComponentElement);
|
|
29
|
-
|
|
30
|
-
export { ListenerComponentElement };
|
|
1
|
+
import { AudioListenerComponent } from 'playcanvas';
|
|
2
|
+
|
|
3
|
+
import { ComponentElement } from './component';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The ListenerComponentElement interface provides properties and methods for manipulating
|
|
7
|
+
* {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-listener/ | `<pc-listener>`} elements.
|
|
8
|
+
* The ListenerComponentElement interface also inherits the properties and methods of the
|
|
9
|
+
* {@link HTMLElement} interface.
|
|
10
|
+
*
|
|
11
|
+
* @category Components
|
|
12
|
+
*/
|
|
13
|
+
class ListenerComponentElement extends ComponentElement {
|
|
14
|
+
/** @ignore */
|
|
15
|
+
constructor() {
|
|
16
|
+
super('audiolistener');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Gets the underlying PlayCanvas audio listener component.
|
|
21
|
+
* @returns The audio listener component.
|
|
22
|
+
*/
|
|
23
|
+
get component(): AudioListenerComponent | null {
|
|
24
|
+
return super.component as AudioListenerComponent | null;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
customElements.define('pc-listener', ListenerComponentElement);
|
|
29
|
+
|
|
30
|
+
export { ListenerComponentElement };
|
|
@@ -1,155 +1,155 @@
|
|
|
1
|
-
import { ParticleSystemComponent } from 'playcanvas';
|
|
2
|
-
|
|
3
|
-
import { ComponentElement } from './component';
|
|
4
|
-
import { AssetElement } from '../asset';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* The ParticleSystemComponentElement interface provides properties and methods for manipulating
|
|
8
|
-
* {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-particles/ | `<pc-particles>`} elements.
|
|
9
|
-
* The ParticleSystemComponentElement interface also inherits the properties and methods of the
|
|
10
|
-
* {@link HTMLElement} interface.
|
|
11
|
-
*
|
|
12
|
-
* @category Components
|
|
13
|
-
*/
|
|
14
|
-
class ParticleSystemComponentElement extends ComponentElement {
|
|
15
|
-
private _asset: string = '';
|
|
16
|
-
|
|
17
|
-
/** @ignore */
|
|
18
|
-
constructor() {
|
|
19
|
-
super('particlesystem');
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
getInitialComponentData() {
|
|
23
|
-
const asset = AssetElement.get(this._asset);
|
|
24
|
-
if (!asset) {
|
|
25
|
-
return {};
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
if ((asset.resource as any).colorMapAsset) {
|
|
29
|
-
const id = (asset.resource as any).colorMapAsset;
|
|
30
|
-
const colorMapAsset = AssetElement.get(id)?.id;
|
|
31
|
-
if (colorMapAsset) {
|
|
32
|
-
(asset.resource as any).colorMapAsset = colorMapAsset;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return asset.resource;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Gets the underlying PlayCanvas particle system component.
|
|
41
|
-
* @returns The particle system component.
|
|
42
|
-
*/
|
|
43
|
-
get component(): ParticleSystemComponent | null {
|
|
44
|
-
return super.component as ParticleSystemComponent | null;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
private applyConfig(resource: any) {
|
|
48
|
-
if (!this.component) {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// Set all the config properties on the component
|
|
53
|
-
for (const key in resource) {
|
|
54
|
-
if (resource.hasOwnProperty(key)) {
|
|
55
|
-
(this.component as any)[key] = resource[key];
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
private async _loadAsset() {
|
|
61
|
-
const appElement = await this.closestApp?.ready();
|
|
62
|
-
const app = appElement?.app;
|
|
63
|
-
|
|
64
|
-
const asset = AssetElement.get(this._asset);
|
|
65
|
-
if (!asset) {
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (asset.loaded) {
|
|
70
|
-
this.applyConfig(asset.resource);
|
|
71
|
-
} else {
|
|
72
|
-
asset.once('load', () => {
|
|
73
|
-
this.applyConfig(asset.resource);
|
|
74
|
-
});
|
|
75
|
-
app!.assets.load(asset);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Sets the id of the `pc-asset` to use for the model.
|
|
81
|
-
* @param value - The asset ID.
|
|
82
|
-
*/
|
|
83
|
-
set asset(value: string) {
|
|
84
|
-
this._asset = value;
|
|
85
|
-
if (this.isConnected) {
|
|
86
|
-
this._loadAsset();
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Gets the id of the `pc-asset` to use for the model.
|
|
92
|
-
* @returns The asset ID.
|
|
93
|
-
*/
|
|
94
|
-
get asset(): string {
|
|
95
|
-
return this._asset;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// Control methods
|
|
99
|
-
/**
|
|
100
|
-
* Starts playing the particle system
|
|
101
|
-
*/
|
|
102
|
-
play() {
|
|
103
|
-
if (this.component) {
|
|
104
|
-
this.component.play();
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Pauses the particle system
|
|
110
|
-
*/
|
|
111
|
-
pause() {
|
|
112
|
-
if (this.component) {
|
|
113
|
-
this.component.pause();
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Resets the particle system
|
|
119
|
-
*/
|
|
120
|
-
reset() {
|
|
121
|
-
if (this.component) {
|
|
122
|
-
this.component.reset();
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Stops the particle system
|
|
128
|
-
*/
|
|
129
|
-
stop() {
|
|
130
|
-
if (this.component) {
|
|
131
|
-
this.component.stop();
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
static get observedAttributes() {
|
|
136
|
-
return [
|
|
137
|
-
...super.observedAttributes,
|
|
138
|
-
'asset'
|
|
139
|
-
];
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
attributeChangedCallback(name: string, _oldValue: string, newValue: string) {
|
|
143
|
-
super.attributeChangedCallback(name, _oldValue, newValue);
|
|
144
|
-
|
|
145
|
-
switch (name) {
|
|
146
|
-
case 'asset':
|
|
147
|
-
this.asset = newValue;
|
|
148
|
-
break;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
customElements.define('pc-particles', ParticleSystemComponentElement);
|
|
154
|
-
|
|
155
|
-
export { ParticleSystemComponentElement };
|
|
1
|
+
import { ParticleSystemComponent } from 'playcanvas';
|
|
2
|
+
|
|
3
|
+
import { ComponentElement } from './component';
|
|
4
|
+
import { AssetElement } from '../asset';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The ParticleSystemComponentElement interface provides properties and methods for manipulating
|
|
8
|
+
* {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-particles/ | `<pc-particles>`} elements.
|
|
9
|
+
* The ParticleSystemComponentElement interface also inherits the properties and methods of the
|
|
10
|
+
* {@link HTMLElement} interface.
|
|
11
|
+
*
|
|
12
|
+
* @category Components
|
|
13
|
+
*/
|
|
14
|
+
class ParticleSystemComponentElement extends ComponentElement {
|
|
15
|
+
private _asset: string = '';
|
|
16
|
+
|
|
17
|
+
/** @ignore */
|
|
18
|
+
constructor() {
|
|
19
|
+
super('particlesystem');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
getInitialComponentData() {
|
|
23
|
+
const asset = AssetElement.get(this._asset);
|
|
24
|
+
if (!asset) {
|
|
25
|
+
return {};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if ((asset.resource as any).colorMapAsset) {
|
|
29
|
+
const id = (asset.resource as any).colorMapAsset;
|
|
30
|
+
const colorMapAsset = AssetElement.get(id)?.id;
|
|
31
|
+
if (colorMapAsset) {
|
|
32
|
+
(asset.resource as any).colorMapAsset = colorMapAsset;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return asset.resource;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Gets the underlying PlayCanvas particle system component.
|
|
41
|
+
* @returns The particle system component.
|
|
42
|
+
*/
|
|
43
|
+
get component(): ParticleSystemComponent | null {
|
|
44
|
+
return super.component as ParticleSystemComponent | null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
private applyConfig(resource: any) {
|
|
48
|
+
if (!this.component) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Set all the config properties on the component
|
|
53
|
+
for (const key in resource) {
|
|
54
|
+
if (resource.hasOwnProperty(key)) {
|
|
55
|
+
(this.component as any)[key] = resource[key];
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
private async _loadAsset() {
|
|
61
|
+
const appElement = await this.closestApp?.ready();
|
|
62
|
+
const app = appElement?.app;
|
|
63
|
+
|
|
64
|
+
const asset = AssetElement.get(this._asset);
|
|
65
|
+
if (!asset) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (asset.loaded) {
|
|
70
|
+
this.applyConfig(asset.resource);
|
|
71
|
+
} else {
|
|
72
|
+
asset.once('load', () => {
|
|
73
|
+
this.applyConfig(asset.resource);
|
|
74
|
+
});
|
|
75
|
+
app!.assets.load(asset);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Sets the id of the `pc-asset` to use for the model.
|
|
81
|
+
* @param value - The asset ID.
|
|
82
|
+
*/
|
|
83
|
+
set asset(value: string) {
|
|
84
|
+
this._asset = value;
|
|
85
|
+
if (this.isConnected) {
|
|
86
|
+
this._loadAsset();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Gets the id of the `pc-asset` to use for the model.
|
|
92
|
+
* @returns The asset ID.
|
|
93
|
+
*/
|
|
94
|
+
get asset(): string {
|
|
95
|
+
return this._asset;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Control methods
|
|
99
|
+
/**
|
|
100
|
+
* Starts playing the particle system
|
|
101
|
+
*/
|
|
102
|
+
play() {
|
|
103
|
+
if (this.component) {
|
|
104
|
+
this.component.play();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Pauses the particle system
|
|
110
|
+
*/
|
|
111
|
+
pause() {
|
|
112
|
+
if (this.component) {
|
|
113
|
+
this.component.pause();
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Resets the particle system
|
|
119
|
+
*/
|
|
120
|
+
reset() {
|
|
121
|
+
if (this.component) {
|
|
122
|
+
this.component.reset();
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Stops the particle system
|
|
128
|
+
*/
|
|
129
|
+
stop() {
|
|
130
|
+
if (this.component) {
|
|
131
|
+
this.component.stop();
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
static get observedAttributes() {
|
|
136
|
+
return [
|
|
137
|
+
...super.observedAttributes,
|
|
138
|
+
'asset'
|
|
139
|
+
];
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
attributeChangedCallback(name: string, _oldValue: string, newValue: string) {
|
|
143
|
+
super.attributeChangedCallback(name, _oldValue, newValue);
|
|
144
|
+
|
|
145
|
+
switch (name) {
|
|
146
|
+
case 'asset':
|
|
147
|
+
this.asset = newValue;
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
customElements.define('pc-particles', ParticleSystemComponentElement);
|
|
154
|
+
|
|
155
|
+
export { ParticleSystemComponentElement };
|
|
@@ -1,147 +1,147 @@
|
|
|
1
|
-
import { RenderComponent, StandardMaterial } from 'playcanvas';
|
|
2
|
-
|
|
3
|
-
import { ComponentElement } from './component';
|
|
4
|
-
import { MaterialElement } from '../material';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* The RenderComponentElement interface provides properties and methods for manipulating
|
|
8
|
-
* {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-render/ | `<pc-render>`} elements.
|
|
9
|
-
* The RenderComponentElement interface also inherits the properties and methods of the
|
|
10
|
-
* {@link HTMLElement} interface.
|
|
11
|
-
*
|
|
12
|
-
* @category Components
|
|
13
|
-
*/
|
|
14
|
-
class RenderComponentElement extends ComponentElement {
|
|
15
|
-
private _castShadows = true;
|
|
16
|
-
|
|
17
|
-
private _material: string = '';
|
|
18
|
-
|
|
19
|
-
private _receiveShadows = true;
|
|
20
|
-
|
|
21
|
-
private _type: 'asset' | 'box' | 'capsule' | 'cone' | 'cylinder' | 'plane' | 'sphere' = 'asset';
|
|
22
|
-
|
|
23
|
-
/** @ignore */
|
|
24
|
-
constructor() {
|
|
25
|
-
super('render');
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
getInitialComponentData() {
|
|
29
|
-
return {
|
|
30
|
-
type: this._type,
|
|
31
|
-
castShadows: this._castShadows,
|
|
32
|
-
material: MaterialElement.get(this._material),
|
|
33
|
-
receiveShadows: this._receiveShadows
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Gets the underlying PlayCanvas render component.
|
|
39
|
-
* @returns The render component.
|
|
40
|
-
*/
|
|
41
|
-
get component(): RenderComponent | null {
|
|
42
|
-
return super.component as RenderComponent | null;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Sets the type of the render component.
|
|
47
|
-
* @param value - The type.
|
|
48
|
-
*/
|
|
49
|
-
set type(value: 'asset' | 'box' | 'capsule' | 'cone' | 'cylinder' | 'plane' | 'sphere') {
|
|
50
|
-
this._type = value;
|
|
51
|
-
if (this.component) {
|
|
52
|
-
this.component.type = value;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Gets the type of the render component.
|
|
58
|
-
* @returns The type.
|
|
59
|
-
*/
|
|
60
|
-
get type(): 'asset' | 'box' | 'capsule' | 'cone' | 'cylinder' | 'plane' | 'sphere' {
|
|
61
|
-
return this._type;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Sets the cast shadows flag of the render component.
|
|
66
|
-
* @param value - The cast shadows flag.
|
|
67
|
-
*/
|
|
68
|
-
set castShadows(value: boolean) {
|
|
69
|
-
this._castShadows = value;
|
|
70
|
-
if (this.component) {
|
|
71
|
-
this.component.castShadows = value;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Gets the cast shadows flag of the render component.
|
|
77
|
-
* @returns The cast shadows flag.
|
|
78
|
-
*/
|
|
79
|
-
get castShadows(): boolean {
|
|
80
|
-
return this._castShadows;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Sets the material of the render component.
|
|
85
|
-
* @param value - The id of the material asset to use.
|
|
86
|
-
*/
|
|
87
|
-
set material(value: string) {
|
|
88
|
-
this._material = value;
|
|
89
|
-
if (this.component) {
|
|
90
|
-
this.component.material = MaterialElement.get(value) as StandardMaterial;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Gets the id of the material asset used by the render component.
|
|
96
|
-
* @returns The id of the material asset.
|
|
97
|
-
*/
|
|
98
|
-
get material() {
|
|
99
|
-
return this._material;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Sets the receive shadows flag of the render component.
|
|
104
|
-
* @param value - The receive shadows flag.
|
|
105
|
-
*/
|
|
106
|
-
set receiveShadows(value: boolean) {
|
|
107
|
-
this._receiveShadows = value;
|
|
108
|
-
if (this.component) {
|
|
109
|
-
this.component.receiveShadows = value;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Gets the receive shadows flag of the render component.
|
|
115
|
-
* @returns The receive shadows flag.
|
|
116
|
-
*/
|
|
117
|
-
get receiveShadows(): boolean {
|
|
118
|
-
return this._receiveShadows;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
static get observedAttributes() {
|
|
122
|
-
return [...super.observedAttributes, 'cast-shadows', 'material', 'receive-shadows', 'type'];
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
attributeChangedCallback(name: string, _oldValue: string, newValue: string) {
|
|
126
|
-
super.attributeChangedCallback(name, _oldValue, newValue);
|
|
127
|
-
|
|
128
|
-
switch (name) {
|
|
129
|
-
case 'cast-shadows':
|
|
130
|
-
this.castShadows = newValue !== 'false';
|
|
131
|
-
break;
|
|
132
|
-
case 'material':
|
|
133
|
-
this.material = newValue;
|
|
134
|
-
break;
|
|
135
|
-
case 'receive-shadows':
|
|
136
|
-
this.receiveShadows = newValue !== 'false';
|
|
137
|
-
break;
|
|
138
|
-
case 'type':
|
|
139
|
-
this.type = newValue as 'asset' | 'box' | 'capsule' | 'cone' | 'cylinder' | 'plane' | 'sphere';
|
|
140
|
-
break;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
customElements.define('pc-render', RenderComponentElement);
|
|
146
|
-
|
|
147
|
-
export { RenderComponentElement };
|
|
1
|
+
import { RenderComponent, StandardMaterial } from 'playcanvas';
|
|
2
|
+
|
|
3
|
+
import { ComponentElement } from './component';
|
|
4
|
+
import { MaterialElement } from '../material';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The RenderComponentElement interface provides properties and methods for manipulating
|
|
8
|
+
* {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-render/ | `<pc-render>`} elements.
|
|
9
|
+
* The RenderComponentElement interface also inherits the properties and methods of the
|
|
10
|
+
* {@link HTMLElement} interface.
|
|
11
|
+
*
|
|
12
|
+
* @category Components
|
|
13
|
+
*/
|
|
14
|
+
class RenderComponentElement extends ComponentElement {
|
|
15
|
+
private _castShadows = true;
|
|
16
|
+
|
|
17
|
+
private _material: string = '';
|
|
18
|
+
|
|
19
|
+
private _receiveShadows = true;
|
|
20
|
+
|
|
21
|
+
private _type: 'asset' | 'box' | 'capsule' | 'cone' | 'cylinder' | 'plane' | 'sphere' = 'asset';
|
|
22
|
+
|
|
23
|
+
/** @ignore */
|
|
24
|
+
constructor() {
|
|
25
|
+
super('render');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
getInitialComponentData() {
|
|
29
|
+
return {
|
|
30
|
+
type: this._type,
|
|
31
|
+
castShadows: this._castShadows,
|
|
32
|
+
material: MaterialElement.get(this._material),
|
|
33
|
+
receiveShadows: this._receiveShadows
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Gets the underlying PlayCanvas render component.
|
|
39
|
+
* @returns The render component.
|
|
40
|
+
*/
|
|
41
|
+
get component(): RenderComponent | null {
|
|
42
|
+
return super.component as RenderComponent | null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Sets the type of the render component.
|
|
47
|
+
* @param value - The type.
|
|
48
|
+
*/
|
|
49
|
+
set type(value: 'asset' | 'box' | 'capsule' | 'cone' | 'cylinder' | 'plane' | 'sphere') {
|
|
50
|
+
this._type = value;
|
|
51
|
+
if (this.component) {
|
|
52
|
+
this.component.type = value;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Gets the type of the render component.
|
|
58
|
+
* @returns The type.
|
|
59
|
+
*/
|
|
60
|
+
get type(): 'asset' | 'box' | 'capsule' | 'cone' | 'cylinder' | 'plane' | 'sphere' {
|
|
61
|
+
return this._type;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Sets the cast shadows flag of the render component.
|
|
66
|
+
* @param value - The cast shadows flag.
|
|
67
|
+
*/
|
|
68
|
+
set castShadows(value: boolean) {
|
|
69
|
+
this._castShadows = value;
|
|
70
|
+
if (this.component) {
|
|
71
|
+
this.component.castShadows = value;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Gets the cast shadows flag of the render component.
|
|
77
|
+
* @returns The cast shadows flag.
|
|
78
|
+
*/
|
|
79
|
+
get castShadows(): boolean {
|
|
80
|
+
return this._castShadows;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Sets the material of the render component.
|
|
85
|
+
* @param value - The id of the material asset to use.
|
|
86
|
+
*/
|
|
87
|
+
set material(value: string) {
|
|
88
|
+
this._material = value;
|
|
89
|
+
if (this.component) {
|
|
90
|
+
this.component.material = MaterialElement.get(value) as StandardMaterial;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Gets the id of the material asset used by the render component.
|
|
96
|
+
* @returns The id of the material asset.
|
|
97
|
+
*/
|
|
98
|
+
get material() {
|
|
99
|
+
return this._material;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Sets the receive shadows flag of the render component.
|
|
104
|
+
* @param value - The receive shadows flag.
|
|
105
|
+
*/
|
|
106
|
+
set receiveShadows(value: boolean) {
|
|
107
|
+
this._receiveShadows = value;
|
|
108
|
+
if (this.component) {
|
|
109
|
+
this.component.receiveShadows = value;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Gets the receive shadows flag of the render component.
|
|
115
|
+
* @returns The receive shadows flag.
|
|
116
|
+
*/
|
|
117
|
+
get receiveShadows(): boolean {
|
|
118
|
+
return this._receiveShadows;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
static get observedAttributes() {
|
|
122
|
+
return [...super.observedAttributes, 'cast-shadows', 'material', 'receive-shadows', 'type'];
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
attributeChangedCallback(name: string, _oldValue: string, newValue: string) {
|
|
126
|
+
super.attributeChangedCallback(name, _oldValue, newValue);
|
|
127
|
+
|
|
128
|
+
switch (name) {
|
|
129
|
+
case 'cast-shadows':
|
|
130
|
+
this.castShadows = newValue !== 'false';
|
|
131
|
+
break;
|
|
132
|
+
case 'material':
|
|
133
|
+
this.material = newValue;
|
|
134
|
+
break;
|
|
135
|
+
case 'receive-shadows':
|
|
136
|
+
this.receiveShadows = newValue !== 'false';
|
|
137
|
+
break;
|
|
138
|
+
case 'type':
|
|
139
|
+
this.type = newValue as 'asset' | 'box' | 'capsule' | 'cone' | 'cylinder' | 'plane' | 'sphere';
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
customElements.define('pc-render', RenderComponentElement);
|
|
146
|
+
|
|
147
|
+
export { RenderComponentElement };
|