A voxelizer problem

Hello devforums!
im back again with another problem

so for context i created a voxelizer which basically subdivide parts. here is what it does.

from this part


to this

the voxelizing code is here

but problems arise when the size of the voxel does not add up to the size of the original part, here is the image version of the problem

for context, the y axis of the original part is 22 while the voxel part size is only 4 on each side which results in this:

now what i want to do in this special situation is to add parts on the axis that the voxel could not fill while maintaining the size on other axis which can be filled, here is another image of what i mean


notice that the black part only perfectly fits on the y axis while maintaining other axis the same size as other voxels.

so uh yeah can anyone help me out here? Im just stuck in this problem and its beginning to eat away my patience, thank you

4 Likes

You probably did multiple parts so it can make it “Rainbow or Glitchy”.

So this is why the color was at “163 162 165” and then some random colors.

i dont think you get what i mean, i have the problem when the voxel size are not able to add up to the original parts which results empty spaces, for more details please re-read the post again.

Just deleted all the parts (Or the full model that you currently have) and create another one that doesn’t have 100 parts in total, just 1 part…

ARE NOT ABLE ???
But this is just a recent one…
Bruh.

Oh, ok.

Empty spaces ?

I don’t need to, sorry…

Do you want help ?

I don’t need to = I don’t need to re-read the post.

im not sure if its you or me misunderstanding but that’s not what i wanted though?

im subdividing a cube to a set of sizes that breaks a part to a few parts, but problem arise when that set of sizes are not able to add up to the original 1 part cube, do you get what i mean here?

I guess it’s probably you…

Uhh, no idk what you mean…

alright ill try to explain this as clear as possible

this is the original cube, lets call him Bob

now i have a code that breaks bob to pieces with a set size, lets call those pieces little bobs which results in this

problems arise when the set size for those little bob’s are not able to add up to the original part, Bob which leaves empty spaces like this


this happens when the set size for little bob’s is (4,4,4) while Bob size is (20, 22, 20).

Now what i want to do is to make the code to create a part that will fit in those empty spaces to complete Bob’s size while still being the same as other little bob’s, for example

from the image above we know that all little bob’s size adds up to (20,20,20) while Bob’s size is (20, 22, 20), we just need a part that has the size of (4,2,4) so it can perfectly fits within Bob’s size, here is the image of what im talking about


the black part’s size on the x and z is 4 which is the same as other little bob’s but the size of the y axis is 2 so it fills completely bob’s size

If you didn’t understand what he meant i suggest not replying to the problem with irrelevant things.

Why dont you just divide the part. Like get its size divide it by the number u want then position it.

Instead of using the part size directly, you could round each axis up to the nearest multiple of voxelSize:

local function roundUp(x, n)
  return n*math.ceil(x / n)
end

local size = Vector3.new(
  roundUp(part.Size.X, voxSize),
  roundUp(part.Size.Y, voxSize),
  roundUp(part.Size.Z, voxSize)
)

And then use that size in your loop instead.

You may need to add some padding here and there to avoid rounding errors.

1 Like

this seems promising though one question, on the function

local function roundUp(x, n)
  return n*math.ceil(x / n)
end

what do i put in the “n” argument? since what you used is only the first argument which caused an error for me

Edit: nvm i found out what the “n” argument does and im confident that this can lead me to the results i wanted, thank you mike

1 Like

put your bob’s size in your case its 4