logo

[B]alled

Gallery details

 Code Creates Paint Vertex Colors of a Mesh Based on Deformation Values compared to the rest state – Python Research V.2
“”” CREATES KEYFRAMES AND ANIMATION OF BOTH THE NCLOTH SHAPE AND THE MESH VERTEX COLORS. NDYNAMICS SIM MUST BE CACHED BEFORE THIS IS RUN”””
[Maya NDynamics Sim Deformation viz via Mesh Vertex Colors]

CODE

import maya.cmds as mc
import math
from pymel.core import *
 
#CODE CREATES PAINTS MESH VERTEX COLORS OF A MESH BASED ON DISTANCE DEFORMATION TO THE DRIVER MESH
#CREATES KEYFRAMES AND ANIMATION OF BOTH THE NCLOTH SHAPE AND THE MESH VERTEX COLORS.

#WRITTEN BY LUIS QUINONES
#COMPLICITMATTER.COM // COMPUTATIONALMATTER.COM
#/////////////////////////////////////////////////////////////////////////////////////////////////////
#get the timeslider startFrame
startFrame = mc.playbackOptions(q = True, minTime = True)
#get the timeslider endFrame
endFrame = mc.playbackOptions(q = True, maxTime = True)
#set the current frame to the start frame
currentFrame = startFrame

#/////////////////////////////////////////////////////////////////////////////////////////////////////

#BaseGeom Selection
Meshes = mc.ls(sl=True, long=True)
#Get Vertex Count as INT
verts = mc.polyEvaluate(Meshes[0],v=True)

prevLoc = []

for x in range(verts):
    prevLoc.append(mc.pointPosition(Meshes[0]+'.vtx[{x}]'.format(x=x)))
    
count = 1  
count2 = 2

#mc.setKeyframe('pPlane1', v = 1, at = "visibility")        
while(currentFrame < endFrame):
    
    if currentFrame == startFrame:
        print 'plane 1 hidden'
        mc.setKeyframe('pPlane1', v = 0, at = "visibility")
        mc.setKeyframe('Base', v = 0, at = "visibility")
   
    #print "the Frame is currently at %d" % currentFrame
    unSel = mc.select(cl=True)
    sel = mc.select('pPlane1',r=True)
    Meshes2 = mc.ls(sl=True, long=True)
    verts3 = mc.polyEvaluate(Meshes2,v=True)
    arrVertLoc = []
            
    for i in range(verts3):
        
        arrVertLoc.append(mc.pointPosition(Meshes2[0]+'.vtx[{i}]'.format(i=i)))
  
        dist = (  (prevLoc[i][0]-arrVertLoc[i][0])**2 + (prevLoc[i][1]-arrVertLoc[i][1])**2 + (prevLoc[i][2]-arrVertLoc[i][2])**2  )**0.5
        print dist    
        color = mc.polyColorPerVertex(Meshes2[0]+'.vtx[{i}]'.format(i=i), rgb=(0,0,1))  
                      
        if dist < 0.3:
            print "Ziiiiing"
            R = 0
            R = 0
            R = 0    
            
        elif dist >= 0.3:

            R =  dist + .75
            #print 'R = %f' % R
            G = 1/dist * 0.5
            #print 'G = %f' % G
            B = 0            
            #print 'R %f ' % R
            #print 'G %f ' % G
            #print 'B %f ' % B
                          
        color = mc.polyColorPerVertex(Meshes2[0]+'.vtx[{i}]'.format(i=i), rgb=(R,G,B))
        #color = mc.polyColorPerVertex(Meshes2[0]+'.vtx[{i}]'.format(i=i), rgb=(arrVertColor,arrVertColor,arrVertColor))
       
    nnewMesh = mc.duplicate( Meshes2[0], ic=False)
    mc.constructionHistory( Meshes2[0], tgl = False)
    #mc.setAttr('pPlane %d'%count+".visibility", 1)
    mc.setKeyframe('pPlane %d'%count2, v = 0, at = "visibility")
   
    if currentFrame == endFrame:

        mc.setKeyframe('pPlane1', v = 1, at = "visibility")
        
    mc.currentTime(currentFrame)
    currentFrame += 1
    
    mc.setKeyframe('pPlane %d'%count2, v = 1, at = "visibility")
    
    if currentFrame != startFrame: 
        mc.setKeyframe('pPlane %d'%count, v = 0, at = "visibility")      
          
    count += 1
    count2 += 1
    
Update
  • Share

Leave a reply

Your email address will not be published.