Featured post

new redirect for blender.org bpy docs.

http://www.blender.org/api/blender_python_api_current/ As of 10/11 november 2015 we can now link to the current api docs and not be worr...

March 26, 2013

Painting Vertex Color Map using selected Faces

This script is obsolete, shift+K will fill all selected faces/ verts with the brush colour.

selected faces

During a recent conversation with Jimmy Gunawan of blendersushi I remembered that I wanted to write a script that lets me paint the vertex color map as a function of which faces are selected. Here's a version of this script that runs in vertex paint mode with face masking mode on. i'll leave refactoring this snippet to you.

I've limited some freedom by forcing the user to be in 'VERTEX_PAINT' and Face Masking Active, but it's safer this way (even after some bugfixing by campbell) -- as it is still easy to crash blender in obscure ways otherwise.

4 comments:

  1. Just a guess from looking over the code, I would say that the faces returned from bmesh.from_edit_mesh(my_object) are not the same as my_object.polygons - the fact that you need to request the bmesh faces opposed to accessing the objects polygons would indicate that the two blocks of data may act the same but aren't compatible when it comes to non-edit steps.

    ReplyDelete
    Replies
    1. the paint_lists generated by both methods are identical, from the time spent on this yesterday I can't say that your guess provides a satisfactory answer. I'll ask Campbell and see what he says. Thanks for the heads up.

      Delete
  2. Thanks a lot Dealga, this is exactly what I need.

    I'll have a look and study and also check wtf.py

    Just in case the reader wants everything via script:

    # Add 'Col' at the beginning
    mesh.vertex_colors.new()

    # Create a single Material that respect Vertex Color
    mat = bpy.data.materials.new('VertexMat')
    mat.use_vertex_color_paint = True
    mat.use_vertex_color_light = True

    # Switch back to OBJECT mode at the end.
    bpy.ops.object.mode_set(mode='OBJECT')

    ReplyDelete
    Replies
    1. cool yep, i wanted to keep the script short but might add back the check for existing colormap, and use the currently selected colormap not hardcoding 'Col'

      Delete

Please use Blender.StackExchange.com for python scripting questions unrelated to this post.