-
Notifications
You must be signed in to change notification settings - Fork 3
/
buildings.js
62 lines (60 loc) · 2.23 KB
/
buildings.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
function Buildings(){
this.items = {};
this.modules = {}; //I have to go deeper.
this.from_xml = function(xml){
var nds, child, way, lvl, results = evaluateXPath(xml, "/osm/way[tag/@k='building']");
while(way = results.iterateNext()){
//if(parseInt(way.getAttribute("version"))>3) continue;
id = parseInt(way.getAttribute("id"));
if(processed.ways.indexOf(id) > -1) continue;
ver = parseInt(way.getAttribute("version"));
var tmpway = {};
nds = [];
tmpway.ver = ver;
lvl = 1;
for(var i=0; i<way.children.length; i++){
child = way.children[i];
if(child.tagName==='nd') nds.push(parseInt(child.getAttribute("ref")));
else if(child.tagName==='tag')
if(child.getAttribute("k")==='building:levels') lvl = parseInt(child.getAttribute("v"));
}
var waypoints = [];
for(i=0; i<nds.length; i++){
ref = nds[i];
waypoints.push(nodes[ref]);
}
tmpway.nodes = new Uint32Array(nds);
tmpway.points = waypoints;
tmpway.lvl = lvl;
for(mid in this.modules){
this.modules[mid].parse_itm(tmpway, way);
}
if(processed.ways.indexOf(id)===-1) {
this.items[id] = tmpway;
processed.ways.push(id);
}
delete way;
}
delete results;
}
this.get_mesh = function(meshgroup){
var lvls = {};
for(way in this.items){
waypoints = [];
nds = this.items[way].nodes;
for(i=0; i<nds.length; i++){
ref = nds[i];
waypoints.push(nodes[ref]);
}
if(!lvls[this.items[way].lvl]) lvls[this.items[way].lvl] = [];
lvls[this.items[way].lvl].push(CShape(waypoints));
}
for(lvl in lvls) meshgroup.add( CExtr(lvls[lvl], 0.001, Math.round(Math.random()*0xffffff), lvl) );
}
this.to_render = function(camera){
for(mid in this.modules){
this.modules[mid].to_render(camera);
}
}
}
modules.buildings = new Buildings();