emit particles from colliding objects

Discussion about scripting with Python
nospitters
Posts: 10
Joined: Thu Jul 15, 2010 1:14 pm

emit particles from colliding objects

Postby nospitters » Wed Jan 17, 2018 7:53 pm

hi,
maybe some of you can help me out...
i have two objects that intersects each other. is it possible to emit particles from that "colliding/intersecting" positions?
i want to generate a splash from two colliding objects...
maybe graph? scripting?


User avatar
ChristianZ
Posts: 3338
Joined: Sat Sep 09, 2006 11:37 am
Location: CH

Re: emit particles from colliding objects

Postby ChristianZ » Wed Jan 17, 2018 8:37 pm

Hi

this is a classic job for an "event" script. I don't have much experience with scripting, but basically you want to obtain the collision points of the first object where the second object hits. This gives you a list of points. Then you need an additional emitter somewhere in the scene with speed set to zero. In the script make a loop through the list of collision points and create new particles with the properties of the emitter at these collision sites. It may be harder to emit so many particles that it looks like a splash. Might be faster to hand-animate an emitter and use keyframes.
RF10 standard + RFC4D, System specs: OSX 10.11, MacPro 4.1 2xXeon, GTX980Ti, 64 GB RAM

User avatar
tsn
Posts: 911
Joined: Fri Oct 27, 2006 10:36 am

Re: emit particles from colliding objects

Postby tsn » Thu Jan 18, 2018 7:37 am

Here's a very basic script to illustrate the concept - add it to the "StepsPre" section of the Simulation Flow events tree:

Code: Select all

collPoints = Sphere01.getCollisionPoints(scene.getObject("Cube01"))
for position in collPoints:
   DY_Domain01.addParticle(position, Vector.new(0,0,0))


Line 1 gets all collision points (= positions) from the interaction between Sphere01 and Cube01
Line 2 loops through these points/positions
Line 3 adds particles to the Dyverso domain DY_Domain01. This function requires a position and a velocity, which is 0 in this case.

Cheers,
Thomas

nospitters
Posts: 10
Joined: Thu Jul 15, 2010 1:14 pm

Re: emit particles from colliding objects

Postby nospitters » Thu Jan 18, 2018 5:54 pm

hi thomas,
thank you very much. this helps.
do you know if there is a function to get the normal vector of this collision points. i want to use this normal rotated by 90 degrees to give the particles this direction velocity...

nospitters
Posts: 10
Joined: Thu Jul 15, 2010 1:14 pm

Re: emit particles from colliding objects

Postby nospitters » Fri Jan 19, 2018 9:12 am

hi thomas,

just tried your code-snippet and it doesnt work. i get no particles at all...
do i miss something? tried also to make the objects passive rigid bodies...but also no particles are generated...
also with a scene.message(str(position)) within the for-loop i get no colliding debug values...
did your script work for you?

User avatar
tsn
Posts: 911
Joined: Fri Oct 27, 2006 10:36 am

Re: emit particles from colliding objects

Postby tsn » Fri Jan 19, 2018 9:27 am

do you know if there is a function to get the normal vector of this collision points.


Not directly, but via a detour. There's the following function for Dyverso particles:

[Vector, Vector, int, float] getNearestPointToObject( Vector, string )

Find the nearest point in the object to the particle in a specific direction. If direction is set to 0 then just the nearest point is found.
Arguments: 1) Direction which is normalized internally. 2) Object's name.

Return:
1) Nearest point 2) normal at the nearest point 3) index of the face and distance 4) None if no nearest point is found.

Here's some code that should work.

Code: Select all

velScale = 2.5

collPoints = Sphere01.getCollisionPoints(scene.getObject("Cube01"))
for point in collPoints:
   DY_Domain01.addParticle(point, Vector.new(0,0,0))

for particle in DY_Domain01.getParticles():
   results   = particle.getNearestPointToObject(particle.getPosition(), "Sphere01")

   if (len(results) > 1 and results[1] == True):      
      velDir    = results[1]
      velScaled = velDir.scale(velScale)

      particle.setVelocity(velScaled)

I've never used this function, but "result" contains vectors at least :D. You can also see that I've used "particle.getPosition()" as an argument. The description says that it's normalized internally and this gives you the required direction. When you scale it you get some "fake" velocity. It's not physically accurate, but should do it.

User avatar
tsn
Posts: 911
Joined: Fri Oct 27, 2006 10:36 am

Re: emit particles from colliding objects

Postby tsn » Fri Jan 19, 2018 11:59 am

did your script work for you?


Yes, it works. I guess your cube object doesn't have enough resolution. And I've put the script under StepsPre. You can use a batch script to subdivide the cube - that's what I did:

Code: Select all

Cube01.tesselate(0.02)


And if you need a sphere with more vertices:

Code: Select all

scene.addSphere(4) or scene.addSphere(5)

nospitters
Posts: 10
Joined: Thu Jul 15, 2010 1:14 pm

Re: emit particles from colliding objects

Postby nospitters » Fri Jan 19, 2018 4:53 pm

thank you soooo much.
i will try it as soon as i am back in the office...

User avatar
tsn
Posts: 911
Joined: Fri Oct 27, 2006 10:36 am

Re: emit particles from colliding objects

Postby tsn » Fri Jan 19, 2018 5:28 pm

Hey, you're welocme. Just one last thing on this line of code:

Code: Select all

   if (len(results) > 1 and results[1] == True): 


Instead of >1 it should be >0. It doesn't make too much difference (in fact none at all, since the second condition implies that there are either 4 or no entries in "results"), but I feel better when it's correct ;)

Forester
Posts: 105
Joined: Mon Mar 15, 2010 4:36 am
Contact:

Re: emit particles from colliding objects

Postby Forester » Fri Jan 19, 2018 10:17 pm

:D Oh Thomas, you are The MAN!

Very cool! We can all, every one of us, use this! :lol:
Windows 7 Pro 64 - Realflow 10.1.2.0162 (Nov 2017 patched) Standard Version


Return to “Python-Scripting”

Who is online

Users browsing this forum: No registered users and 1 guest