Skip to content

Commit

Permalink
Shifter: Adding support for bindPlanes Closes #400
Browse files Browse the repository at this point in the history
  • Loading branch information
miquelcampos committed Mar 28, 2024
1 parent d4f7d64 commit 54d4367
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 1 deletion.
10 changes: 9 additions & 1 deletion release/scripts/mgear/core/applyop.py
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,9 @@ def gear_inverseRotorder_op(out_obj, in_obj):
return node


def create_proximity_constraint(shape, in_trans, existing_pin=None, mtx_connect=True, out_trans=None):
def create_proximity_constraint(
shape, in_trans, existing_pin=None, mtx_connect=True, out_trans=None
):
"""Create a proximity constraint between a shape and a transform.
Args:
Expand Down Expand Up @@ -865,6 +867,12 @@ def find_next_available_index(node, attribute):
shape_orig.worldMesh[0] >> shape.inMesh
else:
shape_orig = shape_orig_connections[0]
# in some situation we get the transform instead of the shape.
# In that case we try to get the shape
try:
shape_orig = shape_orig.getShape()
except AttributeError:
pass
if not isinstance(shape_orig, pm.nt.Mesh):
shape_orig = shape_orig.originalGeometry[0].listConnections(
d=True, sh=True
Expand Down
35 changes: 35 additions & 0 deletions release/scripts/mgear/core/node_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import pymel.core as pm


def find_connected_proximity_pin_node(source_object):
"""
Check if the worldMesh[0] output of an object is connected to the
deformedGeometry of a proximityPin node. Return the proximityPin node as
a PyNode if found.
Args:
source_object (pyNode or str): Name of the source object.
Returns:
pymel.core.general.PyNode: The connected proximityPin node as a PyNode
if a connection exists, otherwise None.
"""
# Get the source worldMesh[0] plug as PyNode
if isinstance(source_object, str):
source_object = pm.PyNode(source_object)
source_plug = source_object.worldMesh[0]

# Find all destination connections from this plug
connections = source_plug.connections(d=True, s=False, p=True)

# Check each connection to see if it is to a proximityPin node
for connection in connections:
# The node connected to
node = connection.node()
# Check if this node is of the type 'proximityPin'
if node.type() == "proximityPin":
# Check if the connected attribute is deformedGeometry
if "deformedGeometry" in connection.name():
return node

return None
3 changes: 3 additions & 0 deletions release/scripts/mgear/shifter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ def __init__(self):
self.groups = {}
self.subGroups = {}

self.bindPlanes = {}
self.combinedBindPlanes = {}

self.components = {}
self.componentsIndex = []

Expand Down
32 changes: 32 additions & 0 deletions release/scripts/mgear/shifter/component/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ def __init__(self, rig, guide):
self.settings = self.guide.values
self.setupWS = self.rig.setupWS

self.WIP = self.options["mode"]

self.name = self.settings["comp_name"]
self.side = self.settings["comp_side"]
self.index = self.settings["comp_index"]
Expand Down Expand Up @@ -122,6 +124,9 @@ def __init__(self, rig, guide):
self.jnt_pos = []
self.jointList = []

self.bindPlanes = self.rig.bindPlanes
self.combinedBindPlanes = self.rig.combinedBindPlanes

self.transform2Lock = []

# Data collector
Expand Down Expand Up @@ -157,6 +162,7 @@ def step_01(self):
Get the properties host, create parameters and set layout and logic.
"""
self.getHost()
self.config_bind_planes()
self.validateProxyChannels()
self.addFullNameParam()
self.addAttributes()
Expand Down Expand Up @@ -259,6 +265,32 @@ def addObjects(self):
"""
return

def config_bind_planes(self):
"""This method combine the bind planes."""

# we process the combine bind planes with the first component
if not self.combinedBindPlanes:
for k in self.bindPlanes.keys():
if len(k) >= 2:
combined_mesh = pm.polyUnite(
self.bindPlanes[k],
ch=False,
mergeUVSets=True,
name="{}_bindPlane".format(k),
)
if (
isinstance(combined_mesh, list)
and len(combined_mesh) >= 1
):
combined_mesh = combined_mesh[0]

else:
combined_mesh = self.bindPlanes[k][0]
if not self.WIP:
combined_mesh.visibility.set(False)
pm.parent(combined_mesh, self.setupWS)
self.combinedBindPlanes[k] = combined_mesh

def addJoint(
self,
obj=None,
Expand Down

0 comments on commit 54d4367

Please sign in to comment.