NCloth¶
Nclothconstants¶
Nclothskinned¶
Sets Up A Hybrid Skinned NCloth Setup based off a skinned mesh, usually clothing like a shirt.
Select the skinned mesh
Run the script
All nCloth Nodes and settings will be applied. clothBlenderMesh is created so that the wrinkles can be blendshape paint removed The script assumes regular proportioned human size character in Maya cms
To Do - if mesh is not skinned make sure the warning shows! - remove warnings on names with namespaces - add a central control with common attributes in one place - support presets - add a UI - support using the same nucleus and central control - Add Scale Factor - Change Prefs for play every frame - Auto Cache Timeline Option - add world space support for nCloth function, currently local - add dictionaries as nodes returned are too many
- addClothThickness(obj, thickness=1.0, weight=0.5, select=True)¶
Extrudes a flat object to be thick so that the extrude affects both sides, making it thicker on both sides. Or as per the weight value. 0.5 is centered, 1 extrudes down, zero extrudes up.
This function is not used see the module zoo.libs.maya.cmds.modeling.extrude
- Parameters:
obj (list(str)) – The name of the object or face list to extrude
thickness (float) – The thickness of the object in Maya units usually cms
weight (float) – Controls the direction of the extrude, 0.5 is center and the extrude will go out each side
select (bool) – Select the original selection after the extrude completes?
- Return extrudeNode:
The name of the extrudeNode that was created
- Rtype extrudeNode:
str
- Return moveVertNode:
The name of the extrudeNode that was created
- Rtype moveVertNode:
str
- createNClothNodes(mesh, nClothTransform='nCloth', nucleusNode='nucleus', timeNode='time1', namespace='', spaceLocal=True, startFrame=1, scale=1.0)¶
Creates a nCloth standard setup as it’s not supported in maya cmds
Currently local space setup, but shouldn’t be hard to change to world as it’s just a matter of different connections Could be issues with multiple setups using the same node, but usually a ncloth works on one mesh at a time I believe Should later support specifying the Nucleus node, will always create a new one currently
Supports Namespaces and duplicated names Returns all objects and nodes
- Parameters:
mesh (str) – The mesh to attach the nCLoth setup to
nClothTransform (str) – the name of the nCloth (the transform node not the shade node) Shape is added for the shape
nucleusNode (str) – Name of the Nucleus node to be created, if already exists will add numbers
timeNode (str) – name of the time1 node, in Maya this is always in the scene and is always called time1
namespace (str (no : should be in the name)) – Does the mesh have a namespace in the name? if so it must be specified to be added to the new nodes
spaceLocal (bool) – Not currently supported. nCloth setups can also be in world, will need to add this option later
startTime (int) – simulations start from this frame
scale (float) – the spaceScale attribute on the nuleus node, affects total scale of the sims
- Return allNodesSet:
all the nodes in a set
- Return type:
- nucleusDefaults(nucleusNode, presetDict={'gravity': 0.0, 'maxCollisionIterations': 4.0, 'spaceScale': 0.01, 'startFrame': 1.0, 'subSteps': 10.0})¶
Set nucleus node defaults, see NUCLEUS_DEFAULT_PRESET dictionary
- Parameters:
presetDict (str) – The nucleus preset dictionary of attributes and values
- nClothDefaults(nClothShape, presetDict={'bendAngleDropoff': 0.4, 'bendResistance': 0.4, 'compressionResistance': 10.0, 'damp': 0.8, 'inputMeshAttract': 1.0, 'lift': 0.0001, 'localSpaceOutput': 1.0, 'pointMass': 0.6, 'pushOutRadius': 10.0, 'scalingRelation': 1.0, 'selfCollideWidthScale': 1, 'shearResistance': 0.0, 'stretchResistance': 35.0, 'tangentialDrag': 0.1, 'thickness': 0.005})¶
Adjust nCloth defaults to a Tshirt like setup with some tweaks
- nClothSkinned(mesh, divisionsPolySmooth=2, nucleusNode='nucleus', nClothTransform='nCloth', deleteDeadShapes=False, startFrame=1, scale=1.0, blendMultiply=1.0, presetDict={'bendAngleDropoff': 0.4, 'bendResistance': 0.4, 'compressionResistance': 10.0, 'damp': 0.8, 'inputMeshAttract': 1.0, 'lift': 0.0001, 'localSpaceOutput': 1.0, 'pointMass': 0.6, 'pushOutRadius': 10.0, 'scalingRelation': 1.0, 'selfCollideWidthScale': 1, 'shearResistance': 0.0, 'stretchResistance': 35.0, 'tangentialDrag': 0.1, 'thickness': 0.005}, nucleusAttrs={'gravity': 0.0, 'maxCollisionIterations': 4.0, 'spaceScale': 0.01, 'startFrame': 1.0, 'subSteps': 10.0}, createNetworkNode=True, presetIndex=0, message=True)¶
Sets up a skinned hybrid nCloth setup with blendshapes for painting out and adjusting intensity:
the nCloth setup is local, not world sticks to a skinned/deformed mesh, designed for wrinkle generation.
Mesh should be skinned or deformed, only works with animation.
Will create 4 meshes
original (mesh) is left untouched it’s shape info is are fed into the other objects.
cloth object (has the cloth sim on it).
polySmooth mesh, is a duplicate of the original mesh with a polySmooth and no sim.
blender mesh, is a new mesh with a blendshape to the cloth object so the user can weight in the nCloth.
All nCloth nodes are created as per normal.
nCloth defaults have no gravity and rough Maya t-shirt settings for defaults, or can be passed in Setup supports auto namespaces and duplicated names.
- Parameters:
mesh (str) – the mesh name to apply the cloth sim onto (transform node)
divisionsPolySmooth (int) – how many divisions should the cloth mesh have for polygon density?
nucleusNode (str) – the name of the nucleus node to be created
nClothTransform (str) – the name of the nCloth node to be created (the transform node)
startFrame (int) – The frame to start the sim from
scale (float) – The scale of the ncloth wrinkles
blendMultiply (float) – Multiply the wrinkles by this amount, will affect a blendshape attribute
presetDict (dict) – Preset Dictionary with ncloth attrs and values. See zoo.libs.maya.cmds.ncloth.nclothconstants
presetIndex (int) – This is for GUI tracking, if a preset combo then track the index on the network node
createNetworkNode (bool) – Create the network node for tracking and deletion
- Returns:
The name of the network node created, Dictionary of all nodes, uses keys from zoo.libs.maya.cmds.ncloth.nclothconstants
- Return type:
- nClothSkinnedSelected(divisionsPolySmooth=2, deleteDeadShapes=True, startFrame=1, scale=1.0, blendMultiply=1.0, presetDict={'bendAngleDropoff': 0.4, 'bendResistance': 0.4, 'compressionResistance': 10.0, 'damp': 0.8, 'inputMeshAttract': 1.0, 'lift': 0.0001, 'localSpaceOutput': 1.0, 'pointMass': 0.6, 'pushOutRadius': 10.0, 'scalingRelation': 1.0, 'selfCollideWidthScale': 1, 'shearResistance': 0.0, 'stretchResistance': 35.0, 'tangentialDrag': 0.1, 'thickness': 0.005}, nucleusAttrs={'gravity': 0.0, 'maxCollisionIterations': 4.0, 'spaceScale': 0.01, 'startFrame': 1.0, 'subSteps': 10.0}, presetIndex=0, message=True)¶
Sets up a skinned hybrid nCloth setup with blendshapes for painting out and adjusting intensity Will work off the first selected object which should be nCloth compatible, usually a mesh (transform node)
See function docstring nClothSkinned() for documentation
- skinnedNClothMessageNodeSetup(skinnedNClothNodes, divisionsPolySmooth, presetIndex=0)¶
Connects skinned NCloth nodes to a network node named “zooSkNClothNetwork_*” (ZOO_SK_NCLOTH_NETWORK)
The network node can be handy later, for deleting or managing objects, manage attrs etc
- Parameters:
skinnedNClothNodes (dict) – Dictionary of all nodes, uses keys from zoo.libs.maya.cmds.ncloth.nclothconstants
- Return networkNodeName:
The name of the network node created
- Rtype networkNodeName:
str
- getNClothNetworkObjs(nodeList)¶
Returns a network node from an object list, will return “” if none.
- Parameters:
nodeList (list(str)) – A list of Maya node names, for example the selection
- Return networkNode:
A skinned NCloth network node name, “” if none.
- Rtype networkNode:
str
- getSkinnedNClothDictNetwork(networkNode)¶
Returns a dictionary of connected nodes to the network node, uses SK_NCLOTH_NODE_DICT to categorize the objects
If an expected object does not exist it will not be in the dictionary at all
- Parameters:
networkNode (str) – A skinned NCloth network node name
- Return skinnedNClothNodes:
A dictionary of nodes as values with SK_NCLOTH_NODE_DICT as keys
- Rtype skinnedNClothNodes:
dict()
- getSkinnedNClothDictNode(node)¶
From a node, see if it is connected to a skin nCloth network, if so return:
skinnedNClothNodes: dict (all nodes related to the setup in a nice dict)
networkNode: The network node name that connects to all objects
Will return dict() and “” if no node found
- Parameters:
node (str) – Any maya node that may be a part of a skin nCloth network
- Return skinnedNClothNodes:
skinnedNClothNodes dict (all nodes related to the setup in a nice dict)
- Rtype skinnedNClothNodes:
dict
- Return networkNode:
The network node name that connects to all objects
- Rtype networkNode:
str
- getNetworkNodesAll()¶
Gets all skinned nCloth nodes in the scene and returns them as a list
- Return networkNodes:
a list of displacement network nodes in the scene
- Rtype networkNodes:
list(str)
- getSkinnedNClothDictSelected()¶
From the selection returns:
skinnedDictList list(dict) A list of dicts with nodes related to each setup in a nice dict
networkNodeList list(str) A list of network node names
- Return skinnedDictList:
A list of dicts with nodes related to each setup in a nice dict
- Rtype skinnedDictList:
list(dict)
- Return networkNodeList:
A list of network node names
- Rtype networkNodeList:
list(str)
- validateNClothNetwork(skinnedNClothNodes)¶
Returns whether a network is valid from it’s skinnedNClothNodes dict
If any keys of SK_NCLOTH_NODE_DICT are not found in skinnedNClothNodes, then objects are missing and invalid
- Parameters:
skinnedNClothNodes (dict()) – skinnedNClothNodes dict (all nodes related to the setup in a nice dict)
- Return isValid:
True if valid, False if objects are missing
- Rtype isValid:
bool
- validateNClothNetworkNodes(objList)¶
From a list of Maya objects Returns whether the skinned nCloth network is valid and the network node name
- Parameters:
objList (list(str)) – A list of Maya object names
- Return isValid:
True if valid, False if objects are missing
- Rtype isValid:
bool
- Return networkNode:
The network node name that connects to all objects
- Rtype networkNode:
str
- deleteSkinnedNClothNodes(skinnedDictList)¶
Deletes objects from a Skinned NCloth setup from a dictionary of each object.
Iterates over the keys and deletes each object while skipping the ORIGINAL_MESH_TFRM
- Parameters:
skinnedDictList (dict()) – skinnedNClothNodes dict (all nodes related to the setup in a nice dict)
- bakeSkinnedNClothNodes(skinnedDictList)¶
Bakes the current Skinned NCloth blender mesh in it’s current position and removes all other nodes.
Iterates over the keys and deletes each object while skipping the BLENDER_MESH_TFRM
- Parameters:
skinnedDictList (dict()) – skinnedNClothNodes dict (all nodes related to the setup in a nice dict)
- deleteSkinnedNClothSetupNetwork(networkNode, selectOrigMesh=True, bakeCurrent=False, message=True)¶
Deletes or bakes a Skinned NCloth Setup from the network node name.
Bake will leave the nCloth blender mesh in it’s current state.
- setThickExtrude(networkNode, thickness, weight)¶
- Sets the thick extrude and weight values onthe thick extrude setup
Creates the attributes if they don’t exist
- setAttrNetwork(networkNode, nodeKey, attribute, value)¶
Generic function that sets an attribute and checks if it exists
Needs a node key (dictionary key) to specify the node to set the attribute on.
A list of keys can be found in the dictionary ZOO_SK_NCLOTH_NETWORK
- Parameters:
- Return success:
The attribute was set successfully
- Rtype success:
bool
- nClothSetAttrNetwork(networkNode, attribute, value)¶
Sets an attribute on the nCloth node
- nucleusSetAttrNetwork(networkNode, attribute, value)¶
Sets an attribute on the nucleus node
- blendshapeSetAttrNetwork(networkNode, attribute, value)¶
Sets an attribute on the blendshape node
- enableDisableNucleus(selObjs, value)¶
Finds the related nucleus node and enables or disables it, used while caching which requires selection.
- setPresetIndexNetwork(networkNode, value)¶
Sets the preset index value on the network node, usually after the combo box has changed
- checkThicknessAttrs(networkNode)¶
- getThickExtrudeUpdate(networkNode)¶
Gets the extrude thickness and weight from the setup. If the attributes don’t exist will create them
- Parameters:
networkNode (str) – The network node name that connects to all ncloth objects
- Return thickExtrude:
The extrude thickness value
- Rtype thickExtrude:
float
- Return weight:
The extrude weight value
- Rtype weight:
float
- getAttrDictNetworkAll(networkNode)¶
Gets all attribute values of the nodes:
nCloth: see dict keys SKINNED_NCLOTH_ATTRS nucleus: see dict keys NUCLEUS_NCLOTH_ATTRS blendshape: see dict keys BLEND_NCLOTH_ATTRS
Only keys in the dicts are recorded.
Also returns the networks subD division count for GUI display
- Parameters:
networkNode (str) – The network node name that connects to all ncloth objects
- Return nclothSkinAttrValueDict:
nCloth dictionary of attributes as keys and values
- Rtype nclothSkinAttrValueDict:
dict()
- Return nucleusAttrValueDict:
nucleus dictionary of attributes as keys and values
- Rtype nucleusAttrValueDict:
dict()
- Return blendshapeAttrValueDict:
blendshape dictionary of attributes as keys and values
- Rtype blendshapeAttrValueDict:
dict()
- Return subDDivisions:
Number of subdivisions of the Skinned NCloth setup
- Rtype subDDivisions:
int
- getNucleusEnabledState(networkNode)¶
Returns the state of the Nucleus attribute “enable” 1 or 0 on or off.
- Parameters:
networkNode (str) – The network node name that connects to all ncloth objects
- Return enabledState:
1 is enabled or 0 is off
- Rtype enabledState:
bool
- selectClothMeshes(networkNode)¶
Selects the nCloth mesh which is necessary for cache operations, returns the transform and shape nodes
- Parameters:
networkNode (str) – The network node name that connects to all ncloth objects
- Return clothMesh:
nCloth transform node name, will be “” if empty
- Rtype clothMesh:
str
- Return clothShape:
nCloth shape node name, will be “” if empty
- Rtype clothShape:
str
- createCache(networkNode, delCacheFirst=True)¶
Hardcoded mel for the menu item:
Cache > Create New Cache
Defaults with “One file” set to be True
cmds.cacheFile() is the python but would be annoying to use as it doesn’t reconnect the nodes to the current mesh.
- Parameters:
delCacheFirst (bool) – Will try to delete existing caches before creating new.
- deleteCache(networkNode, reportNoCache=True, checkClothMeshes=True)¶
Hardcoded mel for the menu item:
Cache > Delete Cache
Delete Files = True
- Parameters:
reportNoCache (bool) – Reports a message if no cache’s found
- sortSwitchFromCache(node)¶
Check to see if node is a cacheFile node or if it’s related to a cacheFile node via a historySwitch node
- Parameters:
node (str) – A node to check if it’s a cacheFile node or related to a cacheFile node
- Return cacheFileNode:
The name of the cacheFile node found or “” if None found
- Rtype cacheFileNode:
str
- getCacheNode(clothShape, nClothShape)¶
Returns the cache node if one exists, returns “” if None.
- checkConnectedCache(clothShape, nClothShape)¶
Checks the shape node is connected to a cache with a hardcoded name “cache”
Could depreciate for getCacheNode()
- checkDeleteConnectedCache(networkNode, clothShape, nClothShape)¶
Checks the shape node is connected to a cache with a hardcoded name “cache” and if so will delete it from disk
Similar to:
Cache > Create New Cache
- paintNClothBlendshape(networkNode)¶
Opens the paint weights window for the Blendshape weights, sets the paint color to black (value) and .5 opacity
- Parameters:
networkNode (str) – The network node name that connects to all ncloth objects
- selectCache(networkNode)¶
Select the related cacheFile node if it exists.
- Parameters:
networkNode (str) – The network node name that connects to all ncloth objects
- selectNode(networkNode, nodeKey='blendshapeClothNode', selectNetworkNode=False)¶
Selects a node from the network using the dictionary keys:
ORIGINAL_MESH_TFRM = “originalMeshTransform” POLYSMOOTH_MESH_TFRM = “polySmoothMeshTransform” CLOTH_MESH_TFRM = “clothMeshTransform” CLOTH_MESH_SHAPE = “clothMeshShape” BLENDER_MESH_TFRM = “blenderMeshTransform” BLENDSHAPE_ORIG_NODE = “blendshapeOrigNode” BLENDSHAPE_CLOTH_NODE = “blendshapeClothNode” NCLOTH_NODE = “nClothNode” NCLOTH_TRANSFORM = “nClothTransform” NUCLEUS_NODE = “nucleusNode” CLOTH_NODES_GRP = “clothNodesGrp”
- showMesh(networkNode, nodeKey='originalMeshTransform')¶
Shows one of four meshes in the Skinned NCloth setup while hiding the others.
Meshes are defined as constants see the nodeKeys at nclothconstants.py:
ORIGINAL_MESH_TFRM = “originalMeshTransform” POLYSMOOTH_MESH_TFRM = “polySmoothMeshTransform” CLOTH_MESH_TFRM = “clothMeshTransform” BLENDER_MESH_TFRM = “blenderMeshTransform”
- checkNetworkEnabled(networkNode)¶
Returns if the entire nCloth network enabled True or disabled False, is tricky to calculate.
The returned enable state relates to the entire network, and not the nucleus state, so getting it’s value can be
tricky.
The checkbox is set via checking the node network, depends on a few things as nucleus is disabled while
caching even though the network state is still valid and on (enabled). If nucleus is disabled but the blender mesh is visible and there is a cache, then the network is considered
enabled. Otherwise it’ll go with the nucleus state.
- Parameters:
networkNode (str) – Name of a skinned NCloth network node
- Return networkEnabled:
Is the entire network enabled True or disabled False, see doc description
- Rtype networkEnabled:
bool
- enableDisableNetwork(networkNode, enable=True, affectMeshVis=True)¶
This function will enable or disable the whole nCloth network.
Enable:
The nucleus will be enabled only if there is not a cache connected to the clothMeshShape node. The blender mesh (the fully enabled cloth mesh with a blendshape) will be shown if affectMeshVis=True
Disable:
The nucleus will be disabled, and the original mesh (the skinned mesh before the setup) will be shown if
affectMeshVis=True
- Parameters:
- Return isEnabled:
The resulting state of the setup, usually the same as the enable incoming unless issues.
- Rtype isEnabled:
bool
- Return success:
Will report False if there were issues.
- Rtype success:
bool
- enableDisableNetworkAll(enable=True, affectMeshVis=True, message=True)¶
Enables or disables all network nodes in the scene
- textCurrentPreset(nClothShape)¶
Builds a nicely formatted dictionary code for use as a python preset. Used internally only. Don’t remove.
Code use:
from zoo.libs.maya.cmds.ncloth import nclothskinned print nclothskinned.textCurrentPreset(“nClothShape”)
Returns string used in nclothconstants.py, Eg:
{NCA_INPUT_ATTRACT: 1.0, NCA_LIFT: 0.0001, NCA_STRETCH_RESISTANCE: 35.0, NCA_COMPRESSION_RESISTANCE: 10.0, NCA_BEND_RESISTANCE: 0.4, NCA_BEND_ANGLE_DROPOFF: 0.4, NCA_SHEAR_RESISTANCE: 0.0, NCA_POINT_MASS: 0.6, NCA_TANGENTIAL_DRAG: 0.1, NCA_DAMP: 0.8, NCA_SCALING_RELATION: 1.0, NCA_PUSH_OUT_RADIUS: 10.0, NCA_THICKNESS: 0.005, NCA_LOCAL_SPACE_OUTPUT: 1.0, NCA_SELF_COLLIDE_WIDTH_SCALE: 1 }
- Parameters:
nClothShape (str) – nCloth shape node name
- Return text:
text formatted for manually creating a python preset
- Rtype text:
str