So what would be a more efficient way to write this?
void TestModifier::ModifyObject(TimeValue t, ModContext &mc, ObjectState *os, INode *node) {
mprintf("ModifyObject
");
Object *obj = os->obj;
if(!obj) return;
int n;
float *weights;
if (obj->IsSubClassOf(triObjectClassID)) { // TriObject types
TriObject *triOb = (TriObject *)obj;
Mesh& mesh = triOb->GetMesh();
n = mesh.getNumVerts();
weights = mesh.getVSelectionWeights();
}
else if (obj->IsSubClassOf(polyObjectClassID)) { // PolyObject types
PolyObject *polyOb = (PolyObject *)obj;
MNMesh& mesh = polyOb->GetMesh();
n = mesh.VNum();
weights = mesh.getVSelectionWeights();
}
else if (obj->CanConvertToType(triObjectClassID)) { // all other geometry types should try to convert to a triobject
TriObject *triOb = (TriObject *)obj->ConvertToType(t, triObjectClassID);
Mesh& mesh = triOb->GetMesh();
n = mesh.getNumVerts();
weights = mesh.getVSelectionWeights();
}
for (int i = 0; i < n; i++) { mprintf(_T("%f, "), weights[i]); }
mprintf("
");
}
best way to learn mesh vs mnmesh (and working with them both and the differences as they have implementations for doing the same things) is to look in the mxsagi project in the samples specifically the files meshop.cpp and polyop.cpp. the linker thing is we’ve all been there :). I’ve said many times on here that SDK development (or issues with it) is usually down to lack of understanding of the build process and lack of experience using visual studio and dealing with the complexities of the project settings (it’s why I’m not a fan of the plugin wizard, it’s flakey and does little to help the dev beginners understanding of the process)
how did i do it:
#1 find a similar project in the sdk examples
#2 try to compile it
if it works:
#3 bring all libraries to my project
#4 compile – remove unlikely used – compile – remove – compile…
it’s the same problem for me… i couldn’t find a way to make the wizard helpful
I actually ended up substantially rewriting the wizard, partly to learn how it was all put together, and partly because it didn’t work properly out of the box.
Klunk, how do you set up those overloaded functions you mentioned? I can’t figure out how to pass the mesh variable as an argument.
Don’t pass the mesh, pass the object… so in the class definition
void ObjectModify(TriObject *tobj, params& p, TimeValue t);
void ObjectModify(PolyObject *polyObj, params& p, TimeValue t);
params is defined as a local sub struct to the modifier class used to collect all the param block values then the ModifyObject looks a bit like this
void MyMod::ModifyObject(TimeValue t, ModContext &mc, ObjectState *os, INode *node)
{
Object *obj = os->obj;
if(!obj) return;
Interval iv = GetValidity(t);
iv &= obj->ChannelValidity(t, TOPO_CHAN_NUM);
iv &= obj->ChannelValidity(t, GEOM_CHAN_NUM);
params p;
InitGizmoControl(t, obj, mc, os);
GetParams(p,t, &iv , Inverse(CompMatrix(t, &mc, os->GetTM())));
if (obj->IsSubClassOf(triObjectClassID)) // Handle any triobject types
{
ObjectModify((TriObject*)obj,p,t);
}
else if (obj->IsSubClassOf(polyObjectClassID)) // Handle any PolyObject types
{
ObjectModify((PolyObject*)obj,p,t);
}
else if (obj->CanConvertToType(triObjectClassID)) // all others should try to convert to a triobject,
{
TriObject *triOb = (TriObject *)obj->ConvertToType(t, triObjectClassID);
// Now stuff this into the pipeline!
os->obj = triOb;
ObjectModify(triOb,p,t);
}
obj->UpdateValidity(TOPO_CHAN_NUM, iv);
obj->UpdateValidity(GEOM_CHAN_NUM, iv);
}
then the overloaded functions like this
void MyMod::ObjectModify(TriObject* tobj, params& p, TimeValue t)
{
Mesh& mesh = tobj->GetMesh();
int nverts = mesh.numVerts;
int nfaces = mesh.numFaces;
.....
void MyMod::ObjectModify(PolyObject* polyObj, params& p, TimeValue t)
{
MNMesh& pmesh = polyObj->GetMesh();
int nverts = pmesh.numv;
int nfaces = pmesh.numf;
........
though you should really change my lazy c style casts to static_cast<>()
params is coming up undefined. Is that another linker error?
EDIT
To provide more information, the specific error I am getting is
Error: identifier “params” is undefined.
And when I search for the definition, I get
Tab<FPParamDef*> FPFunctionDef::params - c:\ ... \maxsdk\include\ifnpub.h(688)
Tab<FPValue> FPParams::params - c:\ ... \maxsdk\include\ifnpub.h(942)
Oh ok, fair enough. I assume that is a way to pass information that is common to the overloaded functions?
if you have the function as part of the modifier class there is really no need, but sometimes i share functionality across plugins so have to pass params.