VOXELGENERATOR: added new lua example script for using noise
parent
e47be87b97
commit
91b7da0c29
|
@ -5,6 +5,7 @@ set(LUA_SRCS
|
|||
scripts/modules/volume.lua
|
||||
scripts/cover.lua
|
||||
scripts/delete-rgb.lua
|
||||
scripts/erode.lua
|
||||
scripts/grass.lua
|
||||
scripts/grid.lua
|
||||
scripts/noise.lua
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
local vol = require "modules.volume"
|
||||
|
||||
function arguments()
|
||||
return {
|
||||
{ name = 'emptycnt', desc = 'The amount of empty voxels surrounding the voxel to erode.', type = 'int', default = '12', min = '1', max = '25' },
|
||||
{ name = 'octaves', type = 'int', default = '4', min = '1', max = '10' },
|
||||
{ name = 'lacunarity', desc = 'Scales the frequency', type = 'float', default = '1.0', min = '-3', max = '3' },
|
||||
{ name = 'gain', desc = 'Scales the amplitude', type = 'float', default = '0.5', min = '-3', max = '3' },
|
||||
{ name = 'threshold', desc = 'Noise threshold', type = 'float', default = '0.3', min = '-1', max = '1' }
|
||||
}
|
||||
end
|
||||
|
||||
function main(node, region, color, emptycnt, octaves, lacunarity, gain, threshold)
|
||||
local volume = node:volume()
|
||||
|
||||
local visitor = function (volume, x, y, z)
|
||||
local adjacent = vol.countEmptyAround(volume, x, y, z)
|
||||
if (adjacent >= emptycnt) then
|
||||
local size = region:size()
|
||||
local p = vec3.new(x / size.x, y / size.y, z / size.z)
|
||||
local r = noise.fBm3(p, octaves, lacunarity, gain)
|
||||
if r >= threshold then
|
||||
volume:setVoxel(x, y, z, -1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local condition = function (volume, x, y, z)
|
||||
local voxel = volume:voxel(x, y, z)
|
||||
if voxel == color then
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
vol.conditionYXZ(volume, region, visitor, condition)
|
||||
end
|
Loading…
Reference in New Issue