Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Keystone Correction and post projection scale factor #1

Merged
merged 6 commits into from
Sep 10, 2023
21 changes: 17 additions & 4 deletions projector.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,11 @@ def update_throw_ratio(proj_settings, context):
nodes['Mapping.001'].inputs[3].default_value[1] = 1 / \
throw_ratio * inverted_aspect_ratio

# Update lens shift because it depends on the throw ratio.
update_lens_shift(proj_settings, context)




def update_lens_shift(proj_settings, context):
"""
Expand All @@ -296,20 +301,23 @@ def update_lens_shift(proj_settings, context):
v_shift = proj_settings.get('v_shift', 0.0) / 100
throw_ratio = proj_settings.get('throw_ratio')

w, h = get_resolution(proj_settings, context)
inverted_aspect_ratio = h/w

# Update the properties of the camera.
cam = projector
cam.data.shift_x = h_shift
cam.data.shift_y = v_shift
cam.data.shift_y = v_shift * inverted_aspect_ratio

# Update spotlight node setup.
spot = projector.children[0]
nodes = spot.data.node_tree.nodes['Group'].node_tree.nodes
if bpy.app.version < (2, 81):
nodes['Mapping.001'].translation[0] = h_shift / throw_ratio
nodes['Mapping.001'].translation[1] = v_shift / throw_ratio
nodes['Mapping.001'].translation[1] = v_shift / throw_ratio * inverted_aspect_ratio
else:
nodes['Mapping.001'].inputs[1].default_value[0] = h_shift / throw_ratio
nodes['Mapping.001'].inputs[1].default_value[1] = v_shift / throw_ratio
nodes['Mapping.001'].inputs[1].default_value[1] = v_shift / throw_ratio * inverted_aspect_ratio


def update_resolution(proj_settings, context):
Expand Down Expand Up @@ -514,11 +522,15 @@ def init_projector(proj_settings, context):


class PROJECTOR_OT_create_projector(Operator):
""" Create Projector """
"""Create Projector"""
bl_idname = 'projector.create'
bl_label = 'Create a new Projector'
bl_options = {'REGISTER', 'UNDO'}

@classmethod
def poll(cls, context):
return context.mode == 'OBJECT'

def execute(self, context):
projector = create_projector(context)
init_projector(projector.proj_settings, context)
Expand Down Expand Up @@ -552,6 +564,7 @@ def update_projected_texture(proj_settings, context):


class PROJECTOR_OT_delete_projector(Operator):
"""Delete Projector"""
bl_idname = 'projector.delete'
bl_label = 'Delete Projector'
bl_options = {'REGISTER', 'UNDO'}
Expand Down