Notifications
Clear all

[Closed] [SDK] MNMesh and VertexColor

Hello.
I’m developing a modifier to modify the vertex color channel of an object. I already know how to deal with Mesh from TriObject, but I also need the equivalent for MNMesh (PolyObj). Does someone know how to make it correctly?

This is my code for Mesh:

Mesh& mesh = triobj->GetMesh();
int NumVertexColors = mesh.getNumVerts();
BOOL bRes = mesh.setNumVertCol(NumVertexColors); 
if (!bRes) return; 

const int NumFaces = mesh.getNumFaces(); 
bRes = mesh.setNumVCFaces(NumFaces); 
if (!bRes) return; 

VertColor *vertCol = mesh.vertCol; //array of Point3 vertex colors
if (!vertCol) return;

TVFace *vcFace = mesh.vcFace; //texture faces
Face* faces = mesh.faces; //faces of my mesh, to convert texture vert index to the geometry vert index
		
for (int iFace=0;iFace<NumFaces;++iFace) 
{
	for (int j=0;j<3;++j)
	{
		int vertIndex = faces[iFace].v[j];
		vcFace[iFace].t[j] = vertIndex; //each texture vertex is assigned to its geom vertex
	}
}
5 Replies

this is code i use to set a whole mnmesh vertex colour, IVCmodParams is a data holding class I use. It has two custom function evalcol which computes the colour and blend which uses traditional photoshop blend modes to blend the new colour over the original.

void VCModUtils::TintMesh(MNMesh& pmesh, IVCmodParams& p)
  {
  	AColor c;
  
  // get the vertices & faces in this texture map
  
  	MNMap* mnMap = pmesh.M(p.getMapChannel());
  	int nmapverts = mnMap->numv;
  	UVVert* mapverts = mnMap->v;
  	MNMapFace* mapfaces = mnMap->f;
  	DbgAssert(mapverts);
  	DbgAssert(mapfaces);
  
  // create a bit array to make sure we only visit a map vert once
  
  	BitArray vertset(nmapverts);
  
  // geofaces & verts
  
  	int nfaces = pmesh.numf;
  	MNFace* geofaces = pmesh.f;
  	MNVert* geoverts = pmesh.v;
  
  // unfortunately we can't do the same pointer trickery here :\
  
  	for(int i=0; i < nfaces; ++i)
  	{
  		MNFace&		geoface = geofaces[i];
  		MNMapFace&	mapface = mapfaces[i];
  		const int fdeg = geoface.deg;
  		for(int j = 0; j < fdeg; ++j)
  		{
  			int mapvert = mapface.tv[j];
  			if(!vertset[mapvert])	// have we been here before ?
  			{
  				Point3& pos = geoverts[geoface.vtx[j]].p;
  				p.evalcol(pos, c);		// evaluate the colour
  				p.blend(mapverts[mapvert], c, c.a, mapverts[mapvert]);			
  				vertset.Set(mapvert);
  			}
  		}
  	}
  }

I check for map channel support earlier in the code with

 	int mapChannel = p.getMapChannel();
	if(mapChannel >= pmesh.numm || pmesh.M(mapChannel)->GetFlag(MN_DEAD))
		DefaultMapping(pmesh, mapChannel);

and this is the code I use a intializing the map… you can use some of the existing routines

void DefaultMapping(MNMesh& pmesh, int mapch)
  {
  // initialize the map
  
  	if(mapch >= pmesh.numm)
  		pmesh.SetMapNum(mapch+1);
  	pmesh.InitMap(mapch);
  	
  // fill with white	
  	
  	MNMap* map = pmesh.M(mapch);
  	UVVert* mv = map->v;
  
  	int nmapverts = map->numv;
  	for(int i = 0; i < nmapverts; ++i)
  		mv[i] = uv_white;
  }

Thanks a lot, it works great

there a really useful reference on how to set vert colors/mapping to selected faces e.g hard edges in the samples \Autodesk\3ds Max <version> SDK\maxsdk\samples\modifiers\uvwxform.cpp using a really neat utility class called TvMap which can be used for mesh/mnmesh and patchmesh with either mapping or vertex colors. It’s tough going but worth it.

Hi,

I am trying to set face color (random colors) for the mesh (not editable mesh and not editable poly, its an object mesh filled with details).

I have tried the method mentioned above (for mesh). Additionally, I add this line to set color
after this line,
vcFace[iFace].t[j] = vertIndex;
added this
mesh.setMapVert(1, vertIndex, clr);

but the color changes are not affected, not able to shown in viewport. dont know whether the values are set or not.
Is this the right way to set color ?

Please suggest me.

Regards,
Gopinath

Hello,

I was able to solve this.

Thanks.
Gopinath