local function seperate(part:BasePart)
local halfX = part.Size.X/2
local halfY = part.Size.Y/2
local halfZ = part.Size.Z/2
local smallSize = Vector3.new(halfX,halfY,halfZ)
local cornerPosition = part.Position - smallSize
for i = 0,7 do
local smallPart = part:Clone()
smallPart.Parent = part.Parent
smallPart.Size = smallSize
local xUnits = 0
if i >= 4 then
i-= 4
xUnits = 1
end
local yUnits = 0
if i >= 2 then
i -= 2
yUnits = 1
end
local zUnits = 0
if i >= 1 then
zUnits = 1
end
local basePosition = cornerPosition + Vector3.new(xUnits * halfX,yUnits * halfY,zUnits * halfZ)
smallPart.Position = basePosition + Vector3.new(halfX/2,halfY/2,halfZ/2)
end
part:Destroy()
end
local function subdivide(part, levels)
local pointsPerAxis = math.pow(2, levels)
local pSize = part.Size / pointsPerAxis
local corner = part.Position - part.Size/2 + pSize/2
local positions = {}
for i=0, pointsPerAxis do
for j=0, pointsPerAxis do
for k=0, pointsPerAxis do
table.insert(positions, corner + pSize * Vector3.new(i, j, k)
end
end
end
for _, position in ipairs(positions) do --This could be done above, but I wanted to split it out simply for better distinction between parts. I recommend using a parts cache actually if you can because the :Clone() operation is probably slow.
local p = part:Clone()
p.Size = pSize
p.Position = position --This does techincally assume axis alignment. The position list can be easily made to be in object space though so you can trivially fix that
end
part:Destroy() --optional
end