VL.PolyTools

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

I agree that some nice SVG tools would be great.

I think the future of VL.PolyTools is more low level than that. It’s really about, well, polygon type scope of objects.
For example individual closed shapes, triangles, lines. (Dabbling in some 3D versions)

I think SVG would be better in its own library that looks at the specific usecases you have for it. Working with files and parsing and CSS is really a completely different paradigm than editing shapes.

It could for sure make sense if VL.PolyTools was a dependency in that project, and with nuget you can make ‘nuget install VL.SVGTools’ automatically install VL.PolyTools

2 Likes

hi, @tobyk , i was playing with the poly tools on stride i was learning how to use the nuget and feels good. now i am trying to export the Stride / poly tools - shapes to a svg file but i can’t find the way to do this, do you know how i can this can be done?

Hi @Sabme

I assume you want to use SVGs because you want the vector information? (If you just wanted pixels could of course use png, jpg whatever).

As I understand the SVGWriter is part of the Skia package.

In theory all you have to do is

  • Get your polygons and polypaths and use draw functions that will draw them directly in Skia. EG DrawPolygon (Skia) and DrawPolypath (Skia). Interally these use the Skia SKpath type.
  • Connect those layers to SVGWriter
  • Then I think SVGWriter will takes the layers with vector information (SKPaths) and uses that to write the SVG.

Problem is you said you were using Stride. I’m not sure how you are using it but a rasterised stride scene (pixels) going back to Skia and then to SVGWriter will probably only give you rastersied data in a SVG writer.

There is not much documentation on SVGwriter, maybe this thread could be useful:

hi @tobyk, yep I want the vector info. the thing is I Pass from a Ceate (poly tool ) (rendere on skia) to a CReate (Polytool stride polygon 2d plus) so I played on a 3d space, made spreads and output on scenewindow, the idea is to catch the info like the Processing pdf library to save 3d space info into a 2d space canvas (is the beggin Raw, End Raw statement). i leave my set up and the image i need in vectors maybe this can help for an accurater way to solve it.
I will try the points you write above. ;)


Ok so if you already have the points in 3D it’s just about transforming them back to screen space 2D, in the exact same way as your renderer does (with the same camera). Except we still want to access them as points.

This is nothing really to do with VL.PolyTools BUT you are in luck. It happens to be related to a series of math tutorials I just put into VL.ExtendedTutorials. It might be worth going through those to help understand what’s going on here.

So here is a solution.

Draft Explanation Camera Transform to Screen Space coords.vl (66.2 KB)

There is only one bit I’m unsure of which is a weird X scale transformation for skia. I’ve asked about it in the TransformingBrains chat channel and when I understand that I will also add this to the VL.ExtendedTutorials math series.

2 Likes

ok ok, im a lucky you are on this Math Series Tutorial. i will download the nugget to see your work ;); and looking at the file you sent me, I have seen how to do it. thanks a lot ;)

PD. just one more thing is there a way to pass from a “Create” poly tool stride 2d plus - to a simple a "Create "poly tool node ?

2- on your Draft explanation camera vl file, i just add ( ) 3dmatrix value to correct the pesprective between the 3d viewer and the 2d viewer, it goes under the camera matrices () and on the new matirces mutiplier chahge the 2nd column 2nd row value to ( -1) and then we see the same perspective in both screens.

Ok here is the finalised tutorial patch.
The ‘mystery’ was about aspect ratio correction.
Thanks @motzi for helping me sort it out.

Explanation 22 Camera Transform to Screen Space coords.vl (80.9 KB)

In regards to the question about type conversion perhaps this is helpful?

3 Likes

oki doki got it. thanks a lot