def add_rigid_body( self, objects, magnitude = 50 ): cmds.rigidBody( objects, active = False, m = magnitude, collisions = False ) cmds.gravity( pos = [0, 0, 0], m = magnitude, att = 0, dx = 0, dy = -1, dz = 0, mxd = -1, vsh = 'none', vex = 0, vof = [0, 0, 0], vsw = 360, tsr = 0.5 ) gravity_dag = oopmaya.DAG_Node() cmds.connectDynamic( objects, fields = gravity_dag.name() )
def doIt(self,argList): cmds.polyPlane(n='myPlane', h=5, w=2) cmds.polySphere(n='mySphere', r=5) cmds.select('mySphere') cmds.move(0,5,0) cmds.rigidBody( n='myRigidBody', active=True, b=0.5, sf=0.4 ) cmds.select(cl=True) cmds.gravity(n='myGravity') cmds.connectDynamic('mySphere', fields='myGravity')
def addDynamics(self,*args): for i in self.scene_before: self.obj = mc.listRelatives(i, p = True) mc.select(self.obj) mc.rigidBody( active = True, mass = 10, initialVelocity = (0.0,0.0,0.0), bounciness = 1, dynamicFriction = 0.8, damping = 0.2) self.G = mc.gravity(directionX = 0.0, directionY = -1.0, directionZ = 0.0, magnitude = 100) mc.connectDynamic(*self.obj, f = self.G)
def gravity(*args, **kwargs): res = cmds.gravity(*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
def add_rigid_body(self, objects, magnitude=50): cmds.rigidBody(objects, active=False, m=magnitude, collisions=False) cmds.gravity(pos=[0, 0, 0], m=magnitude, att=0, dx=0, dy=-1, dz=0, mxd=-1, vsh='none', vex=0, vof=[0, 0, 0], vsw=360, tsr=0.5) gravity_dag = oopmaya.DAG_Node() cmds.connectDynamic(objects, fields=gravity_dag.name())
def init(WeatherUI,self): c.select('emitPlane'); c.emitter(n='snowEmitter',type='surf',r=300,sro=0,nuv=0,cye='none',cyi=1,spd=1,srn=0,nsp=1,tsp=0,mxd=0,mnd=0,dx=0,dy=-1,dz=0,sp=1); c.particle(n='snowParticle'); c.select(cl=True); c.setAttr( "snowParticle|snowParticleShape.particleRenderType", 8); # 1 ist for 8 c.gravity(n='snowGravity',m=0.5); c.select(cl=True); c.connectDynamic('snowParticle',em='snowEmitter'); c.connectDynamic('snowParticle',f='snowGravity'); c.addAttr('snowParticleShape', ln='rgbPP', dt='vectorArray' ); c.dynExpression('snowParticleShape', s='snowParticleShape.rgbPP = <<1.0, 1.0, 1.0>>', c=1); c.addAttr('snowParticleShape', ln='radius', at='float', min=0, max=20, dv=1); c.setAttr('snowParticleShape.radius', 0.3); c.setAttr("particleCloud1.color", 1, 1, 1, type="double3"); c.setAttr('snowParticleShape.lifespanMode', 2); c.setAttr('snowParticleShape.lifespan', 30) c.select(cl=True); c.floatSliderGrp('snowIntens', en=True, e=True);
def init(WeatherUI,self): c.select('emitPlane'); c.emitter(n='rainEmitter',type='surf',r=300,sro=0,nuv=0,cye='none',cyi=1,spd=1,srn=0,nsp=1,tsp=0,mxd=0,mnd=0,dx=0,dy=-1,dz=0,sp=1); c.particle(n='rainParticle'); c.select(cl=True); c.setAttr( "rainParticle|rainParticleShape.particleRenderType", 6); # rainParticleShape/render Attributes c.gravity(n='rainGravity'); c.select(cl=True); c.connectDynamic('rainParticle',em='rainEmitter'); c.connectDynamic('rainParticle',f='rainGravity'); c.addAttr('rainParticleShape', ln='rgbPP', dt='vectorArray' ); c.dynExpression('rainParticleShape', s='rainParticleShape.rgbPP = <<0, 0, 1.0>>', c=1); c.select(cl=True); c.setAttr("particleCloud1.color", 1, 1, 1, type="double3"); #instead of particleCloud1? #sets the collision event and particle spawning c.particle( name='rainCollisionParticle' , inherit=True); c.connectDynamic('rainCollisionParticle',f='rainGravity'); c.select(cl=True); c.setAttr( "rainCollisionParticle|rainCollisionParticleShape.particleRenderType", 6); # rainParticleShape/render Attributes c.setAttr('rainCollisionParticle.inheritFactor', 1); c.event( 'rainParticle', em=2, die=True, target='rainCollisionParticle', spread=0.5, random=True, count=0, name='rainParticleCollideEvent' ); c.floatSliderGrp('rainIntens',en=True, e=True);
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."
cmds.setAttr('log3.translateY', 100) cmds.setAttr('log3.translateX', 5) #cmds.setAttr('log3.rotateY', 90) #cmds.rigidBody(active=True, mass=10, b=0) # Create passiv floor floor = cmds.polyPlane(h=55, w=55, sx=10, sy=10, ax=(0, 1, 0), name='floor', cuv=2, ch=0) #cmds.rigidBody(passive=True, bounciness=0.02, layer=-1) RigidBody.CreateRigidBody(False).executeCommandCB() # Add dynamics (gravity) grav = cmds.gravity(pos=(0, 0, 0), m=9.8, dx=0, dy=-1, dz=0, att=0, mxd=-1, name='myGravity') #cmds.connectDynamic( 'log1', 'log2', 'log3', f='myGravity' ) # Add some light #cmds.directionalLight(name='dirLight', decayRate=2, intensity=90, rgb=(1.0, 0.8, 0.8), rotation=(45, 70, 60))
def voxel(victime): #definition step = cmds.intSliderGrp('StepSlider', query=True, value=True) #Bounding box bbox = cmds.exactWorldBoundingBox() #Remplit un mesh de particule if (len(cmds.ls(sl=1))): obj = cmds.ls(sl=1)[0] try: cmds.particleFill(rs=step, maxX=1, maxY=1, maxZ=1, minX=0, minY=0, minZ=0, pd=1, cp=0) except: pass #Met les particules das une liste part = cmds.ls(sl=1)[0] closest = cmds.createNode("closestPointOnMesh") cmds.connectAttr(obj + ".outMesh", closest + ".inMesh") points = cmds.getAttr(part + ".position") cmds.delete(part) #Recupere tous les rayons rayons = [] for point in points: setAttr(closest + ".inPosition", point) rayons.append(mag(point, getAttr(closest + ".position"))) delete(closest) max = 0 #Recherche le MAX entre 2 particules (distance la plus grande) for i in range(len(points)): if rayons[i] > max: max, p, maxId = rayons[i], points[i], i #print max; amount = 0 nbCube = 0.0 cmds.progressWindow(title='Legosification', progress=amount, status='Legosification', isInterruptable=True) #Compte le nombre de lego dans la scene objList1 = ls("lego*", geometry=True, l=True) if (len(objList1) == 0): cmds.polyCube(n="lego") objList1 = ls("lego*", geometry=True, l=True) objList2 = cmds.listRelatives(objList1, p=True) #print len(objList1) name = len(objList2) - 1 #Cree des cubes for point in points: # Check if the dialog has been cancelled if cmds.progressWindow(query=True, isCancelled=True): break # Check if end condition has been reached if cmds.progressWindow(query=True, progress=True) >= 100: break name += 1 dimension = (float)(bbox[3] - bbox[0]) / (float)(step + 1.0) #cmds.duplicate("lego") #cmds.select("lego"+`i`) #cmds.polyCube(w=dimension, h=dimension, d=dimension) #cmds.select("lego") #cmds.move(point[0],point[1],point[2]) createLego(point[0], point[1], point[2], name, dimension, victime) nbCube += 1 amount = (nbCube / len(points)) * 100 cmds.progressWindow(edit=True, progress=amount, status=('Please Wait ! ')) cmds.progressWindow(endProgress=1) #Gravity and animation if cmds.checkBox("physics", query=True, value=True) and cmds.checkBox( "animation", query=True, value=True) == False: objList1 = ls("lego*", geometry=True, l=True) objList2 = cmds.listRelatives(objList1, p=True) cmds.select(cl=1) grav = cmds.gravity() #Connect gravity to list of objects cmds.connectDynamic(objList2, fields=grav[0]) #Menage if cmds.objExists('lego'): cmds.delete("lego")
cmds.addAttr(part[1], internalSet=True, ln="colorAccum", at="bool", dv=False ) cmds.addAttr(part[1], internalSet=True, ln="useLighting", at="bool", dv=False ) cmds.addAttr(part[1], internalSet=True, ln="pointSize", at="long", min=1, max=60, dv=2 ) cmds.addAttr(part[1], internalSet=True, ln="multiCount", at="long", min=1, max=60, dv=10 ) cmds.addAttr(part[1], internalSet=True, ln="multiRadius", at="float", min=0, max=10, dv=0.3 ) cmds.addAttr(part[1], internalSet=True, ln="normalDir", at="long", min=1, max=3, dv=2 ) part_attrs = {'colorAccum':False, 'useLighting':True, 'particleRenderType':0,} for attr, value in part_attrs.items(): cmds.setAttr('%s.%s' %(part[1], attr), value) #Adding fields #This code selects the particles so the gravity field can be added cmds.select(part) drop_grav = cmds.gravity(part, m=15, dy=-1) cmds.connectDynamic(part, f='gravityField1') #Reselect Particles to add in the radial field cmds.select(part) radial_drop = cmds.radial(part, m=0.010) cmds.connectDynamic(part, f=radial_drop[0]) #Create Partilce Mist from the Particle Tool mist_part_1 = cmds.particle(n='mist', c=0) mist_part_2 = cmds.particle(n='mist1', c=0) cmds.select(mist_part_1[0]) cmds.connectDynamic(mist_part_1[0], em=emit[0]) cmds.select(mist_part_2[0]) cmds.connectDynamic(mist_part_2[0], em=emit[0])
def addGravity(): selectDupeArray() gravInf= cmds.ls(sl=True) cmds.select(cl=True) cmds.gravity() cmds.connectDynamic( gravInf, f= 'gravityField1')
def readK2P(): mc.constructionHistory(toggle=False) mc.select(all=True) mc.delete() counterMin = 1; counter=counterMin; counterMax = 200; mc.playbackOptions(minTime=counterMin, maxTime=counterMax) skipCounterMin = 1; skipCounter=skipCounterMin; skipCounterMax = 6; path = "/Users/nick/Development/Maya/readxml" fileName = "mocapData1.xml" #trackPoint = ["l_foot","l_knee","l_hip","r_foot","r_knee","r_hip","l_hand","l_elbow","l_shoulder","r_hand","r_elbow","r_shoulder","torso","neck","head"] trackPoint = ["head"] scaler = 10 grav = mc.gravity() xmlFile = xd.parse(path + "/" + fileName) print("loaded: " + fileName) for t in trackPoint: joint = xmlFile.getElementsByTagName(t) jointCounter = 0; cubeName = t #mergeName = t + "Merge" for j in joint: counter=counterMin; x = scaler * float(j.getAttribute("x")) y = scaler * float(j.getAttribute("y")) z = scaler * float(j.getAttribute("z")) if(x!=0 and y!=0 and z!=0): mc.currentTime(counter) counter+=1 if(skipCounter<skipCounterMax): jointCounter+=1 mc.polyCube(name=cubeName+str(counter)) #polyCube(sx=2, sy=2, sz=2, name=cubeName+str(counter)) #polySmooth(dv=1) mc.connectDynamic(f=grav) #adds gravity mc.move(x, y, z) mc.rotate(rnd.uniform(-1 * scaler, scaler),rnd.uniform(-1 * scaler, scaler),rnd.uniform(-1 * scaler, scaler)) skipCounter+=1 else: skipCounter=skipCounterMin print("cubes made: " + str(jointCounter)) #select(all=True) #polyUnite(constructionHistory=False) #1=union, 2=difference, 3=intersection floor = mc.polyPlane(w=30,h=30) mc.rigidBody(passive=True) mc.move(0,0,0) print("...script complete.")
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."
max=3, dv=2) part_attrs = { 'colorAccum': False, 'useLighting': True, 'particleRenderType': 0, } for attr, value in part_attrs.items(): cmds.setAttr('%s.%s' % (part[1], attr), value) #Adding fields #This code selects the particles so the gravity field can be added cmds.select(part) drop_grav = cmds.gravity(part, m=15, dy=-1) cmds.connectDynamic(part, f='gravityField1') #Reselect Particles to add in the radial field cmds.select(part) radial_drop = cmds.radial(part, m=0.010) cmds.connectDynamic(part, f=radial_drop[0]) #Create Partilce Mist from the Particle Tool mist_part_1 = cmds.particle(n='mist', c=0) mist_part_2 = cmds.particle(n='mist1', c=0) cmds.select(mist_part_1[0]) cmds.connectDynamic(mist_part_1[0], em=emit[0]) cmds.select(mist_part_2[0]) cmds.connectDynamic(mist_part_2[0], em=emit[0])
#Didn't add in all of the attributes for multipoint, just what was directed in the tutorial #Turn on Use Lighting cmds.setAttr('dropletsShape.useLighting', True) #Point Size to 1 cmds.setAttr('dropletsShape.pointSize', 1) ''' #Adding Fields ''' gravity -pos 0 0 0 -m 9.8 -att 0 -dx 0 -dy -1 -dz 0 -mxd -1 -vsh none -vex 0 -vof 0 0 0 -vsw 360 -tsr 0.5 ; // gravityField1 // #Select particles before adding in fields ''' cmds.select('droplets') cmds.gravity('droplets', m=15, dy=-1) cmds.connectDynamic('droplets', f='gravityField1') #Reselect Particles cmds.select('droplets') cmds.radial('droplets', m=0.010) cmds.connectDynamic('droplets', f='radialField1') #Create Partilce Mist from the Particle Tool cmds.particle(n='mist', c=0) cmds.particle(n='mist1', c=0) cmds.select('mist') cmds.connectDynamic('mist', em=emit[0]) cmds.select('mist1') cmds.connectDynamic('mist1', em=emit[0]) #Add gravityField1 and radialField1 to mist and mist1 through dynamicRelationship editor
mygrid = cmds.polyPlane(name='emi') cmds.setAttr("emi.rotateX", -45) cmds.setAttr("emi.translateZ", 10) cmds.setAttr("emi.translateY", 10) cmds.setAttr("emi.scaleX", 30) cmds.setAttr("emi.scaleY", 20) cmds.setAttr("emi.scaleZ", 20) cmds.select('emi') myem = cmds.emitter(name='myEmitter', speed=30, speedRandom=10, rate=0.005) mypa = cmds.particle(name='myParticle') cmds.connectDynamic(mypa[0], em=myem) cmds.setAttr("myEmitter.emitterType", 2) mygr = cmds.gravity(name='myGravity') cmds.connectDynamic(mypa, f=mygr) cmds.setAttr("myGravity.magnitude", 4) cmds.select('pCone1', 'myParticle') cmds.particleInstancer("myParticle", object='pCone1', aimDirection='velocity') cmds.select('myParticle') myem2 = cmds.emitter(name='trailEmitter', rate=1000, spread=1, speed=4, speedRandom=3) mypa2 = cmds.particle(name='trailParticle') cmds.connectDynamic(mypa2[0], em=myem2)
sx=10, sy=1, sz=10, ax=(0, 1, 0), name='floor') cmds.setAttr('floor.translateY', -15) ''' Initiate rigidSolvers mySphere should interact with shards created from myPlane Shards created below by way of cutObject should interact ''' cmds.rigidSolver(create=True, name='rigidSolver1') cmds.select('floor') cmds.rigidBody(passive=True, solver='rigidSolver1', name='passiveRigidBodyFloor') cmds.gravity(pos=(0, 0, 0), m=9.8, dx=0, dy=-1, dz=0, name='gravityField') fracturePosition = cmds.objectCenter(myPlane, gl=True) print("Fracture position") print(fracturePosition) centerPoints = generateVoronoiPoints(fracturePosition) shatteredPlane = cutObject(myPlane, centerPoints) shards = cmds.listRelatives(shatteredPlane, children=True) for i in range(len(shards)): cmds.select(shards[i]) cmds.rigidBody(active=True, solver='rigidSolver1', name='shard' + str(i)) #cmds.connectDynamic('shard' + str(i), f='gravityField')
def buildSplash(self): objectName = str(self.getObject.text()) if self.checkWake.isChecked() == True: wakeEmitter = str(self.getWake.text()) else: wakeEmitter = "OceanWakeEmitter1" if self.checkOcean.isChecked() == True: oceanShader = str(self.getOcean.text()) else: oceanShader = "oceanShader1" ###Bcreating Splash Disc objectNameAxis = generator.getMaxAndMinAxis(objectName) #generator_Return: 0-maxX, 1-minX, 2-maxY, 3-minY, 4-maxZ, 5-minZ avrgX = objectNameAxis[0] - objectNameAxis[1] avrgZ = objectNameAxis[4] - objectNameAxis[5] avrgY = objectNameAxis[2] - objectNameAxis[3] if avrgX > avrgZ: SplashCurve = avrgX else: SplashCurve = avrgZ baseCurve = cmds.circle(name="base", normal=[0, 1, 0], radius=SplashCurve / 1.5) headCurve = cmds.circle(name="head", normal=[0, 1, 0], radius=SplashCurve / 2) cmds.move(0, (avrgY / 4), 0, headCurve) cmds.rebuildCurve("base", ch=1, rpo=1, rt=0, end=1, kr=0, kcp=0, kep=0, kt=0, s=100, d=7, tol=0.01) cmds.rebuildCurve("head", ch=1, rpo=1, rt=0, end=1, kr=0, kcp=0, kep=0, kt=0, s=100, d=7, tol=0.01) splashDisc = cmds.loft("base", "head", name="%s_SplashDisc" % objectName, ch=1, u=1, c=0, ar=1, d=3, ss=int(avrgY + 1), rn=0, po=0, rsn=True) #Return: 0-SplashDisc, 1-loft1 cmds.delete(baseCurve, headCurve) cmds.setAttr("%s.visibility" % splashDisc[0], False) objectPosition = cmds.xform(objectName, query=True, translation=True, worldSpace=True) cmds.move(objectPosition[0], 0, objectPosition[2], splashDisc[0]) ###adding emitter and particle to Object objectNameEmitter = cmds.emitter(objectName, type='surface', rate=0, scaleRateByObjectSize=False, needParentUV=False, cycleEmission="none", cycleInterval=1, speed=1, speedRandom=0, normalSpeed=1, tangentSpeed=0, maxDistance=0, minDistance=0, directionX=1, directionY=0, directionZ=0, spread=0, name="%s_emitter" % objectName) #Return: 0-objectName, 1-objectName_emitter objectNameParticle = cmds.particle(name="%s_particle" % objectName) cmds.connectDynamic(objectNameParticle[0], emitters=objectNameEmitter[0]) ###adding emitter and particle to Splash Disc splashDiscEmitter = cmds.emitter(splashDisc[0], type='surface', rate=0, scaleRateByObjectSize=False, needParentUV=False, cycleEmission="none", cycleInterval=1, speed=1, speedRandom=1.5, normalSpeed=1, tangentSpeed=0, maxDistance=0, minDistance=0, directionX=1, directionY=0, directionZ=0, spread=0, name="%s_emitter" % splashDisc[0]) #Return: 0-SplashDisc, 1-SplashDisc_emitter splashDiscParticle = cmds.particle(name="%s_particle" % splashDisc[0]) cmds.connectDynamic(splashDiscParticle[0], emitters=splashDiscEmitter[0]) #connecting the X and Z object position to Splash Disc to follow cmds.connectAttr("%s.translate.translateZ" % objectName, "%s.translate.translateZ" % splashDisc[0]) cmds.connectAttr("%s.translate.translateX" % objectName, "%s.translate.translateX" % splashDisc[0]) #setting up the splash Disc particle Setting cmds.setAttr("%s.lifespanMode" % splashDiscParticle[1], 3) cmds.setAttr("%s.lifespanRandom" % splashDiscParticle[1], 0.5) cmds.setAttr("%s.conserve" % splashDiscParticle[1], 0.983) cmds.setAttr("%s.inheritFactor" % splashDiscParticle[1], 0.2) cmds.setAttr("%s.particleRenderType" % splashDiscParticle[1], 5) cmds.addAttr(splashDiscParticle[1], keyable=True, ln="useLighting", at="bool", dv=False) cmds.addAttr(splashDiscParticle[1], ln="spriteScaleYPP", dt="doubleArray") cmds.addAttr(splashDiscParticle[1], ln="spriteScaleYPP0", dt="doubleArray") cmds.addAttr(splashDiscParticle[1], ln="spriteScaleXPP", dt="doubleArray") cmds.addAttr(splashDiscParticle[1], ln="spriteScaleXPP0", dt="doubleArray") cmds.addAttr(splashDiscParticle[1], ln="spriteTwistPP", dt="doubleArray") cmds.addAttr(splashDiscParticle[1], ln="spriteTwistPP0", dt="doubleArray") #creating Ramp for Splash Disc particle splashDiscParticle_spriteScaleXPP = cmds.arrayMapper( target=splashDiscParticle[1], destAttr="spriteScaleXPP", inputV="ageNormalized", type="ramp") ramp_spriteScaleXPP = cmds.listConnections( splashDiscParticle_spriteScaleXPP, type="ramp") ramp_spriteScaleXPP = cmds.rename( ramp_spriteScaleXPP[1], "%s_spriteScaleXPP_Rampe" % splashDiscParticle[1]) cmds.setAttr("%s.colorEntryList[2].color" % ramp_spriteScaleXPP, 0, 0, 0) cmds.setAttr("%s.colorEntryList[2].position" % ramp_spriteScaleXPP, 1) cmds.setAttr("%s.colorEntryList[1].color" % ramp_spriteScaleXPP, 0.5, 0.5, 0.5) cmds.setAttr("%s.colorEntryList[1].position" % ramp_spriteScaleXPP, 0.165) cmds.setAttr("%s.colorEntryList[0].color" % ramp_spriteScaleXPP, 1, 1, 1) cmds.setAttr("%s.colorEntryList[0].position" % ramp_spriteScaleXPP, 0) splashDiscParticle_spriteScaleYPP = cmds.arrayMapper( target=splashDiscParticle[1], destAttr="spriteScaleYPP", inputV="ageNormalized", type="ramp") ramp_spriteScaleYPP = cmds.listConnections( splashDiscParticle_spriteScaleYPP, type="ramp") ramp_spriteScaleYPP = cmds.rename( ramp_spriteScaleYPP[1], "%s_SpriteScaleYPP_Rampe" % splashDiscParticle[1]) cmds.setAttr("%s.colorEntryList[2].color" % ramp_spriteScaleYPP, 0, 0, 0) cmds.setAttr("%s.colorEntryList[2].position" % ramp_spriteScaleYPP, 1) cmds.setAttr("%s.colorEntryList[1].color" % ramp_spriteScaleYPP, 0.5, 0.5, 0.5) cmds.setAttr("%s.colorEntryList[1].position" % ramp_spriteScaleYPP, 0.165) cmds.setAttr("%s.colorEntryList[0].color" % ramp_spriteScaleYPP, 1, 1, 1) cmds.setAttr("%s.colorEntryList[0].position" % ramp_spriteScaleYPP, 0) #setting up the object particle Setting cmds.setAttr("%s.lifespanMode" % objectNameParticle[1], 3) cmds.setAttr("%s.particleRenderType" % objectNameParticle[1], 7) cmds.addAttr(objectNameParticle[1], keyable=True, ln="threshold", at="float", min=0, max=10, dv=0.7) cmds.addAttr(objectNameParticle[1], keyable=True, ln="radius", at="float", min=0, max=10, dv=0.5) cmds.addAttr(objectNameParticle[1], ln="radiusPP", dt="doubleArray") #creating Ramp for object particle objectNameParticle_radiusPP = cmds.arrayMapper( target=objectNameParticle[1], destAttr="radiusPP", inputV="ageNormalized", type="ramp") ramp_radiusPP = cmds.listConnections(objectNameParticle_radiusPP, type="ramp") ramp_radiusPP = cmds.rename( ramp_radiusPP[1], "%s_RadiusPP_Rampe" % objectNameParticle[1]) cmds.setAttr("%s.colorEntryList[3].color" % ramp_radiusPP, 0.056, 0.056, 0.056) cmds.setAttr("%s.colorEntryList[3].position" % ramp_radiusPP, 1) cmds.setAttr("%s.colorEntryList[2].color" % ramp_radiusPP, 0.223, 0.223, 0.223) cmds.setAttr("%s.colorEntryList[2].position" % ramp_radiusPP, 0.690) cmds.setAttr("%s.colorEntryList[1].color" % ramp_radiusPP, 0.178, 0.178, 0.178) cmds.setAttr("%s.colorEntryList[1].position" % ramp_radiusPP, 0.455) cmds.setAttr("%s.colorEntryList[0].color" % ramp_radiusPP, 0, 0, 0) cmds.setAttr("%s.colorEntryList[0].position" % ramp_radiusPP, 0) #adding gravity to SplashDisc splashDiscGravity = cmds.gravity(name="%s_GravityField" % splashDiscParticle[0], pos=[0, 0, 0], m=9.8, att=0, dx=0, dy=-1, dz=0, mxd=-1, vsh="none", vex=0, vof=[0, 0, 0], vsw=360, tsr=0.5) cmds.connectDynamic(splashDiscParticle[0], fields=splashDiscGravity) #adding gravity to Object objectNameGravity = cmds.uniform(name="%s_UniformField" % objectNameParticle[0], pos=[0, 0, 0], m=5, att=1, dx=1, dy=-1, dz=0, mxd=-1, vsh="none", vex=0, vof=[0, 0, 0], vsw=360, tsr=0.5) cmds.connectDynamic(objectNameParticle[0], fields=objectNameGravity) print objectNameGravity cmds.setAttr("%s.directionX" % objectNameGravity[0], 0) cmds.setAttr("%s.directionY" % objectNameGravity[0], 1) cmds.setAttr("%s.directionZ" % objectNameGravity[0], 0) cmds.setAttr("%s.magnitude" % objectNameGravity[0], 28) #adding Expression for Object and SplashDisc generator.objectNameParticleExpressionBeforeDynamics( objectNameParticle[1], oceanShader) generator.splashDiscParticleExpressionBeforeDynamics( splashDiscParticle[1], oceanShader) generator.splashDiscParticleExpressionAfterDynamics( splashDiscParticle[1]) generator.splashDiscParticleExpressionCreation(splashDiscParticle[1]) if "ocean_MainExpression" not in cmds.ls(): generator.createMainExpression(objectNameEmitter[1]) if "ocean_MainExpression" in cmds.ls(): generator.editMainExpression(objectName, splashDiscEmitter[0], oceanShader, objectNameEmitter[1], wakeEmitter, splashDiscEmitter[1]) # num=0 if "mainSplashDisc_Shader" not in cmds.ls(): generator.shaderSetup() # cmds.select(splashDiscEmitter[0], replace=True) # cmds.sets(edit=True,forceElement="mainSplashDisc_ShaderSG") cmds.sets(splashDiscParticle, edit=True, forceElement='mainSplashDisc_ShaderSG') else: cmds.sets(splashDiscParticle, edit=True, forceElement='mainSplashDisc_ShaderSG') # while cmds.connectionInfo("mainSplashDisc_ShaderSG.dagSetMembers[%s]"%num,getExactDestination=True) != "": # num+=1 # cmds.connectAttr(splashDiscEmitter[1] + ".instObjGroups[0]", "mainSplashDisc_Shader.dagSetMembers[%s]"%num, force = True) # else: # while cmds.connectionInfo("mainSplashDisc_ShaderSG.dagSetMembers[%s]"%num,getExactDestination=True) != "": # num+=1 # cmds.connectAttr(splashDiscEmitter[1] + ".instObjGroups[0]", "mainSplashDisc_Shader.dagSetMembers[%s]"%num, force = True) # pSphere1_SplashDisc.translateX = pSphere1.translateX; # pSphere1_SplashDisc.translateZ = pSphere1.translateZ; return
def create_jiggle_locator(position_object, base_name): """Create jiggle rig at the specified postion, you will then need to make sure this jiggle rig is hooked up to be driven by the source rig Usage: create_jiggle_locator('ball', 'my_jiggle') """ if cmds.objExists(position_object): # Get position of input object pos = cmds.xform(position_object, q=True, ws=True, t=True) # Create single particle part = cmds.particle(p=[pos[0], (pos[1]), pos[2]], c=1, name='{}_particle'.format(base_name)) cmds.setAttr("{}.particleRenderType".format(part[1]), 4) # Goal particle to source object cmds.goal(part[0], goal=position_object, w=0.5, utr=True) # Create output transform jiggle_output = cmds.spaceLocator(name="{}_ctl".format(base_name))[0] cmds.connectAttr("{}.worldCentroid".format(part[1]), '{}.translate'.format(jiggle_output)) # Create jiggle control for attr in ['rx', 'ry', 'rz', 'sx', 'sy', 'sz', 'v']: cmds.setAttr('{}.{}'.format(jiggle_output, attr), k=False, lock=True) # Add gravity grav = \ cmds.gravity(name='{}_gravity'.format(base_name), pos=[0, 0, 0], m=100, att=0, dx=0, dy=-1, dz=0, mxd=-1)[ 0] # , vsh=none -vex 0 -vof 0 0 0 -vsw 360 -tsr 0.5 ; cmds.connectDynamic(part, f=grav) # Add attrs: isDynamic=on, conserve=1.0, goalWeight[0]=1.0, goalSmoothness=3, gravity=9.8 cmds.addAttr(jiggle_output, ln="JIGGLE", at="enum", en="__:") cmds.setAttr('{}.JIGGLE'.format(jiggle_output), cb=True) # Enabled cmds.addAttr(jiggle_output, ln="enabled", at="bool") cmds.setAttr('{}.enabled'.format(jiggle_output), k=True, l=False) cmds.setAttr('{}.enabled'.format(jiggle_output), 1) cmds.connectAttr('{}.enabled'.format(jiggle_output), '{}.isDynamic'.format(part[1])) # Dynamics Weight """ cmds.addAttr(jiggle_output, ln="dynamicsWeight", at="double", min=0, max=1, dv=1) cmds.setAttr('{}.dynamicsWeight'.format(jiggle_output), k=True, l=False) cmds.connectAttr('{}.dynamicsWeight'.format(jiggle_output), '{}.dynamicsWeight'.format(part[1])) """ # Conserve cmds.addAttr(jiggle_output, ln="conserve", at="double", min=0, max=1, dv=1) cmds.setAttr('{}.conserve'.format(jiggle_output), k=True, l=False) cmds.connectAttr('{}.conserve'.format(jiggle_output), '{}.conserve'.format(part[1])) # Goal Smoothness cmds.addAttr(jiggle_output, ln="goalSmoothness", at="double", min=0, dv=3) cmds.setAttr('{}.goalSmoothness'.format(jiggle_output), k=True, l=False) cmds.connectAttr('{}.goalSmoothness'.format(jiggle_output), '{}.goalSmoothness'.format(part[1])) # Goal Weight cmds.addAttr(jiggle_output, ln="goalWeight", at="double", min=0, max=1.0, dv=.5) cmds.setAttr('{}.goalWeight'.format(jiggle_output), k=True, l=False) cmds.connectAttr('{}.goalWeight'.format(jiggle_output), '{}.goalWeight[0]'.format(part[1])) cmds.addAttr(jiggle_output, ln="GRAVITY", at="enum", en="__:") cmds.setAttr('{}.GRAVITY'.format(jiggle_output), cb=True) # Gravity cmds.addAttr(jiggle_output, ln="gravityMagnitude", at="double", min=0, dv=100) cmds.setAttr('{}.gravityMagnitude'.format(jiggle_output), k=True, l=False) cmds.connectAttr('{}.gravityMagnitude'.format(jiggle_output), '{}.magnitude'.format(grav)) # Gravity Direction cmds.addAttr(jiggle_output, ln="gravityDirection", at="double3") cmds.addAttr(jiggle_output, ln="gravityDirectionX", at="double", p="gravityDirection", dv=0) cmds.addAttr(jiggle_output, ln="gravityDirectionY", at="double", p="gravityDirection", dv=-1) cmds.addAttr(jiggle_output, ln="gravityDirectionZ", at="double", p="gravityDirection", dv=0) cmds.setAttr('{}.gravityDirection'.format(jiggle_output), k=True, l=False) cmds.setAttr('{}.gravityDirectionX'.format(jiggle_output), k=True, l=False) cmds.setAttr('{}.gravityDirectionY'.format(jiggle_output), k=True, l=False) cmds.setAttr('{}.gravityDirectionZ'.format(jiggle_output), k=True, l=False) cmds.connectAttr('{}.gravityDirectionX'.format(jiggle_output), '{}.directionX'.format(grav)) cmds.connectAttr('{}.gravityDirectionY'.format(jiggle_output), '{}.directionY'.format(grav)) cmds.connectAttr('{}.gravityDirectionZ'.format(jiggle_output), '{}.directionZ'.format(grav)) # Cleanup jiggle_group = cmds.group(empty=True, name="{}All_grp".format(base_name)) cmds.parent(part[0], jiggle_output, grav, jiggle_group) cmds.select(jiggle_output) return jiggle_output
cmds.setKeyframe( pObjectName, time=pStartTime, attribute=pTargetAttribute, value=0 ) cmds.setKeyframe( pObjectName, time=pEndTime, attribute=pTargetAttribute, value=360 ) cmds.selectKey( pObjectName, time=(pStartTime, pEndTime), attribute=pTargetAttribute, keyframe=True ) cmds.keyTangent( inTangentType='linear', outTangentType='linear' ) ### Main script ### selected = cmds.ls( selection=True, type='transform' ) if len( selected ) > 0: # Set animation keyframes at start and end of playback startTime = cmds.playbackOptions( query=True, minTime=True ) endTime = cmds.playbackOptions( query=True, maxTime=True ) #cmds.gravity(selected) for object in selected: # Apply gravity!? # But first: Rotate! keyFullRotation( object, startTime, endTime, 'rotateY' ) #applyGravity(object) cmds.gravity( object ) else: print 'Please select at least one object'
def buildSplash(self): objectName = str(self.getObject.text()) if self.checkWake.isChecked()==True: wakeEmitter = str(self.getWake.text()) else: wakeEmitter = "OceanWakeEmitter1" if self.checkOcean.isChecked()==True: oceanShader = str(self.getOcean.text()) else: oceanShader = "oceanShader1" ###Bcreating Splash Disc objectNameAxis = generator.getMaxAndMinAxis(objectName) #generator_Return: 0-maxX, 1-minX, 2-maxY, 3-minY, 4-maxZ, 5-minZ avrgX = objectNameAxis[0] - objectNameAxis[1] avrgZ = objectNameAxis[4] - objectNameAxis[5] avrgY = objectNameAxis[2] - objectNameAxis[3] if avrgX > avrgZ: SplashCurve = avrgX else: SplashCurve = avrgZ baseCurve = cmds.circle(name="base",normal=[0,1,0],radius=SplashCurve/1.5) headCurve = cmds.circle(name="head",normal=[0,1,0],radius=SplashCurve/2) cmds.move(0,(avrgY/4),0,headCurve) cmds.rebuildCurve ("base", ch=1, rpo=1, rt=0, end=1, kr=0, kcp=0, kep=0, kt=0, s=100, d=7, tol=0.01) cmds.rebuildCurve ("head", ch=1, rpo=1, rt=0, end=1, kr=0, kcp=0, kep=0, kt=0, s=100, d=7, tol=0.01) splashDisc = cmds.loft ("base", "head",name="%s_SplashDisc"%objectName, ch=1, u=1, c=0, ar=1, d=3, ss=int(avrgY+1), rn=0, po=0, rsn=True) #Return: 0-SplashDisc, 1-loft1 cmds.delete(baseCurve,headCurve) cmds.setAttr("%s.visibility"%splashDisc[0], False ) objectPosition = cmds.xform(objectName, query=True, translation=True, worldSpace=True ) cmds.move(objectPosition[0], 0, objectPosition[2], splashDisc[0]) ###adding emitter and particle to Object objectNameEmitter = cmds.emitter(objectName,type='surface',rate=0,scaleRateByObjectSize=False,needParentUV=False,cycleEmission="none", cycleInterval=1,speed=1,speedRandom=0,normalSpeed=1,tangentSpeed=0,maxDistance=0,minDistance=0, directionX=1,directionY=0,directionZ=0,spread=0,name="%s_emitter"%objectName) #Return: 0-objectName, 1-objectName_emitter objectNameParticle = cmds.particle(name="%s_particle"%objectName) cmds.connectDynamic(objectNameParticle[0],emitters=objectNameEmitter[0]) ###adding emitter and particle to Splash Disc splashDiscEmitter = cmds.emitter(splashDisc[0],type='surface',rate=0,scaleRateByObjectSize=False,needParentUV=False,cycleEmission="none", cycleInterval=1,speed=1,speedRandom=1.5,normalSpeed=1,tangentSpeed=0,maxDistance=0,minDistance=0, directionX=1,directionY=0,directionZ=0,spread=0,name="%s_emitter"%splashDisc[0]) #Return: 0-SplashDisc, 1-SplashDisc_emitter splashDiscParticle = cmds.particle(name="%s_particle"%splashDisc[0]) cmds.connectDynamic(splashDiscParticle[0],emitters=splashDiscEmitter[0]) #connecting the X and Z object position to Splash Disc to follow cmds.connectAttr("%s.translate.translateZ"%objectName, "%s.translate.translateZ"%splashDisc[0]) cmds.connectAttr("%s.translate.translateX"%objectName, "%s.translate.translateX"%splashDisc[0]) #setting up the splash Disc particle Setting cmds.setAttr("%s.lifespanMode"%splashDiscParticle[1],3) cmds.setAttr("%s.lifespanRandom"%splashDiscParticle[1],0.5) cmds.setAttr("%s.conserve"%splashDiscParticle[1],0.983) cmds.setAttr("%s.inheritFactor"%splashDiscParticle[1],0.2) cmds.setAttr("%s.particleRenderType"%splashDiscParticle[1],5) cmds.addAttr(splashDiscParticle[1], keyable=True, ln="useLighting", at="bool", dv=False) cmds.addAttr(splashDiscParticle[1], ln="spriteScaleYPP", dt="doubleArray") cmds.addAttr(splashDiscParticle[1], ln="spriteScaleYPP0", dt="doubleArray") cmds.addAttr(splashDiscParticle[1], ln="spriteScaleXPP", dt="doubleArray") cmds.addAttr(splashDiscParticle[1], ln="spriteScaleXPP0", dt="doubleArray") cmds.addAttr(splashDiscParticle[1], ln="spriteTwistPP", dt="doubleArray") cmds.addAttr(splashDiscParticle[1], ln="spriteTwistPP0", dt="doubleArray") #creating Ramp for Splash Disc particle splashDiscParticle_spriteScaleXPP = cmds.arrayMapper(target=splashDiscParticle[1], destAttr="spriteScaleXPP", inputV="ageNormalized", type="ramp") ramp_spriteScaleXPP = cmds.listConnections(splashDiscParticle_spriteScaleXPP, type="ramp") ramp_spriteScaleXPP = cmds.rename(ramp_spriteScaleXPP[1], "%s_spriteScaleXPP_Rampe"%splashDiscParticle[1]) cmds.setAttr("%s.colorEntryList[2].color"%ramp_spriteScaleXPP, 0,0,0) cmds.setAttr("%s.colorEntryList[2].position"%ramp_spriteScaleXPP, 1) cmds.setAttr("%s.colorEntryList[1].color"%ramp_spriteScaleXPP, 0.5,0.5,0.5) cmds.setAttr("%s.colorEntryList[1].position"%ramp_spriteScaleXPP, 0.165) cmds.setAttr("%s.colorEntryList[0].color"%ramp_spriteScaleXPP, 1,1,1) cmds.setAttr("%s.colorEntryList[0].position"%ramp_spriteScaleXPP, 0) splashDiscParticle_spriteScaleYPP = cmds.arrayMapper(target=splashDiscParticle[1], destAttr="spriteScaleYPP", inputV="ageNormalized", type="ramp") ramp_spriteScaleYPP = cmds.listConnections(splashDiscParticle_spriteScaleYPP, type="ramp") ramp_spriteScaleYPP = cmds.rename(ramp_spriteScaleYPP[1], "%s_SpriteScaleYPP_Rampe"%splashDiscParticle[1]) cmds.setAttr("%s.colorEntryList[2].color"%ramp_spriteScaleYPP, 0,0,0) cmds.setAttr("%s.colorEntryList[2].position"%ramp_spriteScaleYPP, 1) cmds.setAttr("%s.colorEntryList[1].color"%ramp_spriteScaleYPP, 0.5,0.5,0.5) cmds.setAttr("%s.colorEntryList[1].position"%ramp_spriteScaleYPP, 0.165) cmds.setAttr("%s.colorEntryList[0].color"%ramp_spriteScaleYPP, 1,1,1) cmds.setAttr("%s.colorEntryList[0].position"%ramp_spriteScaleYPP, 0) #setting up the object particle Setting cmds.setAttr("%s.lifespanMode"%objectNameParticle[1],3) cmds.setAttr("%s.particleRenderType"%objectNameParticle[1],7) cmds.addAttr(objectNameParticle[1], keyable=True, ln="threshold", at="float", min=0, max=10, dv=0.7) cmds.addAttr(objectNameParticle[1], keyable=True, ln="radius", at="float", min=0, max=10, dv=0.5) cmds.addAttr (objectNameParticle[1], ln="radiusPP", dt="doubleArray") #creating Ramp for object particle objectNameParticle_radiusPP = cmds.arrayMapper(target=objectNameParticle[1], destAttr="radiusPP", inputV="ageNormalized", type="ramp") ramp_radiusPP = cmds.listConnections(objectNameParticle_radiusPP, type="ramp") ramp_radiusPP = cmds.rename(ramp_radiusPP[1], "%s_RadiusPP_Rampe"%objectNameParticle[1]) cmds.setAttr("%s.colorEntryList[3].color"%ramp_radiusPP, 0.056,0.056,0.056) cmds.setAttr("%s.colorEntryList[3].position"%ramp_radiusPP, 1) cmds.setAttr("%s.colorEntryList[2].color"%ramp_radiusPP, 0.223,0.223,0.223) cmds.setAttr("%s.colorEntryList[2].position"%ramp_radiusPP, 0.690) cmds.setAttr("%s.colorEntryList[1].color"%ramp_radiusPP, 0.178,0.178,0.178) cmds.setAttr("%s.colorEntryList[1].position"%ramp_radiusPP, 0.455) cmds.setAttr("%s.colorEntryList[0].color"%ramp_radiusPP, 0,0,0) cmds.setAttr("%s.colorEntryList[0].position"%ramp_radiusPP, 0) #adding gravity to SplashDisc splashDiscGravity = cmds.gravity(name="%s_GravityField"%splashDiscParticle[0], pos=[0,0,0], m=9.8, att=0, dx=0, dy=-1, dz=0, mxd=-1, vsh="none", vex=0, vof=[0,0,0], vsw=360, tsr=0.5) cmds.connectDynamic(splashDiscParticle[0], fields=splashDiscGravity) #adding gravity to Object objectNameGravity = cmds.uniform(name="%s_UniformField"%objectNameParticle[0], pos=[0,0,0], m=5, att=1, dx=1, dy=-1, dz=0, mxd=-1, vsh="none", vex=0, vof=[0,0,0], vsw=360, tsr=0.5) cmds.connectDynamic(objectNameParticle[0], fields=objectNameGravity) print objectNameGravity cmds.setAttr("%s.directionX"%objectNameGravity[0],0) cmds.setAttr("%s.directionY"%objectNameGravity[0],1) cmds.setAttr("%s.directionZ"%objectNameGravity[0],0) cmds.setAttr("%s.magnitude"%objectNameGravity[0],28) #adding Expression for Object and SplashDisc generator.objectNameParticleExpressionBeforeDynamics(objectNameParticle[1], oceanShader) generator.splashDiscParticleExpressionBeforeDynamics(splashDiscParticle[1], oceanShader) generator.splashDiscParticleExpressionAfterDynamics(splashDiscParticle[1]) generator.splashDiscParticleExpressionCreation(splashDiscParticle[1]) if "ocean_MainExpression" not in cmds.ls() : generator.createMainExpression(objectNameEmitter[1]) if "ocean_MainExpression" in cmds.ls() : generator.editMainExpression(objectName, splashDiscEmitter[0], oceanShader, objectNameEmitter[1], wakeEmitter, splashDiscEmitter[1]) # num=0 if "mainSplashDisc_Shader" not in cmds.ls(): generator.shaderSetup() # cmds.select(splashDiscEmitter[0], replace=True) # cmds.sets(edit=True,forceElement="mainSplashDisc_ShaderSG") cmds.sets(splashDiscParticle, edit = True, forceElement = 'mainSplashDisc_ShaderSG') else: cmds.sets(splashDiscParticle, edit = True, forceElement = 'mainSplashDisc_ShaderSG') # while cmds.connectionInfo("mainSplashDisc_ShaderSG.dagSetMembers[%s]"%num,getExactDestination=True) != "": # num+=1 # cmds.connectAttr(splashDiscEmitter[1] + ".instObjGroups[0]", "mainSplashDisc_Shader.dagSetMembers[%s]"%num, force = True) # else: # while cmds.connectionInfo("mainSplashDisc_ShaderSG.dagSetMembers[%s]"%num,getExactDestination=True) != "": # num+=1 # cmds.connectAttr(splashDiscEmitter[1] + ".instObjGroups[0]", "mainSplashDisc_Shader.dagSetMembers[%s]"%num, force = True) # pSphere1_SplashDisc.translateX = pSphere1.translateX; # pSphere1_SplashDisc.translateZ = pSphere1.translateZ; return
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()
cmds.setAttr('dropletsShape.useLighting', True) #Point Size to 1 cmds.setAttr('dropletsShape.pointSize', 1) ''' #Adding Fields ''' gravity -pos 0 0 0 -m 9.8 -att 0 -dx 0 -dy -1 -dz 0 -mxd -1 -vsh none -vex 0 -vof 0 0 0 -vsw 360 -tsr 0.5 ; // gravityField1 // #Select particles before adding in fields ''' # Placement (xform command) # emit and part cmds.select('droplets') drop_grav = cmds.gravity('droplets', m=15, dy=-1) cmds.connectDynamic('droplets', f='gravityField1') #Reselect Particles cmds.select('droplets') radial_drop = cmds.radial('droplets', m=0.010) cmds.connectDynamic(part[0], f=radial_drop[0]) #Create Partilce Mist from the Particle Tool mist_part_1 = cmds.particle(n='mist', c=0) mist_part_2 = cmds.particle(n='mist1', c=0) cmds.select('mist') cmds.connectDynamic(mist_part_1[0], em=emit[0]) cmds.select('mist1') cmds.connectDynamic('mist1', em=emit[0]) #Add gravityField1 and radialField1 to mist and mist1 through dynamicRelationship editor
def generateCity(self, *args): map_file = cmds.textField(self.widgets["osmFileTextField"], q = True, fi = True) winds_file = cmds.textField(self.widgets["wrfFileTextField"], q = True, fi = True) heights_file = cmds.textField(self.widgets["demFileTextField"], q = True, fi = True) jams_file = cmds.textField(self.widgets["jamsFileTextField"], q = True, fi = True) raw_wrf = cmds.checkBox(self.widgets["wrfCheckBox"], q=True, v=True) raw_dem = cmds.checkBox(self.widgets["demCheckBox"], q=True, v=True) if raw_wrf: if platform.system() == 'Windows': s = subprocess.check_output(["where", "python"], shell=True) else: s = subprocess.check_output(["which", "python"], shell=False) python_path = s.splitlines()[-1] script_dir = os.path.dirname(os.path.realpath(__file__)) winds_file = subprocess.check_output([python_path, script_dir + "\NetCDF_converter.py", map_file, winds_file], shell=False).rstrip() if raw_dem: if platform.system() == 'Windows': s = subprocess.check_output(["where", "python"], shell=True) else: s = subprocess.check_output(["which", "python"], shell=False) python_path = s.splitlines()[-1] script_dir = os.path.dirname(os.path.realpath(__file__)) heights_file = subprocess.check_output([python_path, script_dir + "\DEM_converter.py", map_file, heights_file], shell=False).rstrip() if cmds.objExists('city'): cmds.delete('city') def calc_emmiter_level(waypoints): if (jams_file == ""): return 0 jams_data = open(jams_file, 'r') sum_jams_level = 0 jams_points = 0 shift_lat = -0.00766 shift_lon = 0.006868 for waypoint in waypoints: for line in jams_data: tmp = line.split(' ') lon = float(tmp[0]) - shift_lon lat = float(tmp[1]) - shift_lat if lat < minlat or lat > maxlat or lon < minlon or lon > maxlon: continue data = float(tmp[2]) jams_point = convert_coordinates(lon, lat) dist = math.sqrt(math.pow(waypoint[0]-jams_point[0], 2)+math.pow(waypoint[2]-jams_point[2], 2)) if dist < (25.0/size_multiplier): sum_jams_level += data jams_points += 1 if jams_points >= (len(waypoints) * 0.5): return 1.0*sum_jams_level/jams_points else: return 0 jams_data.close() def convert_coordinates(lon, lat): centered_lat = (lat-minlat) - (maxlat-minlat)/2 centered_lon = (lon-minlon) - (maxlon-minlon)/2 normalized_lat = centered_lat * norm_lat normalized_lon = centered_lon * norm_lon return [normalized_lon, 0, -normalized_lat] #meters size_multiplier = float(cmds.textField(self.widgets["sizeMultTextField"], q = True, tx = True)) emit_multiplier = float(cmds.textField(self.widgets["emitMultTextField"], q = True, tx = True)) hasl = float(cmds.textField(self.widgets["haslTextField"], q = True, tx = True)) xmlData = xml.dom.minidom.parse(map_file) points_ids = [] points = [] heights = [] bounds = xmlData.getElementsByTagName("bounds")[0] minlat = float(bounds.getAttribute('minlat')) maxlat = float(bounds.getAttribute('maxlat')) minlon = float(bounds.getAttribute('minlon')) maxlon = float(bounds.getAttribute('maxlon')) dist_lon = self.coordinates_dist(minlon, minlat, maxlon, minlat) dist_lat = self.coordinates_dist(minlon, minlat, minlon, maxlat) norm_lat = (dist_lat/size_multiplier)/(maxlat-minlat) norm_lon = (dist_lon/size_multiplier)/(maxlon-minlon) #============================Get heights=================================== heights_data = open(heights_file, 'r') rows = 0 cols = 0 start_lon = 0 start_lat = 0 delta_lon = 0 delta_lat = 0 heights_matrix = [] for line in heights_data: tmp = line.strip().split(' ') if rows == 0: rows = float(tmp[0]) cols = float(tmp[1]) elif start_lon == 0: start_lon = float(tmp[0]) start_lat = float(tmp[1]) elif delta_lon == 0: delta_lon = float(tmp[0]) delta_lat = float(tmp[1]) else: row = [] for cell in tmp: row.append(int(cell)-hasl) heights_matrix.append(row) #========================================================================== maxprogress = 0 ways = xmlData.getElementsByTagName('way') for way in ways: tags = way.getElementsByTagName('tag') for tag in tags: tag_type = str(tag.getAttribute('k')) if (tag_type == 'highway'): subtype = str(tag.getAttribute('v')) if not(subtype == 'pedestrian') and not(subtype == 'steps') and not(subtype == 'footway') and not(subtype == 'cycleway'): maxprogress += 1 if (tag_type == 'building'): maxprogress += 1 progress = 0 cmds.progressWindow(title='Generating city', min = 0, max = maxprogress, progress = progress, status = 'Processing nodes', isInterruptable = False) #============================Handle nodes================================== nodes = xmlData.getElementsByTagName('node') for node in nodes: lat = float(node.getAttribute('lat')) lon = float(node.getAttribute('lon')) if lat < minlat or lat > maxlat or lon < minlon or lon > maxlon: continue point = convert_coordinates(lon, lat) points_ids.append(int(node.getAttribute('id'))) points.append(point) heights.append(heights_matrix[int(math.floor((lon-start_lon)/delta_lon))][int(math.floor((lat-start_lat)/delta_lat))]) #========================================================================== #=============================Handle ways================================== roads = 0 buildings = 0 emitter = 0 cmds.particle(n='nParticle') cmds.particle('nParticle', e=True, at='mass', order=0, fv=1e-5) cmds.setAttr('nParticleShape.lifespanMode', 2) cmds.setAttr('nParticleShape.lifespan', 6) cmds.setAttr('nParticleShape.lifespanRandom', 2) cmds.select('nParticleShape', r=True) cmds.addAttr(longName='betterIllumination', at='bool', defaultValue=False ) cmds.addAttr(longName='surfaceShading', at='float', defaultValue=0, minValue=0, maxValue=1) cmds.addAttr(longName='threshold', at='float', defaultValue=0, minValue=0, maxValue=10) cmds.addAttr(longName='radius', at='float', defaultValue=1, minValue=0, maxValue=20) cmds.addAttr(longName='flatShaded', at='bool', defaultValue=False) cmds.setAttr('nParticleShape.particleRenderType', 8) cmds.setAttr('nParticleShape.radius', 0.06) cmds.setAttr('particleCloud1.transparency', 0.53, 0.53, 0.53, type='double3') cmds.setAttr('particleCloud1.color', 1.0, 0.0, 0.483, type='double3') cmds.setAttr('particleCloud1.incandescence', 1.0, 0.0, 0.850, type='double3') cmds.setAttr('particleCloud1.glowIntensity', 0.111) ways = xmlData.getElementsByTagName('way') for way in ways: waypoints = [] heights_sum = 0 nodes = way.getElementsByTagName('nd') tags = way.getElementsByTagName('tag') for node in nodes: ref = int(node.getAttribute('ref')) try: index = points_ids.index(ref) except ValueError: index = -1 if index != -1: waypoints.append(points[index]) heights_sum += heights[index] for tag in tags: tag_type = str(tag.getAttribute('k')) if tag_type == 'highway': subtype = str(tag.getAttribute('v')) if not(subtype == 'pedestrian') and not(subtype == 'steps') and not(subtype == 'footway') and not(subtype == 'cycleway'): roads += 1 progress += 1 cmds.progressWindow(edit=True, progress = progress, status='Generating road: ' + str(roads)) lanes = 2 for tag in tags: tag_type = str(tag.getAttribute('k')) if tag_type == 'lanes': lanes = float(str(tag.getAttribute('v'))) if len(waypoints) >= 2: cmds.curve(n='pathcurve_' + str(roads), p=waypoints, d=1) sx = waypoints[0][0] sz = waypoints[0][2] dx = waypoints[0][2]-waypoints[1][2] dz = waypoints[1][0]-waypoints[0][0] ln = math.sqrt(math.pow(2*dx, 2) + math.pow(2*dz, 2)) dx /= (ln*size_multiplier)/(3*lanes) dz /= (ln*size_multiplier)/(3*lanes) ln = 0 for i in range(0, len(waypoints)-2): ln += math.trunc(math.sqrt(math.pow(waypoints[i+1][0]-waypoints[i][0], 2) + math.pow(waypoints[i+1][2]-waypoints[i][2], 2))) + 1 cmds.curve(n='extrudecurve_' + str(roads), p=[(sx-dx, 0, sz-dz), (sx+dx, 0, sz+dz)], d=1) cmds.rebuildCurve('pathcurve_' + str(roads), rt=0, s=200) cmds.nurbsToPolygonsPref(f=2, pt=1, ut=1, un=2, vt=1, vn=ln * 5 + 30) cmds.extrude('extrudecurve_' + str(roads), 'pathcurve_' + str(roads), n='road_' + str(roads), et=2, po=1) cmds.delete('extrudecurve_' + str(roads),) emitter_level = calc_emmiter_level(waypoints) if emitter_level > 0: emitter += 1 cmds.select('pathcurve_' + str(roads), r=True) cmds.move(0, 0.03, 0) cmds.emitter(n='emitter_' + str(emitter), type='omni', r=emit_multiplier*emitter_level, spd=0.1, srn=0, sp=0) cmds.connectDynamic('nParticle', em='emitter_' + str(emitter)) cmds.select('road_' + str(roads), r=True) cmds.move(0, 0.004, 0) elif tag_type == 'building': temp = str(tag.getAttribute('v')) if temp == 'yes': buildings += 1 progress += 1 cmds.progressWindow(edit=True, progress = progress, status='Generating building: ' + str(buildings)) if len(waypoints) >= 3: cmds.polyCreateFacet(n='building_' + str(buildings), p=waypoints) cmds.select('building_' + str(buildings), r=True) normal = cmds.polyInfo(fn=True)[0].partition('0: ')[2].split(' ')[1] if float(normal) < 0: cmds.polyMirrorFace(direction=2, p=(0, 0, 0), mergeMode=0, worldSpace=1) cmds.polyDelFacet('building_' + str(buildings) + '.f[0]') avg_height = heights_sum / len(waypoints) cmds.polyExtrudeFacet('building_' + str(buildings) + '.f[0]', ltz=(1.0 * avg_height/size_multiplier)) cmds.select('building_' + str(buildings), r=True) cmds.collision('building_' + str(buildings), 'nParticle') #========================================================================== #============================Handle winds================================== winds_data = open(winds_file, 'r') winds = 0 cmds.progressWindow(edit=True, progress = progress, status='Setting winds') for line in winds_data: winds += 1 tmp = line.split(' ') lon = float(tmp[0]) lat = float(tmp[1]) x = float(tmp[2]) y = float(tmp[3]) z = float(tmp[4]) magn = math.sqrt(math.pow(x, 2) + math.pow(y, 2) + math.pow(z, 2)) max_dist = self.coordinates_dist(0, 0, 0.006364, 0.006364)/size_multiplier volume_size = self.coordinates_dist(0, 0, 0.0045, 0.0045)/size_multiplier position = convert_coordinates(lon, lat) cmds.air(n='wind_' + str(winds), pos=position, wns=True, dx=x, dy=y, dz=z, m=magn, s=1, mxd=max_dist) cmds.setAttr('wind_' + str(winds) + '.volumeShape', 1) cmds.setAttr('wind_' + str(winds) + '.volumeOffsetY', 1) cmds.scale(volume_size, volume_size/2, volume_size, 'wind_' + str(winds)) cmds.connectDynamic('nParticle', f='wind_' + str(winds)) cmds.select(cl=True) #========================================================================== cmds.gravity(n='gravity', m=9.8*1e-5) cmds.connectDynamic('nParticle', f='gravity') cmds.polyPlane(n='ground', sx=(maxlon-minlon), sy=(maxlat-minlat), w=(maxlon-minlon)*norm_lon, h=(maxlat-minlat)*norm_lat) cmds.collision('ground', 'nParticle') cmds.select('building_*', r=True) cmds.select('road_*', tgl=True) cmds.select('ground', tgl=True) cmds.select('nParticle', tgl=True) cmds.editRenderLayerGlobals(currentRenderLayer='AOLayer') cmds.editRenderLayerMembers('AOLayer') cmds.select('road_*', r=True) cmds.group(n='roads') cmds.select('building_*', r=True) cmds.group(n='buildings') cmds.select('pathcurve_*', r=True) cmds.group(n='emitters') cmds.select('roads', r=True) cmds.select('buildings', tgl=True) cmds.select('emitters', tgl=True) cmds.select('nParticle', tgl=True) cmds.select('gravity', tgl=True) cmds.select('ground', tgl=True) cmds.select('wind_1', tgl=True) cmds.group(n='city') xmlData.unlink() winds_data.close() heights_data.close() if raw_wrf: os.remove(winds_file) if raw_dem: os.remove(heights_file) cmds.progressWindow(endProgress = True)