Leaving vertex group intact during subdivision.

I wonder if there is a way to keep a vertex group intact for subdivisions. Say I create an icosphere, assign a vertex group to all its vertices and then subdivide smooth twice …

I expected the vertex group to include only the original vertices, but all the newly subdivision created vertices have been added to the group as well :confused:

Is there a way to get my intended behavior?

By default Blender interpolates vertex data with the newly subdivided structure. If you don’t like that, do this:

(1) Duplicate your weight-painted, un-subdivided object and move it off to the side somewhere (so that it is easy to select it or the original mesh).

(2) Select the original, Tab into Edit Mode, and do all your subdividing. Don’t edit the mesh: just subdivide.

(3) While still in Edit Mode, in the Editing Buttons (F9) in the ‘Link and Materials’ panel under the Vertex Groups cluster, press ‘Delete’ until you’ve deleted all the vertex groups.

(4) Tab back into Object Mode. Select the duplicated object (which is un-subdivided and has the original vertex group data), then shift-select the original object (which is now subdivided and has no vertex group data).

(5) Run this script:

# Copy vertex weights
# (1) Select the object to PROVIDE vertex weights
# (2) Select the object to RECEIVE vertex weights
# (3) Run this script

import Blender
from Blender import NMesh, Draw

def copy_weights():
	Blender.Window.EditMode( 0 )
	selected_objects = Blender.Object.GetSelected()
	# Complain if exactly two objects are not selected
	if len( selected_objects ) != 2:
		Draw.PupMenu( "Error%t|First select the object to provide vertex weights, then the object to receive." )
	# Gather data
	src_object = selected_objects[ 1 ]
	dst_object = selected_objects[ 0 ]
	src_mesh = src_object.getData()
	dst_mesh = dst_object.getData()
	src_mesh_group_names = src_mesh.getVertGroupNames()
	dst_mesh_group_names = dst_mesh.getVertGroupNames()
	# Run through each vertex group in the source mesh
	for group_name in src_mesh_group_names:
		# Make sure that the vertex group already exists in the target mesh, and is empty
		#mtg this part doesn't seem to have any effect...
		if group_name in dst_mesh_group_names:
			dst_mesh.removeVertsFromGroup( group_name )
			dst_mesh.addVertGroup( group_name )
		# Scan through all the vertices in the source mesh group, and transfer
		# their weight to the corresponding vertex in the destination mesh group
		for src_group_vert in src_mesh.getVertsFromGroup( group_name, 1 ):
			vindex  = src_group_vert[ 0 ]
			vweight = src_group_vert[ 1 ]
			dst_mesh.assignVertsToGroup( group_name, [vindex], vweight, 'add' )
	# Indicate completion by deselecting the source and selecting the dest object
	src_object.select( 0 )
	dst_object.select( 1 )


(6) You can now delete the duplicated (unsubdivided) mesh.

Hope this helps.

P.S. This script is something I hacked to copy vertex group data exactly from one mesh to another when the meshes are duplicates. It still has a bug in it I haven’t fixed yet (hence step 3), but it’s still useful enough…