forked from JacquesLucke/animation_nodes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmn_execution.py
120 lines (93 loc) · 2.99 KB
/
mn_execution.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
import bpy, time
from bpy.app.handlers import persistent
from animation_nodes.mn_utils import *
from animation_nodes.mn_cache import clearExecutionCache
from animation_nodes.mn_execution_unit_generator import getExecutionUnits
from bpy.props import *
from animation_nodes.utils.mn_selection_utils import *
from animation_nodes.utils.mn_node_utils import *
COMPILE_BLOCKER = 0
executionUnits = []
def updateAnimationTrees(event = "NONE", sender = None):
if COMPILE_BLOCKER == 0:
forbidCompiling()
start = time.clock()
secureExecution(event, sender)
clearExecutionCache()
timeSpan = time.clock() - start
if bpy.context.scene.mn_settings.developer.printUpdateTime:
printTimeSpan("Update Time ", timeSpan)
try:
bpy.context.scene.update()
if bpy.context.scene.mn_settings.update.redrawViewport:
redraw_areas_if_possible()
except: pass
allowCompiling()
def secureExecution(event, sender):
try: executeUnits(event, sender)
except:
resetCompileBlocker()
generateExecutionUnits()
forbidCompiling()
try: executeUnits(event, sender)
except Exception as e: print(e)
def executeUnits(event, sender):
for executionUnit in executionUnits:
executionUnit.execute(event, sender)
def allowCompiling():
global COMPILE_BLOCKER
COMPILE_BLOCKER = max(COMPILE_BLOCKER - 1, 0)
def forbidCompiling():
global COMPILE_BLOCKER
COMPILE_BLOCKER += 1
def resetCompileBlocker():
global COMPILE_BLOCKER
COMPILE_BLOCKER = 0
# generate Scripts
################################
def generateExecutionUnits():
global executionUnits
if COMPILE_BLOCKER == 0:
forbidCompiling()
start = time.clock()
executionUnits = getExecutionUnits()
timeSpan = time.clock() - start
if bpy.context.scene.mn_settings.developer.printGenerationTime:
print("Script Gen. " + str(round(timeSpan, 7)) + " s - " + str(round(1/timeSpan, 5)) + " fps")
allowCompiling()
def getCodeStrings():
codeStrings = []
for executionUnit in executionUnits:
codeStrings.append(executionUnit.executionCode)
return codeStrings
# handlers to start the update
##############################
@persistent
def frameChangeHandler(scene):
updateAnimationTrees("FRAME")
@persistent
def sceneUpdateHandler(scene):
updateSelectionSorting()
updateAnimationTrees("SCENE")
@persistent
def fileLoadHandler(scene):
generateExecutionUnits()
def nodePropertyChanged(self, context):
updateAnimationTrees("PROPERTY")
def settingPropertyChanged(self, context):
generateExecutionUnits()
updateAnimationTrees("PROPERTY")
def nodeTreeChanged(self = None, context = None):
generateExecutionUnits()
updateAnimationTrees("TREE")
def forceExecution(sender = None):
generateExecutionUnits()
updateAnimationTrees("FORCE", sender)
def redraw_areas_if_possible():
try:
for area in bpy.context.screen.areas:
area.tag_redraw()
except: pass
bpy.app.handlers.frame_change_post.append(frameChangeHandler)
bpy.app.handlers.scene_update_post.append(sceneUpdateHandler)
bpy.app.handlers.load_post.append(fileLoadHandler)