Skip to content

Commit

Permalink
Issue #10 fix
Browse files Browse the repository at this point in the history
Add GUI support for DOF
  • Loading branch information
JerryCao1985 authored and JiayinCao committed May 24, 2019
1 parent b8f9221 commit c74ef30
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 12 deletions.
22 changes: 12 additions & 10 deletions sortblend/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,18 @@ def lookAt(camera):
matrix = ori_matrix.transposed()
pos = matrix[3] # get eye position
forwards = -matrix[2] # get forward direction
forwards[3] = 0.0
target = (pos + forwards) # get target
up = matrix[1] # get up direction

#matrix = ori_matrix.transposed()
#pos = matrix[3] # get eye position
#forwards = -ori_matrix[2] # get forward direction
#forwards[3] = 0.0
#target = (pos + forwards) # get target
#up = ori_matrix[1] # get up direction
# get focal distance for DOF effect
if camera.data.dof_object is not None:
focal_object = camera.data.dof_object
fo_mat = utility.getGlobalMatrix() * focal_object.matrix_world
delta = fo_mat.to_translation() - pos.to_3d()
focal_distance = delta.dot(forwards)
else:
focal_distance = max( camera.data.dof_distance , 0.01 )
scaled_forward = mathutils.Vector((focal_distance * forwards[0], focal_distance * forwards[1], focal_distance * forwards[2] , 0.0))
target = (pos + scaled_forward) # get target
up = matrix[1] # get up direction
return (pos, target, up)

# open sort file
Expand Down Expand Up @@ -84,7 +86,7 @@ def export_sort_file(scene, force_debug):
ET.SubElement( camera_node , "Property" , name="eye" , value=utility.vec3tostr(pos))
ET.SubElement( camera_node , "Property" , name="up" , value=utility.vec3tostr(up))
ET.SubElement( camera_node , "Property" , name="target" , value=utility.vec3tostr(target))
ET.SubElement( camera_node , "Property" , name="len" , value="0")
ET.SubElement( camera_node , "Property" , name="len" , value='%f'%camera.data.sort_camera.sort_camera_lens.lens_size)
ET.SubElement( camera_node , "Property" , name="interaxial" , value="0")
ET.SubElement( camera_node , "Property" , name="width" , value="0")
ET.SubElement( camera_node , "Property" , name="height" , value="0")
Expand Down
59 changes: 59 additions & 0 deletions sortblend/ui/ui_camera.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import bpy
import bl_ui
from .. import common
from .. import SORTAddon
from extensions_framework import declarative_property_group

# attach customized properties in lamp
@SORTAddon.addon_register_class
class sort_camera(declarative_property_group):
ef_attach_to = ['Camera']

controls = []
visibility = {}
properties = []

@SORTAddon.addon_register_class
class sort_camera_lens(declarative_property_group):
ef_attach_to = ['sort_camera']

controls = []

properties = [
{
'type': 'float',
'attr': 'lens_size',
'name': 'Size of Camera Lens',
'description': 'The size of lens in camera',
'default': 1.0,
'min': 1e-3,
'soft_min': 1e-3,
'max': 1e3,
'soft_max': 1e3,
'save_in_preset': True
},
]

class SORTCameraPanel(bl_ui.properties_data_camera.CameraButtonsPanel):
bl_space_type = "PROPERTIES"
bl_region_type = "WINDOW"
bl_context = "data"
COMPAT_ENGINES = {common.default_bl_name}

@classmethod
def poll(cls, context):
rd = context.scene.render
return super().poll(context) and rd.engine in cls.COMPAT_ENGINES

class CameraDOFPanel(SORTCameraPanel, bpy.types.Panel):
bl_label = 'Camera Depth of Field'

def draw(self, context):
layout = self.layout
camera = context.camera
layout.prop(camera, "dof_object")
row = layout.row()
row.active = ( camera.dof_object == None )
row.prop(camera, "dof_distance")
layout.prop(camera.sort_camera.sort_camera_lens, "lens_size")
pass
1 change: 0 additions & 1 deletion sortblend/ui/ui_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ def get_panels():
types = bpy.types
panels = [
"DATA_PT_lens",
"DATA_PT_camera_dof",
"DATA_PT_camera",
"RENDER_PT_dimensions",
]
Expand Down
2 changes: 1 addition & 1 deletion sortblend/ui/ui_lamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class SORTLampPanel(bl_ui.properties_data_lamp.DataButtonsPanel):
@classmethod
def poll(cls, context):
rd = context.scene.render
return rd.engine in cls.COMPAT_ENGINES
return super().poll(context) and rd.engine in cls.COMPAT_ENGINES

class LampPanel(SORTLampPanel, bpy.types.Panel):
bl_label = 'Lamp Property'
Expand Down

0 comments on commit c74ef30

Please sign in to comment.