我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用bmesh.update_edit_mesh()。
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")
def collapse_short_edges(bm,obj,threshold=1.0): ### collapse short edges edges_len_average = 0 edges_count = 0 shortest_edge = 10000 for edge in bm.edges: if True: edges_count += 1 length = edge.calc_length() edges_len_average += length if length < shortest_edge: shortest_edge = length edges_len_average = edges_len_average/edges_count verts = [] for vert in bm.verts: if not vert.is_boundary: verts.append(vert) bmesh.update_edit_mesh(obj.data) bmesh.ops.remove_doubles(bm,verts=verts,dist=edges_len_average*threshold) bmesh.update_edit_mesh(obj.data)
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")
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")
def separarcaras(): obj = bpy.context.object me = obj.data bm = bmesh.from_edit_mesh(me) ### separar caras### listabordes = [] for borde in bm.edges: listabordes.append(borde) bmesh.ops.split_edges(bm, edges=listabordes) bpy.ops.mesh.select_all(action='SELECT') bmesh.update_edit_mesh(me, True)
def separarcaras(): obj = bpy.context.object me = obj.data bm = bmesh.from_edit_mesh(me) ### separar caras### listabordes = [] for borde in bm.edges: listabordes.append(borde) bmesh.ops.split_edges(bm, edges=listabordes) bpy.ops.mesh.select_all(action='SELECT') bmesh.update_edit_mesh(me, True) ####################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################
def execute(self, context): """build maze """ obj = context.object bm = bmesh.from_edit_mesh(obj.data) if len(self.vert_centers) == 0: self.update = True maze_params = self.get_maze_params() bpy.ops.mesh.select_mode(type='EDGE') bm, self.link_centers, self.vert_centers = generate_maze(bm, maze_params) self.update = False bmesh.update_edit_mesh(obj.data, destructive=True) return {'FINISHED'}
def update(self, context): # update height via bmesh to avoid loosing material ids # this should be the rule for other simple objects # as long as there is no topologic changes o = context.active_object if archipack_wall.datablock(o) != self: return bpy.ops.object.mode_set(mode='EDIT') me = o.data bm = bmesh.from_edit_mesh(me) bm.verts.ensure_lookup_table() bm.faces.ensure_lookup_table() new_z = self.z last_z = list(v.co.z for v in bm.verts) max_z = max(last_z) for v in bm.verts: if v.co.z == max_z: v.co.z = new_z bmesh.update_edit_mesh(me, True) bpy.ops.object.mode_set(mode='OBJECT')
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)
def execute(self, context): # must force edge selection mode here bpy.context.tool_settings.mesh_select_mode = (False, True, False) obj = context.active_object if obj.mode == "EDIT": bm = bmesh.from_edit_mesh(obj.data) selected_edges = [edge for edge in bm.edges if edge.select] edge_indices = [i.index for i in selected_edges] d = get_intersection_dictionary(bm, edge_indices) unselect_nonintersecting(bm, d.keys(), edge_indices) update_mesh(bm, d) bmesh.update_edit_mesh(obj.data) else: print('must be in edit mode') return {'FINISHED'}
def add_vertex_to_intersection(): obj = bpy.context.object me = obj.data bm = bmesh.from_edit_mesh(me) edges = [e for e in bm.edges if e.select] if len(edges) == 2: [[v1, v2], [v3, v4]] = [[v.co for v in e.verts] for e in edges] iv = geometry.intersect_line_line(v1, v2, v3, v4) if iv: iv = (iv[0] + iv[1]) / 2 bm.verts.new(iv) bm.verts.ensure_lookup_table() bm.verts[-1].select = True bmesh.update_edit_mesh(me)
def execute(self, context): mesh = bpy.context.object.data bm = bmesh.from_edit_mesh(mesh) bm.faces.ensure_lookup_table() uv_layer = bm.loops.layers.uv.active face0=[] #save active face for l in bm.faces.active.loops: face0.append(l[uv_layer].uv) #copy uvs to selected face for f in bm.faces: if f.select: if f is not bm.faces.active: for i,l in enumerate(f.loops): if i < len(face0): l[uv_layer].uv=face0[i] else: #TODO: possibly interpolate uvs for better transfer l[uv_layer].uv=face0[len(face0)-1] bmesh.update_edit_mesh(mesh, False, False) return {'FINISHED'}
def display_color_callback(): if bpy.context.object.mode == 'EDIT': if display_color[0]: ob = bpy.context.object me = ob.data bm = bmesh.from_edit_mesh(me) quads = tris = ngons = 0 ngons_to_tris = 0 verts = len(bm.verts) faces = len(bm.faces) for f in bm.faces: v = len(f.verts) if v == 3: # tris f.material_index = 2 elif v == 4: # quads f.material_index = 0 elif v > 4: # ngons f.material_index = 1 bmesh.update_edit_mesh(me)
def noise_obj(obj, context, self): bm = bmesh.from_edit_mesh(obj.data) verts = [v for v in bm.verts if v.select] if not verts: verts = [v for v in bm.verts if v.hide is False] for vert in verts: noise_pos = vert.co.copy() noise_pos.x += self.offset_x noise_pos.z += self.offset_y noise_pos.z += self.offset_z noise_val = None if self.noise_type == 'Turbulence': noise_val = mathu.noise.turbulence(noise_pos, self.octaves, self.hard, mathu.noise.types.STDPERLIN, self.amplitude_scale, self.frequency_scale) elif self.noise_type == 'Fractal': noise_val = mathu.noise.fractal(noise_pos, self.amplitude_scale, self.frequency_scale, self.octaves, mathu.noise.types.STDPERLIN) else: noise_val = mathu.noise.hetero_terrain(noise_pos, self.amplitude_scale, self.frequency_scale, self.octaves, 0, mathu.noise.types.STDPERLIN) vert_offset = vert.normal.copy().normalized() * noise_val vert.co += vert_offset * self.intensity bm.normal_update() bmesh.update_edit_mesh(obj.data)
def random_uvs(self, context): import bpy import bmesh from mathutils import Vector from random import uniform bpy.ops.object.editmode_toggle() bpy.ops.mesh.select_all(action="SELECT") obj = bpy.context.object me = obj.data bm = bmesh.from_edit_mesh(me) uv_layer = bm.loops.layers.uv.verify() bm.faces.layers.tex.verify() # adjust UVs for f in bm.faces: offset = Vector((uniform(-1.0, 1.0), uniform(-1.0, 1.0))) for v in f.loops: luv = v[uv_layer] luv.uv = (luv.uv + offset).xy bmesh.update_edit_mesh(me) bpy.ops.object.editmode_toggle()
def execute(self, context): obj = context.object me = bmesh.from_edit_mesh(obj.data) uv_layer = me.loops.layers.uv.active clear = False for f in me.faces: for l in f.loops: uv = l[uv_layer] if uv.select and uv.pin_uv: print(uv.uv, uv.pin_uv) clear = True break if clear: break print("pining", clear) bmesh.update_edit_mesh(obj.data) bpy.ops.uv.pin(clear = clear) return {'FINISHED'}
def noise_obj(obj, context, self): bm = bmesh.from_edit_mesh(obj.data) verts = [v for v in bm.verts if v.select] if not verts: verts = [v for v in bm.verts if v.hide is False] for vert in verts: noise_pos = self.frequency * vert.co.copy() noise_pos.x += self.offset_x noise_pos.z += self.offset_y noise_pos.z += self.offset_z noise_val = None if self.noise_type == 'Turbulence': noise_val = mathu.noise.turbulence(noise_pos, self.octaves, self.hard, mathu.noise.types.STDPERLIN, self.amplitude_scale, self.frequency_scale) elif self.noise_type == 'Fractal': noise_val = mathu.noise.fractal(noise_pos, self.amplitude_scale, self.frequency_scale, self.octaves, mathu.noise.types.STDPERLIN) else: noise_val = mathu.noise.hetero_terrain(noise_pos, self.amplitude_scale, self.frequency_scale, self.octaves, 0, mathu.noise.types.STDPERLIN) vert_offset = vert.normal.copy().normalized() * noise_val vert.co += vert_offset * self.intensity bm.normal_update() bmesh.update_edit_mesh(obj.data)
def terminate(global_undo): # update editmesh cached data obj = bpy.context.active_object if obj.mode == 'EDIT': bmesh.update_edit_mesh(obj.data, tessface=True, destructive=True) bpy.context.user_preferences.edit.use_global_undo = global_undo ########################################## ####### Relax functions ################## ########################################## #Relax: create lists with knots and points, all correctly sorted
def clean_mesh(me): debug_message("Cleaning mesh " + me.name) h = bpy.context.scene.hyperpresets[me.hypersettings.preset] if me.is_editmode: bm = bmesh.from_edit_mesh(me) else: bm = bmesh.new() bm.from_mesh(me) layw = bm.verts.layers.float['hyperw'] layx = bm.verts.layers.float['hyperx'] layy = bm.verts.layers.float['hypery'] layz = bm.verts.layers.float['hyperz'] for v in bm.verts: old = Vector([v[layw], v[layx], v[layy], v[layz]]) newco = map4to4(h, v.co, old) v[layw] = newco[0] v[layx] = newco[1] v[layy] = newco[2] v[layz] = newco[3] if me.is_editmode: bmesh.update_edit_mesh(me) else: bm.to_mesh(me)
def project_to_3d(me): debug_message("Projecting " + me.name + " to 3D") h = bpy.context.scene.hyperpresets[me.hypersettings.preset] if me.is_editmode: bm = bmesh.from_edit_mesh(me) else: bm = bmesh.new() bm.from_mesh(me) layw = bm.verts.layers.float['hyperw'] layx = bm.verts.layers.float['hyperx'] layy = bm.verts.layers.float['hypery'] layz = bm.verts.layers.float['hyperz'] for v in bm.verts: p = Vector([v[layw], v[layx], v[layy], v[layz]]) newco = map4to3(h, p) v.co = newco if me.is_editmode: bmesh.update_edit_mesh(me) else: bm.to_mesh(me) me.update()
def execute(self, context): obj_curr = context.active_object mesh = obj_curr.data bm = bmesh.from_edit_mesh(mesh) normal_buffer = self.addon.preferences.normal_buffer vertex_normal_weight_layer = bm.verts.layers.int['vertex-normal-weight'] vertex_normal_x_layer = bm.verts.layers.float['vertex-normal-x'] vertex_normal_y_layer = bm.verts.layers.float['vertex-normal-y'] vertex_normal_z_layer = bm.verts.layers.float['vertex-normal-z'] # Assign stored world space normal vector to all selected vertices. vertex_normal = obj_curr.matrix_world.inverted() * normal_buffer for v in [v for v in bm.verts if v.select]: v[vertex_normal_weight_layer] = self.vertex_normal_weight_map['UNWEIGHTED'] v[vertex_normal_x_layer] = vertex_normal.x v[vertex_normal_y_layer] = vertex_normal.y v[vertex_normal_z_layer] = vertex_normal.z # Update the mesh. bpy.ops.mesh.yavne_update_vertex_normals() bmesh.update_edit_mesh(mesh) return {'FINISHED'}
def clean_boundary_edges(bm,obj): edges_len_average, shortest_edge = get_average_edge_length(bm,obj) edges = [] for edge in bm.edges: if edge.calc_length() < edges_len_average*.12 and not edge.tag: edges.append(edge) bmesh.ops.collapse(bm,edges=edges,uvs=False) bmesh.update_edit_mesh(obj.data)
def average_edge_cuts(bm,obj,cuts=1): ### collapse short edges edges_len_average, shortest_edge = get_average_edge_length(bm,obj) subdivide_edges = [] for edge in bm.edges: cut_count = int(edge.calc_length()/shortest_edge)*cuts if cut_count < 0: cut_count = 0 if not edge.is_boundary: subdivide_edges.append([edge,cut_count]) for edge in subdivide_edges: bmesh.ops.subdivide_edges(bm,edges=[edge[0]],cuts=edge[1]) bmesh.update_edit_mesh(obj.data)
def triangle_fill(bm,obj): edges = [] for edge in bm.edges: if edge.select == True: edges.append(edge) triangle_fill = bmesh.ops.triangle_fill(bm,edges=edges,use_beauty=True) bmesh.update_edit_mesh(obj.data) if triangle_fill["geom"] == []: return False else: return True
def smooth_verts(bm,obj): ### smooth verts smooth_verts = [] for vert in bm.verts: if not vert.is_boundary: smooth_verts.append(vert) for i in range(50): #bmesh.ops.smooth_vert(bm,verts=smooth_verts,factor=1.0,use_axis_x=True,use_axis_y=True,use_axis_z=True) bmesh.ops.smooth_vert(bm,verts=smooth_verts,factor=1.0,use_axis_x=True,use_axis_y=True,use_axis_z=True) bmesh.update_edit_mesh(obj.data)
def clean_verts(bm,obj): ### find corrupted faces faces = [] for face in bm.faces: i = 0 for edge in face.edges: if not edge.is_manifold: i += 1 if i == len(face.edges): faces.append(face) bmesh.ops.delete(bm,geom=faces,context=5) edges = [] for face in bm.faces: i = 0 for vert in face.verts: if not vert.is_manifold and not vert.is_boundary: i+=1 if i == len(face.verts): for edge in face.edges: if edge not in edges: edges.append(edge) bmesh.ops.collapse(bm,edges=edges) bmesh.update_edit_mesh(obj.data) for vert in bm.verts: if not vert.is_boundary: vert.select = False verts = [] for vert in bm.verts: if len(vert.link_edges) in [3,4] and not vert.is_boundary: verts.append(vert) bmesh.ops.dissolve_verts(bm,verts=verts) bmesh.update_edit_mesh(obj.data)
def remove_doubles(obj,edge_average_len,edge_min_len): bm = bmesh.from_edit_mesh(obj.data) verts = [] for vert in bm.verts: if not vert.hide: verts.append(vert) bmesh.ops.remove_doubles(bm,verts=verts,dist=0.0001) bmesh.update_edit_mesh(obj.data)
def reproject(self,context): ### unwrap obj = context.active_object hide_base_sprite = obj.data.coa_hide_base_sprite obj.data.coa_hide_base_sprite = False bm = bmesh.from_edit_mesh(obj.data) selected_edges = [] for edge in bm.edges: if edge.select: selected_edges.append(edge) unselected_verts = [] for vert in bm.verts: if not vert.select: unselected_verts.append(vert) vert.select = True unselected_faces = [] for face in bm.faces: if not face.select: unselected_faces.append(face) face.select = True bpy.ops.uv.project_from_view(camera_bounds=False, correct_aspect=True, scale_to_bounds=True) for edge in selected_edges: edge.select = True for vert in unselected_verts: vert.select = False for face in unselected_faces: face.select = False bmesh.update_edit_mesh(obj.data) obj.data.coa_hide_base_sprite = hide_base_sprite
def normal_fill(self,context): obj = context.active_object bpy.ops.mesh.edge_face_add() bpy.ops.uv.project_from_view(camera_bounds=False, correct_aspect=True, scale_to_bounds=True) self.reset_spritesheet(context,obj) bm = bmesh.from_edit_mesh(obj.data) unselected_faces = [] for face in bm.faces: if face.select == False: unselected_faces.append(face) face.select = True bpy.ops.uv.project_from_view(camera_bounds=False, correct_aspect=True, scale_to_bounds=True) for face in unselected_faces: face.select = False bmesh.update_edit_mesh(obj.data) self.revert_rest_spritesheet(context,obj)
def check_verts(self,context,event): verts = [] bm = bmesh.from_edit_mesh(context.active_object.data) for vert in bm.verts: if vert.select: verts.append(vert) for vert in verts: vert.co = context.active_object.matrix_world.inverted() * self.limit_cursor_by_bounds(context,context.active_object.matrix_world * vert.co) bmesh.update_edit_mesh(context.active_object.data)
def get_selected_vert_pos(self,context): bm = bmesh.from_edit_mesh(context.active_object.data) for vert in bm.verts: if vert.select == True: bmesh.update_edit_mesh(context.active_object.data) return vert.co bmesh.update_edit_mesh(context.active_object.data) return None
def delete_geometry(self,context,bm,position,single_vert=False): obj = context.active_object snapped_vert_coord , point_type , bm_ob = self.snap_to_edge_or_vert(position,get_bm_obj = True) if point_type == "VERT": vert = bm_ob if not vert.is_boundary and not vert.is_wire: bmesh.ops.dissolve_verts(bm,verts=[vert])#,use_face_split=True,use_boundary_tear=True) else: if not vert.hide: if obj.matrix_world * vert.co == snapped_vert_coord: shortest_edge = None edge_length = 10000000000000 for edge in vert.link_edges: if edge.calc_length() < edge_length: shortest_edge = edge edge_length = edge.calc_length() merge_co = shortest_edge.other_vert(vert).co if shortest_edge != None else vert.co verts = [] verts.append(vert) if shortest_edge != None: verts.append(shortest_edge.other_vert(vert)) if len(verts) > 1: bmesh.ops.pointmerge(bm,verts = verts,merge_co = merge_co) else: bm.verts.remove(vert) elif point_type == "EDGE": edge = bm_ob if not edge.is_boundary and not edge.is_wire: bmesh.ops.dissolve_edges(bm,edges=[edge],use_verts=False) else: if len(edge.verts[0].link_edges) > 1 and len(edge.verts[1].link_edges) > 1: bm.edges.remove(edge) elif len(edge.verts[0].link_edges) > 1 and len(edge.verts[1].link_edges) <= 1: bm.verts.remove(edge.verts[1]) elif len(edge.verts[0].link_edges) <= 1 and len(edge.verts[1].link_edges) > 1: bm.verts.remove(edge.verts[0]) else: bmesh.ops.delete(bm,geom=[edge.verts[0],edge.verts[1]],context=1) bmesh.update_edit_mesh(obj.data)
def execute(self, context): scene = context.scene obj = context.active_object bm = bmesh.from_edit_mesh(obj.data) mult = 1 # if context.scene.coa_distance_constraint: # mult = bpy.context.space_data.region_3d.view_distance*.05 for edge in bm.edges: if edge.select: #scene.coa_distance = (obj.matrix_world * (edge.verts[0].co - edge.verts[1].co)).magnitude/mult# edge.calc_length()/mult scene.coa_distance = ((edge.verts[0].co - edge.verts[1].co)).magnitude/mult# edge.calc_length()/mult bmesh.update_edit_mesh(obj.data) return {"FINISHED"}
def update_uv_unwrap(context): obj = context.active_object me = obj.data bm = bmesh.from_edit_mesh(me) ### pin uv boundary vertex uv_layer = bm.loops.layers.uv.active for vert in bm.verts: uv_vert = get_uv_from_vert(uv_layer, vert) if uv_vert != None: pass bmesh.update_edit_mesh(me)
def main3(self, context, chboxVert0, chboxVert1, chboxVert2, grados, chboxreloj): # variable angulo dependiendo los grados ingresados angle = grados obj = bpy.context.object me = obj.data bm = bmesh.from_edit_mesh(me) vertices = [v for v in bm.verts if (v.select==True and not v.hide)] if len(vertices) != 3: print("seleccione solo 2 vertices") #return {'FINISHED'} else: v1,v2,v3 = [v for v in bm.verts if (v.select==True and not v.hide)] if chboxreloj: angle = -angle if chboxVert0: calcularangulos1(v1, v3, v2,angle) if chboxVert1: calcularangulos1(v2, v3, v1,angle) if chboxVert2: calcularangulos1(v3, v2, v1,angle) bmesh.update_edit_mesh(me, True)
def main(self, context, chboxsepara, chboxune): obj = bpy.context.object me = obj.data bm = bmesh.from_edit_mesh(me) if chboxsepara: ### separar caras### listabordes = [] for borde in bm.edges: listabordes.append(borde) bmesh.ops.split_edges(bm, edges=listabordes) bpy.ops.mesh.select_all(action='SELECT') bpy.ops.mesh.select_mode(use_extend=False, use_expand=False, type='FACE') elif chboxune: bpy.ops.mesh.select_all(action='SELECT') bmesh.ops.remove_doubles(bm, verts=bm.verts, dist=0.1) bpy.ops.mesh.select_all(action='SELECT') bmesh.update_edit_mesh(me, True)
def crear_ganchos(self,context): for vertice_index in self._verticesInvolucrados: bpy.ops.mesh.select_all(action='DESELECT') obj = bpy.context.object me = obj.data bm = bmesh.from_edit_mesh(me) if hasattr(bm.verts, "ensure_lookup_table"): bm.verts.ensure_lookup_table() # only if you need to: # bm.edges.ensure_lookup_table() # bm.faces.ensure_lookup_table() bm.verts[vertice_index].select=True bpy.ops.object.hook_add_newob() bmesh.update_edit_mesh(me, True) #SELECCIONAMOS LOS VERTICES ORIGINALES bpy.ops.mesh.select_all(action='DESELECT') obj = bpy.context.object me = obj.data bm = bmesh.from_edit_mesh(me) if hasattr(bm.verts, "ensure_lookup_table"): bm.verts.ensure_lookup_table() # only if you need to: # bm.edges.ensure_lookup_table() # bm.faces.ensure_lookup_table() for vertice_index in self._verticesSeleccionados: bm.verts[vertice_index].select=True bmesh.update_edit_mesh(me, True)
def main(self, context, chboxaxisx, chboxaxisy,chboxaxisz, distance): distancia = distance obj = bpy.context.object me = obj.data bm = bmesh.from_edit_mesh(me) if chboxaxisx: x = distancia else: x = 0.0 if chboxaxisy: y = distancia else: y = 0.0 if chboxaxisz: z = distancia else: z = 0.0 vertices = [v for v in bm.verts if (v.select and not v.hide)] bmesh.ops.translate( bm, verts=vertices, vec=(x, y, z)) ### separar caras### bmesh.update_edit_mesh(me, True) #"Render" bpy.ops.render.render()
def main(self, context, chboxhide, chboxshow): obj = bpy.context.object me = obj.data bm = bmesh.from_edit_mesh(me) try: v1 = [v for v in bm.verts if (v.select == True and v.hide == False)] e1 = [e for e in bm.edges if (e.select == True and e.hide == False)] f1 = [f for f in bm.faces if (f.select == True and f.hide == False)] if len(v1)>0 or len(e1) >0 or f1>0: if chboxhide: bpy.ops.mesh.select_all(action='INVERT') bpy.ops.mesh.hide(unselected=False) bpy.ops.mesh.select_all(action='SELECT') elif chboxshow: bpy.ops.mesh.reveal() except: if chboxshow: bpy.ops.mesh.reveal() bmesh.update_edit_mesh(me, True)
def corte(bm, v1, v2, v3): mid_vec = v1.lerp(v2, 0.5) plane_no = v1 - mid_vec plane_co = mid_vec dist = 0.0001 # hidden geometry will not be affected. visible_geom = [g for g in bm.faces[:] + bm.verts[:] + bm.edges[:] if not g.hide] try: bmesh.ops.bisect_plane( bm, geom=visible_geom, dist=dist, plane_co=plane_co, plane_no=plane_no, use_snap_center=False, clear_outer=False, clear_inner=False) bmesh.update_edit_mesh(me, True) except: print("salto excepcion") ################################################################################ ########## clase del Circumcentro ########################################## ################################################################################
def main(self, context): obj = bpy.context.object me = obj.data bm = bmesh.from_edit_mesh(me) edges = [e for e in bm.edges if (e.select and not e.hide)] vertices = [v for v in bm.verts if (v.select and not v.hide)] listavertices=[] if len(edges) !=0: print("bordes seleccionados: " + str(len(edges))) for edge in edges: listavertices.append(edge.verts[0]) listavertices.append(edge.verts[1]) edge.select=False print(listavertices) contador = len(listavertices) print(contador) while contador != 1: v1 = listavertices[contador-1].co v2 = listavertices[contador-2].co v3 = (0,0,0) print(v1,v2) corte(bm, v1, v2, v3) contador = contador - 1 elif len(edges) ==0 and len(vertices) == 2: v1,v2 =[v.co for v in bm.verts if (v.select and not v.hide)] v3 = (0,0,0) print("seleccionados 2 vertices") corte(bm, v1, v2, v3) else: print("seleccione minimo 1 borde o 2 vertices") bmesh.update_edit_mesh(me, True)
def main(self, context, chboxVert0, chboxVert1, chboxVert2, cortes): # variable angulo dependiendo los grados ingresados secciones = cortes direccion = 1 obj = bpy.context.object me = obj.data bm = bmesh.from_edit_mesh(me) vertices = [v for v in bm.verts if (v.select==True and not v.hide)] if len(vertices) != 3: print("seleccione solo 3 vertices") #return {'FINISHED'} else: vv1,vv2,vv3 = [v for v in bm.verts if (v.select==True and not v.hide)] if chboxVert0: calcularangulos(vv1, vv2, vv3,secciones,direccion) if chboxVert1: calcularangulos(vv2, vv3, vv1,secciones,direccion) if chboxVert2: calcularangulos(vv3, vv1, vv2,secciones,direccion) bmesh.update_edit_mesh(me, True)
def main(self, context, chboxVert0, chboxVert1, chboxVert2): obj = bpy.context.object me = obj.data bm = bmesh.from_edit_mesh(me) vertices = [v for v in bm.verts if (v.select and not v.hide)] if not len(vertices) == 3: msg = "select ONLY 3 vertices" self.report({"WARNING"}, msg) return {'CANCELLED'} v1,v2,v3 = [v for v in vertices] if chboxVert0: corte(bm, v1,v2,v3) if chboxVert1: corte(bm, v2,v1,v3) if chboxVert2: corte(bm, v3,v1,v2) verticeje = v3.co else: print("Select 1 option") bmesh.update_edit_mesh(me, True)
def wall_uv(me, bm): for face in bm.faces: face.select = face.material_index > 0 bmesh.update_edit_mesh(me, True) bpy.ops.uv.cube_project(scale_to_bounds=False, correct_aspect=True) for face in bm.faces: face.select = face.material_index < 1 bmesh.update_edit_mesh(me, True) bpy.ops.uv.smart_project(use_aspect=True, stretch_to_bounds=False)
def _end(bm, o): """ private, end bmesh editing of active object """ bm.normal_update() bmesh.update_edit_mesh(o.data, True) bpy.ops.object.mode_set(mode='OBJECT') bm.free()
def generate_bmesh_repr(p1, v1, axis, num_verts): ''' p1: center of circle (local coordinates) v1: first vertex of circle in (local coordinates) axis: orientation matrix origin: obj.location ''' props = bpy.context.scene.tinycad_props rescale = props.rescale # generate geometry up front chain = [] gamma = 2 * math.pi / num_verts for i in range(num_verts + 1): theta = gamma * i mat_rot = mathutils.Matrix.Rotation(theta, 4, axis) local_point = (mat_rot * ((v1 - p1) * rescale)) chain.append(local_point + p1) obj = bpy.context.edit_object me = obj.data bm = bmesh.from_edit_mesh(me) # add verts v_refs = [] for p in chain: v = bm.verts.new(p) v.select = False # this might be a default.. redundant? v_refs.append(v) # join verts, daisy chain num_verts = len(v_refs) for i in range(num_verts): idx1 = i idx2 = (i + 1) % num_verts bm.edges.new([v_refs[idx1], v_refs[idx2]]) bmesh.update_edit_mesh(me, True)
def extend_vertex(self): obj = bpy.context.edit_object me = obj.data bm = bmesh.from_edit_mesh(me) verts = bm.verts faces = bm.faces planes = [f for f in faces if f.select] if (len(planes) > 1) or (len(planes) == 0): failure_message(self) return plane = planes[0] plane_vert_indices = [v for v in plane.verts[:]] all_selected_vert_indices = [v for v in verts if v.select] M = set(plane_vert_indices) N = set(all_selected_vert_indices) O = N.difference(M) O = list(O) if not len(O) == 2: failure_message(self) return (v1_ref, v1), (v2_ref, v2) = [(i, i.co) for i in O] plane_co = plane.calc_center_median() plane_no = plane.normal new_co = intersect_line_plane(v1, v2, plane_co, plane_no, False) new_vertex = verts.new(new_co) A_len = (v1 - new_co).length B_len = (v2 - new_co).length vertex_reference = v1_ref if (A_len < B_len) else v2_ref bm.edges.new([vertex_reference, new_vertex]) bmesh.update_edit_mesh(me, True)
def execute(self, context): # final attempt to enter unfragmented bm/mesh # ghastly, but what can I do? it works with these # fails without. bpy.ops.object.mode_set(mode='OBJECT') bpy.ops.object.mode_set(mode='EDIT') obj = context.active_object me = obj.data bm = bmesh.from_edit_mesh(me) bm.verts.ensure_lookup_table() bm.edges.ensure_lookup_table() edges = [e for e in bm.edges if e.select and not e.hide] if len(edges) == 2: message = do_vtx_if_appropriate(bm, edges) if isinstance(message, set): msg = messages.get(message.pop()) return self.cancel_message(msg) bm = message else: return self.cancel_message('select two edges!') bm.verts.index_update() bm.edges.index_update() bmesh.update_edit_mesh(me, True) return {'FINISHED'}
def bmesh_to_object(obj, bm): """ Object/Edit Mode update the object. """ me = obj.data is_editmode = (obj.mode == 'EDIT') if is_editmode: bmesh.update_edit_mesh(me, True) else: bm.to_mesh(me) # grr... cause an update if me.vertices: me.vertices[0].co[0] = me.vertices[0].co[0]