1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Blenderでアオリ補正カメラを作成する

Last updated at Posted at 2021-09-19

通常の3Dソフトでカメラを上下に回転させた場合
オブジェクトの縦方向のエッジが奥方向が細くなって表示されます。
一部の建築系に利用されるソフトでは強制的にこのラインを垂直に揃える機能がありますが
Blenderでは直観的にこれを行う機能は搭載されていません

カメラのシフト機能を利用して 同等の効果のカメラを作成するスクリプトを作成してみました
image.png
左が通常のシーンで利用しているカメラの像
右は今回のスクリプトで作成したカメラで ビューのローカルカメラに設定して表示しています

カメラを水平に表示している状態で シフト機能で方向を調整することで縦方向を垂直にできています。

TiltCorrection.py
import bpy
import math
scene = bpy.context.scene
camera = scene.camera
render = scene.render
# 現在のシーンのカメラから値を計算
rotate_x = camera.rotation_euler.x -math.pi/2
aspect = render.resolution_y /max(render.resolution_x, render.resolution_y)
angle_y = camera.data.angle *aspect/math.cos(rotate_x)
y_ratio =  0.5*math.tan(rotate_x)/math.tan(angle_y/2)
# アオリ補正したカメラを作成
copy_data = camera.data.copy()
shift_cam = bpy.data.objects.new('shift_cam', copy_data)
scene.collection.objects.link(shift_cam)
shift_cam.location = camera.location
shift_cam.rotation_euler.order = 'XYZ'
shift_cam.rotation_euler.x = math.pi/2 # カメラを水平に
shift_cam.data.angle = camera.data.angle /math.cos(rotate_x)
shift_cam.data.shift_y = y_ratio

シーンで現在利用しているカメラのデータを元にアオリ補正カメラを作成します。
なお、Blenderの機能の都合上 レンダリング画像のアスペクト比を変更すると再度スクリプトでカメラを作り直す必要があります

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?