shapeFile = GetString("Shape","rockshape01.png", "script png") -- Channels: r = General shape of rockface, g = displacement texture to create details, b - colorvalues for the voxels, only greyscale. See examplefile rock.png in script folder depth = GetInt("Depth", 32) displace = GetFloat("Displacement", 4) displaceOffset = GetInt("Offset", 0) alphaInfluence = GetFloat("AlphaInfluence", 0.5) function init() local rockMaterials = {} -- Declare materials local c = 0 while c < 16 do rockMaterials[c] = CreateMaterial("rock", c * 0.0625,c * 0.0625,c * 0.0625) c = c + 1 end -- Load and put image data in arrays -- This is a leftover from when I thought I could load several images, one for shape, displace and color respectively. I'm aware I could use rgb values directly from image instead. if shapeFile ~= nil then LoadImage(shapeFile) local shapeWidth,shapeHeight = GetImageSize() -- create rock from imagedata if shapeWidth > 0 then local x = 0 local y = 0 Vox(0,0,0) while y < shapeHeight do while x < shapeWidth do local r,g,b,a = GetImagePixel(x,y) if(a > 0) then a = mathClamp(a,alphaInfluence,1.0) Material(math.floor(b/0.0625)) Box(x, shapeHeight-y, 0 , x+1, shapeHeight-y+1, 0+math.floor( math.max(((r*depth) + displaceOffset + g*displace)*a,0))) end x = x + 1 end y = y + 1 x = 0 end end end end function mathClamp(val, lower, upper) assert(val and lower and upper, "not very useful error message here") if lower > upper then lower, upper = upper, lower end -- swap if boundaries supplied the wrong way return math.max(lower, math.min(upper, val)) end