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


Python BPyMesh类代码示例

本文整理汇总了Python中BPyMesh的典型用法代码示例。如果您正苦于以下问题:Python BPyMesh类的具体用法?Python BPyMesh怎么用?Python BPyMesh使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: copy_act_vgroup

def copy_act_vgroup(me, PREF_NAME, PREF_SEL_ONLY):
	Window.WaitCursor(1)
	groupNames, vWeightDict= BPyMesh.meshWeight2Dict(me)
	act_group= me.activeGroup
	
	if not PREF_SEL_ONLY:
		for wd in vWeightDict:
			try:		wd[PREF_NAME] = wd[act_group]
			except:		pass
	else:
		# Selected faces only
		verts = {} # should use set
		for f in me.faces:
			if f.sel:
				for v in f:
					verts[v.index] = None
		
		for i in verts.iterkeys():
			wd = vWeightDict[i]
			try:		wd[PREF_NAME] = wd[act_group]
			except:		pass
		
		
	
	groupNames.append(PREF_NAME)
	# Copy weights back to the mesh.
	BPyMesh.dict2MeshWeight(me, groupNames, vWeightDict)
	Window.WaitCursor(0)
开发者ID:Synric,项目名称:synricproj,代码行数:28,代码来源:weightpaint_copy.py

示例2: actWeightNormalize

def actWeightNormalize(me, PREF_MODE, PREF_MAX_DIST, PREF_STRENGTH, PREF_ITERATIONS):
	Window.WaitCursor(1)
	groupNames, vWeightDict= BPyMesh.meshWeight2Dict(me)
	act_group= me.activeGroup
	
	# Start with assumed zero weights
	orig_vert_weights= [0.0] * len(vWeightDict) # Will be directly assigned to orig_vert_weights
	
	
	# fill in the zeros with real weights.
	for i, wd in enumerate(vWeightDict):
		try:
			orig_vert_weights[i]= wd[act_group]
		except:
			pass
	
	new_vert_weights= list(orig_vert_weights)
	
	for dummy in xrange(PREF_ITERATIONS):
		# Minimize or maximize the weights. connection based.
		
		if PREF_MODE==0: # Grow
			op= max
		else: # Shrink
			op= min
		
		for ed in me.edges:
			if not PREF_MAX_DIST or ed.length < PREF_MAX_DIST:
			
				i1= ed.v1.index
				i2= ed.v2.index
				new_weight= op(orig_vert_weights[i1], orig_vert_weights[i2])
				
				if PREF_STRENGTH==1.0: # do a full copy
					new_vert_weights[i1]= op(new_weight, new_vert_weights[i1])
					new_vert_weights[i2]= op(new_weight, new_vert_weights[i2])
					
				else: # Do a faded copy
					new_vert_weights[i1]= op(new_weight, new_vert_weights[i1])
					new_vert_weights[i2]= op(new_weight, new_vert_weights[i2])
					
					# Face the copy with the original (orig is updated per iteration)
					new_vert_weights[i1]= (new_vert_weights[i1]*PREF_STRENGTH) + (orig_vert_weights[i1]*(1-PREF_STRENGTH))
					new_vert_weights[i2]= (new_vert_weights[i2]*PREF_STRENGTH) + (orig_vert_weights[i2]*(1-PREF_STRENGTH))
		
		
		for i, wd in enumerate(vWeightDict):
			new_weight= new_vert_weights[i]
			if new_weight != orig_vert_weights[i]:
				wd[act_group]= new_weight
		
		if dummy+1 != PREF_ITERATIONS: # dont copy the list on the last round.
			orig_vert_weights= list(new_vert_weights)
		
		
	# Copy weights back to the mesh.
	BPyMesh.dict2MeshWeight(me, groupNames, vWeightDict)
	Window.WaitCursor(0)
开发者ID:Synric,项目名称:synricproj,代码行数:58,代码来源:weightpaint_grow_shrink.py

示例3: write

def write(filename):
	start = Blender.sys.time()
	if not filename.lower().endswith('.raw'):
		filename += '.raw'
	
	scn= Blender.Scene.GetCurrent()
	ob= scn.objects.active
	if not ob:
		Blender.Draw.PupMenu('Error%t|Select 1 active object')
		return
	
	file = open(filename, 'wb')
	
	mesh = BPyMesh.getMeshFromObject(ob, None, True, False, scn)
	if not mesh:
		Blender.Draw.PupMenu('Error%t|Could not get mesh data from active object')
		return
	
	mesh.transform(ob.matrixWorld)
	
	
	file = open(filename, "wb")
	for f in mesh.faces:
		for v in f:
			file.write('%.6f %.6f %.6f ' % tuple(v.co))
		file.write('\n')
	file.close()
	
	end = Blender.sys.time()
	message = 'Successfully exported "%s" in %.4f seconds' % ( Blender.sys.basename(filename), end-start)
	print message
开发者ID:Synric,项目名称:synricproj,代码行数:31,代码来源:raw_export.py

示例4: weightClean

def weightClean(me, PREF_THRESH, PREF_KEEP_SINGLE, PREF_OTHER_GROUPS):
	
	groupNames, vWeightDict= BPyMesh.meshWeight2Dict(me)
	act_group= me.activeGroup
	
	rem_count = 0
	
	if PREF_OTHER_GROUPS:
		for wd in vWeightDict:
			l = len(wd)
			if not PREF_KEEP_SINGLE or l > 1:
				# cant use iteritems because the dict is having items removed
				for group in wd.keys():
					w= wd[group]
					if w <= PREF_THRESH:
						# small weight, remove.
						del wd[group]
						rem_count +=1
						l-=1
					
					if PREF_KEEP_SINGLE and l == 1:
						break
	
	else:
		for wd in vWeightDict:
			if not PREF_KEEP_SINGLE or len(wd) > 1:
				try:
					w= wd[act_group]
					if w <= PREF_THRESH:
						# small weight, remove.
						del wd[act_group]
						rem_count +=1
				except:
					pass
	
	# Copy weights back to the mesh.
	BPyMesh.dict2MeshWeight(me, groupNames, vWeightDict)
	return rem_count
开发者ID:Synric,项目名称:synricproj,代码行数:38,代码来源:weightpaint_clean.py

示例5: write

def write(filename):
  
  Blender.Window.WaitCursor(1)
  
  if not filename.lower().endswith('.begc'):
    filename += '.begc'
  out = file(filename, "w")
  objects = Blender.Object.GetSelected()
  
  num_objects = 0
  for object in objects:
    if object.type == 'Mesh':
      num_objects = num_objects + 1
      
  out.write('%d\n' % num_objects)
  node_offset = 0
  for object in objects:
    if object.type == 'Mesh':
      out.write(object.name)
      out.write('\n')
  for object in objects:
    if object.type == 'Mesh':

      mesh = BPyMesh.getMeshFromObject(object, None, True, False, bpy.data.scenes.active)
      #mesh  = object.getData(0,1)
      mesh.transform(object.matrixWorld)
      faces = mesh.faces
      nodes = mesh.verts
      out.write('%d' % len(nodes))
      out.write(' %d\n' % len(faces))
      for n in nodes:
        #out.write("%e " % n.co[0])
        #out.write("%e " % n.co[1])
        #out.write("%e\n" % n.co[2])
        out.write("%e "  % n.co[0])
        out.write("%e "  % n.co[1])
        out.write("%e\n" % n.co[2])
      for f in faces:
        N = len(f.verts)
        if N < 3 and N > 4:
          Blender.Draw.PupMenu('Error%t|Only triangles and quads allowed')
          return
        out.write("%d" % N)
        for v in f.verts:
          out.write(' %d' % (v.index + node_offset))
        out.write('\n')
      node_offset = node_offset + len(nodes)

  Blender.Window.WaitCursor(0)
开发者ID:mtav,项目名称:script_inception_public,代码行数:49,代码来源:bfdtd_export.py

示例6: exportPath

def exportPath(curve, filename):
  print "Exporting curve "+curve.name+" to "+filename
  
  mesh = BPyMesh.getMeshFromObject(curve)
  mesh.transform(curve.matrixWorld)
  numVertices = len(mesh.verts)

  file = open(filename, "w")
  for i in range(0, numVertices):
    vertex = mesh.verts[i]
    file.write("%g %g %g\n" % (vertex.co[0], vertex.co[1], vertex.co[2]))
  if curve.data.isCyclic():
    vertex = mesh.verts[0]
    file.write("%g %g %g\n" % (vertex.co[0], vertex.co[1], vertex.co[2]))    
  file.close()
开发者ID:kralf,项目名称:morsel,代码行数:15,代码来源:morsel_paths_export.py

示例7: selSameWeights

def selSameWeights(me, PREF_TOLERENCE):
	
	# Check for missing data
	if not me.faceUV:	return
	
	act_group= me.activeGroup
	if not act_group:	return
	
	act_face = me.faces[me.activeFace]
	if act_face == None:	return
	
	
	
	groupNames, vWeightDict= BPyMesh.meshWeight2Dict(me)
	
	def get_face_weight(f):
		'''
		Return the faces median weight and weight range.
		'''
		wmin = 1.0
		wmax = 0.0
		w = 0.0
		for v in f:
			try:
				new_weight = vWeightDict[v.index][act_group]
				if wmin > new_weight: wmin = new_weight
				if wmax < new_weight: wmax = new_weight
				w += new_weight
			except:
				pass
		return w, wmax-wmin # weight, range
	
	weight_from, weight_range_from = get_face_weight(act_face)
	for f in me.faces:
		if (not f.sel) and f != act_face:
			weight, weight_range = get_face_weight(f)
			
			# Compare the 2 faces weight difference and difference in their contrast.
			if\
			abs(weight - weight_from) <= PREF_TOLERENCE and\
			abs(weight_range - weight_range_from) <= PREF_TOLERENCE:
				f.sel = True
开发者ID:Synric,项目名称:synricproj,代码行数:42,代码来源:faceselect_same_weights.py

示例8: meshNormalizedWeights

def meshNormalizedWeights(mesh):
  try:
    groupNames, vWeightList = BPyMesh.meshWeight2List(mesh)
  except:
    return [],[]

  if not groupNames:
    return [],[]

  for i, vWeights in enumerate(vWeightList):
    tot = 0.0
    for w in vWeights:
      tot+=w

    #print 'i:%d tot:%f' %  (i, tot)
    if tot:
      for j, w in enumerate(vWeights):
        vWeights[j] = w/tot
        #if w/tot > 0:
          #print 'i:%d j:%d w:%f w/tot:%f' %  (i, j, w, vWeights[j])

  return groupNames, vWeightList
开发者ID:venetianthief,项目名称:civ-dbs,代码行数:22,代码来源:OLD_export_br2.py

示例9: write

def write(filename):
	start = Blender.sys.time()
	if not filename.lower().endswith('.ml.txt'):
		filename += '.ml.txt'
	
	scn= Blender.Scene.GetCurrent()
	ob= scn.objects.active
	if not ob:
		Blender.Draw.PupMenu('Error%t|Select 1 active object')
		return
	
	file = open(filename, 'wb')
	
	mesh = BPyMesh.getMeshFromObject(ob, None, True, False, scn)
	if not mesh:
		Blender.Draw.PupMenu('Error%t|Could not get mesh data from active object')
		return
	
	mesh.transform(ob.matrixWorld)
	
	with open(filename, "w") as ml_file:
		ml_file.write('#MiniLight\n')
		ml_file.write('%d\n' % DEFAULT_ITERATIONS)
		ml_file.write('%d %d\n' % DEFAULT_RESOLUTION)
		ml_file.write('(%.2f %.2f %.2f) (%.2f %.2f %.2f) %.2f\n' % DEFAULT_CAMERA)
		ml_file.write('(%.2f %.2f %.2f) (%.2f %.2f %.2f)\n' % DEFAULT_SKY_AND_GROUND)
		
		for f in mesh.faces:
			if len(f) != 3:
				Blender.Draw.PupMenu('Error%t|Non-triangular face found in mesh')
				return
			for v in f:
				ml_file.write('(%.6f %.6f %.6f) ' % tuple(v.co))
			ml_file.write('(%.6f %.6f %.6f) ' % DEFAULT_COLOR)
			ml_file.write('(%.6f %.6f %.6f)\n' % DEFAULT_REFLECTIVITY)
	
	end = Blender.sys.time()
	message = 'Successfully exported "%s" in %.4f seconds' % ( Blender.sys.basename(filename), end-start)
	print message
开发者ID:UIKit0,项目名称:scripts,代码行数:39,代码来源:minilight_export.py

示例10: split

def split(mesh, splitHeight):
	'''
	Split the mesh into tetra-, pentahedra, one for every face.
	Very close opposite faces (like a concave thin wall) will break visibility info.
	'''
	# we'll return a list of new meshes, together making the original one
	ms = []
	for f in mesh.faces:
		vs = [v.co for v in f.verts]

		# check if the face won't cause trouble
		if len(vs) != 3:
			warning('\t\tSkipping a face not being a triangle, with %d vertices.' % len(vs))
			continue
		if f.area < minFaceArea:
			warning('\t\tSkipping a face with very small area: %.2f.' % f.area)
			continue
		as = filter(lambda a: a < minFaceAngle, BPyMesh.faceAngles(f)) # *** just till the first is found
		if as:
			warning('\t\tSkipping a face with a very small angle: %.2f.' % as[0])
			continue
		es = filter(lambda ei: mesh.edges[ei].length < minEdgeLength, mesh.findEdges(f.edge_keys)) # *** same
		if es:
			warning('\t\tSkipping a face with a very short edge: %.2f.' % mesh.edges[es[0]].length)
			continue

		# make a new tetrahedron, watch vertex order not to flip any normals
		m = Mesh.New()
		m.verts.extend(vs)
		m.verts.extend(f.cent - f.no * splitHeight)
		m.faces.extend(((0, 1, 2), (1, 0, 3), (2, 1, 3), (0, 2, 3)))
		m.faces[0].image = f.image
		m.faces[0].uv = f.uv
		ms.append(m)
	return ms
	'''
开发者ID:ArkyRomania,项目名称:ufoai,代码行数:36,代码来源:export_ufoai.py

示例11: env_from_group

def env_from_group(ob_act, grp, PREF_UPDATE_ACT=True):
	
	me = ob_act.getData(mesh=1)
	
	if PREF_UPDATE_ACT:
		act_group = me.activeGroup
		if act_group == None:
			Draw.PupMenu('Error%t|No active vertex group.')
			return
		
		try:
			ob = Object.Get(act_group)
		except:
			Draw.PupMenu('Error%t|No object named "'+ act_group +'".')
			return
		
		group_isect = intersection_data(ob)
		
	else:
		
		# get intersection data
		# group_isect_data = [intersection_data(ob) for ob in group.objects]
		group_isect_data = []
		for ob in grp.objects:
			if ob != ob_act: # in case we're in the group.
				gid = intersection_data(ob)
				if gid[1]: # has some triangles?
					group_isect_data.append( gid )
					
					# we only need 1 for the active group
					if PREF_UPDATE_ACT:
						break
	
		# sort by name
		group_isect_data.sort()
	
	if PREF_UPDATE_ACT:
		group_names, vweight_list = BPyMesh.meshWeight2List(me)
		group_index = group_names.index(act_group)
	else:
		group_names = [gid[0] for gid in group_isect_data]
		vweight_list= [[0.0]* len(group_names) for i in xrange(len(me.verts))]
	
	
	
	ob_act_mat = ob_act.matrixWorld
	for vi, v in enumerate(me.verts):
		# Get all the groups for this vert
		co = v.co * ob_act_mat
		
		if PREF_UPDATE_ACT:
			# only update existing
			if point_in_data(co, group_isect):	w = 1.0
			else:								w = 0.0
			vweight_list[vi][group_index] = w
			
		else:
			# generate new vgroup weights.
			for group_index, group_isect in enumerate(group_isect_data):
				if point_in_data(co, group_isect):
					vweight_list[vi][group_index] = 1.0
	
	BPyMesh.list2MeshWeight(me, group_names, vweight_list)
开发者ID:Synric,项目名称:synricproj,代码行数:63,代码来源:weightpaint_envelope_assign.py

示例12: create_mesh

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,代码行数:101,代码来源:importer.py

示例13: main

def main():
	scn = Scene.GetCurrent()
	act_ob= scn.objects.active
	if not act_ob or act_ob.type != 'Mesh':
		BPyMessages.Error_NoMeshActive()
		return
	
	act_me= act_ob.getData(mesh=1)
	
	if act_me.multires:
		BPyMessages.Error_NoMeshMultiresEdit()
		return
	
	act_group= act_me.activeGroup
	if not act_group: act_group= ''
	
	
	# Defaults
	PREF_REDUX= Draw.Create(0.5)
	PREF_BOUNDRY_WEIGHT= Draw.Create(5.0)
	PREF_REM_DOUBLES= Draw.Create(1)
	PREF_FACE_AREA_WEIGHT= Draw.Create(1.0)
	PREF_FACE_TRIANGULATE= Draw.Create(1)
	
	VGROUP_INF_ENABLE= Draw.Create(0)
	VGROUP_INF_REDUX= Draw.Create(act_group)
	VGROUP_INF_WEIGHT= Draw.Create(10.0)
	
	PREF_DO_UV= Draw.Create(1)
	PREF_DO_VCOL= Draw.Create(1)
	PREF_DO_WEIGHTS= Draw.Create(1)
	PREF_OTHER_SEL_OBS= Draw.Create(0)
	
	pup_block = [\
	('Poly Reduce:', PREF_REDUX, 0.05, 0.95, 'Scale the meshes poly count by this value.'),\
	('Boundry Weight:', PREF_BOUNDRY_WEIGHT, 0.0, 20.0, 'Weight boundry verts by this scale, 0.0 for no boundry weighting.'),\
	('Area Weight:', PREF_FACE_AREA_WEIGHT, 0.0, 20.0, 'Collapse edges effecting lower area faces first.'),\
	('Triangulate', PREF_FACE_TRIANGULATE, 'Convert quads to tris before reduction, for more choices of edges to collapse.'),\
	'',\
	('VGroup Weighting', VGROUP_INF_ENABLE, 'Use a vertex group to influence the reduction, higher weights for higher quality '),\
	('vgroup name: ', VGROUP_INF_REDUX, 0, 32, 'The name of the vertex group to use for the weight map'),\
	('vgroup mult: ', VGROUP_INF_WEIGHT, 0.0, 100.0, 'How much to make the weight effect the reduction'),\
	('Other Selected Obs', PREF_OTHER_SEL_OBS, 'reduce other selected objects.'),\
	'',\
	'',\
	'',\
	('UV Coords', PREF_DO_UV, 'Interpolate UV Coords.'),\
	('Vert Colors', PREF_DO_VCOL, 'Interpolate Vertex Colors'),\
	('Vert Weights', PREF_DO_WEIGHTS, 'Interpolate Vertex Weights'),\
	('Remove Doubles', PREF_REM_DOUBLES, 'Remove doubles before reducing to avoid boundry tearing.'),\
	]
	
	if not Draw.PupBlock("Poly Reducer", pup_block):
		return
	
	PREF_REDUX= PREF_REDUX.val
	PREF_BOUNDRY_WEIGHT= PREF_BOUNDRY_WEIGHT.val
	PREF_REM_DOUBLES= PREF_REM_DOUBLES.val
	PREF_FACE_AREA_WEIGHT= PREF_FACE_AREA_WEIGHT.val
	PREF_FACE_TRIANGULATE= PREF_FACE_TRIANGULATE.val
	
	VGROUP_INF_ENABLE= VGROUP_INF_ENABLE.val
	VGROUP_INF_WEIGHT= VGROUP_INF_WEIGHT.val
	
	if VGROUP_INF_ENABLE and VGROUP_INF_WEIGHT:
		VGROUP_INF_REDUX= VGROUP_INF_REDUX.val
	else:
		VGROUP_INF_WEIGHT= 0.0
		VGROUP_INF_REDUX= None
		
		
	PREF_DO_UV= PREF_DO_UV.val
	PREF_DO_VCOL= PREF_DO_VCOL.val
	PREF_DO_WEIGHTS= PREF_DO_WEIGHTS.val
	PREF_OTHER_SEL_OBS= PREF_OTHER_SEL_OBS.val
	
	
	t= sys.time()
	
	is_editmode = Window.EditMode() # Exit Editmode.
	if is_editmode: Window.EditMode(0)
	Window.WaitCursor(1)	
	print 'reducing:', act_ob.name, act_ob.getData(1)
	BPyMesh.redux(act_ob, PREF_REDUX, PREF_BOUNDRY_WEIGHT, PREF_REM_DOUBLES, PREF_FACE_AREA_WEIGHT, PREF_FACE_TRIANGULATE, PREF_DO_UV, PREF_DO_VCOL, PREF_DO_WEIGHTS, VGROUP_INF_REDUX, VGROUP_INF_WEIGHT)
	
	if PREF_OTHER_SEL_OBS:
		for ob in scn.objects.context:
			if ob.type == 'Mesh' and ob != act_ob:
				print 'reducing:', ob.name, ob.getData(1)
				BPyMesh.redux(ob, PREF_REDUX, PREF_BOUNDRY_WEIGHT, PREF_REM_DOUBLES, PREF_FACE_AREA_WEIGHT, PREF_FACE_TRIANGULATE, PREF_DO_UV, PREF_DO_VCOL, PREF_DO_WEIGHTS, VGROUP_INF_REDUX, VGROUP_INF_WEIGHT)
				Window.RedrawAll()
	
	if is_editmode: Window.EditMode(1)
	Window.WaitCursor(0)
	Window.RedrawAll()
	
	print 'Reduction done in %.6f sec.' % (sys.time()-t)
开发者ID:Synric,项目名称:synricproj,代码行数:97,代码来源:mesh_poly_reduce.py

示例14: export_map

def export_map(filepath):
	
	pup_block = [\
	('Scale:', PREF_SCALE, 1, 1000, 'Scale the blender scene by this value.'),\
	('Face Width:', PREF_FACE_THICK, 0.01, 10, 'Thickness of faces exported as brushes.'),\
	('Grid Snap', PREF_GRID_SNAP, 'snaps floating point values to whole numbers.'),\
	'Null Texture',\
	('', PREF_NULL_TEX, 1, 128, 'Export textureless faces with this texture'),\
	'Unseen Texture',\
	('', PREF_INVIS_TEX, 1, 128, 'Export invisible faces with this texture'),\
	]
	
	if not Draw.PupBlock('map export', pup_block):
		return
	
	Window.WaitCursor(1)
	time= sys.time()
	print 'Map Exporter 0.0'
	file= open(filepath, 'w')
	
	
	obs_mesh= []
	obs_lamp= []
	obs_surf= []
	obs_empty= []
	
	SCALE_MAT= Mathutils.Matrix()
	SCALE_MAT[0][0]= SCALE_MAT[1][1]= SCALE_MAT[2][2]= PREF_SCALE.val
	
	dummy_mesh= Mesh.New()
	
	TOTBRUSH= TOTLAMP= TOTNODE= 0
	
	for ob in Object.GetSelected():
		type= ob.type
		if type == 'Mesh':		obs_mesh.append(ob)
		elif type == 'Surf':	obs_surf.append(ob)
		elif type == 'Lamp':	obs_lamp.append(ob)
		elif type == 'Empty':	obs_empty.append(ob)
	
	if obs_mesh or obs_surf:
		# brushes and surf's must be under worldspan
		file.write('\n// entity 0\n')
		file.write('{\n')
		file.write('"classname" "worldspawn"\n')
	
	
	print '\twriting cubes from meshes'
	for ob in obs_mesh:
		dummy_mesh.getFromObject(ob.name)
		
		#print len(mesh_split2connected(dummy_mesh))
		
		# Is the object 1 cube? - object-is-a-brush
		dummy_mesh.transform(ob.matrixWorld*SCALE_MAT) # 1 to tx the normals also
		
		if PREF_GRID_SNAP.val:
			for v in dummy_mesh.verts:
				co= v.co
				co.x= round(co.x)
				co.y= round(co.y)
				co.z= round(co.z)
		
		# High quality normals
		BPyMesh.meshCalcNormals(dummy_mesh)
		
		# Split mesh into connected regions
		for face_group in BPyMesh.mesh2linkedFaces(dummy_mesh):
			if is_cube_facegroup(face_group):
				write_cube2brush(file, face_group)
				TOTBRUSH+=1
			elif is_tricyl_facegroup(face_group):
				write_cube2brush(file, face_group)
				TOTBRUSH+=1
			else:
				for f in face_group:
					write_face2brush(file, f)
					TOTBRUSH+=1
			
			#print 'warning, not exporting "%s" it is not a cube' % ob.name
			
	
	dummy_mesh.verts= None
	

	valid_dims= 3,5,7,9,11,13,15
	for ob in obs_surf:
		'''
		Surf, patches
		'''
		surf_name= ob.getData(name_only=1)
		data= Curve.Get(surf_name)
		mat = ob.matrixWorld*SCALE_MAT
		
		# This is what a valid patch looks like
		
		"""
// brush 0
{
patchDef2
#.........这里部分代码省略.........
开发者ID:Synric,项目名称:synricproj,代码行数:101,代码来源:export_map.py

示例15: file_callback

def file_callback(filename):

    if not filename.lower().endswith(".ctm"):
        filename += ".ctm"

        # Get object mesh from the selected object
    scn = bpy.data.scenes.active
    ob = scn.objects.active
    if not ob:
        Blender.Draw.PupMenu("Error%t|Select 1 active object")
        return
    mesh = BPyMesh.getMeshFromObject(ob, None, False, False, scn)
    if not mesh:
        Blender.Draw.PupMenu("Error%t|Could not get mesh data from active object")
        return

        # Check which mesh properties are present...
    hasVertexUV = mesh.vertexUV or mesh.faceUV
    hasVertexColors = mesh.vertexColors

    # Show a GUI for the export settings
    pupBlock = []
    EXPORT_APPLY_MODIFIERS = Draw.Create(1)
    pupBlock.append(("Apply Modifiers", EXPORT_APPLY_MODIFIERS, "Use transformed mesh data."))
    EXPORT_NORMALS = Draw.Create(1)
    pupBlock.append(("Normals", EXPORT_NORMALS, "Export vertex normal data."))
    if hasVertexUV:
        EXPORT_UV = Draw.Create(1)
        pupBlock.append(("UVs", EXPORT_UV, "Export texface UV coords."))
    if hasVertexColors:
        EXPORT_COLORS = Draw.Create(1)
        pupBlock.append(("Colors", EXPORT_COLORS, "Export vertex Colors."))
    EXPORT_MG2 = Draw.Create(0)
    pupBlock.append(("Fixed Point", EXPORT_MG2, "Use limited precision algorithm (MG2 method = better compression)."))
    if not Draw.PupBlock("Export...", pupBlock):
        return

        # Adjust export settings according to GUI selections
    EXPORT_APPLY_MODIFIERS = EXPORT_APPLY_MODIFIERS.val
    EXPORT_NORMALS = EXPORT_NORMALS.val
    if hasVertexUV:
        EXPORT_UV = EXPORT_UV.val
    else:
        EXPORT_UV = False
    if hasVertexColors:
        EXPORT_COLORS = EXPORT_COLORS.val
    else:
        EXPORT_COLORS = False
    EXPORT_MG2 = EXPORT_MG2.val

    # If the user wants to export MG2, then show another GUI...
    if EXPORT_MG2:
        pupBlock = []
        EXPORT_VPREC = Draw.Create(0.01)
        pupBlock.append(("Vertex", EXPORT_VPREC, 0.0001, 1.0, "Relative vertex precision (fixed point)."))
        if EXPORT_NORMALS:
            EXPORT_NPREC = Draw.Create(1.0 / 256.0)
            pupBlock.append(("Normal", EXPORT_NPREC, 0.0001, 1.0, "Normal precision (fixed point)."))
        if EXPORT_UV:
            EXPORT_UVPREC = Draw.Create(1.0 / 1024.0)
            pupBlock.append(("UV", EXPORT_UVPREC, 0.0001, 1.0, "UV precision (fixed point)."))
        if EXPORT_COLORS:
            EXPORT_CPREC = Draw.Create(1.0 / 256.0)
            pupBlock.append(("Color", EXPORT_CPREC, 0.0001, 1.0, "Color precision (fixed point)."))
        if not Draw.PupBlock("Fixed point precision...", pupBlock):
            return

            # Adjust export settings according to GUI selections
    if EXPORT_MG2:
        EXPORT_VPREC = EXPORT_VPREC.val
    else:
        EXPORT_VPREC = 0.1
    if EXPORT_MG2 and EXPORT_NORMALS:
        EXPORT_NPREC = EXPORT_NPREC.val
    else:
        EXPORT_NPREC = 0.1
    if EXPORT_MG2 and EXPORT_UV:
        EXPORT_UVPREC = EXPORT_UVPREC.val
    else:
        EXPORT_UVPREC = 0.1
    if EXPORT_MG2 and EXPORT_COLORS:
        EXPORT_CPREC = EXPORT_CPREC.val
    else:
        EXPORT_CPREC = 0.1

    is_editmode = Blender.Window.EditMode()
    if is_editmode:
        Blender.Window.EditMode(0, "", 0)
    Window.WaitCursor(1)
    try:
        # Get the mesh, again, if we wanted modifiers (from GUI selection)
        if EXPORT_APPLY_MODIFIERS:
            mesh = BPyMesh.getMeshFromObject(ob, None, EXPORT_APPLY_MODIFIERS, False, scn)
            if not mesh:
                Blender.Draw.PupMenu("Error%t|Could not get mesh data from active object")
                return
            mesh.transform(ob.matrixWorld, True)

            # Count triangles (quads count as two triangles)
        triangleCount = 0
#.........这里部分代码省略.........
开发者ID:rgkoo,项目名称:meshlab,代码行数:101,代码来源:openctm_export.py


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