Closed hanson-hschang closed 5 days ago
Instead of camera, blender python implement region_3d
in viewport
(see the following reference)
def camera(self, view):
""" Return position, rotation data about a given view for the first space attached to it """
look_at = view.spaces[0].region_3d.view_location
matrix = view.spaces[0].region_3d.view_matrix
camera_pos = self.camera_position(matrix)
rotation = view.spaces[0].region_3d.view_rotation
return look_at, camera_pos, rotation
The following implementation works:
def find_area(area_type: str) -> Optional[bpy.types.Area]:
try:
for area in bpy.data.window_managers[0].windows[0].screen.areas:
if area.type == area_type:
return area
return None
except:
return None
def set_view_distance(distance: float) -> None:
assert (
isinstance(distance, (int, float)) and distance > 0
), "distance must be a positive number"
area_view_3d = find_area("VIEW_3D")
region_3d = area_view_3d.spaces[0].region_3d
region_3d.view_distance = distance
With commit 8ce65ad, it now can set view distance. Still missing other property, e.g. look_at, view_position, rotation... etc
Branch merge #28 closes this issue.
Currently, the camera in the results of the
.blend
file is initialized from a far distance. It might be better to have a command to set camera location, look at and some other camera properties. (Might be useful to have similar things as the one in povray?