CSG To Mesh is a plugin that converts CSG part operations into editable meshes. This can be used to convert many scenes into meshes which as a byproduct allows you to access the triangle data. This can be very valuable for generating and modifying assets in studio.
Keep in mind editable meshes don’t save and must be published before using in an actual game.
How was this achieved?
When local unions are saved as rbxm or rbxmx files they contain their rendered mesh data in a special format. This plugin serializes unions into the rbxm format and then reads and parses the mesh data into an editable mesh.
It’s worth emphasizing that all unions that run through this plugin get cloned and unioned with nothing. This seems like a really random step, but it ensures that the union we’re reading from is local and not storing its mesh data in the cloud.
This was only achievable due to the amazing work of krakow10 in reverse engineering the csg mesh format. I used their work to write the lua parser and in the event that Roblox changes the CSG format I make no guarantees of future support.
Why would I need this?
This plugin essentially gives you the ability to convert anything that can become a union operation into a mesh. This means you can effectively interface with a large body of common roblox assets as meshes.
For example in the following video this plugin is used to convert a happy home to a mesh and then rotate the vertices so it can be skewed.
Just wanted to provide an update on this plugin for anyone who stumbles upon this.
I took this plugin off-sale b/c Roblox changed the CSG serialization format effectively breaking the plugin. The format likely changed to support the new solid modeling on mesh APIs.
I’ve made significant progress in figuring out how to parse the new format, but I have a few callouts:
MeshParts generated with the new API only seem to retain their physics data when serialized. This means they are impossible to convert with the plugin. This may change in the future b/c technically we should be able to load a mesh part as an editable mesh (?). This mostly depends on however Roblox ends up handling permissions on mesh CSG operations.
Although I have made significant headway in parsing the new format there’s still a marker for a set of data I can’t figure out. I strongly suspect this is UV data, but I can’t seem to generate a union operation that has any of this mystery data in it. Since I don’t know what this data is I’m reluctant to push the new format b/c it might break in a case where a user tries to convert a csg part that has the unknown data.
If you’re interested in the details or want to help me out feel free to check out the PR where I’m working on this new support.
This is back on sale w/ support for the new format.
I never did figure out what that last marker is - I couldn’t ever create a union that had any of the data in it. I currently throw an error if some of this data is detected and ask that the user send the problematic union my way.