From 48a1f294843a3a7b3f12f9dd3d8af23ae218e0c3 Mon Sep 17 00:00:00 2001 From: Joji Date: Wed, 27 Dec 2023 23:52:58 -0800 Subject: [PATCH 1/6] Added an option to mirror the controller's behaviour between L and R sides for shoulder_01 --- .../shoulder_01/__init__.py | 11 +++++++++ .../shoulder_01/guide.py | 16 +++++++++++-- .../shoulder_01/settingsUI.py | 12 +++++++++- .../shoulder_01/settingsUI.ui | 24 +++++++++++++++++-- 4 files changed, 58 insertions(+), 5 deletions(-) diff --git a/release/scripts/mgear/shifter_classic_components/shoulder_01/__init__.py b/release/scripts/mgear/shifter_classic_components/shoulder_01/__init__.py index fb998734..aa4ab3ce 100644 --- a/release/scripts/mgear/shifter_classic_components/shoulder_01/__init__.py +++ b/release/scripts/mgear/shifter_classic_components/shoulder_01/__init__.py @@ -26,6 +26,9 @@ def addObjects(self): self.length0 = vector.getDistance(self.guide.apos[0], self.guide.apos[1]) + if self.settings["mirrorBehaviour"] and self.negate: + self.length0 = self.length0 * -1 + t = transform.getTransformLookingAt(self.guide.apos[0], self.guide.apos[1], self.normal, @@ -47,6 +50,10 @@ def addObjects(self): po=datatypes.Vector(.5 * self.length0 * self.n_factor, 0, 0), tp=self.parentCtlTag) + if self.settings["mirrorBehaviour"] and self.negate: + self.ctl_npo.ry.set(180) + self.ctl_npo.sz.set(-1) + t = transform.getTransformFromPos(self.guide.apos[1]) self.orbit_ref1 = primitive.addTransform( self.ctl, self.getName("orbit_ref1"), t) @@ -66,6 +73,10 @@ def addObjects(self): w=self.length0 / 4, tp=self.ctl) + if self.settings["mirrorBehaviour"] and self.negate: + self.orbit_cns.rotateBy((0, 180, 0), space="object") + self.orbit_cns.sy.set(-1) + self.jnt_pos.append([self.ctl, "shoulder"]) # ===================================================== diff --git a/release/scripts/mgear/shifter_classic_components/shoulder_01/guide.py b/release/scripts/mgear/shifter_classic_components/shoulder_01/guide.py index 8e6c674a..29e2da5e 100644 --- a/release/scripts/mgear/shifter_classic_components/shoulder_01/guide.py +++ b/release/scripts/mgear/shifter_classic_components/shoulder_01/guide.py @@ -12,10 +12,10 @@ from . import settingsUI as sui # guide info -AUTHOR = "Jeremie Passerin, Miquel Campos" +AUTHOR = "Jeremie Passerin, Miquel Campos, Joji Nishimura" URL = ", www.miquletd.com" EMAIL = ", " -VERSION = [1, 0, 0] +VERSION = [1, 1, 0] TYPE = "shoulder_01" NAME = "shoulder" DESCRIPTION = "Simple shoulder with space switch for\n the arm, and Orbit " \ @@ -59,6 +59,7 @@ def addParameters(self): self.pRefArray = self.addParam("refArray", "string", "") self.pUseIndex = self.addParam("useIndex", "bool", False) + self.pMirrorBehaviour = self.addParam("mirrorBehaviour", "bool", False) self.pParentJointIndex = self.addParam( "parentJointIndex", "long", -1, None, None) @@ -114,6 +115,13 @@ def populate_componentControls(self): # populate tab self.tabs.insertTab(1, self.settingsTab, "Component Settings") + if self.root.attr("mirrorBehaviour").get(): + self.settingsTab.mirrorBehaviour_checkBox.setCheckState( + QtCore.Qt.Checked) + else: + self.settingsTab.mirrorBehaviour_checkBox.setCheckState( + QtCore.Qt.Unchecked) + # populate component settings refArrayItems = self.root.attr("refArray").get().split(",") for item in refArrayItems: @@ -128,6 +136,10 @@ def create_componentLayout(self): self.setLayout(self.settings_layout) def create_componentConnections(self): + self.settingsTab.mirrorBehaviour_checkBox.stateChanged.connect( + partial(self.updateCheck, + self.settingsTab.mirrorBehaviour_checkBox, + "mirrorBehaviour")) self.settingsTab.refArrayAdd_pushButton.clicked.connect( partial(self.addItem2listWidget, diff --git a/release/scripts/mgear/shifter_classic_components/shoulder_01/settingsUI.py b/release/scripts/mgear/shifter_classic_components/shoulder_01/settingsUI.py index 6dbefe37..73cb1d43 100644 --- a/release/scripts/mgear/shifter_classic_components/shoulder_01/settingsUI.py +++ b/release/scripts/mgear/shifter_classic_components/shoulder_01/settingsUI.py @@ -33,6 +33,15 @@ def setupUi(self, Form): Form.resize(284, 207) self.gridLayout = QtWidgets.QGridLayout(Form) self.gridLayout.setObjectName("gridLayout") + self.mirrorBehaviour_groupBox = QtWidgets.QGroupBox(Form) + self.mirrorBehaviour_groupBox.setTitle("") + self.mirrorBehaviour_groupBox.setObjectName("mirrorBehaviour_groupBox") + self.mirrorBehaviour_gridLayout = QtWidgets.QGridLayout(self.mirrorBehaviour_groupBox) + self.mirrorBehaviour_gridLayout.setObjectName("mirrorBehaviour_gridLayout") + self.mirrorBehaviour_checkBox = QtWidgets.QCheckBox(Form) + self.mirrorBehaviour_checkBox.setObjectName("mirrorBehaviour_checkBox") + self.mirrorBehaviour_gridLayout.addWidget(self.mirrorBehaviour_checkBox) + self.gridLayout.addWidget(self.mirrorBehaviour_groupBox, 0, 0, 1, 1) self.upvRefArray_groupBox = QtWidgets.QGroupBox(Form) self.upvRefArray_groupBox.setObjectName("upvRefArray_groupBox") self.gridLayout_2 = QtWidgets.QGridLayout(self.upvRefArray_groupBox) @@ -63,13 +72,14 @@ def setupUi(self, Form): 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, 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.mirrorBehaviour_checkBox.setText(gqt.fakeTranslate("Form", "Mirror Behaviour L and R", None, -1)) self.upvRefArray_groupBox.setTitle(gqt.fakeTranslate("Form", "Reference Array", None, -1)) self.refArrayAdd_pushButton.setText(gqt.fakeTranslate("Form", "<<", None, -1)) self.refArrayRemove_pushButton.setText(gqt.fakeTranslate("Form", ">>", None, -1)) diff --git a/release/scripts/mgear/shifter_classic_components/shoulder_01/settingsUI.ui b/release/scripts/mgear/shifter_classic_components/shoulder_01/settingsUI.ui index 36c583db..b447cf1a 100644 --- a/release/scripts/mgear/shifter_classic_components/shoulder_01/settingsUI.ui +++ b/release/scripts/mgear/shifter_classic_components/shoulder_01/settingsUI.ui @@ -7,7 +7,7 @@ 0 0 284 - 207 + 361 @@ -15,12 +15,32 @@ + + + + + + + + + + + Mirror Behaviour L and R + + + + + + + + + Reference Array - + From 21c9eaa9530f08042fd409ce0ae13415ae2631fd Mon Sep 17 00:00:00 2001 From: Joji Date: Wed, 27 Dec 2023 23:53:05 -0800 Subject: [PATCH 2/6] Added an option to mirror the controller's behaviour between L and R sides for shoulder_02 --- .../shoulder_02/__init__.py | 11 ++++++++++ .../shoulder_02/guide.py | 16 ++++++++++++-- .../shoulder_02/settingsUI.py | 12 +++++++++- .../shoulder_02/settingsUI.ui | 22 ++++++++++++++++++- 4 files changed, 57 insertions(+), 4 deletions(-) diff --git a/release/scripts/mgear/shifter_classic_components/shoulder_02/__init__.py b/release/scripts/mgear/shifter_classic_components/shoulder_02/__init__.py index dba24156..832cb8a2 100644 --- a/release/scripts/mgear/shifter_classic_components/shoulder_02/__init__.py +++ b/release/scripts/mgear/shifter_classic_components/shoulder_02/__init__.py @@ -26,6 +26,9 @@ def addObjects(self): self.length0 = vector.getDistance(self.guide.apos[0], self.guide.apos[1]) + if self.settings["mirrorBehaviour"] and self.negate: + self.length0 = self.length0 * -1 + t = transform.getTransformLookingAt(self.guide.apos[0], self.guide.apos[1], self.normal, @@ -47,6 +50,10 @@ def addObjects(self): po=datatypes.Vector(.5 * self.length0 * self.n_factor, 0, 0), tp=self.parentCtlTag) + if self.settings["mirrorBehaviour"] and self.negate: + self.ctl_npo.ry.set(180) + self.ctl_npo.sz.set(-1) + t = transform.getTransformFromPos(self.guide.apos[2]) self.orbit_ref1 = primitive.addTransform( self.ctl, self.getName("orbit_ref1"), t) @@ -66,6 +73,10 @@ def addObjects(self): w=self.length0 / 4, tp=self.ctl) + if self.settings["mirrorBehaviour"] and self.negate: + self.orbit_cns.rotateBy((0, 180, 0), space="object") + self.orbit_cns.sy.set(-1) + self.jnt_pos.append([self.ctl, "shoulder"]) # ===================================================== diff --git a/release/scripts/mgear/shifter_classic_components/shoulder_02/guide.py b/release/scripts/mgear/shifter_classic_components/shoulder_02/guide.py index 03a80c2a..e870c7ce 100644 --- a/release/scripts/mgear/shifter_classic_components/shoulder_02/guide.py +++ b/release/scripts/mgear/shifter_classic_components/shoulder_02/guide.py @@ -12,10 +12,10 @@ from . import settingsUI as sui # guide info -AUTHOR = "anima inc." +AUTHOR = "anima inc., Joji Nishimura" URL = "www.studioanima.co.jp" EMAIL = "" -VERSION = [1, 0, 0] +VERSION = [1, 1, 0] TYPE = "shoulder_02" NAME = "shoulder" DESCRIPTION = "Simple shoulder with space switch for\n the arm, and Orbit " \ @@ -63,6 +63,7 @@ def addParameters(self): self.pRefArray = self.addParam("refArray", "string", "") self.pUseIndex = self.addParam("useIndex", "bool", False) + self.pMirrorBehaviour = self.addParam("mirrorBehaviour", "bool", False) self.pParentJointIndex = self.addParam( "parentJointIndex", "long", -1, None, None) @@ -118,6 +119,13 @@ def populate_componentControls(self): # populate tab self.tabs.insertTab(1, self.settingsTab, "Component Settings") + if self.root.attr("mirrorBehaviour").get(): + self.settingsTab.mirrorBehaviour_checkBox.setCheckState( + QtCore.Qt.Checked) + else: + self.settingsTab.mirrorBehaviour_checkBox.setCheckState( + QtCore.Qt.Unchecked) + # populate component settings refArrayItems = self.root.attr("refArray").get().split(",") for item in refArrayItems: @@ -132,6 +140,10 @@ def create_componentLayout(self): self.setLayout(self.settings_layout) def create_componentConnections(self): + self.settingsTab.mirrorBehaviour_checkBox.stateChanged.connect( + partial(self.updateCheck, + self.settingsTab.mirrorBehaviour_checkBox, + "mirrorBehaviour")) self.settingsTab.refArrayAdd_pushButton.clicked.connect( partial(self.addItem2listWidget, diff --git a/release/scripts/mgear/shifter_classic_components/shoulder_02/settingsUI.py b/release/scripts/mgear/shifter_classic_components/shoulder_02/settingsUI.py index 2bd4970c..8587b32a 100644 --- a/release/scripts/mgear/shifter_classic_components/shoulder_02/settingsUI.py +++ b/release/scripts/mgear/shifter_classic_components/shoulder_02/settingsUI.py @@ -33,6 +33,15 @@ def setupUi(self, Form): Form.resize(284, 207) self.gridLayout = QtWidgets.QGridLayout(Form) self.gridLayout.setObjectName("gridLayout") + self.mirrorBehaviour_groupBox = QtWidgets.QGroupBox(Form) + self.mirrorBehaviour_groupBox.setTitle("") + self.mirrorBehaviour_groupBox.setObjectName("mirrorBehaviour_groupBox") + self.mirrorBehaviour_gridLayout = QtWidgets.QGridLayout(self.mirrorBehaviour_groupBox) + self.mirrorBehaviour_gridLayout.setObjectName("mirrorBehaviour_gridLayout") + self.mirrorBehaviour_checkBox = QtWidgets.QCheckBox(Form) + self.mirrorBehaviour_checkBox.setObjectName("mirrorBehaviour_checkBox") + self.mirrorBehaviour_gridLayout.addWidget(self.mirrorBehaviour_checkBox) + self.gridLayout.addWidget(self.mirrorBehaviour_groupBox, 0, 0, 1, 1) self.upvRefArray_groupBox = QtWidgets.QGroupBox(Form) self.upvRefArray_groupBox.setObjectName("upvRefArray_groupBox") self.gridLayout_2 = QtWidgets.QGridLayout(self.upvRefArray_groupBox) @@ -63,13 +72,14 @@ def setupUi(self, Form): 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, 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.mirrorBehaviour_checkBox.setText(gqt.fakeTranslate("Form", "Mirror Behaviour L and R", None, -1)) self.upvRefArray_groupBox.setTitle(gqt.fakeTranslate("Form", "Reference Array", None, -1)) self.refArrayAdd_pushButton.setText(gqt.fakeTranslate("Form", "<<", None, -1)) self.refArrayRemove_pushButton.setText(gqt.fakeTranslate("Form", ">>", None, -1)) diff --git a/release/scripts/mgear/shifter_classic_components/shoulder_02/settingsUI.ui b/release/scripts/mgear/shifter_classic_components/shoulder_02/settingsUI.ui index 36c583db..8a4be24c 100644 --- a/release/scripts/mgear/shifter_classic_components/shoulder_02/settingsUI.ui +++ b/release/scripts/mgear/shifter_classic_components/shoulder_02/settingsUI.ui @@ -15,12 +15,32 @@ + + + + + + + + + + + Mirror Behaviour L and R + + + + + + + + + Reference Array - + From 37d2f1c45f89b9c1b3899e3c5bc6c813bc7090d0 Mon Sep 17 00:00:00 2001 From: Joji Date: Thu, 28 Dec 2023 00:55:29 -0800 Subject: [PATCH 3/6] Corrected the orientation direction issue. --- .../shoulder_01/__init__.py | 13 +++++++++---- .../shoulder_02/__init__.py | 13 +++++++++---- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/release/scripts/mgear/shifter_classic_components/shoulder_01/__init__.py b/release/scripts/mgear/shifter_classic_components/shoulder_01/__init__.py index aa4ab3ce..af8c26e8 100644 --- a/release/scripts/mgear/shifter_classic_components/shoulder_01/__init__.py +++ b/release/scripts/mgear/shifter_classic_components/shoulder_01/__init__.py @@ -51,8 +51,14 @@ def addObjects(self): tp=self.parentCtlTag) if self.settings["mirrorBehaviour"] and self.negate: - self.ctl_npo.ry.set(180) - self.ctl_npo.sz.set(-1) + t = transform.getTransformLookingAt(self.guide.apos[0], + self.guide.apos[1], + self.normal, + axis="-xy", + negate=self.negate) + t = transform.setMatrixPosition(t, [0, 0, 0]) + t = transform.setMatrixScale(t, [1, -1, 1]) + self.ctl_npo.setMatrix(t) t = transform.getTransformFromPos(self.guide.apos[1]) self.orbit_ref1 = primitive.addTransform( @@ -74,8 +80,7 @@ def addObjects(self): tp=self.ctl) if self.settings["mirrorBehaviour"] and self.negate: - self.orbit_cns.rotateBy((0, 180, 0), space="object") - self.orbit_cns.sy.set(-1) + self.orbit_cns.sx.set(-1) self.jnt_pos.append([self.ctl, "shoulder"]) diff --git a/release/scripts/mgear/shifter_classic_components/shoulder_02/__init__.py b/release/scripts/mgear/shifter_classic_components/shoulder_02/__init__.py index 832cb8a2..b9b42890 100644 --- a/release/scripts/mgear/shifter_classic_components/shoulder_02/__init__.py +++ b/release/scripts/mgear/shifter_classic_components/shoulder_02/__init__.py @@ -51,8 +51,14 @@ def addObjects(self): tp=self.parentCtlTag) if self.settings["mirrorBehaviour"] and self.negate: - self.ctl_npo.ry.set(180) - self.ctl_npo.sz.set(-1) + t = transform.getTransformLookingAt(self.guide.apos[0], + self.guide.apos[1], + self.normal, + axis="-xy", + negate=self.negate) + t = transform.setMatrixPosition(t, [0, 0, 0]) + t = transform.setMatrixScale(t, [1, -1, 1]) + self.ctl_npo.setMatrix(t) t = transform.getTransformFromPos(self.guide.apos[2]) self.orbit_ref1 = primitive.addTransform( @@ -74,8 +80,7 @@ def addObjects(self): tp=self.ctl) if self.settings["mirrorBehaviour"] and self.negate: - self.orbit_cns.rotateBy((0, 180, 0), space="object") - self.orbit_cns.sy.set(-1) + self.orbit_cns.sx.set(-1) self.jnt_pos.append([self.ctl, "shoulder"]) From 8a03fa39d787ae50a84ff3c7ff9526bbe650adcb Mon Sep 17 00:00:00 2001 From: Joji Date: Sun, 14 Jan 2024 13:46:51 -0800 Subject: [PATCH 4/6] The joint axis is not changed when using the mirror setting --- .../shoulder_01/__init__.py | 11 +++++++++-- .../shoulder_02/__init__.py | 11 +++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/release/scripts/mgear/shifter_classic_components/shoulder_01/__init__.py b/release/scripts/mgear/shifter_classic_components/shoulder_01/__init__.py index af8c26e8..78d9563d 100644 --- a/release/scripts/mgear/shifter_classic_components/shoulder_01/__init__.py +++ b/release/scripts/mgear/shifter_classic_components/shoulder_01/__init__.py @@ -50,6 +50,7 @@ def addObjects(self): po=datatypes.Vector(.5 * self.length0 * self.n_factor, 0, 0), tp=self.parentCtlTag) + rot_offset = (0, 0, 0) if self.settings["mirrorBehaviour"] and self.negate: t = transform.getTransformLookingAt(self.guide.apos[0], self.guide.apos[1], @@ -59,6 +60,7 @@ def addObjects(self): t = transform.setMatrixPosition(t, [0, 0, 0]) t = transform.setMatrixScale(t, [1, -1, 1]) self.ctl_npo.setMatrix(t) + rot_offset = (180, 180, 0) t = transform.getTransformFromPos(self.guide.apos[1]) self.orbit_ref1 = primitive.addTransform( @@ -82,8 +84,13 @@ def addObjects(self): if self.settings["mirrorBehaviour"] and self.negate: self.orbit_cns.sx.set(-1) - self.jnt_pos.append([self.ctl, "shoulder"]) - + self.jnt_pos.append( + { + "obj": self.ctl, + "name": "shoulder", + "rot_off": rot_offset, + } + ) # ===================================================== # ATTRIBUTES # ===================================================== diff --git a/release/scripts/mgear/shifter_classic_components/shoulder_02/__init__.py b/release/scripts/mgear/shifter_classic_components/shoulder_02/__init__.py index b9b42890..4bd9122d 100644 --- a/release/scripts/mgear/shifter_classic_components/shoulder_02/__init__.py +++ b/release/scripts/mgear/shifter_classic_components/shoulder_02/__init__.py @@ -50,6 +50,7 @@ def addObjects(self): po=datatypes.Vector(.5 * self.length0 * self.n_factor, 0, 0), tp=self.parentCtlTag) + rot_offset = (0, 0, 0) if self.settings["mirrorBehaviour"] and self.negate: t = transform.getTransformLookingAt(self.guide.apos[0], self.guide.apos[1], @@ -59,6 +60,7 @@ def addObjects(self): t = transform.setMatrixPosition(t, [0, 0, 0]) t = transform.setMatrixScale(t, [1, -1, 1]) self.ctl_npo.setMatrix(t) + rot_offset = (180, 180, 0) t = transform.getTransformFromPos(self.guide.apos[2]) self.orbit_ref1 = primitive.addTransform( @@ -82,8 +84,13 @@ def addObjects(self): if self.settings["mirrorBehaviour"] and self.negate: self.orbit_cns.sx.set(-1) - self.jnt_pos.append([self.ctl, "shoulder"]) - + self.jnt_pos.append( + { + "obj": self.ctl, + "name": "shoulder", + "rot_off": rot_offset, + } + ) # ===================================================== # ATTRIBUTES # ===================================================== From c2097e8be8fd9923776515cf7a98472d7a6bd46b Mon Sep 17 00:00:00 2001 From: Joji Date: Sun, 14 Jan 2024 13:48:32 -0800 Subject: [PATCH 5/6] Extracted the processing of each joint position (jpo) into separate methods This will make the code more readable and maintainable. --- .../mgear/shifter/component/__init__.py | 144 ++++++++---------- 1 file changed, 60 insertions(+), 84 deletions(-) diff --git a/release/scripts/mgear/shifter/component/__init__.py b/release/scripts/mgear/shifter/component/__init__.py index 9b374fe8..6a78989c 100644 --- a/release/scripts/mgear/shifter/component/__init__.py +++ b/release/scripts/mgear/shifter/component/__init__.py @@ -183,7 +183,9 @@ def step_04(self): """ Step 04. Joint structure creation. """ + self.retrieveParentJoint() self.jointStructure() + self.setJointRadius() return def step_05(self): @@ -1950,13 +1952,8 @@ def postConnect(self): # ===================================================== # JOINTS STRUCTURE # ===================================================== - def jointStructure(self): - """Build the Joint structure - - Handle the building of the joint structure, when we select jnt_org - option. - - """ + def retrieveParentJoint(self): + """Retrieve the parent joint based on settings.""" # get parent component joint if self.settings["useIndex"]: try: @@ -1991,12 +1988,8 @@ def jointStructure(self): except Exception: if oParent_comp.parent_comp: pgpc = oParent_comp.guide.parentComponent - parent_name = pgpc.getName( - oParent_comp.guide.parentLocalName - ) - relative_name = oParent_comp.rig.getRelativeName( - parent_name - ) + parent_name = pgpc.getName(oParent_comp.guide.parentLocalName) + relative_name = oParent_comp.rig.getRelativeName(parent_name) else: pm.displayInfo( "The parent components for: %s don't have joint " @@ -2006,99 +1999,82 @@ def jointStructure(self): oParent_comp = oParent_comp.parent_comp - # Joint creation - for jpo in self.jnt_pos: + def jointStructure(self): + """Build the Joint structure + + Handle the building of the joint structure, when we select jnt_org + option. - # NOTE: using a list was a mitake. Adding support for a kwargs dict + """ + # Create joints based on joint positions. + for jpo in self.jnt_pos: if isinstance(jpo, list): - if len(jpo) >= 3 and self.options["joint_rig"]: - if jpo[2] == "component_jnt_org": - newActiveJnt = self.component_jnt_org - elif jpo[2] == "parent_relative_jnt": - # this option force the active jnt always to the parent - # relative jnt. - # If None the active jnt will be updated to the latest in - # each jnt creation - newActiveJnt = self.parent_relative_jnt - else: - try: - # here jpo[2] is also the string name of the jnt inside - # the component. IE: "root" - newActiveJnt = self.jointList[ - self.jointRelatives[jpo[2]] - ] - - except Exception: - if jpo[2]: - pm.displayWarning( - "Joint Structure creation: " - "The object %s can't be found. Joint parent is" - " NONE for %s, from %s" - % (jpo[2], jpo[0], self.fullName) - ) - newActiveJnt = None - else: - newActiveJnt = None + # Process joint position when provided as a list + newActiveJnt = self.determineActiveJoint(jpo, index=2) # Handle the uniform scale if len(jpo) >= 4 and self.options["joint_rig"]: uniScale = jpo[3] else: uniScale = False - # TODO: handle rotation offset and vanilla nodes connection - # handle the matrix node connection - # Defaults to use Maya multiply Matrix node if len(jpo) >= 5 and self.options["joint_rig"]: gearMulMatrix = jpo[4] else: gearMulMatrix = False + # Handle rotation offset + rotOffset = jpo[5] if len(jpo) >= 6 else (0, 0, 0) + self.jointList.append( self.addJoint( - jpo[0], - jpo[1], - newActiveJnt, - uniScale, + obj=jpo[0], + name=jpo[1], + newActiveJnt=newActiveJnt, + UniScale=uniScale, gearMulMatrix=gearMulMatrix, - ) + rot_off=rotOffset) ) - elif isinstance(jpo, dict): - if "newActiveJnt" in jpo.keys(): - if jpo["newActiveJnt"] == "component_jnt_org": - jpo["newActiveJnt"] = self.component_jnt_org - elif jpo["newActiveJnt"] == "parent_relative_jnt": - # this option force the active jnt always to the parent - # relative jnt. - # If None the active jnt will be updated to the latest in - # each jnt creation - jpo["newActiveJnt"] = self.parent_relative_jnt - else: - try: - # here jpo["newActiveJnt"] is also the string name - # of the jnt inside the component. IE: "root" - jpo["newActiveJnt"] = self.jointList[ - self.jointRelatives[jpo["newActiveJnt"]] - ] - - except Exception: - if jpo["newActiveJnt"]: - pm.displayWarning( - "Joint Structure creation: " - "The object %s can't be found. Joint parent is" - " NONE for %s, from %s" - % ( - jpo["newActiveJnt"], - jpo["obj"], - self.fullName, - ) - ) - jpo["newActiveJnt"] = None + elif isinstance(jpo, dict): + # Process joint position when provided as a dictionary + if "newActiveJnt" in jpo: + jpo["newActiveJnt"] = self.determineActiveJoint(jpo, key="newActiveJnt") self.jointList.append(self.addJoint(**jpo)) + def determineActiveJoint(self, jpo, index=None, key=None): + """Determine the active joint based on the joint position info.""" + + # Check if jpo is a list and index is within range + if isinstance(jpo, list) and index is not None and index < len(jpo): + joint_identifier = jpo[index] + # Check if jpo is a dictionary and key exists + elif isinstance(jpo, dict) and key is not None and key in jpo: + joint_identifier = jpo.get(key) + else: + # Handle cases where jpo does not have the expected index or key + return None + + if joint_identifier == "component_jnt_org": + return self.component_jnt_org + elif joint_identifier == "parent_relative_jnt": + return self.parent_relative_jnt + else: + try: + return self.jointList[self.jointRelatives[joint_identifier]] + except Exception: + obj = jpo[0] if isinstance(jpo, list) else jpo["obj"] + if joint_identifier: + pm.displayWarning( + "Joint Structure creation: The object %s can't be found. " + "Joint parent is NONE for %s, from %s" % (joint_identifier, obj, self.fullName) + ) + return None + + def setJointRadius(self): + """Set the radius for all joints.""" + radiusValue = self.rig.guide.model.joint_radius.get() for jnt in self.jointList: - radiusValue = self.rig.guide.model.joint_radius.get() jnt.radius.set(radiusValue) # ===================================================== From 0df1fa82b8f3be9395c966e6cdf9926800510e0e Mon Sep 17 00:00:00 2001 From: Joji Date: Sun, 14 Jan 2024 13:55:45 -0800 Subject: [PATCH 6/6] Revert "Extracted the processing of each joint position (jpo) into separate methods" This reverts commit c2097e8be8fd9923776515cf7a98472d7a6bd46b. --- .../mgear/shifter/component/__init__.py | 144 ++++++++++-------- 1 file changed, 84 insertions(+), 60 deletions(-) diff --git a/release/scripts/mgear/shifter/component/__init__.py b/release/scripts/mgear/shifter/component/__init__.py index 6a78989c..9b374fe8 100644 --- a/release/scripts/mgear/shifter/component/__init__.py +++ b/release/scripts/mgear/shifter/component/__init__.py @@ -183,9 +183,7 @@ def step_04(self): """ Step 04. Joint structure creation. """ - self.retrieveParentJoint() self.jointStructure() - self.setJointRadius() return def step_05(self): @@ -1952,8 +1950,13 @@ def postConnect(self): # ===================================================== # JOINTS STRUCTURE # ===================================================== - def retrieveParentJoint(self): - """Retrieve the parent joint based on settings.""" + def jointStructure(self): + """Build the Joint structure + + Handle the building of the joint structure, when we select jnt_org + option. + + """ # get parent component joint if self.settings["useIndex"]: try: @@ -1988,8 +1991,12 @@ def retrieveParentJoint(self): except Exception: if oParent_comp.parent_comp: pgpc = oParent_comp.guide.parentComponent - parent_name = pgpc.getName(oParent_comp.guide.parentLocalName) - relative_name = oParent_comp.rig.getRelativeName(parent_name) + parent_name = pgpc.getName( + oParent_comp.guide.parentLocalName + ) + relative_name = oParent_comp.rig.getRelativeName( + parent_name + ) else: pm.displayInfo( "The parent components for: %s don't have joint " @@ -1999,82 +2006,99 @@ def retrieveParentJoint(self): oParent_comp = oParent_comp.parent_comp - def jointStructure(self): - """Build the Joint structure - - Handle the building of the joint structure, when we select jnt_org - option. - - """ - # Create joints based on joint positions. + # Joint creation for jpo in self.jnt_pos: + + # NOTE: using a list was a mitake. Adding support for a kwargs dict if isinstance(jpo, list): - # Process joint position when provided as a list - newActiveJnt = self.determineActiveJoint(jpo, index=2) + if len(jpo) >= 3 and self.options["joint_rig"]: + if jpo[2] == "component_jnt_org": + newActiveJnt = self.component_jnt_org + elif jpo[2] == "parent_relative_jnt": + # this option force the active jnt always to the parent + # relative jnt. + # If None the active jnt will be updated to the latest in + # each jnt creation + newActiveJnt = self.parent_relative_jnt + else: + try: + # here jpo[2] is also the string name of the jnt inside + # the component. IE: "root" + newActiveJnt = self.jointList[ + self.jointRelatives[jpo[2]] + ] + + except Exception: + if jpo[2]: + pm.displayWarning( + "Joint Structure creation: " + "The object %s can't be found. Joint parent is" + " NONE for %s, from %s" + % (jpo[2], jpo[0], self.fullName) + ) + newActiveJnt = None + else: + newActiveJnt = None # Handle the uniform scale if len(jpo) >= 4 and self.options["joint_rig"]: uniScale = jpo[3] else: uniScale = False + # TODO: handle rotation offset and vanilla nodes connection + # handle the matrix node connection + # Defaults to use Maya multiply Matrix node if len(jpo) >= 5 and self.options["joint_rig"]: gearMulMatrix = jpo[4] else: gearMulMatrix = False - # Handle rotation offset - rotOffset = jpo[5] if len(jpo) >= 6 else (0, 0, 0) - self.jointList.append( self.addJoint( - obj=jpo[0], - name=jpo[1], - newActiveJnt=newActiveJnt, - UniScale=uniScale, + jpo[0], + jpo[1], + newActiveJnt, + uniScale, gearMulMatrix=gearMulMatrix, - rot_off=rotOffset) + ) ) - elif isinstance(jpo, dict): - # Process joint position when provided as a dictionary - if "newActiveJnt" in jpo: - jpo["newActiveJnt"] = self.determineActiveJoint(jpo, key="newActiveJnt") - self.jointList.append(self.addJoint(**jpo)) - - def determineActiveJoint(self, jpo, index=None, key=None): - """Determine the active joint based on the joint position info.""" - - # Check if jpo is a list and index is within range - if isinstance(jpo, list) and index is not None and index < len(jpo): - joint_identifier = jpo[index] - # Check if jpo is a dictionary and key exists - elif isinstance(jpo, dict) and key is not None and key in jpo: - joint_identifier = jpo.get(key) - else: - # Handle cases where jpo does not have the expected index or key - return None + if "newActiveJnt" in jpo.keys(): + if jpo["newActiveJnt"] == "component_jnt_org": + jpo["newActiveJnt"] = self.component_jnt_org + elif jpo["newActiveJnt"] == "parent_relative_jnt": + # this option force the active jnt always to the parent + # relative jnt. + # If None the active jnt will be updated to the latest in + # each jnt creation + jpo["newActiveJnt"] = self.parent_relative_jnt + else: + try: + # here jpo["newActiveJnt"] is also the string name + # of the jnt inside the component. IE: "root" + jpo["newActiveJnt"] = self.jointList[ + self.jointRelatives[jpo["newActiveJnt"]] + ] + + except Exception: + if jpo["newActiveJnt"]: + pm.displayWarning( + "Joint Structure creation: " + "The object %s can't be found. Joint parent is" + " NONE for %s, from %s" + % ( + jpo["newActiveJnt"], + jpo["obj"], + self.fullName, + ) + ) + jpo["newActiveJnt"] = None - if joint_identifier == "component_jnt_org": - return self.component_jnt_org - elif joint_identifier == "parent_relative_jnt": - return self.parent_relative_jnt - else: - try: - return self.jointList[self.jointRelatives[joint_identifier]] - except Exception: - obj = jpo[0] if isinstance(jpo, list) else jpo["obj"] - if joint_identifier: - pm.displayWarning( - "Joint Structure creation: The object %s can't be found. " - "Joint parent is NONE for %s, from %s" % (joint_identifier, obj, self.fullName) - ) - return None + self.jointList.append(self.addJoint(**jpo)) - def setJointRadius(self): - """Set the radius for all joints.""" - radiusValue = self.rig.guide.model.joint_radius.get() for jnt in self.jointList: + radiusValue = self.rig.guide.model.joint_radius.get() jnt.radius.set(radiusValue) # =====================================================