Class: Floorplanner::Wall3D
- Inherits:
-
Geom::TriangleMesh
- Object
- Geom::TriangleMesh
- Floorplanner::Wall3D
- Defined in:
- lib/floorplanner/wall3d.rb
Constant Summary collapse
Instance Attribute Summary collapse
-
#baseline ⇒ Object
Returns the value of attribute baseline.
-
#inner ⇒ Object
Returns the value of attribute inner.
-
#name ⇒ Object
Returns the value of attribute name.
-
#outer ⇒ Object
Returns the value of attribute outer.
-
#outline ⇒ Object
Returns the value of attribute outline.
Attributes inherited from Geom::TriangleMesh
#data, #faces, #meshes, #tess, #texcoord, #vertices
Instance Method Summary collapse
-
#initialize(baseline, thickness, height, name) ⇒ Wall3D
constructor
A new instance of Wall3D.
- #opening(position, size, type) ⇒ Object
-
#prepare(num_start_connections, num_end_connections) ⇒ Object
create base ‘outline’ polygon of wall.
- #update ⇒ Object
- #windows ⇒ Object
Methods inherited from Geom::TriangleMesh
#<<, #bounding_box, #merge, #reverse, #transform_vertices
Constructor Details
#initialize(baseline, thickness, height, name) ⇒ Wall3D
Returns a new instance of Wall3D.
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/floorplanner/wall3d.rb', line 5 def initialize(baseline,thickness,height,name) super() @baseline = baseline @thickness = thickness @height = height @name = name # create inner and outer Edges of wall @inner = @baseline.offset(@thickness/2.0,UP) @outer = @baseline.offset(-@thickness/2.0,UP) @openings = Array.new end |
Instance Attribute Details
#baseline ⇒ Object
Returns the value of attribute baseline.
4 5 6 |
# File 'lib/floorplanner/wall3d.rb', line 4 def baseline @baseline end |
#inner ⇒ Object
Returns the value of attribute inner.
4 5 6 |
# File 'lib/floorplanner/wall3d.rb', line 4 def inner @inner end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/floorplanner/wall3d.rb', line 4 def name @name end |
#outer ⇒ Object
Returns the value of attribute outer.
4 5 6 |
# File 'lib/floorplanner/wall3d.rb', line 4 def outer @outer end |
#outline ⇒ Object
Returns the value of attribute outline.
4 5 6 |
# File 'lib/floorplanner/wall3d.rb', line 4 def outline @outline end |
Instance Method Details
#opening(position, size, type) ⇒ Object
18 19 20 |
# File 'lib/floorplanner/wall3d.rb', line 18 def opening(position,size,type) @openings << {:position => position, :size => size, :type => type} end |
#prepare(num_start_connections, num_end_connections) ⇒ Object
create base ‘outline’ polygon of wall
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 |
# File 'lib/floorplanner/wall3d.rb', line 27 def prepare(num_start_connections,num_end_connections) @outline = Geom::Polygon.new if num_start_connections == 1 || num_start_connections == 2 @outline.vertices.push( @outer.start_point, @inner.start_point) else @outline.vertices.push( @outer.start_point, @baseline.start_point, @inner.start_point) end if num_end_connections == 1 || num_end_connections == 2 @outline.vertices.push( @inner.end_point, @outer.end_point) else @outline.vertices.push( @inner.end_point, @baseline.end_point, @outer.end_point) end @outline.vertices.reverse! @outline.data[:color] = "#ff9999" end |
#update ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/floorplanner/wall3d.rb', line 54 def update @openings.each_with_index do |opening,i| op = Opening3D.new(@baseline,@thickness,opening) op.update @meshes << op @openings[i] = op end @openings = @openings.sort_by{|o| o.position.distance(@baseline.start_point.position)} @outline.update @meshes << @outline # create top cap for wall top_cap = @outline.clone top_cap.transform_vertices(Geom::Matrix3D.translation(0,0,@height)) @meshes << top_cap # flip bottom cap @outline.reverse # create walls side polygons num = @outline.vertices.length starts = [@outer.start_point,@inner.start_point,@baseline.start_point] ends = [@outer.end_point, @inner.end_point, @baseline.end_point] outs = [@outer.start_point,@outer.end_point] @outline.vertices.each_with_index do |v,i| j = @outline.vertices[(i+1) % num] # omit starting and ending polygons next if ( starts.include?(v) && starts.include?(j) ) || ( ends.include?(v) && ends.include?(j) ) edge = Geom::Edge.new(v,j) poly = edge.extrude(@height,UP) mesh = Geom::TriangleMesh.new mesh << poly # drill holes to side @openings.each do |opening| opening.drill(mesh,outs.include?(v)) end mesh.update @meshes << mesh end end |
#windows ⇒ Object
22 23 24 |
# File 'lib/floorplanner/wall3d.rb', line 22 def windows @openings.collect{|o| o.window}.compact end |