CapsAdmin

Untitled

Jul 25th, 2012
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.45 KB | None | 0 0
  1. local function GO()
  2.  
  3.     local function decode(str)
  4.         local out = {}
  5.        
  6.         local v = {}
  7.         local vn = {}
  8.         local f = {}
  9.        
  10.         for t, x, y, z in str:gmatch("(%S+)%s-(%S+)%s-(%S+)%s-(%S+)%s-\n") do
  11.             x, y, z = tonumber(x), tonumber(y), tonumber(z)
  12.            
  13.             if t == "v" then
  14.                 table.insert(v, Vector(x,y,z))
  15.             elseif t == "vn" then
  16.                 table.insert(vn, Vector(x,y,z))
  17.             elseif t == "f" then
  18.                 -- !?!?!?!?!?!
  19.                 table.insert(f, Vector(x,y,z))
  20.             end
  21.         end
  22.        
  23.         for i = 1, #v do
  24.             out[i] = {pos = v[i], normal = vn[i]}
  25.         end
  26.        
  27.         return out
  28.     end
  29.  
  30.     local mesh = NewMesh()
  31.  
  32.     local data = decode(file.Read("skull_obj.txt"))
  33.  
  34.     mesh:BuildFromTriangles(data)
  35.  
  36.     local material = Material("models/wireframe")
  37.  
  38.     SafeRemoveEntity(_G.render_node)
  39.  
  40.     local node = ClientsideModel("error.mdl")
  41.  
  42.     node:SetPos(LocalPlayer():EyePos() + LocalPlayer():GetAimVector() * 200)
  43.  
  44.     function node:RenderOverride()
  45.         local matrix = Matrix()
  46.        
  47.         matrix:SetAngle(self:GetAngles())
  48.         matrix:SetTranslation(self:GetPos())
  49.         matrix:Scale(self:GetModelScale())
  50.        
  51.         render.SetMaterial(material)
  52.            
  53.         cam.PushModelMatrix(matrix)
  54.            
  55.             mesh:Draw()
  56.            
  57.         cam.PopModelMatrix()
  58.     end
  59.  
  60.     _G.render_node = node
  61.  
  62. end
  63.  
  64. if not file.Exists("skull_obj.txt") then
  65.     print("downloading skull lol3%50!!!!!")
  66.     http.Get("http://web.eecs.umich.edu/~guskov/eecs598-1/skull.obj", "", function(c)
  67.         -- lol3%50
  68.         file.Write("skull_obj.txt")
  69.        
  70.         GO()
  71.     end)
  72. else
  73.     GO()
  74. end
Advertisement
Add Comment
Please, Sign In to add comment