this should work:
windows->plugins->nearestPointOnMesh load and/or autoload
then the mel command
nearestPointOnMesh
creates a node, in my case it was called nearestPointOnMesh1
if you select that node, you can see it has a mesh and XYZ position input and the output is
position
normal
U
V
face index
you can also type
listAttr nearestPointOnMesh1;
to list the attributes
you want the position and the normal
if the position on the mesh + the normal is closer to you (you=the position you feed into the node) than the position on the mesh - normal, then you are on the "outside" of the face, presumedly of the enitre mesh.
in mel:
// set the input position
setAttr nearestPointOnMesh1.inPosition 0 10 0 ;
// get the out position
float $p[] = getAttr nearestPointOnMesh1.position;
float $n[] = getAttr nearestPointOnMesh1.normal;
that should get you the info you need in MEL. now you use math/vector math to find which points are closest.
ill post that later.
select the mesh, enter the point by editing the script and source it, then
insideOut
chris
global proc string insideOut () {
// MEL script to determine if a point is on the outside or inside of a mesh
// assumes the normals for the mesh are correct
// by Chris Rogers
// http://opototopo.com
// chris ( AT ) opototopo.com
// Aug 16 2010
// this will hold the normal returned from nearestPointOnMesh
vector $vnor;
// this will hold the position on the mesh returned from nearestPointOnMesh
vector $vpos;
// these are for the distances from input to point+normal and point-normal
float $d1;
float $d2;
// checks to see if the nearestPointOnMesh plugin is loaded, and load it if it isnt
// the .mll might make this Windows specific? i dont have a linux/osx version to test....
// this plugin is a standard part of maya, not a bonus tool
if ( ! pluginInfo -q -loaded nearestPointOnMesh ) {
loadPlugin -n "nearestPointOnMesh" "nearestPointOnMesh.mll" ;
}
// checks to make sure the inputMesh is selected
string $ls[] = ls -sl; // put a list of all the currently selected nodes in $ls
// check to make sure there is at least 1 object selected
if (size ($ls) < 1 ) {
error "no object selected";
return "no object";
}
string $l = $ls[0];
select $l; // make sure only the first object is selected in case multiple obj's were selected
pickWalk -d down; // this should select the Shape node from the transform node
$ls = ls -sl;
$l = $ls[0];
if ( objectType $l != "mesh" ) {
error "the selected object is not a mesh";
return "not a mesh";
}
// create a new nearestPointOnMesh node and put the name of the node in the variable $npom, and sets the inputMesh (inMesh) to the selected mesh
string $npom = nearestPointOnMesh;
// find normal, position for nearestPoint
vector $pos = <>; // weird syntax for assignment for a vector....
// for this example we'll just make it 0,10,0
setAttr ($npom+".inPosition") ($pos.x) ($pos.y) ($pos.z) ; // in MEL, vector compenents have to be in ()'s
// get the XYZ from the node and put into the vector data types for easier comparisons
$vpos =getAttr ($npom+".position");
$vnor = getAttr ($npom+".normal");
// using the vector datatype saves lots of steps
// mag returns the length of a vector
// $d1 is the distance from the input position to the nearestPointOnMesh + the normal
$d1 = mag(($vpos+$vnor)-$pos);
//$d2 is the distance from the input position to the nearestPointOnMesh - the normal
$d2 = mag(($vpos-$vnor)-$pos);
// show the lines from the in position to the p+n, p-n, and the nearestPointOnMesh for debugging
curve -d 1 -p ($pos.x) ($pos.y) ($pos.z) -p ($vpos.x + $pos.x) ($vpos.y + $pos.y) ($vpos.z + $pos.z);
curve -d 1 -p ($pos.x) ($pos.y) ($pos.z) -p ($vpos.x - $pos.x) ($vpos.y - $pos.y) ($vpos.z - $pos.z);
curve -d 1 -p ($pos.x) ($pos.y) ($pos.z) -p ($vpos.x) ($vpos.y) ($vpos.z);
if ($d1 < $d2) {
print ("OUTSIDE");
return "outside";
} else {
print ("INSIDE");
return "inside";
}
// should never reach here.....
return "error?";
}