action-engine-js 1.0.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 +45 -0
- package/README.md +348 -0
- package/actionengine/3rdparty/goblin/goblin.js +9609 -0
- package/actionengine/3rdparty/goblin/goblin.min.js +5 -0
- package/actionengine/camera/actioncamera.js +90 -0
- package/actionengine/camera/cameracollisionhandler.js +69 -0
- package/actionengine/character/actioncharacter.js +360 -0
- package/actionengine/character/actioncharacter3D.js +61 -0
- package/actionengine/core/app.js +430 -0
- package/actionengine/debug/basedebugpanel.js +858 -0
- package/actionengine/display/canvasmanager.js +75 -0
- package/actionengine/display/gl/programmanager.js +570 -0
- package/actionengine/display/gl/shaders/lineshader.js +118 -0
- package/actionengine/display/gl/shaders/objectshader.js +1756 -0
- package/actionengine/display/gl/shaders/particleshader.js +43 -0
- package/actionengine/display/gl/shaders/shadowshader.js +319 -0
- package/actionengine/display/gl/shaders/spriteshader.js +100 -0
- package/actionengine/display/gl/shaders/watershader.js +67 -0
- package/actionengine/display/graphics/actionmodel3D.js +191 -0
- package/actionengine/display/graphics/actionsprite3D.js +230 -0
- package/actionengine/display/graphics/lighting/actiondirectionalshadowlight.js +864 -0
- package/actionengine/display/graphics/lighting/actionlight.js +211 -0
- package/actionengine/display/graphics/lighting/actionomnidirectionalshadowlight.js +862 -0
- package/actionengine/display/graphics/lighting/lightingconstants.js +263 -0
- package/actionengine/display/graphics/lighting/lightmanager.js +789 -0
- package/actionengine/display/graphics/renderableobject.js +44 -0
- package/actionengine/display/graphics/renderers/actionrenderer2D.js +341 -0
- package/actionengine/display/graphics/renderers/actionrenderer3D/actionrenderer3D.js +655 -0
- package/actionengine/display/graphics/renderers/actionrenderer3D/canvasmanager3D.js +82 -0
- package/actionengine/display/graphics/renderers/actionrenderer3D/debugrenderer3D.js +493 -0
- package/actionengine/display/graphics/renderers/actionrenderer3D/objectrenderer3D.js +790 -0
- package/actionengine/display/graphics/renderers/actionrenderer3D/spriteRenderer3D.js +266 -0
- package/actionengine/display/graphics/renderers/actionrenderer3D/sunrenderer3D.js +140 -0
- package/actionengine/display/graphics/renderers/actionrenderer3D/waterrenderer3D.js +173 -0
- package/actionengine/display/graphics/renderers/actionrenderer3D/weatherrenderer3D.js +87 -0
- package/actionengine/display/graphics/texture/proceduraltexture.js +192 -0
- package/actionengine/display/graphics/texture/texturemanager.js +242 -0
- package/actionengine/display/graphics/texture/textureregistry.js +177 -0
- package/actionengine/input/actionscrollablearea.js +1405 -0
- package/actionengine/input/inputhandler.js +1647 -0
- package/actionengine/math/geometry/geometrybuilder.js +161 -0
- package/actionengine/math/geometry/glbexporter.js +364 -0
- package/actionengine/math/geometry/glbloader.js +722 -0
- package/actionengine/math/geometry/modelcodegenerator.js +97 -0
- package/actionengine/math/geometry/triangle.js +33 -0
- package/actionengine/math/geometry/triangleutils.js +34 -0
- package/actionengine/math/mathutils.js +25 -0
- package/actionengine/math/matrix4.js +785 -0
- package/actionengine/math/physics/actionphysics.js +108 -0
- package/actionengine/math/physics/actionphysicsobject3D.js +164 -0
- package/actionengine/math/physics/actionphysicsworld3D.js +238 -0
- package/actionengine/math/physics/actionraycast.js +129 -0
- package/actionengine/math/physics/shapes/actionphysicsbox3D.js +158 -0
- package/actionengine/math/physics/shapes/actionphysicscapsule3D.js +200 -0
- package/actionengine/math/physics/shapes/actionphysicscompoundshape3D.js +147 -0
- package/actionengine/math/physics/shapes/actionphysicscone3D.js +126 -0
- package/actionengine/math/physics/shapes/actionphysicsconvexshape3D.js +72 -0
- package/actionengine/math/physics/shapes/actionphysicscylinder3D.js +117 -0
- package/actionengine/math/physics/shapes/actionphysicsmesh3D.js +74 -0
- package/actionengine/math/physics/shapes/actionphysicsplane3D.js +100 -0
- package/actionengine/math/physics/shapes/actionphysicssphere3D.js +95 -0
- package/actionengine/math/quaternion.js +61 -0
- package/actionengine/math/vector2.js +277 -0
- package/actionengine/math/vector3.js +318 -0
- package/actionengine/math/viewfrustum.js +136 -0
- package/actionengine/network/ACTIONNETREADME.md +810 -0
- package/actionengine/network/client/ActionNetManager.js +802 -0
- package/actionengine/network/client/ActionNetManagerGUI.js +1709 -0
- package/actionengine/network/client/ActionNetManagerP2P.js +1537 -0
- package/actionengine/network/client/SyncSystem.js +422 -0
- package/actionengine/network/p2p/ActionNetPeer.js +142 -0
- package/actionengine/network/p2p/ActionNetTrackerClient.js +623 -0
- package/actionengine/network/p2p/DataConnection.js +282 -0
- package/actionengine/network/p2p/README.md +510 -0
- package/actionengine/network/p2p/example.html +502 -0
- package/actionengine/network/server/ActionNetServer.js +577 -0
- package/actionengine/network/server/ActionNetServerSSL.js +579 -0
- package/actionengine/network/server/ActionNetServerUtils.js +458 -0
- package/actionengine/network/server/SERVERREADME.md +314 -0
- package/actionengine/network/server/package-lock.json +35 -0
- package/actionengine/network/server/package.json +13 -0
- package/actionengine/network/server/start.bat +27 -0
- package/actionengine/network/server/start.sh +25 -0
- package/actionengine/network/server/startwss.bat +27 -0
- package/actionengine/sound/audiomanager.js +1589 -0
- package/actionengine/sound/soundfont/ACTIONSOUNDFONT_README.md +205 -0
- package/actionengine/sound/soundfont/actionparser.js +718 -0
- package/actionengine/sound/soundfont/actionreverb.js +252 -0
- package/actionengine/sound/soundfont/actionsoundfont.js +543 -0
- package/actionengine/sound/soundfont/sf2playerlicence.txt +29 -0
- package/actionengine/sound/soundfont/soundfont.js +2 -0
- package/dist/action-engine.min.js +328 -0
- package/package.json +35 -0
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
// actionengine/sound/actionreverb.js
|
|
2
|
+
// ActionReverb - Reverb effect for audio processing
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* ActionReverb Class
|
|
6
|
+
* Provides reverb effect using convolver node
|
|
7
|
+
*/
|
|
8
|
+
class ActionReverb {
|
|
9
|
+
constructor(ctx, providedOptions = {}) {
|
|
10
|
+
const defaultOptions = {
|
|
11
|
+
decay: 5,
|
|
12
|
+
delay: 0,
|
|
13
|
+
filterFreq: 2200,
|
|
14
|
+
filterQ: 1,
|
|
15
|
+
filterType: 'lowpass',
|
|
16
|
+
mix: 0.5,
|
|
17
|
+
reverse: false,
|
|
18
|
+
time: 3
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const options = { ...defaultOptions, ...providedOptions };
|
|
22
|
+
|
|
23
|
+
this.ctx = ctx;
|
|
24
|
+
this.wetGainNode = this.ctx.createGain();
|
|
25
|
+
this.dryGainNode = this.ctx.createGain();
|
|
26
|
+
this.filterNode = this.ctx.createBiquadFilter();
|
|
27
|
+
this.convolverNode = this.ctx.createConvolver();
|
|
28
|
+
this.outputNode = this.ctx.createGain();
|
|
29
|
+
|
|
30
|
+
this._decay = options.decay;
|
|
31
|
+
this._delay = options.delay;
|
|
32
|
+
this._reverse = options.reverse;
|
|
33
|
+
this._time = options.time;
|
|
34
|
+
this._filterType = options.filterType;
|
|
35
|
+
this._freq = options.filterFreq;
|
|
36
|
+
this._q = options.filterQ;
|
|
37
|
+
this._mix = options.mix;
|
|
38
|
+
|
|
39
|
+
this.time(this._time);
|
|
40
|
+
this.delay(this._delay);
|
|
41
|
+
this.decay(this._decay);
|
|
42
|
+
this.reverse(this._reverse);
|
|
43
|
+
this.filterType(this._filterType);
|
|
44
|
+
this.filterFreq(this._freq);
|
|
45
|
+
this.filterQ(this._q);
|
|
46
|
+
this.mix(this._mix);
|
|
47
|
+
|
|
48
|
+
this.isConnected = false;
|
|
49
|
+
|
|
50
|
+
this.buildImpulse();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Connect source node through reverb
|
|
55
|
+
* @param {AudioNode} sourceNode
|
|
56
|
+
* @return {AudioNode}
|
|
57
|
+
*/
|
|
58
|
+
connect(sourceNode) {
|
|
59
|
+
this.isConnected = true;
|
|
60
|
+
|
|
61
|
+
// Connect convolver to filter
|
|
62
|
+
this.convolverNode.connect(this.filterNode);
|
|
63
|
+
// Connect filter to wet gain
|
|
64
|
+
this.filterNode.connect(this.wetGainNode);
|
|
65
|
+
// Connect input to convolver
|
|
66
|
+
sourceNode.connect(this.convolverNode);
|
|
67
|
+
// Connect dry path
|
|
68
|
+
sourceNode.connect(this.dryGainNode).connect(this.outputNode);
|
|
69
|
+
// Connect wet path
|
|
70
|
+
sourceNode.connect(this.wetGainNode).connect(this.outputNode);
|
|
71
|
+
|
|
72
|
+
return this.outputNode;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Disconnect source node from reverb
|
|
77
|
+
* @param {AudioNode} sourceNode
|
|
78
|
+
* @return {AudioNode}
|
|
79
|
+
*/
|
|
80
|
+
disconnect(sourceNode) {
|
|
81
|
+
try {
|
|
82
|
+
this.convolverNode.disconnect(this.filterNode);
|
|
83
|
+
this.filterNode.disconnect(this.wetGainNode);
|
|
84
|
+
sourceNode.disconnect(this.convolverNode);
|
|
85
|
+
sourceNode.disconnect(this.dryGainNode);
|
|
86
|
+
this.dryGainNode.disconnect(this.outputNode);
|
|
87
|
+
sourceNode.disconnect(this.wetGainNode);
|
|
88
|
+
this.wetGainNode.disconnect(this.outputNode);
|
|
89
|
+
} catch (e) {
|
|
90
|
+
// Nodes may already be disconnected
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
this.isConnected = false;
|
|
94
|
+
return sourceNode;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Set dry/wet mix level
|
|
99
|
+
* @param {number} mix - Mix level (0.0 to 1.0)
|
|
100
|
+
*/
|
|
101
|
+
mix(mix) {
|
|
102
|
+
if (!this.inRange(mix, 0, 1)) {
|
|
103
|
+
console.warn('[ActionReverb] Dry/Wet level must be between 0 to 1.');
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
this._mix = mix;
|
|
107
|
+
this.dryGainNode.gain.value = 1 - this._mix;
|
|
108
|
+
this.wetGainNode.gain.value = this._mix;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Set impulse response time length
|
|
113
|
+
* @param {number} value - Time in seconds
|
|
114
|
+
*/
|
|
115
|
+
time(value) {
|
|
116
|
+
if (!this.inRange(value, 1, 50)) {
|
|
117
|
+
console.warn('[ActionReverb] Time length of impulse response must be less than 50sec.');
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
this._time = value;
|
|
121
|
+
this.buildImpulse();
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Set impulse response decay rate
|
|
126
|
+
* @param {number} value - Decay level
|
|
127
|
+
*/
|
|
128
|
+
decay(value) {
|
|
129
|
+
if (!this.inRange(value, 0, 100)) {
|
|
130
|
+
console.warn('[ActionReverb] Impulse Response decay level must be less than 100.');
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
this._decay = value;
|
|
134
|
+
this.buildImpulse();
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Set impulse response delay time
|
|
139
|
+
* @param {number} value - Delay time
|
|
140
|
+
*/
|
|
141
|
+
delay(value) {
|
|
142
|
+
if (!this.inRange(value, 0, 100)) {
|
|
143
|
+
console.warn('[ActionReverb] Impulse Response delay time must be less than 100.');
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
this._delay = value;
|
|
147
|
+
this.buildImpulse();
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Reverse the impulse response
|
|
152
|
+
* @param {boolean} reverse
|
|
153
|
+
*/
|
|
154
|
+
reverse(reverse) {
|
|
155
|
+
this._reverse = reverse;
|
|
156
|
+
this.buildImpulse();
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Set filter type
|
|
161
|
+
* @param {BiquadFilterType} type
|
|
162
|
+
*/
|
|
163
|
+
filterType(type) {
|
|
164
|
+
this._filterType = type;
|
|
165
|
+
this.filterNode.type = type;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Set filter frequency
|
|
170
|
+
* @param {number} freq - Frequency in Hz
|
|
171
|
+
*/
|
|
172
|
+
filterFreq(freq) {
|
|
173
|
+
if (!this.inRange(freq, 20, 5000)) {
|
|
174
|
+
console.warn('[ActionReverb] Filter frequency must be between 20 and 5000.');
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
this._freq = freq;
|
|
178
|
+
this.filterNode.frequency.value = this._freq;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Set filter quality
|
|
183
|
+
* @param {number} q - Quality value
|
|
184
|
+
*/
|
|
185
|
+
filterQ(q) {
|
|
186
|
+
if (!this.inRange(q, 0, 10)) {
|
|
187
|
+
console.warn('[ActionReverb] Filter quality value must be between 0 and 10.');
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
this._q = q;
|
|
191
|
+
this.filterNode.Q.value = this._q;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Check if value is in range
|
|
196
|
+
* @private
|
|
197
|
+
* @param {number} x - Target value
|
|
198
|
+
* @param {number} min - Minimum value
|
|
199
|
+
* @param {number} max - Maximum value
|
|
200
|
+
* @return {boolean}
|
|
201
|
+
*/
|
|
202
|
+
inRange(x, min, max) {
|
|
203
|
+
return ((x - min) * (x - max) <= 0);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Build impulse response buffer
|
|
208
|
+
* @private
|
|
209
|
+
*/
|
|
210
|
+
buildImpulse() {
|
|
211
|
+
const rate = this.ctx.sampleRate;
|
|
212
|
+
const length = Math.max(rate * this._time, 1);
|
|
213
|
+
const delayDuration = rate * this._delay;
|
|
214
|
+
const impulse = this.ctx.createBuffer(2, length, rate);
|
|
215
|
+
const impulseL = new Float32Array(length);
|
|
216
|
+
const impulseR = new Float32Array(length);
|
|
217
|
+
|
|
218
|
+
for (let i = 0; i < length; i++) {
|
|
219
|
+
let n = 0;
|
|
220
|
+
|
|
221
|
+
if (i < delayDuration) {
|
|
222
|
+
impulseL[i] = 0;
|
|
223
|
+
impulseR[i] = 0;
|
|
224
|
+
n = this._reverse ? length - (i - delayDuration) : i - delayDuration;
|
|
225
|
+
} else {
|
|
226
|
+
n = this._reverse ? length - i : i;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const pow = Math.pow(1 - n / length, this._decay);
|
|
230
|
+
|
|
231
|
+
impulseL[i] = this.getNoise(pow);
|
|
232
|
+
impulseR[i] = this.getNoise(pow);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
impulse.getChannelData(0).set(impulseL);
|
|
236
|
+
impulse.getChannelData(1).set(impulseR);
|
|
237
|
+
|
|
238
|
+
this.convolverNode.buffer = impulse;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Generate white noise
|
|
243
|
+
* @private
|
|
244
|
+
* @param {number} rate - Attenuation rate
|
|
245
|
+
* @return {number}
|
|
246
|
+
*/
|
|
247
|
+
getNoise(rate) {
|
|
248
|
+
return (Math.random() * 2 - 1) * rate;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
window.ActionReverb = ActionReverb;
|