1
$\begingroup$

does blender have the function of snapping objects of same topology together by vertex index? for example, take a simple cube A at origin and duplicate it as cube B, move it aside. now compare vertex index in cube A with cube B and move every vertex in cube A to cube B base on the index number.

it is simple to use modifier such as shrinkwrap and snap to closest vert option, but for more complex mesh, it is often misaligned to different vert on dense parts. hence I wonder if there is a way to do it via vert index.

$\endgroup$
2
$\begingroup$

I don't think there is something about that except Python.

This script will report vertex coordinates of active object to all the selected objects.

Version 1

Just give object the same topology:

import bpy

def snap_by_vertex_index(obj, target):
    for o, t in zip(obj.data.vertices, target.data.vertices):
        o.co = t.co
        

target = bpy.context.active_object

if target and target.type == 'MESH':
    objects = [o for o in bpy.context.selected_objects if o.type == 'MESH' and o is not target]
    for o in objects:
        snap_by_vertex_index(o, target)

Version 2

Or, as suggested @batFINGER in comments, that can be moving vertices to the target:

import bpy

def snap_by_vertex_index2(obj, target):
    mat = obj.matrix_world.inverted() @ target.matrix_world
    for o, t in zip(obj.data.vertices, target.data.vertices):
        o.co = mat @ t.co

target = bpy.context.active_object

if target and target.type == 'MESH':
    objects = [o for o in bpy.context.selected_objects if o.type == 'MESH' and o is not target]
    for o in objects:
        snap_by_vertex_index2(o, target)
$\endgroup$
10
  • $\begingroup$ Imagine this would require converting target to object space of obj. (and checking vert counts match) $\endgroup$ – batFINGER Nov 5 '20 at 16:37
  • $\begingroup$ @batFINGER, I know. But have considered the topology only here. But maybe you're right... just matrices product... $\endgroup$ – lemon Nov 5 '20 at 16:39
  • $\begingroup$ ok, will add it if you agree $\endgroup$ – lemon Nov 5 '20 at 16:44
  • $\begingroup$ I think so, going by question otherwise cubes A and B will stay in exactly the same locations $\endgroup$ – batFINGER Nov 5 '20 at 16:47
  • 1
    $\begingroup$ WOW~~~ that code works like a charm !!!!! thank you so very much !!! $\endgroup$ – sleepyhead Nov 7 '20 at 8:27

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.