XNA Creators Club Online
Page 1 of 1 (5 items)
Sort Posts: Previous Next

Passing information from model to material processors

Last post 10/19/2009 8:58 PM by jwatte. 4 replies.
  • 10/12/2009 6:52 PM

    Passing information from model to material processors

    Hi!
    I have built a custom model processor with a set of properties (e.g. "UseSpecular", etc.) than ca be set from visual studio.

    In my model processor, I have overridden ConvertMaterial in order to redirect material processing to my custom material processor. For my custom material processor to be able to select the appropriate material file, it needs to know the values of the aforementioned properties (e.g. whether to use specular lighting or not, etc.)

    Unfortunately I can't figure out how to pass that information.

    I've tried to use the OpaqueDataDictionary, but in the MaterialProcessor.Process method, the information is apparently "lost". Code sample:

    // In CustomModelProcessor 
    protected override MaterialContent ConvertMaterial(MaterialContent _material, ContentProcessorContext _context) 
    {                      
        OpaqueDataDictionary data = new OpaqueDataDictionary(); 
        data.Add("UseSpecular"this.UseSpecular); 
     
        return _context.Convert<MaterialContent, MaterialContent>(_material, "CustomMaterialProcessor", data); 
     
    // In CustomMaterialProcessor 
    public override MaterialContent Process(MaterialContent input, ContentProcessorContext context) 
        if (input.OpaqueData.ContainsKey("UseSpecular")) // false! 
        // ... 


    Can anyone help on this?
  • 10/12/2009 7:15 PM In reply to

    Re: Passing information from model to material processors

    OpaqueDataDictionary is exactly the right way to do this.

    When you call Convert, your ContentProcessorContext object does not change, so you get the main context for the entire asset, not a new one for this specific Convert call.

    The easiest way to read this data is to put a public UseSpecular property on your CustomMaterialProcessor.

    XNA Framework Developer - blog - homepage
  • 10/12/2009 7:46 PM In reply to

    Re: Passing information from model to material processors

    Awesome! So the content of the opaque data dictionary gets automagically remapped to the processor properties!

    That will force me to duplicate all the properties though. I'm going to try to put them all in a base class and use multiple inheritance for each one of my processors, or to create a single processor that implements both MaterialProcessor and ModelProcessor, if that's possible

    Mmhh, what would be a good way to avoid duplicating these properties in both processors?
  • 10/12/2009 11:31 PM In reply to

    Re: Passing information from model to material processors

    I think you have to duplicate them.
    XNA Framework Developer - blog - homepage
  • 10/19/2009 8:58 PM In reply to

    Re: Passing information from model to material processors


    Mmhh, what would be a good way to avoid duplicating these properties in both processors?


    You can't. You'll have to hunker down and do it. If C# supported multiple inheritance, you could do something neat with that, but it doesn't (and if you put the properties in an interface, you have to re-implement them in each class anyway).
    Jon Watte, Direct3D MVP
    Tweets, occasionally
    kW X-port 3ds Max .X exporter
    kW Animation source code
Page 1 of 1 (5 items) Previous Next
var gDomain='m.webtrends.com'; var gDcsId='dcschd84w10000w4lw9hcqmsz_8n3x'; var gTrackEvents=1; var gFpc='WT_FPC'; /*<\/scr"+"ipt>");} /*]]>*/
DCSIMG