Need help modifying RhinoRenderMaterial to change texture maps

Hello everyone,

I am currently working on a project where I need to modify RhinoRenderMaterials to include custom texture maps. I have been able to use the SetParameter() method to modify the material’s color and other properties, but I am having trouble changing the texture maps.

I have tried using the SetChildSlotParameter() method and have looked through the RhinoCommon documentation, but I can’t seem to find a working solution. The method doesn’t throw any errors, but the texture maps don’t seem to be updated.

Can anyone give me some direction or advice on how to properly update the texture maps for RhinoRenderMaterials?

Here’s the code snippet that I’ve been using:
Hello everyone,

I am currently working on a project where I need to modify RhinoRenderMaterials to include custom texture maps. I have been able to use the SetParameter() method to modify the material’s color and other properties, but I am having trouble changing the texture maps.

I have tried using the SetChildSlotParameter() method and have looked through the RhinoCommon documentation, but I can’t seem to find a working solution. The method doesn’t throw any errors, but the texture maps don’t seem to be updated.

Can anyone give me some direction or advice on how to properly update the texture maps for RhinoRenderMaterials?

Here’s the code snippet that I’ve been using:

using Rhino.DocObjects;
using Rhino.Render;

// get the active document
RhinoDoc doc = RhinoDoc.ActiveDoc;

// get the material object
ObjRef material_obj = pick_obj(); // Here you should provide your own method to pick an object in Rhino
RhinoObject rhino_obj = material_obj.Object();
Material material = rhino_obj.RenderMaterial;

 material.BeginChange(RenderContent.ChangeContexts.Program);
// set the diffuse color
material.SetParameter("diffuse",  new Color4f(0,0,0,0););

// set the texture map
material.SetChildSlotParameter("bitmap-texture", "filename", "D:\\03.png",RenderContent.ExtraRequirementsSetContexts.Program);
 material.EndChange();

Hi @401247906,

it depends on which render material type is assigned. Below Python example changes the texture for the diffuse Color slot of a rendermaterial of type “Custom”. Basically it does get the “bitmap-texture” slot of the rendermaterial and then changes the filename using SetParameter().

Note that you need to do 2 things to test below script in the script editor (_EditPythonScript):

  1. Create any object and assign a rendermaterial of type Custom with a Color texture
  2. Change the new_file_name in line 57 of the script to an existing texture file

I’ve tested this in Rhino 7 (Windows) only.

ChangeCustomMaterialColorTexture.py (2.2 KB)

_
c.