Is there a way in the SDK to load a specific material (*rmtl) file from disk and add it to the material table?
One idea was to use a scripted command from the SDK - I noticed in another topic, that there should be a command “RenderLoadMaterialFromFile”, but Rhino says “command not found”.
Of course it would also be good in the other direction - so I would like to export a specific material from the Rhino material table to a .rmtl file.
@johnc, can you help with this?
You can use this to do the entire job:
/** Loads a content from a library file and attaches it to a document, hence the returned
pointer is to a const content. Do not const-cast or attempt to delete the retured pointer.
To make changes to the content, call its BeginChange() method.
\param doc is the document to attach the loaded content to.
\param wszFullPath is the full path to the file to be loaded.
\return a pointer to the loaded content or nullptr if an error occurred. /
RHRDK_SDK const CRhRdkContent RhRdkLoadPersistentContentFromFile(const CRhinoDoc& doc, const wchar_t* wszFullPath, bool bForceDownloadTextures = false);
thanks for the hint! I never used RHRDK_SDK before…
My question is now: How to get material parameters from the imported content? I did like the following:
CRhinoDoc* activeDoc = RhinoApp().ActiveDoc();
const CRhRdkContent *pMyContent = RhRdkLoadPersistentContentFromFile(*activeDoc, fileName);
const CRhRdkMaterial* pMaterial = static_cast<const CRhRdkMaterial*>(pMyContent);
const ON_Material &myMaterial = pMaterial->SimulatedMaterial(CRhRdkTexture::TextureGeneration::Skip);
Unfortunately the ON_Material contains just default parameters, so something is missing. So what would be the best or recommended way to get material parameters like ambient color, reflectivity etc.?
That should work. What RMTL file are you trying this with?
At the moment I’m just trying to import files from the installed Rhino material library, e.g.
MyUser\AppData\Roaming\McNeel\Rhinoceros\6.0\Localization\en-US\Render Content\Metal\Polished\Polished Chrome.rmtl
Later on we are planning to deliver and support some custom materials edited and saved by our users. Basic properties (w/o textures and other high sophisticated stuff) are ok for the moment. It is not really for rendering purpose, the goal is supporting structured individual object display. We have some other ways of structuring objects than layers, so we cannot just use the Rhino way (materials for individual objects or layers).
So you are going to be assigning materials using some other property, and you would like to draw in the display? You should be able to do that in a conduit.
In the meanwhile I’m able to import the .rmtl files successfully.
I have already a special display variant and a conduit, that is able to handle different material assignments to objects.
Thanks for the help!