#頂点のディゾルブ2 #選択頂点のうち、二つの頂点にのみ接続されている頂点が削除され、その頂点に接続されていた前後の頂点同士にエッジが張られます #複数の頂点を選択状態だと、そのうち二つの頂点とのみ接続している頂点全てを個々にディゾルブします。 #三点以上の頂点と接続されてる頂点が選択の中に入っていても、その頂点は無視します。 #動作条件 #選択形状がポリゴンメッシュ a #編集モードに入ってる a #頂点選択モード a #頂点が一つ以上選択されている 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_edge_number(pointnum1,pointnum2): #頂点二つの頂点番号を与えると、その頂点で構成される辺の辺番号を返す #エラー(辺の両端のポイントでは無い)の場合は-1を返す returnnum=-1 for i in range(xshade.scene().active_shape().number_of_edges): if xshade.scene().active_shape().edge(i).v0==pointnum1 and xshade.scene().active_shape().edge(i).v1==pointnum2: returnnum=i if xshade.scene().active_shape().edge(i).v1==pointnum1 and xshade.scene().active_shape().edge(i).v0==pointnum2: returnnum=i return returnnum 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 substract_b_from_a(lista,listb): #リストAからリストBに存在する要素を抜いたリストを返す a[1,2,3,4,4,5] b[3,4] 結果[1,2,5] #リストBに重複する値が存在するとエラーが出るので、あらかじめ重複する値は消しておく listacopy=[] for i in range(len(lista)): listacopy.append(lista[i]) listbcopy=[] for i in range(len(listb)): listbcopy.append(listb[i]) kesulis=[] for i in listbcopy: for j in listacopy: if j==i: kesulis.append(i) for i in kesulis: listacopy.remove(i) return listacopy #頂点のディゾルブプログラム開始 if xshade.scene().is_modify_mode==True and xshade.scene().selection_mode==2 and xshade.scene().active_shape().type==7: if xshade.scene().active_shape().number_of_active_control_points>0: #元形状をクリップボードにコピーしておく xshade.scene().active_shape().copy() xshade.scene().enter_modify_mode() #選択頂点をリスト化して格納 activepointlist=[] positionlist=[]#選択頂点の位置リスト 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) positionlist.append(xshade.scene().active_shape().vertex(i).position) #各頂点ごとにディゾルブ xshade.scene().active_shape().begin_removing_control_points() for i in activepointlist: setuzokulist=return_pointlist(i) if len(setuzokulist)==2: if return_edge_number(setuzokulist[0],setuzokulist[1])==-1: xshade.scene().active_shape().append_edge(setuzokulist[0],setuzokulist[1]) xshade.scene().active_shape().vertex(i).remove() xshade.scene().active_shape().end_removing_control_points() #連続している頂点を選択状態では一部の頂点が残ってしまうので、その頂点を選択状態に for i in range(len(activepointlist)): for ggg in range(xshade.scene().active_shape().total_number_of_control_points): if xshade.scene().active_shape().vertex(ggg).position==(positionlist[i][0],positionlist[i][1],positionlist[i][2]): xshade.scene().active_shape().vertex(ggg).active=True #面の向きを統一しておく xshade.scene().active_shape().adjust_face_direction()