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 03-05-2003 05:57 PM

EXPRESSIONS FOR ALL! (knowledge tidbits)
 
Sorry to break-in mind-raper, but I'm making this thread STICKY so it will always be at the top for everyone to learn from!

Post your particle/dynamics EXPRESSIONS here for everyone to learn from!

Please write a little "how-to" along with your expression, so we will all know how to try it, and experiment with applying it to our dynamics/particle scenes!

Thanks all!:beer:


THREAD STARTS HERE first post by mind_raper
here's a little nice expression to .. colorize you particles system,
i have learnd it from gnomon workshop well its really good & ...
is very simply

first from general options add per particle attribute
the rightclick---> write creation expression::

take ur your are particle shape node (particleShape1) and add per particle attiribute (rgbPP)
and then assign a random value b/w (minVector i.e <<.3,5,7>>) and (maxVector i.e <<.5,7,1>>).

select the render type streaks or multi-streaks or what ever u want check on the color Accum button and the lightining button too

play around the values to see different color effects...


particleShape1.rgbPP = rand(<<.3,5,7>>,<<.5,7,1>>);



hope u find it usefull
enjoy - -> :banana:

ragecgi 03-05-2003 06:25 PM

Thanks mind-raper!

I think everyone should know the power of using expressions with particle systems, and your post will help others "EXPERIMENT" and learn, rather than be affraid, or overwhelmed.

Good job m8!

ragecgi 03-05-2003 06:44 PM

Here is a little expression tidbit from me to help this thread along:

TO RANDOMIZE STUFF: selectedObjectname.tx = rand(-10,10);

"tx", or whatever, is the attribute you can choose to have the expression applied to.

So, for random particle ROTATION:

selectedObjectname.rotX = rand(0,360);
selectedObjectname.roty = rand(0,360);
selectedObjectname.rotz = rand(0,360);

Try this as a CREATION expression, AND then try it as a RUNTIME expression to see the difference between these calculation types:)

mind_raper 08-05-2003 06:07 PM

Speed, Stuff
 
i think that was difficult...
well no prb....

tell u one thing....they are very easy just u need little bit of understanding......here's one more example from maya's documentation!
moving the particles.....

Use the Particle Tool to place a collection of particles in the workspace. You then create the following creation expression to control their velocity:

particleShape1.velocity = <<0,1,0>>;

All the particles move in a Y-axis direction at one grid unit per second as the animation plays.

explaination

"particleShape1" is the shape node for ur particle object that can be anything that u have named

"velocity" is the attirbute for shape node.

"<<0,1,0>>" is the value for X, Y, Z Respectivly
try to change the values and make it more dynamic with coditional statments

like if frame==something
move in X direction

or the way u wanted.


hope this works for u ....!

enjoy coding...! :beer:

mind_raper 20-05-2003 08:04 AM

Kill particles a few moments after they reach a specified locator
 
create an emitter and a locator and create another locator
first select the particle and shift select the 1st locator
goto --- > Particles -- > goals--option reset the setting
and press ok
do the same with other locator
Animate the particle from one locator to another using Goalweight attribute

then add the following script and see the magic of expressions
thanks for the cool expression
<< Daniele Tosti >>

<b>
vector $partPos = particleShape1.position;
if ($partPos > locatorName.ty)
{
particleShape1.lifespanPP = rand (5);
}
else
{
particleShape1.lifespanPP = 5 ;
}</b>

enjoy coding :beer:
:banana:

mind_raper 02-07-2003 01:40 PM

Attribute of an object at a certain
 
This expression will take the attribute of an object at a certain “offset” time, and apply it to another objects attribute. For instance it will take it off a cubes translateZ attribute, and assign it to a spheres translateZ attribute.

-Create a new scene.

-Create a polyCube.

-Create a polySphere.

-Translate the sphere about 10 units in Y.

-Open the Expressions editor, then Select Filter/By Expression Name.

-Type in the following:

int $offset = 10;
int $currentTime = `currentTime -q`;
$offsetTime = $currentTime - $offset;
$cube1Zpos = `getAttr -t $offsetTime pCube1.tz`;
pSphere1.translateZ = $cube1Zpos;

-Hit Create.

and here is the explaination !


//Time offset expression
//offset length (in frames)
int $offset = 10;


//Get current time
int $currentTime = `currentTime -q`;


//Substract the offset to the current time
//so if current time is 10,
//and offset is 2, offsetTime will be 8
$offsetTime = $currentTime - $offset;


//Get the value of pCube1.translateZ
//at frame $offsetTime (8 in our example)
$cube1Zpos = `getAttr -t $offsetTime pCube1.tz`;


//Assign it to pSphere1.translateZ
pSphere1.translateZ = $cube1Zpos;

This could be taken much further, you could for example setup joints and IK so it looks like power tubes are going from the mothership to the children, you could also add a custom attribute called “motion” and multiply the “noise” section of the expression by it, so that if you decide to turn you noisy motion off you would just have to set the custom attribute to 0. You could keyframe that attribute so you could control the random “floating” motion of the ship throughout the scene so it stops looking as if it were floating if it lands for example.

This type of setup could also be applied to a cranefly, or any other type of futuristic flying object etc. Experiment with setting all sorts of different relationships etc until you are comfortable with this expression.


this is very handy little snippet from
Oliver Shyal Beardsley
thanks alot for .......it

hope you enjoy it...........

schmick 03-07-2003 03:06 AM

Nice thread here, i know i'll be learning from it, just hope it sticks :D

brian_ellebracht 03-07-2003 12:06 PM

Wow nice thread :) THis is a really good idea
brian

ragecgi 03-07-2003 02:38 PM

It can only get bigger:)

mind_raper 04-07-2003 08:14 AM

yes absolutly !
Cause expression makes ur animation look more healthy and realistic
support is all needed...!

kbrown 04-07-2003 08:35 AM

Here's a little tip. If you use the seed() function you can be sure your expression with rand() functions run always the same way.

Code:

{
        seed(1234);

        float $foo = rand(-5, 5);
}

The $foo will contain a random value, but it is allways the same in a given frame...

ragecgi 04-07-2003 04:03 PM

Cool K!!

mind_raper 06-07-2003 06:31 PM

Removing linear breaks
 
Moving a turbulance field with object the problem is..
noise patterens move slong with it
if u we want remove linear breaks
we use turbulance phase attribute

let say you....want to move a turbulance field...through particles and want to....
effect its nearest as u know turbulance field is not good at moving, thats why to aviod that we use phase as per need


Example script :


turbulance field.phaseX = times * 4;

play wid it....
it really handy in particle system..!

enjoying coding..!

ragecgi 06-07-2003 11:12 PM

Rock on m8!

mind_raper 16-07-2003 12:11 PM

Some Handly Little Expressions
 
Rotating Wheels of Car or anything

Wheels on a car: apply to the wheel rotate in z channel
wheel.rz=car.tx/(2*3.145) * 1*360;

Wind shield wipers

Windshield wipers: apply to the wiper rotate in x channel
wiper.rx = (sin (.9 *time)*45)+10;
wiper = wiper
sine = sine
speed = how much fast you want() here i have put .9
time = time
degree = i put (45)
offset for position i put (10)


Random

Imbedded Sin Waves for a Random Effect
ty = sin (sin (.5 * time) * time);


enjoy ~ !

ragecgi 19-07-2003 07:52 AM

Thanks again mind-raper!

..and to post another variant for randomly-created particle attributes per a request in the MATRIX BULLET TRAIL thread
on how to get emitted particle instances (or even just particles)
to emit at random scale values:

Quote:

Originally posted by Rage:

Try this in a creation expression:

NOTE: you MUST add a radiusPP attribute to your particleShape, and apply this expression to that for this to work as you intend:)

The BOLD one is the one to use first, as it is what you asked for.
The rest are variants to try for fun:)

particleShape1.radiusPP = rand(.5,1)

OR

particleShape1.radiusPP = sin(time)

OR

particleShape1.radiusPP = sin(age)

mind_raper 25-08-2003 08:29 AM

Controlling speed for instanced Object
 
when you have instanced an object to particle specially a moving geometry its sometime very difficult to handle cause sometime movement of particles is higher than your instanced object or the other way your object speed is higher then particles(e.g you have created a crown moving through the scene and when you have instanced it to particle they are moving (sliding). there are other manual ways to fix it but i will show you how to do it with expressions, And For this we use a matching script with it you can query how much fast is....particle/object is moving and then according to it you can plug that value into your instanced object/Particles.

A real good way while you are using instanced Geometry, is to use Custom Attributes and then write the expression on the custom attribute and then plug that custom attribute into your instanced geometry.

for a situation where let say you have (crowd) walking animation
you instanced it with particles first you instance like you do normally with basic cautions thats you take before instancing any geometry

create custom attibute from Particle Attribute

goto

ADD DYNAMIC ATTRIBUTE
and add a attribute with you desired setting

customAge
float and Per Particle Array

you will see a new attribute in per particle array attributes named customAge

we'll write a custom expression as follow:-

float $Speed = mag(particle2Shape.velocity);
particleShape1.customAge = particleShape1.age * $Speed /10 (this number can differ as per your need you have to keep playing untill your object is no longer sliding !) ;


mag is for Magnitude ! see documentation for it !

if you are not getting a very good try low down da lifespan of the particle through the scene

hope it helps

enjoy instancing
:bannana:

ragecgi 25-08-2003 02:28 PM

Rock on m8! That's a keeper!

Alan 25-08-2003 10:24 PM

this one selects a random element from an array

proc int selectRandArrayVal(string $arr[])

{
int $randomInt = floor(rand(size($arr)))+1;
return $randomInt ;
}

:)

Cool thread btw

Alan

PixelPost 09-09-2003 09:54 AM

Hehe, I think mind_raper is raping all the gnomon video expressions

mind_raper 09-09-2003 10:19 AM

Hummmm
 
lolz
yeah..........
Cause not everyOne has the material so i think.....its helpfull ...!
but offcourse not all of them.....the are from different authors they are also mentioned !

PixelPost 09-09-2003 10:35 AM

its all cool

ragecgi 09-09-2003 04:45 PM

Either way, an expression is an expression, so keep em coming guys! :)

kbrown 11-09-2003 07:26 PM

Ok here's one which I just figured out.

Driving a shader attribute with distance from camera

Let's dig in to this with an example:

1. Create a lambert shader
2. Create a ramp texture (delete the place2dTexture node if it is created)
3. Connect the ramp's output to the lambert's color channel
4. Create a sampler info node
5. Create an expression with following code:
Code:

// NOTE: I'm using default object names here

vector $vPw = << samplerInfo1.pointWorldX, samplerInfo1.pointWorldY, samplerInfo1.pointWorldZ >>;
vector $vCamPos = << persp.translateX, persp.translateY, persp.translateZ >>;

float $fDistance = mag($vPw - $vCamPos);

ramp1.vCoord = $fDistance / 50; // The divider (50) is acting like a max distance value. You may need to adjust it depending on your scene size.

To test this, create a nurbs plane. Scale it in X and Z by 20. Apply the new lambert shader to it and render from different angles. You should see that the plane is red at near distance, green in the middle and blue in far distance. If you get repeats and banding then you need to adjust the divider in the expression.

ragecgi 11-09-2003 09:14 PM

WOW! Kinda like the Yuya Depth shader, only better!

Good one Kman!

kbrown 13-09-2003 09:58 PM

I just figured out that controlling things based on the distance from camera is really usefull. For example HW particles (mainly points and streaks) are sized in pixels. So no matter how far they are, they will be (HW) rendered the same size -> not exactly realistic looking. If you add a runtime expression which scales the opacityPP based on the distance from the current camera it will look a lot better.

Example:
Code:

vector $vPPos = lpos; // last position of the particle
vector $vCPos = << persp.tx, persp.ty, persp.tz >>; // current camera position
float $fDistance = mag($vPPos - $vCPos) / 20; // particle's distance from camera (scaled to be in range of 0 - 1)
opacityPP = 1.2 - $fDistance; // the opacity will be at least 0.2 but degrades when the distance increases from the cam

Again you need to play with the divider (20) to scale the opacity reduction to fit the size of your scene. The "1.2" on the last line determines the overall opacity level of all particles (you want to keep this greater than 1.0)...

ragecgi 14-09-2003 05:10 AM

And with this expression, who says a lot of rain spoils a shot?

Good one again Kman!

mind_raper 14-09-2003 01:56 PM

yeah that helps in densed(populated) particles scene where it need lots of camera adjustment will cut down lots of time !

tathu 06-01-2004 05:45 AM

I don't care from where they come here
 
Hi.

Cool thread !
I'm new here and I'd learned alot from these expressions.
I don't care from where they come here, all of them are good for me. Thank mind_raper and everyone.

Why the thread had stoped ?

Sorry about my poor English.

ragecgi 06-01-2004 04:56 PM

Hasn't really stopped, just slowed down a bit because folks are a little busy.
It is a "sticky" thread so that way it is always at the top for reference:)

Feel free to post any questions, and we will see if we can help:)

mind_raper 23-01-2004 06:05 PM

Creating runway lighiting effects
 
Well its time for a cool Particle function guys...!


A linstep function is used in conjunction with a ramp to control the rgbPP attribute of the particles color. The particles appear to "turn on" sequentially from front to back. An offset is added to the particle's age to create this effect.






creation expression:

$pos=particleShape1.position;

particleShape1.lightOffset= ($pos.z+20);


--------------------


Runtime expression:


$myAge=particleShape1.age-(particleShape1.lightOffset*.25);

particleShape1.rgbVPP=linstep (2,3,$myAge);


enjoying...!

tathu 27-01-2004 07:12 AM

Quote:

Originally posted by ragecgi
Hasn't really stopped, just slowed down a bit because folks are a little busy.
It is a "sticky" thread so that way it is always at the top for reference:)

Feel free to post any questions, and we will see if we can help:)

:confused: I don't know how to create footprints on the ground.

If you have an expression for it ...

I love the thread.

tathu

ragecgi 27-01-2004 05:12 PM

I personaly would use blendshapes for that, but in combination with that, you might also wanna try doing it with SetDriven Keys as well maybe.

I think Mike Mckinley or even Danny Ngan know of a way to do this, so they might be better people to ask:)

Thanks! Good luck!

tathu 28-01-2004 06:23 AM

Thanks for your response so fast, and sorry if I do harass the thread.
:(

ragecgi 28-01-2004 03:38 PM

No prob!

mind_raper 29-01-2004 08:20 AM

well if u still want to use expression then u can ......program ur geometry e.g

like:

if (your foot touches ground )
the ground should effect;

else if (if its leaving the surface)
the ground should effect;



i think u'll not be able to ...produce realistic effects with only expressions
like Rage said blendshape could help....and i think that there will be an attribute that can be keyable and can be controlled through expressions...so...give a try...u know...expression makes your scene clean from raw data that take up extra..resourse cause they excute when conditions are met......

well will be putting....expression for same type of effect soon...which produces swells in softbodies....it will be helpfull to produce perfect result...for ur scene


enjoy ....

mind_raper 02-02-2004 07:43 PM

1 Attachment(s)
A noise function is used to control the Y position of a string of particles. Arithmetic operators are used to control the amplitude, frequency and offset of the function.




1. Create an emitter with as desired parameters......

2. Create Custom Attributes as follows

a. tornodoRadius
b. tornodoTwist
c. tornodoRadiusMult


now let code:

creation Expression

particleShape1.tornadoRadius=rand (.75,1.25);

particleShape1.toranadoTwist=rand (1,3);

particleShape1.position=<<1000,0,0>>;

****

Runtime Expression

vector $pos=particleShape1.position;

float $radius=particleShape1.tornadoRadius*particleShape 1.tornadoRadiusMult;
float $speed=time*particleShape1.toranadoTwist;
float $noise=noise((time*.3)+(particleShape1.particleId* .01));


particleShape1.position=<<($radius*(sin($speed+par ticleShape1.particleId)))+$noise
,$pos.y+.1,


($radius*(cos($speed+particleShape1.particleId)))+ $noise>>;

****

and third create a ramp on tornodoRadiusMult custom attribute this ramp will be used to control its hollowness from top or bottom.....

adding source file.........check it out...!

enjoying.......!


:beer:

dirack 10-02-2004 03:06 PM

hey guys, I've decided to join in the fun as well :D.

Let's see, for a spotlight, you attach the color to a water map, edit it as you like and then for the expression (for your new water1 texture):

water1.waveTime = time*0.2 and
water1.waveVelocity = (cos(time)+1)/2

If you put a nice fog to it, and color the water map right, you could have a cool spotlight for underwater (works very well with www.thegnomonworkshop.com 's fog light,) or the illusion of the sunlight going trough the leaves of trees when you move under them.

water1.waveTime = time*0.2 makes sure the wave texture 'moves' to the left ( because it's endless ), and
water1.waveVelocity = (cos(time)+1)/2 makes sure the number stays between the 0 and 1, so that when spotlighted, it increases and decreases, just as if waves take away some sunlight :). I hope I helped! :D:bgreen:

mind_raper 10-02-2004 03:27 PM

hey thats....good
 
this means we all are learning.....more n more..

dirack 10-02-2004 03:41 PM

Speak for yourself... the more expressions I seem to learn, the more I forget about the rest of the world :p :D :beer: :bgreen: It's just like :beer: , you learn to drink more and you forget more about the rest while doing that :D :beer:


All times are GMT. The time now is 10:35 PM.

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