当前位置: 首页>>代码示例>>Python>>正文


Python BPyMesh.ngon方法代码示例

本文整理汇总了Python中BPyMesh.ngon方法的典型用法代码示例。如果您正苦于以下问题:Python BPyMesh.ngon方法的具体用法?Python BPyMesh.ngon怎么用?Python BPyMesh.ngon使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BPyMesh的用法示例。


在下文中一共展示了BPyMesh.ngon方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create_mesh

# 需要导入模块: import BPyMesh [as 别名]
# 或者: from BPyMesh import ngon [as 别名]
def create_mesh(scn, new_objects, has_ngons, CREATE_FGONS, CREATE_EDGES, verts_loc, verts_tex, faces, unique_materials, unique_material_images, unique_smooth_groups, dataname):
	'''
	Takes all the data gathered and generates a mesh, adding the new object to new_objects
	deals with fgons, sharp edges and assigning materials
	'''
	if not has_ngons:
		CREATE_FGONS= False
	
	if unique_smooth_groups:
		sharp_edges= {}
		smooth_group_users= dict([ (context_smooth_group, {}) for context_smooth_group in unique_smooth_groups.iterkeys() ])
		context_smooth_group_old= -1
	
	# Split fgons into tri's
	fgon_edges= {} # Used for storing fgon keys
	if CREATE_EDGES:
		edges= []
	
	context_object= None
	
	# reverse loop through face indicies
	for f_idx in xrange(len(faces)-1, -1, -1):
		
		face_vert_loc_indicies,\
		face_vert_tex_indicies,\
		context_material,\
		context_smooth_group,\
		context_object= faces[f_idx]
		
		len_face_vert_loc_indicies = len(face_vert_loc_indicies)
		
		if len_face_vert_loc_indicies==1:
			faces.pop(f_idx)# cant add single vert faces
		
		elif not face_vert_tex_indicies or len_face_vert_loc_indicies == 2: # faces that have no texture coords are lines
			if CREATE_EDGES:
				# generators are better in python 2.4+ but can't be used in 2.3
				# edges.extend( (face_vert_loc_indicies[i], face_vert_loc_indicies[i+1]) for i in xrange(len_face_vert_loc_indicies-1) )
				edges.extend( [(face_vert_loc_indicies[i], face_vert_loc_indicies[i+1]) for i in xrange(len_face_vert_loc_indicies-1)] )

			faces.pop(f_idx)
		else:
			
			# Smooth Group
			if unique_smooth_groups and context_smooth_group:
				# Is a part of of a smooth group and is a face
				if context_smooth_group_old is not context_smooth_group:
					edge_dict= smooth_group_users[context_smooth_group]
					context_smooth_group_old= context_smooth_group
				
				for i in xrange(len_face_vert_loc_indicies):
					i1= face_vert_loc_indicies[i]
					i2= face_vert_loc_indicies[i-1]
					if i1>i2: i1,i2= i2,i1
					
					try:
						edge_dict[i1,i2]+= 1
					except KeyError:
						edge_dict[i1,i2]=  1
			
			# FGons into triangles
			if has_ngons and len_face_vert_loc_indicies > 4:
				
				ngon_face_indices= BPyMesh.ngon(verts_loc, face_vert_loc_indicies)
				faces.extend(\
				[(\
				[face_vert_loc_indicies[ngon[0]], face_vert_loc_indicies[ngon[1]], face_vert_loc_indicies[ngon[2]] ],\
				[face_vert_tex_indicies[ngon[0]], face_vert_tex_indicies[ngon[1]], face_vert_tex_indicies[ngon[2]] ],\
				context_material,\
				context_smooth_group,\
				context_object)\
				for ngon in ngon_face_indices]\
				)
				
				# edges to make fgons
				if CREATE_FGONS:
					edge_users= {}
					for ngon in ngon_face_indices:
						for i in (0,1,2):
							i1= face_vert_loc_indicies[ngon[i  ]]
							i2= face_vert_loc_indicies[ngon[i-1]]
							if i1>i2: i1,i2= i2,i1
							
							try:
								edge_users[i1,i2]+=1
							except KeyError:
								edge_users[i1,i2]= 1
					
					for key, users in edge_users.iteritems():
						if users>1:
							fgon_edges[key]= None
				
				# remove all after 3, means we dont have to pop this one.
				faces.pop(f_idx)
		
		
	# Build sharp edges
	if unique_smooth_groups:
		for edge_dict in smooth_group_users.itervalues():
			for key, users in edge_dict.iteritems():
#.........这里部分代码省略.........
开发者ID:merfed,项目名称:wow2collada,代码行数:103,代码来源:importer.py

示例2: processBuilding

# 需要导入模块: import BPyMesh [as 别名]
# 或者: from BPyMesh import ngon [as 别名]
def processBuilding(building, groups, ids,path):
	#
	global zzMesh
	if zzMesh==None:
		zzMesh=bpy.data.meshes.new('zz')
	# 
	o=open(os.sep.join([path,'building_%i.bld'%building]),'w')
	# Compute building position!
	avgX=0.0
	avgY=0.0
	minX=9999.0
	maxX=-9999.0
	minY=9999.0
	maxY=-9999.0
	count=0
	for id in groups[building]:
		for (x,y,z) in ids[id][Attributes.GEOM]:
			avgX+=x
			avgY+=y
			count+=1
			if x>maxX: maxX=x
			if x<minX: minX=x
			if y>maxY: maxY=y
			if y<minY: minY=y
	icountf=1.0/float(count)
	avgX*=icountf
	avgY*=icountf
	print >>o, '{'
	print >>o, '	"origin":(%f,%f),'%(avgX,avgY)
	print >>o, '	"bounds":((%f,%f),(%f,%f)),'%(minX,minY,maxX,maxY)
	print >>o, '	"parts":{'
	# Convert geometry to meters
	angleToDistance=111226.3
	yFactor=math.cos(avgY*0.017453292519943295769236907684886)
	baseindex=0
	for id in groups[building]:
		print >>o, '		%i:{'%id
		# First, base geometry
		l=len(ids[id][Attributes.GEOM])
		for i in xrange(0,l):
			(x,y,z)=ids[id][Attributes.GEOM][i]
			ids[id][Attributes.GEOM][i]=[(x-avgX)*angleToDistance*yFactor, (y-avgY)*angleToDistance, z]
		baseindex+=1
		basegeom=ids[id][Attributes.GEOM]
		faces=BPyMesh.ngon(basegeom[::-1], range(0,len(basegeom)))
		zzMesh.verts.delete(zzMesh.verts)
		zzMesh.verts.extend(basegeom[::-1])
		zzMesh.faces.extend(faces)
		zzMesh.calcNormals()
		print >>o, '			"base":{'
		outputMesh(o,zzMesh,4)
		print >>o, '			},'
		# Then, roofs
		topgeom=[]
		if ids[id].has_key(Attributes.ROOF):
			print >>o, '			"roofs":['
			l=len(ids[id][Attributes.ROOF])
			for i in xrange(0,l):
				ll=len(ids[id][Attributes.ROOF][i])
				for j in xrange(0,ll):
					(x,y,z)=ids[id][Attributes.ROOF][i][j]
					ids[id][Attributes.ROOF][i][j]=[(x-avgX)*angleToDistance*yFactor, (y-avgY)*angleToDistance, z]
				rgeom=ids[id][Attributes.ROOF][i]
				topgeom.extend(rgeom)
				faces=BPyMesh.ngon(rgeom, range(0,len(rgeom)))
				zzMesh.verts.delete(zzMesh.verts)
				zzMesh.verts.extend(rgeom)
				zzMesh.faces.extend(faces)
				zzMesh.calcNormals()
				#
				print >>o, '				{'
				outputMesh(o,zzMesh,5)
				print >>o, '				},'
			print >>o, '			],'
		# Last, pediments
		if ids[id].has_key(Attributes.PEDIMENT):
			print >>o, '			"pediments":['
			l=len(ids[id][Attributes.PEDIMENT])
			for i in xrange(0,l):
				ll=len(ids[id][Attributes.PEDIMENT][i])
				for j in xrange(0,ll):
					(x,y,z)=ids[id][Attributes.PEDIMENT][i][j]
					ids[id][Attributes.PEDIMENT][i][j]=[(x-avgX)*angleToDistance*yFactor, (y-avgY)*angleToDistance, z]
				pgeom=ids[id][Attributes.PEDIMENT][i]
				topgeom.extend(pgeom)
				faces=BPyMesh.ngon(pgeom, range(0,len(pgeom)))
				zzMesh.verts.delete(zzMesh.verts)
				zzMesh.verts.extend(pgeom)
				zzMesh.faces.extend(faces)
				zzMesh.calcNormals()
				#
				print >>o, '				{'
				outputMesh(o,zzMesh,5)
				print >>o, '				},'
			print >>o, '			],'
		# And while we're here, construct some walls...
		upper=[]
		for (x,y,z) in basegeom:
			minz=99999.0
			for (rx,ry,rz) in topgeom:
#.........这里部分代码省略.........
开发者ID:jcayzac,项目名称:random-stuff,代码行数:103,代码来源:shp2py_main.py


注:本文中的BPyMesh.ngon方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。