POLYGON SLICER

SLICING THINGS INTO ITTY-BITTY STRIPS SINCE 2021

UPDATE: Polygon Slicer has grow-up. It’s packed up it’s things and moved on over to SideFX Labs where it chose it’s new name “PolySlice”. I’ll no longer dev the tool here, and you can consider this tool deprecated. I’ll leave the page and files online for learning/education purposes.

DOWNLOAD



Welcome to the Polygon Slicer! There are many ways you can slice geometry in Houdini:

  • Clips in a loop
  • Gamedev slicer
  • Divide’s Sop Bricker mode

But most start to struggle with many divisions and complex geometry. Cooking time sky-rockets and memory use can spiral. It was just that limit that I was hitting whilst developing some Greeble tools. So I thought why not give it a go? If I could manage to implement something in VEX that could process each polygon in parallel, theoretically it should scale like a beast.



FEATURES

Polygon Slicer automatically propagates attributes to the new geometry - strings, floats, vectors and integers for points and vertices and primitives. All types supported for detail and primitive attributes. Currently it doesn’t transfer groups.

In addition to polygons, it also has a polyline mode. I know, Woah!!

OVERVIEW

Here’s a simplified overview what is going on per polygon:

  1. Check if a slicing plane passes through the polygon. If so it continue.
  2. Step around the polygons to get a list half-edges.
  3. Reorder the half-edges so that the half-edge with the source point with the lowest value in the dimension perpendicular to the slicing plane is first.
  4. For each Half-edge in the list, starting at the source point, record if lies on a slice plane, then step along towards the end point adding points as each slice plane is crossed, recording these points in an array.
  5. Steps forward from the first item, and backwards from last item, pairing points that are cut by the same slicing plane.
  6. Create a new polygon for each pair including the previous wound point forward and backwards respectively.
  7. Fuse the the points back together.


APPROACH/OPTIMISATION

The tool transforms the geometry it's acting on into a “slice space”, where each slice plane lies at a whole number in the x dimension. This allowed me to implement a large part of the algorithm using simple logic and to store data as arrays of integers rather than floats. This leads to good memory performance and less complex computations… well that was the theory! Regarding computation, I managed to calculate new slice point positions with one simple dot product per half-edge as opposed to more costly matrix operations.

In some ways it is computationally inefficient as every edge is stepped along more than once - once for each polygon that shares that edge.
However by doing so we break the dependency between each polygon which:

  • Simplifies data structures
  • Decreases data needed to be stored
  • Decreases resources needed to retrieve and sort data - this can be party-pooper in VEX
  • Minimises waiting for another process to complete

By only requiring relatively short integer arrays and not using recursion, it made it possible to implement the core largely in VEX.

With the front-to-back and back-to-front pairing winding method, you’ll notice that the tool can handle triangles, quads and ngons. Proud of that bit. If a polygon is concave - if edges dip in and out of the slice planes - the method won’t find a nice pair of polygons to form it’s wind. Fear not, you can enable “Divide Convex Polys” and then you’ll be golden.

Please consider subscribing if you’d like to keep updated with what I’m up to or follow me on Twitter DoesCG.

DOWNLOAD



LIMITATIONS

The fusing of the points after slicing is a little naïve. There is some logic and control on how new polygons are joined back together, but underlying the safeties it still relies on spatial relationships. In the future I would like to check the source edge/pts/polygons connection relationships and then ensure their progeny followed these relationships. The current implementation is fast though. I’d also like to have a look at improving the slice remap function that changes the spacing of the slices with a ramp to give straighter slices.



HAVE A LOOK

Dive inside and have a poke around. Most of the VEX is commented, but it could be more readable. Hopefully the overview above will help signpost things.

I’d like to refactor so it is cleaner and more intelligible at some point but I want to first use it more, and allow that to inform me if and how I should take the Polygon Slicer forward.

Have a play around and send me some images. I’d love to hear if you end up using it. I may even put them up! I plan to play around and make some fun renders. And please give me some feedback.

If you do find this tool useful please point others to this page so they may learn and benefit. Why not consider subscribing or following me on Twitter @DoesCG for more. I’d love to see what you’re up to as well!

Thanks to Ten24 for the head model I use in the Gif.