Can I control Environment rotation with a script?


#1

Hi, I have tried to find the settings to control an Environment rotation through scripting (Ideally I would like to make a panel with some sliders for fast manipulation, but I can not find it in Rhino Common.

Thanks!


(Nathan 'jesterKing' Letwory) #2

You’d get the RenderEnvironment, then use SetParameter(“azimuth”, newrotval);

Drag an environment from Rhino to a folder in Windows Explorer so that you get the .renv. Open it in a text editor. You’ll be able to find all parameters you can set. The same you can do with materials and textures, as they are all render contents.

Especially handy when you want to programmatically fiddle with custom RenderContent. This way you don’t need to know the type, nor need access to the class definition.


#3

Ouch… that didn’t make enough sense to me…

It seems it needs three parameters and I don’t know how to find the identification of the active Environment… (It needs the RenderContent)


(Nathan 'jesterKing' Letwory) #4

I’m going to talk V6 here, I don’t know V5, but maybe this information helps you find the necessary bits and pieces for V5.

To get current environment you use RhinoDoc.CurrentEnvironment. You can query for a specific type of environment, i.e. ForBackground, ForLighting, ForReflectionAndRefraction.

That will give you a RenderEnvironment. I just checked my environment handling code in RhinoCycles, and it turns out that I get the RenderTexture from the RenderEnvironment. It is this texture that will give you the mapping information.

For RenderEnvironment re you’d RenderTexture rt = re.FindChild("texture") as RenderTexture;

If a texture is set in the environment re will be not null. Now from this RenderTexture you get the parameters, and you set the parameters:

var azimuth = re.GetParameter("azimuth"); This will be an object that you’ll have to System.Convert.ToDouble

Setting then goes like thus:

re.SetParameter("azimuth", newdoubleval);

In V6 you’ll have to bracket changes with

re.BeginChange(RenderContent.ChangeContext cc); followed by a set of re.SetParameter() closed off with a re.EndChange()

You can see how I access RenderEnvironment texture in RhinoCycles bitmap converter code.

If you still need V5 mechanisms instead I’ll be able to check only on Monday, as my dev machine in the office seems to have fallen off the grid - I can’t connect to it.

Hope this helps,

/Nathan


(Nathan 'jesterKing' Letwory) #5

@Holo, did this code help you?


#6

I hope it will, tha last week my family had the cold and yesterday I got struck, so my mind clouded and wasn’t working at full speed… I’ll see if I can cook it together tonight :slight_smile:


(Nathan 'jesterKing' Letwory) #7

Ah, ok. No hurries (: Tend to the family and your brain cells. I can wait. (I think).


#8

Ugh… I seriously lack the basic skills to understand this level of coding… :frowning:
Jumping from Rhinoscript to Python was tough enough so sorry for the basic questionbecause I don’t know how to querry …

When I try the following then I get an error in line 4:
Message: ‘getset_descriptor’ object has no attribute ‘FindChild’


import Rhino
re = Rhino.RhinoDoc.CurrentEnvironment
print re
rt = re.FindChild("texture")
print rt


(Nathan 'jesterKing' Letwory) #9

Is this V5 or V6? For the latter I definitely can try creating a Python script, for the former you’ll have to call out to the oldies, maybe @pascal .


#10

Hi @Holo,

you might look here, it works in V5.

_
c.


#11

Hi @nathanletwory,

could you file a bug for V6 please. My script above also works in V6 but when the dialog to enter the env rotation is open while running the script, the field for the rotation does not update. If i go one step back to the material controls and then return to the texture controls, it is updated.

_
c.


(Nathan 'jesterKing' Letwory) #12

Sounds like Skylight: HDRI Intensity setting discrepency?, in which case it is fixed and will be in next BETA.

@clement, note that the RenderEnvironment.CurrentEnvironment method you use in your script uses obsoleted method. You should instead use RhinoDoc.CurrentEnviroment to access either ForBackground, ForLighting or ForReflectionAndRefraction.


#13

It is for V6, and a good start is just to know how to access either ForBackground, ForLighting or ForReflectionAndRefraction :slight_smile:

I am working on the slider UI now, and will probably hit my head against a few walls there too, but we’ll see.


(Nathan 'jesterKing' Letwory) #14

Without testing, just thinking out loud (because doing some fun Sunday evening/night coding with wrapping ToonBsdf node), I’d use the scriptcontext to access current doc: scriptcontext.doc.CurrentEnvironment.ForBackground I think I actually use that in one of my regression.py scripts for testing changes in a larger data set.


#15

Thanks, perfect!
Happy coding!

import scriptcontext
print scriptcontext.doc.CurrentEnvironment.ForBackground
print scriptcontext.doc.CurrentEnvironment.ForReflectionAndRefraction
print scriptcontext.doc.CurrentEnvironment.ForLighting

Returns this on a new document:

None
<Rhino.Render.NativeRenderEnvironment object at 0x000000000000002B [Rhino.Render.NativeRenderEnvironment]>
<Rhino.Render.NativeRenderEnvironment object at 0x000000000000002C [Rhino.Render.NativeRenderEnvironment]>


#16

@nathanletwory, as i wrote above my script is for Rhino 5 not 6. If i try to access below in V5:

scriptcontext.doc.CurrentEnvironment.ForBackground

it returns an error:

Message: ‘RhinoDoc’ object has no attribute ‘CurrentEnvironment’

When i run my example from above in V6 i do not get any deprication warning. It may be useful für us scripters to be informed like for other outdated code snippets.

_
c.


#17

Hi @Holo, by default a solid color background is used. If you change that to “360° Environment” you should get returned something for

scriptcontext.doc.CurrentEnvironment.ForBackground

_
c.


#18

Ok, so I finally took time to sit down and fiddle with this.

And this gives a 360 spin of the environment.

import scriptcontext
import System
import rhinoscriptsyntax as rs

print "ForBackground= "+str( scriptcontext.doc.CurrentEnvironment.ForBackground )
print "ForReflectionAndRefraction= "+str( scriptcontext.doc.CurrentEnvironment.ForReflectionAndRefraction )
print "ForLighting= "+str( scriptcontext.doc.CurrentEnvironment.ForLighting )

re=scriptcontext.doc.CurrentEnvironment.ForReflectionAndRefraction

rt = re.FindChild("texture")
print "RenderTexture= "+str( rt )

azimuth = System.Convert.ToDouble( rt.GetParameter("azimuth") )

print  azimuth

newAzimuth = 0

Rad=6.2831853
steps= 20

for i in range (steps):
    newAzimuth += Rad/steps
    rt.SetParameter("azimuth", newAzimuth)
    rs.Redraw()

But on my systems this laggs instead of giving a steady flow of frames. Do you know what causes that? (gtx1070, so it has enough horse power)


(Nathan 'jesterKing' Letwory) #19

Looks smooth to me, especially if you use more than 20 steps with smaller increase, here a version with a full 360° using a 1° rotation over 360 steps.


#20

Ok, thanks. On my other machine it looks smoother but the moment I move the mouse it goes to a halt, then starts again when I stop moving it.