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

Adaptive Polygons mk3 #3798

Merged
merged 19 commits into from
Jan 9, 2021
Merged

Conversation

vicdoval
Copy link
Collaborator

Numpy implementation for the Adaptive polygons node.
In this scenario:
image
Before 0.793 seconds. Now 0.058 seconds (13X)
I left the previous implementation because is faster when the donor has less than 12 vertices for quad transform and 50 for tris transform. (approx.)
The default is a Auto mode that switches implementation depending on the donor vert count.
Also added a Donor Matching property that can be Repeat Last, Cycle or By Index (controlled by input)
image

  • 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.

@Durman
Copy link
Collaborator

Durman commented Dec 28, 2020

I have tested it. In my layout the new node is about 2 times faster and whole layout is about 1.5 times faster.
2020-12-28_08-53-18

@Durman
Copy link
Collaborator

Durman commented Dec 28, 2020

By the way in my case I would not mind to have opportunities to set use normals parameter per face.

face normals

arr[:,0] /= lens
arr[:,1] /= lens
arr[:,2] /= lens
return arr
Copy link
Collaborator

@portnov portnov Dec 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest

  1. Change this to something like
result = np.zeros(arr.shape)
norms = np.linalg.norm(arr, axis=1, keepdims=True)
nonzero = (norms > 0)[:,0]
result[nonzero] = arr[nonzero] / norms[nonzero][:,0][np.newaxis].T

this 1) uses vectorization more effectively (at least, theoretically it should), 2) takes care of division by zero.

  1. Move it to sverchok.utils.math, because I think I saw similar functions in other modules, at least next time there will be "standard" function to use.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.
I did some performance tests
and this was 10% faster:

def np_normalized_v3(vecs):
    result = np.zeros(vecs.shape)
    norms = np.linalg.norm(vecs, axis=1)
    nonzero = (norms > 0)
    result[nonzero] = vecs[nonzero] / norms[nonzero][:,np.newaxis]
    return result

And this like 2.5x faster. Does the normalisation in-place (good for me in this case)

def np_normalize_v3(vecs):
    norms = np.linalg.norm(vecs, axis=1)
    nonzero = (norms > 0)
    vecs[nonzero] = vecs[nonzero] / norms[nonzero][:,np.newaxis]

I added both to sverchok.utils.math

@vicdoval
Copy link
Collaborator Author

Added:
Normal mapping mode per face

New SubQuads mode,
Top: Frame Transform Bottom: SubQuads Transform
image

Properties refactor with possibility to control transform mode with mask input.
Transform options available per Tris, Quads and Ngons (last ones produce interesting/strange results):
image

Mask can be used to control transformation mode:

image

@vicdoval
Copy link
Collaborator Author

Could anyone give me a hint of why the CI is failing? i found an error in the bl_idname of trim_and_tesselate (@portnov) but maybe I should leave it like was to avoid layout breaks because does not seem the cause

@vicdoval vicdoval force-pushed the adaptative_polygons_mk3 branch 2 times, most recently from 8e565cf to dfda417 Compare January 2, 2021 15:24
@portnov
Copy link
Collaborator

portnov commented Jan 2, 2021

@vicdoval did you re-save json files, or just replaced Mk2 with Mk3?
I tried to import Adaptive_Voronoi_panel.json from this PR, it lacks some node links, and also the node is not configured properly. When I reconnected nodes correctly and re-exported the tree, this test stopped failing...

@portnov
Copy link
Collaborator

portnov commented Jan 2, 2021

The error message is still confusing...

@vicdoval
Copy link
Collaborator Author

vicdoval commented Jan 2, 2021

Thanks @portnov. You were right the key was in the examples, they broke with the socket renaming.
Btw the error in the bl_idname of trim_and_tesselate is still there

@vicdoval
Copy link
Collaborator Author

vicdoval commented Jan 7, 2021

Custom Normals
image
Edges channel
image

@Durman
Copy link
Collaborator

Durman commented Jan 8, 2021

Also if you are interesting in adding new stuff in the node it could be useful to make the node dealing with UW mappings.

@vicdoval
Copy link
Collaborator Author

vicdoval commented Jan 8, 2021

With "As is" in Coordinates it does UV mapping but for -0.5 to 0.5
image

@vicdoval vicdoval merged commit ec2f028 into nortikin:master Jan 9, 2021
@enzyme69
Copy link
Collaborator

@Durman Do you have the building example Blend with adaptive polygon? I am curious about the building and the logic.

@Durman
Copy link
Collaborator

Durman commented Jan 15, 2021

This file I used in this some sort of a tutorial.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants