Skip to content

Commit 1eb827b

Browse files
author
BASSET Jean
committed
fixed issues #7 and #8, added unbake button, fixed python crash when baking on non animated object
1 parent ddae4ce commit 1eb827b

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

blender_manifest.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
schema_version = "1.0.0"
22

33
id = "SMEAR"
4-
version = "1.1.6"
4+
version = "1.1.7"
55
name = "SMEAR"
66
tagline = "Create smear frames for 3D animations"
77
maintainer = "Jean Basset <jean.basset@inria.fr>"

smear_control_panel.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ def draw(self,context):
6969
if bpy.context.scene.camera != None:
7070
col.prop(scene.smear,"cameraPOV")
7171

72+
col.operator(UnbakeSmearOperator.bl_idname)
73+
7274
col.operator(BakeDeltasTrajectoriesOperator.bl_idname)
7375

7476
class EffectControlPanel(Panel,bpy.types.Panel):
@@ -178,6 +180,30 @@ def clear_attributes(obj):
178180
for name in to_remove:
179181
obj.data.attributes.remove(obj.data.attributes[name])
180182

183+
class UnbakeSmearOperator(bpy.types.Operator):
184+
bl_idname = "scene.unbake_smear"
185+
bl_label = "Unbake Smears"
186+
187+
def execute(self,context):
188+
obj = bpy.context.active_object
189+
190+
# unlink node network
191+
if "Smear Control Panel" in obj.modifiers:
192+
obj.modifiers.remove(obj.modifiers.get("Smear Control Panel"))
193+
194+
# remove all "delta_X" attributes
195+
att_names = [att.name for att in obj.data.attributes]
196+
for att_name in att_names:
197+
if att_name.startswith("delta_"):
198+
att = obj.data.attributes[att_name]
199+
obj.data.attributes.remove(att)
200+
201+
# delete aggregated animation
202+
if f"aggregated_animation_{obj.name}" in bpy.data.objects:
203+
bpy.data.objects.remove(bpy.data.objects[f"aggregated_animation_{obj.name}"])
204+
205+
return {"FINISHED"}
206+
181207
class BakeDeltasTrajectoriesOperator(bpy.types.Operator):
182208
bl_idname = "scene.bake_deltas_and_trajectories"
183209
bl_label = "Bake Smears"
@@ -226,6 +252,9 @@ def execute(self,context):
226252
if len(keyframe_frames) > 0:
227253
frame_start = keyframe_frames[0]
228254
frame_end = keyframe_frames[-1]
255+
else:
256+
print("No animation found")
257+
return {"FINISHED"}
229258

230259
if bpy.context.scene.camera != None:
231260
keyframe_frames = get_keyframe_frames(bpy.context.scene.camera)
@@ -245,7 +274,8 @@ def execute(self,context):
245274
for frame in animation_deltas:
246275
dname = f"delta_{frame}"
247276
obj.data.attributes.new(name=dname,type="FLOAT",domain="POINT")
248-
obj.data.attributes[dname].data.foreach_set("value",animation_deltas[frame])
277+
for i in range(len(animation_deltas[frame])):
278+
setattr(obj.data.attributes[dname].data[i],"value",animation_deltas[frame][i])
249279

250280

251281
pos_aggregated = np.concatenate([positions[frame] for frame in positions])
@@ -327,6 +357,9 @@ def set_node_tree(obj,frame_start,frame_end,cameraPOV):
327357
camera_identifier = mod.node_group.interface.items_tree["Camera"].identifier
328358
mod[camera_identifier] = bpy.context.scene.camera
329359

360+
manual_weights_group_identifier = mod.node_group.interface.items_tree["Manual Weights Group"].identifier
361+
bpy.ops.object.geometry_nodes_input_attribute_toggle(input_name = manual_weights_group_identifier, modifier_name = "Smear Control Panel")
362+
330363
class SmearPropertyGroup(bpy.types.PropertyGroup):
331364
fullBody: bpy.props.BoolProperty(name="Ignore Skeleton",default=False)
332365
discardedBone: bpy.props.StringProperty(name="Bones",search=get_bone_names)
@@ -339,6 +372,7 @@ def register():
339372

340373
bpy.utils.register_class(SmearControlPanel)
341374
bpy.utils.register_class(BakeDeltasTrajectoriesOperator)
375+
bpy.utils.register_class(UnbakeSmearOperator)
342376

343377
bpy.utils.register_class(ElongatedInbetweensControlPanel)
344378
bpy.utils.register_class(MotionLinesControlPanel)
@@ -350,6 +384,7 @@ def unregister():
350384

351385
bpy.utils.unregister_class(SmearControlPanel)
352386
bpy.utils.unregister_class(BakeDeltasTrajectoriesOperator)
387+
bpy.utils.unregister_class(UnbakeSmearOperator)
353388

354389
bpy.utils.unregister_class(ElongatedInbetweensControlPanel)
355390
bpy.utils.unregister_class(MotionLinesControlPanel)

utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ def get_anim_vertices_and_joints(obj,frame_start,frame_end,bones_to_discard,came
159159
for mod_name in mods_to_remove:
160160
obj_copy.modifiers.remove(obj_copy.modifiers[mod_name])
161161

162-
col = obj.users_collection[0]
162+
col = bpy.data.collections.new("SMEAR_TEMP_COLLECTION")
163+
bpy.context.scene.collection.children.link(col)
163164
col.objects.link(obj_copy)
164165

165166
wm = bpy.context.window_manager
@@ -220,13 +221,15 @@ def get_anim_vertices_and_joints(obj,frame_start,frame_end,bones_to_discard,came
220221

221222
objs = bpy.data.objects
222223
objs.remove(objs[obj_copy.name],do_unlink=True)
224+
bpy.data.collections.remove(col, do_unlink=True)
223225

224226
raise error
225227

226228
wm.progress_end()
227229

228230
objs = bpy.data.objects
229231
objs.remove(objs[obj_copy.name],do_unlink=True)
232+
bpy.data.collections.remove(col, do_unlink=True)
230233

231234
return anim_vertices, anim_joints
232235

0 commit comments

Comments
 (0)