Advertisement
ecco7777

obj reader

Nov 1st, 2020 (edited)
895
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.02 KB | None | 0 0
  1. args={...}
  2.  
  3. function loadFile(filename)
  4.     fp=fs.open(filename,"r")
  5.     lines={}
  6.     i=1
  7.     lines[i]=fp.readLine()
  8.     while lines[i]~=nil do
  9.         i=i+1
  10.         lines[i]=fp.readLine()
  11.     end
  12.     return lines
  13. end
  14.  
  15. function split (inputstr, sep)
  16.         if sep == nil then
  17.                 sep = "%s"
  18.         end
  19.         local t={}
  20.         for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
  21.                 table.insert(t, str)
  22.         end
  23.         return t
  24. end
  25.  
  26. function compileObj(lines)
  27.     v = {}
  28.     vt = {}
  29.     vn = {}
  30.     f = {}
  31.     l = {}
  32.     print(#lines)
  33.     for i=5, #lines do
  34.         if string.sub(lines[i],1,2)=="v " then
  35.             table.insert(v,split(lines[i]))
  36.         end
  37.         if string.sub(lines[i],1,2)=="vt" then
  38.             table.insert(vt,split(lines[i]))
  39.         end
  40.         if string.sub(lines[i],1,2)=="vn" then
  41.             table.insert(vn,split(lines[i]))
  42.         end
  43.         if string.sub(lines[i],1,2)=="f " then
  44.             table.insert(f,split(lines[i]))
  45.         end
  46.         if string.sub(lines[i],1,2)=="l " then
  47.             table.insert(l,split(lines[i]))
  48.         end
  49.     end
  50. end
  51.  
  52. compileObj(loadFile(args[1]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement