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

    TEXTURE resource parameter

    Cinema 4D SDK
    c++ r23
    2
    4
    638
    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.
    • rsodreR
      rsodre
      last edited by rsodre

      Hi,

      I'm building a ShaderData plugin, that at first just reads a TEXTURE parameter, extracts a BaseBitmap from it on InitRender() and samples it on Output(). I added it to a material's Color Texture, but the result is strange.

      As I understand, the TEXTURE resource parameter is internally a STRING. When I get from the node, it contains only the file name, not the path. Then we need to use GenerateTexturePath() to find out where it is.

      How can we resolve a texture that is not on the same path as the project, as the parameter does not know where it came from?

      In my case, the texture IS o the same folder.
      The attribute preview works, it can sample the texture.
      The material's Texture shader link preview also works.
      The material preview doesn't, it does not find the texture.
      And objects in the scene using the material also do not get the texture.

      What's missing here?
      This is how I get the texture path:

      sh->GetParameter( textureParamId, data, DESCFLAGS_GET_0 );
      const auto textureName = data.GetString(); // This returns only the file name, not the path
      auto doc = sh->GetDocument();
      
      Filename textureFullPath;
      GenerateTexturePath( doc->GetDocumentPath() + doc->GetDocumentName(), Filename( textureName ), Filename(), &textureFullPath );
      

      Thanks,
      Roger

      1 Reply Last reply Reply Quote 0
      • rsodreR
        rsodre
        last edited by rsodre

        This renders the texture on the object and material preview, nd solved all my problems
        Note that this call is very different from the recommended on the TEXTURE reference (needs update).

        bool FindTextureFullPath( BaseDocument* doc, const String& textureName, Filename& result )
        {
        	if( GenerateTexturePath( doc->GetDocumentPath() , Filename( textureName ), Filename(), &result ) )
        		return true;
        	return GenerateTexturePath( GetActiveDocument()->GetDocumentPath() , Filename( textureName ), Filename(), &result );
        }
        
        1 Reply Last reply Reply Quote 0
        • ManuelM
          Manuel
          last edited by

          hi,

          when you define your texture, it will ask you if you want to copy to the working directory or not.
          This seems to be based on if it can find it or not.

          GenerateTexturePath() will try to find it, including the file you can define in the preferences (file, path, file asset)
          So if like me you include c:\ that will be super slow but it will find your texture.

          If your texture is set to a relative path and not in one of those directory it will not be found.

          The same directory and the tex subfolder are include by default.

          Using this kind of code seems to work.

          	if (sh->GetParameter(DescID(ID_PC13203_TEXTURE), data, DESCFLAGS_GET::NONE))
          		{
          			const maxon::String texturePath = data.GetString();
          			if (texturePath.IsPopulated())
          			{
          				Filename texturePathfn;
          				if (GenerateTexturePath(doc->GetDocumentPath(), Filename(texturePath), Filename(), &texturePathfn, nullptr))
          //					mytexture->Init(texturePathfn);
          					ApplicationOutput("path file is @", texturePathfn);
          				else
          					ApplicationOutput("path not found");
          			}
          
          		}
          		
          

          And yes, the documentation is strange i will update it 🙂

          Cheers
          Manuel.

          MAXON SDK Specialist

          MAXON Registered Developer

          1 Reply Last reply Reply Quote 0
          • rsodreR
            rsodre
            last edited by

            Thanks, seems to be working now, thanks.

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