#選択しているポイントをポリゴンメッシュのすぐ下(弟)に作成した球の球面上に移動 #吸い寄せられる方向は球の中心方向 #選択してるポイント数が0の場合は移動しない #編集モードがonで、かつ頂点編集モードでないと機能しない #ポリゴンメッシュのすぐ下に球が存在する事 dousasuru=0 if xshade.scene().is_modify_mode==True: imamodify=1 #編集モードで、かつ頂点編集で、頂点が一つでも選択されているか? if xshade.scene().is_modify_mode==True and xshade.scene().selection_mode==2 and xshade.scene().active_shape().number_of_active_control_points>0: dousasuru=1 #選択形状はポリゴンメッシュ? if xshade.scene().active_shape().type!=7: dousasuru=0 #真下に球があるか? if xshade.scene().active_shape().bro.type!=5: dousasuru=0 else: #球の半径と中心位置を格納 center1=xshade.scene().active_shape().bro.center radius1=xshade.scene().active_shape().bro.radius if dousasuru==1: #念のため元の形状をクリップボードにコピー xshade.scene().active_shape().copy() #選択されている頂点の頂点番号をリストに格納 activepointlist=[] 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) #選択されている頂点を球面上に移動 for i in activepointlist: #現在の頂点の位置 qx1=xshade.scene().active_shape().vertex(i).position[0] qy1=xshade.scene().active_shape().vertex(i).position[1] qz1=xshade.scene().active_shape().vertex(i).position[2] #球の中心から現在の頂点位置へのベクトルを求める vec1=(qx1-center1[0],qy1-center1[1],qz1-center1[2]) vec2=(abs(vec1[0]),abs(vec1[1]),abs(vec1[2])) #頂点と球との距離を、球の半径のn倍とすると n=(pow(vec2[0]*vec2[0]+vec2[1]*vec2[1]+vec2[2]*vec2[2],0.5)/radius1[0]) #球面上の点は球の中心を開始点とし、頂点のベクトル(vec1)の方へ球頂点間の1/n分移動したものなので… x1=center1[0]+vec1[0]/n y1=center1[1]+vec1[1]/n z1=center1[2]+vec1[2]/n xshade.scene().active_shape().vertex(i).position=(x1,y1,z1) #同一座標の頂点をクリーンナップ xshade.scene().active_shape().cleanup_redundant_vertices() #クリップボードに形状をコピーした場合、以下の「編集モードに入る」を実行しないと編集モードでなくなってしまいます xshade.scene().enter_modify_mode() xshade.scene().active_shape().adjust_face_direction() #以下ダイアログを表示して元に戻す #2スペース分インデントしてあるので使うとき注意 kekka=True #ダイアログを表示して、選択頂点数と結果を確認してもらう #okで確定(何もせず)cancelだと元に戻す if dousasuru==1: dialog=xshade.create_dialog_with_uuid('0x51901F00') 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() xshade.scene().enter_modify_mode() for i in activepointlist: xshade.scene().active_shape().vertex(i).active=True #選択番号が変更されているので、入れなおし for i in range(len(activepointlist)): xshade.scene().active_shape().vertex(activepointlist[i]).active_order=i+1 #戻す終わり