def __init__(self, index, generator): # Stores its location. self.__index = index # Retrieves the values needed from the UI. self.__get_values(generator) # Fetches a pointer to the cratering data. cratering = self.__cratering # Stores the transform and shape nodes. nodes = [] # If this is the first moon created, create a polyPlatonicSolid. if (index == 0): # Creates the shape. nodes = polyPlatonicSolid(radius=self.__radius, name="Moon") # For aesthetics, the polyPlatonicSolid is beveled (based on the user's input) and smoothed. polyBevel3(offset=getAttr("polyBevel1.offset") * generator.get_spinbox_value("moon_ratio"), depth=cratering.get_depth(), segments=cratering.get_segments(), fraction=cratering.get_fraction()) polySmooth(divisions=2) # Otherwise, instance the original. else: nodes = instance("Moon") # Stores the transform node. self.__transform_node = nodes[0]
def makeShards(number,size,sizeVar,rgb1,rgb2,transparency,glow): ''' Creates a number of ice shard particles number : Number of particles to create size : Radius of the particles sizeVar : Variation in the radius rgb1 : One end of the colour range in the form (r,g,b) rgb2 : The other end of the colour range in the form (r,g,b) transparency : Alpha value for the shader glow : Glow value for the shader The progress window is updated and the shading group list is created. A while loop is initiated to create octahedrons, add them to the list and assign shaders. The list of objects is returned. ''' cmds.progressWindow(e=1,progress=0,status='Making Shards...') SGList = createColourList(rgb1,rgb2,transparency,glow,5) list=[] count=0 while count<number: radius = size+random.uniform(-(size*sizeVar*0.01),(size*sizeVar*0.01)) list[len(list):] = [cmds.polyPlatonicSolid(r=radius,st=2)[0]] cmds.polySoftEdge(list[-1],a=0) cmds.sets(list[-1], e=1, forceElement=SGList[random.randint(0,4)]) cmds.progressWindow(e=1,step=100/number) count += 1 return list
def makeShards(number, size, sizeVar, rgb1, rgb2, transparency, glow): ''' Creates a number of ice shard particles number : Number of particles to create size : Radius of the particles sizeVar : Variation in the radius rgb1 : One end of the colour range in the form (r,g,b) rgb2 : The other end of the colour range in the form (r,g,b) transparency : Alpha value for the shader glow : Glow value for the shader The progress window is updated and the shading group list is created. A while loop is initiated to create octahedrons, add them to the list and assign shaders. The list of objects is returned. ''' cmds.progressWindow(e=1, progress=0, status='Making Shards...') SGList = createColourList(rgb1, rgb2, transparency, glow, 5) list = [] count = 0 while count < number: radius = size + random.uniform(-(size * sizeVar * 0.01), (size * sizeVar * 0.01)) list[len(list):] = [cmds.polyPlatonicSolid(r=radius, st=2)[0]] cmds.polySoftEdge(list[-1], a=0) cmds.sets(list[-1], e=1, forceElement=SGList[random.randint(0, 4)]) cmds.progressWindow(e=1, step=100 / number) count += 1 return list
def __init__(self, generator): # Creates a pointer to the generator. self.__generator = generator # The radius and cratering data is fetched from the UI. self.__get_values() # Maya generates the shape. polyPlatonicSolid(radius=self.__radius, name="Planet") # The cratering data is fetched, cratering = self.__cratering # For aesthetics, the polyPlatonicSolid is beveled (based on the user's input) and smoothed. polyBevel3(depth=cratering.get_depth(), segments=cratering.get_segments(), fraction=cratering.get_fraction()) polySmooth(divisions=2) # Cleanup objects that are no long necessary. self.__generator = None self.__cratering = None
def run_script(num_shield_pieces=50): RED = [1, 0, 0] #red blood cells BLUE = [0, 0, 1] #blue for the core, aka Sonic DARK_RED = [.545, 0, 0] #create the lighting for the scene main_light = cmds.directionalLight(name="main_light", intensity=5) cmds.move(-5.711, 14.564, 11.097, "main_light") cmds.rotate('-67.367deg', '-24.33deg', '54.557deg', "main_light") #create the shape of the core and the shield shield_shape = cmds.polyTorus(sr=0.2, name="myRing#") #shape of shield shield_center = cmds.polyPlatonicSolid(radius=2.55, st=1, name="core") applyMaterial(shield_center[0], DARK_RED, 'lambert') cmds.move(0, 9, 0, "core") #move the core higher #add decorative cylinder to core core_piece_1 = cmds.polyCylinder(name="tube_1") applyMaterial(core_piece_1[0], BLUE, 'lambert') cmds.move(0.195, 11.014, -1.221, "tube_1") cmds.rotate('-30.351deg', 0, 0, "tube_1") cmds.scale(0.505, 0.619, 0.505, "tube_1") #add another decorative cylinder to core core_piece_2 = cmds.polyCylinder(name="tube_2") applyMaterial(core_piece_2[0], RED, 'lambert') cmds.move(-0.917, 11.185, -0.216, "tube_2") cmds.rotate('-3.436deg', '14.201deg', '24.834deg', "tube_2") cmds.scale(0.505, 0.619, 0.505, "tube_2") #generate random shield fragments shield_pieces, shield_pieces_group = generate_shield( shield_shape, num_shield_pieces) #coloring the shield pieces for piece_obj in shield_pieces: applyMaterial(piece_obj[0], RED, 'phong') #aim fragments at core aim_at_first(shield_center, shield_pieces) #create and link expansion attribute locator_group = expand_from_first(shield_center, shield_pieces) #must group locators so they can be rotated with the fragments cmds.parent(locator_group, shield_pieces_group) startTime = cmds.playbackOptions(query=True, minTime=True) endTime = cmds.playbackOptions(query=True, maxTime=True) #second param is rotation param key_rotation(shield_pieces_group, 'rotateY', startTime, endTime) #create heartbeat animation pattern cmds.cutKey(shield_center, time=(startTime, endTime), attribute='expansion') heartbeat(shield_center, 0) heartbeat(shield_center, 2) heartbeat(shield_center, 4) heartbeat(shield_center, 6) heartbeat(shield_center, 8) heartbeat(shield_center, 10) cmds.selectKey(shield_center, time=(startTime, endTime), attribute='expansion', keyframe=True) cmds.keyTangent(inTangentType='linear', outTangentType='linear')
def create_blob(size=2): obj_name, _ = cmds.polyPlatonicSolid(st=1, r=size) cmds.polySmooth(mth=1) # Linear smooth randomize_faces(move_bias=[2, 1, 3]) return obj_name
def polyPlatonicSolid(*args, **kwargs): res = cmds.polyPlatonicSolid(*args, **kwargs) if not kwargs.get('query', kwargs.get('q', False)): res = _factories.maybeConvert(res, _general.PyNode) return res
def createPine(self, p_depth, # tree depth, p_length, p_length_inc, p_r, p_rate, p_l, # last segment tip p_ll, # last segment base branch_turn, branch_shift, polygons, num_branches, branch_ang, foliage_sze, foliage_res, turn, branch, foliage_num, foliage_spr, first_segment_l, pine_level, branch_chance, angle_chance, turn_chance, turn_amount, angle_amount): if p_depth > 0: branch_length = p_length * first_segment_l lv = [p_l[0] - p_ll[0], p_l[1] - p_ll[1], p_l[2] - p_ll[2]] m = math.sqrt(math.pow(lv[0], 2) + math.pow(lv[1], 2) + math.pow(lv[2], 2)) u = [lv[0] / m, lv[1] / m, lv[2] / m] v = [lv[0] + p_ll[0] + (u[0] * branch_length), lv[1] + p_ll[1] + (u[1] * branch_length), lv[2] + p_ll[2] + (u[2] * branch_length)] if pine_level == 3 or pine_level == 2: newP = [p_l[0] + 0.1, p_l[1], p_l[2]] p = self.get_sp_point(p_l, p_ll, newP) points = self.point_rotate_3d(p[0], p[1], p[2], newP[0], newP[1], newP[2], v[0], v[1], v[2], branch_turn) yTurn = self.point_rotate_3d(p_l[0], p_l[1], p_l[2], v[0], v[1], v[2], points[0], points[1], points[2], branch_shift) p_n = yTurn else: p_n = v self.polytube( p_l[0], p_l[1], p_l[2], # base point p_n[0], p_n[1], p_n[2], # top point p_ll[0], p_ll[1], p_ll[2], p_r, p_r * p_rate, # base and top radius polygons) p_length = (p_length * p_length_inc) p_r = p_r * p_rate p_depth = p_depth - 1.0 if pine_level == 1: self.createPine(p_depth, p_length, p_length_inc, p_r, p_rate, p_n, p_l, branch_turn, branch_shift, polygons, num_branches, branch_ang, foliage_sze, foliage_res, turn, branch, foliage_num, foliage_spr, 1, 1, branch_chance, angle_chance, turn_chance, turn_amount, angle_amount) c = 0 if p_depth > 0: branch_turn = branch_ang turn = turn + math.pi / 2.0 for i in range(0, num_branches): branch = True p_length = p_length + random.uniform(-0.5, 0.5) if random.uniform(0, 1) < turn_chance: turn = turn + random.uniform(-turn_amount, turn_amount) if random.uniform(0, 1) < angle_chance: branch_turn = branch_turn + random.uniform(-angle_amount, angle_amount) if random.uniform(0, 1) < 1.0 - branch_chance: branch = False c = c + 1 branch_shift = (i * ((math.pi * 2.0) / num_branches)) + turn if branch: self.createPine(p_depth * 0.5, p_length * 0.7, p_length_inc, p_r, p_rate, p_n, p_l, branch_turn, branch_shift, polygons, num_branches, branch_ang, foliage_sze, foliage_res, turn, branch, foliage_num, foliage_spr, 1, 2, branch_chance, angle_chance, turn_chance, turn_amount, angle_amount) if c == num_branches or p_depth <= 0: randx = [] randy = [] randz = [] for r in range(0, 20): randx.append(random.uniform(-foliage_spr, foliage_spr)) randy.append(random.uniform(-foliage_spr, foliage_spr)) randz.append(random.uniform(-foliage_spr, foliage_spr)) for j in range(0, foliage_num): my_sphere = cmds.polyPlatonicSolid(l=foliage_sze, name='leaves#') for i in range(0, foliage_res): cmds.polySmooth(my_sphere) cmds.move(p_n[0] + randx[j], p_n[1] + randy[j], p_n[2] + randz[j], my_sphere)
cmds.select(all=True) cmds.delete() cmds.polySphere(n='Sphere') cmds.polyCube(n='Cube') cmds.move(0, 0, 5) cmds.polyCylinder(n='Cylinder') cmds.move(0, 0, 10) cmds.polyCone(n='Cone') cmds.move(0, 0, 15) cmds.polyTorus(n='Torus') cmds.move(0, 0, 20) cmds.polyPlane(n='Plane') cmds.move(0, 0, 25) #cmds.polyDisc(n='Disc') #cmds.move( 0, 0, 30 ) cmds.polyPyramid(n='Pyramid') cmds.move(0, 0, 30) cmds.polyPlatonicSolid(n='Platonic') cmds.move(0, 0, 35) cmds.polyPrism(n='Prism') cmds.move(0, 0, 40) cmds.polyPipe(n='Pipe') cmds.move(0, 0, 45) cmds.polyHelix(n='Helix') cmds.move(0, 0, 50) #cmds.polyGear(n='Gear') #cmds.move( 0, 0, 60 ) cmds.polyPrimitive(r=1, l=0.4036, pt=0, n='SoccerBall') cmds.move(0, 0, 55)