Browse Source

add sun

master
Peter Hajas 3 years ago
parent
commit
ef47843342
  1. 27
      script.js

27
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(' ','_'))

Loading…
Cancel
Save