PDA

View Full Version : MEL help


BenKing
04-20-2010, 08:21 PM
Hi

I am failry new to MEL and i was wondering if anyone new of a way to load an image file and read specific pixel colours based on UV coordinates.

Thanks in advance for the help.

misterbk
05-08-2010, 09:47 PM
You will probably need to create and use a File Texture node for that. You can probably set the U and V inputs and then read the color. If you know the resolution of your image file or can retrieve that information at runtime, you just divide the pixel coordinates by the image size to get the equivalent U and V coordinates between 0 and 1.

I don't think MEL has good structure for storing an image, but if you really want to have the image within arrays in MEL and not make retrieval calls on this file texture node, you could write a procedure:

Please note this is pseudocode and not supposed to be valid MEL.

nodeToDelete = create a file texture node
myArray = create a 3D array to store colors in X[0->XRez], Y[0->YRez], and Color[R,G,B,A]
// i.e. Green channel at pixel 5,12 retrieved with myArrray[5][12][1].
delete the 2DPlacement node if it gets in the way (Or maybe you need it?)
setAttr nodeToDelete's filename
for(all pixels in X from X=0 to X=XResolution) {
for(all pixels in Y from Y=0 to Y=YResolution) {
Ucoord = X / XResolution;
Vcoord = Y / YResolution;
setAttr on nodeToDelete (or its 2D Placement?) to set U and V
gotColor = getAttr on nodeToDelete's outColor
myArray[X][Y][0] = gotColor[0]
myArray[X][Y][1] = gotColor[1]
myArray[X][Y][2] = gotColor[2]
myArray[X][Y][3] = gotColor[3]
(Maybe this works as myArray[X][Y] = gotColor?)
}
}

EJ
05-09-2010, 08:20 AM
Dude, take a look at the colorAtPoint command, it does exactly what you want.

misterbk
05-09-2010, 11:17 PM
Lol, there I go again, scripting things that already exist!

CGTalk Moderation
05-09-2010, 11:17 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.