Last active
July 2, 2019 08:09
-
-
Save bnolan/340bebef466bcb7c04262d7bbe81a2d7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
generate () { | |
const text = this.description.text | |
let options: any = { | |
width: this.scale.x * 128 * 2, | |
height: this.scale.y * 128 * 2, | |
} | |
// Make a dynamic texture | |
var dynamicTexture = new B.DynamicTexture('sign-texture', options, this.scene, true) | |
dynamicTexture.hasAlpha = false | |
var ctx = dynamicTexture.getContext() | |
ctx.textAlign = 'center' | |
ctx.font = `${this.fontSize}px 'Source Code Pro', monospace` | |
ctx.fillStyle = this.description.inverted ? 'black' : 'white' | |
ctx.fillRect(0, 0, options.width, options.height) | |
ctx.fillStyle = this.description.inverted ? 'white' : 'black' | |
ctx.fillText(text, options.width / 2, options.height / 2 + 10) | |
if (this.isLink) { | |
let width = this.description.text.length * this.fontSize / 256 * 0.6 | |
ctx.fillRect(options.width / 2 - width * 128, 90, width * 128 * 2, 4) | |
} | |
// dynamicTexture.wrapU = B.Texture.CLAMP_ADDRESSMODE | |
// dynamicTexture.wrapV = B.Texture.CLAMP_ADDRESSMODE | |
dynamicTexture.update(true) | |
const material = new B.StandardMaterial('sign-text', this.scene) | |
material.diffuseColor.set(1, 1, 1) | |
material.diffuseTexture = dynamicTexture | |
material.alpha = 0.999 | |
material.alphaMode = this.description.inverted ? B.Engine.ALPHA_SCREENMODE : B.Engine.ALPHA_MULTIPLY | |
material.zOffset = -4 | |
material.specularColor.set(0, 0, 0) | |
material.emissiveColor.set(1, 1, 1) | |
material.backFaceCulling = false | |
var plane = B.MeshBuilder.CreatePlane('sign', { size: 1 }, this.scene) | |
plane.material = material | |
this.mesh = plane | |
this.setCommon() | |
if (this.isLink) { | |
this.addEvents() | |
} | |
return plane | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment