Thursday, 30 July 2015

Week15 - InClassExercise: Create ShadingNode


import maya.cmds as mc

#create a row of cube

myCubeList = []
for each in range (5):
    myCube= mc.polyCube()
    mc.move ( each,0,0)
    myCubeList.append(myCube[0])
    
for each in myCubeList:
    myShader = mc.shadingNode ('blinn',asShader=True)
    mySG = mc.sets (renderable = True, noSurfaceShader= True, empty= True, name='blinnSG');
    mc.connectAttr ( str(myShader)+".outColor",str(mySG) + ".surfaceShader")
    mc.sets (each, myShader, fe=str ( mySG))

Thursday, 2 July 2015

Week10 - InClassExercise: ExpressionEditor

import maya.cmds as mc

#creates 10 Cube the x direction
for each in range (10):
        myCube = mc.polyCube()
        mc.move (each,0,0)

#creates a Torus      
myTorus = mc.polyTorus (sr=0.05, r= 6)
mc.move (4.5, 0, 0, myTorus[0])

#this selects all cube and list it
mc.select(all=True)
myCubeList = mc.ls('pCube*',selection=True)
print myCubeList

#adds expression in each Cube's rotateX relating Torus' rotateX
n=1
for each in myCubeList:
    mc.expression( string = str(each) +".rotateX=pTorus1.rotateX*"+str(-n))
    n=n+3
 
#                   Try rotating Torus' rotateX




Thursday, 4 June 2015

Week 7 - Assignment 1 Final

Final

Final python:

import maya.cmds as mc
n=0
m=0
for each in range(30):
CubeOne=mc.polyCube(w=4,h=0.6,d=0.6)
mc.move (2,0,0,CubeOne[0])
mc.rotate (-22.5,0,0, CubeOne[0])
CubeTwo=mc.polyCube(w=4,h=0.6,d=0.6)
mc.move (-2,0,0,CubeTwo[0])
mc.rotate (22.5,0,0,CubeTwo[0])
SphereOne=mc.polySphere()
mc.move (-4.5,0,0,SphereOne[0])
SphereTwo=mc.polySphere()
mc.move (4.5,0,0,SphereTwo[0])
Chain= mc.group(CubeOne, CubeTwo, SphereOne, SphereTwo, n='Chain1')
mc.move(0,each+n,0,Chain)
mc.rotate(0,each+m,0,Chain)
n=n+0.5
m=m+15

mc.select( all=True )
Spiralyo = mc.ls( 'Chain*', sl=True )
print Spiralyo
oddlist= []
for each in range(len(Spiralyo)):
    if (each%2==1):
        selected = "Chain"+str(each)
        print selected
        oddlist.append(selected)

shader = mc.shadingNode("blinn",asShader=True, name='YellowBlinn')
mc.setAttr(shader + '.color', 1, 1, 0)
mc.select(oddlist)
mc.hyperShade( a=shader)

mc.select (all=True)
mc.select (oddlist,tgl=True)
evenlist= mc.ls( 'Chain*', sl=True )
print evenlist

shader2= mc.shadingNode("blinn",asShader=True, name='RedBlinn')
mc.setAttr(shader2 + '.color', 1, 0, 0)
mc.select(evenlist)
mc.hyperShade( a=shader2)


How I did it:

For the first segment of the script (red font), I used loop and insert simple meshes like cube and spheres and position them in a way that looks like a single 'chain' of the DNA. I set in a range of 30 to duplicate into 30 chains and move plus rotate for each 'chain'.

The Next Step (Orange and Green front), I'm going to find the word 'Chain*' . "List all selected objects named "group*". To get the odd and even numbers of the Chain, I use each%2==1 and find the word 'Chain' and append the results. After obtaining the odd list, I simply toggle select and the even list will be selected.

For the Material part, 
shader = mc.shadingNode("blinn",asShader=True, name='YellowBlinn')
mc.setAttr(shader + '.color', 1, 1, 0)
mc.select(oddlist)
mc.hyperShade( a=shader)

I use shadingNode to create the blinn, followed by setting the attributes of .color to the values of R,G,B. Finally I select the list and assign the shader to selected.

Wednesday, 20 May 2015

Week 7 - Assignment 1 WIP

Ideas:

I decided to give a try and do a DNA pattern for Assignment 1.
References:


The shape consist of spheres and cubes. I have thought and tried different methods on creating the single chain. Eventually, I group them together using my script:  (below)

import maya.cmds as mc
import math

myCubeList =[(mc.polyCube(w=4,h=0.6,d=0.6,name="myCube1")) , (mc.polyCube(w=4,h=0.6,d=0.6,name="myCube2")) , (mc.polySphere(name="mySphere1")), (mc.polySphere(name="mySphere2"))]

mc.move (2,0,0,myCubeList[0][0])
mc.move (-2,0,0,myCubeList[1][0])
mc.move (-4.5,0,0,myCubeList[2][0])
mc.move (4.5,0,0,myCubeList[3][0])

mc.rotate (-22.5,0,0,myCubeList[0][0])
mc.rotate (22.5,0,0,myCubeList[1][0])

cmds.group( 'myCube1', 'myCube2', 'mySphere1', 'mySphere2', n='Chain1' )

Chain1 = [myCubeList]

Problems faced:

I am not sure what is the proper pipeline on creating and duplicating plus rotating them uniformly. Hence, the script created may not be in the correct order.

Plans:

After I have found a way of duplicating and rotating them together, I am planning to mirror every alternate chain to create a more organic look of the DNA.
example:
0>>>>0 to right
0<<<<0 to left
0>>>>0
0<<<<0