forked from bookyakuno/Blender-Scramble-Addon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSCENE_PT_rigid_body_world.py
128 lines (109 loc) · 4.4 KB
/
SCENE_PT_rigid_body_world.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
# 「プロパティ」エリア > 「シーン」タブ > 「リジッドボディワールド」パネル
# "Propaties" Area > "Scene" Tab > "Rigid Body World" Panel
import bpy
from bpy.props import *
################
# オペレーター #
################
class WorldReset(bpy.types.Operator):
bl_idname = "rigidbody.world_reset"
bl_label = "Re-create Rigid Body World"
bl_description = "Re-create rigid body world with same settings"
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context):
if (not context.scene.rigidbody_world):
return False
return context.scene.rigidbody_world.enabled
def execute(self, context):
collection = context.scene.rigidbody_world.collection
constraints = context.scene.rigidbody_world.constraints
time_scale = context.scene.rigidbody_world.time_scale
steps_per_second = context.scene.rigidbody_world.steps_per_second
use_split_impulse = context.scene.rigidbody_world.use_split_impulse
solver_iterations = context.scene.rigidbody_world.solver_iterations
frame_start = context.scene.rigidbody_world.point_cache.frame_start
frame_end = context.scene.rigidbody_world.point_cache.frame_end
bpy.ops.rigidbody.world_remove()
bpy.ops.rigidbody.world_add()
context.scene.rigidbody_world.collection = collection
context.scene.rigidbody_world.constraints = constraints
context.scene.rigidbody_world.time_scale = time_scale
context.scene.rigidbody_world.steps_per_second = steps_per_second
context.scene.rigidbody_world.use_split_impulse = use_split_impulse
context.scene.rigidbody_world.solver_iterations = solver_iterations
context.scene.rigidbody_world.point_cache.frame_start = frame_start
context.scene.rigidbody_world.point_cache.frame_end = frame_end
return {'FINISHED'}
class SyncFrames(bpy.types.Operator):
bl_idname = "rigidbody.sync_frames"
bl_label = "Match Rigid Body World's Start/End to Rendering's ones"
bl_description = "Change rigid body world's start / end frames to the rendering's start / end frames"
bl_options = {'REGISTER', 'UNDO'}
startOffset : IntProperty(name="Start Offset", default=0, step=1)
endOffset : IntProperty(name="End Offset", default=0, step=1)
@classmethod
def poll(cls, context):
if context.scene.rigidbody_world:
if context.scene.rigidbody_world.point_cache:
return True
return False
def invoke(self, context, event):
return context.window_manager.invoke_props_dialog(self, width=310)
def draw(self, context):
box = self.layout.box()
sp = box.split(factor=0.55)
row = sp.row()
row.label(text="Start Frame")
row.label(text=f": {context.scene.frame_start} + {self.startOffset}")
sp.prop(self, 'startOffset')
sp = box.split(factor=0.55)
row = sp.row()
row.label(text="End Frame")
row.label(text=f": {context.scene.frame_end} + {self.endOffset}")
sp.prop(self, 'endOffset')
def execute(self, context):
rigidbody_world = context.scene.rigidbody_world
point_cache = rigidbody_world.point_cache
point_cache.frame_start = context.scene.frame_start + self.startOffset
point_cache.frame_end = context.scene.frame_end + self.endOffset
for area in context.screen.areas:
area.tag_redraw()
return {'FINISHED'}
################
# クラスの登録 #
################
classes = [
WorldReset,
SyncFrames
]
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(WorldReset.bl_idname, icon='PLUGIN', text="Re-create")
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(SyncFrames.bl_idname, icon='LINKED', text="")
if (context.preferences.addons[__name__.partition('.')[0]].preferences.use_disabled_menu):
self.layout.operator('wm.toggle_menu_enable', icon='CANCEL').id = __name__.split('.')[-1]