Return to site

Snowy scene generator | Maya | Python

    The second project I decided to generate a snowy scene in Maya. At first I tried to emulate the scene using codes myself, but found it too complicated. Ian, our teacher, suggested me to use the particle system. So finally it's down using particles.
    Scene preview:
    User interface:
    See how it works on YouTube:
    Code sample:
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!')
instructions:
1. click on the plane
2. click 'Select Start Plane' button
3. if you want to use a specific image as snowflake texture, browse and select the image, then turn on the 'Use file as texture' checkbox. if you don't turn on the checkbox, the particle will be rendered as white cloud type
4. if you want to use more than one image to texture different particles, then turn on the 'Use file Sequence' checkbox. then the file browsered just now will be set as the start of the file sequence. make sure to name the textures in 'image.n' format. for example, 'snow.1'
5. set values of 'Average Size', 'Density', 'MaxHeight'
6. set values of 'Direction Vector'
7. if you want to make collisions between other objects and the particles, select those objects and then click 'Select Object Collide With' button, and turn on 'Make Collision' checkbox
8. click 'Run' to start generating the snowy scene
logs:
v1.0.5: 12-19-2015, add error captions
v1.0.4: 12-19-2015, add collisions; delete animation length option
v1.0.3: 12-16-2015, add particle render type - cloud
v1.0.2: 12-9-2015, add texture sequence
v1.0.1: 12-2-2015, add log function
All Posts
×

Almost done…

We just sent you an email. Please click the link in the email to confirm your subscription!

OKSubscriptions powered by Strikingly