#片面削除後ミラーコピー #孤立したポリゴンメッシュがミラーコピー後に面の向きが反転するのを修正(2010.02.23) #上位パートに変換がかかっていると使用できないように変更(2010.03.03) #正常に動作してるものの、プログラム上に記述ミスがあったので修正(2010.11.10) #x座標がマイナスである頂点を全て削除した後、残った頂点、辺、面を反転コピーし #マージ処理を行います。 #動作条件 #選択形状がポリゴンメッシュ def invert_list(list1): #リストを反転して返す newlist=[] for i in range(len(list1)): newlist.append(list1[len(list1)-1-i]) return newlist xscene=xshade.scene() ashape=xshade.scene().active_shape() dousasuru=0 if ashape.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: imamodify=xscene.is_modify_mode xscene.inhibit_update() #元の形状をコピー ashape.copy() # if imamodify==True:xscene.enter_modify_mode if imamodify==True:xscene.enter_modify_mode() #x座標がマイナスの頂点を削除 kesulist=[] for i in range(ashape.total_number_of_control_points): tpos=ashape.vertex(i).position if tpos[0]<0:kesulist.append(i) ashape.begin_removing_control_points() for i in kesulist: ashape.vertex(i).remove() ashape.end_removing_control_points() #残った頂点、辺、面を反転コピー vposlist=[] ev01list=[] facelist=[] tasu=ashape.total_number_of_control_points for i in range(tasu): tpos=ashape.vertex(i).position vposlist.append([tpos[0]*(-1),tpos[1],tpos[2]]) for i in range(ashape.number_of_edges): tv0=ashape.edge(i).v0+tasu tv1=ashape.edge(i).v1+tasu ev01list.append([tv0,tv1]) for i in range(ashape.number_of_faces): tvlist=list(ashape.face(i).vertex_indices) for i in range(len(tvlist)): tvlist[i]=tvlist[i]+tasu tvlist=invert_list(tvlist) facelist.append(tvlist) #コピー for i in vposlist: ashape.append_point(i) for i in ev01list: ashape.make_edge(i[0],i[1]) for i in facelist: ashape.append_face(i) ashape.cleanup_redundant_vertices() ashape.adjust_face_direction() xscene.allow_update() #やり直すか聞く #ダイアログを表示して、選択頂点数と結果を確認してもらう #okで確定(何もせず)cancelだと元に戻す if dousasuru==1: dialog=xshade.create_dialog() 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() if imamodify==1: xshade.scene().enter_modify_mode() if kekka==True: if imamodify==0: xscene.exit_modify_mode()