Class: Wavefront::Group

Inherits:
Object
  • Object
show all
Defined in:
lib/wavefront/group.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(n) ⇒ Group

Returns a new instance of Group.



5
6
7
8
9
# File 'lib/wavefront/group.rb', line 5

def initialize n
  @name = n
  @triangles = []
  @smoothing_groups = []
end

Instance Attribute Details

#materialObject (readonly)

Returns the value of attribute material.



3
4
5
# File 'lib/wavefront/group.rb', line 3

def material
  @material
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/wavefront/group.rb', line 3

def name
  @name
end

#smoothing_groupsObject (readonly)

Returns the value of attribute smoothing_groups.



3
4
5
# File 'lib/wavefront/group.rb', line 3

def smoothing_groups
  @smoothing_groups
end

#trianglesObject (readonly)

Returns the value of attribute triangles.



3
4
5
# File 'lib/wavefront/group.rb', line 3

def triangles
  @triangles
end

Instance Method Details

#add_triangle(triangle) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/wavefront/group.rb', line 29

def add_triangle triangle
  if @current_smoothing_group
    @current_smoothing_group.add_triangle triangle
  else
    @triangles << triangle
  end
end

#merge_smoothing_groups!Object



23
24
25
26
27
# File 'lib/wavefront/group.rb', line 23

def merge_smoothing_groups!
  set_smoothing_group nil
  smoothing_groups.each { |smoothing_group| triangles += smoothing_group.triangles }
  smoothing_groups.clear
end

#num_facesObject



37
38
39
# File 'lib/wavefront/group.rb', line 37

def num_faces
  triangles.size + smoothing_groups.map(&:num_faces).inject(:+).to_i
end

#num_verticesObject



41
42
43
# File 'lib/wavefront/group.rb', line 41

def num_vertices
  triangles.size * 3 + smoothing_groups.map(&:num_vertices).inject(:+).to_i
end

#set_smoothing_group(smoothing_group_name) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/wavefront/group.rb', line 11

def set_smoothing_group smoothing_group_name
  if smoothing_group_name.nil? || 'off' == smoothing_group_name.to_s || '0' == smoothing_group_name.to_s
    @current_smoothing_group = nil
  else
    @current_smoothing_group = smoothing_groups.find{ |sg| sg.name.to_s == smoothing_group_name.to_s }
    if @current_smoothing_group.nil?
      @current_smoothing_group = SmoothingGroup.new smoothing_group_name
      smoothing_groups << @current_smoothing_group
    end
  end
end