mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-11 10:06:47 +00:00
Points are now added relative to default container Z value.
This commit is contained in:
committed by
Bruno Perdigão
parent
bf96c63f7d
commit
723701f1b8
@@ -340,9 +340,11 @@ class WallPolylineDecorator:
|
||||
def calculate_distance_and_angle(cls, context, is_input_on):
|
||||
try:
|
||||
polyline_data = context.scene.BIMModelProperties.polyline_point
|
||||
default_container_elevation = tool.Ifc.get_object(tool.Root.get_default_container()).location.z
|
||||
last_point_data = polyline_data[len(polyline_data) - 1]
|
||||
except:
|
||||
last_point_data = None
|
||||
default_container_elevation = 0
|
||||
|
||||
snap_prop = context.scene.BIMModelProperties.snap_mouse_point[0]
|
||||
|
||||
@@ -352,11 +354,11 @@ class WallPolylineDecorator:
|
||||
last_point = Vector((0, 0, 0))
|
||||
|
||||
if is_input_on:
|
||||
snap_vector = Vector((float(cls.input_panel["X"]), float(cls.input_panel["Y"]), 0))
|
||||
snap_vector = Vector((float(cls.input_panel["X"]), float(cls.input_panel["Y"]), default_container_elevation))
|
||||
else:
|
||||
snap_vector = Vector((snap_prop.x, snap_prop.y, 0))
|
||||
snap_vector = Vector((snap_prop.x, snap_prop.y, default_container_elevation))
|
||||
|
||||
distance = (snap_vector - last_point).length # TODO get height from default container
|
||||
distance = (snap_vector - last_point).length
|
||||
x_axis_edge = (
|
||||
Vector((0, 0)),
|
||||
Vector((1, 0)),
|
||||
@@ -364,7 +366,7 @@ class WallPolylineDecorator:
|
||||
current_axis = (
|
||||
Vector((last_point.x, last_point.y)),
|
||||
Vector((snap_vector.x, snap_vector.y)),
|
||||
) # TODO get height from default container
|
||||
)
|
||||
if distance > 0:
|
||||
angle = tool.Cad.angle_edges(x_axis_edge, current_axis, degrees=True, signed=True)
|
||||
if cls.input_panel:
|
||||
@@ -446,6 +448,7 @@ class WallPolylineDecorator:
|
||||
gpu.state.point_size_set(10)
|
||||
|
||||
snap_prop = context.scene.BIMModelProperties.snap_mouse_point[0]
|
||||
default_container_elevation = tool.Ifc.get_object(tool.Root.get_default_container()).location.z
|
||||
|
||||
# Point related to the mouse
|
||||
mouse_point = [Vector((snap_prop.x, snap_prop.y, snap_prop.z))]
|
||||
@@ -459,7 +462,7 @@ class WallPolylineDecorator:
|
||||
projection_point = []
|
||||
if snap_prop.snap_type != "Plane" and snap_prop.z != 0:
|
||||
self.line_shader.uniform_float("lineWidth", 1.0)
|
||||
projection_point = [Vector((snap_prop.x, snap_prop.y, 0))] # TODO get height from default container
|
||||
projection_point = [Vector((snap_prop.x, snap_prop.y, default_container_elevation))]
|
||||
self.draw_batch("POINTS", projection_point, decorator_color_unselected)
|
||||
edges = [[0, 1]]
|
||||
self.draw_batch("LINES", mouse_point + projection_point, (1.0, 0.6, 0.0, 1.0), edges)
|
||||
|
||||
@@ -331,7 +331,8 @@ class DrawPolylineWall(bpy.types.Operator):
|
||||
)
|
||||
|
||||
# Plane to intersect. Default Container
|
||||
plane_origin = Vector((0, 0, 0))
|
||||
default_container_elevation = tool.Ifc.get_object(tool.Root.get_default_container()).location.z
|
||||
plane_origin = Vector((0, 0, default_container_elevation))
|
||||
plane_normal = Vector((0, 0, 1))
|
||||
|
||||
def cast_rays_and_get_best_object():
|
||||
@@ -398,22 +399,22 @@ class DrawPolylineWall(bpy.types.Operator):
|
||||
try:
|
||||
snap_point_vector = Vector(
|
||||
(snap_point[0].x, snap_point[0].y, snap_point[0].z)
|
||||
) # TODO use Z from default container
|
||||
)
|
||||
snap_point_axis_1 = (
|
||||
Vector((snap_point[0].x + 1000, snap_point[0].y, 0)),
|
||||
Vector((snap_point[0].x - 1000, snap_point[0].y, 0)),
|
||||
Vector((snap_point[0].x + 1000, snap_point[0].y, default_container_elevation)),
|
||||
Vector((snap_point[0].x - 1000, snap_point[0].y, default_container_elevation)),
|
||||
)
|
||||
snap_point_axis_2 = (
|
||||
Vector((snap_point[0].x, snap_point[0].y + 1000, 0)),
|
||||
Vector((snap_point[0].x, snap_point[0].y - 1000, 0)),
|
||||
Vector((snap_point[0].x, snap_point[0].y + 1000, default_container_elevation)),
|
||||
Vector((snap_point[0].x, snap_point[0].y - 1000, default_container_elevation)),
|
||||
)
|
||||
snap_angle_axis = (axis_start, axis_end)
|
||||
result_1 = tool.Cad.intersect_edges(snap_angle_axis, snap_point_axis_1)
|
||||
result_1 = Vector((result_1[0].x, result_1[0].y, 0)) # TODO use Z from default container
|
||||
result_1 = Vector((result_1[0].x, result_1[0].y, default_container_elevation))
|
||||
distance_1 = (result_1 - snap_point_vector).length
|
||||
|
||||
result_2 = tool.Cad.intersect_edges(snap_angle_axis, snap_point_axis_2)
|
||||
result_2 = Vector((result_2[0].x, result_2[0].y, 0)) # TODO use Z from default container
|
||||
result_2 = Vector((result_2[0].x, result_2[0].y, default_container_elevation))
|
||||
distance_2 = (result_2 - snap_point_vector).length
|
||||
|
||||
if distance_1 < distance_2:
|
||||
@@ -424,7 +425,6 @@ class DrawPolylineWall(bpy.types.Operator):
|
||||
tool.Snaping.update_snaping_point(best_result, "Axis")
|
||||
|
||||
except Exception as e:
|
||||
print(str(e))
|
||||
tool.Snaping.update_snaping_point(snap_point[0], snap_point[1])
|
||||
|
||||
else:
|
||||
@@ -643,7 +643,6 @@ class DrawPolylineWall(bpy.types.Operator):
|
||||
WallPolylineDecorator.uninstall()
|
||||
tool.Snaping.clear_polyline()
|
||||
tool.Blender.update_viewport()
|
||||
print("CANCELLED")
|
||||
return {"CANCELLED"}
|
||||
|
||||
return {"RUNNING_MODAL"}
|
||||
|
||||
@@ -19,8 +19,7 @@
|
||||
import bpy
|
||||
from bpy_extras import view3d_utils
|
||||
import blenderbim.core.tool
|
||||
|
||||
# from blenderbim.bim.module.model.decorator import WallPolylineDecorator
|
||||
import blenderbim.tool as tool
|
||||
import math
|
||||
import mathutils
|
||||
from mathutils import Matrix, Vector
|
||||
@@ -113,14 +112,15 @@ class Raycasting(blenderbim.core.tool.Raycasting):
|
||||
mouse_pos = event.mouse_region_x, event.mouse_region_y
|
||||
ray_origin, ray_target, ray_direction = cls.get_viewport_ray_data(context, event)
|
||||
|
||||
intersection = Vector((0, 0, 0))
|
||||
default_container_elevation = tool.Ifc.get_object(tool.Root.get_default_container()).location.z
|
||||
intersection = Vector((0, 0, default_container_elevation))
|
||||
try:
|
||||
loc = view3d_utils.region_2d_to_location_3d(region, rv3d, mouse_pos, ray_direction)
|
||||
intersection = mathutils.geometry.intersect_line_plane(ray_target, loc, plane_origin, plane_normal)
|
||||
except:
|
||||
intersection = Vector((0, 0, 0))
|
||||
intersection = Vector((0, 0, default_container_elevation))
|
||||
|
||||
if intersection == None:
|
||||
intersection = Vector((0, 0, 0))
|
||||
intersection = Vector((0, 0, default_container_elevation))
|
||||
|
||||
return intersection
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
import bpy
|
||||
import blenderbim.core.tool
|
||||
import blenderbim.tool as tool
|
||||
from blenderbim.bim.module.model.decorator import WallPolylineDecorator
|
||||
import math
|
||||
import mathutils
|
||||
@@ -93,14 +94,15 @@ class Snaping(blenderbim.core.tool.Snaping):
|
||||
def insert_polyline_point(cls, x=None, y=None):
|
||||
snap_vertex = bpy.context.scene.BIMModelProperties.snap_mouse_point[0]
|
||||
polyline_point = bpy.context.scene.BIMModelProperties.polyline_point.add()
|
||||
default_container_elevation = tool.Ifc.get_object(tool.Root.get_default_container()).location.z
|
||||
if x is not None and y is not None:
|
||||
polyline_point.x = x
|
||||
polyline_point.y = y
|
||||
polyline_point.z = 0 # TODO Update to the the default container height
|
||||
polyline_point.z = default_container_elevation
|
||||
else:
|
||||
polyline_point.x = snap_vertex.x
|
||||
polyline_point.y = snap_vertex.y
|
||||
polyline_point.z = 0 # TODO Update to the the default container height
|
||||
polyline_point.z = default_container_elevation
|
||||
|
||||
@classmethod
|
||||
def clear_polyline(cls):
|
||||
@@ -122,12 +124,13 @@ class Snaping(blenderbim.core.tool.Snaping):
|
||||
end = origin - rot_dir * length
|
||||
return start, end
|
||||
|
||||
default_container_elevation = tool.Ifc.get_object(tool.Root.get_default_container()).location.z
|
||||
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))
|
||||
last_point = Vector((0, 0, default_container_elevation))
|
||||
|
||||
# Translates intersection point based on last_point
|
||||
translated_intersection = intersection - last_point
|
||||
@@ -142,8 +145,8 @@ class Snaping(blenderbim.core.tool.Snaping):
|
||||
for axis in snap_axis:
|
||||
rot_mat = Matrix.Rotation(math.radians(360 - axis), 3, "Z")
|
||||
start, end = create_axis_line(rot_mat, last_point)
|
||||
WallPolylineDecorator.set_angle_axis_line(start, end)
|
||||
rot_intersection = rot_mat @ translated_intersection
|
||||
WallPolylineDecorator.set_angle_axis_line(start, end)
|
||||
if lock_axis:
|
||||
is_on_rot_axis = True
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user