Browse Source

some work on getting text rendering working better

master
Peter Hajas 3 years ago
parent
commit
697bc82ae6
  1. 37
      script.js

37
script.js

@ -98,14 +98,25 @@ animate()
function createTextMesh(text, colorName) {
let canvas = document.createElement('canvas')
let context = canvas.getContext('2d')
let size = context.measureText(text)
canvas.width = 100
canvas.height = 100
context.textAlign = "center"
context.textBaseline = "middle"
context.fillStyle = colorName
context.font = '24pt sans-serif'
context.fillText(text, 50, 50)
context.font = '144pt sans-serif'
let size = context.measureText(text)
let height = context.measureText('M').width
size.height = height
let canvasScale = 0.1
canvas.width = size.width * canvasScale * 0.6
canvas.height = size.height * canvasScale
console.log([canvas.width, canvas.height])
context.fillStyle = 'red'
context.fillRect(0, 0, canvas.width, canvas.height)
context.fillStyle = 'blue'
context.fillText(text, 5, 10)
let texture = new THREE.CanvasTexture(canvas)
texture.needsUpdate = true
@ -114,7 +125,9 @@ function createTextMesh(text, colorName) {
})
material.transparent = true
let plane = new THREE.PlaneGeometry(3, 3)
let scaleFactor = 0.05
let plane = new THREE.PlaneGeometry(canvas.width * scaleFactor, canvas.height * scaleFactor)
let mesh = new THREE.Mesh(plane, material)
return mesh
@ -223,15 +236,19 @@ function configureScene(data) {
roomLines.userData.name = "lines"
roomContainer.add(roomLines)
let roomLabel = createTextMesh("A test or something", "red")
roomLabel.userData.name = "label"
roomContainer.add(roomLabel)
let roomZ = room.z || 0
setPosition(roomContainer, room.x, room.y, roomZ, room.w, room.h, room.d)
home.add(roomContainer)
let roomLabel = createTextMesh(room.name, room.color)
roomLabel.position.x = roomContainer.position.x
roomLabel.position.y = roomContainer.position.y
roomLabel.position.z = roomZ
roomLabel.renderOrder = 5000
// not yet
// homeContainer.add(roomLabel)
minX = Math.min(minX, room.x)
minY = Math.min(minY, room.y)
minZ = Math.min(minZ, roomZ)

Loading…
Cancel
Save