Here’s a very simple implementation:
try(destroydialog insideOutside)catch()
rollout insideOutside "Inside or Outside?" --main rollout
(
label l1 ""
button bTest "Test"
on bTest pressed do
(
vObj = $Volume --volume to test
pObj = $Point01 --point
converttomesh vObj
numF = getnumfaces vObj --get number of faces of volume
dist = 10000000 --initialize face-distance check
testPoint = undefined
for q in 1 to numF do --loop through all faces
(
fCenter = meshop.getfacecenter vObj q --get point at center of current face
testDist = distance fCenter pObj.pos --test distance from center of face to point object
if testDist < dist then --check if current face is closer to point than last face
(
dist = testDist
testPoint = fCenter --if we're closer this time than last time, set current face as test face
)
)
vec1 = testPoint - pObj.pos --get vector between test point and test face center point
ray1 = ray pObj.pos vec1 --construct ray
intRay = intersectRay vObj ray1 --shoot ray
if intRay == undefined then
(
l1.text = "Inside Object"
)else
(
l1.text = "Outside Object"
)
)
)
createdialog insideOutside
To successfully run the script, create a point in the viewport, then create your volume object and name it “Volume”. Then run the script and click the “Test” button. Moving the point around (inside or outside the object" and then pressing the “Test” button will return the results in the rollout label.
Note: you might not even need the “find closest face” functionality of the script if the object has a closed surface, since shooting a ray in any direction will return a value of “undefined” if there are no missing faces in the surface (because when you’re inside an object with a closed surface, all normals point away from you)
Also, if your volume mesh has self-intersections, this could cause problems because “outside” faces will intersect into the interior of the volume and skew the intersectray results, if one of those intersecting “outside” faces happens to be the face you test with the ray.
To implement this type of thing into your own script, just use vertex positions instead of a point helper’s position, and loop the main function for however many verts the mesh has.