forked from bookyakuno/Blender-Scramble-Addon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPHYSICS_PT_rigid_body.py
87 lines (74 loc) · 2.55 KB
/
PHYSICS_PT_rigid_body.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
# 「プロパティ」エリア > 「物理演算」タブ > 「リジッドボディ」パネル
# "Propaties" Area > "Physics" Tab > "Rigid Body" Panel
import bpy
################
# オペレーター #
################
class CopySetting(bpy.types.Operator):
bl_idname = "rigidbody.copy_setting"
bl_label = "Copy Rigid Body Setting"
bl_description = "Copy active object's Rigid Body settings to other selected objects"
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context):
if 2 <= len(context.selected_objects):
if context.active_object:
if context.active_object.rigid_body:
return True
return False
def execute(self, context):
active_ob = context.active_object
for ob in context.selected_objects:
if ob.name == active_ob.name:
continue
if not ob.rigid_body:
bpy.ops.rigidbody.object_add({'object':ob})
for val_name in dir(ob.rigid_body):
if val_name[0] != '_' and 'rna' not in val_name:
value = active_ob.rigid_body.__getattribute__(val_name)
try:
ob.rigid_body.__setattr__(val_name, value[:])
except TypeError:
try:
ob.rigid_body.__setattr__(val_name, value)
except AttributeError:
pass
except AttributeError:
pass
return {'FINISHED'}
################
# クラスの登録 #
################
classes = [
CopySetting
]
def register():
for cls in classes:
bpy.utils.register_class(cls)
def unregister():
for cls in classes:
bpy.utils.unregister_class(cls)
################
# メニュー追加 #
################
# メニューのオン/オフの判定
def IsMenuEnable(self_id):
for id in bpy.context.preferences.addons[__name__.partition('.')[0]].preferences.disabled_menu.split(','):
if (id == self_id):
return False
else:
return True
# メニューを登録する関数
def menu(self, context):
if (IsMenuEnable(__name__.split('.')[-1])):
row = self.layout.split(factor=0.4)
row.use_property_split = False
row.operator(CopySetting.bl_idname, icon='COPY_ID', text="Copy Setting")
if context.scene.rigidbody_world:
if context.scene.rigidbody_world.point_cache:
row_item = row.row(align=True)
row_item.prop(context.scene.rigidbody_world.point_cache, 'frame_start')
row_item.prop(context.scene.rigidbody_world.point_cache, 'frame_end')
row_item.operator('rigidbody.sync_frames', icon='LINKED', text="")# SCENE_PT_rigid_body_world.py で定義
if (context.preferences.addons[__name__.partition('.')[0]].preferences.use_disabled_menu):
self.layout.operator('wm.toggle_menu_enable', icon='CANCEL').id = __name__.split('.')[-1]