Class: Floorplanner::Opening3D

Inherits:
Geom::TriangleMesh show all
Defined in:
lib/floorplanner/opening3d.rb

Constant Summary collapse

TYPE_DOOR =
1
TYPE_WINDOW =
2

Instance Attribute Summary collapse

Attributes inherited from Geom::TriangleMesh

#data, #faces, #meshes, #tess, #texcoord, #vertices

Instance Method Summary collapse

Methods inherited from Geom::TriangleMesh

#<<, #bounding_box, #merge, #reverse, #transform_vertices, #update

Constructor Details

#initialize(baseline, thickness, opening) ⇒ Opening3D

Returns a new instance of Opening3D.



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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/floorplanner/opening3d.rb', line 9

def initialize(baseline,thickness,opening)
  super()
  base_z    = opening[:position].z
  @position = baseline.snap(opening[:position])
  @type     = opening[:type]
  @size     = opening[:size]
  dir = baseline.direction
  angle  = Math.atan2(dir.y,dir.x)
  width  = opening[:size].x

  case @type
  when TYPE_DOOR
    @position.z = 0.01
    height = @size.z == 0 ? Floorplanner.config['openings']['door_height'] : @size.z
  else
    @position.z = base_z == 0 ? Floorplanner.config['openings']['window_base'] : base_z
    height = @size.z == 0 ? Floorplanner.config['openings']['window_height'] : @size.z
  end

  v1 = Geom::Vertex.new(-width/2,0,0)
  v2 = Geom::Vertex.new( width/2,0,0)
  o_base = Geom::Edge.new(v1,v2)

  # create opening side
  o_inner = o_base.offset(thickness/2.0,Wall3D::UP)
  o_outer = o_base.offset(-thickness/2.0,Wall3D::UP)

  @base = Geom::Polygon.new([
    o_inner.end_point, o_inner.start_point,
    o_outer.start_point  , o_outer.end_point
  ])

  # rotate in wall's direction
  @base.transform_vertices(Geom::Matrix3D.rotationZ(angle))
  # move to position
  @base.transform_vertices(Geom::Matrix3D.translation(@position.x,@position.y,@position.z))

  extrusion = @base.extrude(height,Wall3D::UP,nil,false)

  # delete sides
  extrusion.delete_at(0)
  extrusion.delete_at(1)

  # flip top cap
  extrusion.last.reverse

  @meshes << @base
  @meshes.concat(extrusion)

  # create glass
  if @type == TYPE_WINDOW
    g_inner = o_base.offset( 0.02, Wall3D::UP)
    g_outer = o_base.offset(-0.02, Wall3D::UP)

    glass_base = Geom::Polygon.new([
      g_inner.end_point, g_inner.start_point,
      g_outer.start_point  , g_outer.end_point
    ])

    # rotate in wall's direction
    glass_base.transform_vertices(Geom::Matrix3D.rotationZ(angle))
    # move to position
    glass_base.transform_vertices(Geom::Matrix3D.translation(@position.x,@position.y,@position.z))

    extrusion = glass_base.extrude(height,Wall3D::UP,nil,false)

    # flip base cap
    glass_base.reverse

    @window = Geom::TriangleMesh.new
    @window.meshes.concat extrusion
    @window << glass_base
    @window.update
  end
end

Instance Attribute Details

#positionObject

Returns the value of attribute position.



7
8
9
# File 'lib/floorplanner/opening3d.rb', line 7

def position
  @position
end

#windowObject

Returns the value of attribute window.



7
8
9
# File 'lib/floorplanner/opening3d.rb', line 7

def window
  @window
end

Instance Method Details

#drill(mesh, outer) ⇒ Object

drill hole to sides



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/floorplanner/opening3d.rb', line 86

def drill(mesh,outer)
  side = outer ? mesh.meshes.first : mesh.meshes.last

  # opening start
  t1   = @meshes.first.vertices[outer ? 0 : 3].clone
  t1.z = side.vertices[0].z
  t1b  = @meshes[3].vertices[outer ? 0 : 3]

  b1   = @meshes.first.vertices[outer ? 0 : 3].clone
  b1.z = side.vertices[2].z
  b1t  = @meshes.first.vertices[outer ? 0 : 3]

  # opening end
  t2   = @meshes.first.vertices[outer ? 1 : 2].clone
  t2.z = side.vertices[0].z
  t2b  = @meshes[3].vertices[outer ? 1 : 2]

  b2   = @meshes.first.vertices[outer ? 1 : 2].clone
  b2.z = side.vertices[2].z
  b2t  = @meshes.first.vertices[outer ? 1 : 2]

  # old side vertices
  ot = side.vertices[1]
  ob = side.vertices[2]
  side.vertices[1] = outer ? t2 : t1
  side.vertices[2] = outer ? b2 : b1

  # polygon above opening
  op_top = Geom::Polygon.new
  if outer
    op_top.vertices.push(t2,t1,t1b,t2b)
  else
    op_top.vertices.push(t1,t2,t2b,t1b)
  end

  # polygon below opening
  op_bot = Geom::Polygon.new
  if outer
    op_bot.vertices.push(b2t,b1t,b1,b2)
  else
    op_bot.vertices.push(b1t,b2t,b2,b1)
  end

  rest = Geom::Polygon.new
  if outer
    rest.vertices.push(t1,ot,ob,b1)
  else
    rest.vertices.push(t2,ot,ob,b2)
  end

  mesh.meshes.push(op_top)
  mesh.meshes.push(op_bot)
  mesh.meshes.push(rest)
end