[Plugin request] Better fog control
-
Greetings.
I know that sounds ridiculous, but is it possible to make a plugin that will allow to resize the window of Fog settings?
At the moment it's looking like this:But it can't be resized. And that can be a problem if you'll need, for example, a gradient from 0% to 100% in a range of 15 centimeters, - it's just not possible to place sliders with sufficient precision for that. I think the minimal result would be something like 1 meter, anything less is practically impossible to achieve. So I really wish I could do something like that:
Or maybe some other way to set fog range in very precise value, e.g. a new window with numerical input.
Why do I need to set such ridiculous values? It's simple: actually, Fog is a very convenient feature to bake height maps from your models. And if you're intending to bake a metal panel of a mere 5 centimeter height, it's currently impossible just because slider is not precise enough.
Here's an example of how to use fog. Here is the sample model (50 meters high, unfortunately):
I change the camera position to vertical and switch off the perspective, change the fog color to black and adjust the fog range so that the white color will be on the highest point of the object and the lowest point will fade into black. This gives us a great image:
Practically, it is a height map. It can be used for tons of applications, for example as a displacement map or as a base for normal map generation:
Looks great, isn't it?
Both folks who are using SketchUp as for visualization (e.g. with V-Ray) and folks who intend to export objects for an outside use (e.g. game developers) will benefit from the ability to bake simple height maps.
Thanks in advance for any answers!
P.S. Whoops, haven't thought of that before - maybe there are Ruby Console variables for setting fog values? Would be awesome if they exist, then no plugin would be required at all.
-
The Fog settings can be accessed from the Ruby Console, although it might awkward. For example:
Sketchup.active_model.rendering_options["FogStartDist"] = 0.0
Other "Fog" settings can be found here, although some of the given names are not correct:
http://code.google.com/apis/sketchup/docs/ourdoc/renderingoptions.htmlThe correct Fog settings names are (with sample types:)
["DisplayFog", false]
["FogColor", Color(196, 207, 210, 255)]
["FogEndDist", -1.0]
["FogStartDist", -1.0]
["FogUseBkColor", true] -
Thank you very much, Jim, I will try to make it work with these
-
Copy&Paste this code into a file called
TIGfog.rb
in the ../Plugins folder.<span class="syntaxdefault">module TIG<br />def self</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">fog</span><span class="syntaxkeyword">()<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment">###<br /></span><span class="syntaxdefault"> model</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_model<br /> ros</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">rendering_options<br /> display</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">ros</span><span class="syntaxkeyword">[</span><span class="syntaxstring">"DisplayFog"</span><span class="syntaxkeyword">]<br /></span><span class="syntaxdefault"> if display<br /> display</span><span class="syntaxkeyword">=</span><span class="syntaxstring">"Yes"<br /></span><span class="syntaxdefault"> else<br /> display</span><span class="syntaxkeyword">=</span><span class="syntaxstring">"No"<br /></span><span class="syntaxdefault"> end<br /> color</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">ros</span><span class="syntaxkeyword">[</span><span class="syntaxstring">"FogColor"</span><span class="syntaxkeyword">].</span><span class="syntaxdefault">to_a<br /> enddist</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">ros</span><span class="syntaxkeyword">[</span><span class="syntaxstring">"FogEndDist"</span><span class="syntaxkeyword">].</span><span class="syntaxdefault">to_l<br /> startdist</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">ros</span><span class="syntaxkeyword">[</span><span class="syntaxstring">"FogStartDist"</span><span class="syntaxkeyword">].</span><span class="syntaxdefault">to_l<br /> rgb</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">color</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">].</span><span class="syntaxdefault">to_s</span><span class="syntaxkeyword">+</span><span class="syntaxstring">","</span><span class="syntaxkeyword">+</span><span class="syntaxdefault">color</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">].</span><span class="syntaxdefault">to_s</span><span class="syntaxkeyword">+</span><span class="syntaxstring">","</span><span class="syntaxkeyword">+</span><span class="syntaxdefault">color</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">2</span><span class="syntaxkeyword">].</span><span class="syntaxdefault">to_s<br /> bkcolor</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">ros</span><span class="syntaxkeyword">[</span><span class="syntaxstring">"FogUseBkColor"</span><span class="syntaxkeyword">]<br /></span><span class="syntaxdefault"> if bkcolor<br /> bkcolor</span><span class="syntaxkeyword">=</span><span class="syntaxstring">"Yes"<br /></span><span class="syntaxdefault"> else<br /> bkcolor</span><span class="syntaxkeyword">=</span><span class="syntaxstring">"No"<br /></span><span class="syntaxdefault"> end<br /> prompts</span><span class="syntaxkeyword">=[</span><span class="syntaxstring">"Display ? "</span><span class="syntaxkeyword">,</span><span class="syntaxstring">"End Distance; "</span><span class="syntaxkeyword">,</span><span class="syntaxstring">"Start Distance; "</span><span class="syntaxkeyword">,</span><span class="syntaxstring">"Color=R,G,B "</span><span class="syntaxkeyword">,</span><span class="syntaxstring">"Use Background Color ? "</span><span class="syntaxkeyword">]<br /></span><span class="syntaxdefault"> values</span><span class="syntaxkeyword">=[</span><span class="syntaxdefault">display</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">enddist</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">startdist</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">rgb</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">bkcolor</span><span class="syntaxkeyword">]<br /></span><span class="syntaxdefault"> drops</span><span class="syntaxkeyword">=[</span><span class="syntaxstring">"Yes|No"</span><span class="syntaxkeyword">,</span><span class="syntaxstring">""</span><span class="syntaxkeyword">,</span><span class="syntaxstring">""</span><span class="syntaxkeyword">,</span><span class="syntaxstring">""</span><span class="syntaxkeyword">,</span><span class="syntaxstring">"Yes|No"</span><span class="syntaxkeyword">]<br /></span><span class="syntaxdefault"> titl</span><span class="syntaxkeyword">=</span><span class="syntaxstring">"Fog Settings"<br /></span><span class="syntaxdefault"> results</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">inputbox</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">prompts</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> values</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> drops</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> titl</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment">###<br /></span><span class="syntaxdefault"> return nil if not results<br /> </span><span class="syntaxcomment">###<br /></span><span class="syntaxdefault"> display</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">results</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">]<br /></span><span class="syntaxdefault"> if display</span><span class="syntaxkeyword">==</span><span class="syntaxstring">"No"<br /></span><span class="syntaxdefault"> ros</span><span class="syntaxkeyword">[</span><span class="syntaxstring">"DisplayFog"</span><span class="syntaxkeyword">]=</span><span class="syntaxdefault">false<br /> else<br /> ros</span><span class="syntaxkeyword">[</span><span class="syntaxstring">"DisplayFog"</span><span class="syntaxkeyword">]=</span><span class="syntaxdefault">true<br /> end<br /> </span><span class="syntaxcomment">###<br /></span><span class="syntaxdefault"> enddist</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">results</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">]<br /></span><span class="syntaxdefault"> ros</span><span class="syntaxkeyword">[</span><span class="syntaxstring">"FogEndDist"</span><span class="syntaxkeyword">]=</span><span class="syntaxdefault">enddist<br /> </span><span class="syntaxcomment">###<br /></span><span class="syntaxdefault"> startdist</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">results</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">2</span><span class="syntaxkeyword">]<br /></span><span class="syntaxdefault"> ros</span><span class="syntaxkeyword">[</span><span class="syntaxstring">"FogStartDist"</span><span class="syntaxkeyword">]=</span><span class="syntaxdefault">startdist<br /> </span><span class="syntaxcomment">###<br /></span><span class="syntaxdefault"> rgb</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">results</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">3</span><span class="syntaxkeyword">]<br /></span><span class="syntaxdefault"> rgb</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">rgb</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">tr</span><span class="syntaxkeyword">(</span><span class="syntaxstring">' '</span><span class="syntaxkeyword">,</span><span class="syntaxstring">''</span><span class="syntaxkeyword">).</span><span class="syntaxdefault">split</span><span class="syntaxkeyword">(</span><span class="syntaxstring">","</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> r</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">rgb</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">].</span><span class="syntaxdefault">to_i<br /> g</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">rgb</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">].</span><span class="syntaxdefault">to_i<br /> b</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">rgb</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">2</span><span class="syntaxkeyword">].</span><span class="syntaxdefault">to_i<br /> col</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">Sketchup</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Color</span><span class="syntaxkeyword">.new(</span><span class="syntaxdefault">r</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">g</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">b</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> ros</span><span class="syntaxkeyword">[</span><span class="syntaxstring">"FogColor"</span><span class="syntaxkeyword">]=</span><span class="syntaxdefault">col<br /> </span><span class="syntaxcomment">###<br /></span><span class="syntaxdefault"> bkcolor</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">results</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">4</span><span class="syntaxkeyword">]<br /></span><span class="syntaxdefault"> if bkcolor</span><span class="syntaxkeyword">==</span><span class="syntaxstring">"No"<br /></span><span class="syntaxdefault"> ros</span><span class="syntaxkeyword">[</span><span class="syntaxstring">"FogUseBkColor"</span><span class="syntaxkeyword">]=</span><span class="syntaxdefault">false<br /> else<br /> ros</span><span class="syntaxkeyword">[</span><span class="syntaxstring">"FogUseBkColor"</span><span class="syntaxkeyword">]=</span><span class="syntaxdefault">true<br /> end<br /> </span><span class="syntaxcomment">###<br /></span><span class="syntaxdefault"> model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_view</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">invalidate<br /> </span><span class="syntaxcomment">###<br /></span><span class="syntaxdefault">end<br />end</span>
To use type
TIG.fog
in the Ruby Console and adjust the settings in the dialog.
Options:
Display - Yes|No to display fog
EndDist - in current units, -1 for 'infinity'
StartDist - in current units, -1 for <=0
ColorRGB - to set fog color - three integers 0 to 255, separated by commas
Background - Yes|No to use background color instead
Note it cannot be 'undone'!
You'll need to rerun it to revert.
If it does what you want I could package it as a .rb file etc in its own thread... -
Another method for creating bump maps (no fog needed):
-
This method http://forums.sketchucation.com/viewtopic.php?p=149747#p149747 [from within that thread] by RickW is very simple too... I have used it.
-
First of all, thanks a lot, TIG, I really appreciate your help! I've started to ask my friends familiar with programming about how to make a Ruby script based on Jim's advices, but you've actually wrote the whole thing already! It really feels great to be there, in such a friendly community.
Plugin works great!
Hovewer, I feel really, really dumb for not thinking about the method proposed by RickW earlier. It is really perfect: incredibly simple and producing really great results, especially with high-res gradient image.
Still, I think your plugin, TIG, deserves a release: as the default fog control window is perhaps insufficiently precise in some other areas - for example, for some styles of architectural visualization. I imagine it would be very useful with one small addition - the detection of a distance to the camera from a certain point on screen. I don't know if API allows to read that, but if it is, it would be awesome: you just click on some vertex and get a distance to it, allowing you to precisely configure the fog distances for your needs (or perhaps other things, like Depth of Field falloff range in V-Ray). I don't know, maybe distance determination would work better as a separate window (or even separate plugin), or maybe it'll be handy to instantly paste it to the fog values. Oh, well, maybe such a plugin already exists? Nevertheless, great work and thank you again!
Advertisement