2020-08-01 21:51:54 +02:00
|
|
|
// 3D Audio-Waves -> maybe also 2D?
|
|
|
|
class Wave extends Visual {
|
2020-08-06 23:44:37 +02:00
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
this.name = "3D Wave";
|
|
|
|
}
|
|
|
|
|
2020-08-01 21:51:54 +02:00
|
|
|
updateData() {
|
|
|
|
let data = audioHandler.getFloatArray();
|
|
|
|
let add = 2 / data.length,
|
|
|
|
x = -1;
|
2020-08-05 11:24:59 +02:00
|
|
|
let outerLoop = 0;
|
2020-08-01 21:51:54 +02:00
|
|
|
for (let i = 0; i < data.length; i++) {
|
2020-08-05 11:24:59 +02:00
|
|
|
//first
|
|
|
|
this.data[outerLoop] = x;
|
|
|
|
this.data[outerLoop + 1] = data[i];
|
|
|
|
this.data[outerLoop + 2] = 0;
|
|
|
|
//second
|
|
|
|
this.data[outerLoop + 3] = x;
|
|
|
|
//third
|
|
|
|
this.data[outerLoop + 6] = x;
|
|
|
|
this.data[outerLoop + 8] = data[i + 1] || 0;
|
|
|
|
outerLoop += 9;
|
2020-08-01 21:51:54 +02:00
|
|
|
x += add;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
draw(program) {
|
|
|
|
this.prepare(program);
|
|
|
|
let position = this.position,
|
|
|
|
positionBuffer = gl.createBuffer();
|
|
|
|
this.rotate(program);
|
|
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
|
|
|
|
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(this.data), gl.DYNAMIC_DRAW);
|
|
|
|
let vao = gl.createVertexArray();
|
|
|
|
gl.bindVertexArray(vao);
|
|
|
|
gl.enableVertexAttribArray(position);
|
|
|
|
gl.vertexAttribPointer(position, 3, gl.FLOAT, true, 0, 0);
|
2020-08-05 11:24:59 +02:00
|
|
|
gl.drawArrays(vConf.get("waveForm", gl.TRIANGLES), 0, this.data.length / 3);
|
2020-08-06 23:44:37 +02:00
|
|
|
this.afterDraw();
|
2020-08-01 21:51:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
rotate(program) {
|
2020-08-05 11:24:59 +02:00
|
|
|
let aspect = c.width / c.height,
|
2020-08-01 21:51:54 +02:00
|
|
|
matrix = [
|
2020-08-05 11:24:59 +02:00
|
|
|
1 / aspect, 0, 0, 0,
|
|
|
|
0, 0.6, 0, 0,
|
|
|
|
0, 0, 1, 0,
|
|
|
|
0, 0, 0, 1
|
|
|
|
]
|
2020-08-06 23:44:37 +02:00
|
|
|
matrix = TDUtils.multiply(matrix, TDUtils.xRotation(vConf.get("rotation-x", 10)));
|
|
|
|
matrix = TDUtils.multiply(matrix, TDUtils.yRotation(vConf.get("rotation-y", 50)));
|
|
|
|
matrix = TDUtils.multiply(matrix, TDUtils.zRotation(vConf.get("rotation-z", -30)));
|
2020-08-01 21:51:54 +02:00
|
|
|
let rotate = gl.getUniformLocation(program, "u_matrix");
|
|
|
|
gl.uniformMatrix4fv(rotate, false, matrix);
|
|
|
|
}
|
|
|
|
|
|
|
|
setup() {
|
2020-08-06 23:44:37 +02:00
|
|
|
this.updateFFT(vConf.get('fftSize', 4096));
|
|
|
|
vConf.get("rotation-z", -30);
|
|
|
|
vConf.get("rotation-y", 50);
|
|
|
|
vConf.get("rotation-x", 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
updateFFT(fftSize) {
|
|
|
|
audioHandler.fftSize(fftSize);
|
|
|
|
this.data = new Float32Array(fftSize * 9);
|
2020-08-01 21:51:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
prepare(program) {
|
|
|
|
this.position = gl.getAttribLocation(program, "a_position");
|
|
|
|
this.color = gl.getUniformLocation(program, "u_color");
|
2020-08-07 19:31:30 +02:00
|
|
|
let lightPos = gl.getUniformLocation(program, "u_lightPos"),
|
|
|
|
light = gl.getUniformLocation(program, "u_light");
|
|
|
|
gl.uniform3fv(lightPos, [
|
|
|
|
vConf.get("light-x", 0),
|
|
|
|
vConf.get("light-y", 5),
|
|
|
|
vConf.get("light-z", -56)
|
|
|
|
]);
|
|
|
|
gl.uniform1f(light, parseFloat(vConf.get("light-strength", 0.3)));
|
2020-08-06 23:44:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
afterDraw() {
|
|
|
|
TDUtils.updateRotate('rotation-x', 10);
|
|
|
|
TDUtils.updateRotate('rotation-y', 50);
|
|
|
|
TDUtils.updateRotate('rotation-z', -30);
|
|
|
|
vConf.save();
|
2020-08-01 21:51:54 +02:00
|
|
|
}
|
|
|
|
}
|