Class: Wavefront::Group
- Inherits:
-
Object
- Object
- Wavefront::Group
- Defined in:
- lib/wavefront/group.rb
Instance Attribute Summary collapse
-
#material ⇒ Object
readonly
Returns the value of attribute material.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#smoothing_groups ⇒ Object
readonly
Returns the value of attribute smoothing_groups.
-
#triangles ⇒ Object
readonly
Returns the value of attribute triangles.
Instance Method Summary collapse
- #add_triangle(triangle) ⇒ Object
-
#initialize(n) ⇒ Group
constructor
A new instance of Group.
- #merge_smoothing_groups! ⇒ Object
- #num_faces ⇒ Object
- #num_vertices ⇒ Object
- #set_smoothing_group(smoothing_group_name) ⇒ Object
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
#material ⇒ Object (readonly)
Returns the value of attribute material.
3 4 5 |
# File 'lib/wavefront/group.rb', line 3 def material @material end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/wavefront/group.rb', line 3 def name @name end |
#smoothing_groups ⇒ Object (readonly)
Returns the value of attribute smoothing_groups.
3 4 5 |
# File 'lib/wavefront/group.rb', line 3 def smoothing_groups @smoothing_groups end |
#triangles ⇒ Object (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_faces ⇒ Object
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_vertices ⇒ Object
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 |