#選択頂点の中心に円球を作成 #上位パートに変換がかかっていると使用できないように変更(2010.03.03) #ポリゴンメッシュで頂点をいくつか選択してからこのスクリプトを実行すると、選択頂点の中心位置に円か球を作成できます。 #shade1202に対応 #動作条件 #選択形状がポリゴンメッシュ #編集モードに入っている #頂点編集モード #頂点を一つ以上選択している dousasuru=0 if xshade.scene().is_modify_mode==True and xshade.scene().active_shape().type==7: if xshade.scene().selection_mode==2: 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) if len(activepointlist)>0: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: #初期設定 type=0#0なら円を作成 1なら球を作成 muki=0#円作成の場合の向き hankei=100#円および球の半径 renzoku=1 hankeitype=0#0なら指定サイズ、1なら外周、2なら内周 while(renzoku==1): #ダイアログ表示 dialog=xshade.create_dialog() idx1=dialog.append_radio_button('/円/球') dialog.begin_group('円の場合の向き') # idx2=dialog.append_radio_button('/X軸に直行/Y軸に直行/Z軸に直行/選択頂点に平行') idx2=dialog.append_radio_button('/X軸に直行/Y軸に直行/Z軸に直行') dialog.end_group() idx3=dialog.append_radio_button('半径サイズ/指定/外周/内周') dialog.begin_group('「指定」の場合の半径サイズ') idx4=dialog.append_float('半径サイズ') dialog.end_group() dialog.set_value(idx1,type) dialog.set_value(idx2,muki) dialog.set_value(idx3,hankeitype) dialog.set_value(idx4,hankei) xshade.idle(10) kekka=dialog.ask('選択頂点の中心に円球を作成') if kekka==False:renzoku=0 if kekka==True: type=dialog.get_value(idx1) muki=dialog.get_value(idx2) hankeitype=dialog.get_value(idx3) hankei=dialog.get_value(idx4) #中心位置を求める kaisuu=0 possum=[0,0,0] for i in activepointlist: pos=xshade.scene().active_shape().vertex(i).position kaisuu+=1 possum[0]=pos[0]+possum[0] possum[1]=pos[1]+possum[1] possum[2]=pos[2]+possum[2] possum=[possum[0]/kaisuu,possum[1]/kaisuu,possum[2]/kaisuu] #半径サイズを求める if hankeitype==0:dhankei=hankei if hankeitype==1: temppos=xshade.scene().active_shape().vertex(activepointlist[0]).position dhankei=pow((temppos[0]-possum[0])**2+(temppos[1]-possum[1])**2+(temppos[2]-possum[2])**2,0.5) for i in activepointlist: temppos=xshade.scene().active_shape().vertex(i).position tempsize=pow((temppos[0]-possum[0])**2+(temppos[1]-possum[1])**2+(temppos[2]-possum[2])**2,0.5) if tempsize>=dhankei:dhankei=tempsize if hankeitype==2: temppos=xshade.scene().active_shape().vertex(activepointlist[0]).position dhankei=pow((temppos[0]-possum[0])**2+(temppos[1]-possum[1])**2+(temppos[2]-possum[2])**2,0.5) for i in activepointlist: temppos=xshade.scene().active_shape().vertex(i).position tempsize=pow((temppos[0]-possum[0])**2+(temppos[1]-possum[1])**2+(temppos[2]-possum[2])**2,0.5) if tempsize<=dhankei:dhankei=tempsize #球の作成 if type==1: xshade.scene().begin_creating() xshade.scene().create_sphere(None,possum,dhankei) xshade.scene().end_creating() #円の作成 if type==0: if muki==3: tmuki=2 else: tmuki=muki xshade.scene().begin_creating() xshade.scene().create_disk(None,possum,dhankei,tmuki) xshade.scene().end_creating() #「選択頂点に平行」の場合は円を回転する if muki==3 and len(activepointlist)>2: xshade.scene().select_sister() #選択頂点三つから平面方程式のパラメーターを求める temppointlist3=[] for vv in range(3): temppointlist3.append(xshade.scene().active_shape().vertex(activepointlist[vv]).position) heimenp=xshade.make_plane_equation((temppointlist3[0],temppointlist3[1],temppointlist3[2])) tempvec=tuple([heimenp[0],heimenp[1],heimenp[2]]) #選択頂点の平面と直行するベクトル henkanmat=xshade.get_amat((0.0,0.0,1.0),tempvec) seibun=xshade.unmatrix(henkanmat) # print seibun xshade.scene().select_brother() kaitens=seibun[2] print kaitens #円を回転 xshade.scene().exit_modify_mode() xshade.scene().move_object(possum,[1.0,1.0,1.0],[kaitens[0],kaitens[1],kaitens[2]],[0,0,0]) # xshade.scene().move_object(possum,[1.0,1.0,1.0],[60,60,0],[0,0,0]) #xshade.scene().move_object([150.000000, 0.000000, 750.000000], [1.000000, 1.000000, 1.000000], [120.000000, 0.000000, 0.000000], [0.000000, 0.000000, 0.000000]) #やり直すか #ダイアログを表示して、結果を確認してもらう #okで確定(何もせず)cancelだと元に戻す dialog=xshade.create_dialog() idx3=dialog.append_push_button('結果を確定する場合はokを') idx4=dialog.append_push_button('取り消す場合はcancelを押してください') xshade.idle(10) kekka2=dialog.ask('選択頂点の中心に円球を作成') #キャンセルなら円あるいは球を削除 if kekka2==False: xshade.scene().clear() xshade.scene().enter_modify_mode() if kekka2==True: renzoku=0 #戻す終わり