Class: OBJ::Mesh
- Inherits:
-
Object
- Object
- OBJ::Mesh
- Defined in:
- lib/obj.rb
Instance Attribute Summary collapse
-
#faces ⇒ Object
Returns the value of attribute faces.
-
#normals ⇒ Object
Returns the value of attribute normals.
-
#text_coords ⇒ Object
Returns the value of attribute text_coords.
-
#vertices ⇒ Object
Returns the value of attribute vertices.
Instance Method Summary collapse
-
#initialize(file_path) ⇒ Mesh
constructor
A new instance of Mesh.
- #normals? ⇒ Boolean
- #text_coords? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(file_path) ⇒ Mesh
Returns a new instance of Mesh.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/obj.rb', line 7 def initialize(file_path) @vertices = [] @normals = [] @text_coords = [] @faces = [] File.open(file_path, 'r') do |f| f.each_line do |line| case line.split.first when 'v' @vertices << 0.0 when 'vt' @text_coords << 0.0 when 'vn' @normals << 0.0 when 'f' @faces << 0.0 when 'mtllib' # fail ArgumentError, 'invalid file (mtllib not supported)' end end end end |
Instance Attribute Details
#faces ⇒ Object
Returns the value of attribute faces.
5 6 7 |
# File 'lib/obj.rb', line 5 def faces @faces end |
#normals ⇒ Object
Returns the value of attribute normals.
5 6 7 |
# File 'lib/obj.rb', line 5 def normals @normals end |
#text_coords ⇒ Object
Returns the value of attribute text_coords.
5 6 7 |
# File 'lib/obj.rb', line 5 def text_coords @text_coords end |
#vertices ⇒ Object
Returns the value of attribute vertices.
5 6 7 |
# File 'lib/obj.rb', line 5 def vertices @vertices end |
Instance Method Details
#normals? ⇒ Boolean
31 32 33 |
# File 'lib/obj.rb', line 31 def normals? !@normals.empty? end |
#text_coords? ⇒ Boolean
35 36 37 |
# File 'lib/obj.rb', line 35 def text_coords? !@text_coords.empty? end |
#to_s ⇒ Object
39 40 41 42 |
# File 'lib/obj.rb', line 39 def to_s "<#{self.class} vertices: #{@vertices.size} normals: #{@normals.size}" \ " text_coords: #{@text_coords.size} faces: #{@faces.size}>" end |