Notifications
Clear all
[Closed] Poly face from mesh face
Jul 29, 2008 8:06 pm
When I do a RayMeshGridIntersect, it returns the hit trimesh faces, not polygonal faces. Is there any way to determine what polymesh faces have been hit? If this isn’t clear, just I can explain more.
2 Replies
Jul 29, 2008 8:06 pm
Hey,
You can use a method like this:
fn GetPolygonFromFace objPoly objMesh face =
(
local faceVerts = GetFace objMesh face
local sharedPoly = PolyOp.GetFacesUsingVert objPoly faceVerts.X
sharedPoly *= PolyOp.GetFacesUsingVert objPoly faceVerts.Y
sharedPoly *= PolyOp.GetFacesUsingVert objPoly faceVerts.Z
)
Cheers,
Light
Jul 29, 2008 8:06 pm
Hi Rob,
on editable polygons made by tris or quads only, testing the shared poly from mesh face vertices is fine. But if you’re working with n-gons, it may happen there is more than one polygon sharing the same three mesh face verts, so you need some additional testing to sort the right poly index. This is done by checking vertices match.
function getPolyFromFace EditPoly iFace =
(
-- here some argument type checking
-- EditPoly should be (classOf EditPoly == Editable_Poly)
-- iFace should be an integer > 0 and <= meshop.getNumFaces EditPoly.mesh
-- get vertices from specified mesh face
local aiVert = (meshOp.getVertsUsingFace EditPoly.mesh iFace) as Array
-- init an array to store polygons sharing verts from mesh face
local aPolyFromVert = #()
-- get polygons sharing verts from mesh face
for iVert in aiVert do
(
append aPolyFromVert (polyOp.getFacesUsingVert EditPoly iVert)
)
-- get polygons having all three mesh face verts in common
-- NOTE: they could be more than one, depending on n-gon geometry
local baPoly = aPolyFromVert[1] * aPolyFromVert[2] * aPolyFromVert[3]
-- test
if (baPoly.numberSet == 1) then
(
return (baPoly as Array)[1]
)
else -- there is more than one polygon sharing all three verts from mesh face
(
-- get all mesh faces enclosed in the polygon we're looking for
local baMeshFaceInPoly = meshOp.getPolysUsingFace EditPoly.mesh iFace ignoreVisEdges:false threshhold:90
-- get verts from polygon mesh faces
local baMeshFaceVert = meshOp.getVertsUsingFace EditPoly.mesh baMeshFaceInPoly
-- test what's the right polygon from previous search by matching vertices
for iPoly in baPoly do
(
-- get poly verts
local baPolyVert = polyOp.getVertsUsingFace EditPoly iPoly
-- match test
if (((baPolyVert - baMeshFaceVert).isEmpty == true) and ((baMeshFaceVert - baPolyVert).isEmpty == true)) then
(
return iPoly
)
)
)
)
- Enrico