예제 #1
0
	def _prep(self,args):
		basename=self.inputName.getText()
		nparticle=pm.ls(sl=True)[0]
		if not pm.objExists(self.inputBar.getText()):
			pm.error ('GEO plane doesn\'t exist')
		geo = pm.PyNode(self.inputBar.getText())
		if not isinstance(nparticle.getShape(), pm.nt.NParticle):
			pm.error('Your selection is not an nParticle object')
        #create an instancer
		tempCube=pm.polyCube(n='temp_iinst_GEO',w=.01,h=.01,d=.01,ch=0)
		

		self.instancer=pm.PyNode(pm.particleInstancer(nparticle,name=(nparticle.name().replace('_NPARTICLE','_INSTANCER')),addObject=True,object=tempCube[0],cycleStep=1,cycleStepUnits='Frames',levelOfDetail='Geometry',rotationUnits='Degrees',rotationOrder='XYZ',position='worldPosition',rotation='rotPP',scale='scalePP',objectIndex='indexPP'))

		pm.delete(tempCube)
		#group the nparticle + instancer
		group=pm.group(n=(nparticle.name().replace('_NPATICLE','_lodA_GRP')))
		nparticle.setParent(group)
		self.instancer.setParent(group)
        #nCache itR
		
		if not pm.objExists( nparticle.name().replace('_NPARTICLE','_NUCLEUS') ):
			pm.error('Nucleus doesn\'t exist!')
		nucleus = nparticle.name().replace('_NPARTICLE','_NUCLEUS')
        #delete everything unnecessary that might cause issues
		print geo, nucleus
		print 'issue?'
		pm.delete(geo, nucleus)
		print 'issue?'
		pm.select(nparticle)
		mm.eval('performCreateNclothCache 1 \"add\";')
		pm.confirmDialog(m='WARNING, DO NOT SAVE AFTER THIS STEP',t='DONT SAVE!')
예제 #2
0
    def createParticleEmitter(self, meshEmitter, collider):

        # Force nParticle balls at creation
        pm.optionVar(sv=("NParticleStyle", "Balls"))

        self.particle, self.partShape = pm.nParticle(n=str(meshEmitter) + "_particle")
        # Add attribute in particleShape
        pm.addAttr(self.partShape, ln="indexPP", dt="doubleArray")
        pm.addAttr(self.partShape, ln="rotatePP", dt="vectorArray")
        pm.addAttr(self.partShape, ln="scalePP", dt="vectorArray")
        pm.addAttr(self.partShape, ln="rgbPP", dt="vectorArray")
        pm.addAttr(self.partShape, ln="fixPosPP", dt="vectorArray")
        pm.addAttr(self.partShape, ln="opacityPP", dt="doubleArray")

        pm.addAttr(self.partShape, ln="typePP", dt="doubleArray")

        self.nameEmitter = str(meshEmitter) + "_emitter"
        pm.emitter(meshEmitter, type="surface", name=self.nameEmitter, r=float(self.ui.simulationEmit_le.text()))
        pm.connectDynamic(self.partShape, em=self.nameEmitter)

        # Used maya command because pymel crash when find nucleus node
        self.nucleusName = mel.eval('listConnections -type "nucleus" ' + self.partShape + ";")[0]

        pm.parent(self.partShape, self.worldParent)
        pm.parent(self.nameEmitter, self.worldParent)
        pm.parent(self.nucleusName, self.worldParent)

        self.setParamaters(self.partShape, self.particleParameter)
        self.setParamaters(self.nameEmitter, self.emitterParameter)
        self.setParamaters(self.nucleusName, self.nucleusParameter)
        pm.addAttr(self.partShape, ln="radiusPP", dt="doubleArray")

        # Create Rigid
        pm.select(collider, r=1)
        pm.runtime.nClothMakeCollide(collider)
        self.nrigid = pm.listConnections(collider.listRelatives(s=1, c=1)[0], type="nRigid")[0]
        self.setParamaters(self.nrigid.listRelatives(s=1, c=1)[0], self.rigidParameter)
        pm.parent(self.nrigid, self.worldParent)
        self.nrigid.setAttr("v", 0)

        # Create instancer
        self.instancer = pm.particleInstancer(
            self.partShape,
            a=True,
            object=self.listInstance,
            n=str(meshEmitter) + "_instancer",
            cycle="sequential",
            age="indexPP",
            rotation="rotatePP",
            scale="scalePP",
            visibility="opacityPP",
        )
        pm.parent(self.instancer, self.worldParent)

        # Create proc Colision
        expression = """
global proc forestGeneratorEvent(string $particleObject,int $particleId, string  $geometryObject) 
{

    vector $rgb = `nParticle -attribute rgbPP -id $particleId -q $particleObject`;

    if ($rgb != << 1,1,1 >>)
    {
        nParticle -e -attribute rgbPP -id $particleId -vv 0 1 0 $particleObject;
    }
    
    vector $pos = `nParticle -attribute position -id $particleId -q $particleObject`;
    
    vector $lastPos = `nParticle -attribute lastPosition -id $particleId -q $particleObject`;
    
    
    
    nParticle -e -attribute opacityPP -id $particleId -fv 1 $particleObject;

    if (mag($pos - $lastPos) >= 10 && $rgb != << 1,1,1 >>){
    
        nParticle -e -attribute lifespanPP -id $particleId -fv 0 $particleObject;
    }
}"""
        pm.expression(s=expression, n="forestGenerator_exp")
        # Create  Colision event

        pm.event(self.partShape, die=0, count=0, proc="forestGeneratorEvent")
예제 #3
0
    def createParticleEmitter(self, meshEmitter, collider):

        # Force nParticle balls at creation
        pm.optionVar(sv=("NParticleStyle", "Balls"))

        self.particle, self.partShape = pm.nParticle(n=str(meshEmitter) +
                                                     "_particle")
        #Add attribute in particleShape
        pm.addAttr(self.partShape, ln="indexPP", dt="doubleArray")
        pm.addAttr(self.partShape, ln="rotatePP", dt="vectorArray")
        pm.addAttr(self.partShape, ln="scalePP", dt="vectorArray")
        pm.addAttr(self.partShape, ln="rgbPP", dt="vectorArray")
        pm.addAttr(self.partShape, ln="fixPosPP", dt="vectorArray")
        pm.addAttr(self.partShape, ln="opacityPP", dt="doubleArray")

        pm.addAttr(self.partShape, ln="typePP", dt="doubleArray")

        self.nameEmitter = str(meshEmitter) + "_emitter"
        pm.emitter(meshEmitter,
                   type="surface",
                   name=self.nameEmitter,
                   r=float(self.ui.simulationEmit_le.text()))
        pm.connectDynamic(self.partShape, em=self.nameEmitter)

        #Used maya command because pymel crash when find nucleus node
        self.nucleusName = mel.eval("listConnections -type \"nucleus\" " +
                                    self.partShape + ";")[0]

        pm.parent(self.partShape, self.worldParent)
        pm.parent(self.nameEmitter, self.worldParent)
        pm.parent(self.nucleusName, self.worldParent)

        self.setParamaters(self.partShape, self.particleParameter)
        self.setParamaters(self.nameEmitter, self.emitterParameter)
        self.setParamaters(self.nucleusName, self.nucleusParameter)
        pm.addAttr(self.partShape, ln="radiusPP", dt="doubleArray")

        #Create Rigid
        pm.select(collider, r=1)
        pm.runtime.nClothMakeCollide(collider)
        self.nrigid = pm.listConnections(collider.listRelatives(s=1, c=1)[0],
                                         type='nRigid')[0]
        self.setParamaters(
            self.nrigid.listRelatives(s=1, c=1)[0], self.rigidParameter)
        pm.parent(self.nrigid, self.worldParent)
        self.nrigid.setAttr("v", 0)

        #Create instancer
        self.instancer = pm.particleInstancer(self.partShape,
                                              a=True,
                                              object=self.listInstance,
                                              n=str(meshEmitter) +
                                              "_instancer",
                                              cycle="sequential",
                                              age="indexPP",
                                              rotation="rotatePP",
                                              scale="scalePP",
                                              visibility="opacityPP")
        pm.parent(self.instancer, self.worldParent)

        #Create proc Colision
        expression = """
global proc forestGeneratorEvent(string $particleObject,int $particleId, string  $geometryObject) 
{

    vector $rgb = `nParticle -attribute rgbPP -id $particleId -q $particleObject`;

    if ($rgb != << 1,1,1 >>)
    {
        nParticle -e -attribute rgbPP -id $particleId -vv 0 1 0 $particleObject;
    }
    
    vector $pos = `nParticle -attribute position -id $particleId -q $particleObject`;
    
    vector $lastPos = `nParticle -attribute lastPosition -id $particleId -q $particleObject`;
    
    
    
    nParticle -e -attribute opacityPP -id $particleId -fv 1 $particleObject;

    if (mag($pos - $lastPos) >= 10 && $rgb != << 1,1,1 >>){
    
        nParticle -e -attribute lifespanPP -id $particleId -fv 0 $particleObject;
    }
}"""
        pm.expression(s=expression, n="forestGenerator_exp")
        #Create  Colision event

        pm.event(self.partShape, die=0, count=0, proc="forestGeneratorEvent")
예제 #4
0
    def set_insAttr(self, **kwargs):

        pc.particleInstancer(self.nparticle, e=True, **kwargs)
예제 #5
0
def getPtcInstancer(ptcNode=''):
    ptcInst = pm.particleInstancer(ptcNode='', q=True, name=True)
    if ptcInst:
        return ptcInst[0]