Search code examples
c#.netplugins3dsmax3ds

How to correctly implement ChannelsChanged and ChannelsUsed when creating a modifier plugin for 3dsmax in C#?


How to correctly implement ChannelsChanged and ChannelsUsed when creating a modifier plugin for 3dsmax in C#?

When I ask VS to implement the abstract class derived from Autodesk.Max.Plugins.Modifier, I get following to implement:

public override uint ChannelsChanged {

  get { throw new NotImplementedException(); }
}

public override uint ChannelsUsed {

  get { throw new NotImplementedException(); }
}

In C++, I should do something like this:

ChannelMask ChannelsChanged() {return PART_GEOM|TEXMAP_CHANNEL|VERTCOLOR_CHANNEL; }

Some C++ defines like GEOMOBJECT_CLASS_ID show up in C# SDK as SClass_ID.Geomobject. But I can't find anything like those flags in the Object Browser for Autodesk.Max. There are plenty of information missing besides this one. I didn't find examples or how-tos for Modifiers in C# anywhere.

Any help is much appreciated.


Solution

  • The fact that the methods expects a uint as a return value, hints that Autodesk have failed to implement a strong enumeration for Object Channel PartIDs.

    You can define your own enumeration to handle it, based on the values defined in the c++ SDK.

    [Flags]
    enum ChannelPartID : uint
    {
        // The topology channel - the face or polygon structures. 
        TOPO_CHANNEL = 1 << 0,
        // The vertices of the object. 
        GEOM_CHANNEL = 1 << 1,
        // The texture vertices and procedural mappings. 
        TEXMAP_CHANNEL = 1 << 2,
        // This is no longer used. 
        MTL_CHANNEL = 1 << 3,
        // The sub-object selection channel. 
        SELECT_CHANNEL = 1 << 4,        
        // The current level of selection. 
        SUBSEL_TYPE_CHANNEL = 1 << 5,
        // The miscellaneous bits controlling the item's display. 
        DISP_ATTRIB_CHANNEL = 1 << 6,
        // The color per vertex channel. 
        VERTCOLOR_CHANNEL = 1 << 7
        // The used internally by 3ds Max for stripping. 
        GFX_DATA_CHANNEL = 1 << 8,
        // Displacement approximation. 
        DISP_APPROX_CHANNEL = 1 << 9,
        // The channel used by extension channel objects. 
        EXTENSION_CHANNEL = 1 << 13,
        // The ObjectState Transform that flows down the pipeline. 
        TM_CHANNEL = 1 << 10,
        // For internal use. 
        EDGEVISIBILITY_CHANNEL = 1 << 11,
        // For internal use. 
        DONT_RECREATE_TRISTRIP_CHANNEL = 1 << 12,
        // This is no longer used. 
        GLOBMTL_CHANNEL = 1 << 31,
        OBJ_CHANNELS = TOPO_CHANNEL | GEOM_CHANNEL | SELECT_CHANNEL | TEXMAP_CHANNEL | MTL_CHANNEL | SUBSEL_TYPE_CHANNEL | DISP_ATTRIB_CHANNEL | VERTCOLOR_CHANNEL | GFX_DATA_CHANNEL | DISP_APPROX_CHANNEL | EXTENSION_CHANNEL,
        ALL_CHANNELS = OBJ_CHANNELS | TM_CHANNEL | GLOBMTL_CHANNEL 
    }
    

    And then in your methods use it like so

    public override uint ChannelsChanged 
    {
      get { return (uint)(ChannelPartID.PART_GEOM | ChannelPartID.TEXMAP_CHANNEL | ChannelPartID.VERTCOLOR_CHANNEL); }
    }