1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
| """ SnowPiece.py
examples of proper usage of logging module
__author__ = "Vega Bai" __copyright__ = "Copyright 2015, Vega Bai" __version__ = "1.0.1" __maintainer__ = "Vega Bai" __email__ = "vegabaixuan@gmail.com" __status__ = "Practise"
"""
import pymel.core as pm
def select_obj(selType): global snow_obj global from_point global from_point_index global to_point global to_point_index sel_obj = pm.selected() if not sel_obj: pm.PopupError("No object selected!") return if selType == 0: snow_obj = sel_obj print 'obj OK' print snow_obj return snow_obj
elif selType == 2: to_point = sel_obj[0] to_point_index = to_point.index() print to_point_index return to_point_index
def on_click_run(slider_scale, slider_angle, slider_level, snow_win): snow_scale = slider_scale.getValue() snow_angle = slider_angle.getValue() snow_level = slider_level.getValue()
snow_list = [] snow_list.append(snow_obj) snow_joint_list = [] pm.rename(snow_obj, 's0')
for i in range(1, snow_level): tmp = pm.duplicate(snow_list[i-1]) snow_list.append(tmp[0]) pm.rotate(snow_list[i], 0, snow_angle, 0, r = True) pm.scale(snow_list[i], snow_scale, 1, snow_scale, r = True) pos = pm.xform('%s.vtx[%d]'%(snow_list[i], to_point_index), q = 1, t = 1, ws = 1) pm.xform(snow_list[i], t = (pos[0], 0, pos[2]), ws = 1)
tmpunit = snow_list[0] for i in range(1, snow_level): print tmpunit, i tmpunit = pm.polyUnite(tmpunit, snow_list[i]) snow_joint_list.append(tmpunit[0]) for i in range(1, 6): tmp = pm.duplicate(tmpunit[0]) snow_joint_list.append(tmp) pm.rotate(tmp, 0, 60*i, 0, r = True) snow_final = snow_joint_list[0] for i in range(1,6): snow_final = pm.polyUnite(snow_final, snow_joint_list[i]) snow_win.delete() return
def ui(): win_title = 'Draw A Snowpiece' win_name = 'snow_window' win_width = 300 win_height = 160
if pm.window(win_name, exists = True): pm.deleteUI(win_name)
snow_win = pm.window(win_name, title = win_title, widthHeight = (win_width, win_height), sizeable = False ) col_layout1 = pm.columnLayout(adj = True) row_layout1 = pm.rowLayout(nc = 2, cw2 = ((win_width/2-10), (win_width/2+10)), parent = col_layout1 ) button_sel_obj = pm.button(label = 'Select Object', width = 100, command = pm.Callback(select_obj, 0) ) button_sel_end_point = pm.button(label = 'Select Destination Point', width = 130, command = pm.Callback(select_obj, 2) ) slider_scale = pm.floatSliderGrp(label = 'Scale', field = True, minValue = -2.0, maxValue = 2.0, fieldMinValue = -2.0, fieldMaxValue = 2.0, value = 0.5, cw3 = (40, 50, 200), adj = 3, parent = col_layout1 ) slider_angle = pm.floatSliderGrp(label = 'Angle', field = True, minValue = -30, maxValue = 30, fieldMinValue = -30, fieldMaxValue = 30, value = 0, cw3 = (40, 50, 200), adj = 3, parent = col_layout1 ) slider_level = pm.intSliderGrp(label = 'Level', field = True, minValue = 0, maxValue = 10, fieldMinValue = 0, fieldMaxValue = 10, value = 4, cw3 = (40, 50, 200), adj = 3, parent = col_layout1 ) row_layout2 = pm.rowLayout(nc = 2, cw2 = ((win_width/2), (win_width/2)), co2 = (20, 20), parent = col_layout1 ) button_run = pm.button(label = 'Run', width = 100 ) button_run.setCommand(pm.Callback(on_click_run, slider_scale = slider_scale, slider_angle = slider_angle, slider_level = slider_level, snow_win = snow_win ) ) button_cancel = pm.button(label = 'Cancel', width = 100, command = pm.Callback(snow_win.delete) ) snow_win.show() snow_win.setWidthHeight((win_width, win_height))
|