mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-30 12:09:51 +00:00
shape_builder - remove mathutils dependency completely #5192
This commit is contained in:
@@ -27,7 +27,6 @@ import ifcopenshell.util.element
|
||||
import ifcopenshell.util.representation
|
||||
import ifcopenshell.util.schema
|
||||
import ifcopenshell.util.unit
|
||||
from ifcopenshell.util.shape_builder import V
|
||||
import bonsai.tool as tool
|
||||
import bonsai.core.geometry
|
||||
import bonsai.core.geometry as core
|
||||
@@ -40,6 +39,8 @@ from typing import Union, Any, Optional
|
||||
import json
|
||||
import collections
|
||||
|
||||
V_ = tool.Blender.V_
|
||||
|
||||
|
||||
def update_door_modifier_representation(context: bpy.types.Context) -> None:
|
||||
obj = context.active_object
|
||||
@@ -188,15 +189,15 @@ def bm_sort_out_geom(
|
||||
def bm_mirror(
|
||||
bm: bmesh.types.BMesh,
|
||||
verts: list[bmesh.types.BMVert],
|
||||
mirror_axes: Vector = V(1, 0, 0).freeze(),
|
||||
mirror_point: Vector = V(0, 0, 0).freeze(),
|
||||
mirror_axes: Vector = V_(1, 0, 0).freeze(),
|
||||
mirror_point: Vector = V_(0, 0, 0).freeze(),
|
||||
create_copy: bool = False,
|
||||
) -> list[bmesh.types.BMVert]:
|
||||
matrix = Matrix.Translation(mirror_point)
|
||||
for i, v in enumerate(mirror_axes):
|
||||
if not v:
|
||||
continue
|
||||
mirror_axis = V(0, 0, 0)
|
||||
mirror_axis = V_(0, 0, 0)
|
||||
mirror_axis[i] = 1.0
|
||||
matrix = matrix @ Matrix.Scale(-1, 4, mirror_axis)
|
||||
matrix = matrix @ Matrix.Translation(-mirror_point)
|
||||
@@ -219,9 +220,9 @@ def create_bm_extruded_profile(
|
||||
points: list[Vector],
|
||||
edges: Optional[list[tuple[int, int]]] = None,
|
||||
faces: Optional[list[list[int]]] = None,
|
||||
position: Vector = V(0, 0, 0).freeze(),
|
||||
position: Vector = V_(0, 0, 0).freeze(),
|
||||
magnitude: float = 1.0,
|
||||
extrusion_vector: Vector = V(0, 0, 1).freeze(),
|
||||
extrusion_vector: Vector = V_(0, 0, 1).freeze(),
|
||||
) -> list[bmesh.types.BMVert]:
|
||||
bm.verts.index_update()
|
||||
bm.edges.index_update()
|
||||
@@ -250,7 +251,7 @@ def create_bm_extruded_profile(
|
||||
|
||||
|
||||
def create_bm_door_lining(
|
||||
bm: bmesh.types.BMesh, size: Vector, thickness: list, position: Vector = V(0, 0, 0).freeze()
|
||||
bm: bmesh.types.BMesh, size: Vector, thickness: list, position: Vector = V_(0, 0, 0).freeze()
|
||||
) -> list[bmesh.types.BMVert]:
|
||||
"""`thickness` of the profile is defined as list in the following order: `(SIDE, TOP)`
|
||||
|
||||
@@ -363,9 +364,9 @@ def update_door_modifier_bmesh(context: bpy.types.Context) -> None:
|
||||
glass_thickness = 0.01
|
||||
|
||||
# handle dimensions (hardcoded)
|
||||
handle_size = V(120, 40, 20) * 0.001
|
||||
handle_offset = V(60, 0, 1000) * 0.001 # to the handle center
|
||||
handle_center_offset = V(handle_size.y / 2, 0, handle_size.z) / 2
|
||||
handle_size = V_(120, 40, 20) * 0.001
|
||||
handle_offset = V_(60, 0, 1000) * 0.001 # to the handle center
|
||||
handle_center_offset = V_(handle_size.y / 2, 0, handle_size.z) / 2
|
||||
|
||||
if transfom_offset:
|
||||
panel_height = transfom_offset + transom_thickness - lining_to_panel_offset_x - threshold_thickness
|
||||
@@ -377,7 +378,7 @@ def update_door_modifier_bmesh(context: bpy.types.Context) -> None:
|
||||
bm = bmesh.new()
|
||||
|
||||
# add lining
|
||||
lining_size = V(overall_width, lining_depth, lining_height)
|
||||
lining_size = V_(overall_width, lining_depth, lining_height)
|
||||
lining_thickness = [side_lining_thickness, top_lining_thickness]
|
||||
lining_verts = create_bm_door_lining(bm, lining_size, lining_thickness)
|
||||
|
||||
@@ -385,8 +386,8 @@ def update_door_modifier_bmesh(context: bpy.types.Context) -> None:
|
||||
if not threshold_thickness:
|
||||
threshold_verts = []
|
||||
else:
|
||||
threshold_size = V(threshold_width, threshold_depth, threshold_thickness)
|
||||
threshold_position = V(side_lining_thickness, threshold_offset, 0)
|
||||
threshold_size = V_(threshold_width, threshold_depth, threshold_thickness)
|
||||
threshold_position = V_(side_lining_thickness, threshold_offset, 0)
|
||||
threshold_verts = create_bm_box(bm, threshold_size, threshold_position)
|
||||
|
||||
# add casings
|
||||
@@ -400,12 +401,12 @@ def update_door_modifier_bmesh(context: bpy.types.Context) -> None:
|
||||
]
|
||||
outer_casing_thickness = inner_casing_thickness.copy() if double_swing_door else casing_thickness
|
||||
|
||||
casing_size = V(overall_width + casing_wall_overlap * 2, casing_depth, overall_height + casing_wall_overlap)
|
||||
casing_position = V(-casing_wall_overlap, -casing_depth, 0)
|
||||
casing_size = V_(overall_width + casing_wall_overlap * 2, casing_depth, overall_height + casing_wall_overlap)
|
||||
casing_position = V_(-casing_wall_overlap, -casing_depth, 0)
|
||||
outer_casing_verts = create_bm_door_lining(bm, casing_size, outer_casing_thickness, casing_position)
|
||||
casing_verts.extend(outer_casing_verts)
|
||||
|
||||
inner_casing_position = V(-casing_wall_overlap, lining_depth, 0)
|
||||
inner_casing_position = V_(-casing_wall_overlap, lining_depth, 0)
|
||||
inner_casing_verts = create_bm_door_lining(bm, casing_size, inner_casing_thickness, inner_casing_position)
|
||||
casing_verts.extend(inner_casing_verts)
|
||||
|
||||
@@ -417,12 +418,12 @@ def update_door_modifier_bmesh(context: bpy.types.Context) -> None:
|
||||
door_verts.extend(create_bm_box(bm, panel_size, panel_position))
|
||||
# add door handle
|
||||
handle_points = [
|
||||
V(0, 0, 0),
|
||||
V(0, -handle_size.y, 0),
|
||||
V(handle_size.x, -handle_size.y, 0),
|
||||
V(handle_size.x, -handle_size.y / 2, 0),
|
||||
V(handle_size.y / 2, -handle_size.y / 2, 0),
|
||||
V(handle_size.y / 2, 0, 0),
|
||||
V_(0, 0, 0),
|
||||
V_(0, -handle_size.y, 0),
|
||||
V_(handle_size.x, -handle_size.y, 0),
|
||||
V_(handle_size.x, -handle_size.y / 2, 0),
|
||||
V_(handle_size.y / 2, -handle_size.y / 2, 0),
|
||||
V_(handle_size.y / 2, 0, 0),
|
||||
]
|
||||
handle_position = panel_position + handle_offset - handle_center_offset
|
||||
door_handle_verts = create_bm_extruded_profile(
|
||||
@@ -432,22 +433,22 @@ def update_door_modifier_bmesh(context: bpy.types.Context) -> None:
|
||||
|
||||
if door_swing_type == "LEFT":
|
||||
bm_mirror(
|
||||
bm, door_handle_verts, mirror_axes=V(1, 0, 0), mirror_point=panel_position + V(panel_size.x / 2, 0, 0)
|
||||
bm, door_handle_verts, mirror_axes=V_(1, 0, 0), mirror_point=panel_position + V_(panel_size.x / 2, 0, 0)
|
||||
)
|
||||
|
||||
door_handle_mirrored_verts = bm_mirror(
|
||||
bm,
|
||||
door_handle_verts,
|
||||
mirror_axes=V(0, 1, 0),
|
||||
mirror_point=handle_position + V(0, panel_size.y / 2, 0),
|
||||
mirror_axes=V_(0, 1, 0),
|
||||
mirror_point=handle_position + V_(0, panel_size.y / 2, 0),
|
||||
create_copy=True,
|
||||
)
|
||||
door_verts.extend(door_handle_mirrored_verts)
|
||||
return door_verts
|
||||
|
||||
door_verts = []
|
||||
panel_size = V(panel_width, panel_depth, panel_height)
|
||||
panel_position = V(lining_to_panel_offset_x, lining_to_panel_offset_y, threshold_thickness)
|
||||
panel_size = V_(panel_width, panel_depth, panel_height)
|
||||
panel_position = V_(lining_to_panel_offset_x, lining_to_panel_offset_y, threshold_thickness)
|
||||
|
||||
if double_door:
|
||||
# keeping a little space between doors for readibility
|
||||
@@ -455,8 +456,8 @@ def update_door_modifier_bmesh(context: bpy.types.Context) -> None:
|
||||
panel_size.x = panel_size.x / 2 - double_door_offset
|
||||
door_verts.extend(create_bm_door_panel(panel_size, panel_position, "LEFT"))
|
||||
|
||||
mirror_point = panel_position + V(door_opening_width / 2, 0, 0)
|
||||
door_verts.extend(bm_mirror(bm, door_verts, V(1, 0, 0), mirror_point, create_copy=True))
|
||||
mirror_point = panel_position + V_(door_opening_width / 2, 0, 0)
|
||||
door_verts.extend(bm_mirror(bm, door_verts, V_(1, 0, 0), mirror_point, create_copy=True))
|
||||
else:
|
||||
door_swing_type = "LEFT" if door_type.endswith("LEFT") else "RIGHT"
|
||||
door_verts.extend(create_bm_door_panel(panel_size, panel_position, door_swing_type))
|
||||
@@ -474,9 +475,9 @@ def update_door_modifier_bmesh(context: bpy.types.Context) -> None:
|
||||
transom_thickness,
|
||||
]
|
||||
window_lining_thickness.append(transom_thickness)
|
||||
window_lining_size = V(overall_width, lining_depth, window_lining_height)
|
||||
window_position = V(0, 0, overall_height - window_lining_height)
|
||||
frame_size = V(door_opening_width, frame_depth, frame_height)
|
||||
window_lining_size = V_(overall_width, lining_depth, window_lining_height)
|
||||
window_position = V_(0, 0, overall_height - window_lining_height)
|
||||
frame_size = V_(door_opening_width, frame_depth, frame_height)
|
||||
window_lining_verts, frame_verts, glass_verts = create_bm_window(
|
||||
bm,
|
||||
window_lining_size,
|
||||
@@ -490,7 +491,7 @@ def update_door_modifier_bmesh(context: bpy.types.Context) -> None:
|
||||
)
|
||||
|
||||
lining_offset_verts = lining_verts + door_verts + window_lining_verts + frame_verts + glass_verts
|
||||
bmesh.ops.translate(bm, vec=V(0, lining_offset, 0), verts=lining_offset_verts)
|
||||
bmesh.ops.translate(bm, vec=V_(0, lining_offset, 0), verts=lining_offset_verts)
|
||||
bmesh.ops.remove_doubles(bm, verts=bm.verts, dist=0.0001)
|
||||
|
||||
if bpy.context.active_object.mode == "EDIT":
|
||||
|
||||
Reference in New Issue
Block a user