XaiJu
Megan Fox
Megan Fox

patreon


How to improve the ProBuilder tool

First, read the $1+ post to get the source. Get it working. Got an arch? Cool, ok, let's talk about how to fix the source to work like you expect.

Now, first real code step, change DoAction() to look like this:

This wasn't intentional gelding, I just realized I'd broken this in the course of fighting with the code. That will make the "SubDivs" option do something again (when you press the + button beside Arch). Though I recommend re-titling it to Facets, since that's more literally what it is, now. That argument originally did something else.

Next up, how to fix the options:

If you wire the depth argument up as a modulator of radius, you can trivially make the arch deeper or shallower. Nice for making, you know, different sorts of arches.

Now to the more important stuff. First, how to specify arch direction:

You'll notice that the direction the arch goes is seemingly arbitrary, and varies randomly based on what polygon you use. That's because the first edge of the arch defines the direction the arch goes in, and it always defaults to the first one. Add a boolean argument that, optionally, makes it choose the second edge instead of the first.

Just make that 1 instead of 0, and it'll flip which way the arch goes. A little silly, but since you can undo the arch, just undo, flip the bool, hit arch again, now it'll face how you want.

Second, if you want an outie arch instead of an innie:

I think you'll sometimes get outies or innies naturally, it's similarly arbitrary based on the nature of the face you choose. So you want another boolean that toggles back and forth easily, just add it to the options page.

This one's easy too. Just change this argument,

Flip that positive or negative, and it should flip the arch outie vs innie.

Finally, if you want a quarter-pipe instead of a half-pipe:

You'll want another boolean that controls this in the options. It'll start by changing that 180f to 90f, if quarter-pipe mode is engaged.

The other thing you'll change is here, and it'll involve some math,

Instead of being the center of the face, you want the center of the circle arching through your arch. To extract that, you need to exploit the math of a circle inscribed in a square. Imagine your polygon is one edge of a square inscribed in a circle. You know the center position of that line, you know its normal, you know the normal points at / goes through the center of the circle, and you know the length of the line. From that, you can calculate the radius of the circle, and the offset from the center of the line, along the normal, to the center of the circle.

So do that. Then change centerOfRotation to be that position, instead of the face centroid. Simple! (heh)

Hopefully now you know how to make ProBuilder custom tools. The super huge take-away is that you need to be working with selected faces, to stand a prayer. If you try to start with selected edges or, worse, vertices, you'll find they have almost no unique identifiers that let you easily jump up the logic tree to figure out what face would be implicitly selected by selecting the given edges or verts. You have to write all of that helper logic yourself.

If you start with faces? It's a ton easier. The downside is you get those goofy "the direction is arbitrary since you didn't start with any edges selected" problems, like above with the changing the direction or innie/outie of the arch. Still, it's better for your sanity.

Have fun!




More Creators