Transfer vertex weights to vertex colors and vice versa

In a previous article I mentioned that my WeightLifter addon was updated and could now (besides many other things) transfer vertex weights to vertex colors and vice versa. Because this might be of use to many people I decided to split off this specific functionality into a separate addon and provide it for free.

After installing the addon in the usual manner you get two new menu options: one in the Weights menu in Weight Paint mode called VertexColorsToWeights and a corresponding one in the Paint menu in Vertex Paint mode.


Weight paint mode

In weight paint mode clicking on Weights -> VertexColorToWeight will transfer a color from the active vertex color layer to the active vertex group. If there is no vertex color layer present a will cretae a new one. You have an option to choose which color channel to use as weight or to combine all colors.

Vertex paint mode

In vertex paint mode clicking on Paint -> WeightToVertexColor will transfer the weights from the active vertex group to the active vertex color layer. if there is no veretx group present it will create a new one. You have again an option to transfer the weights to a single color channel or to all color channels.

Code Availability

The code can be downloaded from my GitHub repository.

5 comments:

  1. Thank you, Michel! I just tried your .py, but I get
    line 178, in execute
    ValueError: bpy_struct: item.attr = val: sequences of dimension 0 should contain 4 items, not 3


    Could that be a Python version mismatch?
    I'm using recent Blender Foundation versions of Blender 2.79,
    which come with Python 3.7.

    ReplyDelete
  2. Python mismatch, indeed: I just tried it with the official
    Blender 2.79b, which comes with Python 3.5, and it works like a charm.

    How time-consuming would it be for you to update it to Python 3.7
    (which is also what recent builds of Blender 2.80 use)?

    ReplyDelete
    Replies
    1. I am sorry but my time is too limited to actively provide support for the free add-ons on non-official Blender version. I agree it would be sensible to make stuff compatible with Python 3.7, but 2.8 is beta and even worse, the Python API is not stable at this point so it would be a waste of time in my opinion to try and shoot at a moving target.
      Having said that, that doesn't mean I am averse to keeping the free stuff up to date: if someone sends me a pull request with a patch I am certainly willing to consider it for a merge, it is just that my own time is a bit limited :-(

      Delete
    2. Understood. But I feel enough motivation to attempt a hack.

      On a simple .blend, your .py with Blender 2.79b works;
      not so with a more complex .blend,
      and the error hails from line 176 or 178,
      inside an iteration on mesh.loops,
      which makes me wonder:
      why not iterate over the mesh’s vertices?

      Delete
  3. Aha: In Blender 2.79b,
    bpy.context.active_object.data.vertex_colors.active[0].color
    has three components; in recent Blender 2.79 builds, it has four!

    ReplyDelete