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

    BaseShader global vs local filename

    Cinema 4D SDK
    c++ r19 r20 r21
    2
    6
    642
    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.
    • C4DSC
      C4DS
      last edited by C4DS

      Hi,
      When one creates a material and loads an image into the color channel Cinema4D pops up a messagebox, saying:
      "This image is not in the project search path.
      Do you want to create a copy at the project location ..."

      When you reply "no" the full path to the image can be obtained from the BaseShader.
      When you reply "yes" only the image filename (without full path) is stored.

      How to know if the content of the BaseShader's parameter BITMAPSHADER_FILENAME is a full path or simply the image's filename?
      In other words, how to know to simply use the obtained data from the parameter as a global path, or as a local path relative to the project's tex folder?

      1 Reply Last reply Reply Quote 0
      • kbarK
        kbar
        last edited by kbar

        @C4DS said in BaseShader global vs local filename:

        BITMAPSHADER_FILENAME

        You might be looking for GenerateTexturePath. Or possibly IsInSearchPath may work for you if you just want to check and not actually get the path? But if you want to see if it is a filename or a path you can inspect the characters or check Filename::GetDirectory();

        BaseContainer bc = pChannel->GetData();
        Filename fullTexturePath;
        GeData d;
        pRefLayShader->GetParameter(DescID(BITMAPSHADER_FILENAME), d, DESCFLAGS_GET::NONE);
        Filename fn = d.GetFilename();
        if (fn.IsPopulated())
        {
        	Filename suggestedFolder = bc.GetFilename(BASECHANNEL_SUGGESTEDFOLDER);
        	if (GenerateTexturePath(_doc->GetDocumentPath(), fn, suggestedFolder, &fullTexturePath))
        	{
        		hasTexture = true;
        	}
        }
        

        https://www.gamelogicdesign.com
        https://www.plugins4d.com

        C4DSC 1 Reply Last reply Reply Quote 1
        • C4DSC
          C4DS @kbar
          last edited by

          @kbar
          Thanks for the tip

          Actually, looking back at my original code I now notice what I did wrong:

          BaseShader* colorShader = colorChannel->GetShader();
          if (colorShader && colorShader->IsInstanceOf(Xbitmap))
          {
          	GeData data;
          	colorShader->GetParameter(DescID(BITMAPSHADER_FILENAME), data, DESCFLAGS_GET::NONE);
          	texturePath = data.GetFilename();
          	// when the filename doesn't contain a directory this means the bitmap
          	// is located in same directory as the scene file
          	// -> get the path of the scene file and prepend it to the bitmap,
          	// as we need a full path to load the bitmap
          	if (texturePath.GetDirectory().IsEmpty())
          	{
          		BaseDocument* doc = object->GetDocument();
          		Filename path = doc->GetDocumentPath();
          		texturePath = path + texturePath;
          	}
          

          Simply had to replace the last line of code:

          texturePath = path + texturePath;
          

          with

          texturePath.SetDirectory(path);
          

          I cannot imagine I never tested the original code. As such, I assume it did probably work back then in R19 (maybe by accident), but definitely doesn't in R21. Maybe not even in R20.

          1 Reply Last reply Reply Quote 0
          • kbarK
            kbar
            last edited by

            ๐Ÿ˜€

            On a side note: man these emojis are weird looking.

            https://www.gamelogicdesign.com
            https://www.plugins4d.com

            C4DSC 1 Reply Last reply Reply Quote 0
            • C4DSC
              C4DS @kbar
              last edited by

              @kbar said in BaseShader global vs local filename:

              ๐Ÿ˜€

              On a side note: man these emojis are weird looking.

              I mostly never use emojis, as I seem to misinterpret their meaning ... and most people already find it hard understanding what I mean ๐Ÿ˜‰

              kbarK 1 Reply Last reply Reply Quote 0
              • kbarK
                kbar @C4DS
                last edited by

                @C4DS

                That was the most normal happy smiling glad you solved your issue emoji I could find. Any of the others could definitely have been interpreted in many ways. Hope that one came across alright ๐Ÿ™‚

                https://www.gamelogicdesign.com
                https://www.plugins4d.com

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