forked from Project-StudioQ/camera_extends
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoverScan.py
243 lines (201 loc) · 9.12 KB
/
overScan.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
import bpy
# -----------------------------------------------------------------------------
class QANIM_OT_overscan_reset(bpy.types.Operator):
bl_label = "reset_overScan"
bl_idname = "qanim.overscan_reset"
bl_description = ""
bl_options = {'REGISTER', 'UNDO'} # undo効くようにする設定
def resetOverScan(self, context):
''' オーバースキャンで設定したパラメータをリセット
'''
camera_object = context.active_object
camera = camera_object.data
bpy.context.scene.render.resolution_x = camera.oriResX
bpy.context.scene.render.resolution_y = camera.oriResY
camera.shift_x = camera.overscan_original_shift_x
camera.shift_y = camera.overscan_original_shift_y
camera.sensor_width = camera.sensorWidth
camera_object.delta_rotation_euler.x = 0
camera_object.delta_rotation_euler.z = 0
del camera["oriResX"]
del camera["oriResY"]
del camera["sensorWidth"]
bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1)
def execute(self, context):
''' メイン処理
'''
camera_object = context.active_object
camera = camera_object.data
if hasattr(camera, "oriResX") is False: # 初回起動時はこちらでオーバースキャン実行
self.resetOverScan( context )
elif camera.oriResX > 0: # 2回目以降はこちら
self.resetOverScan( context )
return{'FINISHED'}
class QANIM_OT_overscan_run(bpy.types.Operator):
bl_label = "run_overScan"
bl_idname = "qanim.overscan_run"
bl_description = ""
bl_options = {'REGISTER', 'UNDO'} # undo効くようにする設定
def overScan(self, context):
''' オーバースキャン設定
'''
camera_object = context.active_object
camera = camera_object.data
pivot = camera.pivot_prop_enum
scaleRatioX = camera.magnification_prop_FloatX
scaleRatioY = camera.magnification_prop_FloatY
# 解像度変更
curResX = bpy.context.scene.render.resolution_x
curResY = bpy.context.scene.render.resolution_y
if camera.pixOrPer_prop_enum == 'percent':
bpy.context.scene.render.resolution_x = curResX * scaleRatioX
bpy.context.scene.render.resolution_y = curResY * scaleRatioY
elif camera.pixOrPer_prop_enum == 'pixcel':
bpy.context.scene.render.resolution_x = camera.magnification_prop_IntX
bpy.context.scene.render.resolution_y = camera.magnification_prop_IntY
resResult = bpy.context.scene.render.resolution_y / bpy.context.scene.render.resolution_x
# センサーフィットが自動だったら水平に変換しセンサーの初期値確定
curSensor = camera.sensor_width
if camera.sensor_fit == 'AUTO':
camera.sensor_fit = 'HORIZONTAL'
if curResY > curResX:
camera.sensor_width = (curResY / curResX * curSensor) / 2
# 元のカメラ設定・解像度をカスタムプロパティに格納
bpy.types.Camera.oriResX = bpy.props.IntProperty(name="oriResX")
bpy.types.Camera.oriResY = bpy.props.IntProperty(name="oriResY")
bpy.types.Camera.sensorWidth = bpy.props.IntProperty(name="sensor_width")
camera.oriResX = curResX
camera.oriResY = curResY
camera.sensorWidth = camera.sensor_width
# センサーサイズ変更によるオーバースキャン
sensorWidth = camera.sensor_width
if camera.pixOrPer_prop_enum == 'percent':
camera.sensor_width = sensorWidth * scaleRatioX
elif camera.pixOrPer_prop_enum == 'pixcel':
camera.sensor_width = sensorWidth * (camera.magnification_prop_IntX / camera.oriResX)
# オーバースキャン基点設定
if pivot[0] == 'U':
LRPivot = 1
elif pivot[0] == 'D':
LRPivot = -1
elif pivot[0] == 'M':
LRPivot = 0
if pivot[1] == 'L':
UDPivot = -1
elif pivot[1] == 'R':
UDPivot = 1
elif pivot[1] == 'M':
UDPivot = 0
if camera.pixOrPer_prop_enum == 'pixcel':
scaleRatioX = camera.magnification_prop_IntX / camera.oriResX
scaleRatioY = camera.magnification_prop_IntY / camera.oriResY
camera.overscan_original_shift_x = camera.shift_x
camera.overscan_original_shift_y = camera.shift_y
camera.shift_x = camera.overscan_original_shift_x + (scaleRatioX - 1) / scaleRatioX / 2 * LRPivot
camera.shift_y = camera.overscan_original_shift_y + (scaleRatioY - 1) / scaleRatioY / 2 * resResult * UDPivot
camera.temp_camera_overscan_force_apply = False
def execute(self, context):
''' メイン処理
'''
camera_object = context.active_object
camera = camera_object.data
# オーバースキャン実行
if 'CAMERA' == camera_object.type:
if hasattr(camera, "oriResX") is False: # 初回起動時はこちらでオーバースキャン実行
self.overScan( context )
elif camera.oriResX == 0: # 2回目以降はこちら
self.overScan( context )
elif camera.temp_camera_overscan_force_apply: # 多重かけ防止だが、強制的にONにする
self.overScan( context )
return{'FINISHED'}
# -----------------------------------------------------------------------------
def _initialized():
''' プロパティの初期化
'''
scene = bpy.types.Camera
# scene = bpy.types.Scene
# 比を固定して変更するようにするか
scene.temp_ratio_interlocked = bpy.props.BoolProperty(
name='temp_ratio_interlocked',
description='lock/unlock screen/pixel ratio',
default=True,
)
# 更新中に追加更新しないように(無限ループになる)
scene.temp_updating_locked = bpy.props.BoolProperty(
name='temp_updating_locked',
description='block infinity loop for update value',
default=False,
)
scene.temp_camera_overscan_force_apply = bpy.props.BoolProperty(
name='Force applies overscan',
description='Force applies overscan',
default=False,
)
# オーバースキャン比率プロパティ
scene.magnification_prop_FloatX = bpy.props.FloatProperty(precision=1, default=1.2, step=10.0, update=_update_magnification_prop_FloatX)
scene.magnification_prop_FloatY = bpy.props.FloatProperty(precision=1, default=1.2, step=10.0, update=_update_magnification_prop_FloatY)
# オーバースキャン後解像度プロパティ
scene.magnification_prop_IntX = bpy.props.IntProperty(default=2304)
scene.magnification_prop_IntY = bpy.props.IntProperty(default=1296)
# オリジナルシフト値を保存
scene.overscan_original_shift_x = bpy.props.FloatProperty(name="Original Camera Shift X")
scene.overscan_original_shift_y = bpy.props.FloatProperty(name="Original Camera Shift Y")
# オーバースキャン比率か解像度のいずれをえらぶかのプロパティ
scene.pixOrPer_prop_enum = bpy.props.EnumProperty(
name='pixOrPer',
description='select method',
items=[
('percent', 'percent', 'percent'),
('pixcel', 'pixcel', 'pixcel'),
],
default='percent'
)
# オーバースキャンpivot
scene.pivot_prop_enum = bpy.props.EnumProperty(
name='pivot',
description='overscan pivot',
items=[
('UL', '', 'up_left'),
('UM', '', 'up_mid'),
('UR', '', 'up_right'),
('ML', '', 'mid_left'),
('MM', '', 'mid_mid'),
('MR', '', 'mid_right'),
('DL', '', 'down_left'),
('DM', '', 'down_mid'),
('DR', '', 'down_right'),
],
default='MM'
)
def _deinitialized( ):
"""
後始末
"""
scene = bpy.types.Camera
del scene.pixOrPer_prop_enum
del scene.pivot_prop_enum
del scene.temp_ratio_interlocked
del scene.temp_updating_locked
del scene.temp_camera_overscan_force_apply
del scene.magnification_prop_FloatX
del scene.magnification_prop_FloatY
del scene.magnification_prop_IntX
del scene.magnification_prop_IntY
del scene.overscan_original_shift_x
del scene.overscan_original_shift_y
def _update_magnification_prop_FloatX( self, context ):
scene = context.active_object.data
if scene.temp_updating_locked:
return
scene.temp_updating_locked = True
if scene.temp_ratio_interlocked:
scene.magnification_prop_FloatY = scene.magnification_prop_FloatX
scene.temp_updating_locked = False
def _update_magnification_prop_FloatY( self, context ):
scene = context.active_object.data
if scene.temp_updating_locked:
return
scene.temp_updating_locked = True
if scene.temp_ratio_interlocked:
scene.magnification_prop_FloatX = scene.magnification_prop_FloatY
scene.temp_updating_locked = False