How to emit particles from CV curve and control lifespanPP with a ramp?

55 views
Skip to first unread message

Eric Corriel

unread,
Jun 13, 2014, 1:47:26 AM6/13/14
to python_in...@googlegroups.com
Imagine there's:
  • curve1
  • particles1 emitted from curve1
  • black to white ramp1

I'd like to:
  • use a black to white ramp to control the lifespan of particles being emitted along a curve
  • by somehow mapping particle1.lifespanPP to ramp1.getValueAtPosition()
  • where the argument passed into getValueAtPosition() is the normalized value of where the particle was born on the curve (a float from 0 to 1, where 0 represents one end of the curve and 1 represents the other end)
So the two problems are: 
  1. Find, on a scale of 0 to 1, where a particle was born along the length of the curve
  2. Once that's found, how can I use the ramp as something like a lookup table to get a value to set particle1.lifespanPP?
Any help would be greatly appreciated.  If there's an easier way of doing this, I'm all ears.  Also greatly appreciated would be explaining this to me like I'm 5…Thanks!

Justin Israel

unread,
Jun 13, 2014, 5:39:19 PM6/13/14
to python_in...@googlegroups.com
Maybe something like this might help for the first part of the problem?
import maya.cmds as cmds
import maya.OpenMaya as om

# This point would refer to our particle birth location
point = om.MPoint(*cmds.xform(q=True, t=True, ws=True))

# Loading the curve, in case we didn't have it already
curve = om.MObject()
sel = om.MSelectionList()
om.MGlobal.getSelectionListByName("curveShape1", sel)
sel.getDependNode(0, curve)

curveFn = om.MFnNurbsCurve(curve)

# Have to use pointers to get double data
double1 = om.MScriptUtil(0.0)
double2 = om.MScriptUtil(0.0)
ptr1 = double1.asDoublePtr()
ptr2 = double2.asDoublePtr()

# Get the parameter range of the curve
curveFn.getKnotDomain(ptr1, ptr2)
start = double1.getDouble(ptr1)
end = double2.getDouble(ptr2)

# Get the parameter value for our point location
curveFn.getParamAtPoint(point, ptr1, 0.5)
param = double1.getDouble(ptr1)

# Normalize to 0-1
norm = param / (end-start)

This might get you the scaled value of the point on the curve?



--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/46b14d6f-4446-45a1-b484-0d5d2a108fee%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Eric Corriel

unread,
Jun 14, 2014, 3:10:13 AM6/14/14
to python_in...@googlegroups.com
@Justin: thx so much for the help!

Okay, so it's possible I may have gotten this to work, but won't really know until I start part 2…

After cutting and pasting your script I was getting the following error:
// Error: An execution error occurred in the creation expression for particleShape1. //
# Error: RuntimeError: (kInvalidParameter): value not in valid range #


Examining your script, there was one part that I didn't understand:
point = om.MPoint(*cmds.xform(q=True, t=True, ws=True))

How was "point" supposed to represent the just-born particle?  It seemed to me that xform needed to be passed a particular particle, like so:

point = om.MPoint(*cmds.xform('particle1.pt[particleId]', q=True, t=True, ws=True))
//see: http://mayaspiral.blogspot.com/2013/04/python-getting-particle-rgbpp-and-apply.html

After much googling I still couldn't figure out how to get the particleId via openMaya so I came up with a pretty ugly looking hack to pass it from MEL:

(Note: For now I'm doing all this from within the Expression Editor for particleShape1; which means that I wrapped each line of your script in python() commands and am executing it from within the Expression Editor.)


//get particleId via MEL
$pid
= particleShape1.particleId;

//pass MEL variable to python, see: http://forums.cgsociety.org/archive/index.php/t-696519.html
string $s = "pid = " + $pid;
string $sCMD = "python(\"" + $s + "\")";
eval($sCMD);

//create particleIdString for xform command
python
("particleIdStr=\"particle1.pt[\" + str(pid) + \"]\"");
python
("point = om.MPoint(*cmds.xform(particleIdStr, q=True, t=True, ws=True))");


And so far that seems to work!  The error went away and I'm getting normalized values for norm.  Next will be integrating the ramp…if you have any ideas about how to do that I'm all ears (or a more elegant way of doing what I did), otherwise I'll post back when I get it.  Thanks again–much appreciated!

Justin Israel

unread,
Jun 14, 2014, 3:35:15 AM6/14/14
to python_in...@googlegroups.com

Oh I hope I didn't mislead you too much on that. The part at the beginning was really a temp example solution to producing a point. I assumed you would be slotting in your own source for the particle birth location. Mine was just grabbing a point off a locator for test.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

Eric Corriel

unread,
Jun 14, 2014, 2:13:52 PM6/14/14
to python_in...@googlegroups.com
got'cha.  no worries, i needed to work with an existing particle system anyway.  thx!
Reply all
Reply to author
Forward
0 new messages