Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions GETOOLS_SOURCE/_prototypes/CurveSpaceSwitching.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# 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 tek942@gmail.com https://www.linkedin.com/in/geneugene https://discord.gg/heMxJhTqCz
# Source code: https://github.com/GenEugene/GETools or https://app.gumroad.com/geneugene

import maya.cmds as cmds

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


def SetupSpaceDeformation(curves=None, *args): # TODO
if curves is None:
cmds.warning("No curves provided")
return None


6 changes: 6 additions & 0 deletions GETOOLS_SOURCE/modules/Tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,12 @@ def UILayoutLocators(self, layoutMain):
cmds.button(label = "Translate + Rotate", command = partial(self.LocatorsBakeAim, False), backgroundColor = Colors.orange10, annotation = ToolsAnnotations.locatorAimSpaceBakeAll)
cmds.button(label = "Only Rotate", command = partial(self.LocatorsBakeAim, True), backgroundColor = Colors.orange10, annotation = ToolsAnnotations.locatorAimSpaceBakeRotate)
# cmds.setParent("..")

### CURVE SPACE SWITCHING
layoutCurveSpace = cmds.frameLayout(parent = layoutColumn, label = "Curve Space Switching", labelIndent = 72, collapsable = False, backgroundColor = Settings.frames2Color, marginWidth = 0, marginHeight = 0)
cmds.button(label = "Create Motion Path Locator", command = Locators.CreateWithMotionPath, backgroundColor = Colors.green10)


def UILayoutBaking(self, layoutMain):
cmds.frameLayout(parent = layoutMain, label = Settings.frames2Prefix + "BAKING", collapsable = True, backgroundColor = Settings.frames2Color, highlightColor = Colors.green100, marginWidth = 0, marginHeight = 0, borderVisible = True)
layoutColumn = cmds.columnLayout(adjustableColumn = True, rowSpacing = Settings.columnLayoutRowSpacing)
Expand Down
14 changes: 7 additions & 7 deletions GETOOLS_SOURCE/utils/Baker.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@

def BakeSelected(classic=True, preserveOutsideKeys=True, sampleBy=1.0, selectedRange=False, channelBox=False, attributes=None, euler=False):
# Check selected objects
selectedList = Selector.MultipleObjects(1)
if (selectedList == None):
selectedList = Selector.MultipleObjects(minimalCount = 1)
if selectedList is None:
return

# Calculate time range if range highlighted
Expand All @@ -53,7 +53,7 @@ def BakeSelected(classic=True, preserveOutsideKeys=True, sampleBy=1.0, selectedR
if (channelBox):
bakeRegular = selectedAttributes == None
if (bakeRegular):
if (attributes == None):
if attributes is None:
cmds.bakeResults(time = (timeRange[0], timeRange[1]), preserveOutsideKeys = preserveOutsideKeys, simulation = True, minimizeRotation = True, sampleBy = sampleBy)
else:
cmds.bakeResults(time = (timeRange[0], timeRange[1]), preserveOutsideKeys = preserveOutsideKeys, simulation = True, minimizeRotation = True, sampleBy = sampleBy, attribute = attributes)
Expand All @@ -76,8 +76,8 @@ def BakeSelected(classic=True, preserveOutsideKeys=True, sampleBy=1.0, selectedR

def BakeSelectedByLastObject(pairOnly=False, sampleBy=1.0, selectedRange=False, channelBox=False, attributes=None, euler=False):
# Check selected objects
selectedList = Selector.MultipleObjects(2)
if (selectedList == None):
selectedList = Selector.MultipleObjects(minimalCount = 2)
if selectedList is None:
return

# Cut list by last 2 items
Expand All @@ -100,8 +100,8 @@ def BakeSelectedByLastObject(pairOnly=False, sampleBy=1.0, selectedRange=False,

def BakeSelectedByWorld(sampleBy=1.0, selectedRange=False, channelBox=False, attributes=None, euler=False):
# Check selected objects
selectedList = Selector.MultipleObjects(1)
if (selectedList == None):
selectedList = Selector.MultipleObjects(minimalCount = 1)
if selectedList is None:
return

world = cmds.group(world = True, empty = True)
Expand Down
20 changes: 10 additions & 10 deletions GETOOLS_SOURCE/utils/Constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,25 @@ def ConstrainSecondToFirstObject(objectParent, objectChild, maintainOffset=True,
### Check attributes with fixed axis labels
def CheckAttributes(attributeName, attributesFiltered):
axisLabels = ["x", "y", "z"]
# Check which attributes are missing
### Check which attributes are missing
check = [attr in attributesFiltered for attr in attributeName]
# If all attributes are present, return "none"
### If all attributes are present, return "none"
if all(check):
return "none"
# Return the axis labels for missing attributes
### Return the axis labels for missing attributes
return [axisLabels[i] for i, valid in enumerate(check) if not valid]

### General function to process attributes
def ProcessAttributes(objectChild, attributeName):
# Construct attributes with object name
### Construct attributes with object name
attributes = ["{0}.{1}".format(objectChild, attr) for attr in attributeName]
attributesFiltered = Attributes.FilterAttributesAnimatable(attributes=attributes, skipConstrainedKeys = False)
# If no attributes are left after filtering, return "none"
### If no attributes are left after filtering, return "none"
if not attributesFiltered:
return ("x", "y", "z")
# Remove object name from attributes
### Remove object name from attributes
attributesFiltered = [attr.replace(objectChild + ".", "") for attr in attributesFiltered]
# Check attributes and return the axes to skip
### Check attributes and return the axes to skip
return CheckAttributes(attributeName, attributesFiltered)

### Use generalized logic for all attributes
Expand Down Expand Up @@ -107,14 +107,14 @@ def ProcessAttributes(objectChild, attributeName):
ConstrainAim(objectParent, objectChild, maintainOffset, weight) # TODO add customization logic

def ConstrainAim(objectParent, objectChild, maintainOffset=True, weight=1, aimVector=(0, 0, 1), upVector=(0, 1, 0), worldUpVector=(0, 1, 0), worldUpObject=None): # TODO complete aim logic
# "scene" "object" "objectrotation" "vector" "none"
### "scene" "object" "objectrotation" "vector" "none"
if worldUpObject is None:
cmds.aimConstraint(objectParent, objectChild, maintainOffset = maintainOffset, weight = weight, skip = "none", aimVector = aimVector, upVector = upVector, worldUpType = "vector", worldUpVector = worldUpVector)
else:
cmds.aimConstraint(objectParent, objectChild, maintainOffset = maintainOffset, weight = weight, skip = "none", aimVector = aimVector, upVector = upVector, worldUpType = "objectrotation", worldUpVector = worldUpVector, worldUpObject = worldUpObject)

def DeleteConstraints(selected):
# First pass
### First pass
connections = Selector.GetConnectionsOfType(selected, type = Enums.Types.constraint, source = True, destination = False)
for item in connections:
if item is None:
Expand All @@ -126,7 +126,7 @@ def DeleteConstraints(selected):
if constraint in connection:
cmds.delete(connection)

# Second pass with checking child objects (if constraint exists but not connected)
### Second pass with checking child objects (if constraint exists but not connected)
children = Selector.GetChildrenOfType(selected, type = Enums.Types.constraint)
for i in range(len(selected)):
if children[i] is not None:
Expand Down
28 changes: 12 additions & 16 deletions GETOOLS_SOURCE/utils/Curves.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,34 +27,31 @@
from ..values import Enums


_curveName = "newCurve"
_curveDegree = 1


def CreateCurveFromSelectedObjects(*args):
degree = 1 # TODO add options to UI

# Check selected objects
selectedList = Selector.MultipleObjects(2)
if (selectedList == None):
selected = Selector.MultipleObjects(minimalCount = 2)
if (selected == None):
return None

positions = []

for item in selectedList:
for item in selected:
position = cmds.xform(item, query = True, translation = True, worldSpace = True)
positions.append(position)

curve = cmds.curve(name = _curveName, degree = _curveDegree, point = positions)
curve = cmds.curve(name = "newCurve", degree = degree, point = positions)
return curve

def CreateCurveFromTrajectory(*args): # TODO rework
def CreateCurveFromTrajectory(name="curve", *args): # TODO rework
### Variables
step = 1
degree = 3
degree = 1

### Names
mtName = "newMotionTrail"
mtFinalName = mtName + Enums.MotionTrail.handle
curveName = "testCurve"


### Get time start/end
Expand All @@ -65,21 +62,20 @@ def CreateCurveFromTrajectory(*args): # TODO rework
cmds.snapshot(name = mtName, motionTrail = 1, increment = step, startTime = start, endTime = end)

### Get points from motion trail
cmds.select(mtFinalName, replace = 1)
selected = cmds.ls(selection = 1, dagObjects = 1, exactType = Enums.MotionTrail.snapshotShape)
cmds.select(mtFinalName, replace = True)
selected = cmds.ls(selection = True, dagObjects = True, exactType = Enums.MotionTrail.snapshotShape)
pts = cmds.getAttr(selected[0] + "." + Enums.MotionTrail.pts)
size = len(pts)
for i in range(size):
pts[i] = pts[i][0:3]
#print "{0}: {1}".format(i, pts[i])

### Create curve
newCurve = cmds.curve(name = curveName, degree = degree, point = pts)
newCurve = cmds.curve(name = name, degree = degree, point = pts)

### End
cmds.delete(mtFinalName)
cmds.select(clear = 1)
cmds.select(clear = True)

return newCurve


Loading