Advertisement
Guest User

Wings3d obj to Minetest block converter

a guest
Jul 16th, 2012
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.65 KB | None | 0 0
  1.  
  2. class Block
  3.   def initialize(name, coords)
  4.     @name = name
  5.     @x1, @y1, @z1 = coords[1]
  6.     @x2, @y2, @z2 = coords[0]
  7.   end
  8.  
  9.   def to_s
  10.     "{ #{@x1}, #{@y1}, #{@z1}, #{@x2}, #{@y2}, #{@z2} }, -- #{@name}"
  11.   end
  12. end
  13.  
  14. name = nil
  15. num = 0
  16. coords = []
  17.  
  18. File.open(ARGV[0]).read.each_line do |line|
  19.  
  20.   if name
  21.     if line =~ /^v ([-0-9.]+) ([-0-9.]+) ([-0-9.]+)/
  22.       if num == 2 || num == 4
  23.         coords << [$1, $2, $3]
  24.       end
  25.  
  26.       if num == 4
  27.         puts Block.new(name.strip, coords)
  28.         name = nil
  29.       end
  30.  
  31.       num += 1
  32.     end
  33.   end
  34.  
  35.   if line =~ /^o (.*)/
  36.     name = $1
  37.     num = 0
  38.     coords = []
  39.   end
  40. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement