BUG (?) Convert PBR material to renderMaterial

I’m trying to convert a Rhino material read from a external file using Rhino.FileIO.File3dm.Read(filePath) using Rhinocommon.

I can’t figure out any way to convert this from original Rhino materials in the File3dm (in memory) to a RenderMaterial, in order to add it in the active document.

I have tried using materials RenderMaterial property: I certainly can obtain a renderMaterial object, but once added to the document’s renderMaterialTable, it happens that it is no more a PBR material, as it originally was.

Is this a bug or is something expected to happen?
Has anyone tried to import a PBR material from a external file using Rhinocommon?

thanks

import Rhino

dlg = Rhino.UI.OpenFileDialog()
if dlg.ShowOpenDialog():
        path = dlg.FileName
        assetFile = Rhino.FileIO.File3dm.Read(path)
        for mat in assetFile.AllMaterials:
            renderMat = mat.RenderMaterial
            Rhino.RhinoDoc.ActiveDoc.RenderMaterials.Add(renderMat)

OriginFile.3dm (293.9 KB)

Please, can anyone have a look to this one? Is it there any chance to expect that renderMaterial property from material will respect the “material type”?
thanks

Hi - this is actually tricky in the current WIP, but from tomorrow should be a lot easier. Once the WIP comes out, I will show how it can be done.

2 Likes

Thanks Andrew!

OK -you should now be able to call RenderMaterial.CreateBasicMaterial and, if the incoming material is a PBR material, the resulting RenderMaterial will be a Physically Based material.