From 4058c63637ecf7f31fd7bd5f182d8846d6d34de4 Mon Sep 17 00:00:00 2001 From: Nathan Vegdahl Date: Wed, 17 Aug 2022 13:43:39 -0700 Subject: [PATCH] Add DoF back to PsychoBlend exporter. --- psychoblend/objects.py | 2 +- psychoblend/world.py | 23 +++++++++++++++-------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/psychoblend/objects.py b/psychoblend/objects.py index 1e08f98..f10ed18 100644 --- a/psychoblend/objects.py +++ b/psychoblend/objects.py @@ -130,7 +130,7 @@ class RectLamp: render_engine.update_stats("", "Psychopath: Collecting '{}' at time {}".format(self.name, time)) if ob.data.psychopath.color_type == 'Rec709': - self.time_col += [('Rec709', ob.data.color * ob.data.energy)] + self.time_col += [('Rec709', ob.data.color * ob.data.energy / 2)] elif ob.data.psychopath.color_type == 'Blackbody': self.time_col += [('Blackbody', ob.data.psychopath.color_blackbody_temp, ob.data.energy)] elif ob.data.psychopath.color_type == 'ColorTemperature': diff --git a/psychoblend/world.py b/psychoblend/world.py index ead824a..b794e1d 100644 --- a/psychoblend/world.py +++ b/psychoblend/world.py @@ -1,6 +1,6 @@ import bpy -from math import degrees, tan, atan +from math import degrees, sin, asin, tan, atan from mathutils import Vector, Matrix from .util import escape_name, mat2str, ExportCancelled @@ -42,17 +42,24 @@ class Camera: def take_sample(self, render_engine, depsgraph, time): render_engine.update_stats("", "Psychopath: Collecting '{}' at time {}".format(self.ob.name, time)) - # Fov - self.fovs += [degrees(self.ob.data.angle_x)] + # Fov. + # TODO: account for the various ways sensor size can be specified. + x_extent = depsgraph.scene.render.resolution_x / depsgraph.scene.render.pixel_aspect_x + y_extent = depsgraph.scene.render.resolution_y / depsgraph.scene.render.pixel_aspect_y + aspect_ratio = x_extent / y_extent + if aspect_ratio >= 1.0: + self.fovs += [degrees(self.ob.data.angle_x)] + else: + self.fovs += [degrees(2.0 * atan(tan(self.ob.data.angle_x * 0.5) * aspect_ratio))] if self.ob.data.dof.use_dof: - # TODO - # # Aperture radius - # self.aperture_radii += [self.ob.data.psychopath.aperture_radius] + # Aperture radius. + radius = self.ob.data.lens / 2000.0 / self.ob.data.dof.aperture_fstop + self.aperture_radii += [radius] # Dof distance - if self.ob.data.dof_object == None: - self.focal_distances += [self.ob.data.dof_distance] + if self.ob.data.dof.focus_object == None: + self.focal_distances += [self.ob.data.dof.focus_distance] else: # TODO: implement DoF object tracking here self.focal_distances += [0.0]