Example #1
0
	def slider_drag_callback(*args):
		if c.objExists('turb'):
			valueTurb = c.floatSliderGrp('snowTurbSlider', query=True, value=True);
			c.turbulence('turb', e=True, m=valueTurb);
		
		if c.objExists('snowEmitter'):
			valueSnowInt = c.floatSliderGrp('snowIntens', query=True, value=True);
			c.emitter('snowEmitter', e=True, r=valueSnowInt);
		
		if c.objExists('rainEmitter'):
			valueRainInt = c.floatSliderGrp('rainIntens', query=True, value=True);
			c.emitter('rainEmitter', e=True, r=valueRainInt);
			
		if c.objExists('air'):
			value2 = c.floatSliderGrp('airMSlider', query=True, value=True);
			value3 = c.floatSliderGrp('airMxdSlider', query=True, value=True);
			c.air('air', e=True, m=value2, mxd=value3);
Example #2
0
def turbulence(*args, **kwargs):
    res = cmds.turbulence(*args, **kwargs)
    if not kwargs.get('query', kwargs.get('q', False)):
        res = _factories.maybeConvert(res, _general.PyNode)
    # unpack create/edit list result
    if isinstance(res, list) and len(res) == 1 and not kwargs.get('query', kwargs.get('q', False)):
        res = res[0]
    return res
Example #3
0
	def init(WeatherUI,self):
		c.select(cl=True);
		c.turbulence(n='turb',m=1);
		c.air(n='air', m=30.0, mxd=20.0, pos=[20, 15, -40], vco=True);
		c.floatSliderGrp('snowTurbSlider', en=True, e=True);
		c.floatSliderGrp('airMSlider', en=True, e=True);
		c.floatSliderGrp('airMxdSlider', en=True, e=True);
		
		if c.objExists('snowParticle'):
			c.connectDynamic('snowParticle',f='turb');
		
		if c.objExists('snowParticle'):
			c.connectDynamic('snowParticle',f='air');
			
		if c.objExists('rainParticle'):
			c.connectDynamic('rainParticle',f='turb');
			
		if c.objExists('rainParticle'):
			c.connectDynamic('rainParticle',f='air');
Example #4
0
	def __init__(self, prefix, mesh):

		## Create ctrl for bubbles
		self.bubbleCtrlShape = cmds.createNode( 'implicitSphere', name = '%s_%sShape' % (prefix, self.BUBBLE_CTRL_NAME) )
		self.bubbleCtrl = cmds.listRelatives(self.bubbleCtrlShape, parent = True, fullPath = True)
		self.bubbleCtrl = cmds.rename( self.bubbleCtrl, '%s_%s' % (prefix, self.BUBBLE_CTRL_NAME) )
		self.bubbleCtrlGroup = cmds.group( self.bubbleCtrl, name = '%s_%s' % (prefix, self.BUBBLE_CTRL_OFFSET_GRP) )

		## Space locator with speed attribute
		self.speedLocator = cmds.spaceLocator( name = '%s_%s' % (prefix, self.LOCATOR_NAME) )[0]
		cmds.addAttr(self.speedLocator, longName = 'speed', attributeType = 'double')
		cmds.setAttr('%s.speed' % self.speedLocator, keyable = True)

		###################################################################################################

		## Creation
		self.bubble, self.bubbleShape = cmds.particle(name = '%s_%s' % (prefix, self.BUBBLE_NAME) )

		## Set presets
		for attr, val in self.BUBBLE_PRESET_ATTRS.iteritems():
			cmds.setAttr('%s.%s' % (self.bubbleShape, attr), val)

		## Create necessary PP attr and hook-up necsesary ramp info
		arrayMap, ramp = self.addAttrPP(particleShapeName = self.bubbleShape, attrPP = self.BUBBLE_ATTR_PP)

		## Emitter
		cmds.select(mesh, replace = True)
		self.bubbleEmitter = cmds.emitter(type = 'surface', rate = 100, sro = 0, nuv = 0, cye = 'none', cyi = 1, spd = 1, srn = 0, nsp = 1, tsp = 0, mxd = 0, mnd = 0, dx = 1, dy = 0, dz = 0, sp = 0)[1]
		# elif _TYPE == 'volume':
		#   cmds.select(clear = True)
		#   self.bubbleEmitter = cmds.emitter(pos = [0, 0, 0], type = 'volume', r = 100, sro = 0, nuv = 0, cye = 'none', cyi = 1, spd = 1, srn = 0, nsp = 1, tsp = 0, mxd = 0, mnd = 0, dx = 0, dy = 0, dz = 0, sp = 0, vsh = 'sphere', vof = [0, 0, 0], vsw = 360, tsr = 0.5, afc = 1, afx = 1, arx = 0, alx = 0, rnd = 0, drs = 0, ssz = 0)[0]
		#   cmds.setAttr('%s.scaleX' % self.bubbleEmitter, 0.2)
		#   cmds.setAttr('%s.scaleY' % self.bubbleEmitter, 0.2)
		#   cmds.setAttr('%s.scaleZ' % self.bubbleEmitter, 0.2)

		self.bubbleEmitter = cmds.rename(self.bubbleEmitter, '%s_%s' % (prefix, self.BUBBLE_EMITTER_NAME) )
		cmds.connectDynamic(self.bubbleShape, emitters = self.bubbleEmitter)

		###################################################################################################

		## Creation
		self.bubbleBurst, self.bubbleBurstShape = cmds.particle(name = '%s_%s' % (prefix, self.BUBBLEBURST_NAME) )

		## Set presets
		for attr, val in self.BUBBLEBURST_PRESET_ATTRS.iteritems():
			cmds.setAttr('%s.%s' % (self.bubbleBurstShape, attr), val)

		## Create necessary PP attr and hook-up necsesary ramp info
		self.addAttrPP(particleShapeName = self.bubbleBurstShape, attrPP = self.BUBBLEBURST_ATTR_PP)

		cmds.select(self.bubbleShape, replace = True)
		self.bubbleBurstEmitter = cmds.emitter(type = 'omni', rate = 100, sro = 0, nuv = 0, cye = 'none', cyi = 1, spd = 1, srn = 0, nsp = 1, tsp = 0, mxd = 0, mnd = 0, dx = 1, dy = 0, dz = 0, sp = 0)[1]
		self.bubbleBurstEmitter = cmds.rename(self.bubbleBurstEmitter, '%s_%s' % (prefix, self.BUBBLEBURST_EMITTER_NAME) )
		cmds.setAttr('%s.speed' % self.bubbleBurstEmitter, 0.4)
		cmds.addPP(self.bubbleBurstEmitter, attribute = 'rate')
		cmds.connectDynamic(self.bubbleBurstShape, emitters = self.bubbleBurstEmitter)

		###################################################################################################

		## Create necessary fields
		## Uniform Field
		self.uniformField = cmds.uniform(name = '%s_%s' % (prefix, self.UNIFORM_FIELD_NAME), pos = [0, 0, 0], m = 2.5, att = 0, dx = 0, dy = 2, dz = 0, mxd = -1, vsh = 'none', vex = 0, vof = [0, 0, 0], vsw = 360, tsr = 0.5)[0]

		## Turbulence Field
		self.turbulenceField = cmds.turbulence(name = '%s_%s' % (prefix, self.TURBULENCE_FIELD_NAME), pos = [0, 0, 0], m = 3, att = 0, f = 10, phaseX = 0, phaseY = 0, phaseZ = 0, noiseLevel = 0, noiseRatio = 0.707, mxd = -1, vsh = 'none', vex = 0, vof = [0, 0, 0], vsw = 360, tsr = 0.5)[0]

		## Radial Field
		self.radialField = cmds.radial(name = '%s_%s' % (prefix, self.RADIAL_FIELD_NAME), pos = [0, 0, 0], m = 2, att = 1, typ = 0, mxd = 20, vsh = 'sphere', vex = 0, vof = [0, 0, 0], vsw = 360, tsr = 0.5)[0]

		## Make necessary connections
		cmds.connectDynamic(self.bubbleShape, fields = self.uniformField)
		cmds.connectDynamic(self.bubbleBurstShape, fields = self.uniformField)
		cmds.connectDynamic(self.bubbleShape, fields = self.turbulenceField)
		cmds.connectDynamic(self.bubbleBurstShape, fields = self.turbulenceField)
		cmds.connectDynamic(self.bubbleShape, fields = self.radialField)
		cmds.connectDynamic(self.bubbleBurstShape, fields = self.radialField)

		###################################################################################################

		self.bubbleGroup = cmds.group(self.bubbleCtrlGroup, self.bubble, self.bubbleBurst, self.uniformField, self.turbulenceField, self.radialField, self.bubbleEmitter, self.bubbleBurstEmitter, self.speedLocator, name = '%s_%s' % (prefix, self.BUBBLE_GROUP_NAME) )
		cmds.parent(self.bubbleEmitter, self.speedLocator)
		cmds.pointConstraint(self.bubbleCtrl, self.speedLocator, maintainOffset = False)
		cmds.pointConstraint(cmds.listRelatives(mesh, parent = True, fullPath = True)[0], self.bubbleCtrlGroup, maintainOffset = False)
		cmds.setAttr('%s.scaleX' % self.radialField, 3.165)
		cmds.setAttr('%s.scaleY' % self.radialField, 3.165)
		cmds.setAttr('%s.scaleZ' % self.radialField, 3.165)

		attr = {'longName':'speed', 'niceName':' ', 'attributeType':'enum', 'enumName':'Speed:', 'keyable':False}
		self.add_custom_attrs(self.bubbleCtrl, **attr)
		attr = {'longName':'minSpeed', 'attributeType':'double', 'defaultValue':0.01, 'min':0}
		self.add_custom_attrs(self.bubbleCtrl, **attr)
		attr = {'longName':'maxSpeed', 'attributeType':'double', 'defaultValue':20}
		self.add_custom_attrs(self.bubbleCtrl, **attr)
		attr = {'longName':'useSpeed', 'niceName':'Use Speed', 'attributeType':'bool', 'defaultValue':0}
		self.add_custom_attrs(self.bubbleCtrl, **attr)

		attr = {'longName':'emitters', 'niceName':' ', 'attributeType':'enum', 'enumName':'Emitters:', 'keyable':False}
		self.add_custom_attrs(self.bubbleCtrl, **attr)
		attr = {'longName':'rate', 'niceName':'Rate', 'attributeType':'double', 'defaultValue':20, 'min':0}
		self.add_custom_attrs(self.bubbleCtrl, **attr)
		attr = {'longName':'splashMaxSpeed', 'niceName':'Splash Max Speed', 'attributeType':'double', 'defaultValue':0.1}
		self.add_custom_attrs(self.bubbleCtrl, **attr)
		attr = {'longName':'directionalSpeed', 'niceName':'Directional Speed', 'attributeType':'double', 'defaultValue':0}
		self.add_custom_attrs(self.bubbleCtrl, **attr)
		attr = {'longName':'randomDirection', 'niceName':'Random Direction', 'attributeType':'double', 'defaultValue':0}
		self.add_custom_attrs(self.bubbleCtrl, **attr)

		attr = {'longName':'burstAttr', 'niceName':' ', 'attributeType':'enum', 'enumName':'Burst Attrs:', 'keyable':False}
		self.add_custom_attrs(self.bubbleCtrl, **attr)
		attr = {'longName':'popVelocity', 'niceName':'Pop Velocity', 'attributeType':'double', 'defaultValue':1}
		self.add_custom_attrs(self.bubbleCtrl, **attr)
		attr = {'longName':'burstSizeMin', 'niceName':'Size Min', 'attributeType':'double', 'defaultValue':0.01, 'min':0}
		self.add_custom_attrs(self.bubbleCtrl, **attr)
		attr = {'longName':'burstSizeMax', 'niceName':'Size Max', 'attributeType':'double', 'defaultValue':0.1, 'min':0}
		self.add_custom_attrs(self.bubbleCtrl, **attr)
		attr = {'longName':'burstLifespanMin', 'niceName':'Lifespan Min', 'attributeType':'double', 'defaultValue':1, 'min':-1}
		self.add_custom_attrs(self.bubbleCtrl, **attr)
		attr = {'longName':'burstLifespanMax', 'niceName':'Lifespan Max', 'attributeType':'double', 'defaultValue':2, 'min':-1}
		self.add_custom_attrs(self.bubbleCtrl, **attr)

		attr = {'longName':'bubbleAttr', 'niceName':' ', 'attributeType':'enum', 'enumName':'Bubble Attrs', 'keyable':False}
		self.add_custom_attrs(self.bubbleCtrl, **attr)
		attr = {'longName':'bubbleSizeMin', 'niceName':'Size Min', 'attributeType':'double', 'defaultValue':0.2, 'min':0}
		self.add_custom_attrs(self.bubbleCtrl, **attr)
		attr = {'longName':'bubbleSizeMax', 'niceName':'Size Max', 'attributeType':'double', 'defaultValue':0.4, 'min':0}
		self.add_custom_attrs(self.bubbleCtrl, **attr)
		attr = {'longName':'lifespanMin', 'niceName':'Lifespan Min', 'attributeType':'double', 'defaultValue':2, 'min':-1}
		self.add_custom_attrs(self.bubbleCtrl, **attr)
		attr = {'longName':'lifespanMax', 'niceName':'Lifespan Max', 'attributeType':'double', 'defaultValue':4, 'min':-1}
		self.add_custom_attrs(self.bubbleCtrl, **attr)

		attr = {'longName':'killField', 'niceName':' ', 'attributeType':'enum', 'enumName':'Kill Field:', 'keyable':False}
		self.add_custom_attrs(self.bubbleCtrl, **attr)
		attr = {'longName':'killHeight', 'niceName':'Kill Height', 'attributeType':'double', 'defaultValue':-0.1}
		self.add_custom_attrs(self.bubbleCtrl, **attr)

		###################################################################################################

		## Locator speed expression
		expStringList = [
						'float $time;',
						'float $trx;',
						'float $try;',
						'float $trz;',
						'float $dx = %s.translateX - $trx;' % self.speedLocator,
						'float $dy = %s.translateY - $try;' % self.speedLocator,
						'float $dz = %s.translateZ - $trz;' % self.speedLocator,
						'float $d = sqrt( ($dx * $dx) + ($dy * $dy) + ($dz * $dz) );',
						'%s.speed = abs( $d / ( time - ($time + 0.001) ) );' % self.speedLocator,
						'$trx = %s.translateX;' % self.speedLocator,
						'$try = %s.translateY;' % self.speedLocator,
						'$trz = %s.translateZ;' % self.speedLocator,
						'$time = time;'
						]
		expString = self.processExpressionString(expStringList)
		cmds.expression(self.speedLocator, string = expString)

		## Bubbles Creation Expression
		expStringList = [
						'%s.lifespanPP = rand(%s.lifespanMin, %s.lifespanMax);' %(self.bubbleShape, self.bubbleCtrl, self.bubbleCtrl)
						]
		expString = self.processExpressionString(expStringList)
		cmds.dynExpression(self.bubbleShape, string = expString, creation = True)

		## Bubbles Runtime After Dynamics
		expStringList = [
						'vector $vel = %s.velocity;' % self.bubbleShape,
						'vector $kill = %s.position;' % self.bubbleShape,
						'float $popVel = %s.popVelocity;' % self.bubbleCtrl,
						'float $age = %s.age;' % self.bubbleShape,
						'',
						'if ( $kill.y > %s.killHeight )' % self.bubbleCtrl,
						'{',
						'   %s.lifespanPP = 0;' % self.bubbleShape,
						'}',
						'',
						'if ($vel.y >=  $popVel)',
						'{',
						'   %s.lifespanPP = 0;' % self.bubbleShape,
						'   %s.%s_emitterRatePP = 100;' % (self.bubbleShape, '_'.join(self.bubbleBurst.split('_')[0:-1])),
						'}',
						]
		expString = self.processExpressionString(expStringList)
		cmds.dynExpression(self.bubbleShape, string = expString, runtimeAfterDynamics = True)

		## Bubble Bursts Creation Expression
		expStringList = [
						'%s.lifespanPP = rand(%s.burstLifespanMin, %s.burstLifespanMax);' %(self.bubbleBurstShape, self.bubbleCtrl, self.bubbleCtrl),
						'%s.radiusPP = rand(%s.burstSizeMin, %s.burstSizeMax)' % (self.bubbleBurstShape, self.bubbleCtrl, self.bubbleCtrl),
						]
		expString = self.processExpressionString(expStringList)
		cmds.dynExpression(self.bubbleBurstShape, string = expString, creation = True)

		## Bubble Bursts Runtime After Dynamics Expression
		expStringList = [
						'vector $kill = %s.position;' % self.bubbleBurstShape,
						'',
						'if ($kill.y > %s.killHeight)' % self.bubbleCtrl,
						'{',
						'   %s.lifespanPP = 0;' % self.bubbleBurstShape,
						'}',
						]
		expString = self.processExpressionString(expStringList)
		cmds.dynExpression(self.bubbleBurstShape, string = expString, runtimeAfterDynamics = True)

		## Expression for Turbulence Field
		expStringList = [
						'%s.phaseX = time;' % self.turbulenceField,
						'%s.phaseY = time;' % self.turbulenceField,
						'%s.phaseZ = time;' % self.turbulenceField,
						]
		expString = self.processExpressionString(expStringList)
		cmds.expression(self.turbulenceField, string = expString)

		## Expression for Bubble Emitter
		expStringList = [
						'float $minSpeed = %s.minSpeed;' % self.bubbleCtrl,
						'float $maxSpeed = %s.maxSpeed;' % self.bubbleCtrl,
						'float $speed = %s.speed;' % self.speedLocator,
						'float $curve = smoothstep($minSpeed, $maxSpeed, $speed);',
						'float $rateMuliplier = %s.rate;' % self.bubbleCtrl,
						'float $splashMaxSpeed = %s.splashMaxSpeed;' % self.bubbleCtrl,
						'',
						'if (%s.useSpeed == 1)' % self.bubbleCtrl,
						'{',
						'   %s.rate = $rateMuliplier * $curve;' % self.bubbleEmitter,
						'',
						'   float $emitterSpeed = $splashMaxSpeed * $curve;',
						'   if ($emitterSpeed == 0)',
						'   {',
						'       $emitterSpeed = 0.1;',
						'   }',
						'   %s.awayFromCenter = $emitterSpeed;' % self.bubbleEmitter,
						'}',
						'else',
						'{',
						'   %s.rate = $rateMuliplier;' % self.bubbleEmitter,
						'   %s.awayFromCenter = $splashMaxSpeed;' % self.bubbleEmitter,
						'}',
						'%s.alongAxis = %s.directionalSpeed;' % (self.bubbleEmitter, self.bubbleCtrl),
						'%s.randomDirection = %s.randomDirection;' % (self.bubbleEmitter, self.bubbleCtrl),
						]
		expString = self.processExpressionString(expStringList)
		cmds.expression(self.bubbleEmitter, string = expString)

		###################################################################################################

		## Finalizing stuffs
		cmds.connectAttr('%s.bubbleSizeMin' % self.bubbleCtrl, '%s.minValue' % arrayMap)
		cmds.connectAttr('%s.bubbleSizeMax' % self.bubbleCtrl, '%s.maxValue' % arrayMap)

		###################################################################################################

		## Assigning shader
		self.bubbleShader(particleShapeName = [self.bubbleShape, self.bubbleBurstShape])
    def create_rain(self, *args):
        # Create the initial rain surface
        rainSurface = cmds.polyPlane(n="rainSurface", sx=10, sy=10, width=10, height=10)
        cmds.move(10, "rainSurface", y=True)

        # Create the emitter and particles
        rate = self.get_float_value(self.rain_rate)
        _emitter = cmds.emitter(type='omni', r=rate, sro=False)
        emitterName = _emitter[1]
        particleName, particleShape = cmds.particle()

        cmds.select(emitterName)
        emitterConnect = cmds.connectDynamic(particleName, em=emitterName)
        cmds.setAttr(emitterName+".emitterType", 2)

        # Set particle attributes
        cmds.setAttr(particleShape+".lifespanMode", 2)
        cmds.setAttr(particleShape+".lifespanRandom", 5)

        # Select particle for gravity field creation
        cmds.select(particleName)

        _gravity = cmds.gravity(pos=(0,0,0), m=9.8)
        #print _gravity
        gravityName = _gravity[0]

        gravityConnect = cmds.connectDynamic(particleName, f=gravityName)

        # Change particle render type
        cmds.setAttr(particleShape + ".particleRenderType", 6)

        # Create turbulence field
        cmds.select(particleName)
        _turbulence = cmds.turbulence()
        turbulenceName = _turbulence[1]
        cmds.connectDynamic(particleShape, f=turbulenceName)
        turb_magnitude = self.get_float_value(self.turbulence_magnitude)
        cmds.setAttr(turbulenceName+".magnitude", turb_magnitude)
        cmds.setAttr(turbulenceName+".attenuation", 0) # Attenuation at 0 for
        cmds.setAttr(turbulenceName+".frequency", 50)

        # Create vortex field
        cmds.select(particleName)
        vortex = cmds.vortex()
        vortexName = vortex[1]
        vortexConnect = cmds.connectDynamic(particleShape,f=vortexName)

        vort_magnitude = self.get_float_value(self.vortex_magnitude)
        print vort_magnitude

        # Update Vortex Attributes
        cmds.setAttr(vortexName+".magnitude",  vort_magnitude)

        # Make raindrops past the bounds of the surface plane
        cmds.setAttr(emitterName+".minDistance", 1)
        cmds.setAttr(emitterName+".maxDistance", 1)

        # Set raindrops speed
        cmds.setAttr(emitterName+".speedRandom", 0.9)
        cmds.setAttr(emitterName+".tangentSpeed", 1.5)

        wind_speed = self.get_float_value(self.rain_speed)
        cmds.setAttr(emitterName+".speed", wind_speed)

        print "Raindrops speed added."
        # Create surface for collisions (should be selected in the beginning, if not, a new surface will be created)
        #if self.selected_surface is None:
        groundName, groundShape = cmds.polyPlane(n="groundSurface", sx=10, sy=10, width=25, height=25)

        # Set resilience
        resilience = self.get_float_value(self.surface_resilience)
        cmds.select(particleName, r=True)
        cmds.select(groundName, add=True)
        cmds.collision(groundName, particleName, r=resilience)
        cmds.connectDynamic(particleName, c=groundName)
        print "Collisions added."

        # Split the raindrops on collision
        splitName, splitShape = cmds.particle(inherit=0.5, name="splitParticle")
        #print splitName, splitShape

        cmds.event(particleName, split=3, t=splitShape, spread=0.5, random=False)
        cmds.setAttr(splitShape+".inheritFactor", 0.5)
        print "Raindrop splits added."

        # Add the gravity field to newly split particles
        cmds.select(gravityName, r=True)
        cmds.select(splitShape, add=True)
        cmds.connectDynamic(splitShape, f=gravityName)
        print "Gravity field added."
    def create_rain(self, *args):
        # Create the initial rain surface
        rainSurface = cmds.polyPlane(n="rainSurface",
                                     sx=10,
                                     sy=10,
                                     width=10,
                                     height=10)
        cmds.move(10, "rainSurface", y=True)

        # Create the emitter and particles
        rate = self.get_float_value(self.rain_rate)
        _emitter = cmds.emitter(type='omni', r=rate, sro=False)
        emitterName = _emitter[1]
        particleName, particleShape = cmds.particle()

        cmds.select(emitterName)
        emitterConnect = cmds.connectDynamic(particleName, em=emitterName)
        cmds.setAttr(emitterName + ".emitterType", 2)

        # Set particle attributes
        cmds.setAttr(particleShape + ".lifespanMode", 2)
        cmds.setAttr(particleShape + ".lifespanRandom", 5)

        # Select particle for gravity field creation
        cmds.select(particleName)

        _gravity = cmds.gravity(pos=(0, 0, 0), m=9.8)
        #print _gravity
        gravityName = _gravity[0]

        gravityConnect = cmds.connectDynamic(particleName, f=gravityName)

        # Change particle render type
        cmds.setAttr(particleShape + ".particleRenderType", 6)

        # Create turbulence field
        cmds.select(particleName)
        _turbulence = cmds.turbulence()
        turbulenceName = _turbulence[1]
        cmds.connectDynamic(particleShape, f=turbulenceName)
        turb_magnitude = self.get_float_value(self.turbulence_magnitude)
        cmds.setAttr(turbulenceName + ".magnitude", turb_magnitude)
        cmds.setAttr(turbulenceName + ".attenuation",
                     0)  # Attenuation at 0 for
        cmds.setAttr(turbulenceName + ".frequency", 50)

        # Create vortex field
        cmds.select(particleName)
        vortex = cmds.vortex()
        vortexName = vortex[1]
        vortexConnect = cmds.connectDynamic(particleShape, f=vortexName)

        vort_magnitude = self.get_float_value(self.vortex_magnitude)
        print vort_magnitude

        # Update Vortex Attributes
        cmds.setAttr(vortexName + ".magnitude", vort_magnitude)

        # Make raindrops past the bounds of the surface plane
        cmds.setAttr(emitterName + ".minDistance", 1)
        cmds.setAttr(emitterName + ".maxDistance", 1)

        # Set raindrops speed
        cmds.setAttr(emitterName + ".speedRandom", 0.9)
        cmds.setAttr(emitterName + ".tangentSpeed", 1.5)

        wind_speed = self.get_float_value(self.rain_speed)
        cmds.setAttr(emitterName + ".speed", wind_speed)

        print "Raindrops speed added."
        # Create surface for collisions (should be selected in the beginning, if not, a new surface will be created)
        #if self.selected_surface is None:
        groundName, groundShape = cmds.polyPlane(n="groundSurface",
                                                 sx=10,
                                                 sy=10,
                                                 width=25,
                                                 height=25)

        # Set resilience
        resilience = self.get_float_value(self.surface_resilience)
        cmds.select(particleName, r=True)
        cmds.select(groundName, add=True)
        cmds.collision(groundName, particleName, r=resilience)
        cmds.connectDynamic(particleName, c=groundName)
        print "Collisions added."

        # Split the raindrops on collision
        splitName, splitShape = cmds.particle(inherit=0.5,
                                              name="splitParticle")
        #print splitName, splitShape

        cmds.event(particleName,
                   split=3,
                   t=splitShape,
                   spread=0.5,
                   random=False)
        cmds.setAttr(splitShape + ".inheritFactor", 0.5)
        print "Raindrop splits added."

        # Add the gravity field to newly split particles
        cmds.select(gravityName, r=True)
        cmds.select(splitShape, add=True)
        cmds.connectDynamic(splitShape, f=gravityName)
        print "Gravity field added."
Example #7
0
    def doIt(self, args):
        # Procesar argumentos
        try:
            self.parseArgs(args)
        except Exception as e:
            print('[' + commandName + '] Sintaxis de flag invalida')
            return

        # Guardar seleccion de la superficie
        surface = cmds.ls(sl=True)

        ################################# Control maestro ###############################
        cmds.spaceLocator(name=self.controllerName)
        cmds.addAttr(ln='floor', at='double', defaultValue=self.floor)
        cmds.addAttr(ln='beginTolerance',
                     at='double',
                     defaultValue=0.3,
                     minValue=0,
                     maxValue=1)
        cmds.addAttr(ln='gravity', at='double', defaultValue=self.gravity)
        cmds.addAttr(ln='magnitudeTLow',
                     at='double',
                     defaultValue=self.turbulenceLow)
        cmds.addAttr(ln='magnitudeTHigh',
                     at='double',
                     defaultValue=self.turbulenceHigh)
        cmds.addAttr(ln='dewRate',
                     at='double',
                     defaultValue=self.dewRate,
                     minValue=0)
        cmds.addAttr(ln='spumeRate',
                     at='double',
                     defaultValue=self.spumeRate,
                     minValue=0)
        cmds.addAttr(ln='waterRate',
                     at='double',
                     defaultValue=self.waterRate,
                     minValue=0)
        cmds.setAttr(self.controllerName + '.translateX', keyable=False)
        cmds.setAttr(self.controllerName + '.translateY', keyable=False)
        cmds.setAttr(self.controllerName + '.translateZ', keyable=False)
        cmds.setAttr(self.controllerName + '.rotateX', keyable=False)
        cmds.setAttr(self.controllerName + '.rotateY', keyable=False)
        cmds.setAttr(self.controllerName + '.rotateZ', keyable=False)
        cmds.setAttr(self.controllerName + '.scaleX', keyable=False)
        cmds.setAttr(self.controllerName + '.scaleY', keyable=False)
        cmds.setAttr(self.controllerName + '.scaleZ', keyable=False)
        cmds.setAttr(self.controllerName + '.floor', keyable=True)
        cmds.setAttr(self.controllerName + '.beginTolerance', keyable=True)
        cmds.setAttr(self.controllerName + '.gravity', keyable=True)
        cmds.setAttr(self.controllerName + '.magnitudeTLow', keyable=True)
        cmds.setAttr(self.controllerName + '.magnitudeTHigh', keyable=True)
        cmds.setAttr(self.controllerName + '.dewRate', keyable=True)
        cmds.setAttr(self.controllerName + '.spumeRate', keyable=True)
        cmds.setAttr(self.controllerName + '.waterRate', keyable=True)

        ################################ Campos de fuerza ###############################
        cmds.select(clear=True)
        cmds.gravity(name=self.gravityName, att=0, dx=0, dy=-1, dz=0)
        cmds.connectAttr(self.controllerName + '.gravity',
                         self.gravityName + '.magnitude')

        cmds.select(clear=True)
        cmds.turbulence(name=self.turbulenceLowName, att=0, f=0.8, nsr=0.6)
        cmds.expression(
            s=
            "phaseX = rand(1,100)*10;\nphaseY = rand(1,100)*20;\nphaseZ = rand(1,100)*30;",
            o=self.turbulenceLowName,
            alwaysEvaluate=1)
        cmds.connectAttr(self.controllerName + '.magnitudeTLow',
                         self.turbulenceLowName + '.magnitude')

        cmds.select(clear=True)
        cmds.turbulence(name=self.turbulenceHighName, att=0, f=0.8, nsr=0.7)
        cmds.expression(
            s=
            "phaseX = time*135.165;\nphaseY = time+10*135.165;\nphaseZ = time+767*135.165;",
            o=self.turbulenceHighName,
            alwaysEvaluate=1)
        cmds.connectAttr(self.controllerName + '.magnitudeTHigh',
                         self.turbulenceHighName + '.magnitude')

        ##################################### Gotas #####################################
        # Crear sistema y emisor
        cmds.select(surface)

        cmds.emitter(n=self.dewEmitterName, type='surface', rate=self.dewRate)
        cmds.particle(n=self.dewSystemName)
        cmds.connectDynamic(self.dewSystemShapeName, em=self.dewEmitterName)
        cmds.connectAttr(self.controllerName + '.dewRate',
                         self.dewEmitterName + '.rate')

        # Agregar goal entre superficie y sistema
        cmds.select(self.dewSystemName, r=True)
        cmds.select(surface, add=True)
        cmds.goal(self.dewSystemName, g=surface, w=1, utr=0)

        cmds.connectDynamic(self.dewSystemName, f=self.gravityName)
        cmds.connectDynamic(self.dewSystemName, f=self.turbulenceLowName)
        cmds.connectDynamic(self.dewSystemName, f=self.turbulenceHighName)

        # Setear valores
        cmds.setAttr(self.dewSystemShapeName + ".conserve", 0.98)
        cmds.setAttr(self.dewSystemShapeName + ".lifespanMode",
                     3)  # only LifespanPP
        cmds.setAttr(self.dewSystemShapeName + ".particleRenderType",
                     3)  # points
        cmds.select(self.dewSystemShapeName)
        cmds.addAttr(ln='goalU', dt='doubleArray')
        cmds.addAttr(ln='goalU0', dt='doubleArray')
        cmds.addAttr(ln='goalV', dt='doubleArray')
        cmds.addAttr(ln='goalV0', dt='doubleArray')
        cmds.addAttr(ln='opacityPP', dt='doubleArray')
        cmds.addAttr(ln='opacityPP0', dt='doubleArray')
        cmds.dynExpression(self.dewSystemShapeName,
                           s="goalV = 0;\ngoalU = rand(1);\nopacityPP = 0;",
                           c=1)
        cmds.dynExpression(
            self.dewSystemShapeName,
            s="goalV += rand(0.1);\nif (goalV > " + self.controllerName +
            ".beginTolerance){\n\topacityPP = 1;\n}\nif (goalV > 0.99){\n\tgoalPP = 0;\n\tvector $pos = position;\n\tif ($pos.y < "
            + self.controllerName + ".floor){\n\t\tlifespanPP = 0;\n\t}\n}",
            rbd=1)

        ##################################### Espuma ####################################
        # Crear sistema y emisor
        cmds.select(surface)

        cmds.emitter(n=self.spumeEmitterName,
                     type='surface',
                     rate=self.spumeRate)
        cmds.particle(n=self.spumeSystemName)
        cmds.connectDynamic(self.spumeSystemShapeName,
                            em=self.spumeEmitterName)
        cmds.connectAttr(self.controllerName + '.spumeRate',
                         self.spumeEmitterName + '.rate')

        # Agregar goal entre superficie y sistema
        cmds.select(self.spumeSystemName, r=True)
        cmds.select(surface, add=True)
        cmds.goal(self.spumeSystemName, g=surface, w=1, utr=0)

        cmds.connectDynamic(self.spumeSystemName, f=self.gravityName)
        cmds.connectDynamic(self.spumeSystemName, f=self.turbulenceLowName)
        cmds.connectDynamic(self.spumeSystemName, f=self.turbulenceHighName)

        # Setear valores
        cmds.setAttr(self.spumeSystemShapeName + ".conserve", 0.98)
        cmds.setAttr(self.spumeSystemShapeName + ".lifespanMode",
                     3)  # only LifespanPP
        cmds.setAttr(self.spumeSystemShapeName + ".particleRenderType",
                     6)  # streaks
        cmds.select(self.spumeSystemShapeName)
        cmds.addAttr(ln='goalU', dt='doubleArray')
        cmds.addAttr(ln='goalU0', dt='doubleArray')
        cmds.addAttr(ln='goalV', dt='doubleArray')
        cmds.addAttr(ln='goalV0', dt='doubleArray')
        cmds.addAttr(ln='opacityPP', dt='doubleArray')
        cmds.addAttr(ln='opacityPP0', dt='doubleArray')
        cmds.dynExpression(self.spumeSystemShapeName,
                           s="goalV = 0;\ngoalU = rand(1);\nopacityPP = 0;",
                           c=1)
        cmds.dynExpression(
            self.spumeSystemShapeName,
            s="goalV += rand(0.1);\nif (goalV > " + self.controllerName +
            ".beginTolerance){\n\topacityPP = 1;\n}\nif (goalV > 0.99){\n\tgoalPP = 0;\n\tvector $pos = position;\n\tif ($pos.y < "
            + self.controllerName + ".floor){\n\t\tlifespanPP = 0;\n\t}\n}",
            rbd=1)

        ###################################### Agua #####################################
        # Crear sistema y emisor
        cmds.select(surface)

        cmds.emitter(n=self.waterEmitterName,
                     type='surface',
                     rate=self.waterRate)
        cmds.particle(n=self.waterSystemName)
        cmds.connectDynamic(self.waterSystemShapeName,
                            em=self.waterEmitterName)
        cmds.connectAttr(self.controllerName + '.waterRate',
                         self.waterEmitterName + '.rate')

        # Agregar goal entre superficie y sistema
        cmds.select(self.waterSystemName, r=True)
        cmds.select(surface, add=True)
        cmds.goal(self.waterSystemName, g=surface, w=1, utr=0)

        cmds.connectDynamic(self.waterSystemName, f=self.gravityName)
        cmds.connectDynamic(self.waterSystemName, f=self.turbulenceLowName)
        cmds.connectDynamic(self.waterSystemName, f=self.turbulenceHighName)

        # Setear valores
        cmds.setAttr(self.waterSystemShapeName + ".conserve", 0.98)
        cmds.setAttr(self.waterSystemShapeName + ".lifespanMode",
                     3)  # only LifespanPP
        cmds.setAttr(self.waterSystemShapeName + ".particleRenderType",
                     7)  # Bubble
        cmds.select(self.waterSystemShapeName)
        cmds.addAttr(ln='threshold',
                     at='float',
                     defaultValue=0.75,
                     minValue=0,
                     maxValue=10)
        #cmds.addAttr(ln='radius',at='float',defaultValue=0.75,minValue=0,maxValue=20)
        cmds.addAttr(ln='radiusPP', dt='doubleArray')
        cmds.addAttr(ln='radiusPP0', dt='doubleArray')
        cmds.setAttr(self.waterSystemShapeName + ".threshold", 0.75)
        cmds.select(self.waterSystemShapeName)
        cmds.addAttr(ln='goalU', dt='doubleArray')
        cmds.addAttr(ln='goalU0', dt='doubleArray')
        cmds.addAttr(ln='goalV', dt='doubleArray')
        cmds.addAttr(ln='goalV0', dt='doubleArray')
        cmds.dynExpression(
            self.waterSystemShapeName,
            s=
            "goalV = 0;\ngoalU = rand(1);\nif (rand(1) < 0.25){\n\tradiusPP = rand(0.7);\n} else {\n\tradiusPP = rand(1,2);\n}",
            c=1)
        cmds.dynExpression(
            self.waterSystemShapeName,
            s="goalV += rand(0.1);\nif (goalV > 0.99){\n\tgoalPP = 0;\n\tvector $pos = position;\n\tif ($pos.y < "
            + self.controllerName + ".floor){\n\t\tlifespanPP = 0;\n\t}\n}",
            rbd=1)

        cmds.select(self.controllerName)
        # cmds.getAttr()
        self.dagModifier.doIt()
Example #8
0
import maya.cmds as cmds

cmds.turbulence(n='Grass_wind_FX',
                m=20,
                pos=(0, 0, 0),
                att=0.0,
                f=1,
                mxd=0,
                nsl=8)
x = 1
lat = 1

for i in range(109):
    cmds.select('grass_grass' + str(i))  #select object
    cmds.polyUnite(muv=1, n='grass' + str(i))  #Combine and rename
    cmds.delete(ch=True)
    cmds.select('grass' + str(i))  #slect new shape

    ################################ Create FX ###########################
    cmds.lattice(dv=(7, 7, 7), oc=True)
    cmds.select("ffd" + str(x) + "Lattice")
    cmds.duplicate(n="ffd" + str(x) + "Lattice_goal")
    cmds.select("ffd" + str(x) + "Base")
    cmds.duplicate(n="ffd" + str(x) + "Base_goal")

    cmds.select("ffd" + str(x) + "Lattice")
    cmds.soft("ffd" + str(x) + "Lattice", c=True)
    cmds.goal("ffd" + str(x) + "LatticeParticle",
              g="ffd" + str(x) + "Lattice_goal",
              w=0.5)
    cmds.connectDynamic("ffd" + str(x) + "LatticeParticle", f='Grass_wind_FX')