-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy paththreex.dynamictext2dobject.js
50 lines (41 loc) · 1.6 KB
/
threex.dynamictext2dobject.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
var THREEx = THREEx || {}
//////////////////////////////////////////////////////////////////////////////////
// Constructor //
//////////////////////////////////////////////////////////////////////////////////
/**
* create a plane on which we map 2d text
*/
THREEx.DynamicText2DObject = function(){
var geometry = new THREE.PlaneGeometry(1,1,1)
var material = new THREE.MeshPhongMaterial({
transparent: true
})
THREE.Mesh.call( this, geometry, material )
// create the dynamicTexture
console.assert(this.dynamicTexture === undefined)
var dynamicTexture = new THREEx.DynamicTexture(512,512)
this.dynamicTexture = dynamicTexture
// same parameters as THREEx.DynamicTexture.drawTextCooked
// - TODO take it from the default paramters of the functions
// - no need to duplicate here
this.parameters = {
text : 'Hello World',
margin : 0.1,
lineHeight : 0.2,
align : 'left',
fillStyle : 'blue',
}
// set the texture material
material.map = this.dynamicTexture.texture
this.update()
}
THREEx.DynamicText2DObject.prototype = Object.create( THREE.Mesh.prototype );
THREEx.DynamicText2DObject.prototype.update = function(){
var dynamicTexture = this.dynamicTexture
var parameters = this.parameters
var context = dynamicTexture.context
// update the text
dynamicTexture.clear()
// actually draw the text
dynamicTexture.drawTextCooked(parameters)
}