Introduction to Maya - Modeling Fundamentals Vol 2
This course will look in the fundamentals of modeling in Maya with an emphasis on creating good topology. It's aimed at people that have some modeling experience in Maya but are having trouble with complex objects.
# 1 31-10-2008 , 01:19 AM
bendingiscool's Avatar
Subscriber
Join Date: Jul 2006
Location: London
Posts: 567

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

# 2 31-10-2008 , 11:11 PM
bendingiscool's Avatar
Subscriber
Join Date: Jul 2006
Location: London
Posts: 567
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

# 3 01-11-2008 , 03:19 AM
bendingiscool's Avatar
Subscriber
Join Date: Jul 2006
Location: London
Posts: 567
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

Posting Rules Forum Rules
You may not post new threads | You may not post replies | You may not post attachments | You may not edit your posts | BB code is On | Smilies are On | [IMG] code is On | HTML code is Off

Similar Threads