Skip to content

Commit

Permalink
Shifter: optinal controls orientation closes #163
Browse files Browse the repository at this point in the history
  • Loading branch information
miquelcampos committed Nov 29, 2022
1 parent a136c0b commit ab5dedf
Show file tree
Hide file tree
Showing 7 changed files with 237 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ def populate_componentControls(self):
self.settingsTab.maxSquash_spinBox.setValue(
self.root.attr("maxsquash").get())

self.settingsTab.ctlOri_comboBox.setCurrentIndex(
self.root.attr("ctlOrientation").get()
)

def create_componentLayout(self):

self.settings_layout = QtWidgets.QVBoxLayout()
Expand Down Expand Up @@ -187,5 +191,13 @@ def create_componentConnections(self):
self.settingsTab.maxSquash_spinBox,
"maxsquash"))

self.settingsTab.ctlOri_comboBox.currentIndexChanged.connect(
partial(
self.updateComboBox,
self.settingsTab.ctlOri_comboBox,
"ctlOrientation",
)
)

def dockCloseEventTriggered(self):
pyqt.deleteInstances(self, MayaQDockWidget)
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'C:/datawork/repo/mgear4/release/scripts/mgear/shifter_classic_components/chain_IK_spline_variable_FK_01/settingsUI.ui'
#
# Created: Tue Nov 29 10:59:41 2022
# by: pyside2-uic running on PySide2 2.0.0~alpha0
#
# WARNING! All changes made in this file will be lost!

import mgear.core.pyqt as gqt
QtGui, QtCore, QtWidgets, wrapInstance = gqt.qt_import()

class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(272, 232)
Form.resize(406, 440)
self.verticalLayout = QtWidgets.QVBoxLayout(Form)
self.verticalLayout.setObjectName("verticalLayout")
self.groupBox_3 = QtWidgets.QGroupBox(Form)
Expand Down Expand Up @@ -63,30 +72,14 @@ def setupUi(self, Form):
self.position_spinBox.setObjectName("position_spinBox")
self.horizontalLayout_4.addWidget(self.position_spinBox)
self.formLayout.setLayout(1, QtWidgets.QFormLayout.FieldRole, self.horizontalLayout_4)
self.softness_label_3 = QtWidgets.QLabel(Form)
self.softness_label_3.setObjectName("softness_label_3")
self.formLayout.setWidget(2, QtWidgets.QFormLayout.LabelRole, self.softness_label_3)
self.horizontalLayout_5 = QtWidgets.QHBoxLayout()
self.horizontalLayout_5.setObjectName("horizontalLayout_5")
self.lockOri_slider = QtWidgets.QSlider(Form)
self.lockOri_slider.setMinimumSize(QtCore.QSize(0, 15))
self.lockOri_slider.setMaximum(100)
self.lockOri_slider.setOrientation(QtCore.Qt.Horizontal)
self.lockOri_slider.setObjectName("lockOri_slider")
self.horizontalLayout_5.addWidget(self.lockOri_slider)
self.lockOri_spinBox = QtWidgets.QSpinBox(Form)
self.lockOri_spinBox.setMaximum(100)
self.lockOri_spinBox.setObjectName("lockOri_spinBox")
self.horizontalLayout_5.addWidget(self.lockOri_spinBox)
self.formLayout.setLayout(2, QtWidgets.QFormLayout.FieldRole, self.horizontalLayout_5)
self.maxStretch_label = QtWidgets.QLabel(Form)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding, QtWidgets.QSizePolicy.MinimumExpanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.maxStretch_label.sizePolicy().hasHeightForWidth())
self.maxStretch_label.setSizePolicy(sizePolicy)
self.maxStretch_label.setObjectName("maxStretch_label")
self.formLayout.setWidget(3, QtWidgets.QFormLayout.LabelRole, self.maxStretch_label)
self.formLayout.setWidget(2, QtWidgets.QFormLayout.LabelRole, self.maxStretch_label)
self.maxStretch_spinBox = QtWidgets.QDoubleSpinBox(Form)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
Expand All @@ -97,15 +90,15 @@ def setupUi(self, Form):
self.maxStretch_spinBox.setSingleStep(0.1)
self.maxStretch_spinBox.setProperty("value", 1.0)
self.maxStretch_spinBox.setObjectName("maxStretch_spinBox")
self.formLayout.setWidget(3, QtWidgets.QFormLayout.FieldRole, self.maxStretch_spinBox)
self.formLayout.setWidget(2, QtWidgets.QFormLayout.FieldRole, self.maxStretch_spinBox)
self.maxSquash_label = QtWidgets.QLabel(Form)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding, QtWidgets.QSizePolicy.MinimumExpanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.maxSquash_label.sizePolicy().hasHeightForWidth())
self.maxSquash_label.setSizePolicy(sizePolicy)
self.maxSquash_label.setObjectName("maxSquash_label")
self.formLayout.setWidget(4, QtWidgets.QFormLayout.LabelRole, self.maxSquash_label)
self.formLayout.setWidget(3, QtWidgets.QFormLayout.LabelRole, self.maxSquash_label)
self.maxSquash_spinBox = QtWidgets.QDoubleSpinBox(Form)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
Expand All @@ -117,8 +110,19 @@ def setupUi(self, Form):
self.maxSquash_spinBox.setSingleStep(0.1)
self.maxSquash_spinBox.setProperty("value", 1.0)
self.maxSquash_spinBox.setObjectName("maxSquash_spinBox")
self.formLayout.setWidget(4, QtWidgets.QFormLayout.FieldRole, self.maxSquash_spinBox)
self.formLayout.setWidget(3, QtWidgets.QFormLayout.FieldRole, self.maxSquash_spinBox)
self.ctlOri_comboBox = QtWidgets.QComboBox(Form)
self.ctlOri_comboBox.setObjectName("ctlOri_comboBox")
self.ctlOri_comboBox.addItem("")
self.ctlOri_comboBox.addItem("")
self.ctlOri_comboBox.addItem("")
self.formLayout.setWidget(4, QtWidgets.QFormLayout.FieldRole, self.ctlOri_comboBox)
self.ctlOri_label = QtWidgets.QLabel(Form)
self.ctlOri_label.setObjectName("ctlOri_label")
self.formLayout.setWidget(4, QtWidgets.QFormLayout.LabelRole, self.ctlOri_label)
self.verticalLayout.addLayout(self.formLayout)
spacerItem = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
self.verticalLayout.addItem(spacerItem)

self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
Expand All @@ -129,7 +133,10 @@ def retranslateUi(self, Form):
self.fkNb_label.setText(gqt.fakeTranslate("Form", "FK Ctl Number", None, -1))
self.softness_label.setText(gqt.fakeTranslate("Form", "Softness", None, -1))
self.softness_label_2.setText(gqt.fakeTranslate("Form", "Position", None, -1))
self.softness_label_3.setText(gqt.fakeTranslate("Form", "Lock Orient", None, -1))
self.maxStretch_label.setText(gqt.fakeTranslate("Form", "Max Stretch", None, -1))
self.maxSquash_label.setText(gqt.fakeTranslate("Form", "Max Squash", None, -1))
self.ctlOri_comboBox.setItemText(0, gqt.fakeTranslate("Form", "XZ", None, -1))
self.ctlOri_comboBox.setItemText(1, gqt.fakeTranslate("Form", "YZ", None, -1))
self.ctlOri_comboBox.setItemText(2, gqt.fakeTranslate("Form", "ZX", None, -1))
self.ctlOri_label.setText(gqt.fakeTranslate("Form", "CTL Orientation", None, -1))

Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>272</width>
<height>232</height>
<width>406</width>
<height>440</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -194,8 +194,47 @@
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QComboBox" name="ctlOri_comboBox">
<item>
<property name="text">
<string>XZ</string>
</property>
</item>
<item>
<property name="text">
<string>YZ</string>
</property>
</item>
<item>
<property name="text">
<string>ZX</string>
</property>
</item>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="ctlOri_label">
<property name="text">
<string>CTL Orientation</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,47 @@ def addObjects(self):
j.drawStyle.set(2)

# Ik Controlers ------------------------------------
axis_ori = ["yx", "x-y", "zx"][self.settings["ctlOrientation"]]
t = transform.getTransformLookingAt(self.guide.apos[0],
self.guide.apos[1],
self.guide.blades["blade"].z * -1,
"yx",
axis_ori,
self.negate)

# check first axis
if axis_ori[0] == "-":
first_axis = axis_ori[1]
else:
first_axis = axis_ori[0]
# set ro offset
if first_axis == "x":
ro_vec = datatypes.Vector([0, 0, 1.5708])
self.front_axis = 0
self.up_axis = 1
self.ref_twist_vec = datatypes.Vector(-1.0, 0, 0)
self.dist_attr = "tx"
self.autoBend_ro_axis = "rx"
self.ikAutoRot_X = "rz"
self.ikAutoRot_Y = "ry"
elif first_axis == "y":
ro_vec = datatypes.Vector([0, 0, 0])
self.front_axis = 1
self.up_axis = 0
self.ref_twist_vec = datatypes.Vector(1.0, 0, 0.0)
self.dist_attr = "ty"
self.autoBend_ro_axis = "ry"
self.ikAutoRot_X = "rz"
self.ikAutoRot_Y = "rx"
elif first_axis == "z":
ro_vec = datatypes.Vector([1.5708, 0, 0])
self.front_axis = 2
self.up_axis = 0
self.ref_twist_vec = datatypes.Vector(1.0, 0, 0)
self.dist_attr = "tz"
self.autoBend_ro_axis = "rz"
self.ikAutoRot_X = "ry"
self.ikAutoRot_Y = "rx"

self.ik0_npo = primitive.addTransform(
self.root, self.getName("ik0_npo"), t)

Expand All @@ -51,11 +86,12 @@ def addObjects(self):
self.color_ik,
"compas",
w=self.size,
ro=ro_vec,
tp=self.parentCtlTag)

attribute.setKeyableAttributes(self.ik0_ctl, self.tr_params)
attribute.setRotOrder(self.ik0_ctl, "ZXY")
attribute.setInvertMirror(self.ik0_ctl, ["tx", "ry", "rz"])
attribute.setInvertMirror(self.ik0_ctl, ["tx", self.autoBend_ro_axis, "rz"])

t = transform.setMatrixPosition(t, self.guide.apos[1])
if self.settings["autoBend"]:
Expand All @@ -69,12 +105,13 @@ def addObjects(self):
"square",
w=self.size,
d=.3 * self.size,
ro=ro_vec,
tp=self.parentCtlTag)

attribute.setKeyableAttributes(self.autoBend_ctl,
["tx", "ty", "tz", "ry"])
["tx", "ty", "tz", self.autoBend_ro_axis])

attribute.setInvertMirror(self.autoBend_ctl, ["tx", "ry"])
attribute.setInvertMirror(self.autoBend_ctl, ["tx", self.autoBend_ro_axis])

self.ik1_npo = primitive.addTransform(
self.autoBendChain[0], self.getName("ik1_npo"), t)
Expand All @@ -88,6 +125,7 @@ def addObjects(self):
self.color_ik,
"compas",
w=self.size,
ro=ro_vec,
tp=self.autoBend_ctl)
else:
t = transform.setMatrixPosition(t, self.guide.apos[1])
Expand All @@ -99,11 +137,12 @@ def addObjects(self):
self.color_ik,
"compas",
w=self.size,
ro=ro_vec,
tp=self.ik0_ctl)

attribute.setKeyableAttributes(self.ik1_ctl, self.tr_params)
attribute.setRotOrder(self.ik1_ctl, "ZXY")
attribute.setInvertMirror(self.ik1_ctl, ["tx", "ry", "rz"])
attribute.setInvertMirror(self.ik1_ctl, ["tx", self.autoBend_ro_axis, "rz"])

# Tangent controllers -------------------------------
if self.settings["centralTangent"]:
Expand Down Expand Up @@ -185,6 +224,7 @@ def addObjects(self):
self.color_ik,
"sphere",
w=self.size * .2,
ro=ro_vec,
tp=self.ik0_ctl)

attribute.setKeyableAttributes(self.tan0_ctl, self.t_params)
Expand All @@ -204,6 +244,7 @@ def addObjects(self):
self.color_ik,
"sphere",
w=self.size * .2,
ro=ro_vec,
tp=self.ik1_ctl)

attribute.setKeyableAttributes(self.tan1_ctl, self.t_params)
Expand Down Expand Up @@ -289,6 +330,7 @@ def addObjects(self):
w=self.size,
h=self.size * .05,
d=self.size,
ro=ro_vec,
tp=self.preiviousCtlTag)

attribute.setKeyableAttributes(self.fk_ctl)
Expand Down Expand Up @@ -322,7 +364,7 @@ def addObjects(self):
ref_twist = primitive.addTransform(
parent_twistRef, self.getName("%s_pos_ref" % i), t)
ref_twist.setTranslation(
datatypes.Vector(1.0, 0, 0), space="preTransform")
self.ref_twist_vec, space="preTransform")

self.twister.append(twister)
self.ref_twist.append(ref_twist)
Expand Down Expand Up @@ -437,8 +479,26 @@ def addOperators(self):
[self.autoBendChain[0].ry, self.autoBendChain[0].rz],
[self.sideBend_att, self.frontBend_att])

mul_node.outputX >> self.ik1autoRot_lvl.rz
mul_node.outputY >> self.ik1autoRot_lvl.rx
# mul_node.outputX >> self.ik1autoRot_lvl.rz
# mul_node.outputY >> self.ik1autoRot_lvl.rx

# invert when ikAutoRot is ry
if self.ikAutoRot_X == "ry":
invert_rot_X = -1
else:
invert_rot_X = 1
# invert when ikAutoRot is ry
if self.ikAutoRot_Y == "ry":
invert_rot_Y = -1
else:
invert_rot_Y = 1

mul_node2 = node.createMulNode(
[mul_node.outputX, mul_node.outputY],
[invert_rot_X, invert_rot_Y])

mul_node2.outputX >> self.ik1autoRot_lvl.attr(self.ikAutoRot_X)
mul_node2.outputY >> self.ik1autoRot_lvl.attr(self.ikAutoRot_Y)

self.ikHandleAutoBend = primitive.addIkHandle(
self.autoBend_ctl,
Expand All @@ -460,22 +520,22 @@ def addOperators(self):

# tan0
mul_node = node.createMulNode(self.tan0_att,
self.tan0_npo.getAttr("ty"))
self.tan0_npo.getAttr(self.dist_attr))

res_node = node.createMulNode(mul_node + ".outputX",
div_node + ".outputX")

pm.connectAttr(res_node + ".outputX",
self.tan0_npo.attr("ty"))
self.tan0_npo.attr(self.dist_attr))

# tan1
mul_node = node.createMulNode(self.tan1_att,
self.tan1_npo.getAttr("ty"))
self.tan1_npo.getAttr(self.dist_attr))

res_node = node.createMulNode(mul_node + ".outputX",
div_node + ".outputX")

pm.connectAttr(res_node + ".outputX", self.tan1_npo.attr("ty"))
pm.connectAttr(res_node + ".outputX", self.tan1_npo.attr(self.dist_attr))

# Tangent Mid --------------------------------------
if self.settings["centralTangent"]:
Expand Down Expand Up @@ -515,8 +575,8 @@ def addOperators(self):

cns = applyop.pathCns(
self.div_cns[i], self.slv_crv, False, u, True)
cns.setAttr("frontAxis", 1) # front axis is 'Y'
cns.setAttr("upAxis", 0) # front axis is 'X'
cns.setAttr("frontAxis", self.front_axis) # front axis
cns.setAttr("upAxis", self.up_axis) # up axis

# Roll
intMatrix = applyop.gear_intmatrix_op(
Expand Down
Loading

0 comments on commit ab5dedf

Please sign in to comment.