MX.Polyline = MX.Object3D.extend({ init: function(polyline){ this.faces = [] this.points = polyline.points for (var i = 1; i < this.points.length; i++) { var mx = new MX.Object3D() var head = this.points[i-1] var tail = this.points[i] this.move_face(mx, head, tail) this.faces.push(mx) scene.add(mx) } }, rebuild: function(){ for (var i = 1; i < this.points.length; i++) { var mx = this.faces[i-1] var head = this.points[i-1] var tail = this.points[i] this.move_face(mx, head, tail) } }, move_face: function (mx, head, tail){ var mid_x = (head.a + tail.a) var mid_z = (head.b + tail.b) var len = head.distanceTo( tail ) var angle = atan2( head.b - tail.b, head.a - tail.a ) mx.move({ x: mid_x / 2, y: wallHeight/2 + 1, z: mid_z / 2, width: ceil(len), height: wallHeight, rotationY: angle }) var hue = abs(round( angle / PI * 90 + 300)) mx.el.style.backgroundColor = 'hsl(' + [hue, "100%", "50%"] + ')' }, set_height: function(height){ for (var i = 0; i < this.faces.length; i++) { this.faces[i].height = height this.faces[i].y = height / 2 + 1 } }, destroy: function(){ this.faces.forEach(function(mx){ scene.remove(mx) }) this.faces = null this.points = null }, })