Material Modifiers
 
 
 

Material modifiers alter the material ID stored by the object. An example of this type of modifier is the Material Modifier implemented by the MatMod class in the file \MAXSDK\SAMPLES\MODIFIERS\SURFMOD.CPP.

Below are the implementations of Modifier::InputType(), Modifier::ChannelsUsed(), and Modifier::ChannelsChanged() of the Material modifier. Note that materials are rolled into the face structure of the object so this modifier alters the topology channel.

Class_ID InputType() {
  returntriObjectClassID;
} 
 
ChannelMask ChannelsUsed() {
  returnOBJ_CHANNELS;
}
 
ChannelMask ChannelsChanged() {
  returnGEOM_CHANNEL|TOPO_CHANNEL;
}

This modifier specifies it changes the geometry channel, however it doesn't need to since it only changes the material index at the face level and nothing at the vertex level.

Below is the implementation of the Material modifier's Modifier::ModifyObject(). Note that when the modifier is done it updates the validity of the object flowing down the pipeline by calling UpdateValidity() and passing the topology channel number.

void MatMod::ModifyObject(TimeValue t, ModContext &mc,
            ObjectState *os, INode *node)
{
   Interval valid = FOREVER;
   intid;
   pblock->GetValue(PB_MATID,t,id,valid); 
   id--;
   if (id<0) id = 0;
   if (id>0xffff) id = 0xffff;
 
   dbgAssert(os->obj->IsSubClassOf(triObjectClassID));
   TriObject *triOb = ( TriObject *)os->obj;
   BOOLuseSel = triOb->mesh.selLevel==MESH_FACE;
 
   for (int i=0; i<triOb->mesh.getNumFaces(); i++)
   {
     if (!useSel || triOb->mesh.faceSel[i])
     {
      triOb->mesh.setFaceMtlIndex(i,(MtlID)id);
     }
   }
 
   triOb->UpdateValidity(TOPO_CHAN_NUM, valid); 
}