def loopTime(): for time in range(int(timeMin),int(timeMax)): count = pm.particle(part,q = 1,ct = 1) for num in range(0,count): pt = part + '.pt[' + str(num) + ']' if pt not in ptList: ptList.append(pt) createCurve(pt) else : addCurvePoint(pt,curveList[num]) pm.currentTime(time + 1)
def particle_constraint(target, goal_weight, goal_smooth, start_offset): user_scene_time = maya_utils.scene_utils.get_scene_times() start_frame = user_scene_time[0] - abs(start_offset) lico_particle = pm.particle(name="lico_particle_dynamic", c=1, p=[0, 0, 0])[1] temp_locator_a = pm.spaceLocator(n="temp_locator_a", p=[0, 0, 0]) temp_locator_b = pm.spaceLocator(n="temp_locator_b", p=[0, 0, 0]) temp_locator_correction = pm.spaceLocator( n="temp_locator_orient_correction", p=[0, 0, 0]) pm.pointConstraint(target, temp_locator_correction, mo=False) pm.delete( pm.pointConstraint(temp_locator_correction, lico_particle.getParent(), offset=[0, 0, 2], mo=False)) pm.goal(lico_particle, w=0.5, utr=0, g=temp_locator_correction) lico_particle.worldCentroid >> temp_locator_a.translate dynamic_scene_time = (start_frame, start_frame, user_scene_time[2], user_scene_time[3]) maya_utils.scene_utils.set_scene_times(dynamic_scene_time) lico_particle.goalWeight[0].set(goal_weight) lico_particle.goalSmoothness.set(goal_smooth) lico_particle.startFrame.set(start_frame) delete_constraint = pm.parentConstraint(temp_locator_a, temp_locator_b, mo=False) maya_utils.baking.bake_objects([temp_locator_b], True, True, True, simulation=True) pm.delete(delete_constraint) maya_utils.scene_utils.set_scene_times(user_scene_time) return [ lico_particle, temp_locator_a, temp_locator_b, temp_locator_correction ]
def importAgisoftDenseCloud(path=None): showProgWin = 1 cws = cmds.workspace(q=1 ,fn=1) title = 'Import Agisoft Dense Cloud' rFile = [path] if path else cmds.fileDialog2(cap=title, dir=cws, fm=1, ff='Text Files (*.txt)') if rFile: rFile = rFile[0] name = "Agisoft_Ptc_1" #mel.eval('particle') #mel.eval('rename "Agisoft_Ptc_1"') #p = cmds.ls(sl=1, l=1) #cmds.select(clear=1) fileLength = len(open(rFile,'r').read().split('\n')) if showProgWin == 1: title = 'Import Agisoft Dense Cloud' inc = 1 max = 100 progWin = cmds.window(t=title, w=350, h=20, s=0) cmds.showWindow(progWin) cmds.columnLayout(progWin) progBar = cmds.progressBar(max=max, w=350, h=20) cmds.progressBar(progBar, e=1, s=1) positions = list() colors = list() f = open(rFile, 'r') for line in f: val = line.split() positions.append((float(val[0]), float(val[1]), float(val[2]))) colors.append((float(val[3])/256, float(val[4])/256, float(val[5])/256)) ''' pX = str(val[0]) pY = str(val[1]) pZ = str(val[2]) cR = str(float(val[3])/256) cG = str(float(val[4])/256) cB = str(float(val[5])/256) emitStr = ('emit -object ' + pShape + '-pos ' + pX + ' ' + pY + ' ' + pZ + ' -at rgbPP -vv ' + cR + ' ' + cG + ' ' +cB) mel.eval(emitStr) ''' if showProgWin == 1: if inc>=(fileLength/max): cmds.progressBar(progBar, e=1, s=1) cmds.refresh(progBar) mel.eval('viewFit') inc=1 inc+=1 f.close() #pm.particle(p, e=True, position=positions, attribute='rgbPP', vectorValue=colors) created = pm.particle(name=name, position=positions) print created ''' pShape = cmds.listRelatives(p, f=1, typ='shape') pShape = str(pShape[0]) cmds.addAttr(pShape, ln='rgbPP', dt='vectorArray') cmds.addAttr(pShape, ln='rgbPP0', dt='vectorArray') cmds.saveInitialState(pShape, atr=('pos', 'rgbPP')) cmds.disconnectAttr('time1.outTime', (pShape + '.currentTime')) ''' if showProgWin == 1: cmds.progressBar(progBar, ep=1) cmds.deleteUI(progWin, wnd=1)
test = pm.selected() #particle geo sphere creation import pymel.core as pm curve_selection = pm.selected() data_position_list = [] curve_root_list = [] yeti_outerRadius = [] for curve in curve_selection: cv_root = pm.PyNode(curve.name() + '.cv[0]') curve_root_list.append(cv_root) for root in curve_root_list: data_position = root.getPosition(space='world') data_position_list.append(data_position) clean_particle_group = pm.createNode( 'transform', name='Yeti_OutterRadius_grp', ) for number, position in enumerate(data_position_list): particle = pm.particle(p=[0, 0, 0], name=curve_selection[number].name() + '_' + str(number) + '_particle') particle[0].translate.set(position) particle[1].particleRenderType.set(4) pm.parent(particle[0], clean_particle_group)
def run(sliderSize, sliderDensity, sliderHeight, textSequence, ckboxTexture, ckboxSequence, ckboxCover, directionX, directionY, directionZ, snowPieceBrowser): ''' This function is the main function to generate the snowy scene. Args: avgSize from sliderSize: The average size of all snow piece density from sliderDensity: The density of the snow maxDistance from sliderHeight: The highest distance the user want the snow to fall snowTexture from ckboxTexture: Whether using the texture for snowflakes snowSequence from textSequence: The length of the sequence of images as texture directionX: directionX of gravity field directionY: directionX of gravity field directionZ: directionX of gravity field coverFlag(coverObj) from ckboxCover: Decide whether the snow will cover the models and which models to cover windFlag(windDirection, windStrength): Decide whether there are winds and the directions and strength GLobal variables used: startArea: The surface area the user want the snow fall from snowPath: The file path of the snowflake texture coverObj: The objects the particles will make collision with Result: a generated snowy scene animation Return: none ''' ## check whether the user has selected the start Area if isset('startArea') == 0: logger.error('Please choose a plane to start snow!') pm.PopupError('Please choose a plane to start snow!') return ## check whether the user has selected the objects to make collision with if ckboxCover.getValue(): if isset('coverObj') == 0: logger.error('Please select the objects to make collision with!') pm.PopupError('Please select the objects to make collision with!') return ## check whether the user has selected files for textures snowPath = snowPieceBrowser.getText() if ckboxTexture.getValue(): if snowPath == '': logger.error('Please select the images for textures!') pm.PopupError('Please select the images for textures!') return logger.info('Start generating the snowy scene') snowSize = sliderSize.getValue() snowDensity = sliderDensity.getValue() snowHeight = sliderHeight.getValue() snowTexture = ckboxTexture.getValue() snowSequenceTmp = textSequence.getText() snowSequence = int(snowSequenceTmp) gdXs = directionX.getText() gdYs = directionY.getText() gdZs = directionZ.getText() gdX = float(gdXs) gdY = float(gdYs) gdZ = float(gdZs) pm.playbackOptions(ps = 0.4) offsetSize = snowSize * 0.3 minSize = snowSize - offsetSize maxSize = snowSize + offsetSize startFace = startArea emitter1 = pm.emitter(startFace, sro = True, type = 'surface', rate = snowDensity, minDistance = 0.5, mxd = 1) particle_snow2 = pm.particle() pm.connectDynamic(particle_snow2, em = emitter1) ## using image textures for particles if ckboxTexture.getValue(): logger.info(' particle render type: sprite ') pm.setAttr('%s.particleRenderType'%particle_snow2[0], 5) pm.addAttr(particle_snow2[1], internalSet = True, longName = 'spriteTwist', attributeType = 'float', minValue = -180, maxValue = 180, defaultValue = 0.0) pm.addAttr(particle_snow2[1], internalSet = True, ln = 'spriteScaleX', dv = 0.2) pm.addAttr(particle_snow2[1], internalSet = True, ln = 'spriteScaleY', dv = 0.2) pm.addAttr(particle_snow2[1], internalSet = True, ln = 'spriteNum', at = 'long', dv = 1) pm.addAttr(particle_snow2[1], internalSet = True, ln = 'useLighting', at = 'bool',dv = False) shader2 = pm.shadingNode('lambert', asShader = True) file_node2 = pm.shadingNode('file', asTexture = True) pm.setAttr('%s.fileTextureName'%file_node2, snowPath, type = 'string') shading_group2 = pm.sets(renderable = True, noSurfaceShader = True, empty = True) pm.setAttr('%s.ambientColor'%shader2, 1.0, 1.0, 1.0, type = 'double3') pm.connectAttr('%s.outColor'%shader2, '%s.surfaceShader'%shading_group2, force = True) pm.connectAttr('%s.outColor'%file_node2, '%s.color'%shader2, force = True) pm.connectAttr('%s.outTransparency'%shader2, '%s.surfaceShader'%shading_group2, force = True) pm.connectAttr('%s.outTransparency'%file_node2, '%s.transparency'%shader2, force = True) pm.sets(shading_group2, e = True, forceElement = '%s'%particle_snow2[0]) if ckboxSequence.getValue(): pm.setAttr('%s.useFrameExtension'%file_node2, 1) pm.setAttr('%s.useHardwareTextureCycling'%file_node2, 1) pm.setAttr('%s.endCycleExtension'%file_node2, snowSequence) pm.addAttr(particle_snow2[1], dataType = 'doubleArray', ln = 'spriteScaleXPP') pm.addAttr(particle_snow2[1], dataType = 'doubleArray', ln = 'spriteScaleXPP0') pm.addAttr(particle_snow2[1], dataType = 'doubleArray', ln = 'spriteScaleYPP') pm.addAttr(particle_snow2[1], dataType = 'doubleArray', ln = 'spriteScaleYPP0') pm.addAttr(particle_snow2[1], dataType = 'doubleArray', ln = 'spriteTwistPP') pm.addAttr(particle_snow2[1], dataType = 'doubleArray', ln = 'spriteTwistPP0') pm.dynExpression(particle_snow2[1], s = 'spriteScaleXPP = rand(%f,%f);\nspriteScaleYPP = spriteScaleXPP;\nspriteTwistPP = rand(0,30);'%(minSize, maxSize), c = True) if ckboxSequence.getValue(): pm.addAttr(particle_snow2[1], dataType = 'doubleArray', ln = 'spriteNumPP') pm.addAttr(particle_snow2[1], dataType = 'doubleArray', ln = 'spriteNumPP0') pm.dynExpression(particle_snow2[1], s = 'spriteScaleXPP = rand(%f,%f);\nspriteScaleYPP = spriteScaleXPP;\nspriteTwistPP = rand(0,30);\nspriteNumPP = rand(0,%f);\nspriteNumPP = (spriteNumPP+1)%%%f;'%(minSize, maxSize, snowSequence, snowSequence+1), c = True) ## don't using textures else: logger.info(' particle render type: cloud ') pm.setAttr('%s.particleRenderType'%particle_snow2[0], 8) pm.addAttr(particle_snow2[1], dataType = 'doubleArray', ln = 'radiusPP') pm.addAttr(particle_snow2[1], dataType = 'doubleArray', ln = 'radiusPP0') pm.addAttr(particle_snow2[1], dataType = 'vectorArray', ln = 'rgbPP') pm.addAttr(particle_snow2[1], dataType = 'vectorArray', ln = 'rgbPP0') pm.dynExpression(particle_snow2[1], s = 'radiusPP = rand(%f,%f);\nrgbPP = <<1,1,1>>;'%(minSize, maxSize), c = True) ## if make collision if ckboxCover.getValue(): for j in range(len(coverObj)): pm.collision(coverObj[j], particle_snow2[1], r = 0, f = 1) ## add gravity snowGravity = pm.gravity('%s'%particle_snow2[0], dx = gdX, dy = gdY, dz = gdZ, magnitude = 1.0) pm.connectDynamic('%s'%particle_snow2[0], f = snowGravity) logger.info('Scene generation finished!') return
def freezeParticles() : part = pm.selected()[0].getShape(type='particle') pts = [p.position for p in part.points] newpart = pm.particle(p=pts) print('[freezeParticles]:%s' % created.newpart)
def makeWord(self, in_word): """ create particle word""" # in_word='maya' # font = 'Arial' # font = self.fontChoose.currentFont() # print self.font[-1] tCrvs = pm.textCurves(t=in_word, f=self.font, ch=0) tCrvs = pm.PyNode(tCrvs[0]) letterNum = tCrvs.numChildren() letter = [] grpWord = pm.group(em=True) for n in range(0, letterNum): letterShape = pm.listRelatives(tCrvs.getChildren()[n], type='nurbsCurve', ad=True, path=True) letter.append( pm.planarSrf(letterShape, ch=1, tol=0.01, o=1, po=1)[0]) pm.parent(letter, grpWord) # pm.select(grpWord) wordshape = pm.polyUnite(ch=1, muv=1)[0] mc.DeleteHistory() wordshape = pm.PyNode(wordshape) self.word.append(wordshape) # see(wordshape) pm.setAttr(tCrvs + ".visibility", 0) wordshape.centerPivots() # pm.move(-8,0,0) pm.makeIdentity(apply=True, t=1, r=1, s=1, n=0, pn=1) wordshape.makeLive() wordshape.select() pm.emitter(type='surface', r=1000, spd=0) wordEmitter = wordshape.getChildren()[1] wordEmitter = pm.PyNode(wordEmitter) wordEmitter.cycleEmission.set(1) wordEmitter.maxDistance.set(5) # see(wordEmitter) # wordEmitter.select() wordParticle = pm.particle()[0] wordParticle = pm.PyNode(wordParticle) wordPaShape = wordParticle.getShape() self.wordPar.append(wordPaShape) pm.connectDynamic(wordParticle, em=wordEmitter) mc.setKeyframe([wordEmitter + ".rate"], v=200, t=100) mc.setKeyframe([wordEmitter + ".rate"], v=0, t=101) wordPaShape.lifespanMode.set(2) wordPaShape.attr("lifespan").set(5) wordPaShape.lifespanRandom.set(3) wordPaShape.particleRenderType.set(0) wordPaShape.addAttr('colorAccum', dv=True, at='bool', internalSet=True, keyable=True) wordPaShape.addAttr('useLighting', dv=False, at='bool', internalSet=True) wordPaShape.addAttr('multiCount', at='long', min=1, max=60, dv=2, internalSet=True) wordPaShape.addAttr('multiRadius', at='float', min=1, max=60, dv=0.3, internalSet=True) wordPaShape.addAttr('normalDir', min=1, max=3, at='long', internalSet=True, dv=2) wordPaShape.addAttr('pointSize', min=1, max=60, at='long', internalSet=True, dv=2) wordPaShape.colorAccum.set(1) wordPaShape.multiCount.set(7) wordPaShape.pointSize.set(1) wordPaShape.addAttr('goalU', dt='doubleArray', keyable=True) wordPaShape.addAttr('goalV', dt='doubleArray', keyable=True) pm.dynExpression(wordPaShape, s='goalU=rand(0,1);\ngoalV=rand(0,1);', c=1) wordPaShape.addAttr('rgbPP', dt='vectorArray', keyable=True) pm.dynExpression(wordPaShape, s='rgbPP=position;', rbd=1) pm.goal(wordParticle, g=wordshape, w=1, utr=0) pm.setKeyframe(wordParticle, attribute='goalWeight[0]', v=1, t=90) pm.setKeyframe(wordParticle, attribute='goalWeight[0]', v=0, t=100) pm.setAttr(wordshape + ".visibility", 0) field = pm.turbulence(pos=(0, 0, 2), m=10) pm.connectDynamic(wordParticle, f=field) pm.setKeyframe(field, attribute='tx', v=12, t=100) pm.setKeyframe(field, attribute='tx', v=0, t=110) pm.parent(field, wordshape) lambert = pm.shadingNode('lambert', asShader=1) lambertSG = pm.sets(renderable=True, empty=1, noSurfaceShader=True, name=lambert + "SG") pm.connectAttr(lambert + ".outColor", lambert + "SG.surfaceShader", f=1) # pm.sets(wordParticle,forceElement='lambert6SG',e=True) wordParticle.select() pm.hyperShade(a=lambertSG) self.wordTexture.append(lambert) pm.setAttr(lambert + ".transparency", 0.7, 0.7, 0.7, type='double3') pm.setAttr(lambert + ".incandescence", 0.6, 0.6, 0.6, type='double3') pm.setAttr(lambert + ".incandescence", 0.5, 0.5, 0.5, type='double3') pm.setAttr(lambert + ".glowIntensity", 0.6) wordshape.select()
def ph_mainCode(extraHeight, particleRate, getInitialInfo, minSlope, minSlopeVariance, setBoundingBox, maxTilt, objectScale, objectScaleVariance, objectHeightVariance): displayWindow = True windowError = py.window(title="Notice", mxb=False, s=False) errorLayout = py.rowColumnLayout(numberOfColumns=3, parent=windowError) #initialise varibables originalTime = py.currentTime(query=True) deleteCount = 0 decimalPoints = 2 #file validation storeSelection = py.ls(selection=True) try: validFile = True myfile = open('storedobjects.txt') objectList = myfile.readlines() myfile.close() py.select(clear=True) for i in range(len(objectList)): py.select(objectList[i], add=True) 1 / len(objectList) except: validFile = False #get original selection py.select(clear=True) for i in range(len(storeSelection)): py.select(storeSelection[i], add=True) #deselect non polygons if type(storeSelection[i]) != py.nodetypes.Transform: py.select(storeSelection[i], deselect=True) #deselect objects in the text file if getInitialInfo == False: for j in range(len(objectList)): selectionEdit = storeSelection[i] + objectList[j][ -2] + objectList[j][-1] if objectList[j] == selectionEdit: py.select(storeSelection[i], deselect=True) storeSelection = py.ls(selection=True) startTime = time() listOfPoints = [] totalNum = 0 if len(storeSelection) == 0: displayMessage = "Nothing is selected. Please select an object and try again." ph_displayWindow(displayWindow, displayMessage) elif getInitialInfo == True: #write to file selection = py.ls(selection=True) myfile = open('storedobjects.txt', 'w') for i in range(len(selection)): myfile.write("" + selection[i] + "\r\n") myfile.close() if len(selection) > 0: print str(len(selection)) + " object(s) successfully stored." if displayWindow == True: py.text(label=" ") py.text(label=" ") py.text(label=" ") py.text(label=" ") py.text(label=str(len(selection)) + " object(s) successfully stored.", align="center") py.text(label=" ") py.text(label=" ") py.text(label=" ") py.text(label=" ") py.showWindow() else: displayMessage = "Please select the objects you wish to store." ph_displayWindow(displayWindow, displayMessage) for i in range(len(storeSelection)): py.select(storeSelection[i], add=True) elif validFile == False: displayMessage = "Error with stored list. Please choose new object(s) to duplicate." ph_displayWindow(displayWindow, displayMessage) elif len(objectList) == 0: displayMessage = "No objects stored. Please choose new object(s) to duplicate." ph_displayWindow(displayWindow, displayMessage) else: for loops in range(len(storeSelection)): particleID = [] particleLoc = [] particleVelocity = [] #get information about selected object py.select(storeSelection[loops], r=True) originalObj = py.ls(selection=True) originalObjLoc = originalObj[0].getTranslation() originalObjX = originalObjLoc.x originalObjY = originalObjLoc.y originalObjZ = originalObjLoc.z #duplicate object to work on tempObj = py.instance(originalObj) #make emitter particleEmitter = py.emitter(n='tempEmitter', type='surface', r=particleRate * 24, sro=0, speed=0.0001) particles = py.particle(n='emittedParticles') py.connectDynamic('emittedParticles', em='tempEmitter') py.setAttr(particles[1] + '.seed[0]', rd.randint(0, sys.maxint)) #get list from file myfile = open('storedobjects.txt') objectList = myfile.readlines() objectListCopy = [] myfile.close() for i in range(len(objectList)): copyObj = py.duplicate(objectList[i]) objectListCopy.append(copyObj) #fixes the seed always being 0 py.currentTime(originalTime + 1, edit=True, update=True) py.currentTime(originalTime, edit=True, update=True) py.currentTime(originalTime + 1, edit=True, update=True) numOfParticles = particles[1].num() for i in range(numOfParticles): #get particle info particleInfo = particles[1].Point('emittedParticles', i) particleID.append(particleInfo) particleLoc.append(particleInfo.position) particleVelocity.append(particleInfo.velocity) for i in range(len(particleID)): #place objects randomNum = rd.randint(0, len(objectListCopy) - 1) instanceObj = objectListCopy[randomNum] dupObj = py.instance(instanceObj) yDir = particleVelocity[i][1] * 10000 #get height of object py.select(instanceObj, r=True) py.scale(1, 1, 1) height = py.ls(selection=True)[0].getBoundingBox().height() #reselect instance py.select(dupObj[0], r=True) py.move(dupObj[0], particleLoc[i][0], particleLoc[i][1] + extraHeight, particleLoc[i][2]) py.rotate(dupObj[0], rd.uniform(-maxTilt, maxTilt), rd.randint(0, 360), rd.uniform(-maxTilt, maxTilt), os=True) scaleX = rd.uniform(objectScale - objectScaleVariance, objectScale + objectScaleVariance) scaleY = rd.uniform(objectScale - (objectHeightVariance / 2), objectScale + objectHeightVariance) scaleZ = rd.uniform(objectScale - objectScaleVariance, objectScale + objectScaleVariance) py.scale(dupObj[0], scaleX, scaleY, scaleZ) if yDir <= rd.uniform(minSlope - minSlopeVariance, minSlope + minSlopeVariance): py.delete(dupObj) deleteCount = deleteCount + 1 else: listOfPoints.append(dupObj) #display percent completed maxValue = int(pow(len(particleID), 0.5)) if float(i / maxValue) == float(i) / maxValue: print str( int((float(i) * 100 / len(particleID)) * 100.0) / 100.0) + "% completed" totalNum = totalNum + numOfParticles #delete temp objects py.select(tempObj, 'tempEmitter', 'emittedParticles') py.delete() py.currentTime(originalTime, edit=True, update=True) for i in range(len(objectListCopy)): py.delete(objectListCopy[i][0]) #place objects in display layer py.select(clear=True) if len(listOfPoints) > 0: if setBoundingBox == True: displayLayerName = 'duplicatedObjectsBB' else: displayLayerName = 'duplicatedObjectsMesh' #add to display layer try: for i in range(len(listOfPoints)): py.editDisplayLayerMembers(displayLayerName, listOfPoints[i]) #create display layer first except: py.createDisplayLayer(noRecurse=True, name=displayLayerName) for i in range(len(listOfPoints)): py.editDisplayLayerMembers(displayLayerName, listOfPoints[i]) #display objects as bounding box if setBoundingBox == True: py.setAttr(displayLayerName + '.levelOfDetail', 1) py.setAttr(displayLayerName + '.color', 17) #add to group for i in range(len(listOfPoints)): py.select(listOfPoints[i][0], add=True) py.group(n='duplicatedObjectsGroup') #output time taken endTime = time() ph_timeOutput(startTime, endTime, decimalPoints) secondsDecimal, sec = ph_timeOutput(startTime, endTime, decimalPoints) displayMessage = str(totalNum - deleteCount) + " objects created in " + str( secondsDecimal) + str(sec) ph_displayWindow(displayWindow, displayMessage) #select original selection py.select(clear=True) for i in range(len(storeSelection)): py.select(storeSelection[i], add=True)