Emit particles based on an objects speed?

Discussion about scripting with Python
vectorhead
Posts: 385
Joined: Tue Oct 17, 2006 5:54 am

Emit particles based on an objects speed?

Postby vectorhead » Thu Jul 10, 2008 4:49 pm

Hello,

I would like to try emitting particles based on a n objects speed, I don't know where to start. It would be cool also if the particles followed the object too. Does any have an idea how this could be done?


vectorhead
Posts: 385
Joined: Tue Oct 17, 2006 5:54 am

Emit particles based on an objects speed?

Postby vectorhead » Thu Jul 10, 2008 8:39 pm

Basically I have an animated object from my 3d package, and I would like to transfer the velocity information on to something like a circle emitter. So when the objects speed is faster the speed of particles are faster. Would it be possible to do something like parent a locator to the object and get velocity from that, and transfer that info to the circle emitter?

Thanks if any one can help!

lukeiamyourfather
Posts: 2880
Joined: Mon Oct 15, 2007 4:09 pm
Contact:

Emit particles based on an objects speed?

Postby lukeiamyourfather » Thu Jul 10, 2008 8:47 pm

vectorhead wrote: Basically I have an animated object from my 3d package, and I would like to transfer the velocity information on to something like a circle emitter. So when the objects speed is faster the speed of particles are faster. Would it be possible to do something like parent a locator to the object and get velocity from that, and transfer that info to the circle emitter?

Thanks if any one can help!

Yes this is possible. Something like this:

Code: Select all

#Get the object and velocity of object
myObject = scene.getObject('Cube01')
objVel = myObject.getVelocity()

#Convert the vector velocity into a number
objVelMod = objVel.module()

#Adjust the velocity as necessary
adjustFactor = .5
objVelMod = objVelMod * adjustFactor

#Set the speed of the emitter based off the speed of the object
myEmitter = scene.getEmitter('Circle01')
myEmitter.setParameter('Speed', objVelMod)

I would use this per step of the simulation in an event script. It will probably take more code than that to tweak and get just right, but its a start. The same could be done for different parts of an object based on velocity from vertices or faces. Cheers!

vectorhead
Posts: 385
Joined: Tue Oct 17, 2006 5:54 am

Emit particles based on an objects speed?

Postby vectorhead » Thu Jul 10, 2008 9:18 pm

myObject = scene.getObject('Cube01')
objVel = myObject.getVelocity()
objVelMod = objVel.module()

adjustFactor = .5
objVelMod = objVelMod * adjustFactor

myEmitter = scene.getEmitter('Circle01')
myEmitter.setParameter('Speed', objVelMod)

Thanks Luke,

I was unable to get that script to work It is having problems with the sec line:


def onSimulationStep():

myObject = scene.getObject('pSphere1')
objVel = myObject.getVelocity()
objVelMod = objVel.module()

adjustFactor = .5
objVelMod = objVelMod * adjustFactor

myEmitter = scene.getEmitter('Circle01')
myEmitter.setParameter('Speed', objVelMod)

Is this because this is imported animation?

lukeiamyourfather
Posts: 2880
Joined: Mon Oct 15, 2007 4:09 pm
Contact:

Emit particles based on an objects speed?

Postby lukeiamyourfather » Thu Jul 10, 2008 9:28 pm

It should work for animated objects as well as simulated objects. As long as the object is active in the node parameters. Is everything tabbed over? Since the onSimulationStep() is a function, the lines following it must be tabbed over inside of it. Python uses tabs and indentation to control flow.

What does the error message say?

lukeiamyourfather
Posts: 2880
Joined: Mon Oct 15, 2007 4:09 pm
Contact:

Emit particles based on an objects speed?

Postby lukeiamyourfather » Thu Jul 10, 2008 9:32 pm

I did a quick test with an animated cube and it worked. This is what I used to test it:

Code: Select all

#--------------------------------------------------
# Function: onSimulationBegin
#--------------------------------------------------

def onSimulationBegin():
   pass




#--------------------------------------------------
# Function: onSimulationStep
#--------------------------------------------------

def onSimulationStep():
   #Get the object and velocity of object
   myObject = scene.getObject('Cube01')
   objVel = myObject.getVelocity()
   
   #Convert the vector velocity into a number
   objVelMod = objVel.module()
   
   scene.message('Object speed is ' + str(objVelMod))
   
   #Adjust the velocity as necessary
   #adjustFactor = .5
   #objVelMod = objVelMod * adjustFactor
   
   #Set the speed of the emitter based off the speed of the object
   #myEmitter = scene.getEmitter('Circle01')
   #myEmitter.setParameter('Speed', objVelMod)



#--------------------------------------------------
# Function: onSimulationFrame
#--------------------------------------------------

def onSimulationFrame():
   pass




#--------------------------------------------------
# Function: onSimulationEnd
#--------------------------------------------------

def onSimulationEnd():
   pass




#--------------------------------------------------
# Function: onChangeToFrame
#--------------------------------------------------

def onChangeToFrame():
   pass

If the origin doesn't move with the object like some do with SD files, then you'll need to use a vertex on the object or a face to find out the real velocity of the object. Cheers!

vectorhead
Posts: 385
Joined: Tue Oct 17, 2006 5:54 am

Emit particles based on an objects speed?

Postby vectorhead » Fri Jul 11, 2008 1:05 am

Thanks Luke!

I will check it out!

Gregg Glezakos
Posts: 15
Joined: Thu Oct 22, 2009 7:15 pm

Re: Emit particles based on an objects speed?

Postby Gregg Glezakos » Fri Jan 15, 2016 8:43 am

lukeiamyourfather wrote:I did a quick test with an animated cube and it worked. This is what I used to test it:

Code: Select all

#--------------------------------------------------
# Function: onSimulationBegin
#--------------------------------------------------

def onSimulationBegin():
   pass




#--------------------------------------------------
# Function: onSimulationStep
#--------------------------------------------------

def onSimulationStep():
   #Get the object and velocity of object
   myObject = scene.getObject('Cube01')
   objVel = myObject.getVelocity()
   
   #Convert the vector velocity into a number
   objVelMod = objVel.module()
   
   scene.message('Object speed is ' + str(objVelMod))
   
   #Adjust the velocity as necessary
   #adjustFactor = .5
   #objVelMod = objVelMod * adjustFactor
   
   #Set the speed of the emitter based off the speed of the object
   #myEmitter = scene.getEmitter('Circle01')
   #myEmitter.setParameter('Speed', objVelMod)



#--------------------------------------------------
# Function: onSimulationFrame
#--------------------------------------------------

def onSimulationFrame():
   pass




#--------------------------------------------------
# Function: onSimulationEnd
#--------------------------------------------------

def onSimulationEnd():
   pass




#--------------------------------------------------
# Function: onChangeToFrame
#--------------------------------------------------

def onChangeToFrame():
   pass

If the origin doesn't move with the object like some do with SD files, then you'll need to use a vertex on the object or a face to find out the real velocity of the object. Cheers!





I have a character moving around, but as this is coming from a cached animation in an .sd file, the origin doesn't move; only the vertices/faces.
How can i read the speed of those vertices/faces that i want to emit particles from?

Also, is there a way to modulate the emitter's speed, so the emitter starts spitting particles after the object's speed is above a certain value?
For example, if the vertices/faces move with a speed lower than 2, then no particles should be emitted, but if the speed is above 2, then particles start emitted with a value of 2 + the velocity of those vertices/faces.

Thanks in advance...
Greg


Return to “Python-Scripting”

Who is online

Users browsing this forum: No registered users and 1 guest