Created
August 22, 2022 07:01
-
-
Save FhyTan/f9710527acb6f0033597a8c0d3cb3e57 to your computer and use it in GitHub Desktop.
Simple maya instancer example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import maya.cmds as cmds | |
pCone = cmds.polyCone()[0] | |
pCube = cmds.polyCube()[0] | |
pTorus = cmds.polyTorus()[0] | |
cmds.hide(all=True) | |
positionArray = [[0, 0, 0], [2, 0, 0], [5, 0, 0]] | |
rotationArray = [[45, 0, 0], [0, 45, 0], [0, 0, 45]] | |
scaleArray = [[2, 1, 1], [1, 2, 1], [1, 1, 2]] | |
objectIdArray = [1, 1, 2] | |
particle = cmds.particle(position=positionArray) | |
# print(particle) # ['nParticle1', 'nParticleShape1'] | |
# It should have a suffix "0", otherwise it would lost data when you move timeline | |
# cmds.addAttr(particle[1], longName='rotationPP', dataType='vectorArray') | |
cmds.addAttr(particle[1], longName='rotationPP0', dataType='vectorArray') | |
# cmds.addAttr(particle[1], longName='scalePP', dataType='vectorArray') | |
cmds.addAttr(particle[1], longName='scalePP0', dataType='vectorArray') | |
# cmds.addAttr(particle[1], longName='objectIdPP', dataType='Int32Array') | |
cmds.addAttr(particle[1], longName='objectIdPP0', dataType='Int32Array') | |
# cmds.setAttr(particle[1] + '.rotationPP', len(rotationArray), *rotationArray, type='vectorArray') | |
cmds.setAttr(particle[1] + '.rotationPP0', len(rotationArray), *rotationArray, type='vectorArray') | |
# cmds.setAttr(particle[1] + '.scalePP', len(scaleArray), *scaleArray, type='vectorArray') | |
cmds.setAttr(particle[1] + '.scalePP0', len(scaleArray), *scaleArray, type='vectorArray') | |
# cmds.setAttr(particle[1] + '.objectIdPP', objectIdArray, type='Int32Array') | |
cmds.setAttr(particle[1] + '.objectIdPP0', objectIdArray, type='Int32Array') | |
particleInstancer = cmds.particleInstancer( | |
particle[1], | |
addObject=True, | |
object=[ | |
pCone, | |
pCube, | |
pTorus | |
], | |
rotation='rotationPP0', | |
scale='scalePP0', | |
objectIndex='objectIdPP0', | |
levelOfDetail='geometry', | |
rotationUnits='Degrees', | |
rotationOrder='XYZ', | |
position='worldPosition', | |
cycle='None', | |
cycleStep=1, | |
cycleStepUnits='Frames', | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment