mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-12 10:33:20 +00:00
Now the mouse snaps in angle axis in 30 degree intervals
This commit is contained in:
committed by
Bruno Perdigão
parent
a3b2860789
commit
17a0face6e
@@ -464,51 +464,12 @@ class DrawPolylineWall(bpy.types.Operator):
|
||||
else:
|
||||
return None, None, None
|
||||
|
||||
|
||||
def get_snap_points(obj, face_index):
|
||||
snap_points = {}
|
||||
matrix = obj.matrix_world.copy()
|
||||
face = obj.data.polygons[face_index]
|
||||
vertices = []
|
||||
for i in face.vertices:
|
||||
vertices.append(matrix @ obj.data.vertices[i].co)
|
||||
|
||||
edges_center = []
|
||||
for v1, v2 in zip(vertices, vertices[1:] + [vertices[0]]):
|
||||
middle_dist = (v2-v1) / 2
|
||||
edges_center.append(v1 + middle_dist)
|
||||
|
||||
snap_points.update({tuple(vertex): "Vertices" for vertex in vertices})
|
||||
snap_points.update({tuple(edge_center): "Edge Center" for edge_center in edges_center})
|
||||
|
||||
return snap_points
|
||||
|
||||
|
||||
def select_snap_point(snap_points, hit, threshold):
|
||||
shortest_distance = None
|
||||
snap_point = None
|
||||
for point, snap_type in snap_points.items():
|
||||
point = Vector(point)
|
||||
distance = (point - hit).length
|
||||
if distance > threshold:
|
||||
continue
|
||||
if shortest_distance and distance < shortest_distance:
|
||||
shortest_distance = distance
|
||||
snap_point = (point, snap_type)
|
||||
|
||||
elif not shortest_distance:
|
||||
shortest_distance = distance
|
||||
snap_point = (point, snap_type)
|
||||
else:
|
||||
pass
|
||||
|
||||
return snap_point
|
||||
|
||||
|
||||
snap_threshold = 0.3
|
||||
ray_origin, ray_target, ray_direction = get_viewport_ray_data()
|
||||
obj, hit, face_index = cast_rays_and_get_best_object()
|
||||
intersection = ray_cast_to_plane(context, plane_origin, plane_normal)
|
||||
rot_intersection = tool.Snaping.snap_on_axis(intersection)
|
||||
|
||||
|
||||
if obj is not None:
|
||||
@@ -524,7 +485,10 @@ class DrawPolylineWall(bpy.types.Operator):
|
||||
tool.Snaping.update_snaping_point(hit, "Face")
|
||||
|
||||
else:
|
||||
tool.Snaping.update_snaping_point(intersection, "Plane")
|
||||
if rot_intersection:
|
||||
tool.Snaping.update_snaping_point(rot_intersection, "Plane")
|
||||
else:
|
||||
tool.Snaping.update_snaping_point(intersection, "Plane")
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
import bpy
|
||||
import blenderbim.core.tool
|
||||
import math
|
||||
import mathutils
|
||||
from mathutils import Matrix, Vector
|
||||
|
||||
@@ -98,3 +99,30 @@ class Snaping(blenderbim.core.tool.Snaping):
|
||||
def remove_last_polyline_point(cls):
|
||||
polyline_data = bpy.context.scene.BIMModelProperties.polyline_point
|
||||
polyline_data.remove(len(polyline_data) - 1)
|
||||
|
||||
def snap_on_axis(intersection):
|
||||
polyline_data = bpy.context.scene.BIMModelProperties.polyline_point
|
||||
if polyline_data:
|
||||
last_point_data =polyline_data[-1]
|
||||
last_point = Vector((last_point_data.x, last_point_data.y, last_point_data.z))
|
||||
else:
|
||||
last_point = Vector((0, 0, 0))
|
||||
|
||||
# translates intersection point based on last_point
|
||||
translated_intersection = intersection - last_point
|
||||
for i in range(12):
|
||||
angle = 30 * i
|
||||
rot_mat = Matrix.Rotation(math.radians(360 - angle), 3, 'Z')
|
||||
rot_intersection = rot_mat @ translated_intersection
|
||||
print("ROT_INT", rot_intersection)
|
||||
is_on_rot_axis = abs(rot_intersection.y) <= 0.60
|
||||
if is_on_rot_axis:
|
||||
# snap to axis
|
||||
rot_intersection = Vector((rot_intersection.x, 0, rot_intersection.z))
|
||||
# convert it back
|
||||
snap_intersection = rot_mat.inverted() @ rot_intersection + last_point
|
||||
print('SNAP', snap_intersection)
|
||||
return snap_intersection
|
||||
|
||||
return None
|
||||
|
||||
|
||||
Reference in New Issue
Block a user