/* Copyright (C) 2024 Sebastián Santisi , CSC-CONICET */ import * as THREE from 'three'; import { STLLoader } from 'https://cdn.jsdelivr.net/npm/three@0.136.0/examples/jsm/loaders/STLLoader.js'; import { Spring } from './spring.js'; class WindMill extends THREE.Group { static geometryBody = null; static geometryBlades = null; static { const loader = new STLLoader(); loader.load('assets/aspas_126m_85.stl', function(geometry) { WindMill.geometryBlades = geometry; }); loader.load('assets/nacele_126m_90.stl', function(geometry) { //loader.load('assets/cuerpo_126m_50.stl', function(geometry) { WindMill.geometryBody = geometry; }); } static isReady() { return WindMill.geometryBody != null && WindMill.geometryBlades != null; } constructor() { super() this.material = new THREE.MeshStandardMaterial({color: 0xffffff, roughness: 0.15}); this.materialCircle = new THREE.MeshStandardMaterial({color: 0xaa0000}); //this.materialCircle.transparent = true; //this.materialCircle.opacity = 0.5; this.meshBlades = new THREE.Mesh(WindMill.geometryBlades, this.material); this.meshBlades.castShadow = true; this.meshBlades.receiveShadow = true; this.meshBlades.scale.set(0.0075, 0.0075, 0.0075); this.meshBlades.position.z = 90/126; this.meshBody = new THREE.Mesh(WindMill.geometryBody, this.material); this.meshBody.castShadow = true; this.meshBody.receiveShadow = true; this.meshBody.scale.set(0.0075, 0.0075, 0.0075); this.meshBody.position.z = 90/126; var geometry = new THREE.CylinderGeometry(0.02, 0.025, 90/126, 15); this.meshPole = new THREE.Mesh(geometry, this.material); this.meshPole.castShadow = true; this.meshPole.receiveShadow = true; this.meshPole.rotateX(Math.PI/2); this.meshPole.position.z = 90/126/2; this.meshPole.position.x = 0.02; geometry = new THREE.CircleGeometry(0.5, 20); this.meshCircle = new THREE.Mesh(geometry, this.materialCircle); this.meshCircle.receiveShadow = true; this.meshCircle.position.z = 0.001; this.meshCircle.visible = false; this.add(this.meshBlades); this.add(this.meshBody); this.add(this.meshPole); this.add(this.meshCircle); this.spring1 = new Spring(0.5, 2, 20, 6, 1, new THREE.MeshBasicMaterial({color: 0xff0000})); this.spring1.position.z = 90/126; this.spring1.rotation.z = -Math.PI/2; this.spring1.rotation.x = -Math.PI; this.spring1.update(); this.add(this.spring1); this.spring2 = new Spring(0.5, 2, 20, 6, 1, new THREE.MeshBasicMaterial({color: 0xff0000})); this.spring2.position.z = 90/126; this.spring2.rotation.z = -Math.PI/2; this.spring2.rotation.x = -Math.PI * 1 / 3; this.spring2.update(); this.add(this.spring2); this.spring3 = new Spring(0.5, 2, 20, 6, 1, new THREE.MeshBasicMaterial({color: 0xff0000})); this.spring3.position.z = 90/126; this.spring3.rotation.z = -Math.PI/2; this.spring3.rotation.x = Math.PI * 1 / 3; this.spring3.update(); this.add(this.spring3); this.spring1.visible = this.spring2.visible = this.spring3.visible = false; this.selected = false; } animate() { this.meshBlades.rotation.x += 0.1; this.spring1.rotation.x += 0.1; this.spring2.rotation.x += 0.1; this.spring3.rotation.x += 0.1; } select(selected) { if(selected == this.selected) return; this.selected = selected; this.meshCircle.visible = selected; if(selected) this.material.color.set(0xff0000); else this.material.color.set(0xffffff); } show_springs(value) { this.spring1.visible = this.spring2.visible = this.spring3.visible = value; } } export { WindMill };