Browse Source

Some labels on rooms

master
Peter Hajas 3 years ago
parent
commit
d738ce8509
  1. 49
      script.js

49
script.js

@ -63,7 +63,12 @@ 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")
label.lookAt(camera.position)
} }
for (var area of areasToUpdate) { for (var area of areasToUpdate) {
let areaContainer = childWithName(scene, area) let areaContainer = childWithName(scene, area)
@ -75,6 +80,7 @@ function animate() {
let fadeOut = new TWEEN.Tween(box.material) let fadeOut = new TWEEN.Tween(box.material)
.easing(metrics.animationCurve) .easing(metrics.animationCurve)
.delay(1000)
.to( { opacity: metrics.roomDefaultOpacity }, metrics.roomUnhighlightDuration * 1000) .to( { opacity: metrics.roomDefaultOpacity }, metrics.roomUnhighlightDuration * 1000)
// This will rotate to the area that has a change // This will rotate to the area that has a change
@ -82,10 +88,22 @@ function animate() {
.easing(metrics.animationCurve) .easing(metrics.animationCurve)
.to( { z: areaData[area].angle }, 2000 ) .to( { z: areaData[area].angle }, 2000 )
rotate.chain(fadeIn) let label = childWithName(scene, area + "LABEL")
let labelScaleIn = new TWEEN.Tween(label.material)
.easing(metrics.animationCurve)
.to( { opacity: 1.0 }, 500)
let labelScaleOut = new TWEEN.Tween(label.material)
.delay(1000)
.easing(metrics.animationCurve)
.to( { opacity: 0.0 }, 500)
rotate.chain(fadeIn, labelScaleIn)
fadeIn.chain(fadeOut) fadeIn.chain(fadeOut)
rotate.start() labelScaleIn.chain(labelScaleOut)
rotate.start()
} }
// homeContainer.rotation.z += 0.003 // homeContainer.rotation.z += 0.003
@ -100,7 +118,6 @@ function createTextMesh(text, colorName) {
let context = canvas.getContext('2d') let context = canvas.getContext('2d')
context.textAlign = "center" context.textAlign = "center"
context.textBaseline = "middle" context.textBaseline = "middle"
context.fillStyle = colorName
context.font = '144pt sans-serif' context.font = '144pt sans-serif'
let size = context.measureText(text) let size = context.measureText(text)
@ -111,11 +128,7 @@ function createTextMesh(text, colorName) {
canvas.width = size.width * canvasScale * 0.6 canvas.width = size.width * canvasScale * 0.6
canvas.height = size.height * canvasScale canvas.height = size.height * canvasScale
console.log([canvas.width, canvas.height]) context.fillStyle = colorName
context.fillStyle = 'red'
context.fillRect(0, 0, canvas.width, canvas.height)
context.fillStyle = 'blue'
context.fillText(text, 5, 10) context.fillText(text, 5, 10)
let texture = new THREE.CanvasTexture(canvas) let texture = new THREE.CanvasTexture(canvas)
@ -124,6 +137,7 @@ function createTextMesh(text, colorName) {
map: texture map: texture
}) })
material.transparent = true material.transparent = true
material.depthTest = false
let scaleFactor = 0.05 let scaleFactor = 0.05
@ -231,6 +245,7 @@ function configureScene(data) {
let roomEdgesGeo = new THREE.EdgesGeometry(roomGeo) let roomEdgesGeo = new THREE.EdgesGeometry(roomGeo)
let roomLinesMaterial = new THREE.LineBasicMaterial({ color: roomColor }) let roomLinesMaterial = new THREE.LineBasicMaterial({ color: roomColor })
roomLinesMaterial.transparent = true
roomLinesMaterial.linewidth = 3 roomLinesMaterial.linewidth = 3
let roomLines = new THREE.LineSegments(roomEdgesGeo, roomLinesMaterial) let roomLines = new THREE.LineSegments(roomEdgesGeo, roomLinesMaterial)
roomLines.userData.name = "lines" roomLines.userData.name = "lines"
@ -242,12 +257,10 @@ function configureScene(data) {
home.add(roomContainer) home.add(roomContainer)
let roomLabel = createTextMesh(room.name, room.color) let roomLabel = createTextMesh(room.name, room.color)
roomLabel.position.x = roomContainer.position.x roomLabel.material.opacity = 0
roomLabel.position.y = roomContainer.position.y roomLabel.userData.name = room.name + "LABEL"
roomLabel.position.z = roomZ
roomLabel.renderOrder = 5000 roomContainer.add(roomLabel)
// not yet
// homeContainer.add(roomLabel)
minX = Math.min(minX, room.x) minX = Math.min(minX, room.x)
minY = Math.min(minY, room.y) minY = Math.min(minY, room.y)
@ -321,6 +334,14 @@ function configureScene(data) {
// update in areaData // update in areaData
areaData[room.name].angle = angle - Math.PI/2 areaData[room.name].angle = angle - Math.PI/2
// position label
let label = childWithName(scene, room.name + "LABEL")
let radiusForLabel = radiusXY
label.position.x += (unitX * 6)
label.position.y += (unitY * 6)
label.position.z += (unitZ * 6)
} }
} }

Loading…
Cancel
Save