Skip to content

Instantly share code, notes, and snippets.

@paulwinex
Last active April 30, 2018 10:32
Show Gist options
  • Save paulwinex/41776a196ad59f1b3f331b7385be2dac to your computer and use it in GitHub Desktop.
Save paulwinex/41776a196ad59f1b3f331b7385be2dac to your computer and use it in GitHub Desktop.
'''
1. Выделить меш с блендшейпами первым
2. Выделить итоговый врапленный меш вторым
3. Запустить скрипт
'''
from pymel.core import *
def msg():
inViewMessage( amg='1. Select source mesh with blend shapes\n2. Select Wrapped mesh\n3. Start Script', pos='midCenter', fade=True, fst=10000)
def copy_to(obj, name=None, parent=None):
new = duplicate(obj, ic=False)[0]
if parent:
new.setParent(parent)
if not name:
new.rename(obj.name().split('|')[-1])
if name:
new.rename(name)
for sh in new.getShapes():
if sh.intermediateObject.get():
delete(sh)
return new
def generate(source, target):
bs = source.inMesh.inputs(type='blendShape')
if not bs:
system.error('Source mash have no Blend Shapes')
msg()
return
bs = bs[0]
for i in range(bs.getWeightCount()):
bs.setWeight(i, 0)
out_parent = createNode('transform', name=target.name()+'_blendShapes')
target_copy = copy_to(target, parent=out_parent)
shapes = []
for i, name in enumerate(bs.getTarget()):
out_name = name.rsplit('|')[-1]
bs.setWeight(i, 1)
dup = copy_to(target, name=name, parent=out_parent)
dup.hide()
shapes.append(dup)
bs.setWeight(i, 0)
shapes.append(target_copy)
bs2 = blendShape(*shapes)[0]
select(target_copy)
def start():
sel = selected(transforms=True)
if len(sel) != 2:
system.warning('Select Source Mesh with blend shapes and wrapped target mesh')
msg()
return
generate(*sel)
start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment