Skip to content

Commit

Permalink
update Blendshapes logic, fix projecting
Browse files Browse the repository at this point in the history
  • Loading branch information
GenEugene committed Jun 26, 2024
1 parent ae3114c commit 96f77d2
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 64 deletions.
72 changes: 40 additions & 32 deletions GETOOLS_SOURCE/utils/Blendshapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,34 +28,40 @@
from ..utils import Selector


def GetBlendshapeNodesFromList(selectedList):
if (selectedList == None):
def GetBlendshapeNodeFromModel(model):
if (model == None):
return None

result = []
result = ""

# Get blendshape nodes
for element in selectedList:
relatives = cmds.listRelatives(element)
blendshapes = []
relatives = cmds.listRelatives(model)
blendshapes = []

for relative in relatives:
connections = cmds.listConnections(relative, type = "blendShape")
if (connections == None):
continue
for relative in relatives:
connections = cmds.listConnections(relative, type = "blendShape")
if (connections == None):
continue

for connection in connections:
if connection not in blendshapes:
blendshapes.append(connection)
for connection in connections:
if connection not in blendshapes:
result = connection

result.append(blendshapes)
if (len(result) == 0):
return None

# Print result
print(result)#
return result
def GetBlendshapeNodesFromModelList(modelList):
if (modelList == None):
return None

result = []

# Get blendshape nodes
print("\tBLENDSHAPES")#
for item in result:
if (len(item) == 0):
continue
print(item[0])#
for model in modelList:
result.append(GetBlendshapeNodeFromModel(model))

return result
def GetBlendshapeNodesFromSelected(*args):
Expand All @@ -64,43 +70,45 @@ def GetBlendshapeNodesFromSelected(*args):
if (selectedList == None):
return None

return GetBlendshapeNodesFromList(selectedList)
return GetBlendshapeNodesFromModelList(selectedList)

def GetBlendshapeWeights(blendshape):
# Check blendshape node
if (blendshape == None or len(blendshape) == 0):
return None

# Get blendshape weights
blendshapeNode = blendshape[0]
weights = cmds.listAttr(blendshapeNode + ".weight", multi = True)
blendshapeNode = blendshape
weightsNames = cmds.listAttr(blendshapeNode + ".weight", multi = True)

result = []
weightsNamesFull = []

# Print result
print("\tBLENDSHAPE \"{0}\" WEIGHTS".format(blendshape[0]))#
for weight in weights:
result.append(blendshapeNode + "." + weight)
print(result[-1])#
print("\tBLENDSHAPE \"{0}\" WEIGHTS".format(blendshape))#
for weight in weightsNames:
weightsNamesFull.append(blendshapeNode + "." + weight)
print(weightsNamesFull[-1])#

return result
return weightsNamesFull, weightsNames
def GetBlendshapeWeightsFromSelected(*args):
blendshapes = GetBlendshapeNodesFromSelected()
if (blendshapes == None):
return None

result = []
weightsNamesFull = []
weightsNames = []

for blendshape in blendshapes:
result.append(GetBlendshapeWeights(blendshape))
weightsNamesFull.append(GetBlendshapeWeights(blendshape)[0])
weightsNames.append(GetBlendshapeWeights(blendshape)[1])

return result
return weightsNamesFull, weightsNames

def ZeroBlendshapeWeights(weights):
for weight in weights:
cmds.setAttr(weight, 0)
def ZeroBlendshapeWeightsOnSelected(*args):
weights = GetBlendshapeWeightsFromSelected()
weights = GetBlendshapeWeightsFromSelected()[0]
if (weights == None):
return

Expand Down
63 changes: 31 additions & 32 deletions GETOOLS_SOURCE/utils/Deformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import maya.cmds as cmds
# import maya.mel as mel

from ..utils import Blendshapes
from ..utils import Selector
# from ..values import Enums

Expand All @@ -34,7 +35,7 @@
smoothness = 0


def WrapsCreate(elements, *args):
def WrapsCreate(elements):
if (len(elements) < 2):
cmds.warning("Need at least 2 objects for Wrap")
return
Expand Down Expand Up @@ -80,11 +81,26 @@ def WrapsCreateOnSelected(*args):

return selectedList, wraps[0], wraps[1]

def WrapsDelete(wrapsList, *args):
for wrap in wrapsList:
def WrapsDelete(wraps):
for wrap in wraps:
cmds.delete(wrap)

def BlendshapesExtraction(*args): # TODO separate from Wraps logic
def BlendshapesExtraction(*args):
# Check selected objects
selectedList = Selector.MultipleObjects(2)
if (selectedList == None):
return

# Get blendshape node
sourceMesh = selectedList[-1]
blendshapeSource = Blendshapes.GetBlendshapeNodeFromModel(sourceMesh)

# Check blendshape node
if (blendshapeSource == None):
cmds.warning("Last selected object has no blendShape node. Operation aborted")
return

# Create wraps
result = WrapsCreateOnSelected()
if (result == None):
cmds.warning("No objects detected")
Expand All @@ -93,40 +109,22 @@ def BlendshapesExtraction(*args): # TODO separate from Wraps logic
cmds.select(clear = True)

# Map values
selectedList = result[0]
sourceMesh = selectedList[-1]
wraps = result[1]
sourceDuplicate = result[2]

# Get blendshape node
shape = cmds.listRelatives(sourceMesh, shapes = True)[1] # FIXME replace by new Blendshapes methods
blendshapeSource = cmds.listConnections(shape, type = "blendShape")

# Check blendshape node
if (blendshapeSource == None):
cmds.warning("Last selected object has no blendShape node. Operation aborted")
WrapsDelete(wraps)
cmds.delete(sourceDuplicate)
cmds.select(selectedList, replace = True)
return

# Get blendshape weights
blendshapeSource = blendshapeSource[0]
weights = cmds.listAttr(blendshapeSource + ".weight", multi = True)
# Get blendshape weights and zero all of them
weights = Blendshapes.GetBlendshapeWeights(blendshapeSource)
Blendshapes.ZeroBlendshapeWeights(weights[0])

# Zero all weights
for item in weights:
cmds.setAttr(blendshapeSource + "." + item, 0)

# Activate one by one and duplicate results
duplicatesList = []
for i in range(len(selectedList) - 1):
duplicates = []
for item in weights:
cmds.setAttr(blendshapeSource + "." + item, 1)
duplicate = cmds.duplicate(selectedList[i], name = item)
for y in range(len(weights[0])):
cmds.setAttr(weights[0][y], 1)
duplicate = cmds.duplicate(selectedList[i], name = weights[1][y])
duplicates.append(duplicate)
cmds.setAttr(blendshapeSource + "." + item, 0)
cmds.setAttr(weights[0][y], 0)
duplicatesList.append(duplicates)

# Wraps cleanup
Expand All @@ -139,10 +137,11 @@ def BlendshapesExtraction(*args): # TODO separate from Wraps logic
for y in range(len(duplicatesList[x])):
cmds.blendShape(blendshapeTarget, edit = True, target = (selectedList[x], y, duplicatesList[x][y][0], 1.0))
cmds.delete(duplicatesList[x][y][0])
cmds.select(selectedList, replace = True)

def RunBlendshapesLogic(*args): # TODO combine wraps and blendshapes logic
result = WrapsCreateOnSelected()
BlendshapesExtraction()
# result = WrapsCreateOnSelected()
# BlendshapesExtraction()
pass

0 comments on commit 96f77d2

Please sign in to comment.