1
$\begingroup$

I want to approach two vertex groups belonging to two different objects, making sure that these objects are close together. How can I do that scripting?

Thank you so much!

$\endgroup$
1
$\begingroup$

Given an object ob, you can access its mesh at ob.data, and its vertices at ob.data.vertices. The vertex groups are defined on the object as well, at ob.vertex_groups. Each vertex group has a weight() function you can call to get the weight of a vertex.

vg0 = ob.vertex_groups[0]
for index, vertex in enumerate(ob.data.vertices):
    try:
        weight = vg0.weight(index)
    except RuntimeError:
        # Raised when the vertex is not part of the group
        weight = 0.0

    print('Vertex #%d at %s has weight %f' % (index, vertex.co, weight))

For efficient distance queries (from a point in space to a mesh) you can use the BVHTree module. This may work faster than trying to compute the distance between every point of one mesh to every other point on the other.

$\endgroup$
  • $\begingroup$ Good catch, I updated the code. $\endgroup$ – dr. Sybren Jun 27 '18 at 9:52
  • 1
    $\begingroup$ Lightspeed updating! $\endgroup$ – aliasguru Jun 27 '18 at 9:53
  • $\begingroup$ uhmmm, sorry, i want to put very close my objects basing on their 2 vertex groups... why do we consider the weight? $\endgroup$ – Christian Marcias Jun 27 '18 at 11:19
  • $\begingroup$ The code can be used to detect whether a vertex is in the vertex group (use the exception) or you can use the weight itself somehow. The exact use is up to you. $\endgroup$ – dr. Sybren Jun 27 '18 at 14:52

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.