Sha256: aa47703415bfac5a4ad833081b0f9b41432ba98be468a809ea8e66bf58c3f306
Contents?: true
Size: 1.29 KB
Versions: 8
Compression:
Stored size: 1.29 KB
Contents
require "stringio" module Vamp module Ply class PlyObject attr_reader :vertices attr_reader :polygons def initialize @vertices = [] @polygons = [] @output = StringIO.new end def add_vertex(x, y, z) vertices << ([x.to_f, y.to_f, z.to_f]) end def add_polygon(*vertexes) vertexes.each do |v| fail "unknown vertex #{v}" unless vertices[v.to_i] end polygons << vertexes.map(&:to_i) end def to_s @output = StringIO.new print_header print_vertices print_polygons output.string end private attr_accessor :output def print_header output.puts("# ply file to describe a 3D model") output.puts("#") end def print_vertices output.puts("# list of vertices (3 float values, coordinates)") output.puts("# x y z") vertices.each do |v| output.puts("#{v[0].to_f} #{v[1].to_f} #{v[2].to_f}") end output.puts end def print_polygons output.puts("# list of polygons (3, 4, .. integer values, vertex indices)") polygons.each do |p| output.puts("#{p.join(' ')}") end output.puts end end end end
Version data entries
8 entries across 8 versions & 1 rubygems