Forum
Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC:

Scripting Kinetic Drives for Garments 7 months 1 week ago #659

  • Sebastian
  • Sebastian's Avatar Topic Author
  • Offline
  • Administrator
  • Administrator
  • Posts: 122
  • Thank you received: 25
Sometimes you might find yourself in a situation where you have a (potentially quite complex) garment set up on a character and need to apply Kinetic Drives to most or all of them.
I was in this situation the other day...
I set up a garment, using the Carbon Garment Processor, that was made up from over 20 different Cloth panels.
Once the garment was set up, I simulated it on a human character going through a running cycle.
A lot of the garments were quity loose and "bounced" around too much for my liking.
The solution to my problem was quite clear: I need to apply Carbon Kinetic Drives to the Cloths to "inject" some of the running motion into the Cloths, which will prevent them from bouncing too much.

As I did not want to manually set up over two dozen Kinetic Drives, I wrote a quick python script to set them up for me.
The Carbon For Maya plugin comes with a comprehensive python and mel API, and several scripted examples.
So whenever I can, I write helper scripts that make my life easier.

Here is my python script to set up all Kinetic Drives for all Cloths of a Garment Processor.
All Kinetic Drives' Ratio and Physics Draw Scale can be controlled from a parameter on the transform that they are stored under.
Feel free to reuse, edit, share this script:
import maya.cmds as cmds
import carbonPublicAPI

isLoaded = int(cmds.pluginInfo('Carbon', q=1, loaded=1))
# Load Carbon plugin if not loaded yet
if isLoaded == 0:
    cmds.loadPlugin('Carbon')
# Point to Simulation
simulation = 'carbonSimulationShape1' # <========== Change to fit your needs.
# Point to Actor
actor = 'carbonActorShape1'           # <========== Change to fit your needs.
# Point to Cloths folder
clothsFolder = 'Cloths'               # <========== Change to fit your needs.
# Ratio
ratio = 0.2                           # <========== Change to fit your needs.
#============================================================================
# Create Kinetic Drives
carbonPublicAPI.setSimulationStatus(simulation, 0)
clothsParent = cmds.listRelatives(clothsFolder, parent=True)[0]
kineticDrives = cmds.createNode('transform', n='Kinetic_Drives', parent=clothsParent)
cmds.select(kineticDrives, r=True)
cmds.addAttr(longName='ratio', attributeType='float', minValue=0.0, maxValue=1.0, defaultValue=0.1)
cmds.addAttr(longName='renderScale', attributeType='float', minValue=0.0, defaultValue=1.0, softMaxValue=10.0)
cloths = cmds.listRelatives(clothsFolder, children=True)
for cloth in cloths:
    kineticDrive = str(carbonPublicAPI.createNode('KineticDrive', simulation))
    kineticDriveTransform = cmds.listRelatives(kineticDrive, parent=True)[0]
    cmds.parent(kineticDriveTransform, kineticDrives)
    carbonPublicAPI.changeCarbonNode(kineticDrive,"objectA", actor)
    carbonPublicAPI.changeCarbonNode(kineticDrive,"objectB", cloth)
    cmds.setAttr(kineticDrive + '.groupB', '*', type='string')
    cmds.connectAttr(kineticDrives + '.ratio', kineticDrive + '.ratio')
    cmds.connectAttr(kineticDrives + '.renderScale', kineticDrive + '.renderScale')
    cmds.rename(kineticDriveTransform, cloth + '_Kinetic_Drive')
carbonPublicAPI.setSimulationStatus(simulation, 1)

Please Log in or Create an account to join the conversation.

Last edit: by Sebastian.
  • Page:
  • 1
Time to create page: 0.065 seconds