AASubtractor - Fast Box on Box part subtraction!

Hello Developers!

AASubtractor, or Axis Aligned Subtractor allows for fast axis aligned box on box subtracting. You may have seen a code dump for this a while ago, you can still find that post here still if you just desire the barebones cutting mechanics.

The idea

Currently Roblox CSG cannot be replicated onto the client; additionally Roblox CSG is very slow. This module aims to fix those problems and subsequently to make things like bullet holes, explosion craters, among other things within reach!

Examples with video

You can find & edit the game shown in the video here

Basic Usage

To subtract one part from another the code is simply:

local Module = require(game.ServerScriptService.AASubtract)
local PartsTable, Model = Module.SingleSubtract(Object, Subtractor)
-- Will subtract 1 part from another

To subtract one part from a group of parts the code is:

local Module = require(game.ServerScriptService.AASubtract)
local PartsTable, Model = Module.GroupSubtract(List, Subtractor)
--Will subtract 1 part from a collection of parts

However you can input many more parameters to save you time and code

SingleSubtract:

local Module = require(game.ServerScriptService.AASubtract)
local PartsTable, Model = Module.SingleSubtract(Object, Subtractor, Parent, MakeModel, ModelName, KeepOriginalObject)

--Parent // Instance | Default = Object's Parent // is the parent of every part subtracted or the model if MakeModel is set to true

--MakeModel // Boolean | Default = false // determines if a seperate model is made for the subtracted part

--ModelName // String | Default = Object's Name // the name of the new model

--KeepOriginalObject // Boolean | Default = false // When subtracting parts the original object is left over, 
--sometimes keeing it can be valuable

GroupSubtract:

local Module = require(game.ServerScriptService.AASubtract)
local PartsTable, Model = Module.GroupSubtract(Object, Subtractor, Parent, MakeModel, ModelName, KeepOriginalObject, CollectiveModel)

--Parent // Instance | Default = Object's Parent // is the parent of every part subtracted or the model if MakeModel is set to true

--MakeModel // Boolean | Default = false // determines if a seperate model is made for the subtracted part

--ModelName // String | Default = Object's Name // the name of the new model

--KeepOriginalObject // Boolean | Default = false // When subtracting parts the original object is left over, 
--sometimes keeing it can be valuable

--CollectiveModel // Boolean | Default = true // When making the new parts it will bunch all of them 
--together under one model when this is set to true; if not it every part subtracted will retain its own 
--model. Identical behavior can be produced when looping through a list of parts and using :SingleSubtract()

Finally, here is the link to the modulescript!!

Please DM me any bugs or suggestions so i can improve this Module!

15 Likes

Does this support non square shaped cuts?

Amazing module, great work. Good to see someone finally make something like this.

2 Likes

No, the speed in the module lies within it’s narrow use. This module is meant for things like quick bullet holes blocky destruction.

Uh, you can’t edit the “Box subtracting Place”

doing updates to module atp so it privd

1 Like

Sorry for bumping, but this is exactly what I needed for my upcoming voxel-based destruction game! Very nice module, it’s a shame that it didn’t get that much attention. I have one suggestion that I think would benefit this module a lot; would it be possible to add a boolean that if set to true, unanchored any parts that were left floating after a subtraction, so they fell to the ground?

1 Like

did you read any of this thread or no? The point is this is an alternative for voxel type games. Also you cant use CSG on the client for some reason so I thought a different approach would benefit games

3 Likes

well I mean I would take a more additive approach as I think it would function faster. I prolly wont get around to this but if I do:

the approach would be to slightly rescale up the part ex (0.1, 0.1, 0.1) & get its part in bounds, then I would make it so it would index every part it just welded into a “do not weld” list for performance because it’s already joined to a part. Then finally I would make these welds tie in with part-cache since for larger models you would be creating and destroying lots of them

(mostly telling you this incase you want this soon so you have an idea of where to start :sweat_smile:)

Alright, thanks for explaining how this would be achieved, I will try to implement it myself when I have time, if I’m successful I can dm you the new code so you can add it to the module if you want.

1 Like