Class: OBJ::Mesh

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#facesObject

Returns the value of attribute faces.



5
6
7
# File 'lib/obj.rb', line 5

def faces
  @faces
end

#normalsObject

Returns the value of attribute normals.



5
6
7
# File 'lib/obj.rb', line 5

def normals
  @normals
end

#text_coordsObject

Returns the value of attribute text_coords.



5
6
7
# File 'lib/obj.rb', line 5

def text_coords
  @text_coords
end

#verticesObject

Returns the value of attribute vertices.



5
6
7
# File 'lib/obj.rb', line 5

def vertices
  @vertices
end

Instance Method Details

#normals?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/obj.rb', line 31

def normals?
  !@normals.empty?
end

#text_coords?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/obj.rb', line 35

def text_coords?
  !@text_coords.empty?
end

#to_sObject



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