Last active
January 13, 2016 17:14
-
-
Save zeffii/8eede8ff41d6dac47448 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bl_info = { | |
"name": "Invert Vertex Colors", | |
"location": "3D viewport > Header > Paint menu in Vertex Paint mode", | |
"version": (0,1,0), | |
"blender": (2,7,6), | |
"description": "Inverts vertex colors of active paint layer", | |
"author": "Jerryno", | |
"category": "Paint", | |
} | |
import bpy | |
class InvertVertexColors(bpy.types.Operator): | |
bl_idname = "paint.invert_colors" | |
bl_label = "Invert Vertex Colors" | |
bl_description = "Invert vertex colors of active paint layer" | |
@classmethod | |
def poll(self, context): | |
try: | |
return context.active_object is not None | |
except (AttributeError, KeyError, TypeError): | |
return False | |
def execute(self, context): | |
active = context.active_object | |
polygons = active.data.polygons | |
vcol_data = active.data.vertex_colors.active.data | |
for ipoly in range(len(polygons)): | |
for idx, ivertex in enumerate(polygons[ipoly].loop_indices): | |
ivert = polygons[ipoly].vertices[idx] | |
col = vcol_data[ivertex].color | |
vcol_data[ivertex].color = tuple(1-x for x in col) | |
return{'FINISHED'} | |
def menu_entry(self, context): | |
self.layout.operator("paint.invert_colors", icon='IMAGE_ALPHA') | |
def register(): | |
bpy.utils.register_module(__name__) | |
bpy.types.VIEW3D_MT_paint_vertex.append(menu_entry) | |
def unregister(): | |
bpy.utils.unregister_module(__name__) | |
bpy.types.VIEW3D_MT_paint_vertex.remove(menu_entry) | |
if __name__ == "__main__": | |
register() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i only changed the execute function to have aliases for
polygons
andvcol_data
, this speeds up the code by reducing dot lookups and increases readability by making the line more code-concise.