Grasshopper

algorithmic modeling for Rhino

Hi guys,

 

Would you know how to shade an existing mesh according to height values ?

 

thanks,

 

Arthur

Views: 14726

Replies to This Discussion

I looked into this a little while back and the only solution I could come up with (If I remember correctly) was to decompose the mesh and rebuild surfaces from points that are assigned a block colour material based on their centroids height. Once these are baked they will be seen in whatever render engine you chose, however, this only really works well with fine meshes.
If you only need height colour mapping, then you could try this old trick:


Just apply a custom gradient texture (planar mapping) to any object - mesh, surface, whatever... - directly in Rhino.

It will work with any renderer, but since it's kind of a simplified workaround, you won't have detailed control over the process...
For rendering mesh vertex colors you need a render engine that supports this, but none of the standard ones do. What i do is to create a bitmap image through a scripting component and UV map it to the baked surface. This is the process:
- Divide the surface in a grid of points (each point corresponds to a pixel).
- Find out the color that would correspond to each point.
- Use the following code to create a bitmap image:

Dim num As Integer = y
Dim bm As New Bitmap(num, num)

For i As Integer = 0 To num - 1
For j As Integer = 0 To num - 1
bm.SetPixel(i, j, x(i * num + (num - 1 - j)))
Next
Next

' Save the result as a JPEG file.
bm.Save("C:\Users\v\Documents\amid\cubierta\transp.jpg")
End Sub

Where 'y' is the vertical and horizontal resolution (this assumes the image is square) and 'x' is the list of colors. y is a single item, x is a list of items.
I also have this code laying around, i did this many months ago. It does the following, for a set of surfaces, it generates a bitmap for each one, bakes it and applies it's corresponding texture so u don't have to do it manually. In this case the bitmaps were used on the alpha channel. The code is for the old sdk. Sorry, it's a bit of a mess. So each surface (b input) was in an individual path containing one item and the colors (x input) are also separated in paths that correspond to each surface, but in each path there's a list of items that correspond to the pixels of that surface. The z input is a counter (list of numbers) also separated into paths used to name the bitmap files.

Dim num As Integer = y
Dim bm As New Bitmap(num, num)

For i As Integer = 0 To num - 1
For j As Integer = 0 To num - 1
bm.SetPixel(i, j, x(i * num + (num - 1 - j)))
Next
Next

' Save the result as a JPEG file.
bm.Save("C:\Users\v\Documents\amid\cubierta\mapas\transp" & z & ".jpg")

Dim obj As IRhinoSurfaceObject
Dim mat As New OnMaterial
Dim texture As New OnTexture
texture.m_filename = "C:\Users\v\Documents\amid\cubierta\mapas\transp" & z & ".jpg"
texture.m_bApply_uvw = True
' texture.m_transparent_color = New OnColor(0, 0, 0)
texture.m_type = RMA.OpenNURBS.IOnTexture.TYPE.transparency_texture
texture.m_mode = RMA.OpenNURBS.IOnTexture.MODE.modulate_texture
'mat.m_textures.Append(texture)
mat.AddTexture(texture)
mat.m_diffuse = New OnColor(204, 204, 204)
'doc.DeleteObject(New MRhinoObjRef(obj), True, True)
obj = doc.AddSurfaceObject(b)
Dim att As New MRhinoObjectAttributes(obj.Attributes())
att.setmaterialsource(1)
att.m_material_index = doc.m_material_table.AddMaterial(mat)
att.m_rendering_attributes.Default
Dim objref As New MRhinoObjRef(obj.Attributes.m_uuid)
doc.ModifyObjectAttributes(objref, att)
' app.RunScript("_save")
Thanks a million guys,
very useful stuff !

Hi Vicente,

 

I was wondering why this isn't working for me?

Attachments:

'x' should be a flat list of data. Change it from datatree to list and flatten the 'divide surface' output. Also, remember when you divide a surface in n amount of segments you end up with n+1 points on each axis, so you have to add 1 to y.

 

This is only useful for creating a texture that is uv mapped to a nurbs surface. For actual vertex colour rendering of any type of mesh, if you use the Brazil renderer, there's a new shader released some months ago that does this. For other renderers, i posted an alternative that modifies mesh texture coordinates (although it didnt work very well) here: http://www.grasshopper3d.com/forum/topics/rendering-falsecolor-data...

 

Also, i made this thread for a solution to colour different meshes with diferent colours using a single bitmap texture here (this one works well):

http://www.grasshopper3d.com/forum/topics/solution-to-baking-multiple

Thanks, I caught the n+1, but went the other way and reduced the UV to the surface divide. I'll try the list for flattened x tomorrow.

 

Many thanks

Danny

Hello!

It was a great workshop - thank you! By the way  - that's me , who gave you that printscreened error massage with some russian text  -sorry for that :)

I have one question - maybe you can help me. How to convert color of the mesh into texture (so each vertex will have a color value) - to use it later in maya or 3ds-max? cause when i'm exporting colored mesh (after Geco) as obj or 3ds - it can't convert the color.

thank you in advance

 

Andrey

Hi Andrey,

please post such questions in the geco forum, it is easier for me the find ;)

The trick is to export it as an fbx file and you have all the information in 3dsmax or maya ;)

btw. could you maybe translate the text so that we can know what was the error?

cheers,

[uto]

thank's a lot!

 

sure it says:

 

 

Message log start (chronological):


Plugin version: 0.8.0004

 

Component Mesh AddAttributes {180c5fc8-4884-4142-8c0e-78e13c511b77} failed to deserialize itself: Can not load the type  "Grasshopper.Kernel.GH_ParamEventArgs" from assembly "Grasshopper, Version=1.0.0.20, Culture=neutral, PublicKeyToken=null".

 

Object list read 

 

 

best

 

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service