-
Notifications
You must be signed in to change notification settings - Fork 3
/
waynames.js
56 lines (56 loc) · 2.35 KB
/
waynames.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
function Waynames(){
this.items = {};
this.p = modules.ways;
this.parse_itm = function(itm, node){
var id = node.getAttribute("id");
for(var i=0; i<node.children.length; i++){
var child = node.children[i];
if(child.tagName==='tag'){
var k = child.getAttribute("k");
if(k==='name') {
this.items[id] = {};
this.items[id].nm = child.getAttribute("v");
this.items[id].ver = itm.ver;
this.items[id].points = itm.points;
return 1;
}
}
}
}
this.get_mesh = function(meshgroup){
for(way in this.items){
this.items[way].mesh = CTexturedText(this.items[way].nm, 0xffffff);
meshgroup.add( this.items[way].mesh );
this.items[way].mesh.position.z+=0.001;
}
}
this.to_render = function(camera){
for(way in this.items){
if(camera.position.z > 100){
this.items[way].mesh.visible = false;
} else {
var kv = nearest(this.items[way].points, [camera.position.x, camera.position.y]);
//if(!kv[2] || kv[2] === undefined) return;
if(kv[2]>64) {
this.items[way].mesh.visible = false;
continue;
} else {
var k = kv[0];
var l = k===0 ? 1 : k - 1;
var m = this.items[way].points[k > l ? k : l];
var n = this.items[way].points[k > l ? l : k];
var pos = linedist(m, n, [camera.position.x, camera.position.y]);
var angle = Math.atan((m[1]-n[1])/(m[0]-n[0]));
var scale = (Math.min(Math.round(Math.pow(camera.position.z/12, 2)), 6) || 1)/16;
var angle = Math.round((camera.rotation.z-angle)/Math.PI) == 0 ? angle : angle + Math.PI;
this.items[way].mesh.scale.set(scale, scale, 1);
this.items[way].mesh.position.x = pos[0];
this.items[way].mesh.position.y = pos[1];
this.items[way].mesh.rotation.z = angle;
this.items[way].mesh.visible = true;
}
}
}
}
}
modules.ways.modules.waynames = new Waynames();