MCPcopy Create free account
hub / github.com/IfcOpenShell/IfcOpenShell / create_camera

Method create_camera

src/bonsai/bonsai/tool/loader.py:861–913  ·  view source on GitHub ↗

Create camera data. Camera props are automatically updated based on ``element`` and ``shape``.

(
        cls,
        element: ifcopenshell.entity_instance,
        representation: ifcopenshell.entity_instance,
        shape: W.TriangulationElement,
    )

Source from the content-addressed store, hash-verified

859
860 @classmethod
861 def create_camera(
862 cls,
863 element: ifcopenshell.entity_instance,
864 representation: ifcopenshell.entity_instance,
865 shape: W.TriangulationElement,
866 ) -> bpy.types.Camera:
867 """Create camera data.
868
869 Camera props are automatically updated based on ``element`` and ``shape``.
870 """
871 geometry = shape.geometry
872 width = ifcopenshell.util.shape.get_x(geometry)
873 height = ifcopenshell.util.shape.get_y(geometry)
874
875 camera_type = "ORTHO"
876 if any(e.is_a() == "IfcRectangularPyramid" for e in tool.Ifc.get().traverse(representation)):
877 camera_type = "PERSP"
878
879 camera = bpy.data.cameras.new(tool.Loader.get_mesh_name_from_shape(geometry))
880 props = tool.Drawing.get_camera_props(camera)
881 props.camera_type = camera_type
882 camera.show_limits = True
883
884 if camera_type == "ORTHO":
885 depth = ifcopenshell.util.shape.get_z(geometry)
886 camera.clip_start = 0.002 # Technically 0, but Blender doesn't allow this, so 2mm it is!
887 camera.clip_end = depth
888
889 props["width"] = width
890 props["height"] = height
891 elif camera_type == "PERSP":
892 z_values = ifcopenshell.util.shape.get_vertices(geometry)[:, 2]
893 abs_min_z = abs(np.min(z_values).item())
894 abs_max_z = abs(np.max(z_values).item())
895 camera.clip_start = abs_max_z
896 camera.clip_end = abs_min_z
897 max_res = 1000
898
899 props["width"] = width
900 props["height"] = height
901
902 if width > height:
903 fov = 2 * atan(width / (2 * abs_min_z))
904 else:
905 fov = 2 * atan(height / (2 * abs_min_z))
906
907 camera.angle = fov
908
909 tool.Drawing.import_camera_props(element, camera)
910 props.update_camera_resolution() # Only after all props are imported.
911 mat = tool.Drawing.get_camera_shape_matrix(element, shape)
912 props.update_representation(mat)
913 return camera
914
915 @classmethod
916 def get_offset_point(cls, ifc_file: ifcopenshell.file) -> Union[npt.NDArray[np.float64], None]:

Callers 1

Calls 13

get_xMethod · 0.80
get_yMethod · 0.80
newMethod · 0.80
get_camera_propsMethod · 0.80
itemMethod · 0.80
import_camera_propsMethod · 0.80
is_aMethod · 0.45
traverseMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected