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() let home = new THREE.Group()
homeContainer.add(home) 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 // key: area name
// value: info // value: info
var areaData = { } var areaData = { }
var areasWithEntitiesToUpdate = { } var areasWithEntitiesToUpdate = { }
var haInfo = { }
const renderer = new THREE.WebGLRenderer({ const renderer = new THREE.WebGLRenderer({
logarithmicDepthBuffer : true logarithmicDepthBuffer : true
}) })
@ -117,7 +129,15 @@ function animate() {
rotate.start() 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 ) renderer.render( scene, camera )
} }
@ -177,6 +197,11 @@ function updateWithHAData(data) {
for (var entity of data) { for (var entity of data) {
let id = entity.entity_id 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 let friendlyName = entity.attributes.friendly_name || entity.entity_id
for (var area of sortedAreaNames) { for (var area of sortedAreaNames) {
let matchesUnderscored = id.includes(area.toLowerCase().replace(' ','_')) let matchesUnderscored = id.includes(area.toLowerCase().replace(' ','_'))

Loading…
Cancel
Save