Notifications
Clear all

[Closed] Tangent Space Per Geom Vertex

Ok, just to make things clear.
I understand the VNormal class (almost all except the strange thing inside the FindIndex method).
I know that its doing a great job getting the Tangents per face.

What I need is having this data… to get the tanget per vertex…

something like this:

for (int i = 0; i < mesh.numv; i++) {
Tanget t = GetTangent(i);
}

What I need is logic behind the GetTangent(i);

As I understand you suggest the idea to implement something like this?:


GetTangent(i) {
     returnTangent = 0;
      nFaces = getNeighbourFacesOfVert(i);
      for (f = 0; f < nFaces.count; f++)
	  for (j = 0; j < 3; j++)
			  if (nFaces[f].VertexIndex[j] == i)
				returnTangent += channel->GetTangentBasis( f, TvFaceVert[f].TVert[j], j ); 
 
return Normalize(returnTangent)
}

something like this?

I’m not suggesting anything like that. I’m suggesting…

 copying VNormal.h & VNormal.cpp into your plugin project
 
 add something like
VNormalMgr* vnmgr;
 to your plugin class
 
 in the plugin constructor add
vnmgr = GetVNormalMgr();
 change
void VNormalMgr::InitTangentBasis( ShadeContext& sc, int mapChannel )
 to something like
void VNormalMgr::InitTangentBasis( MNMesh& mnmsh, int mapChannel )
 with the necessary changes to the code (see [b]MNMesh::OutToTri(Mesh &  tmesh[/b][)]( http://forums.cgsociety.org/class_m_n_mesh.html#a116)  . And Call this function whenever you need to generate the Tangents.
vnmgr->InitTangentBasis( myMNMesh, 1);
 change 
void VNormalMgr::GetTangentBasis( ShadeContext& sc, int mapChannel, TangentBasis& tangentBasis )
     
 to something like
void VNormalMgr::GetTangentBasis( int face, int mapChannel, TangentBasis& v1,  TangentBasis& v2, TangentBasis& v3)
 again with the required edits in code...
 then you just get the tangents with something like...
for(int f=0;f < mesh->numfaces;f++)
     {
         vnmgr->GetTangentBasis(f,1,v1tangent,v2tangent,v3tangent);
     // do stuff with tangents
    
    
    }

i was forgetting… and add

vnmgr->Free();

to the plugin destructor

I feel a little unconfortable because I’m wasting your time.
We are repeating the same on the last posts.
I understood what you mean from your first post.
I will try to explain one more time what I need.

Here is the image

So the data that I need to process is Geom Vert.

VNormal.cpp calculates data on TFaces and TVerts

If I will use Classes from VNormal I need somehow to convert my GeomVert indeces to TVert indeces as they difer.

From your last post we see that we still getting data per face not per GeomVert
[left]for(int f=0;f < mesh->numfaces;f++) { [/left]
[left]vnmgr->GetTangentBasis(f,1,v1tangent,v2tangent,v3tangent) ; // do stuff with tangents [/left]
[left]}[/left]

[left]if the order of v1tanget, v2tangent, v3tangent coresponds to the GeomFaces vertex indices[/left]
[left]then getting the tangent per GeomVert will look like I wrote in the post above[/left]

[left]GetTangent(i) {[/left]
returnTangent = 0;
nFaces = getNeighbourFacesOfVert(i);
for (f = 0; f < nFaces.count; f++)
for (j = 0; j < 3; j++)
if (nFaces[f].VertexIndex[j] == i)
returnTangent += channel->GetTangentBasis( f, TvFaceVert[f].TVert[j], j );

return Normalize(returnTangent)
}

[left]replacing it with your last code will look like[/left]

[left]GetTangent(i) {[/left]
returnTangent = 0;
nFaces = getNeighbourFacesOfVert(i);

[left]for(int f=0;f < mesh->numfaces;f++) {

[left]vnmgr->GetTangentBasis(f,1,vtangent[0],vtangent[1],vtangent[2]) ; [/left]
[left]// do stuff with tangents [/left]
[left]for (j = 0; j < 3; j++)[/left]
if (nFaces[f].VertexIndex[j] == i)
returnTangent += vtangent[i]
[left]}[/left]
return Normalize(returnTangent)
}

[/left]

[left]So this function will work as it should? or it could be something else.[/left]

[left]Basically I’m looking for a method that will work like[/left]
[left]vnmgr->GetTangentBasis(i)[/left]
[left]where i is the GeomVertex index[/left]

[left]All my problem consist of getting the tangents per Geom Vertex[/left]

[left]VNormal uses the tangents per TFace and computes tangents per TVerts… in Normal Map case its ok, cause the rendering uses per face information and interpolation.[/left]
[left]In my case I need only the geom vertecies[/left]

[left]Also one more problem with VNormal is that its interpolating the tangent space based on smoothing groups. But this is not such a big problem because I can modify it to not do so.[/left]

you just do it on a per face basis…

tvface.v1 = geoface.v1 = tangentface.v1
tvface.v2 = geoface.v2 = tangentface.v2
tvface.v3 = geoface.v3 = tangentface.v3

This is the answer I was for but aren’t TVert indeces of TFace different than Geom Indeces?

tvface.v1 != geoface.v1
tvface.v1 = tangentface.v1

geoface.vertNum < TVertNum

for example in the picture above there are 12 TVerts and only 5 GeomVerts

TVface1 vert1 is the same vert as Geometryface1 vert1
TVface1 vert2 is the same vert as Geometryface1 vert2
TVface1 vert3 is the same vert as Geometryface1 vert3

sorry for the previous comment, I though there was geom.verts not geomFace

So that still means that I need to get the neighbour faces of my absolute vert, to find the coresponding vert on the geom face, so I can get the TVert index on the TVFace to get Tangents to interpolate for each neigbour face

Page 2 / 2