This is the way to set an environment from code in Rhino 5:
var environment = (RenderEnvironment)RenderContent.LoadFromFile(path);
RenderEnvironment.CurrentEnvironment = environment;
But for Rhino 6, it’ doesn’t work (only one time per execution, the first time) the class is marked as deprecated and says: Use RhinoDoc.ActiveDoc.CurrentEnvironment
If you ‘dot’ into RhinoDoc.ActiveDoc.CurrentEnvironment you’ll find ForBackground, ForLighting and ForReflectionAndRefraction. These are the three you’ll want to use. They correspond to 360° Environment, Custom Skylight Environment and Custom Reflection Environment.
RhinoDoc.ActiveDoc.CurrentEnvironment.ForBackground = RenderContent.LoadFromFile(filePath) as RenderEnvironment;
RhinoDoc.ActiveDoc.CurrentEnvironment.ForLighting = RenderContent.LoadFromFile(filePath) as RenderEnvironment;
RhinoDoc.ActiveDoc.CurrentEnvironment.ForReflectionAndRefraction = RenderContent.LoadFromFile(filePath) as RenderEnvironment;
So the environment is actually changing but it’s not set as background, furthermore if you take a look to rendering tab the environment does not appear there:
I just ran my regression tester script in the (regression.py (23.0 KB)) in which I extensively use environments. Here also bundled with the necessary data files raytraced_regression_tests.7z (9.7 MB).
Although this is in Python the same holds still for other .NET languages like C#.
The interesting section is method prepare_model from lines 238 through 318, specifically 278-306. You can ensure the correct background style is set in the render settings (279-280).
With the script I generate all combinations of settings I’m interested in, and generate a huge amount of 3dm-files based on that. This is all to test environments, skylight, sun usage and groundplane. This all seems to work fine with the current public Release Candidate ( Rhino 6 SR0 2018-1-12 (Rhino WIP, 6.0.18012.13241, Git hash:master @ 00ae144185bd9d3bd331a5464cb37a9e051f7258)
)
If you have a small plug-in code that still shows the problem can you please share it so I can test?
/Nathan
P.S. Never mind the messy test code. Evolution wasn’t kind to it.
Thanks for the code, it very close to the code I did but it’s still not setting it as background, I attach you an example plugin, sometimes it crashes, without throwing any exception and sometimes work but without applying it as background.
var env = RenderContent.LoadFromFile(path) as RenderEnvironment;
if (env != null && RhinoDoc.ActiveDoc.RenderEnvironments.Add(env))
{
RhinoDoc.ActiveDoc.CurrentEnvironment.ForBackground = env;
RhinoDoc.ActiveDoc.CurrentEnvironment.ForLighting = env;
RhinoDoc.ActiveDoc.CurrentEnvironment.ForReflectionAndRefraction = env;
}
The environment must be added to the document first before it is set as current. Otherwise, the current environment is pointing to an object that will - at some point - get collected.
@nathanletwory Im poking a stick at cycles specifically, to build a little window for all its settings and a few utilities like rotating the environmet etc live. Is there a rhinocommon settings document for cycles anywhere? Im coming up empty.
Am I even close (for example I cant find the setting that controls caustics in cycles? )
And just so you know: Raytraced/Cycles doesn’t react on the EngineSettings automatically - you’ll have to toggle the display mode to say Wireframe and back to Raytraced.
This may be improved in the future (v7 or later).
Also settings may change over time as well, so don’t get too hung up on them