7
$\begingroup$

I'm a beginner.

Is it possible (and if so, how) to select a single vertex and change its color? I tried the "Vertex paint" mode, but couldn't find a way to select a single vertex and view its color.

Thanks.

Edit:

What I'm trying to do is to encode data with the vertex color so that my game engine will be able to act on that vertex differently, while the actual in-game color of that vertex will be determined by the UV coords and texture I apply. I'm using FBX as binary format.

IMHO this is a very basic functionality which should be exposed from GUI, so if someone here can open a feature request, that would be great.

$\endgroup$
  • $\begingroup$ you can select faces not vertices $\endgroup$ – Chebhou May 14 '15 at 12:33
10
$\begingroup$

A single vertex can have multiple colors at the same time, because it can belong to multiple faces (with different colors). The vertex colors are stored per face loops and not in vertices themselves:

enter image description here

Vertex colors can be viewed in Vertex Paint mode. In this mode individual vertices can also be edited with brushes:

enter image description here

The drawing can be constrained to selected faces, but not selected vertices. Blender doesn't allow this from the UI like other software you mentioned (Max).

You can set the colors to individual face-loop vertices with python like this:

for ipoly in range(len(ob.data.polygons)):
    for ivertex in ob.data.polygons[ipoly].loop_indices:
        ob.data.vertex_colors["col"].data[ivertex].color = (R,G,B)

Here is a script that when run in Text editor will add panel to properties (N) so you can assign vertex colors to vertices in edit-mode:

enter image description here

The viewing of vertex colors is still best in vertex paint mode, having this in panel would clutter it.

Code:

import bpy
import bmesh

class VertexColEditPanel(bpy.types.Panel):
    bl_label = "Vertex Colors"
    bl_space_type = "VIEW_3D"
    bl_region_type = "UI"

    @classmethod
    def poll(self, context):
        ob = context.active_object
        try:
            return ob and ob.type == 'MESH' and ob.mode == 'EDIT'
        except (AttributeError, KeyError, TypeError):
            return False

    def draw(self, context):
        layout = self.layout
        bm = bmesh.from_edit_mesh(context.active_object.data)
        if bm.select_mode != {'VERT'}:
            layout.label("Vertex select only", icon = 'INFO')
            return
        selected = [vert.index for vert in bm.verts if vert.select]
        if not selected:
            layout.label("Nothing selected", icon = 'INFO')
        else:
            layout.template_list("MESH_UL_uvmaps_vcols", "vcols", context.active_object.data, "vertex_colors", context.active_object.data.vertex_colors, "active_index", rows=1)
            row = layout.row(align=True)
            row.prop(context.scene, 'color_picker', text="")
            row.operator("vertex_col.apply")

class ApplyVertCol(bpy.types.Operator):
    bl_idname = "vertex_col.apply"
    bl_label = "Assign"
    bl_description = "Assign color to selected vertices for selected vertex color layer"

    def execute(self, context):
        me = context.active_object.data
        bm = bmesh.from_edit_mesh(me)
        selected = [vert.index for vert in bm.verts if vert.select]
        bpy.ops.object.mode_set(mode='EDIT', toggle=True)
        for face in me.polygons:
            for vert_idx, loop_idx in zip(face.vertices, face.loop_indices):
                if vert_idx in selected:
                    me.vertex_colors[me.vertex_colors.active_index].data[loop_idx].color = context.scene.color_picker
        bpy.ops.object.mode_set(mode='EDIT', toggle=True)
        return{'FINISHED'}

bpy.utils.register_module(__name__)
bpy.types.Scene.color_picker = bpy.props.FloatVectorProperty(subtype='COLOR_GAMMA', default=(1,1,1), min=0.0, max=1.0, description="Color Picker")
$\endgroup$
  • $\begingroup$ Thanks for answering. Too bad I can select a vertex and view its position, but not its color. It's a great functionality we utilize in Max all the time. $\endgroup$ – liorda May 15 '15 at 10:56
  • $\begingroup$ @liorda I know but there is only a couple of Blender developers and they have hands full of bigger issues. You cannot expect the same from free and very high-price software. In Blender you sometimes need to script the tools yourself, the python api is not that hard, with the code snippet I gave and some output to a UI panel you can create an addon to do what you want. $\endgroup$ – Jaroslav Jerryno Novotny May 15 '15 at 11:10
  • $\begingroup$ This script did not work for me. It is showing all vertices as white when they are obviously not. $\endgroup$ – James Watkins Jul 7 '18 at 17:28
  • $\begingroup$ @JamesWatkins the script does not display vertex colors, its function is to assign vert color in edit mode. Just tested it in 2.79b, works as expected. If vertex paint mode does show just white when it is not as you say, maybe there is a bug with your Blender version worth reporting. What exactly did you do so I can maybe replicate the issue? $\endgroup$ – Jaroslav Jerryno Novotny Jul 7 '18 at 20:37
  • $\begingroup$ Sorry, I was trying to view the vertex color not set it. I did not read the question carefully enough. $\endgroup$ – James Watkins Jul 10 '18 at 17:41
2
$\begingroup$

The Blender UI does not offer a way to view/set the color of an individual vertex. Normally, you set the color of a face as the vertex has no width.

If you want a vertex to show a specific (visible) color, then you can align a cylinder on the vertex (with very small radius) and paint that cylinder.

You can access the vertex details from the Python console.

$\endgroup$
  • $\begingroup$ "The Blender UI does not offer a way to view/set the color of an individual vertex" is not true anymore. E.g. for 2.79, there is the command: "3D Editor > Vertex Paint mode > Header > Paint Menu > Set vertex colors". $\endgroup$ – mins Jul 28 '18 at 0:10
  • $\begingroup$ @mins In fact one can not as of 2.79b (non-manually) set individual vertices' colors through UI alone. SHIFT+K (Set Vertex Colors) will either set all vertices to a given color, or those belonging to selected faces when "Face selection masking" is enabled (with no gradient). $\endgroup$ – ecv Jun 18 at 14:41
  • $\begingroup$ @ecv: Isn't that individual vertex coloring at the beginning of the video? $\endgroup$ – mins Jun 18 at 17:48
  • $\begingroup$ @mins that's exactly what I meant by "non-manually" for a lack of a better term. I meant manually as in using brushes/strokes rather than input fields. One has (since whatever version) always been able to paint vertices with strokes, but this isn't relevant to the original question. $\endgroup$ – ecv Jun 19 at 21:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.