Пример #1
0
def particlesToTypePivotPoints():
    selectedObjects = maya.cmds.ls(sl=True)
    if len(selectedObjects) == 0:
        cmds.error("Please select a Type Object")

    for sel in selectedObjects:
        createdSystem = cmds.nParticle()

        selNodeType = cmds.nodeType(sel)
        if selNodeType == "type":
            bboxMinArray = cmds.getAttr(sel + ".characterBoundingBoxesMin")
            bboxMaxArray = cmds.getAttr(sel + ".characterBoundingBoxesMax")

        for i in range(0, len(bboxMinArray), 1):
            thisMin = bboxMinArray[i]
            thisMax = bboxMaxArray[i]

            particleX = thisMin[0] + ((thisMax[0] - thisMin[0]) * 0.5)
            particleY = thisMin[1] + ((thisMax[1] - thisMin[1]) * 0.5)
            particleZ = thisMin[2] + ((thisMax[2] - thisMin[2]) * 0.5)

            #cmds.spaceLocator(p=(particleX, particleY, particleZ))

            cmds.emit(object=createdSystem[0],
                      position=((particleX, particleY, particleZ)))

        setDynStartState
        animationNode = cmds.listConnections(sel + '.animationMessage',
                                             d=True,
                                             s=True)[0]
        cmds.connectAttr(createdSystem[1] + '.positions',
                         animationNode + '.positionInPP')
def dsEmitAlongLocator(start,end,ss):
    y = start
    x = end
    cmds.currentTime(y)
    
    locX = cmds.getAttr('locator1.translateX')
    locY = cmds.getAttr('locator1.translateY')
    locZ = cmds.getAttr('locator1.translateZ')
    beforePos = [locX,locY,locZ]
    
    while y <= x:
        cmds.currentTime(y)
        locX = cmds.getAttr('locator1.translateX')
        locY = cmds.getAttr('locator1.translateY')
        locZ = cmds.getAttr('locator1.translateZ')
        pos = [locX,locY,locZ]
        
        dist = [pos[0]-beforePos[0],pos[1]-beforePos[1],pos[2]-beforePos[2]]
        val = [dist[0]/ss,dist[1]/ss,dist[2]/ss]

        for i in range(ss):
            beforePos = [beforePos[0]+val[0],beforePos[1]+val[1],beforePos[2]+val[2]]
            cmds.emit( object='trail_pt', pos=(beforePos))
            
        beforePos = pos
        y = y + 1
Пример #3
0
def locatorParticles(locList,
                     particle,
                     radius=1,
                     selfCollide=False,
                     rotatePP=False,
                     scalePP=False):
    """
    """
    # Check locator list
    if not locList: return

    # Check particles
    if not particle: particle = 'particle1'
    if not cmds.objExists(particle):
        particle = cmds.nParticle(n=particle)[0]

    # Set Particle Object Attrs
    cmds.setAttr(particle + '.particleRenderType', 4)
    cmds.setAttr(particle + '.radius',
                 cmds.floatSliderGrp('locParticle_radiusFSG', q=True, v=True))
    cmds.setAttr(
        particle + '.selfCollide',
        cmds.checkBoxGrp('locParticle_selfCollideCBG', q=True, v1=True))

    # Create particles
    ptList = [cmds.pointPosition(i) for i in locList]
    cmds.emit(o=particle, pos=ptList)

    # Add and Set RotatePP/ScalePP Values
    if rotatePP:

        # Check rotatePP attrs
        if not cmds.objExists(particle + '.rotatePP'):
            addRotatePP(particle)

        # Set rotatePP attrs
        for i in range(len(locList)):
            rot = cmds.getAttr(locList[i] + '.r')
            cmds.particle(particle, e=True, at='rotatePP', id=i, vv=rot[0])

    if scalePP:

        # Check scalePP attrs
        if not cmds.objExists(particle + '.scalePP'):
            addScalePP(particle)

        # Set scalePP attrs
        for i in range(len(locList)):
            scl = cmds.getAttr(locList[i] + '.s')
            cmds.particle(particle, e=True, at='scalePP', id=i, vv=scl[0])

    # Save Initial State
    cmds.saveInitialState(particle)
Пример #4
0
def locatorParticles(locList, particle, radius=1, selfCollide=False, rotatePP=False, scalePP=False):
    """
    """
    # Check locator list
    if not locList: return

    # Check particles
    if not particle: particle = 'particle1'
    if not cmds.objExists(particle):
        particle = cmds.nParticle(n=particle)[0]

    # Set Particle Object Attrs
    cmds.setAttr(particle + '.particleRenderType', 4)
    cmds.setAttr(particle + '.radius', cmds.floatSliderGrp('locParticle_radiusFSG', q=True, v=True))
    cmds.setAttr(particle + '.selfCollide', cmds.checkBoxGrp('locParticle_selfCollideCBG', q=True, v1=True))

    # Create particles
    ptList = [cmds.pointPosition(i) for i in locList]
    cmds.emit(o=particle, pos=ptList)

    # Add and Set RotatePP/ScalePP Values
    if rotatePP:

        # Check rotatePP attrs
        if not cmds.objExists(particle + '.rotatePP'):
            addRotatePP(particle)

        # Set rotatePP attrs
        for i in range(len(locList)):
            rot = cmds.getAttr(locList[i] + '.r')
            cmds.particle(particle, e=True, at='rotatePP', id=i, vv=rot[0])

    if scalePP:

        # Check scalePP attrs
        if not cmds.objExists(particle + '.scalePP'):
            addScalePP(particle)

        # Set scalePP attrs
        for i in range(len(locList)):
            scl = cmds.getAttr(locList[i] + '.s')
            cmds.particle(particle, e=True, at='scalePP', id=i, vv=scl[0])

    # Save Initial State
    cmds.saveInitialState(particle)
def readASC(ascPath,partObj):
    print ascPath
    ascFile = open(ascPath, 'r')
    tmpDict = {}
    
    for line in ascFile:
        if re.search("frame",line):
            tmpList = line.split(" ")
            frame = tmpList[-1].rstrip('\n')
        if re.search("particles",line):
            tmpList = line.split(" ")
            particles=tmpList[-1].rstrip('\n')
        lineList = line.split(" ")
        if len(lineList) == 10:
            objDict = {}
            objDict['id'] = lineList[0]
            objDict['x'] = lineList[1]
            objDict['y'] = lineList[2]
            objDict['z'] = lineList[3]
            objDict['vx'] = lineList[4]
            objDict['vy'] = lineList[5]
            objDict['vz'] = lineList[6]
            objDict['radius'] = lineList[7]
            objDict['density'] = lineList[8]
            objDict['pressure'] = lineList[9].rstrip("\r\n")
            tmpDict[lineList[0]] = objDict
    cmds.currentTime(int(frame))
    
    for key in tmpDict.values():
        particleId = key['id']
        particleX = key['x']
        particleY = key['y']
        particleZ = key['z']
        try:  
            if testParticle(partObj,int(particleId)) == 0:
               cmds.emit( object=partObj, pos=(float(particleX),float(particleY),float(particleZ)))
            else:
               cmds.particle( partObj, e=True, attribute='position', id=int(particleId), vectorValue= (float(particleX),float(particleY),float(particleZ)))
        except:
            pass
    ascFile.close()
Пример #6
0
def loadShotPoints(sector, *args):
    '''This function will load the generated point cloud in Maya via Houdini Engine.
	It will then copy each point and their attribute to a new point cloud to get rid of Houdini Engine.'''

    # Load Houdini Engine
    if loadHoudiniEngine() == False:
        return

    # Check if point bgeo file exists
    # currentWorkspace = os.path.abspath(cmds.workspace(sn=True,q=True))
    # currentShot = str(os.path.split(currentWorkspace)[1])
    # bgeoPath = '//Merlin/3d4/skid/05_shot/%s/geo/fileCache/%s_instancerPts.bgeo.sc'%(currentShot,currentShot)
    bgeoPath = '//Merlin/3d4/skid/04_asset/set/setForest/geo/pointCloud_sector%s.bgeo.sc' % sector

    # Set persp far clip plane
    cmds.setAttr('perspShape.farClipPlane', 1000000)

    # Set current time to first frame
    fstart = cmds.playbackOptions(ast=True, q=True)
    cmds.currentTime(fstart)

    # Load the bgeo importer
    toolBgeoToMaya = os.path.abspath(
        '//merlin/3d4/skid/04_asset/hda/toolBgeoToMaya_v2.hdanc')
    cmds.houdiniAsset(la=[toolBgeoToMaya, 'Object/toolBgeoToMaya'])
    # Set file path to shot points
    cmds.setAttr('toolBgeoToMaya1.houdiniAssetParm.houdiniAssetParm_file',
                 bgeoPath,
                 type="string")
    # Sync asset
    # cmds.evalDeferred('cmds.houdiniAsset(syn="toolBgeoToMaya1")')
    cmds.houdiniAsset(syn="toolBgeoToMaya1")

    # Duplicate point cloud to get rid of houdini engine
    pointCloud = 'file_bgeoToMaya_0'
    pointCloud_s = pointCloud + 'Shape'

    # Get particle count
    nbPart = cmds.particle(pointCloud, q=True, ct=True)

    # Create new particle system with suffix
    tmp = cmds.particle(n=pointCloud + '_dupli')
    dupliPartXf = tmp[0]
    dupliPartShp = tmp[1]

    cmds.setAttr(dupliPartShp + '.isDynamic', False)

    # Create rgbPP attribute on the new system
    cmds.addAttr(dupliPartShp, ln='rgbPP', dt='vectorArray')
    cmds.addAttr(dupliPartShp, ln='rgbPP0', dt='vectorArray')
    # Create radiusPP attribute
    cmds.addAttr(dupliPartShp, ln='radiusPP', dt='doubleArray')
    cmds.addAttr(dupliPartShp, ln='radiusPP0', dt='doubleArray')
    # Create index attribute
    cmds.addAttr(dupliPartShp, ln='index', dt='doubleArray')
    cmds.addAttr(dupliPartShp, ln='index0', dt='doubleArray')

    # Fill new particle system with positions
    for i in range(nbPart):
        wPos = cmds.getParticleAttr('%s.pt[%s]' % (pointCloud_s, i),
                                    at='position',
                                    array=True)
        cmds.emit(o=dupliPartXf, pos=[wPos[0], wPos[1], wPos[2]])

    # Transfer rgbPP
    for i in range(nbPart):
        attrValue = cmds.getParticleAttr('%s.pt[%s]' % (pointCloud_s, i),
                                         at='rgbPP',
                                         array=True)
        cmds.particle(e=True,
                      at='rgbPP',
                      order=i,
                      vectorValue=[attrValue[0], attrValue[1], attrValue[2]])

    # Transfer radiusPP
    for i in range(nbPart):
        attrValue = cmds.getParticleAttr('%s.pt[%s]' % (pointCloud_s, i),
                                         at='radiusPP',
                                         array=True)
        cmds.particle(e=True, at='radiusPP', order=i, floatValue=attrValue[0])

    # Transfer index
    for i in range(nbPart):
        attrValue = cmds.getParticleAttr('%s.pt[%s]' % (pointCloud_s, i),
                                         at='index',
                                         array=True)
        cmds.particle(e=True, at='index', order=i, floatValue=attrValue[0])

    # Delete unwanted nodes
    cmds.delete('toolBgeoToMaya1')

    # Rename particle system and group
    newname = 'forest_instancing_pc'
    cmds.rename(tmp[0], newname)
    masterGRP = 'FOREST_INSTANCING_GRP'
    try:
        cmds.select(masterGRP, r=True)
    except ValueError:
        cmds.group(newname, name=masterGRP)
    else:
        cmds.parent(newname, masterGRP)

    # Set nucleus (yes we have to keep it for some reason)
    cmds.setAttr('nucleus1.startFrame', fstart)
    cmds.parent('nucleus1', masterGRP)