Hi everyone,
The In-Game CSG API we’ve been recently working on is now available. We’d like you to try it out and report issues in this thread. Its performance is acceptable for performing simple modifications on relatively simple CSG objects.
We are working on more comprehensive documentation and an announcement, so consider this an opportunity to try it out early and help us find and fix problems.
The API can be called from Scripts (but not LocalScripts). The API consists of two new methods which can be called in-game on part types already supported by the CSG engine.
PartInstance:UnionAsync(partsToUnion, [optional] collisionFidelity = "Default")
PartInstance:SubtractAsync(partsToSubtract, [optional] collisionFidelity = "Default")
The operations throw an exception if there was a problem in computing the result (too many triangles, unsupported part types, the usual). If the result is an empty mesh, they return nil
. If everything went well, they return a PartOperation representing the computed result, which can be used in subsequent operations if necessary.
The operation leaves all involved parts unmodified, which will continue to be simulated and rendered normally if they were parented to the workspace. The resulting PartOperation is always un-parented and based on positions of the parts as they were when the operation was started. If the result is intended to replace its constituent parts in rendering and simulation, this needs to be performed explicitly in the script. Replication of the result will start once it is parented to the datamodel, and becomes visible after being parented to workspace.
For the time being, at least one of the supplied parts must be parented to a datamodel (not necessarily the workspace, if it is important to keep the parts hidden).
The part on which the method is called is the base part, from which things like material properties are inherited, and the first argument must be an array containing the other parts. The second argument is an optional parameter specifying the otherwise un-scriptable CollisionFidelity property. SubtractAsync
will subtract all parts in the list from the base part, and UnionAsync
unions them with the base part.
Thank you in advance!