Notifications
Clear all

[Closed] Get geometry Vert ID from map Vert ID?

The best way to picture this is, how would you select a vert in UVUnwrap, and have it select in the viewport? Map verts and Geo verts don’t have the same ID…

4 Replies
1 Reply
(@bobo)
Joined: 11 months ago

Posts: 0

There is no way to know how many vertices correspond to a mapping vert, or the other way round. All you can find is what map faces reference that map vert, then get the geo face with the same index as each map face and get the vertices of that face. The geometry vertex at the same position as the map vertex in the map face (either .x, .y or .z) will be a potential candidate.

So you

  1. Grab the map vertex index
  2. Call meshop.getMapFacesUsingMapVert() to find out what map faces use that vert.
  3. For each map face,
  4. Find where the map vertex is inside the map face definition (.x, .y or .z)
  5. Get the geometry Face with the same index as the map face being processed
  6. Get the .x, .y or .z of the geometry face according to the finding in 4.
  7. Repeat from 3. for any other map faces

In 6., you will have to append the index of the vertex you discovered in that step to some temp. array. At the end of the loop 3 to 7, you will have an array of all possible geometry vertices that match the map vertex. Then you can grab their positions or select them or whatever.

Same applies to the other direction – finding a map vertex by mesh vertex.

I wrote this function:

function getMapVerts object channel = -- return array of map IDs coresponding to mesh verts 
(
	if( meshOp.getMapSupport object channel ) then
	(
		-- prepare array for each verteice
		local mapVerts = for i=1 to object.numverts collect #()
		
		local mapFace, meshFace, mVert
		for i=1 to (meshOp.getNumMapFaces object channel) do 
		(
			mapFace = meshOp.getMapFace object channel i
			mapFace = #( (mapFace.x as integer), (mapFace.y as integer), (mapFace.z as integer) )

			meshFace = getFace object i
			meshFace = #( (meshFace.x as integer), (meshFace.y as integer), (meshFace.z as integer) )
			
			for j=1 to 3 do
			(
				if( (findItem mapVerts[meshFace[j]] mapFace[j]) == 0 ) do -- isn't this map vert already added?
				(
					append mapVerts[meshFace[j]] mapFace[j] -- store index
					--append mapVerts[meshFace[j]] (meshop.getMapVert object channel mapFace[j]) -- vertex, index need less memory than map vertex
				)
			)
		)
		
		mapVerts -- return
	)
	else
		undefined -- return
)

It returns array of arrays. It’s one array peer each mesh vertice, it contains IDs of map verts this vert is using.

Search for your map vert id in my function return, to get know which mesh verts are using it.

Thanks alot guys, i’ll try these out tomorrow.

Hey MiranDMC, why is it that changing this line:

local mapVerts = for i=1 to object.numverts collect #()

…to:

local mapVerts = for i=1 to 5 collect #()

…results in me getting the error “No ““findItem”” function for undefined”, where undefined is mapVerts. It’s a bit odd.