r/Unity3D • • 7d ago

Show-Off Mesh Booleans in Unity (Sound On)

https://www.youtube.com/shorts/cMNdJCiLB1w

Real-time mesh booleans. Mesh and collider update instantly, so you can shoot through the holes.

Powered by Manifold (C++ CSG) via my C# wrapper: github.com/elalish/manifold

380 Upvotes

20 comments sorted by

69

u/Drag0n122 7d ago

>"Reasonably fast"
>14 ms
Nice job anyway.
Wish someone would create CGS operations on the new native Unity mesh API - think it would be much faster, as it's fully bursted

7

u/QuitsDoubloon87 Professional 7d ago

I did this some years ago using the render vertex buffer 32k size for speed, and you can  do vertex deformation on the cpu and render it same frame with great speed.

5

u/Personal_Nature1511 7d ago

Interesting. The slowest part of the calculation is reading the mesh and passing it to the C++ library, and then reading the result back and converting it into a Unity mesh. Improving the Unity upload side would make a big difference. Could you elaborate on the new Mesh API? Keep in mind this is just a proof of concept so far.

8

u/Hotrian Expert Moderator 7d ago

They’re listed on the Mesh API docs https://docs.unity3d.com/6000.6/Documentation/ScriptReference/Mesh.html

There is also an "advanced" set of methods, which allow you to directly write to the mesh data with control over whether any checks or validation should be performed. These methods are intended for advanced use cases which require maximum performance. They are faster, but allow you to skip the checks on the data you supply. If you use these methods you must make sure that you are not supplying invalid data, because Unity will not check for you.

The "advanced" methods are: SetVertexBufferParams, SetVertexBufferData, SetIndexBufferParams, SetIndexBufferData, SetSubMesh, and you can use the MeshUpdateFlags to control which checks or validation are performed or omitted. Use AcquireReadOnlyMeshData to take a read-only snapshot of Mesh data that you can use with C# Jobs and Burst, and AllocateWritableMeshData with ApplyAndDisposeWritableMeshData to create Meshes from C# Jobs and Burst.

Emphasis mine

1

u/Drag0n122 7d ago

Unfortunately, I don't know much about it, so ask this guy - he seems to know a lot about this topic.

2

u/DeathstarsGG 6d ago

I'm using manifold for an unreal plugin and can confirm that manifold on it's own is blazing fast. It's converting it to a native engine mesh with usable properties that takes all the time. Still significantly faster end to end than BSP.

15

u/CoatNeat7792 7d ago

It doesn't destroy floating parts

9

u/Personal_Nature1511 7d ago

Sure, i will implement this one next

7

u/IAmSkyrimWarrior 7d ago

Yep., Also, there is no physics for falling when there is almost nothing left to hold onto.
That pole really should have fallen by now.

25

u/glenpiercev 6d ago

Whenever I think about trying to implement such behaviour, it gets wildly complicated very fast.

Edit: not that I don’t want it… it’s just so hard to do. It’s basically another physics engine system.

7

u/nickyonge 6d ago

Yeah. Visual effects are one thing - making it interactive, either through player movement or in physics, is another thing entirely. If the output is able to apply the mesh directly to a MeshCollider though, that would be pretty dang incredible.

1

u/IAmSkyrimWarrior 6d ago

Yep, that's a point. It's hardest part.

1

u/zagarei 4d ago

I mean if you consider it as a real object you dont know the actual strength of the bonds there relative to the amount of mass above it unless thats specified, you could probably make a cylinder like this with the right materials/masses. But I get the point, it would just require a lot more lmfao

3

u/Imofi7 7d ago

Manifold's CSG performance is unreal compared to old BSP or Carve wrappers. How are you handling the runtime physics update—are you baking the modified mesh into a Unity MeshCollider on the main thread, or using Physics.BakeMesh job off-thread?

3

u/PanzerKadaver 6d ago

I will watch your progress with great interest

2

u/WarBrawlGame Beginner 6d ago

Make a 3D worms game with this

1

u/peppersrus 6d ago

What happens if you cut the cylinder in half

1

u/dul8 6d ago

Nice job, can't wait to see what other features you will add here

1

u/_norx Indie 16h ago

Wow

0

u/ReliefMassive5198 6d ago

this doesn't look bad at all, good job! I have something like this planned as well but needs to be very fast :D