mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-08 17:01:40 +00:00
Align new Model drawings to viewport by default
Previously it was creating not very useful top-down camera at `(0,0,0)`, now it should be more intuitive. Example - https://imgur.com/a/GHrvCSJ
This commit is contained in:
@@ -249,7 +249,7 @@ def add_drawing(
|
||||
assert location_hint is not None
|
||||
drawing_name = drawing.ensure_unique_drawing_name(drawing.generate_drawing_name(target_view, location_hint))
|
||||
drawing_matrix = drawing.generate_drawing_matrix(target_view, location_hint)
|
||||
camera = drawing.create_camera(drawing_name, drawing_matrix, location_hint)
|
||||
camera = drawing.create_camera(drawing_name, drawing_matrix, location_hint, target_view)
|
||||
element = drawing.run_root_assign_class(
|
||||
obj=camera,
|
||||
ifc_class="IfcAnnotation",
|
||||
|
||||
@@ -86,8 +86,11 @@ class Blender(bonsai.core.tool.Blender):
|
||||
def activate_camera(cls, obj: bpy.types.Object) -> None:
|
||||
|
||||
area = cls.get_view3d_area()
|
||||
is_local_view = area.spaces[0].local_view is not None
|
||||
assert area
|
||||
assert isinstance((space := area.spaces[0]), bpy.types.SpaceView3D)
|
||||
is_local_view = space.local_view is not None
|
||||
|
||||
assert bpy.context.screen and bpy.context.scene
|
||||
if is_local_view:
|
||||
# Turn off local view before activating drawing, and then turn it on again.
|
||||
for a in bpy.context.screen.areas:
|
||||
@@ -100,7 +103,8 @@ class Blender(bonsai.core.tool.Blender):
|
||||
else:
|
||||
bpy.context.scene.camera = obj
|
||||
|
||||
area.spaces[0].region_3d.view_perspective = "CAMERA"
|
||||
assert space.region_3d
|
||||
space.region_3d.view_perspective = "CAMERA"
|
||||
|
||||
@classmethod
|
||||
def get_area_props(cls, context: bpy.types.Context) -> bpy.types.PropertyGroup:
|
||||
|
||||
@@ -299,7 +299,11 @@ class Drawing(bonsai.core.tool.Drawing):
|
||||
|
||||
@classmethod
|
||||
def create_camera(
|
||||
cls, name: str, matrix: Matrix, location_hint: Union[LocationHintLiteral, int]
|
||||
cls,
|
||||
name: str,
|
||||
matrix: Matrix,
|
||||
location_hint: Union[LocationHintLiteral, int],
|
||||
target_view: ifcopenshell.util.representation.TARGET_VIEW,
|
||||
) -> bpy.types.Object:
|
||||
camera = bpy.data.objects.new(name, (camera_data := bpy.data.cameras.new(name)))
|
||||
props = cls.get_camera_props(camera_data)
|
||||
@@ -311,7 +315,11 @@ class Drawing(bonsai.core.tool.Drawing):
|
||||
props.camera_type = "ORTHO"
|
||||
camera_data.ortho_scale = 50 # The default of 6m is too small
|
||||
camera_data.clip_start = 0.002 # 2mm is close to zero but allows any GPU-drawn lines to be visible.
|
||||
camera_data.clip_end = 10 # A slightly more reasonable default
|
||||
if target_view == "MODEL_VIEW":
|
||||
assert (space := tool.Blender.get_view3d_space())
|
||||
camera_data.clip_end = max(space.clip_end, 10)
|
||||
else:
|
||||
camera_data.clip_end = 10 # A slightly more reasonable default
|
||||
if bpy.context.scene.unit_settings.system == "IMPERIAL":
|
||||
props.diagram_scale = '1/8"=1\'-0"|1/96'
|
||||
else:
|
||||
@@ -628,7 +636,9 @@ class Drawing(bonsai.core.tool.Drawing):
|
||||
elif location_hint == "WEST":
|
||||
return mathutils.Matrix(((0, 0, 1, x), (1, 0, 0, y), (0, 1, 0, z), (0, 0, 0, 1)))
|
||||
elif target_view == "MODEL_VIEW":
|
||||
return mathutils.Matrix(((1, 0, 0, x), (0, 1, 0, y), (0, 0, 1, z), (0, 0, 0, 1)))
|
||||
assert (space := tool.Blender.get_view3d_space())
|
||||
assert (r3d := space.region_3d)
|
||||
return r3d.view_matrix.inverted()
|
||||
return mathutils.Matrix()
|
||||
|
||||
@classmethod
|
||||
|
||||
Reference in New Issue
Block a user