Advertisement
Guest User

print3d-holo.lua

a guest
Feb 27th, 2016
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.56 KB | None | 0 0
  1. local component = require("component")
  2. local shell = require("shell")
  3. local model = require("model")
  4.  
  5. local args = shell.parse(...)
  6. if #args ~= 1 then
  7.   io.write("Usage: print3d-holo FILE\n")
  8.   os.exit(0)
  9. end
  10.  
  11. local data, reason = model.Model.load(args[1])
  12. if not data then
  13.   io.stderr:write("Failed loading model: " .. reason .. "\n")
  14.   os.exit(1)
  15. end
  16.  
  17. if data.label then
  18.   print("Label: " .. data.label)
  19. end
  20. if data.tooltip then
  21.   print("Tooltip: " .. data.tooltip)
  22. end
  23. if data.lightLevel then -- as of OC 1.5.7
  24.   print("Light Level: " .. data.lightLevel)
  25. end
  26. if data.emitRedstone then
  27.   print("Redstone: " .. tostring(data.emitRedstone))
  28. end
  29. if data.buttonMode then
  30.   print("Button mode: " .. tostring(data.buttonMode))
  31. end
  32. if data.collidable then
  33.   print("Collidable (inactive): " .. tostring(not not data.collidable[1]))
  34.   print("Collidable (active): " .. tostring(not not data.collidable[2]))
  35. end
  36.  
  37.  
  38. -- Preload texture mapping
  39. local txtdb = model.Textures.load()
  40.  
  41. -- Compute a pallette
  42. local palette = {}
  43. local cpi = 1
  44. for voxel in data:voxels_rgb(txtdb) do
  45.   if not palette[voxel.rgb] then
  46.     palette[voxel.rgb] = cpi
  47.     component.hologram.setPaletteColor(cpi, voxel.rgb)
  48.     cpi = cpi + 1
  49.   end
  50. end
  51.  
  52. if #palette > 3 then
  53.   io.stderr:write("Warning: More than 3 colors.\n")
  54. end
  55.  
  56. component.hologram.clear()
  57. -- 3D Printer is low inclusive, high exclusive, 0-16 (fenced)
  58. -- Hologram is both inclusive, 1-16 (indexed)
  59. for voxel in data:voxels_rgb(txtdb) do
  60.   if not voxel.state then
  61.     local c = palette[voxel.rgb]
  62.     component.hologram.set(voxel[1]+16, voxel[2]+8, voxel[3]+16, c)
  63.   end
  64. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement