New Roblox In-Game CSG API is now available

Does this also mean that we will be able to create and set meshpart mesh ID’s soon too?

13 Likes

HOLY SMOKES

This is an awesome birthday present

17 Likes

It appears if you stop a simulation while UnionAsync or SubtractAsync is working, you can cause something to crash - Studio will throw up the “unexpected error occurred” dialog.

Studio will continue to work fine but will close if you click OK. If you ignore this dialog and attempt another simulation, these functions are dead and will no longer work.

Start a simulation and stop it again roughly one second after the first negate happens.
Baseplate.rbxl (13.6 KB)

8 Likes

thanks, I’ve created a ticket for this.

6 Likes

Don’t know how optimized this is yet but bullet holes can finally be a thing.

https://gyazo.com/ea9c53ef1cd64e0849a5db1952b52a1e

19 Likes

For those with problems using the new API, it creates a new Union object and doesn’t change the original parts.

local newPart = Origin:SubtractAsync({Part table to subtract}, Enum.CollisionFidelity.CollisionFidelityOfChoice)
newPart .Parent = workspace
18 Likes

:clap:

1 Like

YES, THE GODS HAVE ANSWERED US! I have to have a complete sentence to post :/.

5 Likes

OH, SO MANY POSSIBILITIES :clap:

3 Likes

YES!

This will make so many things possible!

I’m excited to try it!

2 Likes

:weary::sweat_drops: y e s

7 Likes

I must say, I felt really negated without this feature. I’m glad you guys unioned up to create something so awesome!

Seriously though, I remember a few years ago when something like this was unthinkable with CSG.

16 Likes

thank%20you

This update is much appreciated and will definitely be very helpful with making games feel more realistic.

9 Likes

WOO! Finally! This is going to be a game changer, I just hope it’s very optimised on a larger scale. If not, that’s perfectly fine.

3 Likes

Here’s a code sample that I wrote for in-game CSG a few weeks ago.
It makes explosions carve spheres out of nearby parts!

----------------------------------------------------------------------------------------------
-- @CloneTrooper1019, 2018 <3
-- SwissCheese.lua
----------------------------------------------------------------------------------------------
 
local function createRegion3FromPart(part)
	local pos = part.Position
	local size = part.Size
	
	local corner0 = pos - (size/2)
	local corner1 = pos + (size/2)
	
	return Region3.new(corner0, corner1)
end

local function onExplosion(explosion)
	-- Ignore visual-only explosions
	if explosion.BlastPressure == 0 then
		return
	end
	
	-- Create the sphere that will be subtracted with this explosion.
	local radius = explosion.BlastRadius
	local negateSphere = Instance.new("Part")
	negateSphere.CFrame = CFrame.new(explosion.Position)
	negateSphere.Size = Vector3.new(radius, radius, radius)
	negateSphere.Shape = "Ball"
	
	-- Cast negateSphere into the 'Objects' type.
	local subtractor = {negateSphere}

	-- Capture the parts within a Region3 formed by the sphere.
	local region = createRegion3FromPart(negateSphere)
	local parts = workspace:FindPartsInRegion3(region)
	
	for _,part in pairs(parts) do
		local success, result = pcall(function ()
			return part:SubtractAsync(subtractor)
		end)
		
		if success then
			-- Move the children of the old part into the new part.
			for _,child in pairs(part:GetChildren()) do
				child.Parent = result
			end
			
			-- Swap out the part with the union.
			result.Parent = part.Parent
			result.CFrame = part.CFrame
			part:Destroy()
		else
			warn("SubtractAsync failed because:", result)
		end
	end
end

-- Listen for explosions being added to the workspace
local function onDescendantAdded(desc)
	if desc:IsA("Explosion") then
		onExplosion(desc)
	end
end

workspace.DescendantAdded:Connect(onDescendantAdded)
----------------------------------------------------------------------------------------------
30 Likes

How often does real time CSG error compared to CSG in studio?

6 Likes

I’ve been wanting something like this for years. Thanks for the early release.

2 Likes

A developer @Lauri9 (view roblox profile) has worked on a quick demo, using this, which took only 3 hours(!!) to code and the results are promising!

4 Likes

AMAZING, I can’t wait to see what people do with this.

2 Likes

ive literally just made my entire map destructible i thank you

1 Like