How to change material EnvironmentTexture?

HI;

Rhino.Render.RenderMaterial rn = doc.RenderMaterials[0];
rn.BeginChange(RenderContent.ChangeContexts.Program);
rn.SetParameter("diffuse", System.Drawing.Color.LightBlue);
rn.SetParameter("reflectivity", 1.0);
rn.SetParameter("reflectivity-color", System.Drawing.Color.LightBlue);
rn.SetParameter("shine", System.Drawing.Color.LightBlue);
rn.SetParameter("EnvironmentTexture", bmppa);
rn.EndChange();

IN my code, I can successfully set up some parameters off matarial, but can’t set EnvironmentTexture path, how can I do?

Hi @suc_kiet, does below work ?

env_texture = Rhino.Render.RenderContentType.NewContentFromTypeId(
                             System.Guid("57E0ED08-1907-4529-B01B-0C4A242455FD"), 
                             scriptcontext.doc
                             )

context = Rhino.Render.RenderContent.ChangeContexts.Program
    
env_texture.BeginChange(context)
env_texture.SetParameter("filename", r"C:\MyFolder\MyFile.jpg")
env_texture.EndChange()
    
rn.BeginChange(context)
rn.SetChild(env_texture, "environment-texture")
rn.EndChange()

rn.SetChildSlotOn("environment-texture", True, context)
rn.SetChildSlotAmount("environment-texture", 100, context)

You might remove this from your code:

rn.SetParameter("EnvironmentTexture"), bmppa);

For setting colors, you need Color4f, this line in your code will probably not work:

rn.SetParameter("diffuse", System.Drawing.Color.LightBlue);

Note that “shine” does not expect a color but a float between 0 and 1 eg:

rn.SetParameter("shine", 0.70)

To set this color, use “specular” instead like so:

rn.SetParameter("specular", Rhino.Display.Color4f.White)

_

c.

Hi @clement ;
Thank you, it is very helpful.