Get Environment Texture in RhinoCommon


#1

Hi

I am trying to get the Background Image filename from the Environments Panel using RhinoCommon. I cannot work out how to get it from Rhino.Render.RenderEnvironment.CurrentEnvironment. How is this done pls?

Thanks


(Andrew le Bihan) #2
    using Rhino.Render;
    using Rhino.Render.Fields;        

    RenderContent tex = RenderEnvironment.CurrentEnvironment.FindChild("texture");

    if (null != tex)
    {
        //This will work if it is a bitmap texture or an HDR/EXR, and it 
        //will fail if the texture is procedural or some other 3rd party
        //texture that doesn't support the "filename" parameter.

        Field field = tex.Fields.GetField("filename");

        string filename = field.ToString();
    }

#3

That works - thank you so much.


#4

Hi Andy

A follow-on question - is it possible to iterate all the Child’s (children) of the RenderEnvironment.CurrentEnvironment?

Thanks

Paul


#5

Another follow-on…

How do you get the environment color if the Environment is set to Background = “Solid Color”. And how to you get the environment color if the Environment is set to Background = “Environment” and no background image is loaded (ie. just looking to get the background color.

Thanks

Paul


(Andrew le Bihan) #6

The best way to get the background color for an environment that you don’t know how to render is this:

Rhino.Render.SimulatedEnvironment sim = new Rhino.Render.SimulatedEnvironment();
Rhino.Render.RenderEnvironment.CurrentEnvironment.SimulateEnvironment(ref sim, true);

System.Drawing.Color col = sim.BackgroundColor;

You can also get an LDR version of the texture that way too. If you are not interested in the texture, it is a little faster to call SimulateEnvironment with “true” as the second parameter because it doesn’t produce the bitmap - so if you want the bitmap, use false.


(Andrew le Bihan) #7

Rhino.Display.BackgroundStyle bs = Rhino.RhinoDoc.ActiveDoc.RenderSettings.BackgroundStyle;
if (bs == Rhino.Display.BackgroundStyle.SolidColor)
{
System.Drawing.Color color = Rhino.RhinoDoc.ActiveDoc.RenderSettings.BackgroundColorTop;
}


#8

Works perfectly - thank you Andy.