Class: Wavefront::Serializer

Inherits:
Object
  • Object
show all
Defined in:
server/lib/game_machine/wavefront_ext.rb

Class Method Summary collapse

Class Method Details

.to_protobuf(wavefront_object) ⇒ Object


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'server/lib/game_machine/wavefront_ext.rb', line 25

def self.to_protobuf(wavefront_object)
  proto_mesh = GameMachine::MessageLib::Mesh.new
  wavefront_object.groups.each do |group|
    group.triangles.each do |triangle|
      proto_poly = GameMachine::MessageLib::Polygon.new
      if triangle.vertices.size != 3
        puts "Invalid vert count #{triangle.vertices.size}"
      end
      triangle.vertices.each do |vertice|
        proto_vector3 = GameMachine::MessageLib::Vector3.new
        proto_vector3.set_x(vertice.position.x)
        proto_vector3.set_y(vertice.position.y)
        proto_vector3.set_z(vertice.position.z)
        proto_poly.add_vertex(proto_vector3)
      end
      proto_mesh.add_polygon(proto_poly)
    end
  end
  proto_mesh
end