Simply Maya User Community

Simply Maya User Community (https://simplymaya.com/forum/index.php)
-   Dynamics & Special Effects (https://simplymaya.com/forum/forumdisplay.php?f=33)
-   -   EXPRESSIONS FOR ALL! (knowledge tidbits) (https://simplymaya.com/forum/showthread.php?t=5601)

mind_raper 11-06-2004 08:09 PM

while i was searching for my answers, i found this very usefull information from a siggraph contents



Understanding colorAtPoint MEL Command:



One of the most visible and difficult aspects of water interaction is floating objects, such as particle foam and certain types of objects. Maya has a number of built-in tools to float boats and boat-like objects, tools such as addBuoy, addBoat, and addMotorBoat.

All these tools have one very important thing in common, they’re all based on the colorAtPoint MEL command, By mastering this function, we can expand Maya’s capabilities and use it to create custom tools and effects such as floating curves

or particles on the ocean shader.

colorAtPoint can sample any combination of colors (RGBA) on an Ocean shader (or other texture) at a given UV address. While this can be put to many uses, we are primarily concerned with retrieving the height of the waves and applying it to the Y position of objects and particles. Like most displacement maps in Maya, Ocean outAlpha is used to calculate the displacement height. Since the Ocean shader’s UVs are based on Worldspace (X 3, Z 4 in Maya Worldspace = U 3, V 4 in Ocean shader UV) we can directly convert any point’s Worldspace to ocean UV space and sample the Alpha to get the appropriate Y height of the waves.

colorAtPoint

use: -convert point (object) Worldspace to Ocean UV;

-sample Alpha at given UV address;

-use returned Alpha value as Y height of point (object);

floatSphere is ur object


//myFloat_expression
//float an object on the ocean surface
//translate XZ are free, Y is constrained to ocean
float $posu = floatSphere.translateX;
float $posv = floatSphere.translateZ;
float $posy[] = `colorAtPoint -o A -u $posu -v $posv oceanShader1`;
floatSphere.translateY = $posy[0];


Expression explained:

-o A : “A” samples the Alpha only. Other options are “RGB” and “RGBA”;

-u and –v : place input variable for the Worldspace point you wish to sample
(object’s position XZ you wish to float)

IMPORTANT: since colorAtPoint is a MEL command,
you have to use “`” (not single quote, the other one above TAB on your keyboard) on either end when in an expression. Also, you should use $variables for –u and –v since MEL can’t convert expression syntax such as “locator1.translateX” (MEL sees
this as a string only).

$locY[] : Since colorAtPoint returns a float Array, you can’t use it directly in translateY (requires a single float).
NOTE : When a MEL commands such as colorAtPoint is embedded in an expression, it does not update when names it refers to are changed. E.g. If “oceanShader1” were changed to “myOcean”, the expression would return an error. Since many Maya floating tools (createBoat…) generate expressions with embedded MEL, it is very dangerous to rename the floating object/locator’s transform, or the oceanShader after the tool is invoked. You would have to manually edit the MEL lines in the expression after such a name change.



hope it helps

mind_raper 14-06-2004 09:52 AM

well this script can help u float particles on ocean surface like a foam and can be manuplate as wake happens u see more control..over ur foam



//float particles on ocean surface (runtime)
//get ocean height at current particle position
vector $ppos = foam_particleShape.position;
float $pu = $ppos.x;
float $pv = $ppos.z;
float $cpoint[] = `colorAtPoint -u $pu -v $pv oceanShader1`;
//when particle position lower than ocean, stick to ocean
if($ppos.y <= $py)
foam_particleShape.position = <<$pu, $cpoint[0], $pv>>;


hope it helps !

GuardHom 19-08-2004 07:19 PM

WoW, Pretty Good expressions~

vivi3d 16-12-2004 04:52 AM

Pretty Good expressions~

ragecgi 18-12-2004 06:09 PM

Holy cow Mind-raper!!!! GREAT posts bud!!!

mind_raper 15-01-2005 05:46 PM

Emit More Particles as the emitter goes faster
 
here is the fairly advance trick you may find usefull ....Maya does not let u ...vary emission rates with velocity but this will allow such an effect


Create an Sphere and add expression to its Translation X attribute

tx = sin(time*3);

this will make the sphere oscillate back n forth along x smoothly

- with the ball selected, choose Surface emitter type, setting the rate (Particles/sec) to 2000
and turning to the speed of 0

- In the Particle1 attribute Editor, Turn in herit Factor to 1 under emission attributes

- Now, Under Lifespan Attributes, Select lifespanPP only. Go down to per particle (Array) attribute and right mouse click on lifespanPP and select runtime expression. Enter this expression:

$magv = mag(velocity);
if (rand(1)<linestep(0,1,$magv/3))
lifespanPP = 1
else
lifespanPP = 0



you are done....play with attribute for more finner result

this snippet was taken from Maya Killer tips book

hope it helps :)

ragecgi 15-01-2005 06:13 PM

ROCK ON!!!

Thanks again MR!!

Now im off to test this on a shot where I use an exahust emitter that needs to slow to a crawl when my aircraft stalls out, then picks up again on desent!!

You fail to surprise us all bud!

Thankd again!

joed8349 06-06-2006 11:29 PM

How to convert particles to geometry, not just instances
 
I am creating a background scene that needs to be filled with a bunch of rocks and other small things. I figured I could place particles on a live surface, and then use the Instancer (Replacement) tool to add geometry in place of each particle.

Is there anyway to then convert each instanced geometry into its own object/geometry?

I know there is a feature to convert paint effects into geometry, but I don't think there is a way to convert particles into geometry.

I cannot select the instanced geometry, only the instancer node in the Outliner.

Thank you to anyone that can help me out.

mirek03 07-06-2006 09:21 AM

wow, this is an increible thread, I know very little myself but just glacing through this stuff, it is great.

mind_raper 13-07-2006 12:32 PM

i guess there's an A.I plug for maya that give u more control over instanced geometry try googling for it, i really dont remmeber its offical web !!!!

mind_raper 13-07-2006 01:11 PM

Emit more with speed change
 
1 Attachment(s)
here's an example of playing with particles as the object changes the speed as mention'd above in detail ;)))





enjoy! particling ;)

:p

mirek03 13-07-2006 10:31 PM

a very beautiful effect. im just learning about particles now and that is one hell of a good look.

mirek03 25-11-2006 12:25 PM

hey this is simply maya, not 'my space' drop the porn, be a good boy!

RaginRob 22-05-2008 06:22 PM

how to make object-dependent collision effects
 
1 Attachment(s)
I was wondering if there's a way to make particles behave differently according to the object they collided with. After some hours of trial and error I found this solution:

Let's say you want to have particles raining down on two cubes. Particles that collide with cube 1 shall become red and bounce off the cube (and eventually collide with cube 2), cube 2 shall kill the particles once they collide with it.

- Create an emitter that lets the particles rain down (omni, gravity field)
- Create 2 (or more, it doesn't matter) poly cubes and place them under the emitter in a way that some particles collide with cube 1 and some with cube 2
- name the transform node (pcube1 not pcube1shape) to cube_A and the other one to cube_B
- Make the particles collide with both of them (Particles-->Make collide)
- Select the particleShape and add a per particle collisionGeometryIndex via Add Dynamics Attibutes-->General-->Particle-->collisionGeometryIndex
- Also add an rgbPP Attribute (Add Dynamics Attibutes-->Color-->Add per particle attribute)
- now create a runtime expression on the lifespanPP and rgbPP attribute:

Code:

    int $index = particleShape1.collisionGeometryIndex;
    if( $index != -1 )
    {
            string $geoC[] = `listConnections particleShape1.collisionGeometry[$index]`;
            string $shape[] = `listConnections ( $geoC[0] + ".localGeometry" )`;
           
            if ($shape[0] == "cube_A")
                    {
                    particleShape1.rgbPP = <<1,0,0>>;
                    }
            if ($shape[0] == "cube_B")
                    {
                    particleShape1.lifespanPP=0;
                    }
    }

Important: You have to set the lifespan mode to "lifespanPP only" under Attribute Editor --> particleShape1 --> Lifespan Attributes.

You can easily add more collision objects with different effects on the particles, I think a switch-case condition would be more elegant for that.

I attached a scene file with the stuff above, have fun!

David 14-09-2012 03:13 PM

It's normaly bad practice to bring a thread back to life but this one popped up on a Google search I just did and as it's still relevant I thought I'd bump it back up to the top.

If anyone has anything they would like to share would be great to see it.

I might even turn each expression into a tutorial with example then throw the lot out for free.

All the best
Dave


All times are GMT. The time now is 06:23 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Simply Maya 2018