#マルチリンクツールをまとめたもの #ラジオボタン式のダイアログを表示して、起動するツールを選択する #1マルチリンク(開始点に総接合) #頂点編集モードで、かつ編集モードの時作動 #一番最初に選択した頂点と、残りの選択頂点群に一気にエッジが張られる #すでにエッジが張られてないか確認(エッジ判定メソッドを使用して返り値が-1なら張る) #結果とともに、選択頂点の数をダイアログで表示してokボタンを押すと処理が確定、cancelボタンを押すと取り消し #選択頂点数が2個以上の場合のみ作動 #2マルチリンク(選択順に対接合) #頂点編集モードで、かつ編集モードの時作動 #選択番号が1と2、3と4、5と6、7と8……という風に対にエッジが張られていく #すでにエッジが張られてないか確認(エッジ判定メソッドを使用して返り値が-1なら張る) #結果とともに、選択頂点の数をダイアログで表示してokボタンを押すと処理が確定、cancelボタンを押すと取り消し #選択頂点数が2個以上の場合のみ作動 #かつ選択頂点数が2の倍数の時のみ作動 #3マルチリンク(座標値で対接合) #頂点編集モードで、かつ編集モードの時作動 #指定した座標値が近いもの同士にエッジが張られていく #一つ目のダイアログでx座標、y座標、z座標を選択 #すでにエッジが張られてないか確認(エッジ判定メソッドを使用して返り値が-1なら張る) #実行後に選択頂点の数をダイアログで表示してokボタンを押すと確定、キャンセルで取り消し #選択頂点数が2個以上の場合のみ作動 #かつ選択頂点数が2の倍数の時のみ作動 #4マルチリンク(選択順に連続接合) #頂点編集モードで、かつ編集モードの時作動 #選択番号が1と2、2と3、3と4、……という風に連続でエッジが張られていく #すでにエッジが張られてないか確認(エッジ判定メソッドを使用して返り値が-1なら張る) #結果とともに、選択頂点の数をダイアログで表示してokボタンを押すと処理が確定、cancelボタンを押すと取り消し #選択頂点数が2個以上の場合のみ作動 #5マルチリンク(ダブルループ接合) #頂点編集モードで、かつ編集モードの時作動 #選択頂点数が4個か6個のときのみ作動 def return_pointlist(pointnum): #その点と接続されている頂点の頂点番号をリストで返す(引数 頂点番号) pointlist=[] totaledgesuu=xshade.scene().active_shape().number_of_edges for i in range(totaledgesuu): if xshade.scene().active_shape().edge(i).v0==pointnum: pointlist.append(xshade.scene().active_shape().edge(i).v1) if xshade.scene().active_shape().edge(i).v1==pointnum: pointlist.append(xshade.scene().active_shape().edge(i).v0) return pointlist def return_looplist(a1,a2,a3): #辺a1a2から開始して、ループ状に頂点を追加していってリストを返す maeten=a1 imaten=a2 returnlist=[] if return_edge_number(a1,a2)!=-1: returnlist.append(a1) returnlist.append(a2) renz=1 while(renz==1): templist=return_pointlist(imaten) templist.remove(maeten) #接続頂点と構成される辺の隣接面の数を確認 kouholist=[] for i in templist: if len(return_menlist(return_edge_number(i,imaten)))<2: kouholist.append(i) if len(kouholist)>0: #a3と一緒でないか確認 if kouholist[0]==a3: returnlist.append(a3) renz=0 #すでに格納してないか確認 sumi=0 for i in returnlist: if kouholist[0]==i:sumi=1 if sumi==1:renz=0 else: returnlist.append(kouholist[0]) maeten=imaten imaten=kouholist[0] else:renz=0 return returnlist def sort_point_by_position(pointlist,ziku): #頂点の座標値が低い順にリストの頂点番号をソートして頂点リストを返す #zikuが1の時はx座標で、2の時はy座標で、3の時はz座標でソート #ソート templist=[] for i in pointlist: templist.append(i) newlist=[] while(len(newlist)0: activepointlist.append(i) pointsuu=len(activepointlist)#選択頂点数 #選択頂点数は2個以上あるか? if pointsuu<2: dousasuru=0 #選択頂点数が2個以下の時のダイアログ表示 if imamodify==1 and dousasuru==0 and pointsuu<2 and xshade.scene().selection_mode==2: dialog3=xshade.create_dialog_with_uuid('0x51900F30') idx11=dialog3.append_push_button('選択頂点数が'+str(pointsuu)+'個なので機能しません。') muridesu=dialog3.ask('マルチリンク(開始点に総接合)') #選択番号順に頂点番号をソート activepointlist2=sort_point_by_active_order(activepointlist) if dousasuru==1: #開始点と、残りの頂点群を接合していく(まだエッジが張られてない場合のみ) nokoripointlist=activepointlist2[1:] for i in nokoripointlist: if return_edge_number(activepointlist2[0],i)==-1: xshade.scene().active_shape().append_edge(activepointlist2[0],i) #面の向きがおかしくならないよう面の向きを調整 xshade.scene().active_shape().adjust_face_direction() kekka=True #ダイアログを表示して、選択頂点数と結果を確認してもらう #okで確定(何もせず)cancelだと元に戻す if dousasuru==1: dialog=xshade.create_dialog_with_uuid('0x51900F00') idx1=dialog.append_push_button('選択頂点'+str(pointsuu)+'個のうち') idx2=dialog.append_push_button('最初の選択点以外を、最初の選択点へ総接合しました。') idx3=dialog.append_push_button('結果を確定する場合はokを') idx4=dialog.append_push_button('取り消す場合はcancelを押してください') if imamodify==1: xshade.scene().enter_modify_mode() kekka=dialog.ask('マルチリンク(開始点に総接合)') #キャンセルなら形状を削除してクリップボードの形状を元に戻す #さらに頂点の選択状態も元に戻す? if kekka==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() for i in activepointlist: xshade.scene().active_shape().vertex(i).active=True #選択番号が変更されているので、入れなおし for i in range(len(activepointlist2)): xshade.scene().active_shape().vertex(activepointlist2[i]).active_order=i+1 #クリップボードにコピーしたので編集モードに入っておく if imamodify==1: xshade.scene().enter_modify_mode() #開始点に総接合終わり def sentakutui(): #選択順に対接合 imamodify=0 #今はモディファイモード? if xshade.scene().is_modify_mode==True: imamodify=1 #元の形状を念のためクリップボードにコピー xshade.scene().active_shape().copy() dousasuru=1 if xshade.scene().selection_mode!=2 or imamodify==0: dousasuru=0 #選択状態の頂点数をリストに入れる activepointlist=[] for i in range(xshade.scene().active_shape().total_number_of_control_points): if xshade.scene().active_shape().vertex(i).active_order>0: activepointlist.append(i) pointsuu=len(activepointlist)#選択頂点数 #選択頂点数は2個以上あるか? if pointsuu<2: dousasuru=0 #選択頂点数は2の倍数か? if pointsuu/2!=pointsuu/2.0: dousasuru=0 #選択頂点数が偶数でない時のダイアログ表示 if imamodify==1 and dousasuru==0 and pointsuu/2!=pointsuu/2.0 and xshade.scene().selection_mode==2: dialog3=xshade.create_dialog_with_uuid('0x51900F30') idx11=dialog3.append_push_button('選択頂点数が'+str(pointsuu)+'(奇数個)なので機能しません。') muridesu=dialog3.ask('マルチリンク(選択順に対接合)') #選択番号順に頂点番号をソート activepointlist2=sort_point_by_active_order(activepointlist) if dousasuru==1: #選択順に対接合していく(まだエッジが張られてない場合のみ) for i in range(0,len(activepointlist2),2): if return_edge_number(activepointlist2[i],activepointlist2[i+1])==-1: xshade.scene().active_shape().append_edge(activepointlist2[i],activepointlist2[i+1]) #面の向きがおかしくならないよう面の向きを調整 xshade.scene().active_shape().adjust_face_direction() kekka=True #ダイアログを表示して、選択頂点数と結果を確認してもらう #okで確定(何もせず)cancelだと元に戻す if dousasuru==1: dialog=xshade.create_dialog_with_uuid('0x51900F00') idx1=dialog.append_push_button('選択頂点'+str(pointsuu)+'個を') idx2=dialog.append_push_button('選択順に対接合しました。') idx3=dialog.append_push_button('結果を確定する場合はokを') idx4=dialog.append_push_button('取り消す場合はcancelを押してください') if imamodify==1: xshade.scene().enter_modify_mode() kekka=dialog.ask('マルチリンク(選択順に対接合)') #キャンセルなら形状を削除してクリップボードの形状を元に戻す #さらに頂点の選択状態も元に戻す? if kekka==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() for i in activepointlist: xshade.scene().active_shape().vertex(i).active=True #選択番号が変更されているので、入れなおし for i in range(len(activepointlist2)): xshade.scene().active_shape().vertex(activepointlist2[i]).active_order=i+1 #クリップボードにコピーしたので編集モードに入っておく if imamodify==1: xshade.scene().enter_modify_mode() #選択順に対接合終わり def zahyousetugou(): #座標値で接合 imamodify=0 #今はモディファイモード? if xshade.scene().is_modify_mode==True: imamodify=1 #元の形状を念のためクリップボードにコピー xshade.scene().active_shape().copy() dousasuru=1 if xshade.scene().selection_mode!=2 or imamodify==0: dousasuru=0 #選択状態の頂点数をリストに入れる activepointlist=[] for i in range(xshade.scene().active_shape().total_number_of_control_points): if xshade.scene().active_shape().vertex(i).active_order>0: activepointlist.append(i) pointsuu=len(activepointlist)#選択頂点数 #選択頂点数は2個以上あるか? if pointsuu<2: dousasuru=0 #選択頂点数は2の倍数か? if pointsuu/2!=pointsuu/2.0: dousasuru=0 #選択頂点数が偶数でない時のダイアログ表示 if imamodify==1 and dousasuru==0 and pointsuu/2!=pointsuu/2.0 and xshade.scene().selection_mode==2: dialog3=xshade.create_dialog_with_uuid('0x51900F30') idx11=dialog3.append_push_button('選択頂点数が'+str(pointsuu)+'(奇数個)なので機能しません。') muridesu=dialog3.ask('マルチリンク(座標値で対接合)') #指標軸を聞くダイアログ作成 if imamodify==1 and dousasuru==1 and xshade.scene().selection_mode==2: xshade.scene().enter_modify_mode() zikudialog=xshade.create_dialog_with_uuid('0x51900F23') monn=zikudialog.append_radio_button('参考とする座標/x座標(横)/y座標(高さ)/z座標(奥行き)') zikudialog.set_value(monn,0) kekka2=zikudialog.ask('マルチリンク(座標値で対接合)') if kekka2==False: dousasuru=0 ziku2=zikudialog.get_value(monn) #選択順に戻す用 modosu=[] for i in activepointlist: modosu.append(i) modosu=sort_point_by_active_order(modosu) #座標値で頂点番号をソート activepointlist2=sort_point_by_position(activepointlist,ziku2) if dousasuru==1: #選択順に対接合していく(まだエッジが張られてない場合のみ) for i in range(0,len(activepointlist2),2): if return_edge_number(activepointlist2[i],activepointlist2[i+1])==-1: xshade.scene().active_shape().append_edge(activepointlist2[i],activepointlist2[i+1]) #面の向きがおかしくならないよう面の向きを調整 xshade.scene().active_shape().adjust_face_direction() kekka=True #ダイアログを表示して、選択頂点数と結果を確認してもらう #okで確定(何もせず)cancelだと元に戻す if dousasuru==1: dialog=xshade.create_dialog_with_uuid('0x51900F00') idx1=dialog.append_push_button('選択頂点'+str(pointsuu)+'個を') idx2=dialog.append_push_button('座標値の近いもの同士で対接合しました。') idx3=dialog.append_push_button('結果を確定する場合はokを') idx4=dialog.append_push_button('取り消す場合はcancelを押してください') if imamodify==1: xshade.scene().enter_modify_mode() kekka=dialog.ask('マルチリンク(座標値で対接合)') #キャンセルなら形状を削除してクリップボードの形状を元に戻す #さらに頂点の選択状態も元に戻す? if kekka==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() for i in activepointlist: xshade.scene().active_shape().vertex(i).active=True #選択番号が変更されているので、入れなおし for i in range(len(modosu)): xshade.scene().active_shape().vertex(modosu[i]).active_order=i+1 #クリップボードにコピーしたので編集モードに入っておく if imamodify==1: xshade.scene().enter_modify_mode() #座標値で対接合終わり def renzokusetugou(): #選択順に連続接合 imamodify=0 #今はモディファイモード? if xshade.scene().is_modify_mode==True: imamodify=1 #元の形状を念のためクリップボードにコピー xshade.scene().active_shape().copy() dousasuru=1 if xshade.scene().selection_mode!=2 or imamodify==0: dousasuru=0 #選択状態の頂点数をリストに入れる activepointlist=[] for i in range(xshade.scene().active_shape().total_number_of_control_points): if xshade.scene().active_shape().vertex(i).active_order>0: activepointlist.append(i) pointsuu=len(activepointlist)#選択頂点数 #選択頂点数は2個以上あるか? if pointsuu<2: dousasuru=0 #選択頂点数が2個以上でない時のダイアログ表示 if imamodify==1 and dousasuru==0 and pointsuu<2 and xshade.scene().selection_mode==2: dialog3=xshade.create_dialog_with_uuid('0x51900F30') idx11=dialog3.append_push_button('頂点は2個以上選択してください') muridesu=dialog3.ask('マルチリンク(選択順に連続接合)') #選択番号順に頂点番号をソート activepointlist2=sort_point_by_active_order(activepointlist) if dousasuru==1: #選択順に連続接合していく(まだエッジが張られてない場合のみ) for i in range(len(activepointlist2)-1): if return_edge_number(activepointlist2[i],activepointlist2[i+1])==-1: xshade.scene().active_shape().append_edge(activepointlist2[i],activepointlist2[i+1]) #面の向きがおかしくならないよう面の向きを調整 xshade.scene().active_shape().adjust_face_direction() kekka=True #ダイアログを表示して、選択頂点数と結果を確認してもらう #okで確定(何もせず)cancelだと元に戻す if dousasuru==1: dialog=xshade.create_dialog_with_uuid('0x51900F00') idx1=dialog.append_push_button('選択頂点'+str(pointsuu)+'個を') idx2=dialog.append_push_button('選択順に連続接合しました。') idx3=dialog.append_push_button('結果を確定する場合はokを') idx4=dialog.append_push_button('取り消す場合はcancelを押してください') if imamodify==1: xshade.scene().enter_modify_mode() kekka=dialog.ask('マルチリンク(選択順に連続接合)') #キャンセルなら形状を削除してクリップボードの形状を元に戻す #さらに頂点の選択状態も元に戻す? if kekka==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() for i in activepointlist: xshade.scene().active_shape().vertex(i).active=True #選択番号が変更されているので、入れなおし for i in range(len(activepointlist2)): xshade.scene().active_shape().vertex(activepointlist2[i]).active_order=i+1 #クリップボードにコピーしたので編集モードに入っておく if imamodify==1: xshade.scene().enter_modify_mode() #選択順に連続接合終わり def doublelooplink(): #ダブルループ接合 #元の形状を念のためクリップボードにコピー xshade.scene().active_shape().copy() xshade.scene().enter_modify_mode() error=0 dousasuru=1 if xshade.scene().selection_mode!=2: dousasuru=0 else: activepointlist=[] for i in range(xshade.scene().active_shape().total_number_of_control_points): if xshade.scene().active_shape().vertex(i).active_order>0: activepointlist.append(i) if len(activepointlist)!=4 and len(activepointlist)!=6: dousasuru=0 error=1 if dousasuru==1: #選択番号順に頂点番号をソート activepointlist2=sort_point_by_active_order(activepointlist) if len(activepointlist)==4: alist=return_looplist(activepointlist2[0],activepointlist2[1],-1) blist=return_looplist(activepointlist2[2],activepointlist2[3],-1) if len(activepointlist)==6: alist=return_looplist(activepointlist2[0],activepointlist2[1],activepointlist2[2]) blist=return_looplist(activepointlist2[3],activepointlist2[4],activepointlist2[5]) #接合 if len(alist)!=0 and len(blist)!=0 and len(alist)==len(blist): for i in range(len(alist)): if return_edge_number(alist[i],blist[i])==-1: xshade.scene().active_shape().append_edge(alist[i],blist[i]) #面の向きがおかしくならないよう面の向きを調整 xshade.scene().active_shape().adjust_face_direction() kekka=True #ダイアログを表示して、選択頂点数と結果を確認してもらう #okで確定(何もせず)cancelだと元に戻す dialog=xshade.create_dialog() idx2=dialog.append_push_button('接続を完了しました。') idx3=dialog.append_push_button('結果を確定する場合はokを') idx4=dialog.append_push_button('取り消す場合はcancelを押してください') # xshade.scene().enter_modify_mode() kekka=dialog.ask('マルチリンク(ダブルループ接合)') #キャンセルなら形状を削除してクリップボードの形状を元に戻す #さらに頂点の選択状態も元に戻す? if kekka==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() for i in activepointlist2: xshade.scene().active_shape().vertex(i).active=True #選択番号が変更されているので、入れなおし for i in range(len(activepointlist2)): xshade.scene().active_shape().vertex(activepointlist2[i]).active_order=i+1 if error==1: #選択頂点数が4個か6個でない時のダイアログ表示 dialog3=xshade.create_dialog() idx111=dialog3.append_push_button('頂点は4個か6個選択してください') muridesu=dialog3.ask('マルチリンク(ダブルループ接合)') #ダブルループ接合終わり #選択形状がポリゴンメッシュの時にのみ作動 if xshade.scene().active_shape().type==7 and xshade.scene().is_modify_mode==True and xshade.scene().selection_mode==2: #ラジオボタンを表示して使用する機能を選択 stdialog=xshade.create_dialog_with_uuid('0x51900F02') idxx=stdialog.append_radio_button('マルチリンク/選択順に対接合/開始点に総接合/座標値で対接合/選択順に連続接合/ダブルループ接合') stdialog.set_value(idxx,0) zikkou=stdialog.ask('マルチリンク') sentaku=stdialog.get_value(idxx) if zikkou==True: if sentaku==0: #選択順に対接合 sentakutui() if sentaku==1: #開始点に総接合 sousetugou() if sentaku==2: #座標値で対接合 zahyousetugou() if sentaku==3: #選択順に連続接合 renzokusetugou() if sentaku==4: #ダブルループ接合 doublelooplink()