[Plugin] Color by Slope

[Plugin] Color by Slope

Postby Chris Fullmer » Fri Jul 17, 2009 12:53 am

Hi, this is from a request here:
http://forums.sketchucation.com/viewtop ... 80&t=20626

This plugin will color faces based on their slope. You enter the RGB values for the max slope and minimum slopes.

This plugin OVERWRITES EXISTING MATERIALS. So don't use it on portions that you don't want to change their materials.

USAGE: Select loose geometry (inside of a group/component edit is ok). It only works on faces. Select the faces you want to color, then run the plugin from Plugins > Chris Fullmer Tools > Color by Slope. And it will color the selected faces. You will enter the RGB values for the 2 colors, and you also choose how many gradient steps to use. A high number will create a smooth gradient, whereas a low number will create a non-smooth gradient, but it makes it easier to see the major slope variations that exist. Thanks to ICEPAM for adding in some of these great features.

color by slope.png


This would be a good script to bundle with my color by z script. Maybe I'll do that in the future. Hope it helps,

Download:
http://www.smustard.com/script/ColorBySlope


Chris
0
Lately you've been tan, suspicious for the winter.
All my Plugins I've written
User avatar
Chris Fullmer 
SketchUp Team
SketchUp Team
 

Re: [Plugin] Color by Slope

Postby EarthMover » Fri Jul 17, 2009 1:56 am

Pretty cool Chris. Almost looks like specular highlights. Thanks!
0
3D Artist at Clearstory 3D Imaging
Guide Tool at Winning With Sketchup
Content Creator at Skapeup
User avatar
EarthMover 
Premium Member
Premium Member
 

Re: [Plugin] Color by Slope

Postby pilou » Fri Jul 17, 2009 2:17 am

Another cool plug :enlight:
0
Frenchy Pilou
Is beautiful that please without concept!
Speedy Galerie
User avatar
pilou 
Top SketchUcator
 

Re: [Plugin] Color by Slope

Postby orei » Fri Jul 17, 2009 10:07 am

i'm bit confused about this plugin.. what's the difference between this and color by z?? thanks a lot
0

orei 
 

Re: [Plugin] Color by Slope

Postby TIG » Fri Jul 17, 2009 10:20 am

To avoid loosing existing materials you could have an option to initially make a group of all of the selected faces (remembering their edges so it gets made properly), copy that group and immediately explode the original group back in place, then work on the copy-group's faces, colouring them by slope etc*... You could also have an option to hide the original geometry or move the copy-group to one side etc so what's been coloured is better seen....
[*This could idea also be applied to color_by_Z too...]

AND another plugin idea... Using similar methods work out the various angles of the faces' normals towards the sun's position and colour them 'hot' to 'cold' so you can see the solar-gain incident by face at that time of day / date... you could also make a shading algorithm to see if parts of the face were shaded by other geometry and if so add an extra face matching the shadow and colour that as if it were facing away from the sun ??? So many ideas so little time !!!
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [Plugin] Color by Slope

Postby icepam » Fri Jul 17, 2009 3:06 pm

You're an ace! thanks.
i had started hacking at your color-by-Z yesterday, learning ruby as i go, and managed to make color by steps, meaning it will ask you how many maximum colors you want and color the slopes accordingly. i couldn't figure out how to get the angle of the normal though until you posted this today. i had been using the z of the vector instead of its angle, so the results were off.

anyway, i finally merged both your plugins into the attached aa_color_by_slope.rb. i hope you don't mind, it's yours of course.

i made it ask for the start and end colors and the number of segments (max colors), which i limited to dividents of 90 to reduce hassle. i still don't understand why i can't get the 1st color the same in all variations on the numbers (for example if you go with green to red, and do tests for 2, 3, 9 segments, you will see that sometimes the starting green changes, although it shouldnt)

finally, thanks again for this Chris, and TIG: your ideas rock! (no pun intended, but i'm using this precisely to figure out buildable areas on a rocky site :) )
slopetest.jpg


-aa

EDIT: file removed, please see top post for download link
0

icepam 
 

Re: [Plugin] Color by Slope

Postby Chris Fullmer » Fri Jul 17, 2009 4:20 pm

Ahh, that's very cool. Thanks for adding those features. I had wanted to add user control over the start and end colors, but I really didn't have time when I wrote it. I had not considered step values, forcing only a certain amount of colors to be used. That would be quite heplful.

You could even code it to force certain slopes to certain colors. That could all be set up in a webdialog to make it simpler for the user to specify how they want to make it work.

But that's all over my head still. I'll figure it out eventually.

TIG, those improvements would be cool. I'm not going to get to them anytime soon, but feel free to do it if you'd like :thumb: I do have plans for eventually re-working color by z. So maybe when I get to it, I'll add this in the mix, along with web dialogs, and better options and control. But until then, feel free to hack away at this script :D

Chris
0
Lately you've been tan, suspicious for the winter.
All my Plugins I've written
User avatar
Chris Fullmer 
SketchUp Team
SketchUp Team
 

Re: [Plugin] Color by Slope

Postby Chris Fullmer » Fri Jul 17, 2009 4:25 pm

ok aa, I checked out your version, and thats great! I want to update the rDoc info at the top to make it current. Once I do that, I'll post it up in the top post so everyone finds it easier. Thanks!

Chris
0
Lately you've been tan, suspicious for the winter.
All my Plugins I've written
User avatar
Chris Fullmer 
SketchUp Team
SketchUp Team
 

Re: [Plugin] Color by Slope

Postby •BTM » Fri Jul 17, 2009 5:17 pm

Nice script!
smudgething.jpg

smudgething2.jpg
0

•BTM 
PluginStore Author
PluginStore Author
 

Re: [Plugin] Color by Slope

Postby icepam » Fri Jul 17, 2009 8:06 pm

Chris Fullmer wrote:ok aa, I checked out your version, and thats great! I want to update the rDoc info at the top to make it current. Once I do that, I'll post it up in the top post so everyone finds it easier. Thanks!

Chris


Great! while you're at it, here's a suggestion for a quick and very useful utility: let it give a name to the created materials, you should be able to construct it from the slope segment eg if you've got 3 colors, the materials will be named "0 to 30", "31 to 60", "61 to 90".

it would be great and trivial to have an option where instead of the number of colours you give it a angle, and it does the division... i would do it but too many cooks... ;)

and you're absolutely right about putting all your color face plugins into one package with a great GUI. let me know if you need help. i may not be the best ruby scripter, but am great at testing for usability.

-aa
0

icepam 
 

Re: [Plugin] Color by Slope

Postby icepam » Fri Jul 17, 2009 9:45 pm

icepam wrote:let it give a name to the created materials,


ok i gave that a wiz, the only way i figured how to do it is to create a materials array instead of a colors array, and assign the right one in the second step.

it creates materials called "segment 1 [0 to 30]", "segment 2 [30 to 60] etc.
ISSUES:
* it works fine if other materials have already been created with a similar max_number, but renames the sets of materials by adding numbers at the end. to avoid confusion: delete previous materials and/or purge them.
* the brackets are required, othewise the materials get renamed weirdly if they already end with a number.

attached is an updated version, and here's the diff:
Difference Report - 17/07/2009, 22:35
================================================================================

File 1: "aa_color_by_slope-REVISED.rb"
Last modified on 17/07/2009, 22:28
File 2: "aa_color_by_slope.rb"
Last modified on 17/07/2009, 22:31

================================================================================
Lines added at 1
================================================================================
+ materials = model.materials
+ matarray = []
+
+ #create a material and give it the right name and color
+ hi =90 - i * astep
+ low = 90 - (i+1) * astep
+ seg = max_colors - i
+ matname = "segment #{seg} [#{low} to #{hi}]"
+ #puts matname
+ m = materials.add matname
+ m.color = [r,g,b]
+ matarray.push m
================================================================================
Lines modified at 221
================================================================================
- a.material = colors [segment]
+
- a.back_material = colors [segment]
+ a.material = matarray[segment]
================================================================================
Lines added at 223
================================================================================
+ a.back_material = matarray[segment]

EDIT: file removed, please see top post for download link
0
Last edited by icepam on Fri Jul 17, 2009 10:27 pm, edited 1 time in total.

icepam 
 

Re: [Plugin] Color by Slope

Postby Mike Lucey » Fri Jul 17, 2009 10:02 pm

Thanks Chris, I wonder what it could be used for, other than visual effects? Has anyone any ideas .... I probably end up saying Doh!
0
User avatar
Mike Lucey 
Mayor
 

Re: [Plugin] Color by Slope

Postby icepam » Fri Jul 17, 2009 10:33 pm

Mike Lucey wrote:Thanks Chris, I wonder what it could be used for, other than visual effects? Has anyone any ideas .... I probably end up saying Doh!


It is an amazing utility if you work with landscape and terrains. I'm an urban designer and architect and I use it for example to figure out which parts of a terrain are too steep to build on etc.

geologists use slope analysis to figure out if there is any danger of landslides, and landscape designers to figure out what they can plant where.


you can also use it to figure out if snowfall will build on certain areas and not others.


and from a "image creation" perspective, if you combine the color by slope and the color by z, you could "automatically" create procedural maps of materials for example if you have a mountain, you can cover the highest parts with snow, the flat parts with grass, and the sheer parts with rock :D
0

icepam 
 

Re: [Plugin] Color by Slope

Postby Mike Lucey » Sat Jul 18, 2009 12:52 am

Thanks Icepam for that informitive description, and yes I agree that Colour by Slope would be invaluable in these cases.
0
User avatar
Mike Lucey 
Mayor
 

Re: [Plugin] Color by Slope

Postby JClements » Sat Jul 18, 2009 5:38 pm

Mike:

For freeform shapes, I can see where it could be used as a contrasting tool (like bumping up the contrast in your photoediting software) where SU's builtin Sun for Shading doesn't quite do the trick.

I am wondering if you could start with a grayscale mapping of the surface slopes, then take the grayscale value for each surface and tweek the HLS value of colors used for the surface, create a Palette of these shades, and apply them to their respective surfaces.
0
John
Illustrator
Beaverton, Oregon
User avatar
JClements 
Premium Member
Premium Member
 

Re: [Plugin] Color by Slope

Postby Didier Bur » Sun Jul 19, 2009 12:32 am

Hi,
you could start with a grayscale mapping of the surface slopes, then take the grayscale value for each surface and tweek the HLS value of colors used for the surface, create a Palette of these shades, and apply them to their respective surfaces

I've done something similar (well, sort of) in my "paint_altitude_faces.rb" veeeeery ooooold script. Go look into it if it can help, it is not crypted ;)
0
Didier Bur (Bytes Farmer)
Ecole Nationale Supérieure d'Architecture de Nancy (F)
http://rld.crai.archi.fr/rubylibrarydepot/
User avatar
Didier Bur 
 

Re: [Plugin] Color by Slope

Postby mattg » Wed Aug 19, 2009 1:13 pm

Chris,

Was just wondering if you updated your version of the script with all the new inclusions? No offense intended, but im not sure how stable or whatever the other versions are.

Cheers.

-Matt
0

mattg 
 

Re: [Plugin] Color by Slope

Postby olishea » Wed Aug 19, 2009 5:09 pm

thanks for this plugin. im a big fan of your color by z plugin too, I use it far too often!
0
oli
User avatar
olishea 
Premium Member
Premium Member
 

Re: [Plugin] Color by Slope (Updated Aug-31-2009)

Postby Chris Fullmer » Tue Sep 01, 2009 2:20 am

UPDATE! version 1.5 available. (But not much changed, just compiled all the scripts that had been lying around this thread, and now I've uploaded it to smustard to host).

@MattG, sorry it took so long to respond here! Yes, the other versions that were posted were quite stable. I've now consolidated everything into a single script and uploaded it to smustard.com:

@Olishea - thanks! I'm glad you like these scripts :) It always nice to know poeple use some of them.

Download
http://www.smustard.com/script/ColorBySlope

So go there now to download the final version of this script (I made one or two minor tweaks that might improve the speed, but I wouldn't count on it).
0
Lately you've been tan, suspicious for the winter.
All my Plugins I've written
User avatar
Chris Fullmer 
SketchUp Team
SketchUp Team
 

Re: [Plugin] Color by Slope

Postby mattg » Tue Sep 01, 2009 12:44 pm

Nah no worries.
Thankyou so much for this and all you other scripts - you're an absolute legend!
0

mattg 
 

Re: [Plugin] Color by Slope

Postby Ecuadorian » Thu Sep 17, 2009 9:46 pm

Thank you, Chris!

I could have used this when I was a student, as I had to do it manually for Urban Design class. You know, to decide which parts of a site to use for housing, which ones for parks, which ones not to use at all, etc.
0

Ecuadorian 
 

Re: [Plugin] Color by Slope

Postby riboflavele » Tue Apr 20, 2010 8:03 pm

I im trying to use this script, but i want to know its possible to change the colors and is it possible to know the slope % vs colors...? im not sure if my question is clear... Is it possible to have a legend or somthing to see for example that blue = 0% to 20% of slope and red = 40% to 60% of slope...

Sorry for my english...
0

riboflavele 
 

Re: [Plugin] Color by Slope

Postby TIG » Tue Apr 20, 2010 9:20 pm

See
mat.color=[(255-value),value,value]
line #56~
Sets the face color, value is set by the angle...
Edit it there...
:?:
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [Plugin] Color by Slope

Postby halsktchup » Sun Jun 27, 2010 7:38 pm

TIG, Chris,

Thanks for the color by slope script. Like another person in here, I too am trying to see if I can get specific colors for specific slopes. Is there a later version to your script on smustard that contains this? For example if I need a certain red for anything above 20% slope, how do I get that?

Thanks.
0

halsktchup 
 

Re: [Plugin] Color by Slope

Postby Chris Fullmer » Sun Jun 27, 2010 11:33 pm

Hey, so far the script does not do that. I do plan on implementing it eventually. I've got a super busy week and I do not anticipate being able to look at it right away, but it might be easy enough to just tweak some lines of code to make it work how you want. Maybe by next weekend I'll be able to look at it.

Chris
0
Lately you've been tan, suspicious for the winter.
All my Plugins I've written
User avatar
Chris Fullmer 
SketchUp Team
SketchUp Team
 

Re: [Plugin] Color by Slope

Postby TIG » Mon Jun 28, 2010 9:32 am

Hope I'm not standing on any toes... :?
Code: Select all
### edited/replace the code from here................
faces = []
flat = []
angle = 0.0
sel.each do |e|
  faces << e if e.is_a? Sketchup::Face
end#do
### first set up some [r,g,b] colors for various slope angles
### we use them if they exist, but if not make them...
if not color_00_20 = model.materials["color_00_20"]
  color_00_20 = model.materials.add("color_00_20")
  color_00_20.color= [120,0,0]
end#if
if not color_20_40 = model.materials["color_20_40"]
  color_20_40 = model.materials.add("color_20_40")
  color_20_40.color= [150,0,0]
end#if
if not color_40_60 = model.materials["color_40_60"]
  color_40_60 = model.materials.add("color_40_60")
  color_40_60.color= [180,0,0]
end#if
if not color_60_80 = model.materials["color_60_80"]
  color_60_80 = model.materials.add("color_60_80")
  color_60_80.color= [210,0,0]
end#if
if not color_80_90 = model.materials["color_80_90"]
  color_80_90 = model.materials.add("color_80_00")
  color_80_90.color= [240,0,0]
end#if
### you can adjust the colors' rgb values to suit...
###
faces.each do |e|
  enorm = e.normal
  flat = Geom::Vector3d.new(enorm[0],enorm[1],0)
  angle = (flat.angle_between enorm).radians ### angle in in degrees
  ### now set up the tests for different angles
  ### change these test ranges etc to suit your requirements...
  if angle>=0.0 and angle<=20.0
    color=color_00_20
  elsif angle>20.0 and angle<=40.0
    color=color_30_40
  elsif angle>40.0 and angle<=60.0
    color=color_40_60
  elsif angle>60.0 and angle<=80.0
    color=color_60_80
  else ### angle>80.0
    color=color_80_90
  end#if
  e.material = color
  e.back_material = color
end#do
### end of edit/replace.................
Make a backup copy of the original ruby script outside of the Plugins folder so it won't try load twice. If you mess up then you have the original to use again...
Now edit/replace the version that's still in the Plugins folder, as set out above [open with Notepad.exe or equivalent plain-text editor].
Save it and restart Sketchup - all slopes should now be colored in the angle-ranges and colors you've specified...
:ugeek:
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [Plugin] Color by Slope

Postby Chris Fullmer » Mon Jun 28, 2010 5:49 pm

TIG wrote:Hope I'm not standing on any toes... :?


Nope, not at all! Thanks TIG,

Chris
0
Lately you've been tan, suspicious for the winter.
All my Plugins I've written
User avatar
Chris Fullmer 
SketchUp Team
SketchUp Team
 

Re: [Plugin] Color by Slope

Postby anilnimesh » Wed Nov 03, 2010 2:53 pm

Color by angle by you is amazing...
;) rather i had changed name of the tool as 'Slope by angle' :D

wow! ur work is amazing.

Please brief about color assignments in case of 'color by Slope'?

About myself, i m an Architect from India and doing practice in Delhi.
regards,
Anil Nimesh
0

anilnimesh 
 

Re: [Plugin] Color by Slope

Postby Chris Fullmer » Wed Nov 03, 2010 4:37 pm

anilnimesh wrote:Please brief about color assignments in case of 'color by Slope'?


Thanks for using my plugin. I'm not entirely sure what you are requesting though. Let me know if there is a feature you think should be added, thanks!

Chris
0
Lately you've been tan, suspicious for the winter.
All my Plugins I've written
User avatar
Chris Fullmer 
SketchUp Team
SketchUp Team
 

Re: [Plugin] Color by Slope

Postby anilnimesh » Wed Nov 03, 2010 5:00 pm

Hi Chris,
i using sketchu pro v7.
while using the tool, it is bit difficult to understand, which color is applied for which slope. i need to calculate, hw the tool is working?
is there any color which defines slope (like 0-5% or 5%-10%) in slabs? i mean say 'red' for slope slab 0-5%

u wrote highest color no. is for low gradient and vice versa. u also wrote to explode the group (containing the terrain) and select color and make a new group out of those.

i tried but found it little tidious... :lol:

althought it is much simplied then what we do manually.. :D but i need to understand more about your tool.

u also made a new one for v8 where it is called 'Color by slope stepped'. i found the previous one more relevant for my work.

so i need to know that can the tool defines colors w.r.t. slope in slabs (like 0-5% or 5%-10%) ?


regrds,
0

anilnimesh 
 

SketchUcation One-Liner Adverts

by Ad Machine » 5 minutes ago



Ad Machine 
Robot
 

Next


 

Return to Plugins

Who is online

Users browsing this forum: Bull_10, medeek, NAGGA, pedrinalex and 8 guests

Visit our sponsors: