Last active
August 29, 2015 14:17
-
-
Save nutti/a6e7bdaba172017cccb0 to your computer and use it in GitHub Desktop.
[Blender] ユーザがツールシェルフのオプションからプラグインを制御できるようにするための方法 ref: http://qiita.com/nutti/items/ea4f4b0c3cfa90c88a58
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
i = IntProperty( | |
name = "Integer", | |
description = "Integer ...", | |
default = 0, | |
min = -100, | |
max = 400) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bpy | |
import mathutils | |
from math import radians | |
from bpy.props import * | |
bl_info = { | |
"name" : "Property sample", | |
"author" : "Nutti", | |
"version" : (1, 0), | |
"blender" : (2, 7, 0), | |
"location" : "UV Mapping > Property sample", | |
"description" : "Property sample", | |
"warning" : "", | |
"wiki_url" : "", | |
"tracker_url" : "", | |
"category" : "UV" | |
} | |
class PropertySample(bpy.types.Operator): | |
"""""" | |
bl_idname = "uv.property_samle" | |
bl_label = "Property Sample" | |
bl_description = "Property Sample" | |
bl_options = {'REGISTER', 'UNDO'} | |
# ツールシェルフへ表示させる値 | |
# X軸を中心として回転させる角度(0度から360度の整数値を選択可能) | |
rot = IntProperty( | |
name = "Rotate X", # ツールシェルフに表示されるラベル名 | |
description = "Rotate X ...", # ツールシェルフに表示される説明文 | |
default = 0, # デフォルト値 | |
min = 0, # 選択可能な最小値 | |
max = 360) # 選択可能な最大値 | |
base_euler = None # 初期の角度 | |
# 初期化処理 | |
# __init__はメニューから選択されたときのみ実行される | |
# 初期状態をここで保存しておかないと回転量に不具合が生じる | |
def __init__(self): | |
active_obj = bpy.context.active_object | |
mode = active_obj.rotation_mode | |
active_obj.rotation_mode = 'QUATERNION' | |
# オブジェクトの初期状態を保存 | |
self.base_euler = active_obj.rotation_quaternion.to_euler() | |
active_obj.rotation_mode = mode | |
# 2度目以降にメニューから選択された時、 | |
# 手動でデフォルト値に設定する必要がある | |
self.rot = 0 | |
# メニューから選択した時に加え、 | |
# "ツールシェルフで値を変更した時"にも呼ばれる | |
def execute(self, context): | |
active_obj = bpy.context.active_object | |
mode = active_obj.rotation_mode | |
active_obj.rotation_mode = 'QUATERNION' | |
# 新しいオブジェクトの状態を設定 | |
new_euler = self.base_euler.copy() | |
new_euler.x = self.base_euler.x + radians(self.rot) | |
active_obj.rotation_quaternion = new_euler.to_quaternion() | |
active_obj.rotation_mode = mode | |
return {'FINISHED'} | |
# registration | |
def menu_func(self, context): | |
self.layout.operator(PropertySample.bl_idname) | |
def register(): | |
bpy.utils.register_module(__name__) | |
bpy.types.VIEW3D_MT_uv_map.append(menu_func) | |
def unregister(): | |
bpy.utils.unregister_module(__name__) | |
bpy.types.VIEW3D_MT_uv_map.remove(menu_func) | |
if __name__ == "__main__": | |
register() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ツールシェルフへ表示させる値 | |
# X軸を中心として回転させる角度(0度から360度の整数値を選択可能) | |
rot = IntProperty( | |
name = "Rotate X", # ツールシェルフに表示されるラベル名 | |
description = "Rotate X ...", # ツールシェルフに表示される説明文 | |
default = 0, # デフォルト値 | |
min = 0, # 選択可能な最小値 | |
max = 360) # 選択可能な最大値 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment