From ef4784334265327ca9a7e2bda19fdcfab2aa20ac Mon Sep 17 00:00:00 2001 From: Peter Hajas Date: Sun, 8 May 2022 17:55:41 -0600 Subject: [PATCH] add sun --- script.js | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/script.js b/script.js index 977f24f..5bac8f9 100644 --- a/script.js +++ b/script.js @@ -26,11 +26,23 @@ scene.add(homeContainer) let home = new THREE.Group() homeContainer.add(home) +let sunContainer = new THREE.Group() + +let sunGeo = new THREE.SphereGeometry(1, 32, 32) +let sunMat = new THREE.MeshBasicMaterial({ color: metrics.color3 }) +let sunMesh = new THREE.Mesh(sunGeo, sunMat) +sunMesh.transparent = true + +sunContainer.add(sunMesh) +homeContainer.add(sunContainer) + // key: area name // value: info var areaData = { } var areasWithEntitiesToUpdate = { } +var haInfo = { } + const renderer = new THREE.WebGLRenderer({ logarithmicDepthBuffer : true }) @@ -117,7 +129,15 @@ function animate() { rotate.start() } - // homeContainer.rotation.z += 0.003 + let sun = haInfo.sun + if (sun != null) { + let elevation = sun.attributes.elevation + let azimuth = sun.attributes.azimuth + + sunMesh.position.y = 15 + sunContainer.rotation.z = -1 * (azimuth / 360) * 2 * Math.PI + sunContainer.rotation.y = (elevation / 360) * 2 * Math.PI + } renderer.render( scene, camera ) } @@ -177,6 +197,11 @@ function updateWithHAData(data) { for (var entity of data) { let id = entity.entity_id + // Special treatment for the sun + if (id == 'sun.sun') { + haInfo.sun = entity + } + let friendlyName = entity.attributes.friendly_name || entity.entity_id for (var area of sortedAreaNames) { let matchesUnderscored = id.includes(area.toLowerCase().replace(' ','_'))