#選択辺を線形状に変換 #ポリゴンメッシュ上の連なる辺を選択状態で実行すると、それを線形状に変換してくれる機能です。 #ループしてる場合は閉じた線形状に変換します。 #複数の切断された辺を選択してる場合や、分岐してるような形で辺を選択してる場合は機能しません。 #特定の選択状態で発生する無限ループバグを解消版 #動作条件 #選択形状がポリゴンメッシュ #編集モードに入っている #辺編集モード #辺がひとつでも選択されている def erase_same_num_all(list1): #リスト内に同じ値が重複する場合はその値を全て消したリストを返す関数 例[1,1,1,3,3,4]→[4] #erase_same_numが必要 list1copy=[] for i in range(len(list1)): list1copy.append(list1[i]) list1copy.sort() nagasa=len(list1copy) if nagasa>1: kesu=[] for i in range(nagasa-1): if list1copy[i]==list1copy[i+1]: kesu.append(list1[i]) kesukaisuu=len(kesu) if kesukaisuu>0: for i in kesu: list1copy.remove(i) erase_same_num(kesu) if len(kesu)>0: for i in kesu: list1copy.remove(i) return list1copy def erase_same_num(list1): #リスト内に同じ値が重複する場合は一つに減らす関数 例[1,1,1,3,3,4]→[1,3,4] #呼び出す時はlist=erase_same_num(list)ではなく、erase_same_num(list)で良い list1.sort() nagasa=len(list1) if nagasa>1: kesu=[] for i in range(nagasa-1): if list1[i]==list1[i+1]: kesu.append(list1[i]) kesukaisuu=len(kesu) if kesukaisuu>0: for i in kesu: list1.remove(i) def return_same_num(list1): #リスト内に同じ値が重複する場合はその重複してる数字だけをひとつずつ返す関数 例[1,1,1,3,3,4]→[1,3] #erase_same_numが必要 list1copy=[] for i in list1: list1copy.append(i) list1copy.sort() nagasa=len(list1copy) if nagasa>1: kaesu=[] for i in range(nagasa-1): if list1copy[i]==list1copy[i+1]: kaesu.append(list1copy[i]) erase_same_num(kaesu) return kaesu dousasuru=0 senclosed=0#1なら閉じた線形状 0なら開いた線形状 mugen=0 if xshade.scene().is_modify_mode==True and xshade.scene().active_shape().type==7 and xshade.scene().selection_mode ==1: activeedgelist=[] dousasuru=1 for i in range(xshade.scene().active_shape().number_of_edges): if xshade.scene().active_shape().edge(i).active_order>0: activeedgelist.append(i) if len(activeedgelist)==0: dousasuru=0 #分岐してないかどうかの検査 if dousasuru==1: pointlist=[] for i in activeedgelist: pointlist.append(xshade.scene().active_shape().edge(i).v0) pointlist.append(xshade.scene().active_shape().edge(i).v1) temppointlist=[] for i in pointlist: temppointlist.append(i) #辺のポイントリストで、同じ値が二つ以上存在する場合、その値を二つずつ消していって残った数が0個の場合はループしてる1本の線、2個の場合は開いた線、それ以外は分岐している kesulist=return_same_num(temppointlist) temppointlist2=[] for i in temppointlist: temppointlist2.append(i) erase_same_num(temppointlist2) for i in kesulist: temppointlist.remove(i) temppointlist.remove(i) if len(temppointlist)==0 or (len(temppointlist)==2): if len(temppointlist)==0: senclosed=1 else: dousasuru=0 if dousasuru==1: edgelistcopy=[] for i in activeedgelist: edgelistcopy.append(i) #開始点を決める(ループしてる場合はどこからでもいい。ループしてない場合は端の点から開始) senpointlist=[] if senclosed==1: startpoint=pointlist[0] else: startpoint=temppointlist[0] senpointlist.append(startpoint) imapoint=startpoint while(len(edgelistcopy)>0): mugen+=1 if mugen>2000: break kesuyo=-1 for i in edgelistcopy: if xshade.scene().active_shape().edge(i).v0==imapoint: senpointlist.append(xshade.scene().active_shape().edge(i).v1) imapoint=xshade.scene().active_shape().edge(i).v1 kesuyo=i break if xshade.scene().active_shape().edge(i).v1==imapoint: senpointlist.append(xshade.scene().active_shape().edge(i).v0) imapoint=xshade.scene().active_shape().edge(i).v0 kesuyo=i break if kesuyo!=-1: edgelistcopy.remove(kesuyo) if senclosed==1: senpointlist=senpointlist[1:] if mugen<2001: #座標リストを作成 poslist=[] for i in senpointlist: ttt=xshade.scene().active_shape() poslist.append([ttt.vertex(i).position[0],ttt.vertex(i).position[1],ttt.vertex(i).position[2]]) #線形状描画 xshade.scene().begin_creating() xshade.scene().begin_line(None, senclosed) for i in poslist: xshade.scene().append_point(i, None, None, None, None) xshade.scene().end_line() xshade.scene().end_creating()