Kill particles inside Object

Discussion about scripting with Python
shaun_michael
Posts: 4766
Joined: Sun Sep 10, 2006 8:04 am

Kill particles inside Object

Postby shaun_michael » Wed Jul 14, 2010 7:57 pm

Nice blog Albert.

Shaun


gileez
Posts: 1
Joined: Sun Jan 19, 2014 6:59 am

Re: Kill particles inside Object

Postby gileez » Sun Jan 19, 2014 8:44 am

Tried making this work in 2013:

1: the scene.getEmitter() function does not exist in 2013. you will need to use scene.get_PB_Emitter() (this took quite a while to realize)

2: when a particle gets too close to the kill geometry (from the outside) it is killed before impact. this means that the particles do not interact with it at all. i have changed the flag condition to be greater than -0.3 instead of greater than 0.0. essentially this means that the script will allow slight penetration but i find it preferable to killing the particles before impact. it seems that there is an offset in the dot product calculation. does any one have any idea why?

3: i have an issue with the whole concept. this could work great for a cube for example however in complex shapes you could quite easily be inside the geometry and still have the flag set by positive dot products (meaning normals that are pointing in the same direction as the v2pvect. a very simple example of this would be a ring. am i missing something?

quite surprised the software doesn't come with one such daemon. i could have used it on my last 3 projects.
Any help will be greatly appreciated!

here is the code i ran:

def onSimulationStep():
em =scene.get_PB_Emitter("Circle01")
obj = scene.getObject("Cube01")
vertlist = obj.getVertices()
particle = em.getFirstParticle()

while particle:
nextparticle = particle.getNextParticle()
flag = 1

for v in vertlist:
v2pvec = particle.getPosition() - v.getPosition()
vnorm = v.getNormal()
dotprod = vnorm * v2pvec
#scene.message("dot product of "+str(particle.getId())+ " is "+str(dotprod))

if dotprod > -0.3:
#scene.message("setting flag for "+str(particle.getId())+ " is "+str(dotprod))
flag = 0

if flag:
scene.message("Removing"+str(particle.getId()))
em.removeParticle(particle.getId())

particle = nextparticle

archi
Posts: 6
Joined: Fri Jun 15, 2012 12:27 pm

Re: Kill particles inside Object

Postby archi » Mon Sep 08, 2014 7:44 pm

anybody know how it work in RF 2014 ?
I tried to use the script but it doesn't work

I need the same like kVolume daemon but with an option to use object volume instead of container only

can anybody help with it
thanks

fkfx
Posts: 309
Joined: Wed Apr 11, 2012 11:11 am
Location: Cologne, Germany
Contact:

Re: Kill particles inside Object

Postby fkfx » Wed Sep 10, 2014 4:30 pm

I'd go for Script nodes, as they are a lot faster. Here is how I'd approach the problem (no time for testing right now, maybe tomorrow):

1. Sample object as Signed Distance Field (see description for nodes of type Field in order to be doing so)

2. This will create a volume out of your object. With that volume it is easy to determine if a particle's position is inside or outside that volume (if it is in that Field's nagative or positive area)

3. Delete if it is inside.

You will have to look at the docs a bit, but it shouldn't be too difficult. As I said, if I find some time, I might be looking into that, but I cannot promise.

archi
Posts: 6
Joined: Fri Jun 15, 2012 12:27 pm

Re: Kill particles inside Object

Postby archi » Wed Sep 10, 2014 8:52 pm

3. Delete if it is inside.
but can you explain more about this step
just how ? )

I'm a python noob
but It's strange
industry standard simulation software don't have something like kObject tool in-box (


Return to “Python-Scripting”

Who is online

Users browsing this forum: No registered users and 2 guests