1
1
import MissingCharacter from '@assets/missing_character.png'
2
2
import EVENTS from '@events'
3
3
import { createHash } from 'crypto'
4
- import { type Alignment } from '../../blockbench-additions/outliner-elements/textDisplay'
5
4
import { mergeGeometries } from '../../util/bufferGeometryUtils'
6
5
import { getPathFromResourceLocation } from '../../util/minecraftUtil'
7
6
import { UnicodeString } from '../../util/unicodeString'
7
+ import type { TextDisplayConfig } from '../node-configs'
8
8
import * as assets from './assetManager'
9
9
import { COLOR_MAP , JsonText } from './jsonText'
10
10
import {
@@ -354,27 +354,21 @@ export class MinecraftFont {
354
354
}
355
355
356
356
async generateTextMesh ( {
357
- jsonText ,
358
- maxLineWidth ,
357
+ textComponent ,
358
+ lineWidth ,
359
359
backgroundColor,
360
- backgroundAlpha,
361
360
shadow,
362
361
alignment,
363
- } : {
364
- jsonText : JsonText
365
- maxLineWidth : number
366
- backgroundColor : string
367
- backgroundAlpha : number
368
- shadow ?: boolean
369
- alignment ?: Alignment
370
- } ) : Promise < { mesh : THREE . Mesh ; outline : THREE . LineSegments } > {
362
+ } : Required < TextDisplayConfig > ) : Promise < { mesh : THREE . Mesh ; outline : THREE . LineSegments } > {
371
363
console . time ( 'drawTextToMesh' )
372
364
const mesh = new THREE . Mesh ( )
373
365
366
+ const jsonText = new JsonText ( textComponent )
374
367
const words = getComponentWords ( jsonText )
375
- const { lines, backgroundWidth } = await computeTextWrapping ( words , maxLineWidth )
368
+ const { lines, backgroundWidth } = await computeTextWrapping ( words , lineWidth )
376
369
const width = backgroundWidth + 1
377
370
const height = lines . length * 10 + 1
371
+
378
372
// // Debug output
379
373
// const wordWidths = words.map(word => this.getWordWidth(word))
380
374
// for (const word of words) {
@@ -392,7 +386,7 @@ export class MinecraftFont {
392
386
// )
393
387
// }
394
388
// }
395
- // console.log('Lines:', lines, 'CanvasWidth:', maxLineWidth )
389
+ // console.log('Lines:', lines, 'CanvasWidth:', lineWidth )
396
390
// for (const line of lines) {
397
391
// console.log('Line', lines.indexOf(line), line.width)
398
392
// for (const word of line.words) {
@@ -411,11 +405,15 @@ export class MinecraftFont {
411
405
// }
412
406
// }
413
407
408
+ const color = tinycolor ( backgroundColor )
409
+ const backgroundHex = color . toHexString ( )
410
+ const backgroundAlpha = color . getAlpha ( )
411
+
414
412
const backgroundGeo = new THREE . PlaneBufferGeometry ( width , height )
415
413
const backgroundMesh = new THREE . Mesh (
416
414
backgroundGeo ,
417
415
new THREE . MeshBasicMaterial ( {
418
- color : backgroundColor ,
416
+ color : backgroundHex ,
419
417
transparent : true ,
420
418
opacity : backgroundAlpha ,
421
419
} )
@@ -535,6 +533,7 @@ export class MinecraftFont {
535
533
if ( style . underlined ) hash . update ( 'underlined' )
536
534
if ( style . strikethrough ) hash . update ( 'strikethrough' )
537
535
if ( style . font ) hash . update ( ';' + font . id )
536
+ // I'm not rendering this...
538
537
// if (style.obfuscated) hash.update('obfuscated')
539
538
const digest = hash . digest ( 'hex' )
540
539
0 commit comments