Get the real document in MATPREVIEW_GENERATE_IMAGE material message



  • Hello.

    I have implemented a MaterialData plugin in which I draw my own preview listening to MATPREVIEW_GENERATE_IMAGE.
    To do that, I use the GeListNode* node parameter passed in Message(....), which in this case is the currently selected material.
    To produce the preview, I need to parse the material's parameters and transfer the material into my engine, which produces a preview image.
    If a parameter uses a bitmap shader, I am going to need that image.
    I get the image path using GenerateTexturePath. As first parameter in this function I pass the document's path.
    The problem is that the document in MATPREVIEW_GENERATE_IMAGE is the sphere.c4d in resource\modules\xtensions\preview_scenes.
    The result of this is that GenerateTexturePath returns false.

    So basically, MATPREVIEW_GENERATE_IMAGE forces me to use a GeListNode and a document that I don't need.
    Can I switch this functionality to use the real node and document file ? (othewise my preview generation cannot find the requested images in Bitmap Shaders).

    Thank you.
    Petros.


  • Global Moderator

    Hi Petros,

    you can conveniently find the original document when the MATPREVIEW_PREPARE_SCENE message is intercepted.

    In this case the data passed is MatPreviewPrepareScene where you can find, among the members, the original document (pOriginalDoc).
    From there on you know what to do.

    Best, Riccardo



  • Hello.

    MATPREVIEW_PREPARE_SCENE is not triggered at all.
    In the ideal scenario, I need the original node, but if that's not possible I could use the original document.

    Thank you for your time !


  • Global Moderator

    Hi Petros, in order to have the MATPREVIEW_PREPARE_SCENE being dispatched, you've to set MatPreviewObjectInfo::bNeedsOwnScene to true. At the same time also MatPreviewObjectInfo::bHandlePreview needs to be set to true when the host object is responsible for the rendering.

    Finally I think that looking at MATPREVIEW enums can be helpful as well.

    Best, Riccardo