Rendering utils¶
Common utils function for blender controls
-
threedb.controls.blender.utils.
load_model
(model: str) → str¶ Load an object from a blender file and insert it in the scene
Note
Since .blend files can contain many object we go under the assumption that in the file XXXXXX.blend, there will be an object named XXXXXX, and this is this one we will load
- Parameters
model – The path to the blender file that needs to be loaded
- Returns
The uid of the object loaded
- Return type
str
-
threedb.controls.blender.utils.
cleanup_translate_containers
(obj: Any) → None¶ Remove all translations containers
Note
To know what translate containers are please refer to post_translate
- Parameters
obj (blender object) – The object to remove containers on
-
threedb.controls.blender.utils.
post_translate
(obj: Any, offset: Tuple[float, float, float]) → None¶ Apply a translation on an object but ensure it happens after rotations
Note
To work this function creates a container around the object and apply the translation on the parent. This way, any rotation on the object itself will always be applied before the translation The container name will start by TRANSLATE_PREFIX so that is can easily be detected and removed in cleanup_translate_containers
- Parameters
obj (blender object) – The object to translate
offset – The vector to translate by
-
threedb.controls.blender.utils.
clamp
(value: float, minimum: float, maximum: float) → float¶ Clamp a value between two numbers
- Parameters
value – The value to clamp
minimum – Minimum acceptable value
maximum – Maximum acceptable value
- Returns
The clamped value
- Return type
float
-
threedb.controls.blender.utils.
camera_view_bounds_2d
(scene: bpy.types.Scene, cam_ob: bpy.types.Object, mesh: bpy.types.Mesh) → Tuple[float, float, float, float]¶ Returns camera-space bounding box of mesh object. Negative ‘z’ value means the point is behind the camera. Takes shift-x/y, lens angle and sensor size into account as well as perspective/ortho projections.
- Parameters
scene (bpy.types.Scene) – Scene to use for frame size.
cam_ob (bpy.types.Object) – Camera object
me_ob (bpy.types.Mesh) – Untransformed Mesh.
- Returns
A tuple
(x, y, width, height)
encoding the camera-space bounding box of the mesh object.- Return type
Tuple[float, float, float, float]