Advertisement
CloneTrooper1019

Untitled

Dec 9th, 2014
480
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.13 KB | None | 0 0
  1. function ridiculousJSONAsync(url,tag,decodeAgain)
  2.     local t = h:JSONDecode(h:GetAsync(url))
  3.     local async = h:GetAsync(t[tag])
  4.     return (decodeAgain and h:JSONDecode(async) or async)
  5. end
  6.  
  7. function parseOBJ(objFile)
  8.     -- Parses an OBJ File into a data array.
  9.     local obj = {
  10.         Verts = {};
  11.         Norms = {};
  12.         Texs = {};
  13.         Faces = {};
  14.     }
  15.     local currentMtl = "";
  16.     for line in objFile:gmatch("[^\r\n]+") do
  17.         if #line > 0 then
  18.             local info = {}
  19.             local tagCount = {};
  20.             local tag = ""
  21.             local process = ""
  22.             for char in line:gmatch(".") do
  23.                 if char == " " then
  24.                     if tag == "" then
  25.                         tag = process
  26.                     else
  27.                         table.insert(chunks,tonumber(process) or process)
  28.                     end
  29.                     process = ""
  30.                 else
  31.                     process = process .. char
  32.                 end
  33.             end
  34.             if tag ~= "#" then
  35.                 if tag == "g" then
  36.                     currentMtl = info[1]
  37.                 elseif tag == "v" then
  38.                     local Vert = {
  39.                         Mtl = currentMtl;
  40.                         Coords = Vector3.new(unpack(info));
  41.                     };
  42.                     table.insert(obj.Verts,Vert)
  43.                 elseif tag == "vn" then
  44.                     local Norm = Vector3.new(unpack(info));
  45.                     table.insert(obj.Norms,Norm)
  46.                 elseif tag == "vt" then
  47.                     local texCoord = Vector2.new(unpack(info))
  48.                     table.insert(obj.Texs,texCoord)
  49.                 elseif tag == "f" then
  50.                     local triangle = {}
  51.                     local v,t,n
  52.                     for _,pair in pairs(info) do
  53.                         local index = {}
  54.                         if type(pair) == "number" then
  55.                             v = pair
  56.                         elseif string.find(pair,"//") then
  57.                             v,n = string.match(pair,"(%S+)//(%S+)")
  58.                         else
  59.                             v,t,n = string.match(pair,"(%S+)/(%S+)/(%S+)")
  60.                             if not v or not t or not n then
  61.                                 v,t = string.match(pair,"(%S+)/(%S+)")
  62.                             end
  63.                         end
  64.                     end
  65.                     triangle.Vertex = tonumber(v)
  66.                     triangle.Texture = tonumber(t)
  67.                     triangle.Normal = tonumber(n)              
  68.                     table.insert(obj.Faces,triangle)
  69.                 end
  70.             end
  71.         end
  72.     end
  73.     return obj
  74. end
  75.  
  76. function WriteSMD(assetId)
  77.     local data = ridiculousJSONAsync("http://rproxy.tk/asset-thumbnail-3d/json?assetId=" .. assetId,"Url",true)
  78.     local objFile = ridiculousJSONAsync("http://rproxy.tk/thumbnail/resolvehash/" .. data.obj,"Url")
  79.     local obj = parseOBJ(objFile)
  80.    
  81. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement