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

Pulga physics modular (WIP) #3525

Merged
merged 26 commits into from
Oct 8, 2020
Merged

Conversation

vicdoval
Copy link
Collaborator

@vicdoval vicdoval commented Sep 10, 2020

Annotation 2020-09-06 101658
image

Annotation 2020-09-06 112750
untitled

New Features:

  • Force Chain Control
  • Use Vector Fields as a Vector Force
  • Timed Force (restrict force based on iteration number)
  • Align Force (flocking behaviour)
  • Pins can be fixed only in some axis
  • Angle Force: Resistance to change angles at edges or faces
  • Boundaries Force: Now simulation can happen inside a mesh, over a mesh surface, iside a solid, over a solid surface, over a plane....
  • Scipy + cython superfast collision system
  • Easier upgrade system...

@portnov
Copy link
Collaborator

portnov commented Sep 10, 2020

Yay! :)
Some questions & suggestions:

  • For "Force" socket type, as well as for SvVectorFieldSocket I suggest to add "internal property" as for SvVerticesSocket. Probably @Durman can suggest how to do this the best way :)
  • What about performance? Did you compare this to existing physics engines performance-wise?

@Durman
Copy link
Collaborator

Durman commented Sep 10, 2020

@portnov What type of property the socket should contain?

@vicdoval Can be useful: #3507 (comment)

@portnov
Copy link
Collaborator

portnov commented Sep 10, 2020

@Durman FloatVectorProperty, similar to VerticesSocket. I guess VerticesSocket having such "built-in property" is the reason why @vicdoval used VerticesSocket for the input in "Pulga Vector Force" node.

@Durman
Copy link
Collaborator

Durman commented Sep 10, 2020

The socket should look like this now:

class SvForceSocket(NodeSocket, SvSocketCommon):
    color = (int, int, int, int)
    default_property: FloatVectorProperty(default=(0, 0, 0), size=3, subtype='DISTANCE', update=process_from_socket)

    use_prop: BoolProperty(default=True)  # just in case if it should be True by default

    def draw_property(self, layout, prop_origin=None, prop_name='default_property'): ...
        # here you can draw what ever you like in socket layout
        # it is not mondatory
    def sv_init(self):
        sock = self.inputs.new('SvForceSocket', 'Name')
        sock.use_prop = True  # if it is not by default true
        scok.defaul_property = (1, 1, 1)  # in case if node should have another default value

@vicdoval
Copy link
Collaborator Author

I will look into the new refactored sockets classes :) Thanks for the reminder.

About performance... I think is pretty fast for a numpy engine (but i could not find any other) for hundreds of vertices is usually fine, self aware forces (self collision, self attraction and fit force) are the slowest, and if you use 10000 verts things start getting pretty slow afer some iterations...

In this scenario 729 verts and 2765 edges tool 0.55 seconds to run 400 iterations (0.001375 secs per iteration)
image
But if you add a self collision force jumps to 11 seconds... 0.0275 secs per iteration. I tried scipy kdtree but it was slower..

I'm sure it could be improved but is pretty usable in many cases

@vicdoval
Copy link
Collaborator Author

@Durman is it possible to define the description attribute of the default property?

@Durman
Copy link
Collaborator

Durman commented Sep 14, 2020

Yes, but this description will be shared among all users of the socket.

@vicdoval
Copy link
Collaborator Author

So is not possible to do it per socket (as with the regular props)? (i was trying with a SvStringsSocket)

@Durman
Copy link
Collaborator

Durman commented Sep 14, 2020

Property is like class variable only actual values can be different among class instances.

I had a look at animation nodes and it looks like sockets properties do not have any tooltips. Probably the properties are initialized in sockets.

@vicdoval
Copy link
Collaborator Author

Good news for performance: Cython is pip_instalable and cKDtree of scipy is super fast (up to 40x)

@portnov
Copy link
Collaborator

portnov commented Sep 21, 2020

@vicdoval Did you manage to overcome the necessity of messing with python's *.h files to install Cython?

@vicdoval
Copy link
Collaborator Author

not any file messing, only clicking on the pip install button and start to use cKDTree (that is 100 times faster than the regular KDTree in the same scenario with 26000 vertices)

@nortikin
Copy link
Owner

not any file messing, only clicking on the pip install button and start to use cKDTree (that is 100 times faster than the regular KDTree in the same scenario with 26000 vertices)

than adding to extra nodes deps?

@vicdoval
Copy link
Collaborator Author

Reminder: Don't trust numpy vectorize (creating my own for loop i got a 2x boost)

@portnov
Copy link
Collaborator

portnov commented Sep 23, 2020

Yeah, numpy.vectorize seems to be just a wrapper that creates a "vectorized" function by making a simple for-loop, it does not actually vectorize any computations. If you need performance, you have to actually write your function so that it processes many numbers at once.

@vicdoval
Copy link
Collaborator Author

Also if you have to create a array for every output number (for the vectorize method) is slower that creating the array first and fill it with the values

@vicdoval
Copy link
Collaborator Author

  • Angles force : preserve angles at edges
  • Boundaries: Mesh surface, mesh volume, Solid surface, solid volume and some other strategies to contain the simulation
  • Scipy + Cython collisions and attractions
    image

@vicdoval
Copy link
Collaborator Author

Has anybody experimented with the multiprocessing module in Sverchok? sounds pretty cool

@portnov
Copy link
Collaborator

portnov commented Sep 23, 2020

I did not, but I do not have too many hopes for it: Blender clearly expects all python scripts to be "sequential", so I expect a lot of concurrency problems / locks / wtfs. But worth a try.
Another sort of problem I would expect is that probably if you launch additional Python process, bpy and similar Blender-provided modules will not be available from there. Similar question about modules we install as dependencies. But again, I did not try, may be that's all just false fears.

@Durman
Copy link
Collaborator

Durman commented Sep 23, 2020

It looks like that I tried. I remember each process was launching new Blender.

@onerawartist
Copy link

How can i try the pulga nodes? I can't find them in the master branch
''ps: i know nothing about coding ^^, im just an artist who came here to see and try amazing nodes''
Thank you all for the amazing work 🙏

@vicdoval
Copy link
Collaborator Author

@onerawartist this is a work in progress so it is still not merged with the master. If you want to try it in its actual state (some things may change and there is not full documentation) you can get it from this branch https://github.com/vicdoval/sverchok/tree/pulga_physics_2

@vicdoval vicdoval merged commit 698e940 into nortikin:master Oct 8, 2020
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.

5 participants