TEXTURE resource parameter
-
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 -
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 ); }
-
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. -
Thanks, seems to be working now, thanks.