Skip to main content
deleted 1 character in body
Source Link

Here is a hack:

  • Read the color from object's vertex colors, this way your object'sobjects can share the same material with different colors:

    enter image description here

  • Change the vertex colors on frame change with python script. This won't have real-time performance but that shouldn't matter since you don't get material preview with vertex-colors in view-port anyway (it shows only in render).

     import bpy
    
     # this is how you add vertex-color map:
     obj.data.vertex_colors.new(name='Col')
    
     # this handler function, it will be called on every frame change
     def update_colors_from_rotation(scn):
         for obj in scn.objects:
             color = YOUR_FUNCTION(obj.rotation_euler)
             # color should be float array [R,G,B]
             # or you can access custom ID props here also: color = obj['base_color']
             # and do something with it
    
             # here is how you change the vertex-color map:
             for ipoly in range(len(obj.data.polygons)):
                 for ivertex in obj.data.polygons[ipoly].loop_indices:
                     obj.data.vertex_colors['Col'].data[ivertex].color.r = color[0]
                     obj.data.vertex_colors['Col'].data[ivertex].color.g = color[1]
                     obj.data.vertex_colors['Col'].data[ivertex].color.b = color[2]
    
     # register the function in frame change handlers:
     bpy.app.handlers.frame_change_post.append(update_colors_from_rotation)
    

Here is a hack:

  • Read the color from object's vertex colors, this way your object's can share the same material with different colors:

    enter image description here

  • Change the vertex colors on frame change with python script. This won't have real-time performance but that shouldn't matter since you don't get material preview with vertex-colors in view-port anyway (it shows only in render).

     import bpy
    
     # this is how you add vertex-color map:
     obj.data.vertex_colors.new(name='Col')
    
     # this handler function, it will be called on every frame change
     def update_colors_from_rotation(scn):
         for obj in scn.objects:
             color = YOUR_FUNCTION(obj.rotation_euler)
             # color should be float array [R,G,B]
             # or you can access custom ID props here also: color = obj['base_color']
             # and do something with it
    
             # here is how you change the vertex-color map:
             for ipoly in range(len(obj.data.polygons)):
                 for ivertex in obj.data.polygons[ipoly].loop_indices:
                     obj.data.vertex_colors['Col'].data[ivertex].color.r = color[0]
                     obj.data.vertex_colors['Col'].data[ivertex].color.g = color[1]
                     obj.data.vertex_colors['Col'].data[ivertex].color.b = color[2]
    
     # register the function in frame change handlers:
     bpy.app.handlers.frame_change_post.append(update_colors_from_rotation)
    

Here is a hack:

  • Read the color from object's vertex colors, this way your objects can share the same material with different colors:

    enter image description here

  • Change the vertex colors on frame change with python script. This won't have real-time performance but that shouldn't matter since you don't get material preview with vertex-colors in view-port anyway (it shows only in render).

     import bpy
    
     # this is how you add vertex-color map:
     obj.data.vertex_colors.new(name='Col')
    
     # this handler function, it will be called on every frame change
     def update_colors_from_rotation(scn):
         for obj in scn.objects:
             color = YOUR_FUNCTION(obj.rotation_euler)
             # color should be float array [R,G,B]
             # or you can access custom ID props here also: color = obj['base_color']
             # and do something with it
    
             # here is how you change the vertex-color map:
             for ipoly in range(len(obj.data.polygons)):
                 for ivertex in obj.data.polygons[ipoly].loop_indices:
                     obj.data.vertex_colors['Col'].data[ivertex].color.r = color[0]
                     obj.data.vertex_colors['Col'].data[ivertex].color.g = color[1]
                     obj.data.vertex_colors['Col'].data[ivertex].color.b = color[2]
    
     # register the function in frame change handlers:
     bpy.app.handlers.frame_change_post.append(update_colors_from_rotation)
    
Source Link

Here is a hack:

  • Read the color from object's vertex colors, this way your object's can share the same material with different colors:

    enter image description here

  • Change the vertex colors on frame change with python script. This won't have real-time performance but that shouldn't matter since you don't get material preview with vertex-colors in view-port anyway (it shows only in render).

     import bpy
    
     # this is how you add vertex-color map:
     obj.data.vertex_colors.new(name='Col')
    
     # this handler function, it will be called on every frame change
     def update_colors_from_rotation(scn):
         for obj in scn.objects:
             color = YOUR_FUNCTION(obj.rotation_euler)
             # color should be float array [R,G,B]
             # or you can access custom ID props here also: color = obj['base_color']
             # and do something with it
    
             # here is how you change the vertex-color map:
             for ipoly in range(len(obj.data.polygons)):
                 for ivertex in obj.data.polygons[ipoly].loop_indices:
                     obj.data.vertex_colors['Col'].data[ivertex].color.r = color[0]
                     obj.data.vertex_colors['Col'].data[ivertex].color.g = color[1]
                     obj.data.vertex_colors['Col'].data[ivertex].color.b = color[2]
    
     # register the function in frame change handlers:
     bpy.app.handlers.frame_change_post.append(update_colors_from_rotation)