-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconstrutor.js
More file actions
48 lines (45 loc) · 1.59 KB
/
construtor.js
File metadata and controls
48 lines (45 loc) · 1.59 KB
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
GUI.guiScene = function() {
this.camera = new THREE.OrthographicCamera(window.innerWidth / -2, window.innerWidth / 2, window.innerHeight / 2, window.innerHeight / -2, -500, 1000);
this.scene = new THREE.Scene();
this.scene.add(this.camera);
this.camera.position.z = 50;
this.camera.lookAt(GUI.origin);
this.addElement = function(object) {
this.scene.add(object);
return object;
}
this.render = function(renderer) {
renderer.render(this.scene, this.camera);
}
this.addTextElement = function(text, x, y, opts) {
if(typeof opts === "undefined") opts = {};
if(typeof opts.z === "undefined") opts.z = 0;
if(typeof opts.textColor === "undefined") opts.textColor = "#000";
var canvas = document.createElement('canvas'),
canvasContext = canvas.getContext('2d');
canvas.style.border = '3px solid #000';
canvas.style.borderRadius = '15px';
canvas.height = 105;
canvasContext.font = "100px Arial";
var textWidth = canvasContext.measureText(text).width;
canvas.width = textWidth;
canvasContext.font = "normal 100px Arial";
//canvasContext.fillStyle = "#f06";
//roundRect(canvasContext, 1, 1, (textWidth - 2), 100, 8);
canvasContext.fillStyle = opts.textColor;
canvasContext.fillText(text, 0, 85);
var texture = new THREE.Texture(canvas);
texture.needsUpdate = true;
var material = new THREE.SpriteMaterial({
map: texture
});
var sprite = new THREE.Sprite(material);
sprite.scale.set(textWidth / 4, 25,25);
sprite.position.set(x,y,opts.z);
this.scene.add(sprite);
//scene.add(sprite);
sprite.position.y += 1.5;
sprite.textWidth = textWidth;
return sprite;
}
}