Voxel Grouping Algorithm

Greetings! I am working on a building system that groups certain voxels together (finds a box/rectangle shape to combine blocks together to make them one block rather than multiple) if they are right next to each other. So far, I have the building system complete and a flood fill search system that will search though all parts and return parts that are near another, and then it will recursively search the near parts for parts near those parts, if that makes sense.

The issue I’m having right now is I can’t seem to figure out how to do such a grouping algorithm and I’d appreciate it if someone could point me in the right direction, or let me know if there’s some video on it or something. I’ve looked around a bit but I haven’t found much on what I’m trying to do. I was thinking about converting them into 2D tables to more easily find and group blocks around it but I don’t feel like that’s the best solution…

Here is an example of what I’m trying to do (I’ve grouped them by color in this picture)


I’m not trying to group them in this exact way or anything but just in a way that attempts to find the largest possible “chunk area” it can group.
For example, it could have also grouped like this

If you need me to clear anything up, don’t hesitate to ask! Thank you!

2 Likes

I’m not sure what differentiates different blocks, if nothing then how would it know what to group together?

Thanks

Okay, let me have a go at it, In this scenario I’d do at least one of three things:

  • Add BoolValue’s to each part trying to be grouped,
  • Each part being grouped should be under a specific statement,
  • Paired loop following up based on the values assigned.

Now, let me explain what I mean by this. I’d assert my bool values as in the following:

  • Grouped (Incert a grouped value if you want it to check if it’s grouped or not)
  • Alone (Incert a alone value if you want to check if it’s NOT grouped)
  • Active (Incert an active value to check if it can actively combine with anything in the area.)

Each one of these values hold an important message inside the code, since it will forward to system what exactly has to be done based on the values property. Once you’ve asserted those values throughout the corresponding blocks I suggest then adding a “StringValue”

The String Value should include:

  • Value of the block’s number

The String Value would be used when two or more blocks are being combined, so when you formulate a new block you could just update the corresponding String Value to the new block which you have asserted.

Now furthermore Into this topic, In order to properly assets these blocks through your specified folder, you would do:

for i,v in pairs({Folder_Name}:GetDecedents()) do
      -- Connect your statements here, "v" is your blocks.
end

That should be that issue solved, and I thank you for your condulences. If you have any further questions please feel free to reply, or message me (Scriptuyter#8086) or @Scriptuyter

Thank you for your time!

1 Like

Here are a couple of topics on the devforum that you should consider looking at:

1 Like