Browse Source

fix room label display

master
Peter Hajas 3 years ago
parent
commit
c56ff7da44
  1. 29
      script.js

29
script.js

@ -20,7 +20,7 @@ let metrics = {
} }
const scene = new THREE.Scene() const scene = new THREE.Scene()
const camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 ) const camera = new THREE.PerspectiveCamera(80, window.innerWidth / window.innerHeight, 0.1, 1000 )
let homeContainer = new THREE.Group() let homeContainer = new THREE.Group()
scene.add(homeContainer) scene.add(homeContainer)
let home = new THREE.Group() let home = new THREE.Group()
@ -66,7 +66,7 @@ homeContainer.rotation.x = 0.6 * (-Math.PI / 2)
// Returns the first child (or container) whose name matches // Returns the first child (or container) whose name matches
function childWithName(container, name) { function childWithName(container, name) {
if (container.userData.name == name) { if (container.userData.name == name) {
return container; return container
} }
for (var child of container.children) { for (var child of container.children) {
let childMatches = childWithName(child, name) let childMatches = childWithName(child, name)
@ -86,14 +86,15 @@ function animate() {
let updatedEntities = areasWithEntitiesToUpdate[area] let updatedEntities = areasWithEntitiesToUpdate[area]
if (updatedEntities.length > 0) { if (updatedEntities.length > 0) {
areasToUpdate.add(area) areasToUpdate.add(area)
} else {
} }
let label = childWithName(scene, area + "LABEL") let label = childWithName(scene, area + "LABEL")
label.lookAt(camera.position) label.lookAt(camera.position)
} }
for (var area of areasToUpdate) { for (var area of areasToUpdate) {
let updatedEntities = areasWithEntitiesToUpdate[area]
// plh-evil: use these somehow?
let areaContainer = childWithName(scene, area) let areaContainer = childWithName(scene, area)
let box = childWithName(areaContainer, "box") let box = childWithName(areaContainer, "box")
@ -147,20 +148,24 @@ animate()
function createTextMesh(text, colorName) { function createTextMesh(text, colorName) {
let canvas = document.createElement('canvas') let canvas = document.createElement('canvas')
let context = canvas.getContext('2d') let context = canvas.getContext('2d')
let font = '144px monospace'
context.textAlign = "center" context.textAlign = "center"
context.textBaseline = "middle" context.font = font
context.font = '144pt sans-serif'
let size = context.measureText(text) let size = context.measureText(text)
let height = context.measureText('M').width let height = context.measureText('M').width * 1.5
size.height = height size.height = height
let canvasScale = 0.1 let canvasScale = 1
canvas.width = size.width * canvasScale * 0.6 canvas.width = size.width * canvasScale
canvas.height = size.height * canvasScale canvas.height = size.height * canvasScale
context.font = font
console.log([canvas.width, canvas.height])
context.fillStyle = colorName context.fillStyle = colorName
context.fillText(text, 5, 10) context.fillText(text, 0, 100)
let texture = new THREE.CanvasTexture(canvas) let texture = new THREE.CanvasTexture(canvas)
texture.needsUpdate = true texture.needsUpdate = true
@ -170,7 +175,7 @@ function createTextMesh(text, colorName) {
material.transparent = true material.transparent = true
material.depthTest = false material.depthTest = false
let scaleFactor = 0.05 let scaleFactor = 0.005
let plane = new THREE.PlaneGeometry(canvas.width * scaleFactor, canvas.height * scaleFactor) let plane = new THREE.PlaneGeometry(canvas.width * scaleFactor, canvas.height * scaleFactor)
let mesh = new THREE.Mesh(plane, material) let mesh = new THREE.Mesh(plane, material)
@ -192,7 +197,7 @@ function updateWithHAData(data) {
let sortedAreaNames = areaNames let sortedAreaNames = areaNames
sortedAreaNames.sort(function(a, b) { sortedAreaNames.sort(function(a, b) {
return b.length - a.length; return b.length - a.length
}) })
for (var entity of data) { for (var entity of data) {

Loading…
Cancel
Save