import copy #選択頂点群が中央に来るように移動 #形状の選択部の中心(バウンディングボックスの中心)が原点になるように形状を移動します。(ポリゴンメッシュオンリー) #ポリゴンメッシュを一つ選択し、頂点選択モードに入ってから #頂点を二個以上選択して、このスクリプトを実行してください。 #ローカル座標モードや上位パートに変換がかかっていると結果が不正になります。 #微妙にずれてるよう #shade1301に対応 #130104作成 def return_henkan_pos(pos,mat): #posをmatで変換した座標(タプル)を返す tempx=pos[0] tempy=pos[1] tempz=pos[2] x1=mat[0][0]*tempx+mat[1][0]*tempy+mat[2][0]*tempz+mat[3][0]*1 y1=mat[0][1]*tempx+mat[1][1]*tempy+mat[2][1]*tempz+mat[3][1]*1 z1=mat[0][2]*tempx+mat[1][2]*tempy+mat[2][2]*tempz+mat[3][2]*1 return [x1,y1,z1] xscene=xshade.scene() ashape=xshade.scene().active_shape() #if ashape.type==7:dousasuru=1 dousasuru=0 if ashape.type==7 and xscene.is_modify_mode==True and len(xshade.scene().active_shapes)==1: if xscene.selection_mode==2: aplist=[]#選択頂点リスト for i in range(ashape.total_number_of_control_points): if ashape.vertex(i).active==True: aplist.append(i) if len(aplist)>1:dousasuru=1 if dousasuru>0: #上位パートに変換がかかっているなら動作しない if xshade.scene().active_shape().local_to_world_matrix!=((1.0, 0.0, 0.0, 0.0), (0.0, 1.0, 0.0, 0.0), (0.0, 0.0, 1.0, 0.0), (0.0, 0.0, 0.0, 1.0)): dousasuru=0 dialog=xshade.create_dialog() dialog.append_push_button('上位パートに変換がかかっているため') dialog.append_push_button('スクリプトが実行できません') dialog.ask('エラー') if dousasuru==1: #初期値 renzoku=1 modex=0 modey=0 modez=0 while(renzoku==1): #ダイアログを表示 dialog=xshade.create_dialog() idx1=dialog.append_bool('x軸') idx2=dialog.append_bool('y軸') idx3=dialog.append_bool('z軸') dialog.set_value(idx1,modex) dialog.set_value(idx2,modey) dialog.set_value(idx3,modez) xshade.idle(120) xshade.scene().update_figure_window() kekka=dialog.ask('選択部センタリング') if kekka==False:renzoku=0 else: imamode=xscene.is_modify_mode # print imamode modex=dialog.get_value(idx1) modey=dialog.get_value(idx2) modez=dialog.get_value(idx3) #元の形状をクリップボードにコピー ashape.copy() #中心座標を求める(グローバル座標) # cpos=ashape.center_position #ローカル座標に変換 # henkan=ashape.world_to_local_matrix # cpos=return_henkan_pos(cpos,henkan) minx=ashape.vertex(0).position[0] maxx=ashape.vertex(0).position[0] miny=ashape.vertex(0).position[1] maxy=ashape.vertex(0).position[1] minz=ashape.vertex(0).position[2] maxz=ashape.vertex(0).position[2] for i in aplist: tpos=ashape.vertex(i).position if minx>tpos[0]:minx=tpos[0] if miny>tpos[1]:miny=tpos[1] if minz>tpos[2]:minz=tpos[2] if maxx