-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
117 lines (102 loc) · 3.26 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import { ShadingScene } from "@openpv/simshady"
import * as THREE from "three"
import { MapControls } from "three/addons/controls/MapControls.js"
import { STLLoader } from "three/examples/jsm/loaders/STLLoader.js"
import { raster } from "./raster"
async function main() {
console.log("Main script started")
const geometry = await loadSTLFile("building.stl")
console.log("geometry:")
console.log(geometry)
const scene = new ShadingScene(50, 11)
scene.addSimulationGeometry(geometry)
let url = "https://www.openpv.de/data/irradiance"
//scene.addElevationRaster(raster, { x: 3, y: 3, z: 0 }, 20)
let mesh = await scene.calculate({
diffuseIrradianceURL: "https://www.openpv.de/data/irradiance",
urlDirectIrrandianceTIF:
"https://www.openpv.de/data/irradiance/geotiff/average_direct_radiation.tif",
urlDiffuseIrrandianceTIF:
"https://www.openpv.de/data/irradiance/geotiff/average_diffuse_radiation.tif",
})
console.log("Mesh calculated:", mesh)
showThreeJS(mesh)
}
async function calibration() {
console.log("Calibration script started")
const geometry = new THREE.BufferGeometry()
const vertices = new Float32Array([
-1.0,
-1.0,
0.0, // Vertex 1
1.0,
-1.0,
0.0, // Vertex 2
0.0,
1.0,
0.0, // Vertex 3
])
geometry.setAttribute("position", new THREE.BufferAttribute(vertices, 3))
const scene = new ShadingScene(50, 11)
scene.addSimulationGeometry(geometry)
let mesh = await scene.calculate({
numberSimulations: 100,
diffuseIrradiance: "https://www.openpv.de/data/irradiance",
urlDirectIrrandianceTIF:
"https://www.openpv.de/data/irradiance/geotiff/average_direct_radiation.tif",
urlDiffuseIrrandianceTIF:
"https://www.openpv.de/data/irradiance/geotiff/average_diffuse_radiation.tif",
})
console.log("Mesh calculated:", mesh)
showThreeJS(mesh)
}
main()
async function loadSTLFile(url) {
const loader = new STLLoader()
const response = await fetch(url)
console.log(response)
const arrayBuffer = await response.arrayBuffer()
return loader.parse(arrayBuffer)
}
function showThreeJS(mesh) {
console.log("Called showThreeJS")
console.log(mesh)
const scene = new THREE.Scene()
const renderer = new THREE.WebGLRenderer()
const camera = new THREE.PerspectiveCamera(
45,
window.innerWidth / window.innerHeight,
0.1,
1000
)
camera.up = new THREE.Vector3(0, 0, 1)
const controls = new MapControls(camera, renderer.domElement)
camera.position.set(0, -5, 5) // Adjust the camera position as needed
camera.up.set(0, 0, 1)
controls.mouseButtons = {
LEFT: THREE.MOUSE.PAN,
MIDDLE: THREE.MOUSE.DOLLY,
RIGHT: THREE.MOUSE.ROTATE,
}
controls.screenSpacePanning = false
controls.maxPolarAngle = Math.PI / 2
scene.add(new THREE.AmbientLight(0xffffff, 1))
renderer.setSize(window.innerWidth, window.innerHeight)
document.body.appendChild(renderer.domElement)
window.addEventListener(
"resize",
function () {
renderer.setSize(window.innerWidth, window.innerHeight)
camera.aspect = window.innerWidth / window.innerHeight
camera.updateProjectionMatrix()
},
false
)
scene.add(mesh)
function animate() {
requestAnimationFrame(animate)
controls.update()
renderer.render(scene, camera)
}
animate()
}