Python bmesh.from_edit_mesh() Examples
The following are 30
code examples of bmesh.from_edit_mesh().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
bmesh
, or try the search function
.
Example #1
Source File: split_solidify.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def execute(self, context): obj = bpy.context.active_object self.me = obj.data self.bm = bmesh.from_edit_mesh(self.me) self.me.update() list_0 = [f.index for f in self.bm.faces if f.select] if len(list_0) == 0: self.report({'INFO'}, 'No faces selected') return {'CANCELLED'} elif len(list_0) != 0: f_(self, list_0) context.tool_settings.mesh_select_mode = (True, True, True) if self.b_del: bpy.ops.mesh.delete(type='FACE') else: pass return {'FINISHED'}
Example #2
Source File: import_sprites.py From coa_tools with GNU General Public License v3.0 | 6 votes |
def create_verts(self,width,height,pos,me,tag_hide=False): bpy.ops.object.mode_set(mode="EDIT") bm = bmesh.from_edit_mesh(me) vert1 = bm.verts.new(Vector((0,0,-height))*self.scale) vert2 = bm.verts.new(Vector((width,0,-height))*self.scale) vert3 = bm.verts.new(Vector((width,0,0))*self.scale) vert4 = bm.verts.new(Vector((0,0,0))*self.scale) bm.faces.new([vert1,vert2,vert3,vert4]) bmesh.update_edit_mesh(me) if tag_hide: for vert in bm.verts: vert.hide = True for edge in bm.edges: edge.hide = True bmesh.update_edit_mesh(me) bpy.ops.object.mode_set(mode="OBJECT")
Example #3
Source File: functions.py From coa_tools with GNU General Public License v3.0 | 6 votes |
def unwrap_with_bounds(obj,uv_idx): bpy.ops.object.mode_set(mode="EDIT") me = obj.data bm = bmesh.from_edit_mesh(me) bm.verts.ensure_lookup_table() uv_layer = bm.loops.layers.uv[uv_idx] scale_x = 1.0 / get_local_dimension(obj)[0] * obj.coa_tiles_x scale_z = 1.0 / get_local_dimension(obj)[1] * obj.coa_tiles_y offset = [get_local_dimension(obj)[2][0] * scale_x , get_local_dimension(obj)[2][1] * scale_z] for i,v in enumerate(bm.verts): for l in v.link_loops: uv_data = l[uv_layer] uv_data.uv[0] = (bm.verts[i].co[0] * scale_x) - offset[0] uv_data.uv[1] = (bm.verts[i].co[2] * scale_z)+1 - offset[1] bmesh.update_edit_mesh(me) bm.free() bpy.ops.object.mode_set(mode="OBJECT")
Example #4
Source File: functions.py From coa_tools with GNU General Public License v3.0 | 6 votes |
def remove_base_mesh(obj): bpy.ops.object.mode_set(mode="EDIT") bm = bmesh.from_edit_mesh(obj.data) bm.verts.ensure_lookup_table() verts = [] if "coa_base_sprite" in obj.vertex_groups: v_group_idx = obj.vertex_groups["coa_base_sprite"].index for i,vert in enumerate(obj.data.vertices): for g in vert.groups: if g.group == v_group_idx: verts.append(bm.verts[i]) break bmesh.ops.delete(bm,geom=verts,context=1) bm = bmesh.update_edit_mesh(obj.data) bpy.ops.object.mode_set(mode="OBJECT")
Example #5
Source File: 3dm_snow.py From Blender-Add-ons-3DM-Snow with GNU General Public License v3.0 | 6 votes |
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
Example #6
Source File: SurfaceFollow.py From Modeling-Cloth with MIT License | 6 votes |
def get_bmesh(ob='empty'): '''Returns a bmesh. Works either in edit or object mode. ob can be either an object or a mesh.''' obm = bmesh.new() if ob == 'empty': 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
Example #7
Source File: DynamicTensionMap.py From Modeling-Cloth with MIT License | 6 votes |
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
Example #8
Source File: muv_texlock_ops.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def execute(self, context): props = context.scene.muv_props.texlock obj = bpy.context.active_object bm = bmesh.from_edit_mesh(obj.data) if muv_common.check_version(2, 73, 0) >= 0: bm.verts.ensure_lookup_table() bm.edges.ensure_lookup_table() bm.faces.ensure_lookup_table() if not bm.loops.layers.uv: self.report( {'WARNING'}, "Object must have more than one UV map") return {'CANCELLED'} uv_layer = bm.loops.layers.uv.verify() props.verts_orig = [ {"vidx": v.index, "vco": v.co.copy(), "moved": False} for v in bm.verts if v.select] return {'FINISHED'}
Example #9
Source File: muv_uvbb_ops.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def __update_uvs(self, context, uv_info_ini, trans_mat): """ Update UV coordinate """ obj = context.active_object bm = bmesh.from_edit_mesh(obj.data) if muv_common.check_version(2, 73, 0) >= 0: bm.faces.ensure_lookup_table() if not bm.loops.layers.uv: return uv_layer = bm.loops.layers.uv.verify() for info in uv_info_ini: fidx = info[0] lidx = info[1] uv = info[2] v = mathutils.Vector((uv.x, uv.y, 0.0)) av = trans_mat * v bm.faces[fidx].loops[lidx][uv_layer].uv = mathutils.Vector( (av.x, av.y))
Example #10
Source File: oscurart_worn_edges_map.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def CreateWornEdges(context, factor): actobj = bpy.context.object bpy.ops.object.mode_set(mode="EDIT") bm = bmesh.from_edit_mesh(actobj.data) sf = [(vert.calc_shell_factor() - 1.0) * factor for vert in bm.verts[:]] bpy.ops.object.mode_set(mode="VERTEX_PAINT") purge = {} for ind, loop in enumerate(bpy.context.object.data.loops[:]): if loop.vertex_index not in purge: purge[loop.vertex_index] = [ind] else: purge[loop.vertex_index].append(ind) for vert in actobj.data.vertices[:]: if vert.select: ran = (sf[vert.index], sf[vert.index], sf[vert.index]) for i in purge[vert.index]: actobj.data.vertex_colors.active.data[i].color = ran actobj.data.update()
Example #11
Source File: operator_mesh_uv.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def main(context): obj = context.active_object me = obj.data bm = bmesh.from_edit_mesh(me) uv_layer = bm.loops.layers.uv.verify() bm.faces.layers.tex.verify() # currently blender needs both layers. # adjust UVs for f in bm.faces: for l in f.loops: luv = l[uv_layer] if luv.select: # apply the location of the vertex as a UV luv.uv = l.vert.co.xy bmesh.update_edit_mesh(me)
Example #12
Source File: operator_mesh_uv.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def main(context): obj = context.active_object me = obj.data bm = bmesh.from_edit_mesh(me) uv_layer = bm.loops.layers.uv.verify() bm.faces.layers.tex.verify() # currently blender needs both layers. # adjust UVs for f in bm.faces: for l in f.loops: luv = l[uv_layer] if luv.select: # apply the location of the vertex as a UV luv.uv = l.vert.co.xy bmesh.update_edit_mesh(me)
Example #13
Source File: mesh_show_vgroup_weights.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def avail_vgroups(self, context): if context is None: return [] ob = context.active_object bm = bmesh.from_edit_mesh(ob.data) dvert_lay = bm.verts.layers.deform.active items = [] self.vertex = bm.select_history.active.index dvert = bm.select_history.active[dvert_lay] #XXX since we need an identifier here, user won't be able to add a vgroup with that name ('-1') #XXX could check against vgroup names and find an unused name, but it's a rare case after all. items.append(("-1", "New Vertex Group", "Add a new vertex group to the active object", -1)) for i in ob.vertex_groups: if i.index not in dvert.keys(): items.append((i.name, i.name, str(i.index), i.index)) return items
Example #14
Source File: mesh.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def execute(self, context): import bmesh from .bmesh import find_adjacent obj = context.active_object me = obj.data bm = bmesh.from_edit_mesh(me) if find_adjacent.select_prev(bm, self.report): bm.select_flush_mode() bmesh.update_edit_mesh(me, False) return {'FINISHED'} # XXX This is hackish (going forth and back from Object mode...), to be redone once we have proper support of # custom normals in BMesh/edit mode.
Example #15
Source File: mesh_show_vgroup_weights.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def execute(self, context): ob = context.active_object me = ob.data bm = bmesh.from_edit_mesh(me) # Save current selection selected_verts = [] for v in bm.verts: if v.select is True: selected_verts.append(v.index) if v.index != self.vert_and_group[0]: v.select = False ob.vertex_groups.active_index = self.vert_and_group[1] bpy.ops.object.vertex_group_remove_from() # Re-select vertices for v in bm.verts: if v.index in selected_verts: v.select = True #XXX Hacky, but there's no other way to update the UI panels bpy.ops.object.editmode_toggle() bpy.ops.object.editmode_toggle() return {'FINISHED'}
Example #16
Source File: mesh_floodsel.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def initialize(self, context): bpy.types.Scene.PreSelOff = bpy.props.BoolProperty( name = "PreSelOff", description = "Switch off PreSel during FloodSel", default = True) self.area = context.area self.selobj = context.active_object self.mesh = self.selobj.data self.bm = bmesh.from_edit_mesh(self.mesh) self.area.header_text_set(text="FloodSel : Leftclick selects") self.region = None self.doneset = set([]) self.getmatrix()
Example #17
Source File: mesh_show_vgroup_weights.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def execute(self, context): me = context.active_object.data bm = bmesh.from_edit_mesh(me) dvert_lay = bm.verts.layers.deform.active weights = {} for item in self.vgroup_weights: weights[item.vgroup] = item.weight for v in bm.verts: if v.index == self.index: dvert = v[dvert_lay] for vgroup in dvert.keys(): dvert[vgroup] = weights[vgroup] break context.area.tag_redraw() return {'FINISHED'}
Example #18
Source File: muv_texlock_ops.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def execute(self, context): props = context.scene.muv_props.texlock if props.intr_running is True: return {'CANCELLED'} obj = bpy.context.active_object bm = bmesh.from_edit_mesh(obj.data) if muv_common.check_version(2, 73, 0) >= 0: bm.verts.ensure_lookup_table() bm.edges.ensure_lookup_table() bm.faces.ensure_lookup_table() if not bm.loops.layers.uv: self.report( {'WARNING'}, "Object must have more than one UV map") return {'CANCELLED'} uv_layer = bm.loops.layers.uv.verify() props.intr_verts_orig = [ {"vidx": v.index, "vco": v.co.copy(), "moved": False} for v in bm.verts if v.select] bpy.ops.uv.muv_texlock_updater() return {'FINISHED'} # Texture lock (Stop, Interactive mode)
Example #19
Source File: muv_cpuv_ops.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def execute(self, context): props = context.scene.muv_props.cpuv_obj if self.uv_map == "": self.report({'INFO'}, "Copy UV coordinate per object") else: self.report( {'INFO'}, "Copy UV coordinate per object (UV map:" + self.uv_map + ")") bpy.ops.object.mode_set(mode='EDIT') obj = context.active_object bm = bmesh.from_edit_mesh(obj.data) if muv_common.check_version(2, 73, 0) >= 0: bm.faces.ensure_lookup_table() # get UV layer if self.uv_map == "": if not bm.loops.layers.uv: self.report( {'WARNING'}, "Object must have more than one UV map") return {'CANCELLED'} uv_layer = bm.loops.layers.uv.verify() else: uv_layer = bm.loops.layers.uv[self.uv_map] # get selected face props.src_uvs = [] props.src_pin_uvs = [] for face in bm.faces: uvs = [l[uv_layer].uv.copy() for l in face.loops] pin_uvs = [l[uv_layer].pin_uv for l in face.loops] props.src_uvs.append(uvs) props.src_pin_uvs.append(pin_uvs) self.report({'INFO'}, "%s's UV coordinates are copied" % (obj.name)) return {'FINISHED'}
Example #20
Source File: muv_transuv_ops.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def execute(self, context): props = context.scene.muv_props.transuv active_obj = context.scene.objects.active bm = bmesh.from_edit_mesh(active_obj.data) if muv_common.check_version(2, 73, 0) >= 0: bm.faces.ensure_lookup_table() # get UV layer if not bm.loops.layers.uv: self.report({'WARNING'}, "Object must have more than one UV map") return {'CANCELLED'} uv_layer = bm.loops.layers.uv.verify() props.topology_copied.clear() # get selected faces active_face = bm.faces.active sel_faces = [face for face in bm.faces if face.select] if len(sel_faces) != 2: self.report({'WARNING'}, "Two faces must be selected") return {'CANCELLED'} if not active_face or active_face not in sel_faces: self.report({'WARNING'}, "Two faces must be active") return {'CANCELLED'} # parse all faces according to selection active_face_nor = active_face.normal.copy() all_sorted_faces = main_parse( self, active_obj, bm, uv_layer, sel_faces, active_face, active_face_nor) if all_sorted_faces: for face_data in all_sorted_faces.values(): uv_loops = face_data[2] uvs = [l.uv.copy() for l in uv_loops] pin_uvs = [l.pin_uv for l in uv_loops] props.topology_copied.append([uvs, pin_uvs]) bmesh.update_edit_mesh(active_obj.data) return {'FINISHED'}
Example #21
Source File: muv_cpuv_ops.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def draw(self, context): layout = self.layout # create sub menu obj = context.active_object bm = bmesh.from_edit_mesh(obj.data) uv_maps = bm.loops.layers.uv.keys() layout.operator( MUV_CPUVCopyUV.bl_idname, text="[Default]", icon="PLUGIN").uv_map = "" for m in uv_maps: layout.operator( MUV_CPUVCopyUV.bl_idname, text=m, icon="PLUGIN").uv_map = m
Example #22
Source File: muv_mvuv_ops.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def __find_uv(self, context): bm = bmesh.from_edit_mesh(context.object.data) topology_dict = [] first = True diff = 0 uvs = [] active_uv = bm.loops.layers.uv.active for fidx, f in enumerate(bm.faces): for vidx, v in enumerate(f.verts): if v.select: uvs.append(f.loops[vidx][active_uv].uv.copy()) topology_dict.append([fidx, vidx]) if first: v1 = v.link_loops[0].vert.co sv1 = view3d_utils.location_3d_to_region_2d( context.region, context.space_data.region_3d, v1) v2 = v.link_loops[0].link_loop_next.vert.co sv2 = view3d_utils.location_3d_to_region_2d( context.region, context.space_data.region_3d, v2) vres = sv2 - sv1 va = vres.angle(Vector((0.0, 1.0))) uv1 = v.link_loops[0][active_uv].uv uv2 = v.link_loops[0].link_loop_next[active_uv].uv uvres = uv2 - uv1 uva = uvres.angle(Vector((0.0,1.0))) diff = uva - va first = False return topology_dict, uvs
Example #23
Source File: muv_cpuv_ops.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def draw(self, context): layout = self.layout # create sub menu obj = context.active_object bm = bmesh.from_edit_mesh(obj.data) uv_maps = bm.loops.layers.uv.keys() layout.operator( MUV_CPUVPasteUV.bl_idname, text="[Default]", icon="PLUGIN").uv_map = "" for m in uv_maps: layout.operator( MUV_CPUVPasteUV.bl_idname, text=m, icon="PLUGIN").uv_map = m
Example #24
Source File: mesh_extrude_and_reshape.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def execute(self, context): self.mesh = context.object.data self.bm = bmesh.from_edit_mesh(self.mesh) try: selection = self.bm.select_history[-1] except: for face in self.bm.faces: if face.select == True: selection = face break else: return {'FINISHED'} if not isinstance(selection, bmesh.types.BMFace): bpy.ops.mesh.extrude_region_move('INVOKE_DEFAULT') return {'FINISHED'} else: face = selection #face.select = False bpy.ops.mesh.select_all(action='DESELECT') geom = [] for edge in face.edges: if abs(edge.calc_face_angle(0) - 1.5707963267948966) < 0.01: #self.angle_tolerance: geom.append(edge) ret_dict = bmesh.ops.extrude_discrete_faces(self.bm, faces = [face]) for face in ret_dict['faces']: self.bm.faces.active = face face.select = True sface = face dfaces = bmesh.ops.dissolve_edges(self.bm, edges = geom, use_verts=True, use_face_split=False) bmesh.update_edit_mesh(self.mesh, tessface=True, destructive=True) bpy.ops.transform.translate('INVOKE_DEFAULT', constraint_axis=(False, False, True), constraint_orientation='NORMAL', release_confirm=True) context.window_manager.modal_handler_add(self) self.cancel = False self.confirm = False return {'RUNNING_MODAL'}
Example #25
Source File: uv_align_distribute.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def InitBMesh(): global bm global uvlayer bm = bmesh.from_edit_mesh(bpy.context.edit_object.data) bm.faces.ensure_lookup_table() uvlayer = bm.loops.layers.uv.active
Example #26
Source File: muv_cpuv_selseq_ops.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def draw(self, context): layout = self.layout obj = context.active_object bm = bmesh.from_edit_mesh(obj.data) uv_maps = bm.loops.layers.uv.keys() layout.operator( MUV_CPUVSelSeqCopyUV.bl_idname, text="[Default]", icon="PLUGIN").uv_map = "" for m in uv_maps: layout.operator( MUV_CPUVSelSeqCopyUV.bl_idname, text=m, icon="PLUGIN").uv_map = m
Example #27
Source File: muv_cpuv_selseq_ops.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def draw(self, context): layout = self.layout # create sub menu obj = context.active_object bm = bmesh.from_edit_mesh(obj.data) uv_maps = bm.loops.layers.uv.keys() layout.operator( MUV_CPUVSelSeqPasteUV.bl_idname, text="[Default]", icon="PLUGIN").uv_map = "" for m in uv_maps: layout.operator( MUV_CPUVSelSeqPasteUV.bl_idname, text=m, icon="PLUGIN").uv_map = m
Example #28
Source File: muv_unwrapconst_ops.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def execute(self, context): obj = bpy.context.active_object bm = bmesh.from_edit_mesh(obj.data) if muv_common.check_version(2, 73, 0) >= 0: bm.faces.ensure_lookup_table() if not bm.loops.layers.uv: self.report( {'WARNING'}, "Object must have more than one UV map") return {'CANCELLED'} uv_layer = bm.loops.layers.uv.verify() # get original UV coordinate faces = [f for f in bm.faces if f.select] uv_list = [] for f in faces: uvs = [l[uv_layer].uv.copy() for l in f.loops] uv_list.append(uvs) # unwrap bpy.ops.uv.unwrap( method=self.method, fill_holes=self.fill_holes, correct_aspect=self.correct_aspect, use_subsurf_data=self.use_subsurf_data, margin=self.margin) # when U/V-Constraint is checked, revert original coordinate for f, uvs in zip(faces, uv_list): for l, uv in zip(f.loops, uvs): if self.u_const: l[uv_layer].uv.x = uv.x if self.v_const: l[uv_layer].uv.y = uv.y # update mesh bmesh.update_edit_mesh(obj.data) return {'FINISHED'}
Example #29
Source File: ModelingCloth.py From Modeling-Cloth with MIT License | 5 votes |
def get_bmesh(obj=None): ob = get_last_object()[1] if ob is None: ob = obj obm = bmesh.new() if ob.mode == 'OBJECT': obm.from_mesh(ob.data) elif ob.mode == 'EDIT': obm = bmesh.from_edit_mesh(ob.data) return obm
Example #30
Source File: symmetry_tools.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def execute(self, context): threshold = 1e-6 object = context.object bm = bmesh.from_edit_mesh(object.data) # Deselect all the vertices for v in bm.verts: v.select = False for v1 in bm.verts: if abs(v1.co[0]) < threshold: continue mirror_found = False for v2 in bm.verts: if v1 == v2: continue if v1.co[0] * v2.co[0] > 0.0: continue mirror_coord = Vector(v2.co) mirror_coord[0] *= -1 if (mirror_coord - v1.co).length_squared < threshold: mirror_found = True break if not mirror_found: v1.select = True bm.select_flush_mode() bmesh.update_edit_mesh(object.data) return {"FINISHED"}