Find the colour at the closest point to a locator

So it’s a bit of an odd one, but I needed to be able to calculate the RGB value of the colour at certain points on the mesh, and at first this seemed a bit tricky, but using the cloestPointOnMesh node and the colorAtPoint command I was able to use a locator and easily connect it up to give me the result I needed, hopefully it will help you out too.

// Select mesh
$mesh = `ls -sl`;

// Select locator
$locator = `ls -sl`;

//Name of the texture
string $texture = "noise1";

//Calculates the position of the locator.
float $position[3] = `xform -worldSpace -query -translation $loc`;

//Calcualtes the closest point on the mesh to the locator.
float $uv [] = `closestPointOnMesh -ip $position[0] $position[1] $position[2] -q -u -v $mesh`;

//Calculates the RGB colour of the texture at the point
float $rgb [] = `colorAtPoint -o RGB -u $uv[0] -v $uv[1] $texture`;

2 thoughts on “Find the colour at the closest point to a locator”

  1. Hi there

    Is there now a colour at point node? I can’t see it in 2014. This just seems like Mel but you mention nodes which got me excited. Please let me know if there is one.
    Thanks

    Edd

    1. Hi Edd,

      Nope, you’re quite right, in my haste to post something I got confused, it’s still just a pipe-dream to have a colorAtPoint node, until then we have this mel script, or I found someone had written one over at cgtalk here. Not tested it myself though!

Leave a Reply

Your email address will not be published. Required fields are marked *