1

I added an animated 3D character from mixamo and I need to find the "3D location of the vertex Groups" ( I am completely new to this software )

I found it a little similar to my issue but it did not solve my problem. Is it possible to get vertex locations (world) from a vertex group?

lemon
  • 60,295
  • 3
  • 66
  • 136
  • Please add detail to clarify what "your problem" is: as AFAICT setting an empty to copy the location of a vertex group using a constraint works as expected, as does parenting an empty to a vertex. to place them globally where blender calculates the vg as a collective to be, or at each original vertex. Hence, am of the belief this answers (one way) to get the world position of a vertex group... – batFINGER Sep 13 '20 at 11:29
  • Thanks, @lemon's answer worked :) – leyla khaleghi Sep 15 '20 at 03:21

1 Answers1

1

Considering you want the coordinates for a animated character, you can use the bmesh module and the dependency graph to do that.

bmesh will provide mesh information and the dependency graph is used to retreive this information considering the mesh transformations.

From that, we can get access to vertices that correspond to the vertex group you want.

The principle is to use the active deform layer (vertex groups) of the bmesh and use it over the vertices to have vertex information about this layer.

This access provides a map containing the weights per group index. Here we just need to keep vertices that have the information for the group index we want.

Here is a full commented code (but feel free to ask if anything is not clear enough):

import bpy
import bmesh

Get the object

obj = bpy.context.collection.all_objects["Beta_Surface"] #Your object name here

Get the vertex group

vertex_group = obj.vertex_groups["mixamorig:LeftHand"] #Your vertex group name here

And its index

vg_index = vertex_group.index

Get the dependency graph (used to have mesh information with animation applied)

depsgraph = bpy.context.evaluated_depsgraph_get()

Create a bmesh object

bm = bmesh.new()

Get the information considering the dependency graph

bm.from_object( obj, depsgraph )

Get the deform (vertex groups) active layer (assuming there is one here)

deform = bm.verts.layers.deform.active

The object world matrix

world_matrix = obj.matrix_world

Loop over the vertices keeping only the one attached to the group

v[deform] gets vertex group information as (group index, vertex weight) map

for vert in [v for v in bm.verts if vg_index in v[deform]]: # vertex coordinate in object space co = vert.co # vertex coordinate in world space world_co = world_matrix @ co print(co, world_co)

lemon
  • 60,295
  • 3
  • 66
  • 136