[SDK] How to get vert by tvert?

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 03 March 2013   #1
Question [SDK] How to get vert by tvert?

Hello everyone!
There is a question: how can i get vertex by texture vertex?
I'm using 3DS Max 2013 SDK.
 
Old 03 March 2013   #2
mesh or mnmesh ?
 
Old 03 March 2013   #3
Originally Posted by Klunk: mesh or mnmesh ?

mesh
.......
 
Old 03 March 2013   #4
the process is the same for both though the syntax differs

something like this should do the trick....

	Mesh* mesh = ..... where you get the mesh
  
  	if (!mesh->mapSupport(channel))
  		..... handle the error
  
  	BitArray geoverts(mesh->getNumVerts());
  
  	int nMapFaces = mesh->Map(channel).getNumFaces();
  	TVFace *mapFaces = mesh->mapFaces(channel);
  
  	for (int i = 0; i < nMapFaces; i++) 
  	{
  		if(mapFaces[i]) 
  		{
  			for (int j=0; j<3; j++)
  			{
  				if(mapFaceData[i].t[j] == mapvert)
  				{
  					geoverts.Set(mesh->faces[i].v[j]);
  					break; // there should only be one matching per face
  				}
  			}
  		}
  	}



its not been tested, is a quick conversion from an mnmesh version I have. Though it's not common it is possible to have a single map vert shared with many geo verts, if you are sure that this will never be the case you can add an escape flag for the main loop and use a single int to store the geovert index as opposed to the bitarray.

Last edited by Klunk : 03 March 2013 at 02:17 PM.
 
Old 03 March 2013   #5
I do not quite understand what exactly does this code.


There is my code:

INode* rootNode = i->GetRootNode();
unsigned int meshCount = rootNode->NumberOfChildren();
for(unsigned int u = 0; u < meshCount; u++)
{
	INode* node = rootNode->GetChildNode(u);
	BOOL deleteIt = FALSE;
	TriObject *tri = GetTriObjectFromNode(node, deleteIt);
	unsigned int tVertexCount = tri->mesh.getNumTVerts();
	for(unsigned j = 0; j < tVertexCount; j++)
	{
		float x = tri->mesh.getTVert(j).x;
		float y = tri->mesh.getTVert(j).y;
		
		// So I get the coordinates of the texture vertices.
		// And how do I get the coordinates of the vertex corresponding to the given texture vertex?
	}
}

Last edited by MorzzE : 03 March 2013 at 12:16 PM.
 
Old 03 March 2013   #6
in this case go via the faces....

INode* rootNode = i->GetRootNode();
 unsigned int meshCount = rootNode->NumberOfChildren();
 for(unsigned int u = 0; u < meshCount; u++)
 {
 	INode* node = rootNode->GetChildNode(u);
 	BOOL deleteIt = FALSE;
 	TriObject *tri = GetTriObjectFromNode(node, deleteIt);
 
 
 /*	unsigned int tVertexCount = tri->mesh.getNumTVerts();
 
 	for(unsigned j = 0; j < tVertexCount; j++)
 	{
 		float x = tri->mesh.getTVert(j).x;
 		float y = tri->mesh.getTVert(j).y;
 		
 		// So I get the coordinates of the texture vertices.
 		// And how do I get the coordinates of the vertex corresponding to the given texture vertex?
 	}*/
 
 
 // go by faces
 
 	int nfaces = tri->mesh.getNumFaces();
 	TVFace *mapfaces = tri->mesh.mapFaces(channel); // the generic case or
	//TVFace* mapfaces = tri->mesh.tvFace; // the specific channel 1 case
 	Face   *faces = tri->mesh.faces;	
 
 	for(int i = 0; i < nfaces; i++)
 	{
 		if(mapfaces[i] && faces[i]) 
 		 {
 			for(int j=0; j<3; j++)
 			 {
 				int tvert_index = mapfaces[i].t[j]; // the index into the map vert data
 				int vert_index = faces[i].v[j]; // the index for the equivalent geo vert
 			}
 		}
 	}
 }

Last edited by Klunk : 03 March 2013 at 01:01 PM.
 
Old 03 March 2013   #7
Thank you very much! It works.
 
Old 03 March 2013   #8
you have to be quite careful sometimes, depending on what you are doing, because going by face means you can visit (and effect) the same verts repeatedly . Creating a bitarray of "visited" verts is a way round this.
 
Old 03 March 2013   #9
Originally Posted by Klunk: you have to be quite careful sometimes, depending on what you are doing, because going by face means you can visit (and effect) the same verts repeatedly . Creating a bitarray of "visited" verts is a way round this.

I need that repetition
 
Old 03 March 2013   #10
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 05:05 PM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.