forked from kig/three-bmfont-text
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-2d.js
67 lines (57 loc) · 1.55 KB
/
test-2d.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
This is an example of 2D rendering, simply
using bitmap fonts in orthographic space.
var geom = createText({
multipage: true,
... other options
})
*/
global.THREE = require('three')
var createOrbitViewer = require('three-orbit-viewer')(THREE)
var createText = require('../')
require('./load')({
font: 'fnt/Lato-Regular-64.fnt',
image: 'fnt/lato.png'
}, start)
function start (font, texture) {
var app = createOrbitViewer({
clearColor: 'rgb(80, 80, 80)',
clearAlpha: 1.0,
fov: 65,
position: new THREE.Vector3()
})
app.camera = new THREE.OrthographicCamera()
app.camera.left = 0
app.camera.top = 0
app.camera.near = -100
app.camera.far = 100
var geom = createText({
text: 'this bitmap text\nis rendered with \nan OrthographicCamera',
font: font,
align: 'left',
width: 700,
flipY: texture.flipY
})
var material = new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
color: 'rgb(230, 230, 230)'
})
var layout = geom.layout
var text = new THREE.Mesh(geom, material)
var padding = 40
text.position.set(padding, -layout.descender + layout.height + padding, 0)
var textAnchor = new THREE.Object3D()
textAnchor.add(text)
textAnchor.scale.multiplyScalar(1 / (window.devicePixelRatio || 1))
app.scene.add(textAnchor)
// update orthographic
app.on('tick', function () {
// update camera
var width = app.engine.width
var height = app.engine.height
app.camera.right = width
app.camera.bottom = height
app.camera.updateProjectionMatrix()
})
}