1
0

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のビューポート配置のメモ

Posted at

Blenderのアドオンを書いていても
ビューポート上の配置の情報にアクセスすることはほとんどないのだけれど、
ごくまれに調べる必要があって、その度に調べ直したりしていたのでこの機会にメモしておきます
ほぼ自分用メモなので間違っていてもご勘弁を

image.png

例えば Scriptthingのワークスペースでは3Dビューのある部分は

bpy.context.screen.areas[5]

で取得できる areaが個々のエディタのことで
「現在実行中のウインドウの5番目のエディッタが表示されてる領域」といった感じの意味
Scriptingのワークスペースでは0がプロパティ 4がテキストエディタ
といった感じに作成時の順序になるので .type等で調べてみるまで分からない
area の持つ属性は

>>> dir(bpy.context.screen.areas[5])
['__doc__', '__module__', '__slots__', 'bl_rna', 'header_text_set', 'height', 'regions', 
 'rna_type', 'show_menus', 'spaces', 'tag_redraw', 'type', 'ui_type', 'width', 'x', 'y']

このうち spacesはareaで切り替えて表示したエディッタで spaces[0]が現在表示しているエディタ
そしてアドオンでパネル等にUIを登録した場合クラスのcontext で取得されるのはこの下にある情報の様子で
アドオンのテスト段階でビューの状態に関わるものを試したい場合、これを取得することで挙動を試すことができる

x,yはウインドウ左下基準のareaの位置 width,height はそのままareaの幅と高さ
regionsがarea内の個々のUIの領域(ヘッダやメニュー、ツール等)を表す
このうちサイドバー(図中areas[5].regions[3])のtypeは'UI'となっていて他と命名が違う

それぞれのregionもx,y width,heightを取得できるので(x,yはウインドウ全体の左下基準)
ウインドウの中のどの範囲に必要な情報が表示されているかを取得することは可能

ビューポートの情報の取得例:

space = bpy.context.screen.areas[5].spaces[0]
space.region_3d.is_perspective #パース表示かどうか
space.region_3d.view_location #ビューの中心位置
space.region_3d.view_distance#(距離)
1
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?