2

I am having a mesh. Every face has a ID. There is also a python dictionary where the IDs are mapped to a RGB value (or something else, which can map ID -> RGB. I am just thinking theoretically).

Now I want to have a node setup which colors the surface of the mesh dependent of the RGB value (I am also using these node groups (https://jtheninja.wordpress.com/2015/02/08/simple-pbr-v2/) because I want to see it with pbr values. Later I also want to have values for roughess and metallic for each face).

I am unsure which of the following node-types I should use for that:

  • Attribute Node (has output for color)
  • value Node (has output for floats, so I would need three value nodes and make a color-vector out of it?)
  • Script Node (Only for Open-Shading-Language scripts, am I right? Shouldn't help)

I need a node type which could access the ID Properties of the current object. I also need a node which also "knows" the face it is currently working and gets the face-id.

Any advice? Thanks!

Hamburml
  • 957
  • 1
  • 11
  • 25
  • 1
    is there a reason you aren't using vertex_colors? – zeffii Jul 28 '15 at 11:48
  • The color in the face isn't changing. So I do need to save the RGB-Values only one time instead of 3 or more. But thanks for the link! :D Are vertex_colors for every face or for every vertex? For example face A is green, face B is blue, face B is directly next to A, so they share some vertices. Can I do that with vertex_colors, too? – Hamburml Jul 28 '15 at 11:56
  • For my master thesis I would like to propose the perfect way so the solution "one face - one colour" would be the best. But now I want to know how I can determine, when a vertex has more than one vertex colour, which colour is for the current face? Or should I ask another question? – Hamburml Jul 28 '15 at 12:12
  • 1
    for instance, this works on a cube (if you have a vertex_color map created) https://gist.github.com/zeffii/86fdbec4e58d5cf86fd1 – zeffii Jul 28 '15 at 12:20
  • Thanks! I will try to use vertex colours and maybe someone could give a hint which node I could use for the example above. – Hamburml Jul 28 '15 at 12:27
  • 1
    that's shown here http://i.stack.imgur.com/cjlRu.png , The attribute node can output the values stored in the Vertex Color layer (you can have multiple layers) – zeffii Jul 28 '15 at 12:30
  • You can assign a material to each face, would that still work for you or break the task you are trying? – sambler Jul 28 '15 at 13:17
  • Thanks, I will take a look! @sambler: That could work and was my first idea. I just need to set the RGB-Value for that material. But I thought that every material is doing the same (just different colour-values) so having a material per face kinda feels lame to me(but would work). – Hamburml Jul 28 '15 at 14:02

1 Answers1

3

You can store the face ID as a vertex color o each face then read the vertex color using the Attribute node. This script will create a vertex color layer and store the face index as color :

import bpy

obj = bpy.context.object
obj_data = obj.data
group_name = 'face_ID'

#check for existing group with the same name
if None == obj_data.vertex_colors.get(group_name): 
    obj_data.vertex_colors.new(name=group_name)
color_map =  obj_data.vertex_colors[group_name]

#get faces' number 
count = len(obj_data.polygons)

for poly in obj_data.polygons:

    ID = poly.index / count  #for normalized results
    color = (ID, ID, ID)
    for loop_ind in poly.loop_indices:
        color_map.data[loop_ind].color = color 
Chebhou
  • 19,533
  • 51
  • 98