Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- +--------------------------------------------------------+
- -- | |
- -- | 3dmChar |
- -- | |
- -- +--------------------------------------------------------+
- local version = "Version 1.0.0"
- -- By Jeffrey Alexander, aka Bomb Bloke.
- -- Makes OpenComputers 3D print objects out of character skins.
- -- http://www.computercraft.info/forums2/index.php?/topic/29653-opencomputers-print3d/
- ---------------------------------------------
- ------------ Load APIs ------------
- ---------------------------------------------
- local function loadAPI(API, paste)
- if not _G[API] then
- if not (fs.exists(API) or fs.exists(shell.resolve(API))) then
- shell.run("pastebin get " .. paste .. " " .. API)
- os.loadAPI(shell.resolve(API))
- else os.loadAPI(fs.exists(API) and API or shell.resolve(API)) end
- end
- end
- loadAPI("print3d", "Lr9UyrkR")
- loadAPI("bbpack", "cUYTGbpb")
- loadAPI("GIF", "5uk9uRjC")
- if not fs.exists(shell.resolve("worldTextures.pal")) then shell.run("pastebin get 5aeuGe6Q worldTextures.pal") end
- ---------------------------------------------
- ------------ Texture Offsets ------------
- ---------------------------------------------
- local head = {
- -- start, xDir, yDir, offset1,dimensions
- {{ 4,32,12}, { 1, 0, 0}, { 0, -1, 0}, 8, 8, 8, 8, 40, 8}, -- Head front
- {{ 4,32, 4}, { 0, 0, 1}, { 0, -1, 0}, 0, 8, 8, 8, 32, 8}, -- Head right
- {{12,32,12}, { 0, 0, -1}, { 0, -1, 0}, 16, 8, 8, 8, 48, 8}, -- Head left
- {{12,32, 4}, {-1, 0, 0}, { 0, -1, 0}, 24, 8, 8, 8, 56, 8}, -- Head back
- {{ 4,32, 4}, { 1, 0, 0}, { 0, 0, 1}, 8, 0, 8, 8, 40, 0}, -- Head top
- {{12,24, 4}, {-1, 0, 0}, { 0, 0, 1}, 16, 0, 8, 2, 48, 0}, -- Head bottom(1)
- {{12,24,10}, {-1, 0, 0}, { 0, 0, 1}, 16, 6, 8, 2, 48, 6}, -- Head bottom(2)
- }
- local v1 = {
- {{ 4,24,10}, { 1, 0, 0}, { 0, -1, 0}, 20, 20, 8, 12}, -- Body front
- {{ 4,24, 6}, { 1, 0, 0}, { 0, -1, 0}, 32, 20, 8, 12}, -- Body back
- {{ 0,24,10}, { 1, 0, 0}, { 0, -1, 0}, 44, 20, 4, 12}, -- Right arm front
- {{16,24,10}, {-1, 0, 0}, { 0, -1, 0}, 44, 20, 4, 12}, -- Left arm front
- {{ 0,24, 6}, { 0, 0, 1}, { 0, -1, 0}, 40, 20, 4, 12}, -- Right arm side
- {{16,24, 6}, { 0, 0, 1}, { 0, -1, 0}, 40, 20, 4, 12}, -- Left arm side
- {{ 4,24, 6}, {-1, 0, 0}, { 0, -1, 0}, 52, 20, 4, 12}, -- Right arm back
- {{12,24, 6}, { 1, 0, 0}, { 0, -1, 0}, 52, 20, 4, 12}, -- Left arm back
- {{ 0,24, 6}, { 1, 0, 0}, { 0, 0, 1}, 44, 16, 4, 4}, -- Right arm top
- {{16,24, 6}, {-1, 0, 0}, { 0, 0, 1}, 44, 16, 4, 4}, -- Left arm top
- {{ 0,12, 6}, { 1, 0, 0}, { 0, 0, 1}, 48, 16, 4, 4}, -- Right arm bottom
- {{16,12, 6}, {-1, 0, 0}, { 0, 0, 1}, 48, 16, 4, 4}, -- Left arm bottom
- {{ 4,12,10}, { 1, 0, 0}, { 0, -1, 0}, 4, 20, 4, 12}, -- Right leg front
- {{12,12,10}, {-1, 0, 0}, { 0, -1, 0}, 4, 20, 4, 12}, -- Left leg front
- {{ 4,12, 6}, { 0, 0, 1}, { 0, -1, 0}, 0, 20, 4, 12}, -- Right leg side
- {{12,12, 6}, { 0, 0, 1}, { 0, -1, 0}, 0, 20, 4, 12}, -- Left leg side
- {{ 8,12, 6}, {-1, 0, 0}, { 0, -1, 0}, 12, 20, 4, 12}, -- Right leg back
- {{ 8,12, 6}, { 1, 0, 0}, { 0, -1, 0}, 12, 20, 4, 12}, -- Left leg back
- {{ 4, 0, 6}, { 1, 0, 0}, { 0, 0, 1}, 8, 16, 4, 4}, -- Right leg bottom
- {{12, 0, 6}, {-1, 0, 0}, { 0, 0, 1}, 8, 16, 4, 4}, -- Left leg bottom
- }
- local v2 = {
- {{ 4,24,10}, { 1, 0, 0}, { 0, -1, 0}, 20, 20, 8, 12, 20, 36}, -- Body front
- {{ 4,24, 6}, { 1, 0, 0}, { 0, -1, 0}, 32, 20, 8, 12, 32, 36}, -- Body back
- {{ 0,24,10}, { 1, 0, 0}, { 0, -1, 0}, 44, 20, 4, 12, 44, 36}, -- Right arm front
- {{ 0,24, 6}, { 0, 0, 1}, { 0, -1, 0}, 40, 20, 4, 12, 40, 36}, -- Right arm side
- {{ 4,24, 6}, {-1, 0, 0}, { 0, -1, 0}, 52, 20, 4, 12, 52, 36}, -- Right arm back
- {{ 0,24, 6}, { 1, 0, 0}, { 0, 0, 1}, 44, 16, 4, 4, 44, 32}, -- Right arm top
- {{ 0,12, 6}, { 1, 0, 0}, { 0, 0, 1}, 48, 16, 4, 4, 48, 32}, -- Right arm bottom
- {{ 4,12,10}, { 1, 0, 0}, { 0, -1, 0}, 4, 20, 4, 12, 4, 36}, -- Right leg front
- {{ 4,12, 6}, { 0, 0, 1}, { 0, -1, 0}, 0, 20, 4, 12, 0, 36}, -- Right leg side
- {{ 8,12, 6}, {-1, 0, 0}, { 0, -1, 0}, 12, 20, 4, 12, 12, 36}, -- Right leg back
- {{ 4, 0, 6}, { 1, 0, 0}, { 0, 0, 1}, 8, 16, 4, 4, 8, 32}, -- Right leg bottom
- {{12,24,10}, { 1, 0, 0}, { 0, -1, 0}, 36, 52, 4, 12, 52, 52}, -- Left arm front
- {{16,24,10}, { 0, 0, -1}, { 0, -1, 0}, 40, 52, 4, 12, 56, 52}, -- Left arm side
- {{16,24, 6}, {-1, 0, 0}, { 0, -1, 0}, 44, 52, 4, 12, 60, 52}, -- Left arm back
- {{12,24, 6}, { 1, 0, 0}, { 0, 0, 1}, 36, 48, 4, 4, 52, 48}, -- Left arm top
- {{12,12, 6}, { 1, 0, 0}, { 0, 0, 1}, 40, 48, 4, 4, 56, 48}, -- Left arm bottom
- {{ 8,12,10}, { 1, 0, 0}, { 0, -1, 0}, 20, 52, 4, 12, 4, 52}, -- Left leg front
- {{12,12,10}, { 0, 0, -1}, { 0, -1, 0}, 24, 52, 4, 12, 8, 52}, -- Left leg side
- {{12,12, 6}, {-1, 0, 0}, { 0, -1, 0}, 28, 52, 4, 12, 12, 52}, -- Left leg back
- {{ 8, 0, 6}, { 1, 0, 0}, { 0, 0, 1}, 24, 48, 4, 4, 8, 48}, -- Left leg bottom
- }
- ---------------------------------------------
- ------------ Load Skin ------------
- ---------------------------------------------
- local filename = ...
- if not filename then
- print("Usage: 3dmChar <skinGIFfile>")
- return
- end
- if filename:lower():sub(-4) ~= ".gif" and not fs.exists(filename) then filename = filename .. ".gif" end
- if not fs.exists(filename) then error("Failed opening file: file not found", 0) end
- local GIFImage = GIF.loadGIF(filename, shell.resolve("worldTextures.pal"))
- if filename:lower():sub(-4) == ".gif" then filename = filename:sub(1, -5) end
- local image = {}
- for y = 1, GIFImage.height do
- image[y] = {}
- for x = 1, GIFImage.width do image[y][x] = 0 end
- end
- local pal = {}
- for i = 1, #GIFImage.pal do pal[i] = GIFImage.pal[i][4] end
- pal[0] = "concrete_purple"
- GIFImage = GIFImage[1]
- for y = 1, GIFImage.yend do
- local x, GIFImageY, imageY = GIFImage.xstart + 1, GIFImage[y], image[y + GIFImage.ystart]
- for i = 1, #GIFImageY do
- local GIFImageYI = GIFImageY[i]
- if type(GIFImageYI) == "number" then
- x = x + GIFImageYI
- else
- for pixel = 1, #GIFImageYI do imageY[x + pixel - 1] = GIFImageYI[pixel] end
- x = x + #GIFImageYI
- end
- end
- end
- GIFImage = nil
- ---------------------------------------------
- ------------ Paint Model ------------
- ---------------------------------------------
- local obj = print3d.initModel(filename, 16, 32, 16)
- local function plotPlanes(planes)
- for i = 1, #planes do
- local plane = planes[i]
- local draw = obj.get2DPlane(plane[1], plane[2], plane[3])
- for y = 1, plane[7] do for x = 1, plane[6] do
- local px = image[y+plane[5]][x+plane[4]]
- if #plane > 7 then
- local px2 = image[y+plane[9]][x+plane[8]]
- if px2 > 0 then px = px2 end
- end
- draw(x, y, pal[px])
- end end
- end
- end
- plotPlanes(head)
- plotPlanes(#image > 32 and v2 or v1)
- -- Divider
- local draw = obj.get2DPlane({0, 16, 0}, { 1, 0, 0}, { 0, 0, 1})
- for y = 7, 10 do for x = 1, 16 do draw(x, y, "concrete_gray") end end
- ---------------------------------------------
- ------------ Create Output ------------
- ---------------------------------------------
- local outFile = fs.open(filename .. ".txt", "w")
- obj = obj.parse()
- for i = 1, #obj do
- local cmd = "give @p opencomputers:print 1 0 " .. obj[i]
- outFile.writeLine(cmd .. "\n")
- commands.exec(cmd)
- end
- outFile.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement