My VertexColor journey is annoying...
I tried to set vertex color on a Editable Mesh, instead of add a Edit Mesh modifier, since i dont have any clue how to get my mesh without Eval function.
ITriObject triObj = node.ObjectRef.ConvertToType(0, TriObjectClassID) as ITriObject;
node.ObjectRef = triObj;
IMesh mesh = triObj.Mesh;
// need to set vertex color map support to TRUE, if not, all vertices colors will become white...
mesh.SetMapSupport(0, true);
mesh.SetNumVertCol(mesh.NumVerts, false);
// Get User Interface of Editable Mesh
IMeshDeltaUser mdu = triObj.GetInterface(I_MESHDELTAUSER) as IMeshDeltaUser;
if (mdu != null && mdu.Editing)
mdu.ExitCommandModes();
// Get the mesh in editable mode - delta mesh
IMeshDelta tmd = Global.MeshDelta.Create(mesh);
// Add support to alpha vertex too
tmd.AddVertexColors();
tmd.AddMap(-2);
tmd.SetMapSupport(-2, true);
IBitArray vset = Global.BitArray.Create(mesh.numVerts);
// fill colors and alpha list
for (int v = 0; v < mesh.numVerts; v++)
{
float colorR, colorG, colorB, alphaVal;
vset.ClearAll();
vset.Set(v);
colorR = 0.5f;
colorG = 0.5f;
colorB = 0.5f;
alphaVal = 0.5f;
IPoint3 color = Global.Point3.Create(colorR, colorG, colorB);
tmd.SetVertColors(mesh, vset, color, 0);
IPoint3 alpha = Global.Point3.Create(alphaVal, alphaVal, alphaVal);
tmd.SetVertColors(mesh, vset, alpha, -2);
}
if (mdu != null)
{
IMeshDeltaUserData data = triObj.GetInterface(I_MESHDELTAUSERDATA) as IMeshDeltaUserData;
data.ApplyMeshDelta(tmd, mdu, Ip.Time);
}
else
{
tmd.Apply(mesh);
}
node.CVertMode = 1;
node.ShadeCVerts = 0;
node.VertexColorType = 0;
If i dont set the map support durectly on the Mesh instance, all vertex colors become white, but alpha values are well set.
In the SDK it's written that we have to support the vertex color map on the mesh to keep infos from the delta mesh... But this creates an error of type SEHException on SertVertColors method (so it's a 3dsMax side error, which I can't debug...)
The interesting part is, sometimes the code doesn't crash (with same values tested !) and more often it does. But even if it doesn't crash, all vertex color are black.
@Anonymous if you have any clue 🙂