Hello, i am working on a voxel terrain system for my recent project, I have figured out how to generate a chunk with only the parts that are touching air.
–Image–
–code–
function Chuck:GetNeighbors(X, Y, Z)
local function GetNeighbors(x, y, z)
local neighbors = {}
if x > 1 then neighbors["left"] = blocks[x-1][y][z] end
if x < Global.Dimensions.X then neighbors["right"] = blocks[x+1][y][z] end
if y > 1 then neighbors["top"] = blocks[x][y-1][z] end
if y < Global.Dimensions.Y then neighbors["bottom"] = blocks[x][y+1][z] end
if z > 1 then neighbors["Zl"] = blocks[x][y][z-1] end
if z < Global.Dimensions.Z then neighbors["Zr"] = blocks[x][y][z+1] end
return neighbors
end
for x = 1, X do
blocks.hiddenBlocks[x] = {}
for y = 1, Y do
blocks.hiddenBlocks[x][y] = {}
for z = 1, Z do
local Neighbors = GetNeighbors(x, y, z)
if Neighbors.left and Neighbors.right and Neighbors.top and Neighbors.bottom and Neighbors.Zl and Neighbors.Zr then
local hiddenParts = {x, y, z}
blocks.hiddenBlocks[x][y][z] = hiddenParts
else
local createdChunk = CreateBlock(x, y, z)
table.insert(blocks.instances, createdChunk)
end
end
end
end
end
the problem that i have ran into is that i cant think of a way to make the, hidden parts visible again.