Basically I have animated meshes in Maya (polygon mesh animated via a joint), and I am writing a Maya plugin to duplicate / rotate / translate / scale many times these meshes. Can be up to 50.000, so I prefer to remain in C++ rather than integrating Python code.
The duplication is “virtual”, i.e. only visible at render time. I therefore need to copy the existing mesh’s shaders to the duplicated ones.
Based on the samples, I created an mtlMulti:
int NUM_RANDOM=2;
VRayPlugin *randomMtls[NUM_RANDOM];
for (int i=0; i<NUM_RANDOM; i++)
randomMtls[i]=createRandomMtl(); // Random color material
mtlPlugin=newPlugin("MtlMulti");
DefPluginListParam *mtlListParam=factory.saveInFactory(new DefPluginListParam("mtls_list"));
mtlListParam->setCount(NUM_RANDOM+1);
for (int i=0; i<NUM_RANDOM; i++)
mtlListParam->setPlugin(i, randomMtls[i]);
mtlPlugin->setParameter(mtlListParam);
DefIntListParam *idListParam=factory.saveInFactory(new DefIntListParam("ids_list"));
idListParam->setCount(NUM_RANDOM+1);
IntList list = idListParam->getIntList(0);
for (int i=0; i<NUM_RANDOM+1; i++)
list[i]=i;
mtlPlugin->setParameter(idListParam);
param_shaders.setCount(12); // Cube -> 6 faces x 2
setFace(param_shaders, 0, 0, 1, 0); // Color #0 for some triangles ad #1 for others
setFace(param_shaders, 1, 0, 1, 0);
setFace(param_shaders, 2, 0, 1, 0);
setFace(param_shaders, 3, 0, 1, 0);
mtlPlugin->setParameter(¶m_shaders);
and assign it to my instances:
MaterialInterface *mtl=mtlPlugin? static_cast<MaterialInterface*>(GET_INTERFACE(mtlPlugin, EXT_MATERIAL)) : _mtl;
BSDFInterface *bsdf=mtlPlugin? static_cast<BSDFInterface*>(GET_INTERFACE(mtlPlugin, EXT_BSDF)) : _bsdf;
myInstance->addMesh(geomSource->newInstance(mtl, bsdf, renderID, volume, lightList, bTM, objectID, infoUserAttr.ptr(), primaryVisibility));
But all my instances are grey. Should I do something else ?
Thank you !