BaseShader global vs local filename



  • 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?



  • @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;
    	}
    }
    


  • @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.



  • 😀

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



  • @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 ;-)



  • @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 :)