Simply Maya User Community

Simply Maya User Community (https://simplymaya.com/forum/index.php)
-   Programming (https://simplymaya.com/forum/forumdisplay.php?f=32)
-   -   closestPointOnMesh node (https://simplymaya.com/forum/showthread.php?t=31256)

bendingiscool 31-10-2008 01:19 AM

closestPointOnMesh node
 
Hi, I'm having problems with the closest/nearestPointOnMesh (depending on Maya version). I want to collect the nearest face on the mesh to the locator. This is because I want to eventually be able to draw a curve on the surface and select the faces the curve goes over. The node returns a seemingly random 'closestFaceIndex' number, that is nowhere near the locator's posiiton. Below is what I have at mo...


// create closestPointOnMesh node
string $closestPoint = eval("createNode closestPointOnMesh -n cpom1");

//connect it to the polymesh
connectAttr -f pPlane1.outMesh ($closestPoint + ".inMesh");

//connect locator1 pos' to closestPointOnMesh pos'
connectAttr -f locator1.translateX cpom1.inPositionX;
connectAttr -f locator1.translateY cpom1.inPositionY;
connectAttr -f locator1.translateZ cpom1.inPositionZ;

//store face index
int $selectedFaces = `getAttr cpom1.closestFaceIndex`;


Has anyone had anyluck with this node, am I going about this the wrong way?

Any help/advice/suggestions would be very welcome

Many thanks,

Chris

bendingiscool 31-10-2008 11:11 PM

OK I have this so far, it loops through creating a locator in a random pos (for test purposes), then it makes a new 'nearestPointOnMesh' node each time and an int to grab the value of the 'faceIndex'.

Unfortunatly it seems to be averaging out the position and selecting the face in the middle of the locators, rather than grabbing each face as it goes through. Does anyone know what I'm doing wroung here?


for ($i=1;$i<5;$i++){
spaceLocator -p (rand(-10,10)) 0 (rand(-10,10)) -n ("locator" + $i);

string $nearestPoint = `createNode nearestPointOnMesh -n ("npom" + $i)`;

//connect it to the polymesh
connectAttr -f pPlane1.worldMesh ($nearestPoint + ".inMesh");

//connect locator1 pos' to nearestPointOnMesh pos'
connectAttr -f (("locator" + $i) + ".translateX") (("npom" + $i) + ".inPositionX");
connectAttr -f (("locator" + $i) + ".translateY") (("npom" + $i) + ".inPositionY");
connectAttr -f (("locator" + $i) + ".translateZ") (("npom" + $i) + ".inPositionZ");

//store face index
int $selFaces = `getAttr (("npom" + $i) + ".nearestFaceIndex")`;

select -add pPlane1.f[$selFaces];
}


Any input would be greatly apreciated,

Chris

bendingiscool 01-11-2008 03:19 AM

Hey, getting closer!

I have revised the latest piece of code on the locator's movement.

When the loop is done it now selects the end one so it's getting there, now instead of just selecting the end one how would I go about keeping each faceIndex selected, or at least put in an array, so I can select the array once the loop has finished.

I promise to stop with the annoying questions, for a little while at least ; ) , if I can get this to work lol.

for ($i=1;$i<5;$i++){
spaceLocator -n ("locator" + $i);
move (rand(-10,10)) 0 (rand(-10,10));

// create nearestPointOnMesh node
//string $nearestPoint = eval("createNode nearestPointOnMesh -n npom1");

string $nearestPoint = `createNode nearestPointOnMesh -n ("npom" + $i)`;

//connect it to the polymesh
connectAttr -f pPlane1.worldMesh ($nearestPoint + ".inMesh");

//connect locator1 pos' to nearestPointOnMesh pos'
connectAttr -f (("locator" + $i) + ".translateX") (("npom" + $i) + ".inPositionX");
connectAttr -f (("locator" + $i) + ".translateY") (("npom" + $i) + ".inPositionY");
connectAttr -f (("locator" + $i) + ".translateZ") (("npom" + $i) + ".inPositionZ");

//store face index
int $selFaces = `getAttr (("npom" + $i) + ".nearestFaceIndex")`;

select -add pPlane1.f[$selFaces];
}

Many thanks,

Chris


All times are GMT. The time now is 03:24 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Simply Maya 2018