-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Shifter components: expose joint name description in settings. adding…
… Epic_hydraulic #102
- Loading branch information
1 parent
eefb8e3
commit 0f8d004
Showing
5 changed files
with
507 additions
and
0 deletions.
There are no files selected for viewing
152 changes: 152 additions & 0 deletions
152
release/scripts/mgear/shifter_epic_components/EPIC_hydraulic_01/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
"""Component Hydraulic 01 module""" | ||
|
||
from mgear.shifter import component | ||
from mgear.core import attribute, transform, primitive, applyop | ||
|
||
|
||
########################################################## | ||
# COMPONENT | ||
########################################################## | ||
|
||
|
||
class Component(component.Main): | ||
"""Shifter component Class""" | ||
|
||
# ===================================================== | ||
# OBJECTS | ||
# ===================================================== | ||
def addObjects(self): | ||
"""Add all the objects needed to create the component.""" | ||
|
||
self.normal = self.guide.blades["blade"].z * -1 | ||
self.binormal = self.guide.blades["blade"].x | ||
|
||
t = transform.getTransformLookingAt(self.guide.apos[0], | ||
self.guide.apos[1], | ||
self.normal, | ||
axis="yx", | ||
negate=self.negate) | ||
|
||
self.ctl_npo = primitive.addTransform( | ||
self.root, self.getName("ctl_npo"), t) | ||
self.ctl = self.addCtl(self.ctl_npo, | ||
"base_ctl", | ||
t, | ||
self.color_ik, | ||
"square", | ||
w=1.0, | ||
tp=self.parentCtlTag) | ||
attribute.setKeyableAttributes(self.ctl, self.tr_params) | ||
|
||
self.ref_base = primitive.addTransform( | ||
self.ctl, self.getName("ref_base"), t) | ||
|
||
t = transform.setMatrixPosition(t, self.guide.apos[1]) | ||
self.ik_cns = primitive.addTransform( | ||
self.root, self.getName("ik_cns"), t) | ||
self.tip_npo = primitive.addTransform( | ||
self.ik_cns, self.getName("tip_npo"), t) | ||
|
||
self.tip_ctl = self.addCtl(self.tip_npo, | ||
"tip_ctl", | ||
t, | ||
self.color_ik, | ||
"square", | ||
w=1.0, | ||
tp=self.ctl) | ||
|
||
attribute.setKeyableAttributes(self.tip_ctl, self.tr_params) | ||
|
||
self.ref_tip = primitive.addTransform( | ||
self.tip_ctl, self.getName("ref_tip"), t) | ||
|
||
self.div_cns = [] | ||
|
||
for i in range(self.settings["div"]): | ||
|
||
div_cns = primitive.addTransform(self.root, | ||
self.getName("div%s_loc" % i)) | ||
|
||
self.div_cns.append(div_cns) | ||
self.jnt_pos.append([div_cns, i]) | ||
|
||
# ===================================================== | ||
# ATTRIBUTES | ||
# ===================================================== | ||
def addAttributes(self): | ||
"""Create the anim and setupr rig attributes for the component""" | ||
|
||
# Ref | ||
if self.settings["ikrefarray"]: | ||
ref_names = self.get_valid_alias_list( | ||
self.settings["ikrefarray"].split(",")) | ||
if len(ref_names) > 1: | ||
self.ikref_att = self.addAnimEnumParam( | ||
"ikref", | ||
"Ik Ref", | ||
0, | ||
ref_names) | ||
|
||
# ===================================================== | ||
# OPERATORS | ||
# ===================================================== | ||
def addOperators(self): | ||
"""Create operators and set the relations for the component rig | ||
Apply operators, constraints, expressions to the hierarchy. | ||
In order to keep the code clean and easier to debug, | ||
we shouldn't create any new object in this method. | ||
""" | ||
applyop.aimCns(self.ref_base, | ||
self.tip_ctl, | ||
axis="yx", | ||
wupType=2, | ||
wupVector=[1, 0, 0], | ||
wupObject=self.ctl, | ||
maintainOffset=False) | ||
applyop.aimCns(self.ref_tip, | ||
self.ctl, | ||
axis="-yx", | ||
wupType=2, | ||
wupVector=[1, 0, 0], | ||
wupObject=self.tip_ctl, | ||
maintainOffset=False) | ||
|
||
bIncrement = 1.0 / (self.settings["div"] - 1) | ||
blend = 0 | ||
for i, div_cns in enumerate(self.div_cns): | ||
intMatrix = applyop.gear_intmatrix_op( | ||
self.ref_base.attr("worldMatrix"), | ||
self.ref_tip.attr("worldMatrix"), | ||
blend) | ||
|
||
applyop.gear_mulmatrix_op(intMatrix.attr("output"), | ||
div_cns.attr("parentInverseMatrix[0]"), | ||
div_cns) | ||
|
||
blend = blend + bIncrement | ||
|
||
# ===================================================== | ||
# CONNECTOR | ||
# ===================================================== | ||
def setRelation(self): | ||
"""Set the relation beetween object from guide to rig""" | ||
self.relatives["root"] = self.ref_base | ||
self.relatives["tip"] = self.ref_tip | ||
|
||
self.controlRelatives["root"] = self.ctl | ||
self.controlRelatives["tip"] = self.tip_ctl | ||
|
||
for i in range(0, len(self.div_cns) - 1): | ||
self.relatives["%s_loc" % i] = self.div_cns[i + 1] | ||
self.jointRelatives["%s_loc" % i] = i + 1 | ||
|
||
self.relatives["%s_loc" % (len(self.div_cns) - 1)] = self.div_cns[-1] | ||
|
||
dlen = len(self.div_cns) - 1 | ||
self.jointRelatives["%s_loc" % (len(self.div_cns) - 1)] = dlen | ||
|
||
def connect_standard(self): | ||
"""standard connection definition for the component""" | ||
self.connect_standardWithSimpleIkRef() |
155 changes: 155 additions & 0 deletions
155
release/scripts/mgear/shifter_epic_components/EPIC_hydraulic_01/guide.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
"""Guide Hydraulic 01 module""" | ||
|
||
from functools import partial | ||
|
||
from mgear.shifter.component import guide | ||
from mgear.core import transform, pyqt | ||
from mgear.vendor.Qt import QtWidgets, QtCore | ||
|
||
from maya.app.general.mayaMixin import MayaQWidgetDockableMixin | ||
from maya.app.general.mayaMixin import MayaQDockWidget | ||
|
||
from . import settingsUI as sui | ||
|
||
# guide info | ||
AUTHOR = "Jeremie Passerin, Miquel Campos" | ||
URL = "www.mcsGear.com" | ||
EMAIL = "" | ||
VERSION = [1, 0, 0] | ||
TYPE = "EPIC_hydraulic_01" | ||
NAME = "hydraulic" | ||
DESCRIPTION = "Hydraulic component for mechanical rigging." | ||
|
||
########################################################## | ||
# CLASS | ||
########################################################## | ||
|
||
|
||
class Guide(guide.ComponentGuide): | ||
"""Component Guide Class""" | ||
|
||
compType = TYPE | ||
compName = NAME | ||
description = DESCRIPTION | ||
|
||
author = AUTHOR | ||
url = URL | ||
email = EMAIL | ||
version = VERSION | ||
|
||
def postInit(self): | ||
"""Initialize the position for the guide""" | ||
self.save_transform = ["root", "tip"] | ||
self.save_blade = ["blade"] | ||
|
||
def addObjects(self): | ||
"""Add the Guide Root, blade and locators""" | ||
|
||
self.root = self.addRoot() | ||
vTemp = transform.getOffsetPosition(self.root, [2, 0, 0]) | ||
self.loc = self.addLoc("tip", self.root, vTemp) | ||
self.blade = self.addBlade("blade", self.root, self.loc) | ||
|
||
centers = [self.root, self.loc] | ||
self.dispcrv = self.addDispCurve("crv", centers) | ||
|
||
def addParameters(self): | ||
"""Add the configurations settings""" | ||
|
||
self.pRefArray = self.addParam("ikrefarray", "string", "") | ||
self.pUseIndex = self.addParam("useIndex", "bool", False) | ||
self.pParentJointIndex = self.addParam( | ||
"parentJointIndex", "long", -1, None, None) | ||
|
||
self.pDiv = self.addParam("div", "long", 2, 2, None) | ||
|
||
########################################################## | ||
# Setting Page | ||
########################################################## | ||
|
||
|
||
class settingsTab(QtWidgets.QDialog, sui.Ui_Form): | ||
"""The Component settings UI""" | ||
|
||
def __init__(self, parent=None): | ||
super(settingsTab, self).__init__(parent) | ||
self.setupUi(self) | ||
|
||
|
||
class componentSettings(MayaQWidgetDockableMixin, guide.componentMainSettings): | ||
"""Create the component setting window""" | ||
|
||
def __init__(self, parent=None): | ||
self.toolName = TYPE | ||
# Delete old instances of the componet settings window. | ||
pyqt.deleteInstances(self, MayaQDockWidget) | ||
|
||
super(self.__class__, self).__init__(parent=parent) | ||
self.settingsTab = settingsTab() | ||
|
||
self.setup_componentSettingWindow() | ||
self.create_componentControls() | ||
self.populate_componentControls() | ||
self.create_componentLayout() | ||
self.create_componentConnections() | ||
|
||
def setup_componentSettingWindow(self): | ||
self.mayaMainWindow = pyqt.maya_main_window() | ||
|
||
self.setObjectName(self.toolName) | ||
self.setWindowFlags(QtCore.Qt.Window) | ||
self.setWindowTitle(TYPE) | ||
self.resize(280, 350) | ||
|
||
def create_componentControls(self): | ||
return | ||
|
||
def populate_componentControls(self): | ||
"""Populate Controls | ||
Populate the controls values from the custom attributes of the | ||
component. | ||
""" | ||
# populate tab | ||
self.tabs.insertTab(1, self.settingsTab, "Component Settings") | ||
|
||
# populate component settings | ||
self.settingsTab.div_spinBox.setValue(self.root.attr("div").get()) | ||
|
||
refArrayItems = self.root.attr("ikrefarray").get().split(",") | ||
for item in refArrayItems: | ||
self.settingsTab.refArray_listWidget.addItem(item) | ||
|
||
def create_componentLayout(self): | ||
|
||
self.settings_layout = QtWidgets.QVBoxLayout() | ||
self.settings_layout.addWidget(self.tabs) | ||
self.settings_layout.addWidget(self.close_button) | ||
|
||
self.setLayout(self.settings_layout) | ||
|
||
def create_componentConnections(self): | ||
|
||
self.settingsTab.div_spinBox.valueChanged.connect( | ||
partial(self.updateSpinBox, self.settingsTab.div_spinBox, "div")) | ||
self.settingsTab.refArrayAdd_pushButton.clicked.connect( | ||
partial(self.addItem2listWidget, | ||
self.settingsTab.refArray_listWidget, | ||
"ikrefarray")) | ||
self.settingsTab.refArrayRemove_pushButton.clicked.connect( | ||
partial(self.removeSelectedFromListWidget, | ||
self.settingsTab.refArray_listWidget, | ||
"ikrefarray")) | ||
self.settingsTab.refArray_listWidget.installEventFilter(self) | ||
|
||
def eventFilter(self, sender, event): | ||
if event.type() == QtCore.QEvent.ChildRemoved: | ||
if sender == self.settingsTab.refArray_listWidget: | ||
self.updateListAttr(sender, "ikrefarray") | ||
return True | ||
else: | ||
return QtWidgets.QDialog.eventFilter(self, sender, event) | ||
|
||
def dockCloseEventTriggered(self): | ||
pyqt.deleteInstances(self, MayaQDockWidget) |
Binary file added
BIN
+1.92 KB
release/scripts/mgear/shifter_epic_components/EPIC_hydraulic_01/icon.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
88 changes: 88 additions & 0 deletions
88
release/scripts/mgear/shifter_epic_components/EPIC_hydraulic_01/settingsUI.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# MGEAR is under the terms of the MIT License | ||
|
||
# Copyright (c) 2016 Jeremie Passerin, Miquel Campos | ||
|
||
# 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: Jeremie Passerin geerem@hotmail.com www.jeremiepasserin.com | ||
# Author: Miquel Campos hello@miquel-campos.com www.miquel-campos.com | ||
# Date: 2016 / 10 / 10 | ||
|
||
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(232, 418) | ||
self.gridLayout = QtWidgets.QGridLayout(Form) | ||
self.gridLayout.setObjectName("gridLayout") | ||
self.horizontalLayout = QtWidgets.QHBoxLayout() | ||
self.horizontalLayout.setObjectName("horizontalLayout") | ||
self.divisions_label = QtWidgets.QLabel(Form) | ||
self.divisions_label.setObjectName("divisions_label") | ||
self.horizontalLayout.addWidget(self.divisions_label) | ||
self.div_spinBox = QtWidgets.QSpinBox(Form) | ||
self.div_spinBox.setMinimum(2) | ||
self.div_spinBox.setProperty("value", 2) | ||
self.div_spinBox.setObjectName("div_spinBox") | ||
self.horizontalLayout.addWidget(self.div_spinBox) | ||
self.gridLayout.addLayout(self.horizontalLayout, 0, 0, 1, 1) | ||
self.upvRefArray_groupBox = QtWidgets.QGroupBox(Form) | ||
self.upvRefArray_groupBox.setObjectName("upvRefArray_groupBox") | ||
self.gridLayout_2 = QtWidgets.QGridLayout(self.upvRefArray_groupBox) | ||
self.gridLayout_2.setObjectName("gridLayout_2") | ||
self.upvRefArray_horizontalLayout = QtWidgets.QHBoxLayout() | ||
self.upvRefArray_horizontalLayout.setObjectName("upvRefArray_horizontalLayout") | ||
self.upvRefArray_verticalLayout_1 = QtWidgets.QVBoxLayout() | ||
self.upvRefArray_verticalLayout_1.setObjectName("upvRefArray_verticalLayout_1") | ||
self.refArray_listWidget = QtWidgets.QListWidget(self.upvRefArray_groupBox) | ||
self.refArray_listWidget.setDragDropOverwriteMode(True) | ||
self.refArray_listWidget.setDragDropMode(QtWidgets.QAbstractItemView.InternalMove) | ||
self.refArray_listWidget.setDefaultDropAction(QtCore.Qt.MoveAction) | ||
self.refArray_listWidget.setAlternatingRowColors(True) | ||
self.refArray_listWidget.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection) | ||
self.refArray_listWidget.setSelectionRectVisible(False) | ||
self.refArray_listWidget.setObjectName("refArray_listWidget") | ||
self.upvRefArray_verticalLayout_1.addWidget(self.refArray_listWidget) | ||
self.upvRefArray_horizontalLayout.addLayout(self.upvRefArray_verticalLayout_1) | ||
self.upvRefArray_verticalLayout_2 = QtWidgets.QVBoxLayout() | ||
self.upvRefArray_verticalLayout_2.setObjectName("upvRefArray_verticalLayout_2") | ||
self.refArrayAdd_pushButton = QtWidgets.QPushButton(self.upvRefArray_groupBox) | ||
self.refArrayAdd_pushButton.setObjectName("refArrayAdd_pushButton") | ||
self.upvRefArray_verticalLayout_2.addWidget(self.refArrayAdd_pushButton) | ||
self.refArrayRemove_pushButton = QtWidgets.QPushButton(self.upvRefArray_groupBox) | ||
self.refArrayRemove_pushButton.setObjectName("refArrayRemove_pushButton") | ||
self.upvRefArray_verticalLayout_2.addWidget(self.refArrayRemove_pushButton) | ||
spacerItem = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding) | ||
self.upvRefArray_verticalLayout_2.addItem(spacerItem) | ||
self.upvRefArray_horizontalLayout.addLayout(self.upvRefArray_verticalLayout_2) | ||
self.gridLayout_2.addLayout(self.upvRefArray_horizontalLayout, 0, 0, 1, 1) | ||
self.gridLayout.addWidget(self.upvRefArray_groupBox, 1, 0, 1, 1) | ||
|
||
self.retranslateUi(Form) | ||
QtCore.QMetaObject.connectSlotsByName(Form) | ||
|
||
def retranslateUi(self, Form): | ||
Form.setWindowTitle(gqt.fakeTranslate("Form", "Form", None, -1)) | ||
self.divisions_label.setText(gqt.fakeTranslate("Form", "Divisions", None, -1)) | ||
self.upvRefArray_groupBox.setTitle(gqt.fakeTranslate("Form", "Tip Reference Array", None, -1)) | ||
self.refArrayAdd_pushButton.setText(gqt.fakeTranslate("Form", "<<", None, -1)) | ||
self.refArrayRemove_pushButton.setText(gqt.fakeTranslate("Form", ">>", None, -1)) | ||
|
Oops, something went wrong.