Monday, 24 April 2017

Tip #1: Remove Target from Blendshape (when mesh target has been removed from scene)

A while ago I was writing a blendshape management system that would allow the adding, editing and deletion of a blendshape target.
One of the problems I had when looking more deeply into this was that, prior to 2017 (where I believe its been fixed) the Autodesk tool to delete a blendshape target required that the targets still existed as geometry somewhere in the scene. This is all well and good but if like me you do not want to be dealing with heavy scenes then handing a character rig with dozens of blendshapes attached was not going to help matters, especially with multiple rigs referenced into one scene. So I chose to delete my targets using a tool to rebuild them if required or simply storing them in a seperate scene.
So with the physical targets removed from the scene it appeared that if I wanted to remove a target from the blendshape it was tantamount to rebuilding the blendshape from scratch and re-hooking up any automation that might have previously existed. Not Cool.
It would appear that it is infact possible to remove targets after the scene mesh has been removed using the removeMultiInstance command. The Autodesk documentation list this description.

Removes a particular instance of a multiElement. This is only useful for input attributes since outputs will get regenerated the next time the node gets executed. This command will remove the instance and optionally break all incoming and outgoing connections to that instance. If the connections are not broken (with the -b true) flag, then the command will fail if connections exist.

Indeed, if you input the name of your blendshape along with the weight and target group index Maya should both remove the data at the given index, unhooking any connections. The only thing that is required is keeping track of your target indices. In the posted video I show a basic example of the issues with the in built tool and how these simple lines of code get around the issue. Obviously you will need to adjust the blendshape name and index to make use of it.

 import maya.cmds as mc  
        
 def delete_blendshape_target(blendshape_name, target_index):  
      mc.select(d=True)  
      mc.removeMultiInstance(blendshape_name + ".weight[%s]"%target_index, b=True)  
      mc.removeMultiInstance(blendshape_name + ".inputTarget[0].inputTargetGroup[%s]"%target_index, b=True)  
        
 blendshape_name = "blendShape1"  
 target_index = 0  
 delete_blendshape_target(blendshape_name, target_index)  

Remove Blendshape Targets from SBGrover on Vimeo.

0 comments:

Post a Comment