Help with floor placement system

I’m trying to make a placement system like the one from bloxburg, But the floor placement stumped me. I have read lots of topics like this one but I still can’t figure it out.

Every time you place a point it should recalculate the triangles like this

Thanks!

4 Likes

What have you tried so far, and is there something specific you’re stumped on?

2 Likes

It’s putting the triangles in the right places. My idea was every time you place a point it connected it to the last two. But that cause too much overlapping


Also, the big pink space has nothing in it.

2 Likes

If you’re placing the points in order, you should create a triangle between the first, previous and newly placed points. So when placing e.g. point 4, the new triangle should be between 1, 3 and 4. This only works for convex polygons tho.

How does your building system work? Can new points be placed along existing edges?

2 Likes

Im trying to recreate the bloxburg building system. Also if I connect every point to the last one there wouldn’t be any center. I had an idea to connect every 3 points but that doesn’t account for a number not a multiple of 3 and if this scenario comes up.
g2
The orange area is open because using my method doesn’t account for this scenario

2 Likes

Ah sorry, I don’t know why I thought my idea would work :sweat_smile:

I did some research, and found out that what you’re looking for is an algorithm for doing concave polygon triangulation, i.e. turning a concave polygon (a list of points) into triangles (a list of sets of 3 points each). There’s a bunch of algorithms with different run times and some only work for polygons without holes.

I found a decent explanation of the “ear clipping” algorithm here: https://www.gamedev.net/tutorials/programming/graphics/polygon-triangulation-r3334/ It seems simple enough, and even though basic implementations will run in O(n²) time, it should be fast enough for at least 20 vertices (20^2=400), maybe even more. You’ll have to test it to see if it’s fast enough for your specific situation, and if not then optimize it somehow. You can probably optimize it a lot by only re-calculating the parts that actually changed when the player makes a change.

EDIT: More in-depth stuff from geometrictools.com.

2 Likes

I managed to get it working properly, but you can just build through the other floors how would I go about detecting collisions? I read some posts about region 3 but I can’t get it working. :GetTouchingParts() isn’t helping because the polygons could be touching each other in the right place like the sides.

2 Likes

You could use the RotatedRegion3 module by EgoMoose (IIRC), which lets you do collision detection between parts, wedges, cylinders and spheres.

2 Likes

After some time I managed to get the collisions working:


It completely ruined what I used for the floor triangulation. Notice when the lines turn red because it overlaps. I don’t know why but the triangle just goes outside the lines.
Sorry for bad quality
Any ideas on how I could fix this?

2 Likes

This is what it looks like first:
image

Then after:
image

Any idea why this happens? Here the code:

if i > 1 and i < #Nodes then
     local a = Nodes[i-1]
     local b = Nodes[i]
     local c = Nodes[i+1]
     local ta,tb
     ta, tb = Triangle(a.Position, b.Position, c.Position, workspace, ta, tb)
end
1 Like

Hmm no, I can’t guess it from the code you posted or the screenshots :confused: I’d recommend setting breakpoints and stepping through the code while inspecting variables to see if they have the values you expect when things go wrong.

2 Likes

After a LOT of hard work, I landed on a solution that seems to work but has a problem sometimes. Mainly that the script doesn’t know what to do when there are six points in this format.

image
It doesn’t get better from there. If you add more points that hole remains. The way I connect the dots is as follows:

  • Connect even points to neighbors
  • If last points and is even then connect to the points before and the first point
  • If the last point and is odd then connect to the last even points and third point. Connect the point before as it is the last point (Will be even

Also when complex shapes are made it has a tendency to fail:
image

2 Likes

The algorithm you want is called “ear clipping”. It is described by this paper: https://www.geometrictools.com/Documentation/TriangulationByEarClipping.pdf

and source code (C++) is available here: https://www.geometrictools.com/GTE/Mathematics/TriangulateEC.h

EDIT: THe linked source code is for polygons with lots of holes, and is pretty complex. Check out this instead.

5 Likes

Thanks! After a bit of reading and testing C# Code it’s working! If it has any errors please tell me.

Roblox Floorbuilder.rbxl (32.7 KB)

EDIT: I realized that this still has the same error from before

3 Likes