Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    BaseMaterial::Update() not updating editor

    SDK Help
    0
    9
    760
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H
      Helper
      last edited by

      On 30/01/2013 at 07:27, xxxxxxxx wrote:

      User Information:
      Cinema 4D Version:   R14.025 
      Platform:      
      Language(s) :     C++  ;

      ---------
      Is it intended that BaseMaterial::Update() does not update the editor textures? I call this method
      from BaseShader:Message() to update the material the shader is attached to because of changes that
      do not get pointed out by Cinema. The material itself is updated correctly, but objects that have the
      material attached look as the material wasn't updated.

      -Niklas

      1 Reply Last reply Reply Quote 0
      • H
        Helper
        last edited by

        On 31/01/2013 at 00:04, xxxxxxxx wrote:

        Hi Niklas,

        Do you call BaseMaterial::Update(Bool preview, Bool rttm) with both preview (preview thumbnail is updated) and rttm (real time texture map of the material will be recalculated) parameters set to TRUE?

        1 Reply Last reply Reply Quote 0
        • H
          Helper
          last edited by

          On 31/01/2013 at 08:01, xxxxxxxx wrote:

          Hi Yannick,

          Yes, I even tried all possible combinations.

          1 Reply Last reply Reply Quote 0
          • H
            Helper
            last edited by

            On 31/01/2013 at 08:10, xxxxxxxx wrote:

            I also noticed, that I need to call BaseMaterial::Message(MSG_CHANGE); after calling ~::Update().
            Without, the material isn't updated at all.

            1 Reply Last reply Reply Quote 0
            • H
              Helper
              last edited by

              On 19/04/2013 at 09:24, xxxxxxxx wrote:

              Hi!

              I still have this problem. The material preview is updating properly, but the textures on the objects
              do not update and stay as if nothing would have changed. It doesn't even update when I manually
              change a parameter in the material.

                  Bool CoreMessage(LONG type, const BaseContainer& msg) {
                      if (type == EVMSG_DOCUMENTRECALCULATED) {
                          BaseDocument* doc = GetActiveDocument();
                          if (!doc) return FALSE;
                
                          BaseMaterial* mat = doc->GetFirstMaterial();
                          while (mat) {
                              if (ShaderLinkCheckUpdateMaterial(mat)) {
                                  mat->Update(TRUE, TRUE);
                                  mat->Message(MSG_UPDATE);
                              }
                              mat = mat->GetNext();
                          }
                      }
                      return TRUE;
                  }
              

              I also tried various things from the Script Manager. I can't get the editor textures updated from
              a script. Only, for example, adding a new shader manually to the material does the trick.

              Do I need to use DrawViews() or anything to get them updated as well?

              Thanks,
              -Niklas

              1 Reply Last reply Reply Quote 0
              • H
                Helper
                last edited by

                On 22/04/2013 at 03:16, xxxxxxxx wrote:

                *bump*

                1 Reply Last reply Reply Quote 0
                • H
                  Helper
                  last edited by

                  On 22/04/2013 at 04:10, xxxxxxxx wrote:

                  hey,

                  could you explain what you meant with you cannot get a script to work ? for me on r14.034
                  these few lines do work as expected. it is obviously for a document where the first material 
                  has a checkboard shader in the color channel.

                  import c4d
                    
                  def main() :
                      mat = doc.GetFirstMaterial()
                      sha = mat[c4d.MATERIAL_COLOR_SHADER]
                      sha[c4d.CHECKERBOARDSHADER_SCALEX] += 2
                      mat.Update(1,1)
                      c4d.EventAdd()
                    
                  if __name__=='__main__':
                      main()
                  
                  1 Reply Last reply Reply Quote 0
                  • H
                    Helper
                    last edited by

                    On 22/04/2013 at 04:20, xxxxxxxx wrote:

                    ok, forget what i have said, the parameter passed to Update() have no influence on
                    the result of the script, but why don't you send a msg to the basedocument or the 
                    core as those seem to work (at least in python) as i did in those few lines.

                    1 Reply Last reply Reply Quote 0
                    • H
                      Helper
                      last edited by

                      On 22/04/2013 at 04:53, xxxxxxxx wrote:

                      Hi Ferdinand,

                      thanks for your answer! Your script works for me. I tried marking my shader as dirty when the
                      shader it was referencing (being not inserted in the materials shader list) changed. But that didn't
                      work.

                      EDIT: Yes, it works! 🙂 After the code I posted abvoe, I had an EventAdd() at the end, which was
                      necessary because the textures did only reload after one manually dragged in the viewport. But
                      that seemed to break  up the re-rendering of the textures. I don't know why, but it works when
                      adding the EventAdd() on the next call to CoreMessage() :

                      class ShaderUpdateHook : public MessageData {
                        
                          Bool requireUpdate;
                        
                        public:
                        
                          ShaderUpdateHook() : requireUpdate(FALSE) {}
                        
                        // MessageData
                        
                          Bool CoreMessage(LONG type, const BaseContainer& msg) {
                              if (requireUpdate) {
                                  requireUpdate = FALSE;
                                  EventAdd();
                              }
                              if (type == EVMSG_DOCUMENTRECALCULATED) {
                                  BaseDocument* doc = GetActiveDocument();
                                  if (!doc) return FALSE;
                        
                                  BaseMaterial* mat = doc->GetFirstMaterial();
                                  while (mat) {
                                      if (ShaderLinkCheckUpdateMaterial(mat)) {
                                          mat->Update(TRUE, TRUE);
                                          mat->Message(MSG_UPDATE);
                                          requireUpdate = TRUE;
                                      }
                                      mat = mat->GetNext();
                                  }
                        
                              }
                              return TRUE;
                          }
                        
                      };
                      

                      Best,
                      -Niklas

                      1 Reply Last reply Reply Quote 0
                      • First post
                        Last post