Motion transfer setup #1

Manually merged
Sybren A. Stüvel merged 18 commits from cgtinker/powership:motion_transfer into main 2023-06-05 12:06:15 +02:00
Showing only changes of commit b4b939c280 - Show all commits

View File

@ -1,14 +1,14 @@
# SPDX-License-Identifier: GPL-2.0-or-later # SPDX-License-Identifier: GPL-2.0-or-later
import bpy
from . import nodes
is_first_load = "nodes" not in locals() is_first_load = "nodes" not in locals()
from . import nodes
cgtinker marked this conversation as resolved Outdated

Please keep this block as-is. These changes will break the reloading mechanism.

Please keep this block as-is. These changes will break the reloading mechanism.

Please keep this block as-is. These changes will break the reloading mechanism.

Please keep this block as-is. These changes will break the reloading mechanism.

That's why it hasn't been updating!
My lsp destroyed the formatting a bit, doing my best to fix it – pylance has been fighting against mypy and no-one has been the winner I guess. Pep8 came to the rescue and yea well, here we are :)

What kind of formatter are you using? (probably will add a few more nodes in the future if you don't mind)

That's why it hasn't been updating! My lsp destroyed the formatting a bit, doing my best to fix it – pylance has been fighting against mypy and no-one has been the winner I guess. Pep8 came to the rescue and yea well, here we are :) What kind of formatter are you using? (probably will add a few more nodes in the future if you don't mind)
if not is_first_load: if not is_first_load:
import sys import sys
nodes = sys.modules[nodes.__name__] nodes = sys.modules[nodes.__name__]
import bpy
_skip_next_autorun = False _skip_next_autorun = False
@ -50,6 +50,7 @@ def execute_tree(
# The running of this tree will trigger another depsgraph update, which # The running of this tree will trigger another depsgraph update, which
# should not trigger yet another execution. # should not trigger yet another execution.
global _skip_next_autorun global _skip_next_autorun
try: try:
cgtinker marked this conversation as resolved Outdated

Please don’t include formatting changes like this. Formatting changes shouldn’t be in the same PR as functional changes.

Please don’t include formatting changes like this. Formatting changes shouldn’t be in the same PR as functional changes.
tree.run_event(depsgraph, mode) tree.run_event(depsgraph, mode)
except Exception: except Exception:
@ -66,10 +67,28 @@ def _on_depsgraph_update_post(
scene: bpy.types.Scene, depsgraph: bpy.types.Depsgraph scene: bpy.types.Scene, depsgraph: bpy.types.Depsgraph
) -> None: ) -> None:
global _skip_next_autorun global _skip_next_autorun
if _skip_next_autorun: if _skip_next_autorun:
_skip_next_autorun = False _skip_next_autorun = False
return return
run_node_tree(scene, depsgraph)
@bpy.app.handlers.persistent # type: ignore
def _on_frame_changed_post(
scene: bpy.types.Scene, depsgraph: bpy.types.Depsgraph
) -> None:
global _skip_next_autorun
if not _skip_next_autorun:
_skip_next_autorun = True
cgtinker marked this conversation as resolved

Since _skip_next_autorun is a boolean, the if condition can be removed.

Since `_skip_next_autorun` is a boolean, the `if` condition can be removed.
run_node_tree(scene, depsgraph)
def run_node_tree(
scene: bpy.types.Scene, depsgraph: bpy.types.Depsgraph
) -> None:
for tree in bpy.data.node_groups: for tree in bpy.data.node_groups:
if tree.bl_idname != "PowerShipNodeTree": if tree.bl_idname != "PowerShipNodeTree":
continue continue
@ -97,34 +116,6 @@ def _choose_auto_mode(context: bpy.types.Context) -> str:
return "FORWARD" return "FORWARD"
@bpy.app.handlers.persistent # type: ignore
def _on_frame_changed_post(
scene: bpy.types.Scene, depsgraph: bpy.types.Depsgraph
) -> None:
global _skip_next_autorun
if _skip_next_autorun:
_skip_next_autorun = True
# updating on frame change to allow
# keyframed animation influencing the rig
for tree in bpy.data.node_groups:
if tree.bl_idname != "PowerShipNodeTree":
continue
if not tree.autorun:
return
powership_mode = scene.powership_mode
if powership_mode == "AUTO":
if bpy.context.object and bpy.context.object.mode == "POSE":
powership_mode = "BACKWARD"
else:
powership_mode = "FORWARD"
execute_tree(tree, depsgraph, powership_mode)
classes = ( classes = (
# Operators: # Operators:
PowerShip_OT_execute_tree, PowerShip_OT_execute_tree,