Motion transfer setup #1
51
execute.py
51
execute.py
@ -1,14 +1,14 @@
|
||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
import bpy
|
||||
from . import nodes
|
||||
is_first_load = "nodes" not in locals()
|
||||
from . import nodes
|
||||
|
||||
cgtinker marked this conversation as resolved
Outdated
|
||||
if not is_first_load:
|
||||
import sys
|
||||
|
||||
nodes = sys.modules[nodes.__name__]
|
||||
|
||||
import bpy
|
||||
|
||||
_skip_next_autorun = False
|
||||
|
||||
@ -50,6 +50,7 @@ def execute_tree(
|
||||
# The running of this tree will trigger another depsgraph update, which
|
||||
# should not trigger yet another execution.
|
||||
global _skip_next_autorun
|
||||
|
||||
try:
|
||||
cgtinker marked this conversation as resolved
Outdated
Sybren A. Stüvel
commented
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)
|
||||
except Exception:
|
||||
@ -66,10 +67,28 @@ def _on_depsgraph_update_post(
|
||||
scene: bpy.types.Scene, depsgraph: bpy.types.Depsgraph
|
||||
) -> None:
|
||||
global _skip_next_autorun
|
||||
|
||||
if _skip_next_autorun:
|
||||
_skip_next_autorun = False
|
||||
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
Sybren A. Stüvel
commented
Since 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:
|
||||
if tree.bl_idname != "PowerShipNodeTree":
|
||||
continue
|
||||
@ -97,34 +116,6 @@ def _choose_auto_mode(context: bpy.types.Context) -> str:
|
||||
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 = (
|
||||
# Operators:
|
||||
PowerShip_OT_execute_tree,
|
||||
|
Loading…
Reference in New Issue
Block a user
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)