Notifications
Clear all

[Closed] [C# SDK] IMNMesh accessing vert faces data in Vfac Tab<int>

Hi!
I’d like to get all face indexes related to particular vertex.
Is there anything I’m missing? Maybe some unsafe pointer magic?

static public int[] GetPolyVertFacesTab( )
{
	var global = GlobalInterface.Instance;

	IPolyObject pobj = (IPolyObject)global.COREInterface7.GetSelNode( 0 ).EvalWorldState( 0, false ).Obj;
	IMNMesh mesh = pobj.Mesh;

	uint MN_MESH_FILLED_IN = 1 << 1;
	

	if ( mesh.GetFlag( MN_MESH_FILLED_IN ) )
	{
                // mesh is filled in so all vert-faces data should be in place

		int[] vert_faces = new int[ mesh.Vfac.Count ];

		// according to c++ sdk it should be accessible like this
		// mesh.Vfac[ vert_index ][ j ]
		// but when accessed like this mesh.Vfac[ vert_index ] returns integer value instead of Tab
		// ;(
                // thus only the first vert-faces are available which makes Vfac unusable

		Marshal.Copy( mesh.Vfac.Addr( (IntPtr)0 ), vert_faces, 0, mesh.Vfac.Count );

		return vert_faces;
	}
	else
	{               
		return new int[] { };
	}

}

C++ sdk

	for (int j=0; j<mm.vfac[i].Count(); j++) {
		int fj = mm.vfac[i][j];
		// For each triangle using this vertex:
		Tab<int> tri;
		Point3 fnorm = mm.GetFaceNormal (fj, true);
		mm.f[fj].GetTriangles (tri);
...
2 Replies

wouldn’t you normally “derefence” the tab in c++

Tab<int>& vf = mm.vfac[i];
for(int j = 0; j < vf.Count(); ++j)
{
     int fj = vf[j];......

Well, the thing is that I’m struggling to make it on c# side and I have no idea how it is possible if at all.
VS tells me that I can’t declare pointer type for a managed type.

In c# mesh.Vfac seems like already dereferenced by default as mesh.Vfac[0] value.