kremnev8

3D model creator

Jul 17th, 2015
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.32 KB | None | 0 0
  1. c=        require("component")
  2. computer= require("computer")
  3. event=    require("event")
  4. os=       require("os")
  5. term =    require("term")
  6. gpu=      c.gpu
  7. h=        c.hologram
  8. printer=  c.printer3d;printer.reset()
  9. screenWidth,screenHeight=gpu.getResolution()
  10. screenToggled=false
  11. curx,cury,curz=1,1,1
  12. curstate=0
  13. figStartX,figStartY,figStartZ=0,0,0
  14. texture="command_block"
  15.  
  16. h.clear()
  17. function intro()
  18.   print("move cursor by arrow keys, w s layer up/down")
  19.   print("space- start drawing model. second time for end.")
  20.   print("t to enter name of texture.")
  21.   print("q exit. c clear screen. p print")
  22. end
  23.  
  24. function swap(incrx,incry,incrz)
  25.   h.set(curx,cury,curz,curstate)
  26.   curx,cury,curz=curx+incrx,cury+incry,curz+incrz
  27.   --printvars()
  28.   if figStartX~=0 then
  29.     local fillStartX,fillStartY,fillStartZ=figStartX,figStartY,figStartZ
  30.     local fillEndX,fillEndY,fillEndZ=curx,cury,curz
  31. --print("fillSX="..fillStartX.." fsY"..fillStartY.."fsZ"..fillStartZ)
  32. --print("fillEX="..fillEndX.." feY"..fillEndY.."feZ"..fillEndZ)
  33.  
  34.     if figStartX>curx then fillStartX=curx;fillEndX=figStartX end
  35.     if figStartY>cury then fillStartY=cury;fillEndY=figStartY end
  36.     if figStartZ>curz then fillStartZ=curz;fillEndZ=figStartZ end
  37.  
  38.     for i=fillStartX,fillEndX do
  39.       for j=fillStartZ,fillEndZ do
  40.         for k=fillStartY,fillEndY do
  41.           h.set(i,k,j,2)
  42.         end
  43.       end
  44.     end
  45.   end
  46.   curstate=h.get(curx,cury,curz)
  47.   h.set(curx,cury,curz,1)
  48. end
  49.  
  50. function moveForward()
  51.   if curx<16 then
  52.    swap(1,0,0)
  53.   else computer.beep(1500,0.1) end
  54. end
  55. function moveBack()
  56.   if curx>1 then
  57.     swap(-1,0,0)
  58.   else computer.beep(1500,0.1) end
  59. end
  60. function moveLeft()
  61.   if curz>1 then
  62.     swap(0,0,-1)
  63.   else computer.beep(1500,0.1) end
  64. end
  65. function moveRight()
  66.   if curz<16 then
  67.     swap(0,0,1)
  68.   else computer.beep(1500,0.1) end
  69. end
  70. function layerUp()
  71.   if cury<16 then
  72.     swap(0,1,0)
  73.   else computer.beep(1500,0.1) end
  74. end
  75. function layerDown()
  76.   if cury>1 then
  77.     swap(0,-1,0)
  78.   else computer.beep(1500,0.1) end
  79. end
  80. function mark()
  81.   if figStartX==0 then
  82.    figStartX,figStartY,figStartZ=curx,cury,curz
  83.    swap(0,0,0)
  84.    os.sleep(1)
  85.   else
  86.     local fillStartX,fillStartY,fillStartZ=figStartX,figStartY,figStartZ
  87.     local fillEndX,fillEndY,fillEndZ=curx,cury,curz
  88.     if figStartX>curx then fillStartX=curx;fillEndX=figStartX end
  89.     if figStartY>cury then fillStartY=cury;fillEndY=figStartY end
  90.     if figStartZ>curz then fillStartZ=curz;fillEndZ=figStartZ end
  91.     local result, reason = printer.addShape(fillStartX-1, fillStartY-1, fillStartZ-1, fillEndX, fillEndY, fillEndZ, texture)
  92.     if not result then
  93.       print("Failed adding shape: " .. tostring(reason))
  94.     end
  95.    figStartX,figStartY,figStartZ=0,0,0
  96.    curx,cury,curz=1,1,1
  97. --   swap(0,0,0)
  98.    os.sleep(1)
  99.   end
  100.  
  101. end
  102.  
  103. function printme()
  104.   printer.setLabel("KelLiN block")
  105.   printer.setTooltip("Printed with KelLiN software")
  106.   local result, reason = printer.commit(1)
  107.   if result then
  108.     print("Job successfully committed!")
  109.   else
  110.     print("Failed committing job: " .. tostring(reason))
  111.     gpu.setResolution(screenWidth,screenHeight)
  112.     h.clear()
  113.     os.exit()
  114.   end
  115. end
  116.  
  117. function toggleScreen()
  118.   if screenToggled then
  119.    gpu.setResolution(screenWidth,screenHeight)
  120.    screenToggled=false
  121.    intro()
  122.   else
  123.    gpu.setResolution(1,1)
  124.    screenToggled=true
  125.   end
  126.  
  127. end
  128. function printvars()
  129. print("---------------------")
  130.   print("curx="..curx..";  cury="..cury.."curz="..curz)
  131.   print("figStartX"..figStartX.."  figStartY"..figStartY.."   figStartZ"..figStartZ)
  132.  
  133.  
  134. end
  135. --test keys
  136. --os.sleep(1);print(event.pull("key_down"))
  137. intro()
  138. swap(0,0,0)
  139. while true do
  140.   _,_,key1,key2=event.pull("key_down")
  141.   if key2==19 then      term.clear();toggleScreen();--r
  142.   elseif key2==20 then      print("input texture name")texture=io.read();--t
  143.   elseif key2==46 then  term.clear();intro();--c
  144.   elseif key2==16 then  term.clear();h.clear();os.exit();--q
  145.   elseif key2==200 then moveForward();--up arrow
  146.   elseif key2==208 then moveBack();--down arrow
  147.   elseif key2==203 then moveLeft();--left arrow
  148.   elseif key2==205 then moveRight();--right arrow
  149.   elseif key2==17 then layerUp();--w
  150.   elseif key2==31 then layerDown();--s
  151.   elseif key2==57 then mark();--space
  152.   elseif key2==25 then printme();intro();--p
  153.   end
  154. end
Advertisement
Add Comment
Please, Sign In to add comment