39 lines
1.9 KiB
Python
39 lines
1.9 KiB
Python
import math
|
|
|
|
import unreal
|
|
|
|
|
|
def look_at(actor, target):
|
|
actor.set_actor_rotation(unreal.MathLibrary.find_look_at_rotation(
|
|
actor.get_actor_location(), unreal.Vector(*target)), False)
|
|
|
|
|
|
def create(scene, location=(450, -550, 300), target=(0, 0, 100), fov=43.6):
|
|
"""Create a camera with a horizontal field of view in degrees (0 < fov < 180)."""
|
|
fov = float(fov)
|
|
if not 0 < fov < 180:
|
|
raise ValueError("fov must be between 0 and 180 degrees (exclusive)")
|
|
sensor_width = 36.0
|
|
focal_length = sensor_width / (2 * math.tan(math.radians(fov) / 2))
|
|
actor = scene.spawn(unreal.CineCameraActor, "Camera", location)
|
|
component = actor.get_cine_camera_component()
|
|
filmback = component.get_editor_property("filmback")
|
|
filmback.set_editor_property("sensor_width", sensor_width)
|
|
filmback.set_editor_property("sensor_height", 20.25)
|
|
component.set_editor_property("filmback", filmback)
|
|
component.set_editor_property("current_focal_length", float(focal_length))
|
|
focus = component.get_editor_property("focus_settings")
|
|
focus.set_editor_property("focus_method", unreal.CameraFocusMethod.DISABLE)
|
|
component.set_editor_property("focus_settings", focus)
|
|
settings = component.get_editor_property("post_process_settings")
|
|
settings.set_editor_property("override_auto_exposure_bias", True)
|
|
settings.set_editor_property("auto_exposure_bias", 0.0)
|
|
settings.set_editor_property("override_auto_exposure_min_brightness", True)
|
|
settings.set_editor_property("override_auto_exposure_max_brightness", True)
|
|
# Extended luminance range interprets these as EV100, not linear brightness.
|
|
settings.set_editor_property("auto_exposure_min_brightness", 8.0)
|
|
settings.set_editor_property("auto_exposure_max_brightness", 8.0)
|
|
component.set_editor_property("post_process_settings", settings)
|
|
look_at(actor, target)
|
|
return actor
|