VL.PolyTools

!Update 1.3.0 released 30.08.23, see below

If you find VL.PolyTools useful please put a star on it on github

VL.PolyTools

Tools for working with Polygons and Polypaths in vvvv gamma.

Polygon = shape made only of lines, Polypath = shape made of lines and curves

See the helppatches for a more detailed overview

To Install

Grey menu (top left)>Manage Nugets>Command Line

Type
nuget install VL.PolyTools

What kind of things does it do?

image
Interactive Helppatches

PolyTubeStars

Polygon Tube

NormalMappedTube

Polygon Tube with normal mapping

LerpDemo

Lerp between 2D Polygons in 2D and 3D

VL PolyTools FOV Calc

Visibility from a point inside a polygon
(Using Expanding Triangles method by Francisc Bungiu, Michael Hemmer, John Hershberger, Kan Huang and Alexander Kröller)

VL PolyTools 3D Extrude

3D extrusion of Polygons in stride

VL PolyTools Polypath Union

Union of PolyPaths including internal compartment lines.

VL PolyTools Cutting A Poly into Compartments

Cutting a PolyPath into compartments

VL.PolyTools extruded polygon with normal mapping

An extruded Polygon with Normal mapping

Bonus see included ‘SKPathUtils.vl’ if you are looking for low level ways to extend SKPaths

Dependencies

Made with vvvv Gamma 5.3-0088

com.angusj.Clipper -Version 6.4.2

credit Angus Johnson, gylee

LibTessDotNet

Geometry3Sharp

credit Contributors to speps/LibTessDotNet · GitHub

Special Thanks

@Untone for help unlocking the SKPath verbs for use in vvvv gamma

Version History

V1.4.0

  • !Breaking Change! Fixed error in the Polygon2DPlus Join method that takes 3D polygon points and a normal
  • !Breaking Change! Renamed ‘LineSegmentIntersectsBox’ to just ‘LineIntersectsBox’ to make consistent with similar functions
  • Added new function LineIntersectsRectangle and helppatch.
  • Fixed bug TransformsOnLine where it didn’t normalise internal direction vector
  • Fixed Bug PolyTubeMesh where it would reverse the direction of 2D data but not 3D data.
  • Improved debug out data on PolyTubeMesh
  • Added new function and helppatch ‘find if points are on a line’
  • Added new function and helppatch ‘Interpolate points in a triangle’
  • Added new function and helppatch ‘Calculate normal of a line segment 2d’

V1.3.0

  • !Breaking Changes! Re-categorisation of some nodes into new Line category. Some line related functions may have red nodes. Double click on them, clear their existing associations in the bottom right and search again for the name and you should find the same nodes.
  • !Breaking Change! All polytubes need their input ‘Polygon2DPlus’ types to have heightmode=1 (Y=height). This is now consistent, was 0 on some old helppatches.
  • Added 3D Triangle Intersection, see helppatch.
  • Exposed RayIntersectsTriangle from Stride.Core.Mathematics
  • Added a helppatch for Solving a Triangle in 3D and a node for finding the third point of a triangle if you know some constraints about the first two points.
  • Added function for finding a 3D Line segment intersects a box with helppatch
  • Added new dependency Geometry3Sharp GitHub - gradientspace/geometry3Sharp: C# library for 2D/3D geometric computation, mesh algorithms, and so on. Boost license.. Currently only using this for a few intersections but has potential to do a lot more in this package. It’s Boost 1.0 licence (like clipper).
  • Added LinePoints utility drawing function for stride
  • Added Plane (Plane) utility drawing function for stride, this takes a Plane mathematical struct as input, however note this has some limitations as the struct is infinite and we are drawing a finite plane. Basically just make it really big.
  • Exposed Normal input on LibTessDotNet Triangulation nodes. Triangulation nodes are 2D but it can be necessary to set the face direction in 3D use. See the CalcTubeEndCaps process inside PolyTubes for an example usecase.
  • Improved TransformsOnSpline and TransformOnLine nodeset where you specify either ForwardVectors or a single ForwardVector. See the “Tube On Path” helppatch for an explanation. This is less confusing for their usecases where the UpVector of the Spline/Line is the Y axis, and results in less weird singularity twists in tubes. The previous nodes are still included in obsolete category.
    V1.2.2
  • Bugfixes with dependencies

V1.2.1

  • !Breaking Change! Refactored categories for some of the Polygon3D nodes to make it clearer The actual nodes are still the same, you may have to double click red nodes in your apps and retype the names to recreate them.
  • !Breaking change! Bugfix on winding direction node. With the calculation method I was using winding direction is potentially flipped in some spaces where Y is inverted. Between Stride and Skia we have a mix of spaces where this might be true. There is now a ‘YIncreasesDownward’ pin on the WindingDirection and ForceClockwise/CounterClockwise nodes. Check the helppatch ‘HowTo Calculate Winding Direction Of A Polygon’
  • New Polygon2DPlus datatype, for a 2D polygon that is effectively annotated with a third dimension. The underlying 2D polygon can still be accessed and manipulated.
  • Rearranged helppatches to make general geometric functions clearer
  • Added sample a point on a line
  • New 3D functions for dynamic geometry to make ‘polygon tubes’, where each element of the tube can have a different polygon face. See the new helppatches in 3D category. These come in several flavors where you
  • LERP (morph) between two polygons, see HowTo LERP between Polygons helppatch
  • Added sample a point on a polygon perimeter (previously only for PolyPath)
  • Added DrawPolygonRadialLines to draw radial lines between origin and points
  • Added DrawPolygonPointLabels to draw text labels at each point on a polygon
  • Improved the TriangleContainsPoint helppatch
  • Aspect changed on PolygonVisibility nodes to advanced.
  • Added PointCount operation to Polygon datatype

V1.1.3

  • Removed stride physics Raycast function now there is a native one shipped with vvvv 5.3

V1.1.2

  • PolygonExtrude now has an additional 2D UV scaling option for the sides of the extrude. (Was U only in last release)

V1.1.1

  • Rearranged and expanded the helppatches for PolygonPlane and PolygonExtrusions
  • Added option to generate tangents, needed for normal (bump) mapping
  • Added many options for texture mapping the 3D polygon objects
  • For those planning to make their own dynamic meshes or models in stride the PolygonPlane and PolygonExtrusion patches are reasonably well documented examples, including with UV coordinates, tangents and bounding boxes.
  • Added some tools for debugging stride entities as wireframe, vertices, tangents etc

V1.1.0

  • Tested in vvvv gamma 5.0-stable
  • Added UV map to the ExtrudedPolygon. This is not intended for every usecase but should be a good starting point.
  • Fixed another bug with bounding boxes of PolygonPlane and ExtrudedPolygons that caused incorrect culling.
  • Minor breaking change due to new signature of PolygonPlane and ExtrudedPolygon nodes (so they go red). Just double click on them and recreate them and you should be good to go.

V1.0.10

  • Minor improvement to 3D polygon plane and extrusion nodes and helppatch
  • Can set custom bounding box depth for the 3D polygon plane

V1.0.9

  • Stride dependencies moved to separate document VL.PolyTools.Stride

V1.0.8

  • Ensured compatibility with vvvv 2021.4.11-1313 (RC4)
  • Fxed some helppatch windows potentially not opening

V1.0.7

  • Made the bugfix from V1.0.6 optional as ‘Allow Perfect Diagonals’ on ‘HowTo Find Grid Cells Along A Line’

V1.0.6

  • Fixed bug in line intersects grid calculation

V1.0.5

  • Added second ‘Does Line Intersect Grid cells’ operation including all cells. See helpatch ‘HowTo Find Grid Cells Along A Line’

V1.0.4

  • Added function for finding grid cells along a line based on Bresenhams Line Algorithm. See Helppatch ‘HowTo Find Grid Cells Along A Line’
  • Added function for generating square-ish layout grids using a single count input. I say square-ish because it handles cases where the input count does not have a whole square root and a partial row/column might be needed. See HelpPatch ‘HowTo Generate a nearly Square GridSpread’

V1.0.3

*Helppatch improvements
*Consistent GetBounds method for Polygon and PolyPath
*Added Splitting Circles Example patch kindly contributed by ██ ██
*Added option to Compartments to avoid including outer stroke

License

Boost 1.0

19 Likes

Thanks so much for this!

i hacked together some of the stuff you got in here for my generative lasercutting/3d printing/papercutting stuff, but it was always hacky and not consistent. will try to redo my patches with your library and report back.

2 Likes

Now updated to 1.0.3
-Helppatch improvements
-Consistent GetBounds method for Polygon and PolyPath
-Added Splitting Circles Example patch kindly contributed by ██ ██
-Added option to Compartments operation to avoid including outer stroke

2 Likes

for some reason exception raises in 2022.5 280 preview

@Yar afraid I cannot reproduce.
Those helppatches all working for me in Polytools V1.0.3 on
2022.5.0 280.

@tobyk
I confirm, the error does not reproduce. Now everything starts normally.
But it was a steady result after restarting Gamma for a while. I don’t know what changed.

@Yar
Ok. noted. I’ll do a more thorough test of all the helppatches when 2022.5 goes to release candidate.

Fantastic contribution and nicely structured help patches!
Tested with 2022.5 preview 310

image
It also works with STRG+ to create multiple input pins!


^^

“how to extrude a polypath in 3d” contains an obsolete version of “extruded polygon.”
“how to render a polypath plane in 3d” is missing the “polygonPlane”

I did not look through all the help patches (yet) but thank’s lot for sharing! This is quite extensive, and especially the distance and intersection tools are pretty cool. snap on path, nearest point… those will be really fun to use!

2 Likes

Hi @tobyk
I have a feature suggestion
It would be great to add Keep Tool functionality if it would needed to left one of the paths in output

изображение

1 Like

@yar

Ok, I’ll make a note to include that as a utility op in the next major update (Probably when 2022.5 goes RC)

Nice! Thank you
Maybe, just for consistency, would be great add “both” option

I just realized that these are Skia nodes, not polytool, right?

Yes but I think it makes sense in VL.Polytools as a collection of functions that build on skia and make solving geometric problems easier. It’s also much easier for me to just include it then to mess about with a pull request to VL.Skia (If it’s even on github?)

@tobyk Make sense!

look what I made recently:

Images

изображение

изображение

изображение

6 Likes

Wow super impressive!

Very compelling look

@tobyk Can you suggest a way to get an array of points used to build a polygon / polypath? I am a bit stuck and can’t figure out how to get this action done

Like this?
Maybe there’s a way of sampling it? I would even try to sample only the curved parts.
It looks like this array of points contains the control points of the bezier

@yar

The data inside a polygon is the list of points that make a shape with straight edges. So this list also simply describes the outline of the shape.

The data inside a polypath is indeed the control points. For straight sections will be equivalent to polygon but for curves they are bezier type control points (although possibly one of the verbs is not bezier, don’t remember. In any case it’s control points)

So you got the right idea already: to get a list of points from a polypath that is the outside shape you must sample the curves and ‘flatten’ it into a polygon. You can see there is trade offs here with resolution and losing the vector information.

I’m not near a laptop to find the exact nodes but I think they are in the helppatch ‘convert a polypath to a polygon’

Thank you! I’ll have a look

So far I have solved this problem as follows

изображение

But it is much easier:

1 Like

Hi @tobyk
Can you suggest a way to make an intersection of something like a line and something like a contour that results as a cutted line (or lines)? I tried to investigate this, but not sure if it is even possible at this moment.

Can this be considered a “no” answer?

Or it can be a solution?

@yar

So yes you are in the right direction.
You cannot clip a line by a line.
But you can clip a line by a filled area.

image

CutLineByFill.vl (49.6 KB)

Alternatively in the newer VL.PolyTools is a ‘Line Intersects Line’ function
image

Using this you could at least find the intersection points of multiple lines.

1 Like

We really lack features and operations for working with SVG. Not only has the issue of not being able to display SVG with CSS been raised recently, but all the manipulation of extracting primitives and paths is done by parsing XML instead of doing it without thinking

We should look for ways to integrate SVG, as it makes the most sense in the context of this library

1 Like