start fleshing out obj2d.rb
This commit is contained in:
parent
38a3b1e5f2
commit
cbea6ea70f
29
obj2d.rb
29
obj2d.rb
@ -1,7 +1,36 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
require "erb"
|
||||
|
||||
TEMPLATE = <<EOF
|
||||
int foo()
|
||||
{
|
||||
return 42;
|
||||
}
|
||||
EOF
|
||||
|
||||
def main(obj_fname, d_fname)
|
||||
objects = {}
|
||||
vertices = []
|
||||
cur_obj = nil
|
||||
File.read(obj_fname).each_line do |line|
|
||||
if line =~ /^v\s+(\S+)\s+(\S+)/
|
||||
vertices << [$1.to_f, $2.to_f]
|
||||
elsif line =~ /^o\s+(..)-(\d+)/
|
||||
obj_class, obj_class_index = $1, $2.to_i
|
||||
objects[obj_class] ||= []
|
||||
objects[obj_class][obj_class_index] ||= []
|
||||
cur_obj = objects[obj_class][obj_class_index]
|
||||
elsif line =~ /^o\s+(.*)/
|
||||
raise "Do not know how to handle object #{$1.inspect}"
|
||||
elsif line =~ /^f\s+(\d+)\s+(\d+)\s+(\d+)/
|
||||
cur_obj << [$1, $2, $3].map(&:to_i)
|
||||
elsif line =~ /^l\s+(\d+)\s+(\d+)/
|
||||
cur_obj << [$1, $2].map(&:to_i)
|
||||
end
|
||||
end
|
||||
File.open(d_fname, "w") do |fh|
|
||||
fh.puts ERB.new(TEMPLATE, nil, "<>").result
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user