
Lucas Lim Python Scripting
Wednesday, 25 May 2016
Tuesday, 17 May 2016
So basically this is my base script for the circles
import maya.cmds as mc
import math
import random
def cubeSphere():
myCubeList =[]
for each in range(2000):
myCube = mc.polyCube(name="myCube")
mc.move (10 , 0 , 0 , myCube[0])
---------------------------------------#
as shown, mc.move helps me to get a radius of 10 after I apply the rotation command below since it will allow the cubes to move away from the world pivot
rot= random.uniform (0,360)
---------------------------------------#
the random unifrom from 0, 360 allows the cubes to appear between 0 to 360, since I have about 3000 cubes, the cubes would overlay and form a basic circle. Well since I want a sphere instead of a circle, I would go for the 3D instead thus a base which is my Y is needed and Z axis is needed to form a sphere around the base in a range of 3000 cubes. And since the pivot is world axis, I needed another dimension to make it a sphere, thus I had to use Z axis or else using X axis would just form a circle on a plane
mc.rotate ((0),(each*rot) ,(each) , myCube[0], pivot =(0,0,0))
------------------------------------------#
then the commands below basically helps me in randoming the size and height of the cubes
ranSize = random.uniform (0.01,1)
ranHeight = random.uniform (1,3 )
mc.scale ( ranHeight, ranSize , ranSize)
myCubeList.append(myCube[0])
return myCubeList
myCubeList = cubeSphere()
print myCubeList
import maya.cmds as mc
import math
import random
def cubeSphere():
myCubeList =[]
for each in range(2000):
myCube = mc.polyCube(name="myCube")
mc.move (10 , 0 , 0 , myCube[0])
---------------------------------------#
as shown, mc.move helps me to get a radius of 10 after I apply the rotation command below since it will allow the cubes to move away from the world pivot
rot= random.uniform (0,360)
---------------------------------------#
the random unifrom from 0, 360 allows the cubes to appear between 0 to 360, since I have about 3000 cubes, the cubes would overlay and form a basic circle. Well since I want a sphere instead of a circle, I would go for the 3D instead thus a base which is my Y is needed and Z axis is needed to form a sphere around the base in a range of 3000 cubes. And since the pivot is world axis, I needed another dimension to make it a sphere, thus I had to use Z axis or else using X axis would just form a circle on a plane
mc.rotate ((0),(each*rot) ,(each) , myCube[0], pivot =(0,0,0))
------------------------------------------#
then the commands below basically helps me in randoming the size and height of the cubes
ranSize = random.uniform (0.01,1)
ranHeight = random.uniform (1,3 )
mc.scale ( ranHeight, ranSize , ranSize)
myCubeList.append(myCube[0])
return myCubeList
myCubeList = cubeSphere()
print myCubeList
Previously I've tried by applying cubes onto the vertices to create the effect, but it doesnt work well since it has more of a uniform effect rather than random
import maya.cmds as cmd
import random
import maya.cmds as cmd
import random
mc.polySphere (n="name")
VtxList = mc.getAttr ("name" + "vtrs". multiIndices = True )
(The command above allows me to select the vertices in the Sphere)
for vtx inVtxList:
vtxPos = cmd.xform(vtx, query = True, ws = True, t = True)
vtxName = "name.vtx("str(each)+"]"
(So basically I check for the positions for the vertices existing in the selected object which is my sphere)
replaceVtx = cmd.polyCube( h=0.1, w=0.1, d=0.1 )
#replaceVtx = to the object that I want to replace it on
cmd.move(vtxPos[0],vtxPos[1],vtxPos[2],replaceVtx)
However the results is too uniform
import maya.cmds as cmd
import random
import maya.cmds as cmd
import random
mc.polySphere (n="name")
VtxList = mc.getAttr ("name" + "vtrs". multiIndices = True )
(The command above allows me to select the vertices in the Sphere)
for vtx inVtxList:
vtxPos = cmd.xform(vtx, query = True, ws = True, t = True)
vtxName = "name.vtx("str(each)+"]"
(So basically I check for the positions for the vertices existing in the selected object which is my sphere)
replaceVtx = cmd.polyCube( h=0.1, w=0.1, d=0.1 )
#replaceVtx = to the object that I want to replace it on
cmd.move(vtxPos[0],vtxPos[1],vtxPos[2],replaceVtx)
However the results is too uniform
So I had to go back to the previous trial I had by using random along rotation 0 to 360
Monday, 16 May 2016

def cubeSphere():
myCubeList =[]
for each in range(2000):
myCube = mc.polyCube(name="myCube")
mc.move (10 , 0 , 0 , myCube[0])
rot= random.uniform (0,360)
mc.rotate ((0),(each*rot) ,(0) , myCube[0], pivot =(0,0,0))
myCubeList = cubeSphere()
print myCubeList
For this whole function, it basically creates a round circle around the world 0,0,0 axis
If the values in the X axis in mc.move changes , the radius of the circle changes since the circle grows towards the x axis.
While in mc.rotate, in Y axis creates a circle rotation of the cube to follow since the rot* range is from 0 to 360.
However now it only creates a circle in the X axis thus if i need it to form a sphere shape I would have to alter the stuff on the Z axis. Meanwhile any numbers as long with rot* would create a circle as shown below with only the circle shown will be in different axis
Result:
Monday, 9 May 2016
Approval For Python Scripting
This is my base idea and reference for my python scripting which is random cubes on a sphere. I am currently trying by using vertices to form this, or might be using random rotation towards the centre pivot of the circle, depends on which would give me the better result.
Reference from : http://www.shutterstock.com/pic-69155386/stock-photo-d-sphere-made-of-cubes.html
Reference from : http://www.shutterstock.com/pic-69155386/stock-photo-d-sphere-made-of-cubes.html
Subscribe to:
Posts (Atom)