Maya Training

Introduction to Hard Surface Modeling

Maya Training

Interiors and Furniture Vol 1 & 2 - Modeling & Cloth

Maya Training

Shading, Lighting and Rendering the Bedroom in MR

Maya Training

Robot volume one - Modeling with animation in mind

Maya Training

Spach-Alspaugh House the complete courseware

Maya Training

Burt The Cartoon Dinosaur Vol 01 - Modeling

New Maya Training

Robot Volume 02 - Hybrid Rigging
You are here > Home > SimplyMaya Community Forums
Loading

Welcome to Simply Maya

Please Sign in or Sign up for an account

Member Login

Lost your password?

Not a member yet? Sign Up!

Old 31-10-2008, 02:19 AM   #1
bendingiscool
Subscriber
 
bendingiscool's Avatar
 
Join Date: Jul 2006
Location: London
Posts: 567
Thanks: 0
Thanked 1 Time in 1 Post
Default 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 is offline   Reply With Quote
Old 01-11-2008, 12:11 AM   #2
bendingiscool
Subscriber
 
bendingiscool's Avatar
 
Join Date: Jul 2006
Location: London
Posts: 567
Thanks: 0
Thanked 1 Time in 1 Post
Default

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 is offline   Reply With Quote
Old 01-11-2008, 04:19 AM   #3
bendingiscool
Subscriber
 
bendingiscool's Avatar
 
Join Date: Jul 2006
Location: London
Posts: 567
Thanks: 0
Thanked 1 Time in 1 Post
Default

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
bendingiscool is offline   Reply With Quote

A little bit about who we are
Links you might find useful
Catch up with SimplyMaya
SimplyMaya specialises in Maya tutorials. We offer over 1,000 individual Maya training videos, ranging from basic Maya tutorials through to intermediate Maya tutorials. Our tutorials are created by instructors with industry experience and are designed to get you up and running in Maya quickly without making it seem like hard work.

Copyright © 1999-2015 SimplyMaya - vBulletin® Copyright © 2000-2015, Jelsoft Enterprises Ltd.