diff options
Diffstat (limited to 'assets/javascripts/rectangles/engine/builder.js')
| -rw-r--r-- | assets/javascripts/rectangles/engine/builder.js | 71 |
1 files changed, 40 insertions, 31 deletions
diff --git a/assets/javascripts/rectangles/engine/builder.js b/assets/javascripts/rectangles/engine/builder.js index 8e1508a..c48e8e4 100644 --- a/assets/javascripts/rectangles/engine/builder.js +++ b/assets/javascripts/rectangles/engine/builder.js @@ -19,12 +19,9 @@ var builder = new function(){ } function build (){ clipper.rooms = sort_rooms_by_id(clipper.rooms) - clipper.rooms.forEach(function(r){ - r.walls = [] - r.floors = [] - }) + clipper.regions.forEach(function(r){ - walls(r).forEach(function(el){ + build_walls(r).forEach(function(el){ els.push(el) scene.add(el) }) @@ -32,7 +29,7 @@ var builder = new function(){ clipper.rooms = sort_rooms_by_height(clipper.rooms) clipper.rooms.forEach(function(r){ - floors(r).forEach(function(el){ + build_floors(r).forEach(function(el){ els.push(el) scene.add(el) }) @@ -45,7 +42,9 @@ var builder = new function(){ els = [] } - function walls (r){ + function build_walls (r){ + var rm = clipper.rooms[ r.id ] + var list = [], el = null var width = r.x.length() @@ -53,50 +52,54 @@ var builder = new function(){ var height = clipper.rooms[r.id].height if (r.sides & FRONT) { - el = wall('.front') + el = make_wall('.front') el.width = width el.height = height el.rotationY = PI el.x = r.x.a + width/2 el.y = height/2 el.z = r.y.a + rm.$walls.push(el.el) list.push(el) } if (r.sides & BACK) { - var el = wall('.back') + var el = make_wall('.back') el.width = width el.height = height el.rotationY = 0 el.x = r.x.b - width/2 el.y = height/2 el.z = r.y.b + rm.$walls.push(el.el) list.push(el) } if (r.sides & LEFT) { - el = wall('.left') + el = make_wall('.left') el.rotationY = HALF_PI el.height = height el.width = depth el.x = r.x.a el.y = height/2 el.z = r.y.a + depth/2 + rm.$walls.push(el.el) list.push(el) } if (r.sides & RIGHT) { - el = wall('.right') + el = make_wall('.right') el.rotationY = -HALF_PI el.height = height el.width = depth el.x = r.x.b el.y = height/2 el.z = r.y.b - depth/2 + rm.$walls.push(el.el) list.push(el) } return list } - function floors(rm){ + function build_floors(rm){ var list = [], el = null var already_constructed = rm.intersects.filter(function(rr){ return rr.constructed }) @@ -115,28 +118,38 @@ var builder = new function(){ else if (already_constructed[i].rect.intersects(r)) { intersected = true if (rm.height < already_constructed[i].height) { - list = list.concat( ceiling_walls( rm, already_constructed[i], r ) ) + list = list.concat( make_ceiling_walls( rm, already_constructed[i], r ) ) } } } if (! intersected) { - list.push( ground(rm, r) ) - list.push( ceiling(rm, r) ) + el = make_floor(rm, r) + list.push( el ) + rm.$floor.push(el.el) + + el = make_ceiling(rm, r) + list.push( el ) + rm.$ceiling.push(el.el) } }) } else { // render floor and ceiling for the entire rectangle - list.push( ground(rm, rm.rect) ) - list.push( ceiling(rm, rm.rect) ) + el = make_floor(rm, rm.rect) + list.push( el ) + rm.$floor.push(el.el) + + el = make_ceiling(rm, rm.rect) + list.push( el ) + rm.$ceiling.push(el.el) } rm.constructed = true return list } - function ceiling_walls( lo, hi, r ){ + function make_ceiling_walls( lo, hi, r ){ var list = [] var width = r.x.length() @@ -144,7 +157,7 @@ var builder = new function(){ var height = hi.height - lo.height if (! (r.sides & LEFT) && r.x.a == hi.rect.x.a) { - el = wall('.left') + el = make_wall('.left') el.rotationY = HALF_PI el.height = height el.width = depth @@ -157,7 +170,7 @@ var builder = new function(){ } if (! (r.sides & RIGHT) && r.x.b == hi.rect.x.b) { - el = wall('.right') + el = make_wall('.right') el.rotationY = -HALF_PI el.height = height el.width = depth @@ -169,7 +182,7 @@ var builder = new function(){ } if (! (r.sides & FRONT) && r.y.a == hi.rect.y.a) { - el = wall('.front') + el = make_wall('.front') el.width = width el.height = height el.rotationY = PI @@ -181,7 +194,7 @@ var builder = new function(){ } if (! (r.sides & BACK) && r.y.b == hi.rect.y.b) { - el = wall('.back') + el = make_wall('.back') el.width = width el.height = height el.rotationY = 0 @@ -194,40 +207,36 @@ var builder = new function(){ return list } - function ground(rm, r){ + function make_floor(rm, r){ var width = r.x.length() var depth = r.y.length() - var el = wall('.bottom') + var el = make_wall('.floor') el.height = depth el.width = width el.x = r.x.a + width/2 el.y = 0 el.z = r.y.a + depth/2 el.rotationX = PI/2 - el.el.style.backgroundColor = "#f00" - - rm.floors.push(el) return el } - function ceiling(rm, r){ + function make_ceiling(rm, r){ var width = r.x.length() var depth = r.y.length() var height = rm.height - var el = wall('.top') + var el = make_wall('.ceiling') el.height = depth el.width = width el.x = r.x.a + width/2 el.y = height el.z = r.y.a + depth/2 el.rotationX = -PI/2 - el.el.style.backgroundColor = "#00f" return el } - function wall(klass){ + function make_wall(klass){ var el = new MX.Object3D(".face" + (klass || "")) el.width = el.height = el.scaleX = el.scaleY = el.scaleZ = 1 el.z = el.y = el.x = 0 |
