Son
Son

Reputation: 1863

Maya : Different behaviours in standalone and embedded mode

I would like to create a script that imports a scene, runs the nCloth simulation and exports the result to OBJ format.

The input I use is downloaded from Maya's "Getting started" section. The script is written in Python in order to launch in standalone mode: http://pastebin.com/3hptPYbB

The script works fine when launched within Maya. In standalone mode, the nCloth simulation is not triggered apprently as the result is the scene before simulation and the script terminates quite quickly.

Does anyone know why the result is different between 2 running modes and how to fix this problem ? Maybe a nCloth plugin should be loaded beforehand ?

Thanks,

Upvotes: 0

Views: 722

Answers (1)

theodox
theodox

Reputation: 12218

In this case I think it's actually the flags on bakeResults. I was able to get this to work in a maya standalone:

import maya.mel
import maya.cmds as cmds
cmds.file(new=True, f=True)
cmds.polyCube()
cmds.polyPlane(sx = 21, sy = 22)
cmds.xform(t= (.0005, .015, .0005)) # note units - my maya is working in meters...
mel.eval("createNCloth 0;")
maya.mel.eval("createNCloth 0;")
cmds.select('pCube1')
maya.mel.eval("makeCollideNCloth")
cmds.playbackOptions(animationStartTime=0)
cmds.playbackOptions(animationEndTime=100)
cmds.play(f=True)
cmds.bakeResults('pPlane1', simulation=True, t=(1,20), disableImplicitControl=True, sb = 1, shape=True, cp=True )

# use openMaya to set the frame - cmds.currentTime does not 
# stick in standalone:
import maya.OpenMaya as om
om.MGlobal.viewFrame(20)
# delete the cloth solution 
cmds.delete('nCloth1', 'nRigid1')
# delete the orphaned shape
cmds.delete('pPlaneShape1')
cmds.file(rename = "C:/test/cloth.mb")
cmds.file(save=True)

The two issues I noticed were the need to set the shape and control point flags in bake results, and the need to separate out the baked shape from the original geometry after deleting the cloth solver. In this example deleting the cloth and the rigid body without deleting pPlaneShape1 leaves a copy of the original plane hanging around in the air. You may need to take out the deletions and look at the results to know what do do in this scene.

Upvotes: 2

Related Questions