I would like to create a function that explodes a mesh but am not entirely sure how to approach this.
The first part would mean that I split the mesh into sub-meshes. I have some function already for selecting sub-meshes of a mesh so this isn’t even a problem because I can just work from that.
But once I have X amount of different meshes, I need to “explode” them so that neither mesh intersects with another. There should also be some additional padding around them so that one mesh doesn’t end up right next to another with 0 space inbetween.
I guess moving the meshes can just be done by generating random numbers and use them for the XYZ translation.
But how can I check if the meshes are intersecting or not without making the script so slow it’s unusable? I’m also wondering how to check the distance between two meshes without having to iterate through every single face.
I looked at the PyMEL mesh-class but couldn’t find any function for checking if a mesh intersects another or how to check it’s distance to another mesh.
So ignoring the randomization, my current idea is to split up the mesh list into 3 different lists (one for each axis XYZ), then iterate through each list and move the meshes along one axis only - calculating the bounding box volume of the selection and adding a padding value so that the meshes get space between them. It would look something like this:
Select all meshes in listX > Calculate bounding box X width > Add padding to that value > Move the mesh-package said value > Deselect one mesh > Repeat
Or is there any better way of doing this?