PDA

View Full Version : ColorAtPoint's usage


likaihaha
04-08-2003, 03:13 AM
Does anyone here know how to use mel command "colorAtPoint "

here is what I found in oceanDynamicLocator.mel.
float $disp[] = `colorAtPoint -u $u -v $v $oceanShader`

but when I use it to query the color of other texture
the value in $disp[] are all 0.

I just want to get the exactly color according the UV coord.

any reply is welcome.

ThankS!!

likaihaha
04-08-2003, 08:50 AM
probleme resolved

type
" help colorAtPoint"
in the command line
and get the result
:bounce:

http://www.chinavfx.com/bbs/view.php?part=64&page=1&sort=&id=45873

Duncan
04-08-2003, 05:47 PM
The node documentation for colorAtPoint was accidentally omitted from maya4.5 here it is:


colorAtPoint


colorAtPoint [-output STRING] [-coordU DOUBLE] [-coordV DOUBLE] [-minU DOUBLE] [-minV DOUBLE] [-maxU DOUBLE] [-maxV DOUBLE] [-samplesU UINT] [-samplesV UINT] [SELECT... ]

Command is NOT Undoable, NOT Queryable, and NOT Editable


none


The colorAtPoint command is used to query textures or ocean shaders at passed in uv coordinates. (For ocean shaders uv is x and z in worldspace ). The return value is a floating point array whose size is determined by either the number of input uv arguments passed in and the the queried value. One can query alpha only, rgb only, or rgba values. The returned array is only single indexed, so if rgb is specified then the index for red values would be index * 3. Blue is index * 3 + 1, and green is index * 3 + 2. For rgba use a multiple of 4 instead of 3. For alpha only one can simply use the index. There are two basic argument formats that may be used: colorAtPoint -u 0 -v 0 -u .2 -v .1 etc.. for all points or colorAtPoint -mu 0 -mv 0 -xu 1 -xv 1 -su 10 -sv 10 // samples 100 points If one is sampling several points and they are all in a regular grid formation it is more efficient to call this routine with the latter method, which uses a min/max uv and number of samples, rather than a long argument list of uv coords.
return values (-o A or RGB or RGBA )
individual UV coordinates to sample (-u float -v float )
(numbers of calls to -u and -v must match)
uniform grid of points to sample (-su int -sv int)
(may not use this in combination with -u or -v)
bounds for sample grid (-mu float -mv float -xu float -xv float)


texture, color, alpha, uv, ocean, outColor, paramUV

= Flag can appear in Create mode of command = Flag can appear in Edit mode of command
= Flag can appear in Query mode of command = Flag can be used more than once in a command

-o/-output STRING Type of data to output: A = alpha only RGB = color only RGBA = color and alpha
-u/-coordU DOUBLE Input u coordinate to sample texture at.
-v/-coordV DOUBLE Input v coordinate to sample texture at.
-mu/-minU DOUBLE DEFAULT 0.0 Minimum u bounds to sample.
-mv/-minV DOUBLE DEFAULT 0.0 Minimum v bounds to sample.
-xu/-maxU DOUBLE DEFAULT 1.0 Maximum u bounds to sample.
-xv/-maxV DOUBLE DEFAULT 1.0 Maximum v bounds to sample.
-su/-samplesU UINT DEFAULT 1 The number of points to sample in the U dimension.
-sv/-samplesV UINT DEFAULT 1 The number of points to sample in the V dimension.



# The return value is the array of values determined by the number of
# coord flag uses or samplesU * samplesV. The default return value is alpha.
# If instead the return value is RGB there will be 3 times as many values returned,
# and if it is RGBA there will be 4 times as many values.
createNode checker
colorAtPoint checker1
# returns the alpha value at uv (0.0,0.0) for texture checker1
# The return array will have one entry corresponding to this alpha.
colorAtPoint -u .5 -v .5 checker1
# returns the alpha value at uv (0.5,0.5) for texture checker1
# The return array will have one entry corresponding to this alpha.
colorAtPoint -o RGB -u .5 -v .5 -u 0.0 -v 0.1 checker1
# returns the colors at uv (0.5,0.5) and (0.0, 0.01) for texture checker1
# The return array will have 6 values in the following order: RGBRGB
colorAtPoint -o RGB -u .5 -v .5 -u 0.0 -v 0.1 checker1
# returns the colors at uv (0.5,0.5) and (0.0, 0.01) for texture checker1
# The return array will have 6 values in the following order: RGBRGB
colorAtPoint -o A -su 11 -sv 6 checker1
# returns the alpha for 50 points in a uniform 11 by 6 grid mapped across
# uv (0.0, 0.0) to uv (1.0, 1.0) The 12th point would be the first point
# in the second row of samples where uv = (0.0, 0.2)
colorAtPoint -o A -su 3 -sv 3 -mu 0.3 -mv 0.3 -xu 0.4 -xv 0.4 checker1
# returns the alpha for 9 points in a uniform 3 by 3 grid mapped across
# uv (0.3, 0.3) to uv (0.4, 0.4) The 4th point would be the first point
# in the second row of samples where uv = (0.35, 0.3).


Duncan

likaihaha
04-09-2003, 02:07 AM
Oh! Great Thanks!!Duncan.
:bounce:
That's extactly what I want.
Could you tell me where did you get this?

I've searched the Help.and all over the maya floder.
But found nothing.

Duncan
04-09-2003, 05:32 PM
I wrote the command( as well as this doc) so it wasn't too hard for me to get.:) Sorry the doc did not make it into 4.5( an oversight on my part ).

Duncan

alexx
04-09-2003, 08:38 PM
*knockknock*

duncan.. i have a strange feeling that maya is about 200% more than we see if all your small hidden commands and features would be public :)
i well remember some paint fx commands

*you rock*

cheers

alexx

btw..
duncan is that brain guys who invented paint fx and fluid fx amongst others.. check out the alias homepage and there the fluids.. there he is :)

likaihaha
04-10-2003, 02:41 AM
That Duncan??!!The one who invent PFX? and Fuild effect?

OH MY GOD!!

I 've seen the Video.

Just can't believe Duncan replied me.

Great!!Thanks !!

:applause:

alesmav
04-15-2003, 05:56 PM
Hey Duncan.. How do you feed the value that is returned by colorAtPoint into a let's say translation atttribute of an object.

ALES

Duncan
04-15-2003, 06:19 PM
colorAtPoint is a command, not a node, and so you need to invoke it inside a mel script or expression. You could do something like:
float values[] = `colorAtPoint -u .2 -v .3 checker1`;
nurbsSphere1.ty = values[0];

If you have fluids, check out the way it is used in the expressions created when one does "add ocean surface locator".

Duncan

dbissell
04-10-2004, 05:24 PM
Hey all,

I know it's been about a year now since the original thread was posted. :)

I'd like to convert the UV coordinate returned by colorAtPoint into it's world space counter part. Is there a way to do this?


So, for example, on a character let's say we have a blue dot on it's shirt. I'd like to use colorAtPoint to find this blue dot and then take the UV coord found and make it into the worldspace coord... in essence finding where the dot is on the character in worldspace at any given time as the character moves.

Thanks for any help,
-Dan

ktpr
04-10-2004, 05:29 PM
If you're using polys use Xform. I think xform might even work on Subd uvs but I can't remember. You can also conver uvs to vertices (look up PolyConvert or poly/subdComponentConversion)

dbissell
04-10-2004, 05:39 PM
I don't see how xform can convert from a UV space coordinate to a worldspace. The flags that xform has are only for object or worldspace.

westiemad
04-10-2004, 07:23 PM
dan,
you may be able to cross over, by finding the dot with the colour at point command, then placing a locator at this position, then using the xform to query its world spapce, as although its sitting on the surface, it is still in space :)

AnDy

dbissell
04-11-2004, 02:04 PM
Hey Andy!

Unfortunatly, the colorAtPoint gives a UV coordinate. Even to place a locator I will need to know the corresponding world coordinate... I think? Unless you know something I don't. :)

The other aspect to all of this is that I'm using Polygons... they aren't as "friendly" as NURBS when it comes to doing this. I found a way to do this with NURBS as there is a way to get a world position from a UV... but I can't find a function that would work for POLYS.

Thanks for the feedback. I'm starting to think a plug-in needs to be made. :)

westiemad
04-11-2004, 02:09 PM
hey dan :),
I take it your account is locked on 3dbuzz, I sent u a pm... anyway.

Your right, I have only used a colorAtPoint for making spray on waves by sampling the foam colour and the alpha (for height). Its an interestin problem you have there mind, and one I would like to be able to script in the API, still gotta learn it all first. Maybe there is a slicker, "cheating" approach that can be taken? I'm unsure as to what you are trying to make, which is fair enough because you don't want to go telling everyone your ideas.

AnDy

Duncan
04-12-2004, 04:24 PM
If you are using a nurbs surface, then you can use pointOnSurface to get the world position at the uv point.
If it is a mesh, then there is a plugin for pointOnPoly or pointOnMesh somewhere you could download.


Duncan

dbissell
04-12-2004, 07:50 PM
Kptr, Westimad, Duncan, et al.

Thanks for the responces. I'll try to hunt down those plugins you mentioned Duncan. They sure would help solve the problem assuming they are not a commercial solution.

Thanks again,
-Dan

Nicool
04-12-2004, 08:16 PM
I have coded a little tool thx to the colorAtPoint function (thx Ducan). It may interest you ;)

http://ndhaussy.free.fr/temp/spreadArticle/mapSpreadDemo.jpg


/*

.oO mapSpread by Nicolas d'Haussy Oo.

This melScript spread randomly objects in 2D function to a texture map (has a photo taken from a plane).
Design the texture the way you want to spread your object. For instance : a forest crossed by a river.

.oO mapSpread parameters Oo.

objectToBeDuplicated : name of the object you want to spread (by giving the quotes "myTree").
objectsNb : number of object you want to spread.
map : texture map name (by giving the quotes "myTexture").
threshold : a value between 0 and 0.99 (Determines the contrast).
placingFactor : just so as to scale placement (let tweak).

.oO Notes Oo.

Example of use : type it in the command line "mapSpread("pSphere1", 250, "file1", 0.9, 30)" (after having sourcing this script).
Does not support layered texture directly. Convert it to file texture.
For Maya 4.5 and higher (reason : colorAtPoint function required).
USE OR MODIFY THIS SCRIPT AT YOUR OWN RISK - FOR NON-COMMERCIAL USE ONLY.

*/

global proc mapSpread (
string $objectToBeDuplicated,
int $objectsNb,
string $map,
float $threshold,
float $placingFactor
) {

// Start message
if (`exists colorAtPoint` != 1) { error "Cannot process because \"colorAtPoint\" MEL function does not exist.\n";}
if ($threshold > 1) { $threshold = 0.99; print("Threshold corrected to 0.99 (To prevent error).\n");}
print("\n\nProcessing started from the " + nodeType($map) + " texture called : \"" + $map + "\".\n");
waitCursor -state on;

int $objectsCount = 0;
while($objectsCount < $objectsNb) {

// Get random values for placement
float $randomU = `rand 0 1`;
float $randomV = `rand 0 1`;

// Analyse the map color at this point
float $alphaLevelAtPoint[] = `colorAtPoint -o A -u $randomU -v $randomV $map`;

// Check if the object can exist
if($alphaLevelAtPoint[0] >= $threshold) {

// An object can be created here. So place it.
float $x = $randomU*$placingFactor;
float $z = $randomV*$placingFactor;
string $duplicatedObject[] = `duplicate $objectToBeDuplicated`;
move $x 0 $z $duplicatedObject;

// Count one more object
$objectsCount++;
// print ("\t" + $objectsCount + " . " + $objectToBeDuplicated + " duplicated to (" + $x + ", " + $z + ").\n");
}
}

// End message
waitCursor -state off;
print("Process successful : " + $objectsCount + " objects placed.\n\n");
}

thematt
04-13-2004, 07:40 AM
Thanks for the responces. I'll try to hunt down those plugins you mentioned Duncan. They sure would help solve the problem assuming they are not a commercial solution.


yes there are on the bonus tool..you can find it on alias web site if you don't have it yet.

cheers

dbissell
04-13-2004, 09:49 AM
thematt,

Thank you so much! I didn't realize it was in the bonustools! closestPointOnMesh is exactly the node I need!

Thanks for saying where it is!
-Dan

thematt
04-14-2004, 10:39 AM
sure anytime :thumbsup:

good luck

CGTalk Moderation
01-14-2006, 08:00 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.