Advertisement
rollton

Просмотр на голограмме моделей для печати

Oct 25th, 2017
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.34 KB | None | 0 0
  1. local component = require("component")
  2. local args = require("shell").parse(...)
  3.  
  4. local hologram = component.hologram
  5.  
  6. local colorPoint={}
  7.  
  8. function parallelepipedPrint(x1,y1,z1,x2,y2,z2,col)
  9.     for x = x1+1, x2 do
  10.         for y = y1+1, y2 do
  11.             for z = z1+1, z2 do
  12.                 hologram.set(z+16,y+16,x+16,col and col or math.random(1,3))
  13.             end
  14.         end
  15.     end
  16. end
  17.  
  18. function printModelToHologram(file,block)
  19.  
  20.     local file,reason = io.open(file)
  21.     if not file then io.stderr:write("Failed opening file: " .. reason .. "\n") os.exit(0) end
  22.     file,reason = load("return {"..file:read("*all").."}")
  23.     if not file then io.stderr:write("Failed loading model: " .. reason .. "\n") os.exit(1) end
  24.     file = file()[block]
  25.  
  26.     if file then
  27.         print("Print to hologram: "..file.label)
  28.         for j,v in pairs(file.shapes) do
  29.             local color
  30.             for i = 1, 3 do
  31.                 if colorPoint[i] == v.tint then
  32.                     color = i
  33.                     break
  34.                 else
  35.                     if not colorPoint[i] then
  36.                         hologram.setPaletteColor(i, v.tint)
  37.                         colorPoint[i] = v.tint
  38.                         color = i
  39.                         break
  40.                     end
  41.                 end
  42.             end
  43.             parallelepipedPrint(v[1],v[2],v[3],v[4],v[5],v[6],color)
  44.         end
  45.     else
  46.         io.stderr:write("Block Not found \n") os.exit(2)
  47.     end
  48. end
  49.  
  50. hologram.clear()
  51.  
  52. if args[1] then
  53.     printModelToHologram(args[1],tonumber(args[2]) or 1)
  54. else
  55.     print("Usage: holo <fileModel> <numberBlock>")
  56. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement