3
$\begingroup$

enter image description here

How can I get the vertices location connected to animated bones? E.g. the vertices of vertexgroup "foot.L" at keyframe 2?

$\endgroup$
0
3
$\begingroup$

Copy Location Constraint.

From https://blender.stackexchange.com/a/139758/15543

enter image description here

Can leverage the existing behaviour of the copy location constraint, targeted to a mesh, subtargeted to a vertex group.

Test script, run in object mode with mesh object selected. Will add an empty for each vertex group at the mean location (as determined by constraint) of each vertex group.

import bpy

context = bpy.context

ob = context.object
me = ob.data

for name in ob.vertex_groups.keys():
    bpy.ops.object.empty_add(location=(0, 0, 0))
    mt = context.object
    mt.name = f"{ob.name}_{name}"
    cl = mt.constraints.new('COPY_LOCATION')
    cl.target = ob
    cl.subtarget = name

Thanks, this gives me the center of the vertex group. Is it possible to get the location of all vertices (not only the center)?

Or using another slightly updated example from https://blender.stackexchange.com/a/139758/15543

this one adds an empty parented to each vertex in the vertex group.

For vertex group named "Group" containing vertex index 3, there will be an empty object mt named "Group_3" parented to vertex 3. At any frame the global location of vertex 3 will be mt.matrix_world.translation.

import bpy
from collections import defaultdict
context = bpy.context

vgs = defaultdict(list)
ob = context.object
me = ob.data
for v in me.vertices:
    for g in v.groups:
        vgs[ob.vertex_groups[g.group].name].append(v.index)

for name, vg in vgs.items():
    for i in vg:
        bpy.ops.object.empty_add(location=(0, 0, 0))

        mt = context.object
        mt.parent = ob
        # mt.name = "%s_%d" % (name, i) # for python < 3.6
        mt.name = f"{name}_{i}"
        mt.parent_type = 'VERTEX'
        mt.parent_vertices = (i,) * 3

Note would be a good idea here to jam empties into new linked collection, so they can be removed / hidden easily

Another way is to use one of the solutions outlined here

How do I get a mesh data-block with modifiers and shape keys applied in Blender 2.8?

for a modified mesh. However if you have a subsurf, for example, will have a lot of extra generated vertices.

$\endgroup$
1
  • $\begingroup$ Thanks, this gives me the center of the vertex group. Is it possible to get the location of all vertices (not only the center)? $\endgroup$
    – NanKat
    Jan 7 '20 at 21:14
0
$\begingroup$

I extended your first answer, this does work:

enter image description here

ob = bpy.data.objects['Person:Body']
me = ob.data


for name in ob.vertex_groups.keys():
    bpy.ops.object.empty_add(location=(0, 0, 0))
    mt = context.object
    mt.name = f"empty_{ob.name}_{name}"
    cl = mt.constraints.new('COPY_LOCATION')
    cl.target = ob
    cl.subtarget = name
    mt.matrix_world = mt.matrix_world.copy()
    mt.constraints.clear()

So, I am able to get the location of the vertex group per frame.

However, I can not get the location of the vertices. I tried out your second suggestion. Obviously, they are not at the same place as the animated Person is located.

enter image description here

Image shows the location of one vertice of the thumb (created empty), which is in the left corner instead of on the person.

$\endgroup$
2
  • $\begingroup$ actually I need the position of the linked parent vertex, but can't figure out how. So the location at the end of the black line $\endgroup$
    – NanKat
    Jan 12 '20 at 17:04
  • $\begingroup$ I'm so sorry, didn't have time to deeper look into this. Thanks so much for your support @batFINGER. I will check this weekend :) $\endgroup$
    – NanKat
    Jan 15 '20 at 12:33

This site is temporarily in read only mode and not accepting new answers.

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