當前位置: 首頁>>代碼示例>>Python>>正文


Python BPyMesh.pickMeshRayFace方法代碼示例

本文整理匯總了Python中BPyMesh.pickMeshRayFace方法的典型用法代碼示例。如果您正苦於以下問題:Python BPyMesh.pickMeshRayFace方法的具體用法?Python BPyMesh.pickMeshRayFace怎麽用?Python BPyMesh.pickMeshRayFace使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在BPyMesh的用法示例。


在下文中一共展示了BPyMesh.pickMeshRayFace方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: main

# 需要導入模塊: import BPyMesh [as 別名]
# 或者: from BPyMesh import pickMeshRayFace [as 別名]
def main():
	
	scn = bpy.data.scenes.active
	ob = scn.objects.active
	if not ob or ob.type!='Mesh':
		return
	
	is_editmode = Window.EditMode()
	if is_editmode:
		Window.EditMode(0)
	
	mousedown_wait() # so the menu items clicking dosnt trigger the mouseclick
	
	Window.DrawProgressBar (0.0, '')
	Window.DrawProgressBar (0.1, '(1 of 3) Click on a face corner')	
	
	# wait for a click
	mouse_buttons = Window.GetMouseButtons()
	while not mouse_buttons & LMB:
		sys.sleep(10)
		mouse_buttons = Window.GetMouseButtons()
		
		# Allow for RMB cancel
		if mouse_buttons & RMB:
			return
		
	while mouse_buttons & LMB:
		sys.sleep(10)
		mouse_buttons = Window.GetMouseButtons()
	
	
	Window.DrawProgressBar (0.2, '(2 of 3 ) Click confirms the U coords')
	
	mousedown_wait()
	
	obmat= ob.matrixWorld
	screen_x, screen_y = Window.GetMouseCoords()
	mouseInView, OriginA, DirectionA = mouseViewRay(screen_x, screen_y, obmat)
	
	if not mouseInView or not OriginA:
		return
	
	me = ob.getData(mesh=1)
	
	# Get the face under the mouse
	face_click, isect, side = BPyMesh.pickMeshRayFace(me, OriginA, DirectionA)
	if not face_click:
		return
	
	proj_z_component = face_click.no
	if not face_click:
		return
	
	# Find the face vertex thats closest to the mouse,
	# this vert will be used as the corner to map from.
	best_v= None
	best_length = 10000000
	vi1 = None
	for i, v in enumerate(face_click.v):
		l = (v.co-isect).length
		if l < best_length:
			best_v = v
			best_length = l
			vi1 = i
	
	# now get the 2 edges in the face that connect to v
	# we can work it out fairly easerly
	if len(face_click)==4:
		if	 vi1==0: vi2, vi3= 3,1
		elif vi1==1: vi2, vi3= 0,2
		elif vi1==2: vi2, vi3= 1,3
		elif vi1==3: vi2, vi3= 2,0
	else:
		if   vi1==0: vi2, vi3= 2,1
		elif vi1==1: vi2, vi3= 0,2
		elif vi1==2: vi2, vi3= 1,0
	
	face_corner_main =face_click.v[vi1].co
	face_corner_a =face_click.v[vi2].co
	face_corner_b =face_click.v[vi3].co
	
	line_a_len = (face_corner_a-face_corner_main).length
	line_b_len = (face_corner_b-face_corner_main).length
	
	orig_cursor = Window.GetCursorPos()
	Window.SetCursorPos(face_corner_main.x, face_corner_main.y, face_corner_main.z)
	
	SHIFT = Window.Qual.SHIFT
	MODE = 0 # firstclick, 1, secondclick
	mouse_buttons = Window.GetMouseButtons()
	
	project_mat = Matrix([0,0,0], [0,0,0], [0,0,0])
	
	
	def get_face_coords(f):
		f_uv = f.uv
		return [(v.co-face_corner_main, f_uv[i]) for i,v in enumerate(f.v)]
	
	if me.faceUV==False:
		me.faceUV= True
#.........這裏部分代碼省略.........
開發者ID:Synric,項目名稱:synricproj,代碼行數:103,代碼來源:uvcalc_quad_clickproj.py


注:本文中的BPyMesh.pickMeshRayFace方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。