Image in material preview



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 21/01/2010 at 01:41, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   11.5 
    Platform:   Windows  ;   Mac OSX  ; 
    Language(s) :     C++  ;

    ---------
    Hello all,
    in my material plugin i need to substitute standard material preview with a simple bitmap, any way to do this ?
    Thanks in advance
    franz



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 21/01/2010 at 02:13, xxxxxxxx wrote:

    Please check the MATPREVIEW_ messages in the documentation and the particlevolume.cpp and simplematerial.cpp SDK example files. These two plugin materials replace the the standard material with a custom preview scene.

    cheers,
    Matthias



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 22/01/2010 at 06:19, xxxxxxxx wrote:

    Hello Matthias,
    thanks i found some interesting thisngs in the examples:
    i have some problem to add a bitmap in material here my complete message for preview generation :
    Bool TheaMaterial::Message(GeListNode* node, LONG type, void* data)
    {
         if (type == MSG_UPDATE)
              updatecount++;

    switch (type)
         {
         case MSG_EDIT:
              {
                   //my material stuff
                   break;
              }

    case MATPREVIEW_GET_OBJECT_INFO:
              // the preview needs our object information
              {

    MatPreviewObjectInfo* info = (MatPreviewObjectInfo* )data;
                   info->bHandlePreview = TRUE; // own preview handling
                   info->bNeedsOwnScene = TRUE; // we need our own entry in the preview scene cache
                   info->bNoStandardScene = TRUE; // create our own preview scene
                   info->lFlags = MATPREVIEW_FLAG_HIDE_SCENE_SETTINGS; // hide the scene settings entry
                   return TRUE;
              }
              break;
         case MATPREVIEW_MODIFY_CACHE_SCENE:
              {
                   MatPreviewModifyCacheScene* scene = (MatPreviewModifyCacheScene* )data;
                   BaseObject * back = BaseObject::Alloc(Obackground);
                   if (!back) return FALSE;
                   back->SetName("back");
                   BaseTag* mattag = back->MakeTag(Ttexture);
                   if (!mattag) return FALSE;
                   scene->pDoc->InsertObject(back, NULL, NULL);
                   return TRUE;
              }
              break;
         case MATPREVIEW_PREPARE_SCENE:
              {
                   MatPreviewPrepareScene* preparescene = (MatPreviewPrepareScene* )data;

    BaseMaterial *matclone = BaseMaterial::Alloc(Mmaterial);

    AutoAlloc<AliasTrans> trans;
                   if (!trans)
                        return FALSE;
                   if (!trans->Init(GetActiveDocument()))
                        return FALSE;

    Filename mypreview;
                   mypreview.SetString("tempprev.jpg");
                   BaseBitmap * bitprev = BaseBitmap::Alloc();
                   LONG test = bitprev->Init(mypreview,-1,0);
                   if ( test != IMAGE_OK) GePrint ("error");

    PluginShader *shd = NULL;
                   shd = PluginShader::Alloc(Xbitmap);
                   if(!shd) return FALSE;

    BaseContainer *shddata = shd->GetDataInstance();
                   BaseContainer * matdata = matclone->GetDataInstance();

    matdata->SetLink(MATERIAL_COLOR_SHADER, shd);
                   matclone->InsertShader(shd, NULL);

    shddata->SetFilename(BITMAPSHADER_FILENAME, "mypreview");
                   shd->Message(MSG_UPDATE);
                   matclone->Message(MSG_UPDATE);
                   matclone->Update(TRUE, FALSE);
                   EventAdd();

    BaseMaterial* matclone2 = (BaseMaterial* )(matclone->GetClone(0, trans));

    preparescene->pDoc->InsertMaterial(matclone2);

    if (preparescene->pLink) preparescene->pLink->SetLink(matclone2); // necessary

    BaseObject* back = preparescene->pDoc->SearchObject("back");
                   if (back)
                   {
                        TextureTag* textag = (TextureTag* )back->GetTag(Ttexture);
                        if (textag)
                             textag->SetMaterial(matclone2);
                   }

    preparescene->bScenePrepared = TRUE;
                   return TRUE;
              }
              break;
         case MATPREVIEW_GET_POPUP_OPTIONS:
              {
                   return TRUE;
              }
              break;
         case MATPREVIEW_HANDLE_POPUP_MSG:
              {
                   return TRUE;
              }
              break;
         case MATPREVIEW_GENERATE_IMAGE:
              {
                   MatPreviewGenerateImage* image = (MatPreviewGenerateImage* )data;
                   if (!image->bEditorPreview)
                   {
                        if (image->pDoc)
                        {
                             LONG w = image->pDest->GetBw();
                             LONG h = image->pDest->GetBh();
                             BaseContainer bcRender = image->pDoc->GetActiveRenderData()->GetData();
                             bcRender.SetReal(RDATA_XRES, w);
                             bcRender.SetReal(RDATA_YRES, h);
                             bcRender.SetLong(RDATA_ANTIALIASING, ANTI_GEOMETRY);

    image->pDest->Clear(0, 0, 0);
                             image->lResult = RenderDocument(image->pDoc, bcRender, NULL, NULL, image->pDest, RENDERFLAG_EXTERNAL | RENDERFLAG_PREVIEWRENDER, image->pThread);
                        }
                   }
                   return TRUE;
              }
              break;

    }
         return MaterialData::Message(node, type, data);
    }

    i tried colors and various parameter of material work fine...
    textuore shader don't work
    any sugestion ?
    Franz



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 26/01/2010 at 07:01, xxxxxxxx wrote:

    no news ? :)
    Franz



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 27/01/2010 at 06:24, xxxxxxxx wrote:

    Still working on it. I post again if I've found a solution.

    cheers,
    Matthias



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 04/02/2010 at 05:30, xxxxxxxx wrote:

    one more question, is this a static background image or does it have to be updated by the material?

    cheers,
    Matthias



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 04/02/2010 at 05:43, xxxxxxxx wrote:

    i am working on an external renderer exporter, after material editing (in a external application material editor) i can save the image in a file then i'dd like to load it in cinema material preview.
    franz



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 04/02/2010 at 12:35, xxxxxxxx wrote:

    For just displaying an image it's probably easier to directly modify the displayed bitmap. You can do this in MATPREVIEW_GENERATE_IMAGE. Instead of rendering the preview document simply fill the preview bitmap. This will react to changes made in the AM too. Here is some example code:

      
    Bool ParticleVolume::Message(GeListNode *node, LONG type, void *data)  
    {  
      switch (type)  
      {  
          case MATPREVIEW_GET_OBJECT_INFO:  
          {  
              MatPreviewObjectInfo* info = (MatPreviewObjectInfo* )data;  
              info->bHandlePreview = TRUE; // own preview handling  
              info->bNeedsOwnScene = TRUE; // we need our own entry in the preview scene cache  
              info->bNoStandardScene = TRUE; // create our own preview scene  
              info->lFlags = MATPREVIEW_FLAG_HIDE_SCENE_SETTINGS; // hide the scene settings entry  
                
              return TRUE;  
          }  
          break;  
      
          case MATPREVIEW_MODIFY_CACHE_SCENE:  
          {  
              return TRUE;  
          }  
          break;  
      
          case MATPREVIEW_PREPARE_SCENE:  
          {  
              MatPreviewPrepareScene* preparescene = (MatPreviewPrepareScene* )data;  
      
              AutoAlloc<AliasTrans> trans;  
              if (!trans) return FALSE;  
              if (!trans->Init(GetActiveDocument())) return FALSE;  
                
              BaseMaterial* matclone = (BaseMaterial* )(Get()->GetClone(0, trans));  
              preparescene->pDoc->InsertMaterial(matclone);  
              trans->Translate(TRUE);  
                
              if (preparescene->pLink) preparescene->pLink->SetLink(matclone);  
      
              preparescene->bScenePrepared = TRUE;  
      
              return TRUE;  
          }  
          break;  
      
          case MATPREVIEW_GENERATE_IMAGE:  
          {  
              MatPreviewGenerateImage* image = (MatPreviewGenerateImage* )data;  
                
              if (image->pDoc)  
              {  
                  if (!image->bEditorPreview)  
                  {  
                      AutoAlloc<BaseBitmap> bmp;  
                      if (!bmp || bmp->Init(Filename("C:\\test.jpg")) != IMAGE_OK) return FALSE;  
      
                      bmp->ScaleIt(image->pDest, 256, TRUE, TRUE);  
      
                      image->lResult = RAY_OK;  
                  }  
              }  
      
              return TRUE;  
          }  
          break;  
      }  
      
      return MaterialData::Message(node, type, data);  
    }  
    

    hope this helps

    cheers,
    Matthias



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 04/02/2010 at 13:40, xxxxxxxx wrote:

    Thanks Matthias,
    i'll try this!
    As usual your help is invaluable.
    :)
    Franz


Log in to reply