View Single Post
# 46 11-06-2004 , 08:09 PM
Registered User
Join Date: Nov 2002
Location: Pakistan
Posts: 57
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


Learn the Rules|Then|
Burn the Rules Book