def _buildSpeedExpression(boatWorldCtrl = ''): """ Builds the base expression for the boats world_ctrl speed attr @param boatWorldCtrl: The name of the boat world_ctrl to build the expression for @type boatWorldCtrl: String """ expStringList = [ 'float $time;\n', 'float $translation[] = `xform -q -ws -translation "%s"`;\n' % boatWorldCtrl, 'float $trx;\n', 'float $try;\n', 'float $trz;\n', 'float $dx = $translation[0] - $trx;\n', 'float $dy = $translation[1] - $try;\n', 'float $dz = $translation[2] - $trz;\n', 'float $d = sqrt( ($dx * $dx) + ($dy * $dy) + ($dz * $dz) );\n', '%s.speed = abs( $d / ( time - ($time + 0.001) ) );\n' % boatWorldCtrl, '$trx = $translation[0];\n', '$try = $translation[1];\n', '$trz = $translation[2];\n', '$time = time;\n' ] ## Check if the expression already exists in the scene, if so delete it utils.checkExpressionExists( '%s_speed' % boatWorldCtrl) ## Build new expression try: cmds.expression(n = '%s_speed' % boatWorldCtrl.replace(':', '_'), string = utils.processExpressionString(expStringList)) except: cmds.warning('YOU ARE USING OLD RIGS!!! PLEASE UPDATE YOUR RIGS!!!')
def _create_FOAM_FluidTexture(oceanShader = '', size = '', pathToPreset = '', foamFluidShapeName = CONST.FOAM_FLUID_SHAPENODE): """ create a 3d fluid texture for FOAM, make it a 2d simulation and texture the foamOffset of the ocean shader with it's outAlpha. """ debug(None, method = 'fluids_lib._create_FOAM_FluidTexture', message = 'Building fluid %s' % foamFluidShapeName, verbose = False) fluidShape = cmds.shadingNode('fluidTexture3D', asTexture = True, name = foamFluidShapeName) # Get parent of shape and set attrs fluid = cmds.listRelatives(fluidShape, parent= True) _setBaseFluidAttrs(fluid) ## Connect to time cmds.connectAttr ("time1.outTime",(fluidShape + ".currentTime")) debug(None, method = 'fluids_lib._create_FOAM_FluidTexture', message = '%s connected to time1' % fluidShape, verbose = False) ## Apply foam preset mel.eval("""applyPresetToNode " """+fluidShape+""" " "" "" "%s" 1;""" % pathToPreset) debug(None, method = 'fluids_lib._create_FOAM_FluidTexture', message = 'Mel preset applied: %s' % pathToPreset, verbose = False) #add expression to texture expStringList = [ "float $foamSpeed = 1.0;\n", "%s.textureTime = time * $foamSpeed;\n" % fluidShape ] utils.checkExpressionExists('s_foamTexture_Speed') cmds.expression(n = '%s_foamTexture_Speed' % fluidShape, string = utils.processExpressionString(expStringList)) expStringList = [ 'int $width = %s.dimensionsW;\r\n' % fluidShape, 'int $height = %s.dimensionsH;\r\n' % fluidShape, 'if ($width>= $height)\r\n', '{\r\n', '%s.baseResolution = $width*2;\r\n' % fluidShape, '}\r\n', 'else\r\n', '{\r\n', '%s.baseResolution = $height*2;\r\n' % fluidShape, '}' ] #expression to maintain resolution/container size relationship cmds.expression(n = '%s_foamTexture_ContainerSize' % fluidShape, string = utils.processExpressionString(expStringList)) debug(None, method = 'fluids_lib._create_FOAM_FluidTexture', message = ' Expression %s_foamTexture_ContainerSize built' % fluidShape, verbose = False) baseTextureName = fluidShape.split('Shape')[0] cmds.rename(fluid[0], '%s' % baseTextureName) utils.createTypeTag(obj = '%s' % baseTextureName, typeName = '%s' % baseTextureName) debug(None, method = 'fluids_lib._create_FOAM_FluidTexture', message = ' Rename and Tag successful..', verbose = False) ## Connect fluid to ocean shader cmds.connectAttr("%s.outAlpha" % fluidShape, "%s.foamOffset" % oceanShader, force = True) debug(None, method = 'fluids_lib._create_FOAM_FluidTexture', message = ' Returning %s:' % fluidShape, verbose = False) return fluidShape
def _buildNURBSPlaneExpression(NURBSPlane, xRes, zRes, oceanShader): """ Function to setup the expression that hooks the nurbsPlane to the ocean @param NURBSPlane: The build of the nurbsPlane, this build command should have returned a list. Due to refactoring we're just handling this list instead of accepting the actual name @type NURBSPlane: List """ ## Now build the expression to connect the cv's of the NURBSPlane to the ocean xSize = xRes+1 zSize = zRes+1 expStringList = ['float $u, $v;\n float $minx = %s.scaleX * -0.5 + %s.translateX;\n' % (NURBSPlane[0], NURBSPlane[0]), 'float $maxx = %s.scaleX * 0.5 + %s.translateX;\n' % (NURBSPlane[0], NURBSPlane[0]), 'float $minz = %s.scaleZ * -0.5 + %s.translateZ;\n' % (NURBSPlane[0], NURBSPlane[0]), 'float $maxz = %s.scaleZ * 0.5 + %s.translateZ;\n' % (NURBSPlane[0], NURBSPlane[0]), 'float $disp[] = `colorAtPoint -o A -su %s -sv %s -mu $minx -mv $minz -xu $maxx -xv $maxz %s`;\n' % (str(xSize), str(zSize), oceanShader) ] expString = utils.processExpressionString(expStringList) #unfold loop and use output connections i=0 for x in range(xSize): planeX = x * zSize for z in range(zSize): planeZ= zSize - z - 1 addTo = "%s.cv[%s].yv = $disp[%s];\n" % (NURBSPlane[0], str(planeX +planeZ), str(i)) expString += addTo #increment by 1 i=i+1 ## Check if the expression already exists in the scene, if so delete it utils.checkExpressionExists( '%s_IntersectionPlane' % NURBSPlane[0]) ## Build new expression cmds.expression(n = '%s_IntersectionPlane' % '_'.join(NURBSPlane[0].split(':')), string = expString)
def _create_WAKE_FluidTexture(oceanShader = '', size = '', pathToPreset = '', wakeFluidShapeName = CONST.WAKE_FLUID_SHAPENODE): """ Create a 3d fluid texture, make it a 2d simulation and texture the waveHeightOffset of the ocean shader with it's outAlpha. @param oceanShader: @param size: @type oceanShader: @type size: """ debug(None, method = '_create_WAKE_FluidTexture', message = 'Building fluid %s' % wakeFluidShapeName, verbose = False) fluidShape = cmds.shadingNode('fluidTexture3D', asTexture = True, name = wakeFluidShapeName) # Get parent of shape and set attrs fluid = cmds.listRelatives(fluidShape, parent= True) _setBaseFluidAttrs(fluid) ## Connect to time cmds.connectAttr ("time1.outTime", (fluidShape + ".currentTime")) debug(None, method = '_create_WAKE_FluidTexture', message = '%s connected to time1' % fluidShape, verbose = False) ## Apply wake preset mel.eval("""applyPresetToNode " """+fluidShape+""" " "" "" "%s" 1;""" % pathToPreset) debug(None, method = '_create_WAKE_FluidTexture', message = 'Mel preset applied: %s' % pathToPreset, verbose = False) #expression to maintain resolution/container size relationship expStringList = ["int $width = %s.dimensionsW;\r\n" % fluidShape, 'int $height = %s.dimensionsH;\r\n' % fluidShape, 'if ($width>= $height)\r\n', '{\r\n', '%s.baseResolution = $width*4;\r\n' % fluidShape, '}\r\n', 'else\r\n', '{\r\n%s.baseResolution = $height*4;\r\n}' % fluidShape] utils.checkExpressionExists('waterSurfaceFluidTexture') cmds.expression(n = 'waterSurfaceFluidTexture', string = utils.processExpressionString(expStringList)) debug(None, method = '_create_WAKE_FluidTexture', message = ' Expression %s_foamTexture_ContainerSize built' % fluidShape, verbose = False) baseTextureName = wakeFluidShapeName.split('Shape')[0] cmds.rename(fluid[0], '%s' % baseTextureName) utils.createTypeTag(obj = '%s' % baseTextureName, typeName = '%s' % baseTextureName) debug(None, method = '_create_WAKE_FluidTexture', message = ' Rename and Tag successful..', verbose = False) ## Connect new wake fluid tex to ocean cmds.connectAttr("%s.outAlpha" % wakeFluidShapeName, "%s.waveHeightOffset" % oceanShader, force = True) debug(None, method = '_create_WAKE_FluidTexture', message = ' Returning %s:' % fluidShape, verbose = False) return fluidShape
def _buildNURBSPlaneExpression(NURBSPlane, xRes, zRes, oceanShader): """ Function to setup the expression that hooks the nurbsPlane to the ocean @param NURBSPlane: The build of the nurbsPlane, this build command should have returned a list. Due to refactoring we're just handling this list instead of accepting the actual name @type NURBSPlane: List """ ## Now build the expression to connect the cv's of the NURBSPlane to the ocean xSize = xRes + 1 zSize = zRes + 1 expStringList = [ 'float $u, $v;\n float $minx = %s.scaleX * -0.5 + %s.translateX;\n' % (NURBSPlane[0], NURBSPlane[0]), 'float $maxx = %s.scaleX * 0.5 + %s.translateX;\n' % (NURBSPlane[0], NURBSPlane[0]), 'float $minz = %s.scaleZ * -0.5 + %s.translateZ;\n' % (NURBSPlane[0], NURBSPlane[0]), 'float $maxz = %s.scaleZ * 0.5 + %s.translateZ;\n' % (NURBSPlane[0], NURBSPlane[0]), 'float $disp[] = `colorAtPoint -o A -su %s -sv %s -mu $minx -mv $minz -xu $maxx -xv $maxz %s`;\n' % (str(xSize), str(zSize), oceanShader) ] expString = utils.processExpressionString(expStringList) #unfold loop and use output connections i = 0 for x in range(xSize): planeX = x * zSize for z in range(zSize): planeZ = zSize - z - 1 addTo = "%s.cv[%s].yv = $disp[%s];\n" % ( NURBSPlane[0], str(planeX + planeZ), str(i)) expString += addTo #increment by 1 i = i + 1 ## Check if the expression already exists in the scene, if so delete it utils.checkExpressionExists('%s_IntersectionPlane' % NURBSPlane[0]) ## Build new expression cmds.expression(n='%s_IntersectionPlane' % '_'.join(NURBSPlane[0].split(':')), string=expString)
def _connectNURBSCurveToFluidContainer(nurbsCrv='', fluidContainer='', boatName='', worldCtrl='', animatable=''): """ Used to connect the intersection curves to the fluids. """ debug(None, method='_connectNURBSCurveToFluidContainer', message='Selecting: %s' % nurbsCrv, verbose=False) cmds.select(nurbsCrv, r=True) cmds.selectKey(clear=True) debug(None, method='_connectNURBSCurveToFluidContainer', message='Selecting: %s' % fluidContainer, verbose=False) #mel.eval("EmitFluidFromObject;") emitterName = '%s_%s_emitter' % (nurbsCrv, fluidContainer) debug(None, method='_connectNURBSCurveToFluidContainer', message='emitterName: %s' % emitterName, verbose=False) if not cmds.objExists(emitterName): mel.eval( "fluidEmitter -type curve -name \"%s\" -der 1 -her 1 -fer 1 -fdr 2 -r 100.0 -cye none -cyi 1 -mxd 1 -mnd 0" % emitterName) cmds.select(fluidContainer, add=True) ## NOTE we don't need to do this connect here as we use _linkWakeEmitters later on which does them all #cmds.connectDynamic (fluidContainer, em = emitterName, d = True) ## Set basic attrs for emitter across both foam and wake try: ## for re running script over existing build cmds.setAttr('%s.emitterType' % emitterName, 3) cmds.setAttr('%s.rate' % emitterName, 1500) cmds.setAttr('%s.fluidJitter' % emitterName, 0) cmds.setAttr('%s.motionStreak' % emitterName, 1) cmds.setAttr('%s.fluidDropoff' % emitterName, 1) ## Set special attrs for wake or foam if 'oceanWakeTextureShape' in emitterName: cmds.setAttr('%s.heatMethod' % emitterName, 0) cmds.setAttr('%s.fuelMethod' % emitterName, 0) cmds.setAttr('%s.fluidDensityEmission' % emitterName, 0.05) else: cmds.setAttr('%s.densityMethod' % emitterName, 0) cmds.setAttr('%s.fuelMethod' % emitterName, 0) cmds.setAttr('%s.fluidHeatEmission' % emitterName, 0.05) cmds.setAttr('%s.turbulence' % emitterName, 1) except RuntimeError: pass ## Now build the scene emitter group if not cmds.objExists('FLUID_EMITTERS_hrc'): cmds.group(n='FLUID_EMITTERS_hrc', em=True) try: cmds.parent(emitterName, 'FLUID_EMITTERS_hrc') except RuntimeError: pass ## DO THE EXPRESSIONS... if 'oceanWakeTextureShape' in emitterName: if 'IntersectCurveRight' in emitterName: direction = 'R' else: direction = 'L' ### FOR WAKE EMITTERS ###################################### ## EMISSION RATE: Expression to tie emission rate to boat speed ## LEFT expStringList = [ 'float $minSpeed = %s.minSpeed;\n' % animatable, 'float $maxSpeed = %s.maxSpeed;\n' % animatable, 'float $speed = %s.speed;\n' % worldCtrl, 'float $curve = smoothstep($minSpeed, $maxSpeed, $speed);\n', 'float $rateMultiplier%s = %s.sideWakeMultiplier%s;\n' % (direction, animatable, direction), 'float $idleRate%s = %s.sideWakeIdleMultiplier%s;\n' % (direction, animatable, direction), '\n', 'if (%s.useSpeed == 1)\n' % animatable, '{\n\t', 'if ($speed < $minSpeed)\n\t', '{\n\t', '\t%s.rate = $idleRate%s;\n\t' % (emitterName, direction), '}\n\t', 'else\n\t', '{\n\t', '\t%s.rate = $rateMultiplier%s * $curve;\n\t' % (emitterName, direction), '}\n', '}\n', 'else\n', '{\n\t', '%s.rate = $rateMultiplier%s;\n' % (emitterName, direction), '}\n', ] debug(None, method='_connectNURBSCurveToFluidContainer', message='FOAM expression: %s' % utils.processExpressionString(expStringList), verbose=False) ## Check if the expression already exists in the scene, if so delete it utils.checkExpressionExists('%s_emissionRate' % emitterName) ## Build new expression cmds.expression(n='%s_emissionRate' % emitterName, string=utils.processExpressionString(expStringList)) ## Connect some attributes if not cmds.isConnected( '%s.sideWakeDensity%s' % (animatable, direction), '%s.fluidDensityEmission' % emitterName): cmds.connectAttr('%s.sideWakeDensity%s' % (animatable, direction), '%s.fluidDensityEmission' % emitterName) if not cmds.isConnected( '%s.sideWakeDropoff%s' % (animatable, direction), '%s.fluidDropoff' % emitterName): cmds.connectAttr('%s.sideWakeDropoff%s' % (animatable, direction), '%s.fluidDropoff' % emitterName) elif 'oceanWakeFoamTextureShape' in emitterName: if 'IntersectCurveRight' in emitterName: direction = 'R' else: direction = 'L' ### FOR WAKE EMITTERS ###################################### ## EMISSION RATE: Expression to tie emission rate to boat speed wakeEmitterName = '%sTextureShape_emitter' % emitterName.split( 'FoamTextureShape_emitter')[0] expStringList = [ 'float $minSpeed = %s.minSpeed;\n' % animatable, 'float $maxSpeed = %s.maxSpeed;\n' % animatable, 'float $speed = %s.speed;\n' % worldCtrl, 'float $curve = smoothstep($minSpeed, $maxSpeed, $speed);\n', 'float $rateMultiplier%s = %s.sideFoamMultiplier%s;\n' % (direction, animatable, direction), 'float $idleRate%s = %s.sideFoamIdleMultiplier%s;\n' % (direction, animatable, direction), '\n', 'if (%s.useSpeed == 1)\n' % animatable, '{\n\t', 'if ($speed < $minSpeed)\n\t', '{\n\t', '\t%s.rate = $idleRate%s;\n\t' % (emitterName, direction), '}\n\t', 'else\n\t', '{\n\t', '\t%s.rate = $rateMultiplier%s * $curve;\n\t' % (emitterName, direction), '}\n', '}\n', 'else\n', '{\n\t', '%s.rate = $rateMultiplier%s;\n' % (emitterName, direction), '}\n', ] debug(None, method='_connectNURBSCurveToFluidContainer', message='WAKE expression: %s' % utils.processExpressionString(expStringList), verbose=False) ## Check if the expression already exists in the scene, if so delete it utils.checkExpressionExists('%s_emissionRate' % emitterName) ## Build new expression cmds.expression(n='%s_emissionRate' % emitterName, string=utils.processExpressionString(expStringList)) ## Connect some attributes if not cmds.isConnected( '%s.sideFoamDensity%s' % (animatable, direction), '%s.fluidHeatEmission' % emitterName): cmds.connectAttr('%s.sideFoamDensity%s' % (animatable, direction), '%s.fluidHeatEmission' % emitterName) if not cmds.isConnected( '%s.sideFoamDropoff%s' % (animatable, direction), '%s.fluidDropoff' % emitterName): cmds.connectAttr('%s.sideFoamDropoff%s' % (animatable, direction), '%s.fluidDropoff' % emitterName) else: pass return emitterName
def _connectNURBSCurveToFluidContainer(nurbsCrv = '', fluidContainer = '', boatName = '', worldCtrl = '', animatable = ''): """ Used to connect the intersection curves to the fluids. """ debug(None, method = '_connectNURBSCurveToFluidContainer', message = 'Selecting: %s' % nurbsCrv, verbose = False) cmds.select(nurbsCrv, r = True) cmds.selectKey(clear = True) debug(None, method = '_connectNURBSCurveToFluidContainer', message = 'Selecting: %s' % fluidContainer, verbose = False) #mel.eval("EmitFluidFromObject;") emitterName = '%s_%s_emitter' % (nurbsCrv, fluidContainer) debug(None, method = '_connectNURBSCurveToFluidContainer', message = 'emitterName: %s' % emitterName, verbose = False) if not cmds.objExists(emitterName): mel.eval("fluidEmitter -type curve -name \"%s\" -der 1 -her 1 -fer 1 -fdr 2 -r 100.0 -cye none -cyi 1 -mxd 1 -mnd 0" % emitterName) cmds.select(fluidContainer, add = True) ## NOTE we don't need to do this connect here as we use _linkWakeEmitters later on which does them all #cmds.connectDynamic (fluidContainer, em = emitterName, d = True) ## Set basic attrs for emitter across both foam and wake try: ## for re running script over existing build cmds.setAttr('%s.emitterType' % emitterName, 3) cmds.setAttr('%s.rate' % emitterName, 1500) cmds.setAttr('%s.fluidJitter' % emitterName, 0) cmds.setAttr('%s.motionStreak' % emitterName, 1) cmds.setAttr('%s.fluidDropoff' % emitterName, 1) ## Set special attrs for wake or foam if 'oceanWakeTextureShape' in emitterName: cmds.setAttr('%s.heatMethod' % emitterName, 0) cmds.setAttr('%s.fuelMethod' % emitterName, 0) cmds.setAttr('%s.fluidDensityEmission' % emitterName, 0.05) else: cmds.setAttr('%s.densityMethod' % emitterName, 0) cmds.setAttr('%s.fuelMethod' % emitterName, 0) cmds.setAttr('%s.fluidHeatEmission' % emitterName, 0.05) cmds.setAttr('%s.turbulence' % emitterName, 1) except RuntimeError: pass ## Now build the scene emitter group if not cmds.objExists('FLUID_EMITTERS_hrc'): cmds.group(n = 'FLUID_EMITTERS_hrc', em = True) try: cmds.parent(emitterName, 'FLUID_EMITTERS_hrc') except RuntimeError: pass ## DO THE EXPRESSIONS... if 'oceanWakeTextureShape' in emitterName: if 'IntersectCurveRight' in emitterName: direction = 'R' else: direction = 'L' ### FOR WAKE EMITTERS ###################################### ## EMISSION RATE: Expression to tie emission rate to boat speed ## LEFT expStringList = [ 'float $minSpeed = %s.minSpeed;\n' % animatable, 'float $maxSpeed = %s.maxSpeed;\n' % animatable, 'float $speed = %s.speed;\n' % worldCtrl, 'float $curve = smoothstep($minSpeed, $maxSpeed, $speed);\n', 'float $rateMultiplier%s = %s.sideWakeMultiplier%s;\n' %(direction, animatable, direction), 'float $idleRate%s = %s.sideWakeIdleMultiplier%s;\n' %(direction, animatable, direction), '\n', 'if (%s.useSpeed == 1)\n' % animatable, '{\n\t', 'if ($speed < $minSpeed)\n\t', '{\n\t', '\t%s.rate = $idleRate%s;\n\t' %(emitterName, direction), '}\n\t', 'else\n\t', '{\n\t', '\t%s.rate = $rateMultiplier%s * $curve;\n\t' %(emitterName, direction), '}\n', '}\n', 'else\n', '{\n\t', '%s.rate = $rateMultiplier%s;\n' %(emitterName, direction), '}\n', ] debug(None, method = '_connectNURBSCurveToFluidContainer', message = 'FOAM expression: %s' % utils.processExpressionString(expStringList), verbose = False) ## Check if the expression already exists in the scene, if so delete it utils.checkExpressionExists( '%s_emissionRate' % emitterName) ## Build new expression cmds.expression(n = '%s_emissionRate' % emitterName, string = utils.processExpressionString(expStringList)) ## Connect some attributes if not cmds.isConnected('%s.sideWakeDensity%s' %(animatable, direction), '%s.fluidDensityEmission' % emitterName): cmds.connectAttr('%s.sideWakeDensity%s' %(animatable, direction), '%s.fluidDensityEmission' % emitterName) if not cmds.isConnected('%s.sideWakeDropoff%s' %(animatable, direction), '%s.fluidDropoff' % emitterName): cmds.connectAttr('%s.sideWakeDropoff%s' %(animatable, direction), '%s.fluidDropoff' % emitterName) elif 'oceanWakeFoamTextureShape' in emitterName: if 'IntersectCurveRight' in emitterName: direction = 'R' else: direction = 'L' ### FOR WAKE EMITTERS ###################################### ## EMISSION RATE: Expression to tie emission rate to boat speed wakeEmitterName = '%sTextureShape_emitter' % emitterName.split('FoamTextureShape_emitter')[0] expStringList = [ 'float $minSpeed = %s.minSpeed;\n' % animatable, 'float $maxSpeed = %s.maxSpeed;\n' % animatable, 'float $speed = %s.speed;\n' % worldCtrl, 'float $curve = smoothstep($minSpeed, $maxSpeed, $speed);\n', 'float $rateMultiplier%s = %s.sideFoamMultiplier%s;\n' %(direction, animatable, direction), 'float $idleRate%s = %s.sideFoamIdleMultiplier%s;\n' %(direction, animatable, direction), '\n', 'if (%s.useSpeed == 1)\n' % animatable, '{\n\t', 'if ($speed < $minSpeed)\n\t', '{\n\t', '\t%s.rate = $idleRate%s;\n\t' %(emitterName, direction), '}\n\t', 'else\n\t', '{\n\t', '\t%s.rate = $rateMultiplier%s * $curve;\n\t' %(emitterName, direction), '}\n', '}\n', 'else\n', '{\n\t', '%s.rate = $rateMultiplier%s;\n' %(emitterName, direction), '}\n', ] debug(None, method = '_connectNURBSCurveToFluidContainer', message = 'WAKE expression: %s' % utils.processExpressionString(expStringList), verbose = False) ## Check if the expression already exists in the scene, if so delete it utils.checkExpressionExists( '%s_emissionRate' % emitterName) ## Build new expression cmds.expression(n = '%s_emissionRate' % emitterName, string = utils.processExpressionString(expStringList)) ## Connect some attributes if not cmds.isConnected('%s.sideFoamDensity%s' %(animatable, direction), '%s.fluidHeatEmission' % emitterName): cmds.connectAttr('%s.sideFoamDensity%s' %(animatable, direction), '%s.fluidHeatEmission' % emitterName) if not cmds.isConnected('%s.sideFoamDropoff%s' %(animatable, direction), '%s.fluidDropoff' % emitterName): cmds.connectAttr('%s.sideFoamDropoff%s' %(animatable, direction), '%s.fluidDropoff' % emitterName) else: pass return emitterName
def _buildHullEmitter(boatName, constraint = '', implicitSphere = '', animatable = ''): worldCtrl = boatName cmds.select(clear = True) ns = boatName.split(':')[0] newName = '%s_hullEmitter' % ns grpName = '%s_CONS_GRP' % newName offsetGrp = '%s_OFFSET_GRP' % newName debug(None, method = '_buildHullEmitter', message = 'worldCtrl: %s' % worldCtrl, verbose = False) debug(None, method = '_buildHullEmitter', message = 'ns: %s' % ns, verbose = False) debug(None, method = '_buildHullEmitter', message = 'newName: %s' % newName, verbose = False) debug(None, method = '_buildHullEmitter', message = 'grpName: %s' % grpName, verbose = False) debug(None, method = '_buildHullEmitter', message = 'offsetGrp: %s' % offsetGrp, verbose = False) if not cmds.objExists(newName): cmds.select(clear = True) emitterName = _buildFluidEmitter(newName) if not cmds.objExists(offsetGrp): offsetGrp = cmds.group(emitterName, name = offsetGrp) if not cmds.objExists(grpName): grpName = cmds.group(offsetGrp, name = grpName) else: emitterName = [newName] ## Constraint stuffs if constraint: cmds.parentConstraint(constraint, grpName, maintainOffset = False, name = '%s_fluidPointConstraint' % newName) else: cmds.parentConstraint('%scog_ctrl' % boatName.split('world_ctrl')[0], grpName, maintainOffset = False, name = '%s_fluidPointConstraint' % newName) ## Presets from implicit sphere template if implicitSphere: cmds.delete( cmds.parentConstraint(implicitSphere, offsetGrp, maintainOffset = False) ) cmds.delete( cmds.scaleConstraint(implicitSphere, offsetGrp, maintainOffset = False) ) ## Now build the scene emitter group if not cmds.objExists('FLUID_EMITTERS_hrc'): cmds.group(name = 'FLUID_EMITTERS_hrc', empty = True) try: cmds.parent(grpName, 'FLUID_EMITTERS_hrc') except RuntimeError: pass ### FOR HULL EMITTERS ###################################### ## EMISSION RATE: Expression to tie emission rate to boat speed expStringList = [ 'float $minSpeed = %s.minSpeed;\n' % animatable, 'float $maxSpeed = %s.maxSpeed;\n' % animatable, 'float $speed = %s.speed;\n' % worldCtrl, 'float $curve = smoothstep($minSpeed, $maxSpeed, $speed);\n', 'float $rateMultiplier = %s.rearWakeMultiplier;\n' % animatable, 'float $idleRate = %s.rearWakeIdleMultiplier;\n' % animatable, '\n', 'if (%s.useSpeed == 1)\n' % animatable, '{\n\t', 'if ($speed < $minSpeed)\n\t', '{\n\t', '\t%s.rate = $idleRate;\n\t' % emitterName[0], '}\n\t', 'else\n\t', '{\n\t', '\t%s.rate = $rateMultiplier * $curve;\n\t' % emitterName[0], '}\n', '}\n', 'else\n', '{\n\t', '%s.rate = $rateMultiplier;\n' % emitterName[0], '}\n', ] debug(None, method = '_buildHullEmitter', message = 'HULL expression: %s' % utils.processExpressionString(expStringList), verbose = False) ## Check if the expression already exists in the scene, if so delete it utils.checkExpressionExists( '%s_emissionRate' % emitterName[0]) ## Build new expression cmds.expression(n = '%s_emissionRate' % emitterName[0], string = utils.processExpressionString(expStringList)) ## Connect some attributes if not cmds.isConnected('%s.rearWakeDensity' % animatable, '%s.fluidDensityEmission' % emitterName[0]): cmds.connectAttr('%s.rearWakeDensity' % animatable, '%s.fluidDensityEmission' % emitterName[0]) if not cmds.isConnected('%s.rearWakeDropoff' % animatable, '%s.fluidDropoff' % emitterName[0]): cmds.connectAttr('%s.rearWakeDropoff' % animatable, '%s.fluidDropoff' % emitterName[0])
def _buildRearEmitter(name='', boatName='', splashParticleName='', rearAnimatable='', presetName=None): """ New builder for rear nParticle Emitter Checks if the NPARTICLE_EMITTLERS_hrc exists or not too @param name: The name of the new emitter @param splashParticleName: The name of the nParticleShape node for the splash @type name: String @type splashParticleName: String """ if not cmds.objExists('nPARTICLE_EMITTERS_hrc'): cmds.group(n='nPARTICLE_EMITTERS_hrc', em=True) debug(None, method='_buildRearEmitter', message='name: %s' % name, verbose=False) cmds.select( clear=True ) ## Because if you have anything selected maya may freak out it's the wrong damn thing.. f**k you maya seriously! ## Build the emitter emitter = cmds.emitter(name=name) emitter[0] = cmds.ls(emitter[0], long=True)[0] if presetName: pathToPreset = '%s/%s' % (CONST.EMITTERBASEPRESETPATH, presetName) debug(None, method='_buildRearEmitter', message='emitter: %s' % emitter, verbose=False) debug(None, method='_buildRearEmitter', message='pathToPreset: %s' % pathToPreset, verbose=False) ## Apply the preset to the emitter try: mel.eval('applyPresetToNode "%s" "" "" "%s" 1;' % (emitter[0], pathToPreset)) debug(None, method='_buildRearEmitter', message='Mel preset applied to %s: %s' % (emitter[0], pathToPreset), verbose=False) except RuntimeError: pass ## Now parent it try: emitter[0] = cmds.parent(emitter[0], 'nPARTICLE_EMITTERS_hrc')[0] except: pass ## Connect the emitter to the particles _connect_NParticleShape_to_NParticleEmitter( particleShapeNode=splashParticleName, emitter=emitter[0]) ## Now do the expression for the rear emitter expStringList = [ 'float $minSpeed = %s.minSpeed;\n' % rearAnimatable, 'float $maxSpeed = %s.maxSpeed;\n' % rearAnimatable, 'float $speed = %s:world_ctrl.speed;\n' % boatName, 'float $curve = smoothstep($minSpeed, $maxSpeed, $speed);\n', 'float $rateMuliplier = %s.rateMultiplier;\n' % rearAnimatable, 'float $splashMaxSpeed = %s.splashMaxSpeed;\n' % rearAnimatable, '\n', 'if (%s.useSpeed == 1)\n' % rearAnimatable, '{\n\t', '%s.rate = $rateMuliplier * $curve;\n\t\t' % emitter[0], '\n\t\t', 'float $emitterSpeed = $splashMaxSpeed * $curve;\n\t\t', 'if ($emitterSpeed == 0)\n\t\t', '{\n\t\t\t', '$emitterSpeed = 0.1;\n\t\t', '}\n\t\t', '%s.alongAxis = $emitterSpeed;\n' % emitter[0], '}\n', 'else\n', '{\n\t', '%s.rate = $rateMuliplier;\n\t' % emitter[0], '%s.alongAxis = $splashMaxSpeed;\n' % emitter[0], '}\n', ] ## Check if the expression already exists in the scene, if so delete it # utils.checkExpressionExists('%s_rearEmitter' % boatName) ## Build new expression cmds.expression(emitter[0], n='%s_rearEmitter' % boatName, string=utils.processExpressionString(expStringList)) ## Connect some attributes if not cmds.isConnected('%s.randomSpeed' % rearAnimatable, '%s.speedRandom' % emitter[0]): cmds.connectAttr('%s.randomSpeed' % rearAnimatable, '%s.speedRandom' % emitter[0]) if not cmds.isConnected('%s.randomDirection' % rearAnimatable, '%s.randomDirection' % emitter[0]): cmds.connectAttr('%s.randomDirection' % rearAnimatable, '%s.randomDirection' % emitter[0]) return emitter[0]
def _setupSide_ParticleExpressions(particleShapeName = '', type = 'splash', boatWorldCtrl = '', boatName = '', cPoS = '', sideAnimatable = ''): """ Setup the expressions for the sideEmitter's nParticleShape node @param particleShapeName: The name of the nParticleShape node @param boatWorldCtrl: The name of the boatWorldCtrl curve @param boatName: The name of the boat should be stripped : @type particleShapeName: String @type boatWorldCtrl: String @type boatName: String """ if type == 'splash': ############################ ## Creation expStringList = [ '%s.lifespanPP = rand(%s.lifespanMin, %s.lifespanMax);\n' %(particleShapeName, sideAnimatable, sideAnimatable), '%s.twistSpeedPP = rand(%s.twistSpeedMin, %s.twistSpeedMax);\n' %(particleShapeName, sideAnimatable, sideAnimatable), '%s.spriteStartSizePP = rand(%s.spriteStartSizeMin, %s.spriteStartSizeMax);\n' %(particleShapeName, sideAnimatable, sideAnimatable), '%s.spriteScaleYPP = %s.spriteScaleXPP = %s.spriteStartSizePP;\n' %(particleShapeName, particleShapeName, particleShapeName), '%s.spriteTwistPP = rand(%s.twistAngleMin, %s.twistAngleMax);\n' %(particleShapeName, sideAnimatable, sideAnimatable), ] ## Check if the expression already exists in the scene, if so delete it utils.checkExpressionExists('%s_sprite_settings' % particleShapeName) ## Build new expression cmds.dynExpression( particleShapeName, n = "%s_sprite_settings" % particleShapeName, creation = True, string = utils.processExpressionString(expStringList) ) ############################ ## Runtime Before Dynamics expStringList = [ '%s.spriteScaleYPP = %s.spriteScaleXPP = %s.spriteStartSizePP * %s.scaleOverLifeRamp;\n' %(particleShapeName, particleShapeName, particleShapeName, particleShapeName), '%s.spriteScaleXPP = %s.spriteScaleYPP;\n' %(particleShapeName, particleShapeName), '%s.spriteTwistPP += (%s.twistSpeedPP * %s.twistRateOverLife);\n' %(particleShapeName, particleShapeName, particleShapeName), '\n', ] ## Check if the expression already exists in the scene, if so delete it utils.checkExpressionExists('%s_sprite_settings' % particleShapeName) ## Build new expression cmds.dynExpression( particleShapeName, n = "%s_sprite_settings" % particleShapeName, rbd = True, string = utils.processExpressionString(expStringList) ) ## Connect some attrs to animatable group attrs = ['inheritFactor', 'conserve', 'drag', 'damp'] for att in attrs: if not cmds.isConnected( '%s.%sSprite' %(sideAnimatable, att), '%s.%s' %(particleShapeName, att) ): cmds.connectAttr('%s.%sSprite' %(sideAnimatable, att), '%s.%s' %(particleShapeName, att), force = True) elif type == 'mist': ## Creation expStringList = [ '%s.lifespanPP = rand(%s.lifespanMin, %s.lifespanMax);\n' %(particleShapeName, sideAnimatable, sideAnimatable), ] ## Check if the expression already exists in the scene, if so delete it utils.checkExpressionExists('%s_sprite_settings' % particleShapeName) ## Build new expression cmds.dynExpression( particleShapeName, n = "%s_sprite_settings" % particleShapeName, creation = True, string = utils.processExpressionString(expStringList) ) ## Connect some attrs to animatable group attrs = ['inheritFactor', 'conserve', 'drag', 'damp'] for att in attrs: if not cmds.isConnected( '%s.%sMist' %(sideAnimatable, att), '%s.%s' %(particleShapeName, att) ): cmds.connectAttr('%s.%sMist' %(sideAnimatable, att), '%s.%s' %(particleShapeName, att), force = True)
def _buildRearEmitter(name = '', boatName = '', splashParticleName = '', rearAnimatable = '', presetName = None): """ New builder for rear nParticle Emitter Checks if the NPARTICLE_EMITTLERS_hrc exists or not too @param name: The name of the new emitter @param splashParticleName: The name of the nParticleShape node for the splash @type name: String @type splashParticleName: String """ if not cmds.objExists('nPARTICLE_EMITTERS_hrc'): cmds.group(n = 'nPARTICLE_EMITTERS_hrc', em = True) debug(None, method = '_buildRearEmitter', message = 'name: %s' % name, verbose = False) cmds.select(clear = True) ## Because if you have anything selected maya may freak out it's the wrong damn thing.. f**k you maya seriously! ## Build the emitter emitter = cmds.emitter(name = name) emitter[0] = cmds.ls(emitter[0], long = True)[0] if presetName: pathToPreset = '%s/%s' %(CONST.EMITTERBASEPRESETPATH, presetName) debug(None, method = '_buildRearEmitter', message = 'emitter: %s' % emitter, verbose = False) debug(None, method = '_buildRearEmitter', message = 'pathToPreset: %s' % pathToPreset, verbose = False) ## Apply the preset to the emitter try: mel.eval( 'applyPresetToNode "%s" "" "" "%s" 1;' %(emitter[0], pathToPreset) ) debug(None, method = '_buildRearEmitter', message = 'Mel preset applied to %s: %s' % (emitter[0], pathToPreset), verbose = False) except RuntimeError: pass ## Now parent it try: emitter[0] = cmds.parent(emitter[0], 'nPARTICLE_EMITTERS_hrc')[0] except: pass ## Connect the emitter to the particles _connect_NParticleShape_to_NParticleEmitter(particleShapeNode = splashParticleName, emitter = emitter[0]) ## Now do the expression for the rear emitter expStringList = [ 'float $minSpeed = %s.minSpeed;\n' % rearAnimatable, 'float $maxSpeed = %s.maxSpeed;\n' % rearAnimatable, 'float $speed = %s:world_ctrl.speed;\n' % boatName, 'float $curve = smoothstep($minSpeed, $maxSpeed, $speed);\n', 'float $rateMuliplier = %s.rateMultiplier;\n' % rearAnimatable, 'float $splashMaxSpeed = %s.splashMaxSpeed;\n' % rearAnimatable, '\n', 'if (%s.useSpeed == 1)\n' % rearAnimatable, '{\n\t', '%s.rate = $rateMuliplier * $curve;\n\t\t' % emitter[0], '\n\t\t', 'float $emitterSpeed = $splashMaxSpeed * $curve;\n\t\t', 'if ($emitterSpeed == 0)\n\t\t', '{\n\t\t\t', '$emitterSpeed = 0.1;\n\t\t', '}\n\t\t', '%s.alongAxis = $emitterSpeed;\n' % emitter[0], '}\n', 'else\n', '{\n\t', '%s.rate = $rateMuliplier;\n\t' % emitter[0], '%s.alongAxis = $splashMaxSpeed;\n' % emitter[0], '}\n', ] ## Check if the expression already exists in the scene, if so delete it # utils.checkExpressionExists('%s_rearEmitter' % boatName) ## Build new expression cmds.expression(emitter[0], n = '%s_rearEmitter' % boatName, string = utils.processExpressionString(expStringList)) ## Connect some attributes if not cmds.isConnected('%s.randomSpeed' % rearAnimatable, '%s.speedRandom' % emitter[0]): cmds.connectAttr('%s.randomSpeed' % rearAnimatable, '%s.speedRandom' % emitter[0]) if not cmds.isConnected('%s.randomDirection' % rearAnimatable, '%s.randomDirection' % emitter[0]): cmds.connectAttr('%s.randomDirection' % rearAnimatable, '%s.randomDirection' % emitter[0]) return emitter[0]
def _buildSideSplashEmitter(name = '', boatName = '', splashParticleName = [], boatIntersectCurveShape = '', sideAnimatable = '', presetName = None): """ New builder for sideSplash nParticle Emitter Checks if the NPARTICLE_EMITTLERS_hrc exists or not too @param name: The name of the new emitter @param splashParticleName: List of the names of nParticleShape nodes to connect to the emitter @param boatIntersectCurveShape: The name of the intersection curve to emit from. @type name: String @type splashParticleName: List @type boatIntersectCurveShape: String """ if not cmds.objExists('nPARTICLE_EMITTERS_hrc'): cmds.group(n = 'nPARTICLE_EMITTERS_hrc', em = True) debug(None, method = '_buildSideSplashEmitter', message = 'name: %s' % name, verbose = False) # Get base flat surface lineCurve = cmds.curve( name = '%s_extrudeCurve' % name, degree = 1, point = [(-0.01, 0, 0), (0.01, 0, 0)] ) flatSurface = cmds.extrude(lineCurve, boatIntersectCurveShape, name = '%s_flatSurface' % name, constructionHistory = True, range = False, polygon = 0, useComponentPivot = 1, fixedPath = True, useProfileNormal = True, extrudeType = 2, reverseSurfaceIfPathReversed = True)[0] cmds.rebuildSurface(flatSurface, constructionHistory = True, replaceOriginal = True, rebuildType = 0, endKnots = 1, keepCorners = False, spansU = 1, degreeU = 1, spansV = 100, degreeV = 3) # Offset upwards curve from surface offsetUp = cmds.offsetCurve('%s.u[0.5]' % flatSurface, name = '%s_offsetUp' % name, distance = 0, constructionHistory = True, range = 0, subdivisionDensity = 1)[0] cmds.rebuildCurve(offsetUp, constructionHistory = False, replaceOriginal = True, end = 1, keepRange = 0, keepControlPoints = True, degree = 1) cmds.setAttr('%s.translateY' % offsetUp, 0.01) # Offset from upwards curve with distance and translate down to get the 45 degree angle offset_distance = -0.01 offsetOut = cmds.offsetCurve(offsetUp, name = '%s_offsetOut' % name, distance = offset_distance, constructionHistory = True, range = 0, subdivisionDensity = 1)[0] cmds.setAttr('%s.translateY' % offsetOut, offset_distance) # Finally, loft a non-flipping surface solution (45 degree angle of the boat) noFlipSurface = cmds.loft(offsetUp, offsetOut, degree = 1, constructionHistory = True, range = 0, polygon = 0, sectionSpans = 1)[0] noFlipSurface = cmds.rename(noFlipSurface, '%s_noFlipSurface' % name) ## Build the emitter emitter = cmds.emitter(noFlipSurface, name = '%s_emitter' % name, type = 'surface') # Create closestPointOnSurface for acceleration expression where front more acceleration cPoS = cmds.createNode('closestPointOnSurface', name = '%s_cPoS' % name) cmds.connectAttr('%s.worldSpace' % noFlipSurface, '%s.inputSurface' % cPoS) ## Build the emitter group if it doesn't already exist emitterGroup = '%s_hrc' % name if not cmds.objExists(emitterGroup): cmds.group(lineCurve, flatSurface, offsetUp, offsetOut, noFlipSurface, emitter[0], n = emitterGroup) debug(None, method = '_buildSideSplashEmitter', message = 'emitterName: %s' % emitter[1], verbose = False) ## Check if a custom preset has been assigned via the func flags for the emitter, if not use the default preset... if presetName: pathToPreset = '%s/%s' %(CONST.EMITTERBASEPRESETPATH, presetName) debug(None, method = '_buildSideSplashEmitter', message = 'pathToPreset: %s' % pathToPreset, verbose = False) mel.eval( 'applyPresetToNode "%s" "" "" "%s" 1;' %(emitter[1], pathToPreset) ) ## Now parent it try: cmds.parent(emitterGroup, 'nPARTICLE_EMITTERS_hrc') except: pass ## Connect the emitter to the particles debug(None, method = '_buildSideSplashEmitter', message = 'Connected %s: %s' % (splashParticleName, emitter[1]), verbose = False) for each in splashParticleName: _connect_NParticleShape_to_NParticleEmitter(particleShapeNode = each, emitter = emitter[1]) ## Now do the expression for the side emitter if 'IntersectCurveRight' in emitter[1]: direction = 'R' else: direction = 'L' expStringList = [ 'float $minSpeed = %s.minSpeed;\n' % sideAnimatable, 'float $maxSpeed = %s.maxSpeed;\n' % sideAnimatable, 'float $speed = %s:world_ctrl.speed;\n' % boatName, 'float $curve = smoothstep($minSpeed, $maxSpeed, $speed);\n', 'float $rateMuliplier = %s.rateMultiplier%s;\n' %(sideAnimatable, direction), 'float $splashMaxSpeed = %s.splashMaxSpeed%s;\n' %(sideAnimatable, direction), '\n', 'if (%s.useSpeed == 1)\n' % sideAnimatable, '{\n\t', '%s.rate = $rateMuliplier * $curve;\n' % emitter[1], '\n\t\t', 'float $emitterSpeed = $splashMaxSpeed * $curve;\n\t\t', 'if ($emitterSpeed == 0)\n\t\t', '{\n\t\t\t', '$emitterSpeed = 0.1;\n\t\t', '}\n\t\t', '%s.speed = $emitterSpeed;\n' % emitter[1], '}\n', 'else\n', '{\n\t', '%s.rate = $rateMuliplier;\n\t' % emitter[1], '%s.speed = $splashMaxSpeed;\n' % emitter[1], '}\n', ] ## Check if the expression already exists in the scene, if so delete it utils.checkExpressionExists('%s_sideSplashEmitter' % boatName) ## Build new expression cmds.expression(emitter[1], n = '%s_sideSplashEmitter' % emitter[1], string = utils.processExpressionString(expStringList)) ## Connect some attributes if not cmds.isConnected('%s.normalSpeed%s' %(sideAnimatable, direction), '%s.normalSpeed' % emitter[1]): cmds.connectAttr('%s.normalSpeed%s' %(sideAnimatable, direction), '%s.normalSpeed' % emitter[1]) if not cmds.isConnected('%s.randomSpeed%s' %(sideAnimatable, direction), '%s.speedRandom' % emitter[1]): cmds.connectAttr('%s.randomSpeed%s' %(sideAnimatable, direction), '%s.speedRandom' % emitter[1]) return cPoS
def _buildHullEmitter(boatName, constraint='', implicitSphere='', animatable=''): worldCtrl = boatName cmds.select(clear=True) ns = boatName.split(':')[0] newName = '%s_hullEmitter' % ns grpName = '%s_CONS_GRP' % newName offsetGrp = '%s_OFFSET_GRP' % newName debug(None, method='_buildHullEmitter', message='worldCtrl: %s' % worldCtrl, verbose=False) debug(None, method='_buildHullEmitter', message='ns: %s' % ns, verbose=False) debug(None, method='_buildHullEmitter', message='newName: %s' % newName, verbose=False) debug(None, method='_buildHullEmitter', message='grpName: %s' % grpName, verbose=False) debug(None, method='_buildHullEmitter', message='offsetGrp: %s' % offsetGrp, verbose=False) if not cmds.objExists(newName): cmds.select(clear=True) emitterName = _buildFluidEmitter(newName) if not cmds.objExists(offsetGrp): offsetGrp = cmds.group(emitterName, name=offsetGrp) if not cmds.objExists(grpName): grpName = cmds.group(offsetGrp, name=grpName) else: emitterName = [newName] ## Constraint stuffs if constraint: cmds.parentConstraint(constraint, grpName, maintainOffset=False, name='%s_fluidPointConstraint' % newName) else: cmds.parentConstraint('%scog_ctrl' % boatName.split('world_ctrl')[0], grpName, maintainOffset=False, name='%s_fluidPointConstraint' % newName) ## Presets from implicit sphere template if implicitSphere: cmds.delete( cmds.parentConstraint(implicitSphere, offsetGrp, maintainOffset=False)) cmds.delete( cmds.scaleConstraint(implicitSphere, offsetGrp, maintainOffset=False)) ## Now build the scene emitter group if not cmds.objExists('FLUID_EMITTERS_hrc'): cmds.group(name='FLUID_EMITTERS_hrc', empty=True) try: cmds.parent(grpName, 'FLUID_EMITTERS_hrc') except RuntimeError: pass ### FOR HULL EMITTERS ###################################### ## EMISSION RATE: Expression to tie emission rate to boat speed expStringList = [ 'float $minSpeed = %s.minSpeed;\n' % animatable, 'float $maxSpeed = %s.maxSpeed;\n' % animatable, 'float $speed = %s.speed;\n' % worldCtrl, 'float $curve = smoothstep($minSpeed, $maxSpeed, $speed);\n', 'float $rateMultiplier = %s.rearWakeMultiplier;\n' % animatable, 'float $idleRate = %s.rearWakeIdleMultiplier;\n' % animatable, '\n', 'if (%s.useSpeed == 1)\n' % animatable, '{\n\t', 'if ($speed < $minSpeed)\n\t', '{\n\t', '\t%s.rate = $idleRate;\n\t' % emitterName[0], '}\n\t', 'else\n\t', '{\n\t', '\t%s.rate = $rateMultiplier * $curve;\n\t' % emitterName[0], '}\n', '}\n', 'else\n', '{\n\t', '%s.rate = $rateMultiplier;\n' % emitterName[0], '}\n', ] debug(None, method='_buildHullEmitter', message='HULL expression: %s' % utils.processExpressionString(expStringList), verbose=False) ## Check if the expression already exists in the scene, if so delete it utils.checkExpressionExists('%s_emissionRate' % emitterName[0]) ## Build new expression cmds.expression(n='%s_emissionRate' % emitterName[0], string=utils.processExpressionString(expStringList)) ## Connect some attributes if not cmds.isConnected('%s.rearWakeDensity' % animatable, '%s.fluidDensityEmission' % emitterName[0]): cmds.connectAttr('%s.rearWakeDensity' % animatable, '%s.fluidDensityEmission' % emitterName[0]) if not cmds.isConnected('%s.rearWakeDropoff' % animatable, '%s.fluidDropoff' % emitterName[0]): cmds.connectAttr('%s.rearWakeDropoff' % animatable, '%s.fluidDropoff' % emitterName[0])
def _buildSideSplashEmitter(name='', boatName='', splashParticleName=[], boatIntersectCurveShape='', sideAnimatable='', presetName=None): """ New builder for sideSplash nParticle Emitter Checks if the NPARTICLE_EMITTLERS_hrc exists or not too @param name: The name of the new emitter @param splashParticleName: List of the names of nParticleShape nodes to connect to the emitter @param boatIntersectCurveShape: The name of the intersection curve to emit from. @type name: String @type splashParticleName: List @type boatIntersectCurveShape: String """ if not cmds.objExists('nPARTICLE_EMITTERS_hrc'): cmds.group(n='nPARTICLE_EMITTERS_hrc', em=True) debug(None, method='_buildSideSplashEmitter', message='name: %s' % name, verbose=False) # Get base flat surface lineCurve = cmds.curve(name='%s_extrudeCurve' % name, degree=1, point=[(-0.01, 0, 0), (0.01, 0, 0)]) flatSurface = cmds.extrude(lineCurve, boatIntersectCurveShape, name='%s_flatSurface' % name, constructionHistory=True, range=False, polygon=0, useComponentPivot=1, fixedPath=True, useProfileNormal=True, extrudeType=2, reverseSurfaceIfPathReversed=True)[0] cmds.rebuildSurface(flatSurface, constructionHistory=True, replaceOriginal=True, rebuildType=0, endKnots=1, keepCorners=False, spansU=1, degreeU=1, spansV=100, degreeV=3) # Offset upwards curve from surface offsetUp = cmds.offsetCurve('%s.u[0.5]' % flatSurface, name='%s_offsetUp' % name, distance=0, constructionHistory=True, range=0, subdivisionDensity=1)[0] cmds.rebuildCurve(offsetUp, constructionHistory=False, replaceOriginal=True, end=1, keepRange=0, keepControlPoints=True, degree=1) cmds.setAttr('%s.translateY' % offsetUp, 0.01) # Offset from upwards curve with distance and translate down to get the 45 degree angle offset_distance = -0.01 offsetOut = cmds.offsetCurve(offsetUp, name='%s_offsetOut' % name, distance=offset_distance, constructionHistory=True, range=0, subdivisionDensity=1)[0] cmds.setAttr('%s.translateY' % offsetOut, offset_distance) # Finally, loft a non-flipping surface solution (45 degree angle of the boat) noFlipSurface = cmds.loft(offsetUp, offsetOut, degree=1, constructionHistory=True, range=0, polygon=0, sectionSpans=1)[0] noFlipSurface = cmds.rename(noFlipSurface, '%s_noFlipSurface' % name) ## Build the emitter emitter = cmds.emitter(noFlipSurface, name='%s_emitter' % name, type='surface') # Create closestPointOnSurface for acceleration expression where front more acceleration cPoS = cmds.createNode('closestPointOnSurface', name='%s_cPoS' % name) cmds.connectAttr('%s.worldSpace' % noFlipSurface, '%s.inputSurface' % cPoS) ## Build the emitter group if it doesn't already exist emitterGroup = '%s_hrc' % name if not cmds.objExists(emitterGroup): cmds.group(lineCurve, flatSurface, offsetUp, offsetOut, noFlipSurface, emitter[0], n=emitterGroup) debug(None, method='_buildSideSplashEmitter', message='emitterName: %s' % emitter[1], verbose=False) ## Check if a custom preset has been assigned via the func flags for the emitter, if not use the default preset... if presetName: pathToPreset = '%s/%s' % (CONST.EMITTERBASEPRESETPATH, presetName) debug(None, method='_buildSideSplashEmitter', message='pathToPreset: %s' % pathToPreset, verbose=False) mel.eval('applyPresetToNode "%s" "" "" "%s" 1;' % (emitter[1], pathToPreset)) ## Now parent it try: cmds.parent(emitterGroup, 'nPARTICLE_EMITTERS_hrc') except: pass ## Connect the emitter to the particles debug(None, method='_buildSideSplashEmitter', message='Connected %s: %s' % (splashParticleName, emitter[1]), verbose=False) for each in splashParticleName: _connect_NParticleShape_to_NParticleEmitter(particleShapeNode=each, emitter=emitter[1]) ## Now do the expression for the side emitter if 'IntersectCurveRight' in emitter[1]: direction = 'R' else: direction = 'L' expStringList = [ 'float $minSpeed = %s.minSpeed;\n' % sideAnimatable, 'float $maxSpeed = %s.maxSpeed;\n' % sideAnimatable, 'float $speed = %s:world_ctrl.speed;\n' % boatName, 'float $curve = smoothstep($minSpeed, $maxSpeed, $speed);\n', 'float $rateMuliplier = %s.rateMultiplier%s;\n' % (sideAnimatable, direction), 'float $splashMaxSpeed = %s.splashMaxSpeed%s;\n' % (sideAnimatable, direction), '\n', 'if (%s.useSpeed == 1)\n' % sideAnimatable, '{\n\t', '%s.rate = $rateMuliplier * $curve;\n' % emitter[1], '\n\t\t', 'float $emitterSpeed = $splashMaxSpeed * $curve;\n\t\t', 'if ($emitterSpeed == 0)\n\t\t', '{\n\t\t\t', '$emitterSpeed = 0.1;\n\t\t', '}\n\t\t', '%s.speed = $emitterSpeed;\n' % emitter[1], '}\n', 'else\n', '{\n\t', '%s.rate = $rateMuliplier;\n\t' % emitter[1], '%s.speed = $splashMaxSpeed;\n' % emitter[1], '}\n', ] ## Check if the expression already exists in the scene, if so delete it utils.checkExpressionExists('%s_sideSplashEmitter' % boatName) ## Build new expression cmds.expression(emitter[1], n='%s_sideSplashEmitter' % emitter[1], string=utils.processExpressionString(expStringList)) ## Connect some attributes if not cmds.isConnected('%s.normalSpeed%s' % (sideAnimatable, direction), '%s.normalSpeed' % emitter[1]): cmds.connectAttr('%s.normalSpeed%s' % (sideAnimatable, direction), '%s.normalSpeed' % emitter[1]) if not cmds.isConnected('%s.randomSpeed%s' % (sideAnimatable, direction), '%s.speedRandom' % emitter[1]): cmds.connectAttr('%s.randomSpeed%s' % (sideAnimatable, direction), '%s.speedRandom' % emitter[1]) return cPoS
def _create_FOAM_FluidTexture(oceanShader='', size='', pathToPreset='', foamFluidShapeName=CONST.FOAM_FLUID_SHAPENODE): """ create a 3d fluid texture for FOAM, make it a 2d simulation and texture the foamOffset of the ocean shader with it's outAlpha. """ debug(None, method='fluids_lib._create_FOAM_FluidTexture', message='Building fluid %s' % foamFluidShapeName, verbose=False) fluidShape = cmds.shadingNode('fluidTexture3D', asTexture=True, name=foamFluidShapeName) # Get parent of shape and set attrs fluid = cmds.listRelatives(fluidShape, parent=True) _setBaseFluidAttrs(fluid) ## Connect to time cmds.connectAttr("time1.outTime", (fluidShape + ".currentTime")) debug(None, method='fluids_lib._create_FOAM_FluidTexture', message='%s connected to time1' % fluidShape, verbose=False) ## Apply foam preset mel.eval("""applyPresetToNode " """ + fluidShape + """ " "" "" "%s" 1;""" % pathToPreset) debug(None, method='fluids_lib._create_FOAM_FluidTexture', message='Mel preset applied: %s' % pathToPreset, verbose=False) #add expression to texture expStringList = [ "float $foamSpeed = 1.0;\n", "%s.textureTime = time * $foamSpeed;\n" % fluidShape ] utils.checkExpressionExists('s_foamTexture_Speed') cmds.expression(n='%s_foamTexture_Speed' % fluidShape, string=utils.processExpressionString(expStringList)) expStringList = [ 'int $width = %s.dimensionsW;\r\n' % fluidShape, 'int $height = %s.dimensionsH;\r\n' % fluidShape, 'if ($width>= $height)\r\n', '{\r\n', '%s.baseResolution = $width*2;\r\n' % fluidShape, '}\r\n', 'else\r\n', '{\r\n', '%s.baseResolution = $height*2;\r\n' % fluidShape, '}' ] #expression to maintain resolution/container size relationship cmds.expression(n='%s_foamTexture_ContainerSize' % fluidShape, string=utils.processExpressionString(expStringList)) debug(None, method='fluids_lib._create_FOAM_FluidTexture', message=' Expression %s_foamTexture_ContainerSize built' % fluidShape, verbose=False) baseTextureName = fluidShape.split('Shape')[0] cmds.rename(fluid[0], '%s' % baseTextureName) utils.createTypeTag(obj='%s' % baseTextureName, typeName='%s' % baseTextureName) debug(None, method='fluids_lib._create_FOAM_FluidTexture', message=' Rename and Tag successful..', verbose=False) ## Connect fluid to ocean shader cmds.connectAttr("%s.outAlpha" % fluidShape, "%s.foamOffset" % oceanShader, force=True) debug(None, method='fluids_lib._create_FOAM_FluidTexture', message=' Returning %s:' % fluidShape, verbose=False) return fluidShape
def _create_WAKE_FluidTexture(oceanShader='', size='', pathToPreset='', wakeFluidShapeName=CONST.WAKE_FLUID_SHAPENODE): """ Create a 3d fluid texture, make it a 2d simulation and texture the waveHeightOffset of the ocean shader with it's outAlpha. @param oceanShader: @param size: @type oceanShader: @type size: """ debug(None, method='_create_WAKE_FluidTexture', message='Building fluid %s' % wakeFluidShapeName, verbose=False) fluidShape = cmds.shadingNode('fluidTexture3D', asTexture=True, name=wakeFluidShapeName) # Get parent of shape and set attrs fluid = cmds.listRelatives(fluidShape, parent=True) _setBaseFluidAttrs(fluid) ## Connect to time cmds.connectAttr("time1.outTime", (fluidShape + ".currentTime")) debug(None, method='_create_WAKE_FluidTexture', message='%s connected to time1' % fluidShape, verbose=False) ## Apply wake preset mel.eval("""applyPresetToNode " """ + fluidShape + """ " "" "" "%s" 1;""" % pathToPreset) debug(None, method='_create_WAKE_FluidTexture', message='Mel preset applied: %s' % pathToPreset, verbose=False) #expression to maintain resolution/container size relationship expStringList = [ "int $width = %s.dimensionsW;\r\n" % fluidShape, 'int $height = %s.dimensionsH;\r\n' % fluidShape, 'if ($width>= $height)\r\n', '{\r\n', '%s.baseResolution = $width*4;\r\n' % fluidShape, '}\r\n', 'else\r\n', '{\r\n%s.baseResolution = $height*4;\r\n}' % fluidShape ] utils.checkExpressionExists('waterSurfaceFluidTexture') cmds.expression(n='waterSurfaceFluidTexture', string=utils.processExpressionString(expStringList)) debug(None, method='_create_WAKE_FluidTexture', message=' Expression %s_foamTexture_ContainerSize built' % fluidShape, verbose=False) baseTextureName = wakeFluidShapeName.split('Shape')[0] cmds.rename(fluid[0], '%s' % baseTextureName) utils.createTypeTag(obj='%s' % baseTextureName, typeName='%s' % baseTextureName) debug(None, method='_create_WAKE_FluidTexture', message=' Rename and Tag successful..', verbose=False) ## Connect new wake fluid tex to ocean cmds.connectAttr("%s.outAlpha" % wakeFluidShapeName, "%s.waveHeightOffset" % oceanShader, force=True) debug(None, method='_create_WAKE_FluidTexture', message=' Returning %s:' % fluidShape, verbose=False) return fluidShape
def _buildExpression(locShapeName, oceanLocName, oceanShader, boatName): ## Build the expression for the new locators. if ':' in oceanLocName and 'ADef' not in oceanLocName: finalLine = '%s.translateY = $cpoint[0] / %s:world_ctrl.oceanYDamp;' % (oceanLocName, boatName) else: if 'ADef' not in oceanLocName: if cmds.objExists('world_ctrl.oceanYDamp'): finalLine = '%s.translateY = $cpoint[0] / world_ctrl.oceanYDamp;' % oceanLocName else: finalLine = '%s.translateY = $cpoint[0] / %s:world_ctrl.oceanYDamp;' % (oceanLocName, boatName) else: print 'Processing expression for ASSEMBLY REFERENCE' finalLine = '%s.translateY = $cpoint[0] / %s_oceanCtrls_hrc.oceanYDamp;' % (oceanLocName, boatName) debug(None, method = '_buildExpression', message = 'finalLine: %s' % finalLine, verbose = False) expStringList= [ 'int $lastFrame = %s.lastFrame;\n' % locShapeName, 'int $startFrame = %s.startFrame;\n' % locShapeName, '%s.lastFrame = frame;\n' % locShapeName, 'if( frame <= $startFrame ){\n\t', 'if( $lastFrame == frame ){\n\t\t', '%s.startY = %s.translateY;\n\t\t' % (locShapeName, oceanLocName), '%s.startRotX = %s.rotateX;\n\t\t' % (locShapeName, oceanLocName), '%s.startRotZ = %s.rotateZ;\n\t' % (locShapeName, oceanLocName), '} else {\n\t\t', 'float $val = %s.startY;\n\t\t' % locShapeName, 'setAttr %s.ty $val;\n\t\t' % oceanLocName, '$val = %s.startRotX;\n\t\t' % locShapeName, 'setAttr %s.rx $val;\n\t\t' % oceanLocName, '$val = %s.startRotZ;\n\t\t' % locShapeName, 'setAttr %s.rz $val;\n\t' % oceanLocName, '}\n\t', '%s.velocity = 0.0;\n\t\t' % locShapeName, '%s.waterLevel = 0.0;\n\t\t' % locShapeName, '%s.rotVelX = 0.0;\n\t\t' % locShapeName, '%s.rotVelZ = 0.0;\n' % locShapeName, '} else if( frame > $lastFrame ){\n', 'float $u = %s.translateX;\n' % oceanLocName, 'float $v = %s.translateZ;\n' % oceanLocName, 'float $y = %s.translateY;\n' % oceanLocName, 'float $gravity = %s.gravity / %s.sceneScale;\n' % (locShapeName, locShapeName), 'float $dt = 0.006; //timestep value for 30 fps\n', 'float $height = %s.objectHeight;\n' % locShapeName, 'float $buoyancy = %s.buoyancy;\n' % locShapeName, 'if( $buoyancy > 0.98 ){\n\t', '$buoyancy = 0.98;\n' '}\n', 'float $waterDamp = %s.waterDamping;\n' % locShapeName, 'float $airDamp = %s.airDamping;\n' % locShapeName, 'float $turn = %s.rotateY;\n' % oceanLocName, 'float $rx = %s.rotateX;\n' % oceanLocName, 'float $rz = %s.rotateZ;\n' % oceanLocName, 'float $xoff = sin( deg_to_rad( $turn ));\n', 'float $zoff = cos( deg_to_rad( $turn ));\n', 'float $xwidth = %s.boatWidth * 0.4;\n' % locShapeName, 'float $zwidth = %s.boatLength * 0.4;\n' % locShapeName, 'float $rxgain = %s.roll;\n' % locShapeName, 'float $rzgain = %s.pitch;\n' % locShapeName, 'float $disp[] = `colorAtPoint -u $u -v $v -u (($u + $xoff)*$xwidth) -v (($v + $zoff)*$xwidth) -u (($u - $xoff)*$xwidth) -v (($v - $zoff)*$xwidth) -u (($u - $zoff)*$zwidth) -v (($v + $xoff)*$zwidth) -u (($u + $zoff)*$zwidth) -v (($v - $xoff)*$zwidth) %s`;\n' % oceanShader, 'float $wHeight = ($disp[0] * 2.0 + $disp[1] + $disp[2] + $disp[3] + $disp[4])/6.0;\n', 'float $zdiff = ($disp[1] - $disp[2])/$xwidth;', 'float $xdiff = ($disp[3] - $disp[4])/$zwidth;', 'float $rotVelX = %s.rotVelX;' % locShapeName, 'float $rotVelZ = %s.rotVelZ;' % locShapeName, 'float $newXVel = $rxgain *(($zdiff * -40.0 - $rx) * $waterDamp + $rotVelX * (1-$waterDamp));', 'float $newZVel = $rzgain *(($xdiff * -40.0 - $rz) * $waterDamp + $rotVelZ * (1-$waterDamp));', '%s.rotVelX = $newXVel;\n' % locShapeName, '%s.rotVelZ = $newZVel;\n' % locShapeName, 'float $vel = %s.velocity;\n' % locShapeName, 'float $waterVel = $wHeight - %s.waterLevel;\n' % locShapeName, '%s.waterLevel = $wHeight;\n' % locShapeName, 'float $aboveWater = (($y + $height/2) - $wHeight)/$height;\n', 'if( $aboveWater > 1.0 ){\n', '$aboveWater = 1.0;\n', '$waterVel = 0.0;\n', '}\n', 'else if( $aboveWater < 0.0 )\n', '{\n', '$aboveWater = 0.0;\n', '}\n', 'float $underWater = 1.0 - $aboveWater;\n', 'float $damp = $waterDamp * $underWater + $airDamp * $aboveWater;\n', 'float $force = $gravity * $dt *($underWater/(1-$buoyancy) - 1.0);\n', 'float $newVel = ($waterVel) * $damp + ($force+$vel)*(1-$damp);\n', '%s.velocity = $newVel;\n' % locShapeName, 'setAttr %s.rx ( $rx + $newXVel );\n' % oceanLocName, 'setAttr %s.rz ( $rz + $newZVel );\n' % oceanLocName, 'float $dummy = %s.displacement;\n' % oceanShader, '}\n\n', 'float $pu = %s.translateX;\n' % oceanLocName, 'float $pv = %s.translateZ;\n' % oceanLocName, 'float $cpoint[] = `colorAtPoint -u $pu -v $pv %s`;\n' % oceanShader, finalLine ] ## REMOVED 'setAttr %s.ty ( $y + $newVel );\n' % oceanLocName, ## Check if the expression already exists in the scene, if so delete it utils.checkExpressionExists('%s_boatLockToOcean' % boatName) ## Build new expression cmds.expression(n = '%s_boatLockToOcean' % boatName, string = utils.processExpressionString(expStringList)) debug(None, method = '_buildExpression', message = 'Expression built successfully', verbose = False)
def _buildBaseOceanSetup(editor, ocean_preset_template='', ocean_foam_template='', ocean_wake_template='', hiTide=False): """ Used to setup the base ocean for either FX or Animation. The is the base build for the ocean @param editor: The name of the current modelEditor in the scene to get the camera from @param ocean_preset_template: A valid shotgun template @param ocean_foam_template: A valid shotgun template @param ocean_wake_template: A valid shotgun template @param hiTide: If the scene is hi or low tide. Note this isn't being used at this time @type editor: String @type ocean_preset_template: A valid shotgun template @type ocean_foam_template: A valid shotgun template @type ocean_wake_template: A valid shotgun template @type hiTide: Boolean """ debug(None, method='_buildBaseOceanSetup', message='Entered...', verbose=False) debug(None, method='_buildBaseOceanSetup', message='_buildOceanGroups...', verbose=False) _buildOceanGroups() print if cmds.objExists('wakesOnOfMultiDiv'): cmds.delete('wakesOnOfMultiDiv') debug(None, method='_buildBaseOceanSetup', message='Removed wakesOnOfMultiDiv...', verbose=False) lowCond = 'OceanPrev_highRes_condition' hiCond = 'OceanPrev_lowRes_condition' resAddSub = 'OceanPrev_Res_addsubtract' anyOceans = cmds.ls(type="oceanShader") if not anyOceans: debug(None, method='_buildBaseOceanSetup', message='Creating new ocean...', verbose=False) _createOcean(editor, ocean_preset_template) else: debug(None, method='_buildBaseOceanSetup', message='Ocean already exists in scene: %s' % anyOceans, verbose=False) pass ## Now check the attrs for the ocean grp exist or not... debug(None, method='_buildBaseOceanSetup', message='Setting attrs fr OCEAN_hrc now...', verbose=False) try: cmds.setAttr("OCEAN_hrc.overrideEnabled", 1) except: pass try: cmds.setAttr("OCEAN_hrc.overrideDisplayType", 2) except: pass try: cmds.setAttr("OCEAN_hrc.translateY", lock=True, keyable=False) except: pass try: cmds.setAttr("OCEAN_hrc.rotateX", lock=True, keyable=False) except: pass try: cmds.setAttr("OCEAN_hrc.rotateY", lock=True, keyable=False) except: pass try: cmds.setAttr("OCEAN_hrc.rotateZ", lock=True, keyable=False) except: pass try: cmds.setAttr("OCEAN_hrc.scaleX", lock=True, keyable=False) except: pass try: cmds.setAttr("OCEAN_hrc.scaleY", lock=True, keyable=False) except: pass try: cmds.setAttr("OCEAN_hrc.scaleZ", lock=True, keyable=False) except: pass ## Now add an attr to OCEAN_hrc to handle the Res of the preview plane debug(None, method='_buildBaseOceanSetup', message='Setting attrs fr OCEAN_hrc.oceanRes now...', verbose=False) if not cmds.objExists("OCEAN_hrc.oceanRes"): cmds.addAttr('OCEAN_hrc', longName='oceanRes', attributeType='float', min=0, max=200, dv=50) cmds.setAttr('OCEAN_hrc.oceanRes', keyable=True) ## Now add an attr to OCEAN_hrc to handle the height of the of the tide to reference later in other scripts if not cmds.objExists("OCEAN_hrc.tideHeight"): cmds.addAttr('OCEAN_hrc', longName='tideHeight', attributeType='float', defaultValue=0) ## Now add expression to resolutions note animPlane gets its from the base ocean prev plane... expStringList = [ "oceanPreviewPlane_heightF.resolution = OCEAN_hrc.oceanRes;\n", ] utils.checkExpressionExists('oceanRes_exp') cmds.expression(n='oceanRes_exp', string=utils.processExpressionString(expStringList)) if hiTide: cmds.setAttr('OCEAN_hrc.tideHeight', 0) else: cmds.setAttr('OCEAN_hrc.tideHeight', .321) ## Now transfer the publish DISPocean preset from the ocean over to the animation ocean debug(None, method='_buildBaseOceanSetup', message='_connectAnimToDisp...', verbose=False) _connectAnimToDisp() print debug(None, method='_buildBaseOceanSetup', message='Base Ocean setup complete!', verbose=False)
def _setupSide_ParticleExpressions(particleShapeName='', type='splash', boatWorldCtrl='', boatName='', cPoS='', sideAnimatable=''): """ Setup the expressions for the sideEmitter's nParticleShape node @param particleShapeName: The name of the nParticleShape node @param boatWorldCtrl: The name of the boatWorldCtrl curve @param boatName: The name of the boat should be stripped : @type particleShapeName: String @type boatWorldCtrl: String @type boatName: String """ if type == 'splash': ############################ ## Creation expStringList = [ '%s.lifespanPP = rand(%s.lifespanMin, %s.lifespanMax);\n' % (particleShapeName, sideAnimatable, sideAnimatable), '%s.twistSpeedPP = rand(%s.twistSpeedMin, %s.twistSpeedMax);\n' % (particleShapeName, sideAnimatable, sideAnimatable), '%s.spriteStartSizePP = rand(%s.spriteStartSizeMin, %s.spriteStartSizeMax);\n' % (particleShapeName, sideAnimatable, sideAnimatable), '%s.spriteScaleYPP = %s.spriteScaleXPP = %s.spriteStartSizePP;\n' % (particleShapeName, particleShapeName, particleShapeName), '%s.spriteTwistPP = rand(%s.twistAngleMin, %s.twistAngleMax);\n' % (particleShapeName, sideAnimatable, sideAnimatable), ] ## Check if the expression already exists in the scene, if so delete it utils.checkExpressionExists('%s_sprite_settings' % particleShapeName) ## Build new expression cmds.dynExpression(particleShapeName, n="%s_sprite_settings" % particleShapeName, creation=True, string=utils.processExpressionString(expStringList)) ############################ ## Runtime Before Dynamics expStringList = [ '%s.spriteScaleYPP = %s.spriteScaleXPP = %s.spriteStartSizePP * %s.scaleOverLifeRamp;\n' % (particleShapeName, particleShapeName, particleShapeName, particleShapeName), '%s.spriteScaleXPP = %s.spriteScaleYPP;\n' % (particleShapeName, particleShapeName), '%s.spriteTwistPP += (%s.twistSpeedPP * %s.twistRateOverLife);\n' % (particleShapeName, particleShapeName, particleShapeName), '\n', ] ## Check if the expression already exists in the scene, if so delete it utils.checkExpressionExists('%s_sprite_settings' % particleShapeName) ## Build new expression cmds.dynExpression(particleShapeName, n="%s_sprite_settings" % particleShapeName, rbd=True, string=utils.processExpressionString(expStringList)) ## Connect some attrs to animatable group attrs = ['inheritFactor', 'conserve', 'drag', 'damp'] for att in attrs: if not cmds.isConnected('%s.%sSprite' % (sideAnimatable, att), '%s.%s' % (particleShapeName, att)): cmds.connectAttr('%s.%sSprite' % (sideAnimatable, att), '%s.%s' % (particleShapeName, att), force=True) elif type == 'mist': ## Creation expStringList = [ '%s.lifespanPP = rand(%s.lifespanMin, %s.lifespanMax);\n' % (particleShapeName, sideAnimatable, sideAnimatable), ] ## Check if the expression already exists in the scene, if so delete it utils.checkExpressionExists('%s_sprite_settings' % particleShapeName) ## Build new expression cmds.dynExpression(particleShapeName, n="%s_sprite_settings" % particleShapeName, creation=True, string=utils.processExpressionString(expStringList)) ## Connect some attrs to animatable group attrs = ['inheritFactor', 'conserve', 'drag', 'damp'] for att in attrs: if not cmds.isConnected('%s.%sMist' % (sideAnimatable, att), '%s.%s' % (particleShapeName, att)): cmds.connectAttr('%s.%sMist' % (sideAnimatable, att), '%s.%s' % (particleShapeName, att), force=True)