Ici mon objectif est de faire une simulation avec nParticles et d'y instancier un petit rig de sphere, première étape: faire la simu avec des nParticles Ball de mm taille que les spheres finals, deuxième étapes: récupérer les position de chaque particule a chaque image, troisième étapes: réattribuer ces positions a des locators (aussi nombreux que les particles) et pour finir parenter les rigs (ou autre node non simulable), dupliqué en bon nombre, aux locators.
En image:
pph264 from colin laubry on Vimeo.
et voici le script que j'ai du écrire pour faire tout cela.
#recuperation de la derniere image endFrame = cmds.playbackOptions(q = True, maxTime = True) #recuperation de la premiere image startFrame = cmds.playbackOptions(q = True, minTime = True) #recuperation de la selection, dans l'ordre nParticle Instance de base sel = cmds.ls(sl = True) part = sel[0] inst = sel[1] #nom des futurs instances dupliques new = ("newInstance_"+part+"_") #alignement et freeze de l'instance de base cmds.pointConstraint(part, inst, mo = False) cmds.pointConstraint(part, inst, rm = True) cmds.makeIdentity(inst, apply=True, t=1, r=1, s=1, n=0) #pour chaque frame for i in range(startFrame, endFrame): #deplacement du curseur de la timeline cmds.currentTime(i) #recuperation du nombre de particles nPart = cmds.nParticle(part, ct = True, q = True ) print i #pour chaque particle for j in range(1, nPart+1): #test de l'existence pour pas dupliquer a chaque frame if cmds.objExists((new+str(j))) == 0: #duplication de linstance de base dup = cmds.duplicate(inst, n = (new+str(j))) #recuperation de la position de chaque particle posPP = cmds.nParticle(part, at = 'position', id = j, q = True ) #Attribution de la position a linstance duplique cmds.setAttr((new+str(j)+".tx"), posPP[0]) cmds.setAttr((new+str(j)+".ty"), posPP[1]) cmds.setAttr((new+str(j)+".tz"), posPP[2]) #creation de keyframe cmds.setKeyframe(new+str(j)+".tx") cmds.setKeyframe(new+str(j)+".ty") cmds.setKeyframe(new+str(j)+".tz")
English Version:
My goal is to do a nParticles simulation and to instance a rig sphere on each particle, first i make the simulation with Ball particles who they are approximate the same size of your rig. Next i get the position of each particle on each frame, after i assign this position to locators (as like the particles number) and finaly i duplicate the rig sphere and parent it to locators.
exemple:
and here the script that i made:
#get the last frame endFrame = cmds.playbackOptions(q = True, maxTime = True) #get the first frame startFrame = cmds.playbackOptions(q = True, minTime = True) #get selection, in order: nParticles, instance object sel = cmds.ls(sl = True) part = sel[0] inst = sel[1] #future name of the duplicate instance new = ("newInstance_"+part+"_") #align and freeze the instance cmds.pointConstraint(part, inst, mo = False) cmds.pointConstraint(part, inst, rm = True) cmds.makeIdentity(inst, apply=True, t=1, r=1, s=1, n=0) #for each frame for i in range(startFrame, endFrame): #change current frame of the timeline cmds.currentTime(i) #get particle count nPart = cmds.nParticle(part, ct = True, q = True ) print i #for each particle for j in range(1, nPart+1): #try instance existence for not duplicate on each frame if cmds.objExists((new+str(j))) == 0: #duplicate the instance dup = cmds.duplicate(inst, n = (new+str(j))) #get position for each particle posPP = cmds.nParticle(part, at = 'position', id = j, q = True ) #set th eposition to duplicates instances cmds.setAttr((new+str(j)+".tx"), posPP[0]) cmds.setAttr((new+str(j)+".ty"), posPP[1]) cmds.setAttr((new+str(j)+".tz"), posPP[2]) #set keyframe cmds.setKeyframe(new+str(j)+".tx") cmds.setKeyframe(new+str(j)+".ty") cmds.setKeyframe(new+str(j)+".tz")
Aucun commentaire:
Enregistrer un commentaire