#線形状をポリラインに変換&マージ #やり直した際にデフォルトの分割数が書き換えられるバグ修正(20100214) #上位パートに変換がかかっていると使用できないように変更(2010.03.03) #shade1202に対応 #円や線形状を分割数どおりにポリライン化して真上のポリゴンメッシュとマージします #閉じた線形状や円の場合は、穴のあいたポリラインか、穴のあいてないポリゴン(Ngon)のどちらにするか選択 #動作条件 #選択している形状が線形状か円でかつ真上(兄階層)にポリゴンメッシュがあるか dousasuru=0 if xshade.scene().active_shape().type==4 or xshade.scene().active_shape().type==6: if xshade.scene().active_shape().has_sis==True: if xshade.scene().active_shape().type==6: closed=1 else: closed=xshade.scene().active_shape().closed # if xshade.scene().active_shape().sis.type==7 and closed==1: if xshade.scene().active_shape().sis.type==7: dousasuru=1 if dousasuru>0: #上位パートに変換がかかっているなら動作しない if xshade.scene().active_shape().local_to_world_matrix!=((1.0, 0.0, 0.0, 0.0), (0.0, 1.0, 0.0, 0.0), (0.0, 0.0, 1.0, 0.0), (0.0, 0.0, 0.0, 1.0)): dousasuru=0 dialog=xshade.create_dialog() dialog.append_push_button('上位パートに変換がかかっているため') dialog.append_push_button('スクリプトが実行できません') dialog.ask('エラー') if dousasuru==1: ana=0#穴をあけるか 0であける1であけない nokosu=1#元の線形状および円を残すかどうか musubu=0#近距離で結ぶか renzoku=1 bunkatu=xshade.scene().active_shape().total_number_of_control_points if xshade.scene().active_shape().type==6:bunkatu=4 if xshade.scene().active_shape().type==4: if xshade.scene().active_shape().closed==0: bunkatu-=1 dfbunkatu=bunkatu while(renzoku==1): #ダイアログ表示 dialog=xshade.create_dialog() idx1=dialog.append_int('分割数(デフォルト'+str(dfbunkatu)+')') idx2=dialog.append_radio_button('/ポリライン化/ポリゴン化') idx4=dialog.append_bool('近距離で結ぶ') idx3=dialog.append_bool('元の線形状あるいは円を残す') dialog.set_value(idx1,bunkatu) dialog.set_value(idx2,ana) dialog.set_value(idx3,nokosu) dialog.set_value(idx4,musubu) xshade.idle(10) kekka=dialog.ask('ポリラインに変換&マージ') if kekka==False: renzoku=0 break if kekka==True: bunkatu=dialog.get_value(idx1) ana=dialog.get_value(idx2) nokosu=dialog.get_value(idx3) musubu=dialog.get_value(idx4) #元の線形状および円をクリップボードにコピー xshade.scene().active_shape().copy() #円の場合はまず線形状に変換 if xshade.scene().active_shape().type==6: closed=1 else: closed=xshade.scene().active_shape().closed if xshade.scene().active_shape().type==6: xshade.scene().convert_to_line_object() if closed==1: xshade.scene().active_shape().convert_to_polygon_mesh_with_divisions(bunkatu,1) else: # xshade.scene().select_sister() xshade.scene().clear() xshade.scene().begin_creating() xshade.scene().begin_surface_part() xshade.scene().end_surface_part() xshade.scene().end_creating() xshade.scene().paste() xshade.scene().paste() xshade.scene().select_parent() xshade.scene().active_shape().convert_to_polygon_mesh_with_divisions(1,bunkatu) for tt in range(xshade.scene().active_shape().total_number_of_control_points-1): xshade.scene().active_shape().append_edge(tt,tt+1) xshade.scene().active_shape().cleanup_redundant_vertices() #真上のポリゴンメッシュに移植 #ポリゴンメッシュの頂点座標リストとエッジの両端の頂点番号リスト、5角形以上の面の頂点タプルリストを作成 vposlist=[] v01list=[] ngonlist=[] ngon=0 # edgenum=xshade.scene().active_shape().number_of_edges for i in range(xshade.scene().active_shape().total_number_of_control_points): vposlist.append(xshade.scene().active_shape().vertex(i).position) for i in range(xshade.scene().active_shape().number_of_edges): v01list.append([xshade.scene().active_shape().edge(i).v0,xshade.scene().active_shape().edge(i).v1]) for i in range(xshade.scene().active_shape().number_of_faces): templist=xshade.scene().active_shape().face(i).vertex_indices if len(templist)>2: ngon+=1 ngonlist.append(templist) # if nokosu==0: # xshade.scene().clear() # else: # xshade.scene().clear() # xshade.scene().paste() # xshade.scene().active_shape().rendering=0 # xshade.scene().hide_active() # # xshade.scene().select_sister() xshade.scene().clear() xshade.scene().paste() xshade.scene().hide_active() xshade.scene().select_sister() #上のポリゴンメッシュをクリップボードに記憶しておく xshade.scene().active_shape().copy() #上のポリゴンメッシュに追加する tasu=xshade.scene().active_shape().total_number_of_control_points for i in vposlist: xshade.scene().active_shape().append_point(i) for i in v01list: # xshade.scene().active_shape().append_edge(i[0]+tasu,i[1]+tasu) xshade.scene().active_shape().make_edge(i[0]+tasu,i[1]+tasu) if ngon>0 and ana==1: for i in ngonlist: tempvlist=list(i) for j in range(len(tempvlist)): tempvlist[j]=tempvlist[j]+tasu temptup=tuple(tempvlist) xshade.scene().active_shape().append_face(temptup) tasu2=xshade.scene().active_shape().total_number_of_control_points #近距離点と結ぶ if musubu==1: for i in range(tasu,tasu2): pos=xshade.scene().active_shape().vertex(i).position temppos=xshade.scene().active_shape().vertex(0).position tempkyori=(temppos[0]-pos[0])**2+(temppos[1]-pos[1])**2+(temppos[2]-pos[2])**2 saitan=0 saitanlist=[] saitanlist.append([0,tempkyori]) for j in range(1,tasu): temppos2=xshade.scene().active_shape().vertex(j).position tempkyori2=(temppos2[0]-pos[0])**2+(temppos2[1]-pos[1])**2+(temppos2[2]-pos[2])**2 if tempkyori2<=tempkyori: saitanlist.insert(0,[j,tempkyori2]) tempkyori=tempkyori2 loop=1 for gg in saitanlist: if gg[1]!=tempkyori: break else: xshade.scene().active_shape().append_edge(i,gg[0]) # xshade.scene().active_shape().append_edge(i,saitan) #重複した頂点の削除 xshade.scene().active_shape().cleanup_redundant_vertices() #面の向きがおかしくならないよう面の向きを調整 xshade.scene().active_shape().adjust_face_direction() #やり直すか? kekka2=True #ダイアログを表示して、結果を確認してもらう #okで確定cancelだと元に戻す dialog=xshade.create_dialog_with_uuid('0x51900F00') idx3=dialog.append_push_button('結果を確定する場合はokを') idx4=dialog.append_push_button('取り消す場合はcancelを押してください') xshade.idle(10) kekka2=dialog.ask('ポリライン化とマージ') #キャンセルなら形状を削除してクリップボードの形状を元に戻す if kekka2==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().select_brother() xshade.scene().show_active() xshade.idle(10) if kekka2==True: renzoku=0 if nokosu==0: xshade.scene().select_brother() xshade.scene().clear() else: xshade.scene().select_brother() xshade.scene().active_shape().rendering=0 xshade.scene().select_sister() #戻す終わり