Set Vertex Color from a SplineShape using Edit_Mesh modifier

Set Vertex Color from a SplineShape using Edit_Mesh modifier

Anonymous
Not applicable
1,200 Views
2 Replies
Message 1 of 3

Set Vertex Color from a SplineShape using Edit_Mesh modifier

Anonymous
Not applicable

Hello,

 

Is it possible to change parameters of a Modifier in the SDK ? 

So, how can i edit the vertex color and alpha values in a Edit Mesh modifier, stacked over a SplineShape object ?

 

The modifier doesn't return any ParamBlock, and the only way i found to get the current mesh is by an ObjectState instance created with Eval function... which is oubviously useless since it's a temp object.

 

 

Thank you.

 

0 Likes
1,201 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable

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 🙂

0 Likes
Message 3 of 3

Anonymous
Not applicable

I have found the way to do it with Editable_Poly objects : 

 

IPolyObject poly = node.ObjectRef.ConvertToType(0, Global.PolyObjectClassID) as IPolyObject;

node.ObjectRef = poly.CollapseObject;

IEPoly epi = node.ObjectRef.GetInterface(Global.Interface_ID.Create(0x092779, 0x634020)) as IEPoly;

for (int v = 0; v < poly.Mesh.Numv; v++)
{
  IBitArray verts = Global.BitArray.Create(poly.Mesh.Numv);
  verts.ClearAll();
  verts.Set(v);
  IColor color = Global.Color.Create(colorR(v), colorG(v), colorB(v));
  IColor alpha = Global.Color.Create(alphaVal(v), alphaVal(v), alphaVal(v));

  epi.EpfnPropagateComponentFlags(1, (uint)(1<<2), 1, (uint)(1<<2), false, false, false);
  epi.EpSetVertexFlags(verts, (uint)(1<<2), 0, false);
  epi.BeginVertexColorModify(0);
  epi.SetVertexColor(color, 0, (uint)(1<<2), 0);
  epi.EndVertexColorModify(true);
  epi.BeginVertexColorModify(-2);
  epi.SetVertexColor(alpha, -2, (uint)(1<<2), 0);
  epi.EndVertexColorModify(true);
  epi.LocalDataChanged((uint)(1<<7));
}

I still need to find a way to do the same with Editable_Mesh and EditMesh Modifier.

0 Likes