Skip to content

Instantly share code, notes, and snippets.

@simogasp
Created December 14, 2017 17:42
Show Gist options
  • Save simogasp/0b68316afe436138329a2de1bdcab90d to your computer and use it in GitHub Desktop.
Save simogasp/0b68316afe436138329a2de1bdcab90d to your computer and use it in GitHub Desktop.
[Maya script] Color points according to their visibility in Maya
# color points and their size (if spehere) according to their visibility
# create color attribute per particle
# create general attribute radiusPP
import maya.cmds as mc
import colorsys
name = 'mvgPointCloud'
radiusBase = 0.005
## Count the number of particules
totalParticle = mc.particle(name, query=True, count=True)
print(totalParticle)
visibilitySizePerPoint = mc.getAttr(name+'.mvg_visibilitySize')
maxVisibility = float(max(visibilitySizePerPoint))
for (id) in range(totalParticle):
# Query and print Particle position
# myPos = mc.xform('mvgPointCloud.pt[{id}]'.format(id=id), query=True, translation=True)
# Query and print Particle Color RGBPP
# myColor = mc.particle('mvgPointCloud', query=True, attribute='rgbPP', id=id)
#print 'Particle ID', id, 'Position:', myPos, 'Color:', myColor, 'visibilitySize:', visibilitySizePerPoint[id]
v = visibilitySizePerPoint[id] / maxVisibility
myColor = colorsys.hsv_to_rgb(v*.75, 1.0, 1.0)
radius = radiusBase+0.01*v
mySize = radius
# if visibilitySizePerPoint[id] < 8:
# myColor = [0.7, 0.7, 0.7]
# mySize = radiusBase
#print(id)
mc.particle(name, edit=True, attribute='rgbPP', order=id, vectorValue=myColor)
mc.particle(name, edit=True, attribute='radiusPP', order=id, floatValue=mySize)
mysize = [0, 0, 0]
mySize = mc.particle(name, query=True, attribute='radiusPP', order=1, vectorValue=True)
print(mySize)
mc.particle(name, edit=True, attribute='radiusPP', order=1, floatValue=10.0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment