13
$\begingroup$

In a mesh there is a group of vertices which should not move after being positioned once. I would like to find a way to lock them in place for the whole duration of the project.

Currently I 'lock' them by hiding them and then sculpting. I imagine it is possible also to create shape keys for the vertices. Or I could write a script which would save position of the vertices.

Is there a better way to do it?

$\endgroup$
  • $\begingroup$ When I read your topic I was going to suggest hiding them. Btw, is it only sculpting or is it modifiers and edit mode also? $\endgroup$ – Gunslinger Dec 14 '13 at 21:28
  • $\begingroup$ I would like to lock them completely $\endgroup$ – dimus Dec 14 '13 at 21:34
16
$\begingroup$

I think you outlined most of the the good ways, but here is another option:

Mask modifier:

You could try using the Mask modifier:

  1. Add a mask modifier, select your vertex group and enable Invert so the vertex group is hidden.

  2. Enable Edit mode visibility and Apply to edit cage so that there is no way to select the vertex group elements in edit mode:

    enter image description here

This will basically function like hiding geometry, except it gives more control and does not interfere with normal hiding.
Note that it does not work in sculpt mode (hidden geometry will still be sculpted)

Shape keys:

However, I Think Shape keys is the way to go as it works for both modeling and sculpting.

To set this up:

  1. Add vertex group of all the geometry to want to modify (excluding the geometry you want to lock)

  2. Add two shape keys, a Basis and a shape key. Set the Value of the shape key to 1 and do your modeling sculpting etc.

  3. Set the Blend group to your "modifiable" group. Now only the modifiable geometry will be moved to the new shapekey position, the rest will remain in the Basis position:

    enter image description here

$\endgroup$
5
$\begingroup$

I also found out how to save location of selected vertices with scripts (from Edit mode). I am not sure though how stable vertex indices are.

to dump data:

import bpy
import bmesh
import mathutils
import os

obj = bpy.context.active_object

bm = bmesh.from_edit_mesh(obj.data)
sel_verts = [ vert for vert in bm.verts if vert.select ]
print("number of verts: {}".format(len(sel_verts)))

path = os.path.dirname(os.path.dirname(__file__))
file_path = os.path.join(path,
                        'scripts',
                        "%s_dump.tab" % obj.name)
f = open(file_path, 'w')
for v in sel_verts:   
    row = "%s\t%s\t%s\t%s\n" % (v.index,
                                v.co.x,
                                v.co.y,
                                v.co.z)
    f.write(row)
f.close()

And to restore:

import bpy
import bmesh
import os

obj = bpy.context.active_object
path = os.path.dirname(os.path.dirname(__file__))
file_path = os.path.join(path,
                        'scripts',
                        "%s_dump.tab" % obj.name)
f = open(file_path)

verts = {}

for line in f:
    (index, x, y, z) = line.strip().split("\t")
    verts[int(index)] = { 'x': float(x),
                          'y': float(y),
                          'z': float(z) }

bm = bmesh.from_edit_mesh(obj.data)
for v in bm.verts:
  if v.index in verts:
      vv = verts[v.index]
      v.co.x = vv['x']
      v.co.y = vv['y']
      v.co.z = vv['z']

bmesh.update_edit_mesh(obj.data, True)
$\endgroup$

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.