PDA

View Full Version : equivalent to 'colorAtPoint' in the C++ API ?


paic
12-15-2005, 03:05 PM
Hi there,

I'm trying to port a .mel script into C++ and I'm currently trying to find if there is an equivalent to the 'colorAtPoint' MEL function in the API.
I hoped there would be something like 'MFnTexture' but I didn't find anything :/

Thanks in advance for any help ^^

Edit : forgot to mention : I don't want to use something like MGlobal::ExecuteCommand("colorAtPoint ..."); because I need this to be really fast (that's why I'm converting the .mel into a .mll)

.:: Paic Citron ::.

AndersEgleus
12-15-2005, 04:49 PM
I don't know very much about API programming, but if you look in the manual, under Developer Resources \ API Guide \ Writing a Shading Node \ Evaluating shading nodes outside of the rendering context, you may find something useful there. It also mentions a plugin, sampleCmd, which seems to be using the MRenderUtil::sampleShadingNetwork function to sample shading nodes.

paic
12-16-2005, 07:00 AM
Thx for the reply.
But what's in the documentation isn't what I want to do. And the MRenderUtil:: sampleShadingNetwork can't be used in my case :

Since setting up sampling is an expensive operation, try to pass in as many sample points at one time as possible

And I can only pass 1 point ... and a lot of time. So that would be too slow.

I did found the MImage class, but as the textures I use are already loaded into Maya, I hoped there was a way to quickly sample a texture node in the C++ API.

paic
12-16-2005, 10:05 AM
Ok, I finally used MImage :


// here I get the MImage object from the texture node name
// heightmap is a MString (the name of the texture node)
MImage heightMapImage;
MObject heightMapObj;
MSelectionList heightMapSelList;
MGlobal::getSelectionListByName(heightMap, heightMapSelList);
heightMapSelList.getDependNode(0, heightMapObj);
heightMapImage.readFromTextureNode(heightMapObj);

// then the following function is used to sample a pixel (only r channel)
float SamplePixel(unsigned char *pixels, unsigned int pixelStride, float u, float v, unsigned int width, unsigned int height)
{
unsigned int indexX = (int)floor(u * width);
unsigned int indexY = (int)floor(v * height);
unsigned char r = pixels[(indexX * pixelStride) + width * (indexY * pixelStride)];
return(float(r) / 255.0f);
}

// used like this :
unsigned int width, height;
unsigned int pixelStride = heightMapImage.depth();
unsigned char *pixels = heightMapImage.pixels;
heightMapImage.getSize(width, height);

SamplePixel(pixels, pixelStride, 0.4f, 0.3f, width, height);


The problem with that is that I need to implement texture wrapping / clamp / whatever, and also texture filtering in the SamplePixel() function :/ But at least it works fine / fast.

CGTalk Moderation
12-16-2005, 10:05 AM
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.