Josh Posted Tuesday at 12:16 AM Posted Tuesday at 12:16 AM This script will convert a 4x3 cube cross to a single DDS file, Just paste this in the editor console. local file = RequestFile("Open File") if file == "" then return end local pixmap = LoadPixmap(file) if pixmap == nil then return end local w = pixmap.size.x / 4 if pixmap.size.y ~= w * 3 then Print("Error: Image must have a 4:3 aspect ratio") return end local mipmaps = {} --[[ Right face ]] face = CreatePixmap(w, w, pixmap.format) pixmap:CopyRect(w * 2, w, w, w, face, 0, 0) table.insert(mipmaps, face) --[[ Left face ]] face = CreatePixmap(w, w, pixmap.format) pixmap:CopyRect(0, w, w, w, face, 0, 0) table.insert(mipmaps, face) --[[ Top face ]] local face = CreatePixmap(w, w, pixmap.format) pixmap:CopyRect(w, 0, w, w, face, 0, 0) table.insert(mipmaps, face) --[[ Bottom face ]] face = CreatePixmap(w, w, pixmap.format) pixmap:CopyRect(w, w * 2, w, w, face, 0, 0) table.insert(mipmaps, face) --[[ Front face ]] face = CreatePixmap(w, w, pixmap.format) pixmap:CopyRect(w, w, w, w, face, 0, 0) table.insert(mipmaps, face) --[[ Back face ]] face = CreatePixmap(w, w, pixmap.format) pixmap:CopyRect(w * 3, w, w, w, face, 0, 0) table.insert(mipmaps, face) SaveTexture("skybox.dds", TEXTURE_CUBE, mipmaps, 6) 2 Quote Let's build cool stuff and have fun.
Josh Posted Thursday at 03:58 PM Author Posted Thursday at 03:58 PM The code above does not account for face rotation / flipping. I was just using it on a star background. Quote Let's build cool stuff and have fun.
Josh Posted Thursday at 04:50 PM Author Posted Thursday at 04:50 PM Here is working tested code, with face rotation, for a vertical cube cross: local file = RequestFile("Open File") if file == "" then return end local pixmap = LoadPixmap(file) if pixmap == nil then return end local w = pixmap.size.x / 3 if pixmap.size.y ~= w * 4 then Print("Error: Image must have a 3:4 aspect ratio") return end local mipmaps = {} function RotationPixmap90(pixmap) local r = CreatePixmap(pixmap.size.x, pixmap.size.y, pixmap.format) local x, y, rgba for x = 0, pixmap.size.x - 1 do for y = 0, pixmap.size.y - 1 do rgba = pixmap:Sample(iVec2(x, y)) r:WritePixel(y, pixmap.size.x - 1 - x, rgba) end end return r end --[[ Right face ]] local face = CreatePixmap(w, w, pixmap.format) pixmap:CopyRect(w * 2, w, w, w, face, 0, 0) face = RotationPixmap90(face) face = RotationPixmap90(face) face = RotationPixmap90(face) table.insert(mipmaps, face) --[[ Left face ]] face = CreatePixmap(w, w, pixmap.format) pixmap:CopyRect(0, w, w, w, face, 0, 0) face = RotationPixmap90(face) table.insert(mipmaps, face) --[[ Top face ]] face = CreatePixmap(w, w, pixmap.format) pixmap:CopyRect(w, w * 1, w, w, face, 0, 0) table.insert(mipmaps, face) --[[ Bottm face ]] face = CreatePixmap(w, w, pixmap.format) pixmap:CopyRect(w, w * 3, w, w, face, 0, 0) table.insert(mipmaps, face) --[[ Front face ]] face = CreatePixmap(w, w, pixmap.format) pixmap:CopyRect(w, w * 2, w, w, face, 0, 0) table.insert(mipmaps, face) --[[ Back face ]] face = CreatePixmap(w, w, pixmap.format) pixmap:CopyRect(w, 0, w, w, face, 0, 0) face = RotationPixmap90(face) face = RotationPixmap90(face) table.insert(mipmaps, face) SaveTexture("skybox.dds", TEXTURE_CUBE, mipmaps, 6) 1 Quote Let's build cool stuff and have fun.
Josh Posted Friday at 01:42 AM Author Posted Friday at 01:42 AM If you want to scale the brightness at the same time, this is the way: local COLORSCALE = 1.5 local file = RequestFile("Open File") if file == "" then return end local pixmap = LoadPixmap(file) if pixmap == nil then return end local w = pixmap.size.x / 3 if pixmap.size.y ~= w * 4 then Print("Error: Image must have a 3:4 aspect ratio") return end local mipmaps = {} function ScaleColor(pixmap, scale) if scale == 1.0 then return end local x, y, c for x = 0, pixmap.size.x - 1 do for y = 0, pixmap.size.y - 1 do c = pixmap:Sample(iVec2(x, y)) pixmap:WritePixel(x, y, c * scale) end end end function RotationPixmap90(pixmap) local r = CreatePixmap(pixmap.size.x, pixmap.size.y, pixmap.format) local x, y, rgba for x = 0, pixmap.size.x - 1 do for y = 0, pixmap.size.y - 1 do rgba = pixmap:Sample(iVec2(x, y)) r:WritePixel(y, pixmap.size.x - 1 - x, rgba) end end return r end --[[ Right face ]] local face = CreatePixmap(w, w, pixmap.format) pixmap:CopyRect(w * 2, w, w, w, face, 0, 0) face = RotationPixmap90(face) face = RotationPixmap90(face) face = RotationPixmap90(face) table.insert(mipmaps, face) --[[ Left face ]] face = CreatePixmap(w, w, pixmap.format) pixmap:CopyRect(0, w, w, w, face, 0, 0) face = RotationPixmap90(face) table.insert(mipmaps, face) --[[ Top face ]] face = CreatePixmap(w, w, pixmap.format) pixmap:CopyRect(w, w * 1, w, w, face, 0, 0) table.insert(mipmaps, face) --[[ Bottm face ]] face = CreatePixmap(w, w, pixmap.format) pixmap:CopyRect(w, w * 3, w, w, face, 0, 0) table.insert(mipmaps, face) --[[ Front face ]] face = CreatePixmap(w, w, pixmap.format) pixmap:CopyRect(w, w * 2, w, w, face, 0, 0) table.insert(mipmaps, face) --[[ Back face ]] face = CreatePixmap(w, w, pixmap.format) pixmap:CopyRect(w, 0, w, w, face, 0, 0) face = RotationPixmap90(face) face = RotationPixmap90(face) table.insert(mipmaps, face) local n for n = 1, #mipmaps do ScaleColor(mipmaps[n], COLORSCALE) end SaveTexture("skybox.dds", TEXTURE_CUBE, mipmaps, 6) Quote Let's build cool stuff and have fun.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.