Import_3ds: Improved distance cue node setup
[blender-addons.git] / mesh_tiny_cad / V2X.py
blobd202b80ae629776b34c6c7911b7deb8186cd8886
1 # SPDX-FileCopyrightText: 2016-2022 Blender Foundation
3 # SPDX-License-Identifier: GPL-2.0-or-later
6 import bpy
7 import bmesh
8 from mathutils import geometry
11 def add_vertex_to_intersection():
13 obj = bpy.context.object
14 me = obj.data
15 bm = bmesh.from_edit_mesh(me)
17 edges = [e for e in bm.edges if e.select]
19 if len(edges) == 2:
20 [[v1, v2], [v3, v4]] = [[v.co for v in e.verts] for e in edges]
22 iv = geometry.intersect_line_line(v1, v2, v3, v4)
23 if iv:
24 iv = (iv[0] + iv[1]) / 2
25 bm.verts.new(iv)
27 bm.verts.ensure_lookup_table()
29 bm.verts[-1].select = True
30 bmesh.update_edit_mesh(me)
33 class TCVert2Intersection(bpy.types.Operator):
34 '''Add a vertex at the intersection (projected or real) of two selected edges'''
35 bl_idname = 'tinycad.vertintersect'
36 bl_label = 'V2X vertex to intersection'
37 bl_options = {'REGISTER', 'UNDO'}
39 @classmethod
40 def poll(cls, context):
41 obj = context.active_object
42 return obj is not None and obj.type == 'MESH' and obj.mode == 'EDIT'
44 def execute(self, context):
45 add_vertex_to_intersection()
46 return {'FINISHED'}