4
$\begingroup$

When importing an object with my own script (Yes, I need one, no functional script exists) I want to import it with help of the bmesh-module. It seems to be the best choice for the job as it is as close as you can get to data-only and is kind of standalone (keeps the blender-data clean until everything is ready). There is one problem I am facing now: How do I give names to the vertexGroups? This is what I got so far:

import bmesh
mesh = bmesh.new()
# add vertices
layer = mesh.verts.layers.deform.new() # a new deform layer, why is this singleton??
for vert in mesh.verts:
    vert[layer][0] = 0.5 # assign a value of 0.5 to the first group
    # .... more groups

I suppose you know that Blender handles animation via vertex-groups so I have to make sure that the right vertex-group (index) has the correct name assigned to it.

Do I have to name the groups on the object itself? If yes, do I have to create the group beforehands (before mesh.to_mesh(object.data))? Am I guaranteed that the order is kept?

$\endgroup$
3
  • $\begingroup$ deform and vertex_groups are not related from my understanding, and there's no way to manipulate Vertex Groups through the bmesh module. $\endgroup$
    – CodeManX
    Commented May 9, 2014 at 18:28
  • $\begingroup$ blender.org/documentation/blender_python_api_2_63_8/… says just that :) $\endgroup$ Commented May 9, 2014 at 18:52
  • $\begingroup$ Thanks for the link! It's pretty confusing, so thanks again for asking this question! $\endgroup$
    – CodeManX
    Commented May 9, 2014 at 20:34

1 Answer 1

5
$\begingroup$

Vertex group names are stored in the object, not the mesh.

The order of groups just has to be aligned between the mesh and the object.

So yes, you have to name the group on the object.

$\endgroup$
1
  • $\begingroup$ If you create a fake user for a mesh, remove an object, and then add a new object and change the mesh to the one with vertex groups, the names are still there. I think the names are stored somewhere on the mesh, though maybe not accessible in bmesh. $\endgroup$ Commented Jun 14, 2022 at 8:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .