Hi.
I made a function to hit test subobjects under the cursor, but for unknown reason it behaves very strange on poly mesh, but only in MNedge and MNFace mode. As if it only do hit tests for the last subobject in mesh.
I mean only the last edge and last face return a value. But MNVert mode works as expected and every vertex near the mouse cursor returns a value. Is there anything else I need to do to make it work?
I looked at sdk sources but couldn’t find anything that I would miss…
MNEdge mode test:
Here’s the code I use to hit test editable mesh nodes.
The only difference between MNMesh version is that IObject casts to TriObject instead of IPolyObject.
public static void GetMeshSubObjHit( int x, int y )
{
var ip = GlobalInterface.Instance;
var node = ip.COREInterface.GetSelNode( 0 );
var obj = node.EvalWorldState( ip.COREInterface.Time, true ).Obj;
var mesh = ((ITriObject)obj).Mesh_; // this is the only difference between mesh and poly methods
IHitRegion hr = ip.HitRegion.Create();
ISubObjHitList hl = ip.SubObjHitList.Create();
IIPoint2 pt = ip.CPInitPos_.Add();
pt.X = x;
pt.Y = y;
int crossing = 1;
int POINT_RGN = 0x0001;
uint GW_PICK = 0x0001000;
uint GW_ILLUM = 0x0000002;
uint SUBHIT_EDGES = 1 << 26;
ip.MakeHitRegion( hr, POINT_RGN, crossing, 4, pt );
var gw = ip.COREInterface.ActiveViewExp.Gw;
gw.RndLimits = (gw.RndLimits | GW_PICK) & ~GW_ILLUM;
gw.ClearHitCode();
gw.SetHitRegion( hr );
gw.Transform = node.GetObjectTM( ip.COREInterface.Time, ip.Interval.Create() );
bool has_hit = mesh.SubObjectHitTest( gw, gw.Material, hr, SUBHIT_EDGES, hl, 1 );
if ( !has_hit ) return;
if ( gw.CheckHitCode )
debugPrint( ">> hit " );
debugPrint( $"edge index:{hl.First.Index + 1}" );
}
upd
I just found out that it is possible to get the subobject index using ip->COREInterface->SubObHitTest, but unfortunately it requires that the object must be selected and the subobjectlevel should be active to get edge/face indexes.