summaryrefslogtreecommitdiff
path: root/assets/javascripts/rectangles/builder.js
diff options
context:
space:
mode:
Diffstat (limited to 'assets/javascripts/rectangles/builder.js')
-rw-r--r--assets/javascripts/rectangles/builder.js76
1 files changed, 69 insertions, 7 deletions
diff --git a/assets/javascripts/rectangles/builder.js b/assets/javascripts/rectangles/builder.js
index b25bd59..09040a8 100644
--- a/assets/javascripts/rectangles/builder.js
+++ b/assets/javascripts/rectangles/builder.js
@@ -3,8 +3,15 @@ var builder = new function(){
base.tube = new Tube ()
var els = []
-
- base.tube.on("clipper:update", rebuild)
+
+ base.init = function(){
+ base.bind()
+ }
+
+ base.bind = function(){
+ base.tube.on("clipper:update", rebuild)
+ }
+
base.wheel = new wheel({
el: document.querySelector("#map"),
update: function(e, val, delta){
@@ -13,13 +20,14 @@ var builder = new function(){
})
function rebuild(){
- clear()
- build()
+ if (window.scene) {
+ clear()
+ build()
+ }
}
function build (){
clipper.regions.forEach(function(r){
- var walls = r.walls()
- walls.forEach(function(el){
+ walls(r).forEach(function(el){
els.push(el)
scene.add(el)
})
@@ -32,6 +40,60 @@ var builder = new function(){
els = []
}
-}
+ function walls (r){
+ var list = [], el = null
+
+ var width = r.x.length()
+ var depth = r.y.length()
+ var height = 500
+ if (r.sides & FRONT) {
+ el = wall('.front')
+ el.width = width
+ el.height = height
+ el.x = r.x.a + width/2
+ el.z = r.y.a
+ list.push(el)
+ }
+ if (r.sides & BACK) {
+ var el = wall('.back')
+ el.width = width
+ el.height = height
+ el.rotationY = PI
+ el.x = r.x.b - width/2
+ el.z = r.y.b
+ list.push(el)
+ }
+ if (r.sides & LEFT) {
+ el = wall('.left')
+ el.rotationY = -HALF_PI
+ el.height = height
+ el.width = depth
+ el.x = r.x.a
+ el.z = r.y.a + depth/2
+ list.push(el)
+ }
+ if (r.sides & RIGHT) {
+ el = wall('.right')
+ el.rotationY = HALF_PI
+ el.height = height
+ el.width = depth
+ el.x = r.x.b
+ el.z = r.y.b - depth/2
+ list.push(el)
+ }
+
+ function 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
+ el.y = height/2
+ el.type = "Face"
+ return el
+ }
+
+ return list
+ }
+
+}