Class: Vamp::Ply::PlyObject

Inherits:
Object
  • Object
show all
Defined in:
lib/vamp/ply/ply_object.rb

Direct Known Subclasses

Cube, Vampire

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePlyObject

Returns a new instance of PlyObject.



9
10
11
12
13
# File 'lib/vamp/ply/ply_object.rb', line 9

def initialize
  @vertices = []
  @polygons = []
  @output = StringIO.new
end

Instance Attribute Details

#polygonsObject (readonly)

Returns the value of attribute polygons.



7
8
9
# File 'lib/vamp/ply/ply_object.rb', line 7

def polygons
  @polygons
end

#verticesObject (readonly)

Returns the value of attribute vertices.



6
7
8
# File 'lib/vamp/ply/ply_object.rb', line 6

def vertices
  @vertices
end

Instance Method Details

#add_polygon(*vertexes) ⇒ Object



19
20
21
22
23
24
# File 'lib/vamp/ply/ply_object.rb', line 19

def add_polygon(*vertexes)
  vertexes.each do |v|
    fail "unknown vertex #{v}" unless vertices[v.to_i]
  end
  polygons << vertexes.map(&:to_i)
end

#add_vertex(x, y, z) ⇒ Object



15
16
17
# File 'lib/vamp/ply/ply_object.rb', line 15

def add_vertex(x, y, z)
  vertices << ([x.to_f, y.to_f, z.to_f])
end

#to_sObject



26
27
28
29
30
31
32
# File 'lib/vamp/ply/ply_object.rb', line 26

def to_s
  @output = StringIO.new
  print_header
  print_vertices
  print_polygons
  output.string
end