#ベルト抜きスクリプト #メタセコイアの「ナイフ>連続辺を連続消去」みたいなスクリプトです。(ただし消す辺は手動で全て選択しないといけない) #辺は消えるけど、辺を境に隣接する面同士を結合させていきます #頂点あるいは辺はあらかじめ手動で選択しておいてください。 #注意(辺を抜いた場合、5点以上で構成される面が残るケースでは面にポリゴンは張られません) def hantei_same_num(list1): #リスト内に同じ値が存在するなら1を返し、存在しないなら0を返す関数 例[1,1,3]→1 [1,3]→0 list1.sort() nagasa=len(list1) returnnum=0 if nagasa>1: kesu=[] for i in range(nagasa-1): if list1[i]==list1[i+1]: returnnum=1 return returnnum def return_menlist(edgenumber): #その辺を共有する面の面番号をリストで返す(引数 辺番号) menlist=[] edgevertex=[xshade.scene().active_shape().edge(edgenumber).v0,xshade.scene().active_shape().edge(edgenumber).v1] totalmenmen=xshade.scene().active_shape().number_of_faces for i in range(totalmenmen): konomen=0 temppoint=list(xshade.scene().active_shape().face(i).vertex_indices) for j in temppoint: if edgevertex[0]==j: konomen+=1 if edgevertex[1]==j: konomen+=1 if konomen==2: menlist.append(i) return menlist 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 substract_b_from_a(lista,listb): #リストAからリストBに存在する要素を抜く a[1,2,3,4,4,5] b[3,4] 結果[1,2,5] #リストBに重複する値が存在するとエラーが出るので、あらかじめ重複する値は消しておく kesulis=[] for i in listb: for j in lista: if j==i: kesulis.append(i) for i in kesulis: lista.remove(i) return lista if xshade.scene().is_modify_mode==True and xshade.scene().active_shape().type==7: imamodify=1 #念のため元の形状をクリップボードにコピー xshade.scene().active_shape().copy() #現在の選択モード(頂点、辺、面を記憶しておく) imamode=xshade.scene().selection_mode dousasuru=1 #1なら動作する 0なら動作しない #ポリゴンメッシュかどうか if xshade.scene().active_shape().type!=7: dousasuru=0 #選択頂点数が三個以上か activevertexnum=0 if xshade.scene().selection_mode!=2: xshade.scene().selection_mode=2 for i in range(xshade.scene().active_shape().total_number_of_control_points): if xshade.scene().active_shape().vertex(i).active_order>0: activevertexnum+=1 if activevertexnum<3: dousasuru=0 #辺選択モードにして、辺に隣接する面を辺毎に調べ、同じ面を共有してないかチェックする xshade.scene().selection_mode=1 activeedgelist=[] testmenlist=[] for i in range(xshade.scene().active_shape().number_of_edges): if xshade.scene().active_shape().edge(i).active_order>0: activeedgelist.append(i) testmenlist+=return_menlist(i) if hantei_same_num(testmenlist)==1: dousasuru=0 #95 if dousasuru==1: if xshade.scene().selection_mode!=2: xshade.scene().selection_mode=2 #選択されている頂点をリストに格納 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) #選択頂点ごとに、その頂点とつながっていてかつ選択頂点ではない頂点のリストをリストに格納 setuzokulist=[] #リストの中に接続頂点のリストを入れる for i in activepointlist: templist=return_pointlist(i) templist=substract_b_from_a(templist,activepointlist) setuzokulist.append(templist) #その頂点とつながっていてかつ選択頂点ではない頂点の数が2個の場合のみ、その頂点を消して、接続頂点同士を接続する xshade.scene().active_shape().begin_removing_control_points() for i in range(len(activepointlist)): if len(setuzokulist[i])==2: xshade.scene().active_shape().remove_control_point(activepointlist[i]) temp2=setuzokulist[i] xshade.scene().active_shape().append_edge(temp2[0],temp2[1]) xshade.scene().active_shape().end_removing_control_points() if xshade.scene().selection_mode!=imamode: xshade.scene().selection_mode=imamode #クリップボードに形状をコピーした場合、以下の「編集モードに入る」を実行しないと編集モードでなくなってしまいます xshade.scene().enter_modify_mode() xshade.scene().active_shape().adjust_face_direction() kekka=True imasele=xshade.scene().selection_mode #ダイアログを表示して、選択頂点数と結果を確認してもらう #okで確定(何もせず)cancelだと元に戻す if dousasuru==1: dialog=xshade.create_dialog_with_uuid('0x51900F13') 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() xshade.scene().selection_mode=2 for i in activepointlist: xshade.scene().active_shape().vertex(i).active=True if imasele==1: xshade.scene().selection_mode=1