Notifications
Clear all

[Closed] Faster GetFacesUsingVert

I’ve seen some people write some faster GetVertsUsingEdge methods, or GetFacesUsingEdge methods, I believe DenisT in particular. As the meshop/polyop formats can be extremely slow with single inputs. but I haven’t found any GetFacesUsingVert methods. Does anyone have one of these they’d like to share, or can lead me in the right direction of how to tackle it?

Thanks

4 Replies

really depends on whats happening too the mesh… if it remains unchanged the you can build a vert 2 face reverse lookup

fn build_vert2face_lookup mobj =
(
	nverts = mobj.numverts;
	nfaces = mobj.numfaces;
	
	v2f = #();
	v2f.count = nverts ;
	
	for f = 1 to nfaces do
	(
		fvert = getface mobj f;
		for v = 1 to 3 do
		(	
			vi = fvert[v];
			if v2f[vi] == undefined  then v2f[vi] = #(f) else append v2f[vi] f;
		)
	)	
	v2f;
)	

delete $objects
mobj = ConvertToMesh(plane());
v2f = build_vert2face_lookup mobj;
mobj.selectedfaces = v2f[7];

though if you have to keep rebuilding the look up table then it becomes slower than the brute for meshop function. There are several versions of the above function you could try…e.g. using bitarrays for table entries .

it’s strange that the editable poly mesh struct (MNMesh) maintains a reverse vert to face lookup table by default but the polyop routine doesn’t use it. It uses the same brute force approach as the meshop version.

Ah nice, yes this will help out immensely. Thanks!

if you are doing this in relation to working with mapping verts a useful addition is to cache the face corner as well…

if v2f[vi] == undefined then v2f[vi] = #([f,v]) else append v2f[vi] [f,v];

Ah that is useful! Good idea.