Motion transfer setup #1
51
execute.py
51
execute.py
@ -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
|
||||||
|
|
||||||
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:
|
||||||
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
|
|||||||
|
|
||||||
|
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,
|
||||||
|
Loading…
Reference in New Issue
Block a user
Since
_skip_next_autorun
is a boolean, theif
condition can be removed.