Mapping Coordinate Modifiers
 
 
 

These modifiers alter the texture mapping coordinates of an objects. They can add new mapping coordinates to unmapped objects or modify the existing mapping coordinates of objects. A modifier that adds new mapping coordinates is the UVW Mapping Modifier. The full source code is available in \MAXSDK\SAMPLES\MODIFIERS\MAPMOD.CPP. Below are the implementations of InputType(), ChannelsUsed(), and ChannelsChanged().

Class_ID InputType() { return mapObjectClassID; }
ChannelMask ChannelsUsed()
{
   returnPART_GEOM | PART_TOPO | PART_SELECT |
   PART_SUBSEL_TYPE | PART_VERTCOLOR;
}
ChannelMask ChannelsChanged()
{
   returnTEXMAP_CHANNEL|PART_VERTCOLOR;
}

The mapping modifier requests an object that is mappable by specifying the Class_IDmapObjectClassID. Objects that are mappable (or know how to convert themselves to a mappable object) will return TRUE in the method CObject::CanConvertToType() when passed this Class_ID. This indicates that they may have texture coordinates assigned to them and they implement the method Object::ApplyUVWMap(). Note how the Vertex Color channel is needed and changed as well as the texture map channel. This is because 3ds Max uses the second mapping channel as the vertex color channel and the user is able to specify that the second mapping channel may be used for the mapping coordinates.

Here is the implementation of ModifyObject(). Note that when the modifier is done it updates the validity of the texture map channel by calling UpdateValidity().

void MapMod::ModifyObject(TimeValue t, ModContext &mc,
            ObjectState *os, INode *node)
{
   // If it's not a mappable object then we can't help
   Object *obj = os->obj;
   if (!obj->IsMappable()) return;
 
   // Get pblock values 
   inttype, uflip, vflip, wflip, cap, channel; 
   floatutile, vtile, wtile;
   pblock->GetValue(PB_MAPTYPE, t,type,FOREVER);
   pblock->GetValue(PB_UTILE,t,utile,FOREVER);
   pblock->GetValue(PB_VTILE,t,vtile,FOREVER);
   pblock->GetValue(PB_WTILE,t,wtile,FOREVER);
   pblock->GetValue(PB_UFLIP,t,uflip,FOREVER);
   pblock->GetValue(PB_VFLIP,t,vflip,FOREVER);
   pblock->GetValue(PB_WFLIP,t,wflip,FOREVER);
   pblock->GetValue(PB_CAP,t,cap,FOREVER);
   pblock->GetValue(PB_CHANNEL, t,channel,FOREVER);
 
   // Prepare the controller and set up mats
   if (!tmControl || (flags&CONTROL_OP) || (flags&CONTROL_INITPARAMS))
   {
     InitControl(mc,obj,type,t);
   }
   Matrix3 tm; 
   tm = Inverse(CompMatrix(t,&mc,NULL));
 
   obj->ApplyUVWMap(type,utile,vtile,wtile,uflip,vflip,wflip,cap,tm,channel);
 
   // The tex mapping depends on the geom and topo so make sure the validity interval reflects this.
   Interval iv = LocalValidity(t);
   iv = iv & os->obj->ChannelValidity(t,GEOM_CHAN_NUM);
   iv = iv & os->obj->ChannelValidity(t,TOPO_CHAN_NUM);
 
   os->obj->UpdateValidity(TEXMAP_CHAN_NUM,iv); 
}
See Also