Last active
August 29, 2015 13:57
-
-
Save luizmoreiratd/9717297 to your computer and use it in GitHub Desktop.
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
#---------------------------------- | |
# Create Dynamic Joint Chains | |
#---------------------------------- | |
dynChain = lpDynamiChain(startJoint, endJoint) | |
dynChain.create() | |
def __init__(self, startJoint="", endJoint="", node=""): | |
""" Constructor. Creates the custom node. | |
Params: | |
[in] startJoint - Name of the first joint in the chain | |
[in] endJoint - Name of the last joint in the chain | |
[in] node - Name of the node to manage by the class | |
Returns: | |
Nothing. """ | |
def create(self): | |
""" Creates the actual dynamic joint chain node network. | |
Params: | |
Nothing. | |
Returns: | |
List of all new created nodes. """ | |
#---------------------------------- | |
# Remove Dynamic Nodes | |
#---------------------------------- | |
dynChain = lpDynamicChain(node=node) | |
dynChain.delete() | |
del(dynChain) | |
#---------------------------------- | |
# Iterate Through All Dynamic Chain Nodes | |
#---------------------------------- | |
# create instance | |
dynChain = lpDynamicChain() | |
# create iterable for all dynamic nodes in the scene | |
dynChains = dynChain.Iter() | |
for d in dynChains: | |
print d | |
#---------------------------------- | |
# Get and Set the Active Nucleus | |
#---------------------------------- | |
nucleus = getActiveNucleus() | |
setActiveNucleus(nucleus) | |
def getActiveNucleus(): | |
""" Queries the active nucleus node | |
Params: | |
Nothing. | |
Returns: | |
Name of active nucleus node. """ | |
def setActiveNucleus(nucleus): | |
""" Sets the active nucleus node. | |
Params: | |
[in] nucleus - Name of nucleus node to set as current active nucleus | |
Returns: | |
Nothing. """ | |
#---------------------------------- | |
# Get Connected | |
#---------------------------------- | |
# get selected object | |
obj = cmds.ls(sl=True)[0] | |
dNode = getConnectedDynamicChain(obj) | |
nucleus = getConnectedNucleusNode(dNode) | |
def getConnectedDynamicChain(node): | |
""" Looks for a valid DynamicChain node connected to the given node. | |
Params: | |
[in] node - Name of the node to find connection to DynamicChain | |
Returns: | |
Name of DynamicChain node connected to given node. """ | |
def getConnectedNucleusNode(node): | |
""" Looks for the nucleus node connected to the given node. | |
Params: | |
[in] node - Name of the node to find connection to nucleus | |
Returns: | |
Name of the nucleus node connected to the given node. """ | |
#---------------------------------- | |
# Checks | |
#---------------------------------- | |
# get selected object | |
obj = cmds.ls(sl=True)[0] | |
if isDynamicChain(obj): | |
dynChain = lpDynamicChain(obj) | |
# access attribute | |
hairShape = dynChain.hairSystemShape[0] | |
return isNType(hairShape, "hairSystem") | |
def isDynamicChain(node): | |
""" Looks for the identifier to check if node is 'dynamic'. | |
Parames: | |
[in] node - Name of node to check for 'nodeType' | |
Returns: | |
Boolean value if node is dynamic or not, True or False. """ | |
def isNType(node, nodeType): | |
""" Checks if the given node is a nucleus compatible nDynamics node. | |
Params: | |
[in] node - Name of node to check for 'NType' compatibility | |
[in] nodeType - Node type to check | |
Returns: | |
Boolean value if node is compatible with nDynamics solver. """ | |
#---------------------------------- | |
# Number of Colliders | |
#---------------------------------- | |
# get selected object | |
obj = cmds.ls(sl=True)[0] | |
if isDynamicChain(obj): | |
numColliders = findNumberOfCollisionObjects(obj) | |
def findNumberOfCollisionObjects(node): | |
""" Finds the number of collision objects attached to the node. | |
Params: | |
[in] node - Name of the node t o check for collision objects | |
Returns: | |
Integer number of collision objects attached to the node. """ | |
#---------------------------------- | |
# Delete Unused Nucleus Nodes | |
#---------------------------------- | |
deletedNodes = deleteUnusedNucleusSolvers() | |
def deleteUnusedNucleusSolvers(): | |
""" Deletes all nucleus nodes not being used. | |
Params: | |
Nothing. | |
Returns: | |
List of nucleus node deleted. """ | |
#---------------------------------- | |
# Create and Connect | |
#---------------------------------- | |
# get selected objects | |
selected = cmds.ls(sl=True)[0] | |
dNode = selected[0] | |
mesh = selected[1] | |
nucleus = createNucleus() | |
if isDynamicChain(dNode): | |
nucleus = connectToNucleus(dNode, nucleus) | |
nRigid = createNRigid(mesh, nucleus) | |
index = connectNRigidToNucleus(nRigid, nucleus) | |
def createNucleus(name="", setActive=True): | |
""" Creates nucleus node. | |
Params: | |
[in] name - Name for the new nucleus node | |
[in] setActive - Boolean to set the new nucleus as the current active nucleus | |
Returns: | |
Name of new nucleus node. """ | |
def createNRigid(obj, nucleus=""): | |
""" Create a nRigig node from the given obj. | |
Params: | |
[in] obj - Name of the geo to create nRigid from | |
[in] nucleus - Name of the nucleus to connect nRigid to | |
Returns: | |
Name of new nRigid node. """ | |
def connectToNucleus(node, nucleus): | |
""" Connect the given node to the nucleus node. | |
Params: | |
[in] node - Name of the node to connect to the nucleus solver | |
[in] nucleus - Name of nucleus solver to connect to | |
Returns: | |
Name of nucleus node (debug). """ | |
def connectNRigidToNucleus(nRigid, nucleus, newNucleus=True): | |
""" Connect the given nRigid node to the nucleus node, maintaining prior connections to | |
other nucleus nodes. | |
Params: | |
[in] nRigid - Name of nRigid node to connect to nucleus | |
[in] nucleus - Name of nucleus node to connect | |
[in] newNucleus - Boolean to create a new nucleus node if the specified nucleus doesn't exist | |
Returns: | |
Integer index of next available passive nRigid for the given nucleus. """ | |
#---------------------------------- | |
# Access Connections | |
#---------------------------------- | |
# get selected object | |
obj = cmds.ls(sl=True) | |
if isDynamicChain(obj): | |
dNode = lpDynamicChain(node=obj) | |
nodes = dNode.listConnections() | |
# get hairSystemShape node | |
hairShape = dNode.hairSystemShape[0] | |
def listConnections(self): | |
""" | |
Wrapper to get all connections to the node to message attributes. | |
Params: | |
Nothing. | |
Returns: | |
List of connected nodes to all custom message attributes. """ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment