versioning.py 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  1. #Versioning Tasks
  2. # this will be the new versioning system, and will deprecate the old SOCKETS_ADDED and such
  3. from bpy.types import Node, NodeSocket
  4. from bpy.app import version as bpy_version
  5. from .utilities.utilities import (prRed, prGreen, prPurple, prWhite,
  6. prOrange,
  7. wrapRed, wrapGreen, wrapPurple, wrapWhite,
  8. wrapOrange,
  9. get_socket_maps, do_relink, )
  10. # CHECKLIST FOR DUMMIES:
  11. # Did you make sure to turn off and re-enable tree updates?
  12. # Did you restore connections to the node socket after changing things?
  13. # Did you test FUNCTIONALITY in your test rigs instead of just checking if the tree
  14. # would generate? CHANGED FUNCTIONALITY IS STILL A BUG!!
  15. # Did you make sure to toggle the is_updating flag for ANY node that is touched by
  16. # the edits you are doing to the current node (example: removing a socket causes
  17. # linked group and schema nodes to update)
  18. # (add more whenever a weird or difficult to debug problem occurs)
  19. def version_upgrade_very_old(*args, **kwargs):
  20. node = kwargs['node']
  21. current_major_version = node.id_data.mantis_version[0]
  22. current_minor_version = node.id_data.mantis_version[1]
  23. if current_major_version > 0: return# major version must be 0
  24. if current_minor_version > 11: return# minor version must be 12 or less
  25. # this is the old node update, very inneficient and strange and badly organized
  26. NODES_REMOVED=["xFormRootNode"]
  27. # Node bl_idname, # Socket Name
  28. SOCKETS_REMOVED=[("UtilityDriverVariable", "Transform Channel"),
  29. ("xFormRootNode","World Out"),
  30. ("UtilitySwitch","xForm"),
  31. ("LinkDrivenParameter", "Enable")]
  32. # Node Class #Prior bl_idname # prior name # new bl_idname # new name, # Multi
  33. SOCKETS_RENAMED=[ ("LinkDrivenParameter", "DriverSocket", "Driver", "FloatSocket", "Value", False),
  34. ("DeformerHook", "IntSocket", "Index", "UnsignedIntSocket", "Point Index", False),
  35. ("SchemaConstOutput", "IntSocket", "Expose when N==", "UnsignedIntSocket", "Expose at Index", False),]
  36. # NODE CLASS NAME IN_OUT SOCKET TYPE SOCKET NAME INDEX MULTI DEFAULT
  37. SOCKETS_ADDED=[("DeformerMorphTargetDeform", 'INPUT', 'BooleanSocket', "Use Shape Key", 1, False, False),
  38. ("DeformerMorphTargetDeform", 'INPUT', 'BooleanSocket', "Use Offset", 2, False, True),
  39. ("UtilityFCurve", 'INPUT', "eFCrvExtrapolationMode", "Extrapolation Mode", 0, False, 'CONSTANT'),
  40. ("LinkCopyScale", 'INPUT', "BooleanSocket", "Additive", 3, False, False),
  41. ("DeformerHook", 'INPUT', "FloatFactorSocket", "Influence",3, False, 1.0),
  42. ("DeformerHook", 'INPUT', "UnsignedIntSocket", "Spline Index", 2, False, 0),
  43. ("DeformerHook", 'INPUT', "BooleanSocket", "Auto-Bezier", 5, False, True),
  44. ("UtilityCompare", 'INPUT', "EnumCompareOperation", "Comparison", 0, False, 'EQUAL'),
  45. ("UtilityMatrixFromCurve", 'INPUT', "UnsignedIntSocket", "Spline Index", 1, False, 0),
  46. ("UtilityMatricesFromCurve", 'INPUT', "UnsignedIntSocket", "Spline Index", 1, False, 0),
  47. ("UtilityPointFromCurve", 'INPUT', "UnsignedIntSocket", "Spline Index", 1, False, 0),
  48. ("LinkCopyScale", 'INPUT', "FloatFactorSocket", "Power", 5, False, 1.0),
  49. ]
  50. rename_jobs = []
  51. node_tree = kwargs['node_tree']
  52. try:
  53. if node.bl_idname in NODES_REMOVED:
  54. print(f"INFO: removing node {node.name} of type {node.bl_idname} because it has been deprecated.")
  55. node.inputs.remove(socket)
  56. return
  57. for i, socket in enumerate(node.inputs.values()):
  58. if (node.bl_idname, socket.identifier) in SOCKETS_REMOVED:
  59. print(f"INFO: removing socket {socket.identifier} of node {node.name} of type {node.bl_idname} because it has been deprecated.")
  60. node.inputs.remove(socket)
  61. for old_class, old_bl_idname, old_name, new_bl_idname, new_name, multi in SOCKETS_RENAMED:
  62. if (node.bl_idname == old_class and socket.bl_idname == old_bl_idname and socket.name == old_name):
  63. rename_jobs.append((socket, i, new_bl_idname, new_name, multi))
  64. for i, socket in enumerate(node.outputs.values()):
  65. if (node.bl_idname, socket.identifier) in SOCKETS_REMOVED:
  66. print(f"INFO: removing socket {socket.identifier} of node {node.name} of type {node.bl_idname} because it has been deprecated.")
  67. node.outputs.remove(socket)
  68. for old_class, old_bl_idname, old_name, new_bl_idname, new_name, multi in SOCKETS_RENAMED:
  69. if (node.bl_idname == old_class and socket.bl_idname == old_bl_idname and socket.name == old_name):
  70. rename_jobs.append((socket, i, new_bl_idname, new_name, multi))
  71. for bl_idname, in_out, socket_type, socket_name, index, use_multi_input, default_val in SOCKETS_ADDED:
  72. if node.bl_idname != bl_idname:
  73. continue
  74. if in_out == 'INPUT' and node.inputs.get(socket_name) is None:
  75. print(f"INFO: adding socket \"{socket_name}\" of type {socket_type} to node {node.name} of type {node.bl_idname}.")
  76. s = node.inputs.new(socket_type, socket_name, use_multi_input=use_multi_input)
  77. try:
  78. s.default_value = default_val
  79. except AttributeError:
  80. pass # the socket is read-only
  81. node.inputs.move(len(node.inputs)-1, index)
  82. socket_map = None
  83. if rename_jobs:
  84. socket_maps = get_socket_maps(node)
  85. for socket, socket_index, new_bl_idname, new_name, multi in rename_jobs:
  86. old_id = socket.identifier
  87. print (f"Renaming socket {socket.identifier} to {new_name} in node {node.name}")
  88. if socket.is_output:
  89. index = 1
  90. in_out = "OUTPUT"
  91. node.outputs.remove(socket)
  92. s = node.outputs.new(new_bl_idname, new_name, identifier=new_name, use_multi_input=multi)
  93. node.outputs.move(len(node.outputs)-1, socket_index)
  94. socket_map = socket_maps[1]
  95. else:
  96. index = 0
  97. in_out = "INPUT"
  98. node.inputs.remove(socket)
  99. s = node.inputs.new(new_bl_idname, new_name, identifier=new_name, use_multi_input=multi)
  100. node.inputs.move(len(node.inputs)-1, socket_index)
  101. socket_map = socket_maps[0]
  102. socket_map[new_name] = socket_map[old_id]
  103. if new_name != old_id: del socket_map[old_id] # sometimes rename just changes the socket type or multi
  104. do_relink(node, s, socket_map)
  105. except Exception as e:
  106. prRed(f"Error updating version in node: {node.id_data.name}::{node.name}; see error:")
  107. print(e)
  108. def version_upgrade_bone_0_12_0_from_older(*args, **kwargs):
  109. # we need to check if it has an array collection input and a color input
  110. # then we need to solve each task
  111. node = kwargs['node']
  112. live_updates = node.id_data.do_live_update
  113. node.id_data.do_live_update = False
  114. current_major_version = node.id_data.mantis_version[0]
  115. current_minor_version = node.id_data.mantis_version[1]
  116. if current_major_version > 0: # major version must be 0
  117. return
  118. if current_minor_version >= 12: # minor version must be 11 or less
  119. return
  120. # sub version doesn't matter since any subversion of 11 should trigger this task
  121. collection_input_is_array = False
  122. try:
  123. collection_input_is_array = node.inputs['Bone Collection'].is_multi_input
  124. except KeyError: # I suppose this happens in very, very old trees
  125. pass # but it is extremely unlikely
  126. toggle_updating = []
  127. was_updating = {}
  128. try:
  129. if not collection_input_is_array: # it must be made into an array!
  130. prPurple(f"Updating \"Bone Collection\" Socket in {node.name}")
  131. from .utilities.utilities import get_socket_maps
  132. socket_maps = get_socket_maps(node)
  133. socket_map = socket_maps[0]
  134. for i, socket in enumerate(node.inputs):
  135. if socket.name == 'Bone Collection': break
  136. # Always guard socket removal in case of connection to e.g. schema
  137. for socket_name, links in socket_map.items():
  138. if isinstance(links, list):
  139. for link in links:
  140. if hasattr(link, 'node') and hasattr(link.node, 'is_updating'):
  141. toggle_updating.append(link.node)
  142. was_updating[link.node.name] = link.node.is_updating
  143. link.node.is_updating = True
  144. node.inputs.remove(socket)
  145. s = node.inputs.new('BoneCollectionSocket', 'Bone Collection',
  146. identifier='Bone Collection', use_multi_input=True)
  147. node.inputs.move(len(node.inputs)-1, i)
  148. do_relink(node, s, socket_map, in_out='INPUT')
  149. if node.inputs.get('Color') is None:
  150. prPurple(f"Adding \"Color\" Socket to {node.name}")
  151. s = node.inputs.new('ColorSetSocket', 'Color',)
  152. node.inputs.move(len(node.inputs)-1, 22)
  153. except Exception as e:
  154. prRed(f"Error updating version in node: {node.id_data.name}::{node.name}; see error:")
  155. print(e)
  156. finally:
  157. # Now we have to clean up by removing the unneeded sockets and repositioning.
  158. for other_node in toggle_updating:
  159. other_node.is_updating = was_updating[other_node.name]
  160. node.id_data.do_live_update = live_updates
  161. def up_0_12_1_add_inherit_color(*args, **kwargs):
  162. # add an inherit color input.
  163. node = kwargs['node']
  164. current_major_version = node.id_data.mantis_version[0]
  165. current_minor_version = node.id_data.mantis_version[1]
  166. current_sub_version = node.id_data.mantis_version[2]
  167. if current_major_version > 0: return# major version must be 0
  168. if current_minor_version > 12: return# minor version must be 12 or less
  169. if current_minor_version == 12 and current_sub_version > 9: return # sub version must be 8 or less
  170. # I am having it do 8 or less because there was a bug in this function prior to 9
  171. # sub version doesn't matter since any subversion of 11 should trigger this task
  172. prPurple(f"Adding \"Inherit Color\" socket to {node.name}")
  173. try:
  174. inh_color = node.inputs.get('Inherit Color')
  175. if inh_color and inh_color.bl_idname != 'BooleanSocket':
  176. node.inputs.remove(inh_color)
  177. inh_color = None
  178. if inh_color is None:
  179. s = node.inputs.new('BooleanSocket', 'Inherit Color',)
  180. node.inputs.move(len(node.inputs)-1, 23)
  181. s.default_value=True
  182. except Exception as e:
  183. prRed(f"Error updating version in node: {node.id_data.name}::{node.name}; see error:")
  184. print(e)
  185. def up_0_12_13_add_widget_scale(*args, **kwargs):
  186. node = kwargs['node']
  187. current_major_version = node.id_data.mantis_version[0]
  188. current_minor_version = node.id_data.mantis_version[1]
  189. current_sub_version = node.id_data.mantis_version[2]
  190. if current_major_version > 0: return# major version must be 0
  191. if current_minor_version > 12: return# minor version must be 12 or less
  192. if current_minor_version == 12 and current_sub_version > 12: return
  193. # sub version must be 12 or less
  194. prPurple(f"Adding \"Scale\" socket to {node.name}")
  195. try:
  196. scale = node.inputs.get('Scale')
  197. if scale is None:
  198. s = node.inputs.new('VectorScaleSocket', 'Scale',)
  199. s.default_value=[1.0,1.0,1.0]
  200. node.inputs.move(len(node.inputs)-1, 1)
  201. except Exception as e:
  202. prRed(f"Error updating version in node: {node.id_data.name}::{node.name}; see error:")
  203. print(e)
  204. def up_0_12_25_replace_floor_offset_type(*args, **kwargs):
  205. node = kwargs['node']
  206. current_major_version = node.id_data.mantis_version[0]
  207. current_minor_version = node.id_data.mantis_version[1]
  208. current_sub_version = node.id_data.mantis_version[2]
  209. if current_major_version > 0: return# major version must be 0
  210. if current_minor_version > 12: return# minor version must be 12 or less
  211. if current_minor_version == 12 and current_sub_version > 24: return
  212. socket_maps = get_socket_maps(node)
  213. prPurple(f"Fixing \"Offset\" socket in {node.name}")
  214. try:
  215. offset = node.inputs["Offset"]
  216. node.inputs.remove(offset)
  217. s = node.inputs.new('FloatSocket', 'Offset',)
  218. node.inputs.move(len(node.inputs)-1, 2)
  219. do_relink(node, s, socket_maps[0])
  220. except Exception as e:
  221. prRed(f"Error updating version in node: {node.id_data.name}::{node.name}; see error:")
  222. print(e)
  223. def get_absolute_location(node): # using this for version compatibility
  224. location = node.location.copy() # FUTURE: deprecate old blenders and use absolute_location
  225. while(node.parent):
  226. node = node.parent
  227. location+= node.location
  228. return location
  229. def up_0_13_0_new_custom_prop_node(*args, **kwargs):
  230. tree, node = kwargs['node_tree'], kwargs['node']
  231. current_major_version = tree.mantis_version[0]
  232. if current_major_version > 0: return# major version must be 0
  233. current_minor_version = tree.mantis_version[1]
  234. if current_minor_version >= 13: return# minor version must be 12 or less
  235. remove_me, prop_nodes = [], []
  236. from .xForm_nodes_ui import xFormBoneNode
  237. socket_map_in, socket_map_out = get_socket_maps(node)
  238. if isinstance(node, xFormBoneNode):
  239. for custom_input in reversed(list(node.inputs)):
  240. if 'Parameter' not in custom_input.bl_idname:
  241. continue
  242. custom_prop_node = tree.nodes.new('UtilityCustomProperty')
  243. prop_type = None
  244. if custom_input.bl_idname == 'ParameterBoolSocket':
  245. prop_type = 'BOOL'
  246. custom_prop_node.inputs['Default (Bool)'].default_value = getattr(custom_input, "default_value")
  247. elif custom_input.bl_idname == 'ParameterIntSocket':
  248. prop_type = 'INT'
  249. custom_prop_node.inputs['Default (Int)'].default_value = int( getattr(custom_input, "default_value") )
  250. custom_prop_node.inputs['Min (Int)'].default_value = int( getattr(custom_input, "min") )
  251. custom_prop_node.inputs['Max (Int)'].default_value = int( getattr(custom_input, "max") )
  252. custom_prop_node.inputs['Soft Min (Int)'].default_value = int( getattr(custom_input, "soft_min") )
  253. custom_prop_node.inputs['Soft Max (Int)'].default_value = int( getattr(custom_input, "soft_max") )
  254. elif custom_input.bl_idname == 'ParameterFloatSocket':
  255. prop_type = 'FLOAT'
  256. custom_prop_node.inputs['Default (Float)'].default_value = getattr(custom_input, "default_value")
  257. custom_prop_node.inputs['Min (Float)'].default_value = getattr(custom_input, "min")
  258. custom_prop_node.inputs['Max (Float)'].default_value = getattr(custom_input, "max")
  259. custom_prop_node.inputs['Soft Min (Float)'].default_value = getattr(custom_input, "soft_min")
  260. custom_prop_node.inputs['Soft Max (Float)'].default_value = getattr(custom_input, "soft_max")
  261. elif custom_input.bl_idname == 'ParameterVectorSocket':
  262. prop_type = 'VECTOR'
  263. custom_prop_node.inputs['Default (Vector)'].default_value = getattr(custom_input, "default_value")
  264. try:
  265. custom_prop_node.inputs['Min (Float)'].default_value = getattr(custom_input, "min")
  266. custom_prop_node.inputs['Max (Float)'].default_value = getattr(custom_input, "max")
  267. custom_prop_node.inputs['Soft Min (Float)'].default_value = getattr(custom_input, "soft_min")
  268. custom_prop_node.inputs['Soft Max (Float)'].default_value = getattr(custom_input, "soft_max")
  269. except AttributeError: # I don't know if I just never implemented these or if it is version specific
  270. pass # anyways this isn't critical and should not trigger even a warning
  271. elif custom_input.bl_idname == 'ParameterStringSocket':
  272. prop_type = 'STRING'
  273. custom_prop_node.inputs['Default (String)'].default_value = getattr(custom_input, "default_value")
  274. custom_prop_node.inputs['Name'].default_value = custom_input.name
  275. custom_prop_node.inputs['Type'].default_value = prop_type
  276. prop_nodes.append(custom_prop_node)
  277. remove_me.append(custom_input)
  278. # now we need to relink things, because the custom property socket could have had an
  279. # input supplying the default value
  280. relink_value = socket_map_in.get(custom_input.identifier, None)
  281. if isinstance(relink_value, list): # this indicates it is a list of links
  282. # CRITICALLY, we need to force display update before doing this.
  283. custom_prop_node.display_update({}, None) # parsed_tree and context, not needed
  284. input_socket = None
  285. match prop_type:
  286. case 'BOOL':
  287. input_socket = "Default (Bool)"
  288. case 'INT':
  289. input_socket = "Default (Int)"
  290. case 'FLOAT':
  291. input_socket = "Default (Float)"
  292. case 'VECTOR':
  293. input_socket = "Default (Vector)"
  294. case 'STRING':
  295. input_socket = "Default (String)"
  296. case _: # Should never never happen
  297. raise RuntimeError("Unexpected Code Path Reached, this is a bug.")
  298. do_relink(custom_prop_node, custom_prop_node.inputs[input_socket],
  299. {input_socket:relink_value})
  300. while remove_me:
  301. custom_input = remove_me.pop()
  302. node.inputs.remove(custom_input)
  303. new_input = node.inputs.new("CustomPropSocket", "Custom Properties", use_multi_input=True)
  304. from mathutils import Vector
  305. for i, prop_node in enumerate(prop_nodes):
  306. tree.links.new(input=prop_node.outputs[0], output=new_input)
  307. prop_node.location = get_absolute_location(node)
  308. prop_node.location = prop_node.location - Vector((180, -260*i))
  309. prop_node.select = False # it is annoying to select them all by default
  310. else: # just need to add the socket.
  311. new_input = node.inputs.new("CustomPropSocket", "Custom Properties", use_multi_input=True)
  312. def schema_enable_custom_interface_types(*args, **kwargs):
  313. tree = kwargs['tree']
  314. current_major_version = tree.mantis_version[0]
  315. current_minor_version = tree.mantis_version[1]
  316. current_sub_version = tree.mantis_version[2]
  317. if current_major_version > 0: return# major version must be 0
  318. if current_minor_version >= 13: return# minor version must be 12 or less
  319. # we need to set the new interface values on the schema interface stuff
  320. prGreen(f"Updating Schema tree {tree.name} to support new, improved UI!")
  321. tree.do_live_update = False
  322. for n in tree.nodes:
  323. if hasattr(n, "is_updating"):
  324. n.is_updating = True
  325. try:
  326. for item in tree.interface.items_tree:
  327. if item.item_type == 'PANEL':
  328. continue
  329. parent_name = 'Constant'
  330. if item.parent:
  331. parent_name=item.parent.name
  332. if hasattr(item, "is_array"):
  333. # if is_array exists we're in the custom interface class
  334. # so we'll assume the other attributes exist
  335. if parent_name == 'Array':
  336. item.is_array = True
  337. if parent_name == 'Connection':
  338. item.is_array = False
  339. item.is_connection=True
  340. item.connected_to=item.name
  341. # since heretofore it has been a requirement that the names match
  342. except Exception as e:
  343. prRed(f"Error updating version in tree: {tree.name}; see error:")
  344. print(e)
  345. finally:
  346. for n in tree.nodes:
  347. if hasattr(n, "is_updating"):
  348. n.is_updating = False
  349. tree.do_live_update = True
  350. def update_fcurve_and_armature_node_to_multi_socket(*args, **kwargs):
  351. from .base_definitions import SchemaUINode
  352. node = kwargs['node']
  353. live_updates = node.id_data.do_live_update
  354. node.id_data.do_live_update = False
  355. # First we have to get the socket maps and re-init the sockets
  356. convert_keys = {'UtilityFCurve' : [ 'Keyframe', ],
  357. 'LinkArmature' : [ 'Target', 'Weight', ], }
  358. my_convert_keys = convert_keys[node.bl_idname]
  359. sockets_in, _sockets_out = get_socket_maps(node,)
  360. # NOTE IMPORTANT BUG INFO
  361. # I was using node.inputs.clear() here before unguarded...
  362. # this caused connected Schema nodes to update and mutate the socket map
  363. # which, in turn, connected the new socket to the wildcard and extended the schema
  364. # resulting in trees that fail to run. This was particularly bad because it was
  365. # so hard to debug (due to spooky action at a distance mutation)
  366. # So we have to mark the connected nodes as "updating" before we modify the tree.
  367. # TODO: should I just mark all nodes as updating during versioning?
  368. toggle_updating = []
  369. was_updating = {}
  370. for socket_name, links in sockets_in.items():
  371. if isinstance(links, list):
  372. for link in links:
  373. if hasattr(link, 'node') and hasattr(link.node, 'is_updating'):
  374. toggle_updating.append(link.node)
  375. was_updating[link.node.name] = link.node.is_updating
  376. link.node.is_updating = True
  377. node.inputs.clear() # this is VERY DANGEROUS without the above
  378. add_me_sockets = [st for st in node.socket_templates if st.is_input == True]
  379. node.init_sockets(add_me_sockets)
  380. try:
  381. new_sockets_in = {}
  382. for convert_key in my_convert_keys:
  383. for socket_name, links in sockets_in.items():
  384. print (f"Socket Name: {socket_name}, Links: {links},")
  385. if links is None: continue
  386. if convert_key+'.' in socket_name:
  387. if new_sockets_in.get(convert_key+'s'):
  388. # has to be in this order to come back alright.
  389. # assuming, that is, that the keys are sorted. they should be.
  390. new_sockets_in[convert_key+'s'] = sockets_in[socket_name] + new_sockets_in[convert_key+'s']
  391. else:
  392. new_sockets_in[convert_key+'s'] = sockets_in[socket_name]
  393. do_relink(node, node.inputs[convert_key+'s'], new_sockets_in, in_out="INPUT",)
  394. for socket_name, links in sockets_in.items():
  395. proceed = True
  396. for convert_key in my_convert_keys:
  397. if convert_key in socket_name:
  398. proceed = False
  399. if proceed:
  400. do_relink(node, node.inputs[socket_name], sockets_in, in_out='INPUT')
  401. finally:
  402. # Now we have to clean up by removing the unneeded sockets and repositioning.
  403. for other_node in toggle_updating:
  404. other_node.is_updating = was_updating[other_node.name]
  405. node.id_data.do_live_update = live_updates
  406. # versioning tasks that involve Blender versions rather than Mantis versions:
  407. error_description_4_5_0_LTS = 'There is a bug in Blender 4.5.0 LTS, that is why these sockets are blue.'\
  408. ' This will be fixed in future Blender versions.'
  409. def cleanup_4_5_0_LTS_interface_workaround(*args, **kwargs):
  410. # this is a function for cleaning up the workaround up above
  411. tree = kwargs['tree']
  412. if bpy_version == (4,5,0): return
  413. if not hasattr(tree, "interface_helper"): return
  414. import json
  415. try:
  416. interface_helper = json.loads(tree.interface_helper)
  417. except:
  418. return # this should mean it was never a problem to begin with.
  419. prPurple(f"Restoring Tree Interface for {tree.name}.")
  420. for interface_item in tree.interface.items_tree:
  421. if interface_item.item_type == 'PANEL': continue
  422. # now we need to restore the socket types, which are in the interface helper
  423. # keep the interface stuff around, I'll use it for marking arrays in the future
  424. int_info = interface_helper[interface_item.identifier]
  425. socket_type = int_info['bl_socket_idname']
  426. interface_item.socket_type = socket_type
  427. if interface_item.description == error_description_4_5_0_LTS:
  428. interface_item.description = ''
  429. versioning_tasks = [
  430. # node bl_idname task required keyword arguments
  431. (['ALL'], version_upgrade_very_old, ['node_tree', 'node'],),
  432. (['xFormBoneNode'], version_upgrade_bone_0_12_0_from_older, ['node'],),
  433. (['xFormBoneNode'], up_0_12_1_add_inherit_color, ['node'],),
  434. (['MantisTree', 'SchemaTree'], cleanup_4_5_0_LTS_interface_workaround, ['tree']),
  435. (['InputWidget'], up_0_12_13_add_widget_scale, ['node']),
  436. (['LinkFloor'], up_0_12_25_replace_floor_offset_type, ['node']),
  437. (['XFORM'], up_0_13_0_new_custom_prop_node, ['node', 'node_tree']),
  438. (['SchemaTree'], schema_enable_custom_interface_types, ['tree']),
  439. (['UtilityFCurve', 'LinkArmature'],
  440. update_fcurve_and_armature_node_to_multi_socket, ['node']),
  441. ]
  442. # WORKAROUNDS for bugs should go here:
  443. # 4.5.0 LTS valid socket types bug:
  444. def workaround_4_5_0_interface_update(tree, name, in_out, sock_type, parent_name, do_parent=False):
  445. # TODO: dedupe this code from i_o.py
  446. prRed("There is a bug in Blender 4.5.0 regarding node-group interface sockets. Working around it.")
  447. sock = tree.interface.new_socket(name=name, in_out=in_out, socket_type="NodeSocketGeometry")
  448. import json
  449. interface_helper = {} # initialize it if it is empty
  450. if tree.interface_helper: # may be empty, check here
  451. interface_helper = json.loads(tree.interface_helper)
  452. error_message = error_description_4_5_0_LTS
  453. interface_helper[sock.identifier] = {
  454. 'name' : sock.name,
  455. 'identifier' : sock.identifier,
  456. 'in_out' : sock.in_out,
  457. 'socket_type' : sock_type,
  458. 'bl_socket_idname' : sock_type,
  459. 'mantis_socket_category' : parent_name,
  460. 'description' : error_message,
  461. }
  462. sock.description = error_message # this tells the user why the socket looks weird.
  463. tree.interface_helper = json.dumps(interface_helper)
  464. if do_parent and (parent := tree.interface.items_tree.get(parent_name)):
  465. tree.interface.move_to_parent(
  466. sock,
  467. parent,
  468. 0, # what to do here?
  469. )
  470. return sock
  471. def socket_add_workaround_for_4_5_0_LTS(item, socket_collection, multi):
  472. import json
  473. tree = item.id_data
  474. interface_helper = json.loads(tree.interface_helper)
  475. socket_info = interface_helper.get(item.identifier)
  476. if not socket_info: raise RuntimeError(f"There has been an error adding the socket {item.name}")
  477. s = socket_collection.new(
  478. type=socket_info['bl_socket_idname'],
  479. name=item.name, # in case the user has changed it
  480. identifier=item.identifier,
  481. use_multi_input=multi, )
  482. return s