Directly Apply Delta Blendshape
You cant directly sculpt on the blendshape since it has a different space. So normally I duplicate the model and sculpt in its static state.
After which, I applied the static to the blendshape pose. This will generate the delta pose in the background.
The script to apply
import pymel.core as pm
def go():
target = pm.ls('target')[0] # driven
source = pm.ls('source')[0] # driver
for vtx in source.vtx:
idx = vtx.index()
t = pm.xform(vtx, q=True, t=True)
output = target.vtx[idx]
pm.move(output, t, a=True)
go()
# Version with using it on a specified points
import maya.cmds as cmds
import pymel.core as pm
# Get the selection from the set named 'point_selection'
selected_points = cmds.sets('point_selection', q=True)
def flatten_list(selected_objects): # selected objects is a vertex list
# Check if there are any objects in the selection
vertex_list = []
if selected_objects:
for obj in selected_objects:
if cmds.objectType(obj) == 'mesh': # Check if the object is a mesh
# Extracting the number range from the vertex string
vertex_range = obj.split('[')[-1].split(':')
start_index = int(vertex_range[0])
end_index = int(vertex_range[-1].rstrip(']'))
# Constructing individual vertex names
for i in range(start_index, end_index + 1):
vertex_list.append(f"{obj.split('.')[0]}.vtx[{i}]")
else:
vertex_list = []
return vertex_list
def transfer_points(selected_points=None):
source = pm.ls('source_geo')[0]
target = pm.ls('target_geo')[0]
if selected_points:
vertex_list = selected_points
else:
vertex_list = source.vtx
for vtx in vertex_list:
vtx = pm.PyNode(vtx)
idx = vtx.index()
t = pm.xform(vtx, q=True, t=True)
output = target.vtx[idx]
pm.move(output, t, a=True)
processed_points = flatten_list(selected_points)
transfer_points(selected_points=processed_points)