本文整理汇总了Python中bmesh.new方法的典型用法代码示例。如果您正苦于以下问题:Python bmesh.new方法的具体用法?Python bmesh.new怎么用?Python bmesh.new使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bmesh
的用法示例。
在下文中一共展示了bmesh.new方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: triangulate
# 需要导入模块: import bmesh [as 别名]
# 或者: from bmesh import new [as 别名]
def triangulate(me, ob=None):
"""Requires a mesh. Returns an index array for viewing co as triangles"""
obm = bmesh.new()
obm.from_mesh(me)
bmesh.ops.triangulate(obm, faces=obm.faces)
#obm.to_mesh(me)
count = len(obm.faces)
#tri_idx = np.zeros(count * 3, dtype=np.int32)
#me.polygons.foreach_get('vertices', tri_idx)
tri_idx = np.array([[v.index for v in f.verts] for f in obm.faces])
# Identify bend spring groups. Each edge gets paired with two points on tips of tris around edge
# Restricted to edges with two linked faces on a triangulated version of the mesh
if ob is not None:
link_ed = [e for e in obm.edges if len(e.link_faces) == 2]
ob.bend_eidx = np.array([[e.verts[0].index, e.verts[1].index] for e in link_ed])
fv = np.array([[[v.index for v in f.verts] for f in e.link_faces] for e in link_ed])
fv.shape = (fv.shape[0],6)
ob.bend_tips = np.array([[idx for idx in fvidx if idx not in e] for e, fvidx in zip(ob.bend_eidx, fv)])
obm.free()
return tri_idx#.reshape(count, 3)
示例2: create_vertex_groups
# 需要导入模块: import bmesh [as 别名]
# 或者: from bmesh import new [as 别名]
def create_vertex_groups(groups=['common', 'not_used'], weights=[0.0, 0.0], ob=None):
'''Creates vertex groups and sets weights. "groups" is a list of strings
for the names of the groups. "weights" is a list of weights corresponding
to the strings. Each vertex is assigned a weight for each vertex group to
avoid calling vertex weights that are not assigned. If the groups are
already present, the previous weights will be preserved. To reset weights
delete the created groups'''
if ob is None:
ob = bpy.context.object
vg = ob.vertex_groups
for g in range(0, len(groups)):
if groups[g] not in vg.keys(): # Don't create groups if there are already there
vg.new(groups[g])
vg[groups[g]].add(range(0,len(ob.data.vertices)), weights[g], 'REPLACE')
else:
vg[groups[g]].add(range(0,len(ob.data.vertices)), 0, 'ADD') # This way we avoid resetting the weights for existing groups.
示例3: generate_guide_mesh
# 需要导入模块: import bmesh [as 别名]
# 或者: from bmesh import new [as 别名]
def generate_guide_mesh():
"""Makes the arrow that appears when creating pins"""
verts = [[0.0, 0.0, 0.0], [-0.01, -0.01, 0.1], [-0.01, 0.01, 0.1], [0.01, -0.01, 0.1], [0.01, 0.01, 0.1], [-0.03, -0.03, 0.1], [-0.03, 0.03, 0.1], [0.03, 0.03, 0.1], [0.03, -0.03, 0.1], [-0.01, -0.01, 0.2], [-0.01, 0.01, 0.2], [0.01, -0.01, 0.2], [0.01, 0.01, 0.2]]
edges = [[0, 5], [5, 6], [6, 7], [7, 8], [8, 5], [1, 2], [2, 4], [4, 3], [3, 1], [5, 1], [2, 6], [4, 7], [3, 8], [9, 10], [10, 12], [12, 11], [11, 9], [3, 11], [9, 1], [2, 10], [12, 4], [6, 0], [7, 0], [8, 0]]
faces = [[0, 5, 6], [0, 6, 7], [0, 7, 8], [0, 8, 5], [1, 3, 11, 9], [1, 2, 6, 5], [2, 4, 7, 6], [4, 3, 8, 7], [3, 1, 5, 8], [12, 10, 9, 11], [4, 2, 10, 12], [3, 4, 12, 11], [2, 1, 9, 10]]
name = 'ModelingClothPinGuide'
if 'ModelingClothPinGuide' in bpy.data.objects:
mesh_ob = bpy.data.objects['ModelingClothPinGuide']
else:
mesh = bpy.data.meshes.new('ModelingClothPinGuide')
mesh.from_pydata(verts, edges, faces)
mesh.update()
mesh_ob = bpy.data.objects.new(name, mesh)
bpy.context.scene.objects.link(mesh_ob)
mesh_ob.show_x_ray = True
return mesh_ob
示例4: create_giude
# 需要导入模块: import bmesh [as 别名]
# 或者: from bmesh import new [as 别名]
def create_giude():
"""Spawns the guide"""
if 'ModelingClothPinGuide' in bpy.data.objects:
mesh_ob = bpy.data.objects['ModelingClothPinGuide']
return mesh_ob
mesh_ob = generate_guide_mesh()
bpy.context.scene.objects.active = mesh_ob
bpy.ops.object.material_slot_add()
if 'ModelingClothPinGuide' in bpy.data.materials:
mat = bpy.data.materials['ModelingClothPinGuide']
else:
mat = bpy.data.materials.new(name='ModelingClothPinGuide')
mat.use_transparency = True
mat.alpha = 0.35
mat.emit = 2
mat.game_settings.alpha_blend = 'ALPHA_ANTIALIASING'
mat.diffuse_color = (1, 1, 0)
mesh_ob.material_slots[0].material = mat
return mesh_ob
示例5: execute
# 需要导入模块: import bmesh [as 别名]
# 或者: from bmesh import new [as 别名]
def execute(self, context):
ob = bpy.context.object
bpy.ops.object.mode_set(mode='OBJECT')
sel = [i.index for i in ob.data.vertices if i.select]
name = ob.name
matrix = ob.matrix_world.copy()
for v in sel:
e = bpy.data.objects.new('modeling_cloth_pin', None)
bpy.context.scene.objects.link(e)
if ob.active_shape_key is None:
closest = matrix * ob.data.vertices[v].co# * matrix
else:
closest = matrix * ob.active_shape_key.data[v].co# * matrix
e.location = closest #* matrix
e.show_x_ray = True
e.select = True
e.empty_draw_size = .1
data[name].pin_list.append(v)
data[name].hook_list.append(e)
ob.select = False
bpy.ops.object.mode_set(mode='EDIT')
return {'FINISHED'}
示例6: get_bmesh
# 需要导入模块: import bmesh [as 别名]
# 或者: from bmesh import new [as 别名]
def get_bmesh(ob=None):
'''Returns a bmesh. Works either in edit or object mode.
ob can be either an object or a mesh.'''
obm = bmesh.new()
if ob is None:
mesh = bpy.context.object.data
if 'data' in dir(ob):
mesh = ob.data
if ob.mode == 'OBJECT':
obm.from_mesh(mesh)
elif ob.mode == 'EDIT':
obm = bmesh.from_edit_mesh(mesh)
else:
mesh = ob
obm.from_mesh(mesh)
return obm
示例7: material_setup
# 需要导入模块: import bmesh [as 别名]
# 或者: from bmesh import new [as 别名]
def material_setup(ob=None):
'''Creates a node material for displaying the vertex colors'''
if ob is None:
ob = bpy.context.object
mats = bpy.data.materials
tens = mats.new('TensionMap')
data[ob.name]['material'] = tens
tens.use_nodes = True
tens.specular_intensity = 0.1
tens.specular_hardness = 17
tens.use_transparency = True
tens.node_tree.nodes.new(type="ShaderNodeGeometry")
tens.node_tree.links.new(tens.node_tree.nodes['Geometry'].outputs['Vertex Color'],
tens.node_tree.nodes['Material'].inputs[0])
if 'Tension' not in ob.data.vertex_colors:
ob.data.vertex_colors.new('Tension')
ob.data.materials.append(tens)
tens.node_tree.nodes['Geometry'].color_layer = 'Tension'
tens.node_tree.nodes['Material'].material = tens
示例8: union
# 需要导入模块: import bmesh [as 别名]
# 或者: from bmesh import new [as 别名]
def union(o1, o2):
# create boolean modifier against o1 that unions o2
bool_modifier = o1.modifiers.new(type='BOOLEAN', name='o2_union')
bool_modifier.object = o2
bool_modifier.operation = 'UNION'
# create mesh from o1 + modifier
mesh = o1.to_mesh(bpy.context.scene, True, 'PREVIEW')
# replace o1 mesh with this explicit flattened mesh
bm = bmesh.new()
bm.from_mesh(mesh)
bm.to_mesh(o1.data)
bm.free()
# drop modifier
o1.modifiers.remove(bool_modifier)
# update center of mass
recalc_com(o1)
# remove o2
bpy.context.scene.objects.unlink(o2)
示例9: bmesh_copy_from_object
# 需要导入模块: import bmesh [as 别名]
# 或者: from bmesh import new [as 别名]
def bmesh_copy_from_object(obj, transform=True, triangulate=True, apply_modifiers=False):
assert(obj.type == 'MESH')
if apply_modifiers and obj.modifiers:
import bpy
me = obj.to_mesh(bpy.context.scene, True, 'PREVIEW', calc_tessface=False)
bm = bmesh.new(); bm.from_mesh(me); bpy.data.meshes.remove(me)
del bpy
else:
me = obj.data
if obj.mode == 'EDIT': bm_orig = bmesh.from_edit_mesh(me); bm = bm_orig.copy()
else: bm = bmesh.new(); bm.from_mesh(me)
if transform: bm.transform(obj.matrix_world)
if triangulate: bmesh.ops.triangulate(bm, faces=bm.faces)
return bm
示例10: _create_new_material
# 需要导入模块: import bmesh [as 别名]
# 或者: from bmesh import new [as 别名]
def _create_new_material(name, color):
"""Create a new material.
Args:
name (str): Name for the new material (e.g., 'red')
color (tuple): RGB color for the new material (diffuse_color)
(e.g., (1, 0, 0, 1))
Returns:
The new material.
"""
mat = bpy.data.materials.new(name)
mat.diffuse_color = color
mat.roughness = 0.5
mat.specular_color = (1, 1, 1)
mat.specular_intensity = 0.2
return mat
示例11: createNoncyclicSpline
# 需要导入模块: import bmesh [as 别名]
# 或者: from bmesh import new [as 别名]
def createNoncyclicSpline(curveData, srcSpline, forceNoncyclic):
spline = curveData.splines.new('BEZIER')
spline.bezier_points.add(len(srcSpline.bezier_points)-1)
if(forceNoncyclic):
spline.use_cyclic_u = False
else:
spline.use_cyclic_u = srcSpline.use_cyclic_u
for i in range(0, len(srcSpline.bezier_points)):
DrawableCurve.copyBezierPt(srcSpline.bezier_points[i],
spline.bezier_points[i])
if(forceNoncyclic == True and srcSpline.use_cyclic_u == True):
spline.bezier_points.add(1)
DrawableCurve.copyBezierPt(srcSpline.bezier_points[0],
spline.bezier_points[-1])
#static method
示例12: addCustomWriterKFs
# 需要导入模块: import bmesh [as 别名]
# 或者: from bmesh import new [as 别名]
def addCustomWriterKFs(customWriter, empty, startFrame, endFrame, resetLocation):
if(resetLocation == True):
insertKF(obj = customWriter, dataPath = 'location', frame = (startFrame - 1))
customWriter.location = (0,0,0)
insertKF(obj = customWriter, dataPath = 'location', frame = startFrame)
insertKF(obj = customWriter, dataPath = 'location', frame = endFrame)
const = customWriter.constraints.new(type='CHILD_OF')
const.target = empty
const.name = NEW_DATA_PREFIX + 'Constraint'
const.influence = 0
insertKF(obj = const, dataPath = 'influence', frame = (startFrame - 1))
const.influence = 1
insertKF(obj = const, dataPath = 'influence', frame = startFrame)
insertKF(obj = const, dataPath = 'influence', frame = endFrame)
const.influence = 0
insertKF(obj = const, dataPath = 'influence', frame = (endFrame + 1))
示例13: getCurveDCObjs
# 需要导入模块: import bmesh [as 别名]
# 或者: from bmesh import new [as 别名]
def getCurveDCObjs(selObjs, objType, defaultDepth, retain, copyPropObj, \
flatMat, bevelObj, group = None):
curveDCObjs = []
idx = 0 #Only for naming the new objects
for obj in selObjs:
dcObjs = DrawableCurve.getDCObjsForSpline(obj, objType,
defaultDepth, idx, group, copyPropObj, flatMat, bevelObj)
if(len(dcObjs) == 0 ):
continue
idx += len(dcObjs)
if(retain == 'Copy'):
obj.hide_viewport = True
obj.hide_render = True
curveDCObjs.append(dcObjs)
return curveDCObjs
示例14: getCurveDCObjs
# 需要导入模块: import bmesh [as 别名]
# 或者: from bmesh import new [as 别名]
def getCurveDCObjs(selObjs, objType, defaultDepth, retain, copyPropObj, group = None):
curveDCObjs = []
idx = 0 #Only for naming the new objects
for obj in selObjs:
dcObjs = DrawableCurve.getDCObjsForSpline(obj, objType,
defaultDepth, idx, group, copyPropObj)
if(len(dcObjs) == 0 ):
continue
idx += len(dcObjs)
if(retain == 'Copy'):
obj.hide = True
obj.hide_render = True
curveDCObjs.append(dcObjs)
return curveDCObjs
示例15: set_vertex_groups
# 需要导入模块: import bmesh [as 别名]
# 或者: from bmesh import new [as 别名]
def set_vertex_groups(obj, skin_data):
# Allocate vertex groups
for i in range(skin_data.num_bones):
obj.vertex_groups.new()
# vertex_bone_indices stores what 4 bones influence this vertex
for i in range(len(skin_data.vertex_bone_indices)):
for j in range(len(skin_data.vertex_bone_indices[i])):
bone = skin_data.vertex_bone_indices[i][j]
weight = skin_data.vertex_bone_weights[i][j]
obj.vertex_groups[bone].add([i], weight, 'ADD')
#######################################################