Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New PolygonSort node #2324

Merged
merged 1 commit into from
Dec 7, 2018
Merged

Conversation

DolphinDream
Copy link
Collaborator

@DolphinDream DolphinDream commented Dec 3, 2018

This new nodes allows to sort the polygons based on a distance to a given point or distance along a given direction. The Input is the verts/polys needed to be sorted and the reference (either a point P or a direction D). The node outputs the sorted polygons, same (input) vertices, centers of the sorted polygons, distances for the sorted polygons. The node has two modes P & D for distance to point and distance along a direction. Also there is an option to toggle the sorting ascending/descending. And yes, the node also has 3 presets X/Y/Z to preset the sorting direction to be one of the xyz axis.

  • Code changes complete.
  • Code documentation complete.
  • Documentation for users complete (or not required, if user never sees these changes).
  • Manual testing done.
  • Unit-tests implemented.
  • Ready for merge.

sv-polygonsort-ui1

Example 1 : Sorting by distance to point P

sv-polygonsort-example1

Example 2 : Sorting by distance along distance D

sv-polygonsort-example2

@DolphinDream
Copy link
Collaborator Author

And a simple live demo..

sv-polygonsort-demo1

@DolphinDream
Copy link
Collaborator Author

DolphinDream commented Dec 3, 2018

And a more intricate example / demo..

sv-polygonsort-example3

sv-polygonsort-demo2

@nortikin
Copy link
Owner

nortikin commented Dec 3, 2018

what about area, other qualities? because we already have list sort with key user defined, for poligons can be added more specific options?

@DolphinDream
Copy link
Collaborator Author

what about area, other qualities? because we already have list sort with key user defined, for poligons can be added more specific options?

Sure thing. that can be done (area, normal angle etc). Btw @nortikin , can you show me an example of how you would sort the polygons by distance to point/direction using list sorting node?

@DolphinDream DolphinDream changed the title New Polygon sort node New PolygonSort node Dec 5, 2018
@DolphinDream
Copy link
Collaborator Author

DolphinDream commented Dec 5, 2018

And another live demo :) the magic of toroidal fields
The nodetree takes the distance to polygons (output by the node) and feeds it to scale the polygons, in this case, inverse proportionally to the distance to the moving point.

Note: the reason why only the first 11 indices of the sorted polygons are shown is to avoid cluttering the demo.. as displaying hundreds of poly indices would make the illustration unreadable.

sv-polygonsort-demo3

@DolphinDream
Copy link
Collaborator Author

DolphinDream commented Dec 5, 2018

Behold.. the sorting fiesta 🙌 .. now sorting also by area, normal angle to point and normal angle to direction.

sv-polygonsort-ui2

@DolphinDream
Copy link
Collaborator Author

Anybody knows who created the area node ? I was wondering why the unit_normal is calculated via determinant instead of simply via crossproduct of the poly first edges + normalization. What’s the catch ? I notice the normals generated via both methods are the same, albeit the cross product should be faster.

@enzyme69
Copy link
Collaborator

enzyme69 commented Dec 6, 2018

I am totally intrigue by this and all the example demos...!

@DolphinDream
Copy link
Collaborator Author

I am totally intrigue by this and all the example demos...!

Thanks for the flowers, @enzyme69 :) It’s no mystery that the animation/scaling in these demos is doable with other nodes so not much credit can be given to PolygonSort node itself.. the less obvious from the demos however is that the polygons are in fact sorted and the text showing the reduced set of indices are the first 11 polygons in the sorted polygon list.

@DolphinDream
Copy link
Collaborator Author

Here’s another demo with sorting by “Normal Angle Point”. The red indices are the original (unsorted) polygon indices, the blue indices are the sorted indices. The numbers above the poly normals are the angles between the normals and the vectors connecting the centers to the moving point. (hence the sorting name)

sv-polygonsort-demo4

@DolphinDream
Copy link
Collaborator Author

And sorted by area:

sv-polygonsort-demo5

@DolphinDream
Copy link
Collaborator Author

If there are no objections.. this PR is ready to land.

@DolphinDream
Copy link
Collaborator Author

Final UI layout.

sv-polygonsort-ui3

@DolphinDream DolphinDream merged commit 1a4622e into nortikin:master Dec 7, 2018
@zeffii
Copy link
Collaborator

zeffii commented Dec 7, 2018

@DolphinDream who?
image

This is one of the older nodes :) i don't see where it would handle (concave) ngons. I would do a rewrite. I'll port it over to sv4b280 immediately if you do.

@DolphinDream
Copy link
Collaborator Author

@zeffii The polygon sort node already does area calculation so it would really be replicated code to have it in two nodes. I was wondering if it’s worth factorizing the polygon related calculations into a polygon utilities file so that its functions can be used in multiple nodes. And the same could be said about edge related calculations.

@zeffii
Copy link
Collaborator

zeffii commented Dec 7, 2018

yes, factorize it out if you wish. (sverchok.utils.modules.polygon_utils.py) or wait till these nodes appear in sv4b28, no need to do it immediately.

@DolphinDream DolphinDream deleted the polygonSortNode branch December 7, 2018 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants