@playcanvas/web-components 0.1.5 → 0.1.6
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/README.md +40 -46
- package/dist/app.d.ts +45 -1
- package/dist/components/sound-component.d.ts +48 -0
- package/dist/pwc.cjs +214 -14
- package/dist/pwc.cjs.map +1 -1
- package/dist/pwc.js +214 -14
- 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 +215 -15
- package/dist/pwc.mjs.map +1 -1
- package/package.json +4 -4
- package/src/app.ts +93 -4
- package/src/components/script-component.ts +24 -4
- package/src/components/sound-component.ts +110 -1
- package/src/module.ts +18 -10
|
@@ -8,10 +8,18 @@ import { ComponentElement } from './component';
|
|
|
8
8
|
* @category Components
|
|
9
9
|
*/
|
|
10
10
|
class SoundComponentElement extends ComponentElement {
|
|
11
|
+
private _distanceModel: 'exponential' | 'inverse' | 'linear' = 'linear';
|
|
12
|
+
|
|
13
|
+
private _maxDistance: number = 10000;
|
|
14
|
+
|
|
11
15
|
private _pitch: number = 1;
|
|
12
16
|
|
|
13
17
|
private _positional: boolean = false;
|
|
14
18
|
|
|
19
|
+
private _refDistance: number = 1;
|
|
20
|
+
|
|
21
|
+
private _rollOffFactor: number = 1;
|
|
22
|
+
|
|
15
23
|
private _volume: number = 1;
|
|
16
24
|
|
|
17
25
|
constructor() {
|
|
@@ -20,8 +28,12 @@ class SoundComponentElement extends ComponentElement {
|
|
|
20
28
|
|
|
21
29
|
getInitialComponentData() {
|
|
22
30
|
return {
|
|
31
|
+
distanceModel: this._distanceModel,
|
|
32
|
+
maxDistance: this._maxDistance,
|
|
23
33
|
pitch: this._pitch,
|
|
24
34
|
positional: this._positional,
|
|
35
|
+
refDistance: this._refDistance,
|
|
36
|
+
rollOffFactor: this._rollOffFactor,
|
|
25
37
|
volume: this._volume
|
|
26
38
|
};
|
|
27
39
|
}
|
|
@@ -34,6 +46,44 @@ class SoundComponentElement extends ComponentElement {
|
|
|
34
46
|
return super.component as SoundComponent | null;
|
|
35
47
|
}
|
|
36
48
|
|
|
49
|
+
/**
|
|
50
|
+
* Sets which algorithm to use to reduce the volume of the sound as it moves away from the listener.
|
|
51
|
+
* @param value - The distance model.
|
|
52
|
+
*/
|
|
53
|
+
set distanceModel(value: 'exponential' | 'inverse' | 'linear') {
|
|
54
|
+
this._distanceModel = value;
|
|
55
|
+
if (this.component) {
|
|
56
|
+
this.component.distanceModel = value;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Gets which algorithm to use to reduce the volume of the sound as it moves away from the listener.
|
|
62
|
+
* @returns The distance model.
|
|
63
|
+
*/
|
|
64
|
+
get distanceModel(): 'exponential' | 'inverse' | 'linear' {
|
|
65
|
+
return this._distanceModel;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Sets the maximum distance from the listener at which audio falloff stops.
|
|
70
|
+
* @param value - The max distance.
|
|
71
|
+
*/
|
|
72
|
+
set maxDistance(value: number) {
|
|
73
|
+
this._maxDistance = value;
|
|
74
|
+
if (this.component) {
|
|
75
|
+
this.component.maxDistance = value;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Gets the maximum distance from the listener at which audio falloff stops.
|
|
81
|
+
* @returns The max distance.
|
|
82
|
+
*/
|
|
83
|
+
get maxDistance() {
|
|
84
|
+
return this._maxDistance;
|
|
85
|
+
}
|
|
86
|
+
|
|
37
87
|
/**
|
|
38
88
|
* Sets the pitch of the sound.
|
|
39
89
|
* @param value - The pitch.
|
|
@@ -72,6 +122,44 @@ class SoundComponentElement extends ComponentElement {
|
|
|
72
122
|
return this._positional;
|
|
73
123
|
}
|
|
74
124
|
|
|
125
|
+
/**
|
|
126
|
+
* Sets the reference distance for reducing volume as the sound source moves further from the listener. Defaults to 1.
|
|
127
|
+
* @param value - The ref distance.
|
|
128
|
+
*/
|
|
129
|
+
set refDistance(value: number) {
|
|
130
|
+
this._refDistance = value;
|
|
131
|
+
if (this.component) {
|
|
132
|
+
this.component.refDistance = value;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Gets the reference distance for reducing volume as the sound source moves further from the listener.
|
|
138
|
+
* @returns The ref distance.
|
|
139
|
+
*/
|
|
140
|
+
get refDistance() {
|
|
141
|
+
return this._refDistance;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Sets the factor used in the falloff equation. Defaults to 1.
|
|
146
|
+
* @param value - The roll-off factor.
|
|
147
|
+
*/
|
|
148
|
+
set rollOffFactor(value: number) {
|
|
149
|
+
this._rollOffFactor = value;
|
|
150
|
+
if (this.component) {
|
|
151
|
+
this.component.rollOffFactor = value;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Gets the factor used in the falloff equation.
|
|
157
|
+
* @returns The roll-off factor.
|
|
158
|
+
*/
|
|
159
|
+
get rollOffFactor() {
|
|
160
|
+
return this._rollOffFactor;
|
|
161
|
+
}
|
|
162
|
+
|
|
75
163
|
/**
|
|
76
164
|
* Sets the volume of the sound.
|
|
77
165
|
* @param value - The volume.
|
|
@@ -92,19 +180,40 @@ class SoundComponentElement extends ComponentElement {
|
|
|
92
180
|
}
|
|
93
181
|
|
|
94
182
|
static get observedAttributes() {
|
|
95
|
-
return [
|
|
183
|
+
return [
|
|
184
|
+
...super.observedAttributes,
|
|
185
|
+
'distance-model',
|
|
186
|
+
'max-distance',
|
|
187
|
+
'pitch',
|
|
188
|
+
'positional',
|
|
189
|
+
'ref-distance',
|
|
190
|
+
'roll-off-factor',
|
|
191
|
+
'volume'
|
|
192
|
+
];
|
|
96
193
|
}
|
|
97
194
|
|
|
98
195
|
attributeChangedCallback(name: string, _oldValue: string, newValue: string) {
|
|
99
196
|
super.attributeChangedCallback(name, _oldValue, newValue);
|
|
100
197
|
|
|
101
198
|
switch (name) {
|
|
199
|
+
case 'distance-model':
|
|
200
|
+
this.distanceModel = newValue as 'exponential' | 'inverse' | 'linear';
|
|
201
|
+
break;
|
|
202
|
+
case 'max-distance':
|
|
203
|
+
this.maxDistance = parseFloat(newValue);
|
|
204
|
+
break;
|
|
102
205
|
case 'pitch':
|
|
103
206
|
this.pitch = parseFloat(newValue);
|
|
104
207
|
break;
|
|
105
208
|
case 'positional':
|
|
106
209
|
this.positional = this.hasAttribute('positional');
|
|
107
210
|
break;
|
|
211
|
+
case 'ref-distance':
|
|
212
|
+
this.refDistance = parseFloat(newValue);
|
|
213
|
+
break;
|
|
214
|
+
case 'roll-off-factor':
|
|
215
|
+
this.rollOffFactor = parseFloat(newValue);
|
|
216
|
+
break;
|
|
108
217
|
case 'volume':
|
|
109
218
|
this.volume = parseFloat(newValue);
|
|
110
219
|
break;
|
package/src/module.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { WasmModule } from 'playcanvas';
|
|
1
|
+
import { basisInitialize, WasmModule } from 'playcanvas';
|
|
2
2
|
|
|
3
3
|
class ModuleElement extends HTMLElement {
|
|
4
4
|
private loadPromise: Promise<void>;
|
|
@@ -14,15 +14,23 @@ class ModuleElement extends HTMLElement {
|
|
|
14
14
|
const wasm = this.getAttribute('wasm')!;
|
|
15
15
|
const fallback = this.getAttribute('fallback')!;
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
WasmModule.
|
|
25
|
-
|
|
17
|
+
if (name === 'Basis') {
|
|
18
|
+
basisInitialize({
|
|
19
|
+
glueUrl: glue,
|
|
20
|
+
wasmUrl: wasm,
|
|
21
|
+
fallbackUrl: fallback
|
|
22
|
+
});
|
|
23
|
+
} else {
|
|
24
|
+
WasmModule.setConfig(name, {
|
|
25
|
+
glueUrl: glue,
|
|
26
|
+
wasmUrl: wasm,
|
|
27
|
+
fallbackUrl: fallback
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
await new Promise<void>((resolve) => {
|
|
31
|
+
WasmModule.getInstance(name, () => resolve());
|
|
32
|
+
});
|
|
33
|
+
}
|
|
26
34
|
}
|
|
27
35
|
|
|
28
36
|
public getLoadPromise(): Promise<void> {
|