-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcreate_hdri_environment.html
96 lines (89 loc) · 4.86 KB
/
create_hdri_environment.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<!DOCTYPE html>
<html>
<head>
<meta property="og:description" content="A literate program in the rhipy repository." />
<meta name="description" content="A literate program in the rhipy repository." />
<meta name="author" content="Nathan 'jesterKing' Letwory">
<link rel="stylesheet" type="text/css" href="./style.css">
</head>
<body>
<h1>Create an HDRi environment</h1>
<p><em>written by Nathan 'jesterKing' Letwory</em></p>
<p>The <code>RenderEnvironment</code> represents environments in Rhino. To create an
environment that uses an HDRi texture we'll be creating the <code>RenderTexture</code> that
holds that HDRi image, and the <code>RenderEnvironment</code> to which we will assign that
texture.</p>
<p>We'll be creating the <code>RenderEnvironment</code> using
<a href="https://mcneel.github.io/rhinocommon-api-docs/api/RhinoCommon/html/M_Rhino_Render_RenderContent_Create_5.htm"><code>RenderContent.Create</code></a>
that takes a GUID, in this case the <code>RenderEnvironment</code> GUID which is <code>ba51ce00-ba51-ce00-ba51-ceba51ce0000</code>, content chooser flags that we leave at <code>NONE</code> and a <code>RhinoDoc</code> instance that we get from <code>scriptcontext</code>.</p>
<p>To create the HDR render texture we'll be using
<a href="https://mcneel.github.io/rhinocommon-api-docs/api/RhinoCommon/html/M_Rhino_Render_RenderContentType_NewContentFromTypeId.htm"><code>RenderContentType.NewContentFromTypeId</code></a>
to which we will pass <code>Rhino.Render.ContentUuids.HDRTextureType</code>.</p>
<div class="codefragment">
<div class="fragmentname"><<create an HDRi environment.*>>= ./create_hdri_environment.py $</div>
<div class="code">
<pre><code><span class="hljs-keyword">import</span> scriptcontext <span class="hljs-keyword">as</span> sc
<span class="hljs-keyword">import</span> Rhino
<span class="hljs-keyword">import</span> System
file_dialog = Rhino.UI.OpenFileDialog()
file_dialog.Filter = <span class="hljs-string">"EXR (*.exr)|*.exr"</span>
<span class="hljs-keyword">if</span> file_dialog.ShowDialog():
<span class="literate-tag-name"><<create HDR texture>></span>
<span class="literate-tag-name"><<create environment>></span>
<span class="literate-tag-name"><<assign HDR to environment>></span>
</code></pre>
</div>
</div><h2>Creating the HDR texture</h2>
<p>As mentioned earlier we'll be directly creating the texture through
<code>RenderContentType</code>, giving it the correct GUID.</p>
<div class="codefragment">
<div class="fragmentname"><<create HDR texture>>= </div>
<div class="code">
<pre><code>render_texture = Rhino.Render.RenderContentType.NewContentFromTypeId(
Rhino.Render.ContentUuids.HDRTextureType
)
</code></pre>
</div>
</div><p>Once we have a new instance we set the <code>filename</code> parameter to a string that is
the path to an HDRi file. To set parameters we need to bracket the call to
<code>SetParameter</code> in a <code>BeginChange</code> and <code>EndChange</code> pair.</p>
<p>Additionally we'll also change the texture saturation to show how that can be
done. The parameter name is <code>rdk-texture-adjust-saturation</code>.</p>
<div class="codefragment">
<div class="fragmentname"><<create HDR texture>>=+ </div>
<div class="code">
<pre><code>render_texture.BeginChange(Rhino.Render.RenderContent.ChangeContexts.Program)
render_texture.SetParameter(<span class="hljs-string">"filename"</span>, file_dialog.FileName)
render_texture.SetParameter(<span class="hljs-string">"rdk-texture-adjust-saturation"</span>, <span class="hljs-number">0.0</span>)
render_texture.EndChange()
</code></pre>
</div>
</div><h2>Creating the environment</h2>
<div class="codefragment">
<div class="fragmentname"><<create environment>>= </div>
<div class="code">
<pre><code>render_environment = Rhino.Render.RenderContent.Create(
System.Guid(<span class="hljs-string">'ba51ce00-ba51-ce00-ba51-ceba51ce0000'</span>),
Rhino.Render.RenderContent.ShowContentChooserFlags.NONE,
sc.doc
)
</code></pre>
</div>
</div><h2>Assigning the texture</h2>
<p>Assigning the texture to the environment we do using <code>SetChild</code> to the child
with name <code>texture</code>.</p>
<div class="codefragment">
<div class="fragmentname"><<assign HDR to environment>>= </div>
<div class="code">
<pre><code>render_environment.BeginChange(Rhino.Render.RenderContent.ChangeContexts.Program)
render_environment.SetChild(render_texture, <span class="hljs-string">"texture"</span>)
render_environment.EndChange()
</code></pre>
</div>
</div><h2>The final script</h2>
<p>The Python-only code for this literate program can be found <a href="https://github.com/jesterKing/rhipy/blob/master/create_hdri_environment.py">here</a>.</p>
<script type="module">
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.esm.min.mjs';
</script>
</body>
</html>