import copy #指定位置を中心にスケーリング #「指定座標」「カーソル(クリック位置)」「選択頂点(最初に選択した点)」「選択頂点(最後に選択に追加した点)」 #「選択頂点群の中心」「選択頂点群のバウンディングボックスの中心」のいずれかを中心にスケーリングできます #パラメーターはウインドウを閉じても記憶されるので、連続して同じ #軸ごとに固定あり(x軸方向にだけ拡大するとか) #精度が足りないので、数値入力移動のように「0」倍にしても同一座標に集合しない場合があります。 #上位パートに変換がかかっていると使用できないように変更(2010.03.03) #shade1301に対応 #動作条件 #選択形状がポリゴンメッシュ #編集モードに入っている事 #頂点編集モードに入っている事 #頂点が二つ以上選択されている事 #ローカル座標モードや上位パートに変換がかかっていると結果が不正になります。 #パラメーター #ctype・・・スケーリングのセンターの種類 #scale・・・倍率(0以上) #xon・・・x軸方向に拡大縮小するか #yon・・・y軸方向に拡大縮小するか #zon・・・z軸方向に拡大縮小するか #weldon・・・処理後に同一座標の頂点をウェルドするか def sort_point_by_active_order(pointlist): #頂点の選択番号(active_order)順にリストの頂点番号をソートして頂点リストを返す #ソート templist=[] for i in pointlist: templist.append(i) newlist=[] while(len(newlist)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: aplist=sort_point_by_active_order(aplist) #ここに初期値 renzoku=1 scale=1 ctype=0 xon=1 yon=1 zon=1 spos=[0,0,0]#指定座標 weldon=0 dfscale=scale dfctype=ctype dfxon=xon dfyon=yon dfzon=zon dfspos=spos dfweldon=weldon while(renzoku==1): #ダイアログ表示 dialog=xshade.create_dialog_with_uuid('0x51900FFF') dialog.begin_group('スケーリングの中心') idx1=dialog.append_radio_button('/指定座標/カーソル(クリック位置)/選択頂点(最初に選択した点)/選択頂点(最後に選択に追加した点)/選択頂点群の中心(平均座標)/選択頂点群のバウンディングボックスの中心') dialog.end_group() dialog.append_default_button() idx2=dialog.append_double('倍率(0以上)') idx3=dialog.append_vec3('「指定座標」の場合') dialog.begin_group() idx4=dialog.append_bool('X軸方向ON') idx5=dialog.append_bool('Y軸方向ON') idx6=dialog.append_bool('Z軸方向ON') dialog.end_group() # idx7=dialog.append_bool('処理後に同一座標の頂点をマージする') # dialog.set_value(idx1,dfctype) # dialog.set_value(idx2,dfscale) # dialog.set_value(idx3,dfspos) # dialog.set_value(idx4,dfxon) # dialog.set_value(idx5,dfyon) # dialog.set_value(idx6,dfzon) dialog.set_default_value(idx1,dfctype) dialog.set_default_value(idx2,dfscale) dialog.set_default_value(idx3,dfspos) dialog.set_default_value(idx4,dfxon) dialog.set_default_value(idx5,dfyon) dialog.set_default_value(idx6,dfzon) # dialog.set_default_value(idx7,dfweldon) xshade.idle(120) kekka=dialog.ask('指定位置を中心にスケーリング') if kekka==False:renzoku=0 if kekka==True: #元の形状をクリップボードにコピー ashape.copy() xscene.enter_modify_mode() ctype=dialog.get_value(idx1) scale=dialog.get_value(idx2) if scale<0:scale=0.2 spos=dialog.get_value(idx3) xon=dialog.get_value(idx4) yon=dialog.get_value(idx5) zon=dialog.get_value(idx6) # weldon=dialog.get_value(idx7) #ctypeごとに中心座標(cpos)を求める if ctype==0: cpos=spos if ctype==1: tempos=xscene.cursor_position cpos=[tempos[0],tempos[1],tempos[2]] if ctype==2: cpos=ashape.vertex(aplist[0]).position if ctype==3: cpos=ashape.vertex(aplist[len(aplist)-1]).position if ctype==4: cpos=[0,0,0] for i in aplist: tempos=ashape.vertex(i).position cpos[0]+=tempos[0] cpos[1]+=tempos[1] cpos[2]+=tempos[2] cpos=[cpos[0]/len(aplist),cpos[1]/len(aplist),cpos[2]/len(aplist)] if ctype==5: temp=ashape.vertex(aplist[0]).position xmin=temp[0] xmax=temp[0] ymin=temp[1] ymax=temp[1] zmin=temp[2] zmax=temp[2] for i in aplist: temp2=ashape.vertex(i).position if temp2[0]xmax:xmax=temp2[0] if temp2[1]ymax:ymax=temp2[1] if temp2[2]zmax:zmax=temp2[2] cpos=[(xmin+xmax)/2,(ymin+ymax)/2,(zmin+zmax)/2] scalea=[scale,scale,scale] if xon==0:scalea[0]=1 if yon==0:scalea[1]=1 if zon==0:scalea[2]=1 #拡大縮小 xshade.scene().move_object(cpos,scalea, None, None) #マージするか # if weldon==1: # ashape.cleanup_redundant_vertices() #やり直すか聞く dialog=xshade.create_dialog() idx333=dialog.append_push_button('結果を確定しますか?') xshade.idle(120) kekka2=dialog.ask('指定位置を中心にスケーリング') if kekka2==False: idou1=0 if xshade.scene().active_shape().has_sis==True: idou1=1 xshade.scene().paste() xshade.scene().select_sister(1) xshade.scene().clear() if idou1==1: xshade.scene().select_brother() xshade.scene().enter_modify_mode() # xshade.scene().selection_mode=2 for i in aplist: xshade.scene().active_shape().vertex(i).active=True ashape=xshade.scene().active_shape() if kekka2==True: renzoku=0 #戻す終わり