Material::CopyTo() problems



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

    On 16/11/2006 at 13:28, xxxxxxxx wrote:

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

    ---------
    What is wrong with this code? I've tried without COPY_NO_INTERNALS, but the links to the Texture tags are then broken. I've tried calling AliasTrans::Translate after each and at the end (as shown). Is the AliasTrans::Init() document correct (source)? This is getting frustrating as it works to an extent, but the materials don't update properly (show the texture image) and rendering fails.

    // Paste Materials  
    //*---------------------------------------------------------------------------*  
    Bool GeIPPPaste_Materials(BaseDocument* sdoc, BaseObject* sobj, BaseDocument* ddoc, BaseObject* dobj)  
    //*---------------------------------------------------------------------------*  
    {  
         BaseTag*          stag;  
         BaseTag*          dtag;  
         TextureTag*          sttag;  
         TextureTag*          dttag;  
         Material*          smat;  
         Material*          dmat;  
         GeData               data;  
         String               sname;  
         BOOL               doTranslate =     FALSE;  
      
         AutoAlloc<AliasTrans> aliastrans;  
         if (!(aliastrans && aliastrans->Init(sdoc))) return FALSE;  
         // Materials  
         for (stag = sobj->GetFirstTag(); stag; stag = stag->GetNext())  
         {  
              if (!stag->IsInstanceOf(Ttexture))     continue;  
              sttag =                                        (TextureTag* )stag;  
              sttag->GetParameter(DescID(TEXTURETAG_MATERIAL), data, NULL);  
              smat =                                        static_cast<Material*>(data.GetLink(sdoc, Mbase));  
              if (!smat)                                   continue;  
              sname =                                        stag->GetName();  
              for (dtag = dobj->GetFirstTag(); dtag; dtag = dtag->GetNext())  
              {  
                   if (!dtag->IsInstanceOf(Ttexture))     continue;  
                   dttag =                                        (TextureTag* )dtag;  
                   dttag->GetParameter(DescID(TEXTURETAG_MATERIAL), data, NULL);  
                   dmat =                                        static_cast<Material*>(data.GetLink(ddoc, Mbase));  
                   if (!dmat)                                   continue;  
                   if (dtag->GetName() != sname)          continue;  
                   // Found matching materials, copy  
                   if (!smat->CopyTo(dmat, COPY_NO_INTERNALS, aliastrans))     continue; //aliastrans->Translate(TRUE);  
                   dmat->Update(TRUE, TRUE);  
                   dmat->Message(MSG_CHANGE);  
                   doTranslate =     TRUE;  
                   break;  
              }  
         }  
         if (doTranslate)     aliastrans->Translate(TRUE);  
         return TRUE;  
    }
    

    Thanks,



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

    On 16/11/2006 at 15:03, xxxxxxxx wrote:

    Okay, this code is mostly working, but I still have to either render or Material Manager->Apply to get the material changes to show in the View.

    How do I do that, please?

    // Paste Materials  
    //*---------------------------------------------------------------------------*  
    Bool GeIPPPaste_Materials(BaseDocument* sdoc, BaseObject* sobj, BaseDocument* ddoc, BaseObject* dobj)  
    //*---------------------------------------------------------------------------*  
    {  
         AutoAlloc<AliasTrans>     aliastrans;  
         AutoAlloc<AtomArray>     matArray;  
         AutoAlloc<AtomArray>     tagArray;  
         if (!(matArray && tagArray && aliastrans && aliastrans->Init(sdoc))) return FALSE;  
      
         BaseTag*          stag;  
         BaseTag*          dtag;  
         TextureTag*          sttag;  
         TextureTag*          dttag;  
         Material*          smat;  
         Material*          dmat;  
         GeData               data;  
         String               sname;  
      
         // Materials  
         for (stag = sobj->GetFirstTag(); stag; stag = stag->GetNext())  
         {  
              if (!stag->IsInstanceOf(Ttexture))     continue;  
              sttag =                                        (TextureTag* )stag;  
              sttag->GetParameter(DescID(TEXTURETAG_MATERIAL), data, NULL);  
              smat =                                        static_cast<Material*>(data.GetLink(sdoc, Mbase));  
              if (!smat)                                   continue;  
              sname =                                        stag->GetName();  
              for (dtag = dobj->GetFirstTag(); dtag; dtag = dtag->GetNext())  
              {  
                   if (!dtag->IsInstanceOf(Ttexture))     continue;  
                   dttag =                                        (TextureTag* )dtag;  
                   dttag->GetParameter(DescID(TEXTURETAG_MATERIAL), data, NULL);  
                   dmat =                                        static_cast<Material*>(data.GetLink(ddoc, Mbase));  
                   if (!dmat)                                   continue;  
                   if (dtag->GetName() != sname)          continue;  
                   // Found matching materials, copy  
                   if (!smat->CopyTo(dmat, COPY_NO_BITS, aliastrans)) continue;  
                   matArray->Append(dmat);  
                   tagArray->Append(dttag);  
                   break;  
              }  
         }  
         LONG     count =     matArray->GetCount();  
         if (count)  
         {  
              aliastrans->Translate(TRUE);  
              for (LONG i = 0; i < count; i++)  
              {  
                   dmat =          static_cast<Material*>(matArray->GetIndex(i));  
                   dttag =          static_cast<TextureTag*>(tagArray->GetIndex(i));  
                   dttag->SetMaterial(dmat);  
                   dmat->Update(TRUE, TRUE);  
                   dmat->Message(MSG_CHANGE);  
                   dttag->Message(MSG_UPDATE);  
              }  
         }  
         return TRUE;  
    }
    

    Thanks,



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

    On 16/11/2006 at 15:29, xxxxxxxx wrote:

    Seems that I needed this as well:

      
              ....  
              aliastrans->Translate(TRUE);  
              for (LONG i = 0; i < count; i++)  
              {  
                   dmat =          static_cast<Material*>(matArray->GetIndex(i));  
                   dttag =          static_cast<TextureTag*>(tagArray->GetIndex(i));  
                   dttag->SetMaterial(dmat);  
                   dmat->Update(TRUE, TRUE);  
                   dmat->Message(MSG_CHANGE);  
                   dttag->Message(MSG_UPDATE);  
                   dobj->Message(MSG_UPDATE);  
              }  
              ...  
    

    Thanks for the conversation! ;)



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

    On 18/11/2006 at 08:09, xxxxxxxx wrote:

    lol, you are too fast in finding your own bugs. ;-)



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

    On 18/11/2006 at 10:01, xxxxxxxx wrote:

    The worst part is that there is no example of using CopyTo() with Materials. They neglect the little bit about needing to relink them in the Texture tag and I still don't know why the Object needs to be updated - but heck, it works. ;)


Log in to reply