#ポリライン・ペンツール #現在選択している形状がポリゴンメッシュ以外の場合 #ポリゴンメッシュの作成を開始し、カーソルの座標に頂点を一つ作成し、その頂点を選択状態にします。 #ポリゴンメッシュを選択状態の場合 # 編集モードに入っており、かつ頂点編集モードに入っている場合(面選択モードや辺選択モードでは無反応) # #  頂点をまったく選択してない状態 #   カーソルの座標に頂点を一つ追加し、その頂点を選択状態にします。 #  頂点を一つだけ選択してる状態(複数個選択では無反応) #   カーソルの座標に頂点を一つ追加し、選択していた頂点とエッジを張り、追加した頂点だけを選択状態にします。 #  ただし、選択している頂点を有する辺の隣接面が0か1個の場合のみ作動する。(不正なトポロジーにならないように) #おまけとして、複数の頂点を選択状態で実行すると、全選択解除となります。 #ローカル座標モードや、ろくろ機能で図面を傾けた場合は、作成される頂点の位置がおかしくなります。 def return_henkan_pos(pos,mat): #posをmatで変換した座標(タプル)を返す tempx=pos[0] tempy=pos[1] tempz=pos[2] x1=mat[0][0]*tempx+mat[1][0]*tempy+mat[2][0]*tempz+mat[3][0]*1 y1=mat[0][1]*tempx+mat[1][1]*tempy+mat[2][1]*tempz+mat[3][1]*1 z1=mat[0][2]*tempx+mat[1][2]*tempy+mat[2][2]*tempz+mat[3][2]*1 return [x1,y1,z1] 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_setuzokuhen(point): #頂点番号を渡すと、その頂点と接続されている辺のリストを返す henlist=[] for i in range(xshade.scene().active_shape().number_of_edges): if xshade.scene().active_shape().edge(i).v0==point or xshade.scene().active_shape().edge(i).v1==point: henlist.append(i) return henlist if xshade.scene().active_shape().type==7 and xshade.scene().is_modify_mode==True and xshade.scene().selection_mode==2: tempcursor_pos=xshade.scene().current_cursor_position mat4=xshade.scene().active_shape().world_to_local_matrix # mat4=xshade.scene().active_shape().local_to_world_matrix cursorpos=return_henkan_pos(tempcursor_pos,mat4) if xshade.scene().active_shape().number_of_active_control_points==1: #ポリゴンメッシュで一つの頂点を選択してる場合 pointnum=0 for i in range(xshade.scene().active_shape().total_number_of_control_points): if xshade.scene().active_shape().vertex(i).active_order>0: pointnum=i error=1 #選択頂点に接続されている辺の隣接面の数を検査 setuzokuhenlist=return_setuzokuhen(pointnum) if len(setuzokuhenlist)<1:error=0 else: for i in setuzokuhenlist: tempmenlist=return_menlist(i) if len(tempmenlist)<2:error=0 if error==0: # xshade.scene().cursor_position=xshade.scene().active_shape().vertex(pointnum).position # xshade.scene().append_polygon_mesh_vertex(xshade.scene().current_cursor_position) xshade.scene().append_polygon_mesh_vertex(cursorpos) maxnum=xshade.scene().active_shape().total_number_of_control_points-1 xshade.scene().active_shape().append_edge(maxnum,pointnum) xshade.scene().active_shape().vertex(maxnum).active=True xshade.scene().active_shape().vertex(pointnum).active=False #面の向きがおかしくならないよう面の向きを調整 #xshade.scene().active_shape().adjust_face_direction() xshade.scene().exit_modify_mode() xshade.scene().enter_modify_mode() if xshade.scene().active_shape().number_of_active_control_points==0: #ポリゴンメッシュで選択頂点が0の場合 # xshade.scene().append_polygon_mesh_vertex(xshade.scene().current_cursor_position) xshade.scene().append_polygon_mesh_vertex(cursorpos) maxnum=xshade.scene().active_shape().total_number_of_control_points-1 xshade.scene().active_shape().vertex(maxnum).active=True if xshade.scene().active_shape().number_of_active_control_points>1: #ポリゴンメッシュで選択頂点が2以上の場合は全選択解除 for i in range(xshade.scene().active_shape().total_number_of_control_points): xshade.scene().active_shape().vertex(i).active=False xshade.scene().exit_modify_mode() xshade.scene().enter_modify_mode() if xshade.scene().active_shape().type!=7: tempcursor_pos=xshade.scene().current_cursor_position mat4=xshade.scene().active_shape().world_to_local_matrix # mat4=xshade.scene().active_shape().local_to_world_matrix cursorpos=return_henkan_pos(tempcursor_pos,mat4) #ポリゴンメッシュ以外を選択の場合 xshade.scene().begin_creating() xshade.scene().begin_polygon_mesh(None) # xshade.scene().append_polygon_mesh_vertex(xshade.scene().current_cursor_position) xshade.scene().append_polygon_mesh_vertex(cursorpos) xshade.scene().end_polygon_mesh() xshade.scene().end_creating() xshade.scene().enter_modify_mode() xshade.scene().selection_mode=2 xshade.scene().active_shape().vertex(0).active=True