|
|
|
@ -26,8 +26,11 @@ class WindSimulation {
|
|
|
|
|
|
|
|
|
|
this.wm = null;
|
|
|
|
|
this.simulation = null;
|
|
|
|
|
this.simulationPot = null;
|
|
|
|
|
this.xhr = null;
|
|
|
|
|
|
|
|
|
|
this.lastFrame = Date.now();
|
|
|
|
|
|
|
|
|
|
this.rotation = Math.PI;
|
|
|
|
|
this.targetRotation = Math.PI;
|
|
|
|
|
this.dir = 0;
|
|
|
|
@ -64,18 +67,19 @@ class WindSimulation {
|
|
|
|
|
for(var i = 0; i < this.mills; i++) {
|
|
|
|
|
var wm = new WindMill();
|
|
|
|
|
wm.position.set(4 + 0.5, i + 5 - Math.ceil(this.mills / 2) + 0.5, 0);
|
|
|
|
|
wm.rotation.z = Math.PI;
|
|
|
|
|
wm.rotation.z = this.targetRotation;
|
|
|
|
|
scene.add(wm);
|
|
|
|
|
this.wms.push(wm);
|
|
|
|
|
}
|
|
|
|
|
this.wm = this.wms[0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
move(pos, ended=false) {
|
|
|
|
|
if(this.simulation) {
|
|
|
|
|
scene.remove(this.simulation);
|
|
|
|
|
this.simulation = null;
|
|
|
|
|
}
|
|
|
|
|
move(pos, ended=false, count=2) {
|
|
|
|
|
if(this.simulation)
|
|
|
|
|
this.resetSimulation();
|
|
|
|
|
|
|
|
|
|
if(! count)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
var wm = this.wm;
|
|
|
|
|
|
|
|
|
@ -85,11 +89,22 @@ class WindSimulation {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(wm == null) return false;
|
|
|
|
|
if(pos.x > this.width - 0.5 || pos.x < 0.5 || pos.y > this.height - 0.5 || pos.y < 0.5) return false;
|
|
|
|
|
if(pos.x > this.width - 0.5 || pos.x < 0.5 || pos.y > this.height - 0.5 || pos.y < 0.5) {
|
|
|
|
|
if(pos.x > this.width - 0.5)
|
|
|
|
|
pos.x = this.width - 0.5;
|
|
|
|
|
if(pos.x < 0.5)
|
|
|
|
|
pos.x = 0.5;
|
|
|
|
|
if(pos.y > this.height - 0.5)
|
|
|
|
|
pos.y = this.height - 0.5;
|
|
|
|
|
if(pos.y < 0.5)
|
|
|
|
|
pos.y = 0.5;
|
|
|
|
|
return this.move(pos, ended, count - 1);
|
|
|
|
|
}
|
|
|
|
|
for(var i = 0; i < this.wms.length; i++) {
|
|
|
|
|
if(this.wms[i] == wm) continue;
|
|
|
|
|
if(pos.clone().sub(this.wms[i].position).length() < 1)
|
|
|
|
|
return false;
|
|
|
|
|
if(pos.clone().sub(this.wms[i].position).length() < 1) {
|
|
|
|
|
return this.move(this.wms[i].position.clone().add(pos.clone().sub(this.wms[i].position).normalize()), ended, count - 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
wm.position.x = pos.x;
|
|
|
|
|
wm.position.y = pos.y;
|
|
|
|
@ -99,11 +114,14 @@ class WindSimulation {
|
|
|
|
|
animate() {
|
|
|
|
|
requestAnimationFrame(() => { this.animate(); });
|
|
|
|
|
|
|
|
|
|
var now = Date.now();
|
|
|
|
|
var step = (now - this.lastFrame) / 1000;
|
|
|
|
|
|
|
|
|
|
if(!Screen.isMobile || (Screen.isMobile && screen.clicked)) {
|
|
|
|
|
const intersects = screen.raycaster.intersectObjects(this.wms);
|
|
|
|
|
var wm = null;
|
|
|
|
|
for(var i = 0; i < intersects.length; i++) {
|
|
|
|
|
if(intersects[i].object.geometry.constructor.name != "CylinderGeometry") {
|
|
|
|
|
if(intersects[i].object.constructor.name != "Spring") {
|
|
|
|
|
wm = intersects[i].object.parent;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
@ -111,22 +129,32 @@ class WindSimulation {
|
|
|
|
|
|
|
|
|
|
if(!screen.clicked || Screen.isMobile) {
|
|
|
|
|
if(this.wm != wm) {
|
|
|
|
|
if(this.wm != null) this.wm.select(false);
|
|
|
|
|
if(wm != null) wm.select(true);
|
|
|
|
|
if(this.wm != null) {
|
|
|
|
|
this.wm.select(false);
|
|
|
|
|
document.getElementById("follower").style.display = "none";
|
|
|
|
|
}
|
|
|
|
|
if(wm != null) {
|
|
|
|
|
wm.select(true);
|
|
|
|
|
if(this.simulation) {
|
|
|
|
|
var i = this.wms.indexOf(wm);
|
|
|
|
|
var follower = document.getElementById("follower");
|
|
|
|
|
follower.innerHTML = "Aerogenerador Nº" + (i + 1) + "<br />" + (Math.round(this.simulationPot[i] * 100) / 100) + " GWh (" + Math.round(this.simulationPot[i] * 100 / 14.95) + "%)";
|
|
|
|
|
follower.style.display = "block";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
this.wm = wm;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for(var i = 0; i < this.wms.length; i++)
|
|
|
|
|
this.wms[i].animate();
|
|
|
|
|
this.wms[i].animate(step);
|
|
|
|
|
|
|
|
|
|
var speed = 0.02;
|
|
|
|
|
var speed = 2 * step;
|
|
|
|
|
if(Math.abs(this.targetRotation - this.rotation) > speed) {
|
|
|
|
|
var step = speed * Math.sign(this.targetRotation - this.rotation);
|
|
|
|
|
this.rotation += step;
|
|
|
|
|
for(var i = 0; i < this.wms.length; i++) {
|
|
|
|
|
this.wms[i].animate();
|
|
|
|
|
this.wms[i].rotation.z += step;
|
|
|
|
|
}
|
|
|
|
|
this.flag.rotation.z += step;
|
|
|
|
@ -134,14 +162,25 @@ class WindSimulation {
|
|
|
|
|
|
|
|
|
|
this.flag.animate();
|
|
|
|
|
|
|
|
|
|
if(window.exclamation)
|
|
|
|
|
window.exclamation.rotation.y += 0.02;
|
|
|
|
|
|
|
|
|
|
this.lastFrame = now;
|
|
|
|
|
|
|
|
|
|
renderer.render(scene, camera);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resetSimulation() {
|
|
|
|
|
scene.remove(this.simulation);
|
|
|
|
|
this.simulation = null;
|
|
|
|
|
this.simulationPot = null;
|
|
|
|
|
document.getElementById("follower").style.display = "none";
|
|
|
|
|
document.getElementById("results").style.display = "none";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setRotation(dir) {
|
|
|
|
|
if(this.simulation) {
|
|
|
|
|
scene.remove(this.simulation);
|
|
|
|
|
this.simulation = null;
|
|
|
|
|
}
|
|
|
|
|
if(this.simulation)
|
|
|
|
|
this.resetSimulation();
|
|
|
|
|
|
|
|
|
|
var rotations = {};
|
|
|
|
|
rotations[0] = Math.PI;
|
|
|
|
@ -153,6 +192,30 @@ class WindSimulation {
|
|
|
|
|
this.targetRotation = rotations[dir];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
addWindMill() {
|
|
|
|
|
if(this.mills >= 10) return;
|
|
|
|
|
|
|
|
|
|
this.mills++;
|
|
|
|
|
this.reset();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
removeWindMill() {
|
|
|
|
|
if(this.mills <= 1) return;
|
|
|
|
|
|
|
|
|
|
this.mills--;
|
|
|
|
|
this.reset();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
reset() {
|
|
|
|
|
for(var i = 0; i < this.wms.length; i++)
|
|
|
|
|
scene.remove(this.wms[i]);
|
|
|
|
|
|
|
|
|
|
this.wms = [];
|
|
|
|
|
this.rotation = this.targetRotation;
|
|
|
|
|
|
|
|
|
|
this.init_windmills();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
simulate() {
|
|
|
|
|
if(this.xhr != null)
|
|
|
|
|
this.xhr.abort();
|
|
|
|
@ -165,7 +228,8 @@ class WindSimulation {
|
|
|
|
|
if(this.xhr != xhr) return;
|
|
|
|
|
if (xhr.readyState === 4 && xhr.status === 200) {
|
|
|
|
|
var json = JSON.parse(xhr.responseText);
|
|
|
|
|
this.add_simulation(json.ws);
|
|
|
|
|
console.log(json.pot)
|
|
|
|
|
this.add_simulation(json.ws, json.pot);
|
|
|
|
|
this.xhr = null;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
@ -176,7 +240,17 @@ class WindSimulation {
|
|
|
|
|
xhr.send(data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
add_simulation(ws) {
|
|
|
|
|
add_simulation(ws, pot) {
|
|
|
|
|
var sum = 0;
|
|
|
|
|
for(let i = 0; i < pot.length; i++) {
|
|
|
|
|
this.wms[i].lowPower(pot[i] < 2.75/*14.95 * 0.8*/)
|
|
|
|
|
sum += pot[i];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var results = document.getElementById("results")
|
|
|
|
|
results.innerHTML = (Math.round(sum * 100) / 100) + " GWh (" + Math.round(sum * 100 / 14.95 / pot.length) + "%)";
|
|
|
|
|
results.style.display = "block";
|
|
|
|
|
|
|
|
|
|
var geometry = new THREE.PlaneGeometry(this.width, this.height, 10 * this.width, 10 * this.height);
|
|
|
|
|
var colors = new three.BufferAttribute(new Float32Array(geometry.attributes.position.count * 4), 4);
|
|
|
|
|
geometry.setAttribute('color', colors);
|
|
|
|
@ -190,8 +264,9 @@ class WindSimulation {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(this.simulation)
|
|
|
|
|
scene.remove(this.simulation);
|
|
|
|
|
this.resetSimulation();
|
|
|
|
|
this.simulation = mesh;
|
|
|
|
|
this.simulationPot = pot;
|
|
|
|
|
scene.add(mesh);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -200,7 +275,7 @@ var width = 10;
|
|
|
|
|
var height = 10;
|
|
|
|
|
var ws = new WindSimulation(width, height, 5);
|
|
|
|
|
|
|
|
|
|
var screen = new Screen(camera, renderer, new THREE.Vector3(width / 2 + 0.5, height / 2, -0.65));
|
|
|
|
|
var screen = new Screen(camera, renderer, new THREE.Vector3(width / 2 + 0.5, height / 2, -0.3));
|
|
|
|
|
screen.setMoveCallBack((pos, end) => { ws.move(pos, end); });
|
|
|
|
|
screen.onResize();
|
|
|
|
|
|
|
|
|
@ -232,6 +307,16 @@ window.light = light;
|
|
|
|
|
//scene.add( helper);
|
|
|
|
|
//window.helper = helper;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
window.windmill = WindMill;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
window.ws = ws;
|
|
|
|
|
window.screen = screen;
|
|
|
|
|
window.scene = scene;
|
|
|
|
|