This commit is contained in:
Andrej730
2025-05-07 12:36:29 +05:00
parent cf253824ca
commit 94cf56e080
7 changed files with 15 additions and 3 deletions
@@ -1283,6 +1283,7 @@ class ActivateBcfViewpoint(bpy.types.Operator):
cam_aspect: float,
context: bpy.types.Context,
) -> None:
assert isinstance(obj.data, bpy.types.Camera)
if viewpoint.visualization_info.orthogonal_camera:
camera = viewpoint.visualization_info.orthogonal_camera
obj.data.type = "ORTHO"
@@ -392,6 +392,7 @@ ground_glow source ground
scene.add_surface(scene_path)
scene.add_source(sky_file_path)
print("Setting up view...")
assert isinstance(camera.data, bpy.types.Camera)
if camera.data.type == "PERSP":
# Perspective camera
camera_fov = camera.data.angle
@@ -547,9 +548,11 @@ class ViewFromSun(bpy.types.Operator):
def execute(self, context):
if not (camera := bpy.data.objects.get("SunPathCamera")):
camera = bpy.data.objects.new("SunPathCamera", bpy.data.cameras.new("SunPathCamera"))
assert isinstance(camera.data, bpy.types.Camera)
assert context.scene
camera.data.type = "ORTHO"
camera.data.ortho_scale = 100 # The default of 6m is too small
bpy.context.scene.collection.objects.link(camera)
context.scene.collection.objects.link(camera)
tool.Blender.activate_camera(camera)
props = context.scene.BIMSolarProperties
props.hour = props.hour # Just to refresh camera position
@@ -130,6 +130,7 @@ class LoadsDecorator:
coord = Vector(coord)
rv3d = context.region_data
assert rv3d and context.region
perspective = rv3d.view_perspective
view_matrix = rv3d.view_matrix
point_view_space = view_matrix @ coord
+2
View File
@@ -66,6 +66,7 @@ class Raycast(bonsai.core.tool.Raycast):
cls, context: bpy.types.Context, obj: bpy.types.Object
) -> Union[tuple[bpy.types.Object, list[float]], None]:
rv3d = context.region_data
assert rv3d
view_location = rv3d.view_matrix.inverted().translation
obj_matrix = obj.matrix_world.copy()
bbox = [obj_matrix @ Vector(v) for v in obj.bound_box]
@@ -138,6 +139,7 @@ class Raycast(bonsai.core.tool.Raycast):
):
region = context.region
rv3d = context.region_data
assert rv3d and region
original_perspective = rv3d.view_perspective
# TODO The raycast was working for orthographic view, but not when you are inside a camera view. This solution feels hacky,
+3 -1
View File
@@ -1666,9 +1666,11 @@ class Sequence(bonsai.core.tool.Sequence):
return predefined_type, object_type
@classmethod
def add_animation_camera(cls):
def add_animation_camera(cls) -> None:
bpy.ops.object.camera_add()
camera = bpy.context.active_object
assert camera and isinstance(camera.data, bpy.types.Camera)
assert bpy.context.scene
camera.data.lens = 26
camera.name = "4D Camera"
camera.location = mathutils.Vector((15, 0, 15))
+3 -1
View File
@@ -18,6 +18,7 @@
import bpy
import ifcopenshell
import ifcopenshell.util.unit
import bonsai.core.tool
import bonsai.tool as tool
from bonsai.bim.module.model.decorator import PolylineDecorator
@@ -44,8 +45,9 @@ class Snap(bonsai.core.tool.Snap):
cls.snap_plane_method = value
@classmethod
def get_increment_snap_value(cls, context):
def get_increment_snap_value(cls, context: bpy.types.Context) -> Union[float, None]:
rv3d = context.region_data
assert rv3d
factor = 1
fractions = [100, 20, 10, 2]
+1
View File
@@ -58,6 +58,7 @@ class TestCreateCamera(NewFile):
obj = subject.create_camera("Name", mathutils.Matrix(), "PERSPECTIVE")
assert obj.name == "Name"
assert obj.matrix_world == mathutils.Matrix()
assert isinstance(obj.data, bpy.types.Camera)
assert obj.data.type == "PERSP"
assert obj.data.ortho_scale == 50
assert obj.data.clip_end == 10