Skip to content

Commit

Permalink
save:
Browse files Browse the repository at this point in the history
- moved blendshapes logic to separate script
- added 3 new buttons:
  - "Print Blendshapes Base Nodes"
  - "Print Blendshapes Names"
  - "Zero Blendshapes Weights"
  • Loading branch information
GenEugene committed Jun 26, 2024
1 parent e3b7917 commit ae3114c
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 8 deletions.
4 changes: 4 additions & 0 deletions GETOOLS_SOURCE/modules/GeneralWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from ..modules import Settings
from ..modules import Tools

from ..utils import Blendshapes
from ..utils import Colors
from ..utils import Install
from ..utils import Layers
Expand Down Expand Up @@ -109,6 +110,9 @@ def PrintChannelBoxAttributes(*args):
cmds.menuItem(label = "Print channel box selected attributes", command = PrintChannelBoxAttributes, image = Icons.text)
cmds.menuItem(divider = True)
cmds.menuItem(label = "Open Colors Palette", command = ColorsPalette, image = Icons.color)
cmds.menuItem(dividerLabel = "Blendshapes", divider = True)
cmds.menuItem(label = "Print Blendshapes Base Nodes", command = Blendshapes.GetBlendshapeNodesFromSelected, image = Icons.text)
cmds.menuItem(label = "Print Blendshapes Names", command = Blendshapes.GetBlendshapeWeightsFromSelected, image = Icons.text)

self.LayoutMenuInstall()

Expand Down
16 changes: 13 additions & 3 deletions GETOOLS_SOURCE/modules/Rigging.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

from ..modules import Settings

from ..utils import Blendshapes
from ..utils import Colors
from ..utils import Constraints
from ..utils import Deformers
Expand Down Expand Up @@ -123,13 +124,22 @@ def UICreate(self, layoutMain):


# DEFORMERS
layoutBlendshapes = cmds.frameLayout(parent = layoutMain, label = Settings.frames2Prefix + "DEFORMERS", collapsable = True, backgroundColor = Settings.frames2Color)
layoutColumnBlendshapes = cmds.columnLayout(parent = layoutBlendshapes, adjustableColumn = True)
layoutDeformers = cmds.frameLayout(parent = layoutMain, label = Settings.frames2Prefix + "DEFORMERS", collapsable = True, backgroundColor = Settings.frames2Color)
layoutColumnDeformers = cmds.columnLayout(parent = layoutDeformers, adjustableColumn = True)
#
countOffsets = 2
cmds.gridLayout(parent = layoutColumnBlendshapes, numberOfColumns = countOffsets, cellWidth = windowWidthMargin / countOffsets, cellHeight = lineHeight)
cmds.gridLayout(parent = layoutColumnDeformers, numberOfColumns = countOffsets, cellWidth = windowWidthMargin / countOffsets, cellHeight = lineHeight)
cmds.button(label = "Wraps Create", command = Deformers.WrapsCreateOnSelected, backgroundColor = Colors.blackWhite100, annotation = RiggingAnnotations.wraps)
cmds.button(label = "Blendshapes Projecting", command = Deformers.BlendshapesExtraction, backgroundColor = Colors.blackWhite100, annotation = RiggingAnnotations.blendshapeProjection)


# BLENDSHAPES
layoutBlendshapes = cmds.frameLayout(parent = layoutMain, label = Settings.frames2Prefix + "BLENDSHAPES", collapsable = True, backgroundColor = Settings.frames2Color)
layoutColumnBlendshapes = cmds.columnLayout(parent = layoutBlendshapes, adjustableColumn = True)
#
countOffsets = 1
cmds.gridLayout(parent = layoutColumnBlendshapes, numberOfColumns = countOffsets, cellWidth = windowWidthMargin / countOffsets, cellHeight = lineHeight)
cmds.button(label = "Zero Blendshapes Weights", command = Blendshapes.ZeroBlendshapeWeightsOnSelected)


# CONSTRAINTS
Expand Down
111 changes: 111 additions & 0 deletions GETOOLS_SOURCE/utils/Blendshapes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# GETOOLS is under the terms of the MIT License

# Copyright (c) 2018-2024 Eugene Gataulin (GenEugene). All Rights Reserved.

# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:

# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

# Author: Eugene Gataulin [email protected] https://www.linkedin.com/in/geneugene

import maya.cmds as cmds
# import maya.mel as mel

from ..utils import Selector


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

result = []

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

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)

result.append(blendshapes)

# Print result
print("\tBLENDSHAPES")#
for item in result:
if (len(item) == 0):
continue
print(item[0])#

return result
def GetBlendshapeNodesFromSelected(*args):
# Check selected objects
selectedList = Selector.MultipleObjects(1)
if (selectedList == None):
return None

return GetBlendshapeNodesFromList(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)

result = []

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

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

result = []

for blendshape in blendshapes:
result.append(GetBlendshapeWeights(blendshape))

return result

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

for item in weights:
if (item == None):
continue
ZeroBlendshapeWeights(item)

3 changes: 1 addition & 2 deletions GETOOLS_SOURCE/utils/Deformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ def BlendshapesExtraction(*args): # TODO separate from Wraps logic
sourceDuplicate = result[2]

# Get blendshape node
# print("### {0}".format(cmds.listRelatives(sourceMesh, shapes = True))) # HACK for debug shape issue
shape = cmds.listRelatives(sourceMesh, shapes = True)[1] # FIXME weak solution, index is not always the same and sometimes just 1 element
shape = cmds.listRelatives(sourceMesh, shapes = True)[1] # FIXME replace by new Blendshapes methods
blendshapeSource = cmds.listConnections(shape, type = "blendShape")

# Check blendshape node
Expand Down
6 changes: 3 additions & 3 deletions GETOOLS_SOURCE/utils/Selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@

import maya.cmds as cmds

def MultipleObjects(minimalCount=1, transformsOnly=True):
def MultipleObjects(minimalCount=1, transformsOnly=True, shapes=False):
# Save selected objects to variable
if (transformsOnly):
selectedList = cmds.ls(selection = True, type = "transform", shapes = False)
selectedList = cmds.ls(selection = True, type = "transform", shapes = shapes)
else:
selectedList = cmds.ls(selection = True, shapes = False)
selectedList = cmds.ls(selection = True, shapes = shapes)

# Check selected objects
if (len(selectedList) < minimalCount):
Expand Down

0 comments on commit ae3114c

Please sign in to comment.