Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Sharybin <sergey.vfx@gmail.com>2015-01-15 11:23:33 +0300
committerSergey Sharybin <sergey.vfx@gmail.com>2015-01-22 12:12:22 +0300
commita1ffb49e494deac6cf6d3bcca45c046d9acdfad1 (patch)
tree0ed795eff77b24e1b04d7f33eca661a717476bac /intern/cycles/blender/addon/version_update.py
parent1aa8f0d3c02f65c4e70a5e87dd45f44a135a66a2 (diff)
Fix T43120: Cycles mapping node rotation order is different from viewport
Root of the issue goes to the fact that since the very beginning Cycles was using ZYX euler rotation for mapping shader node but blender was always using XYZ euler rotation. This commit switches Cycles to use XYZ euler order and adds versioning code to preserve backward compatibility. There was no really nice solution here because either we're ending up with versioning code or we'll need to deal with all sort of exceptions from blender side in order to support ZYX order for the mapping node. The latest one is also creepy from the other render engines points of view -- that might break compatibility with existing bindings or introduce some extra headache for them in the future. This could also become a PITA for us with need of supporting all sort of weird and wonderful exceptions in the refactored viewport project. NOTE: This commit breaks forward compatibility, meaning opening new files in older blender might not give proper result if Mapping node was used. Also, libraries are to be re-saved separately from the scene file, otherwise versioning code for them wouldn't run if scene file was re-saved with new version of blender. Reviewers: brecht, juicyfruit, campbellbarton Reviewed By: campbellbarton Differential Revision: https://developer.blender.org/D973
Diffstat (limited to 'intern/cycles/blender/addon/version_update.py')
-rw-r--r--intern/cycles/blender/addon/version_update.py57
1 files changed, 57 insertions, 0 deletions
diff --git a/intern/cycles/blender/addon/version_update.py b/intern/cycles/blender/addon/version_update.py
index 84414123a8c..741c2010774 100644
--- a/intern/cycles/blender/addon/version_update.py
+++ b/intern/cycles/blender/addon/version_update.py
@@ -21,6 +21,59 @@ import bpy
from bpy.app.handlers import persistent
+def check_is_new_shading_material(material):
+ if not material.node_tree:
+ return False
+ for node in material.node_tree.nodes:
+ # If material has any node with ONLY new shading system
+ # compatibility then it's considered a Cycles material
+ # and versioning code would need to perform on it.
+ #
+ # We can not check for whether NEW_SHADING in compatibility
+ # because some nodes could have compatibility with both old
+ # and new shading system and they can't be used for any
+ # decision here.
+ if node.shading_compatibility == {'NEW_SHADING'}:
+ return True
+
+ # If node is only compatible with old shading system
+ # then material can not be Cycles material and we
+ # can stopiterating nodes now.
+ if node.shading_compatibility == {'OLD_SHADING'}:
+ return False
+ return False
+
+
+def foreach_notree_node(nodetree, callback, traversed):
+ if nodetree in traversed:
+ return
+ traversed.add(nodetree)
+ for node in nodetree.nodes:
+ callback(node)
+ if node.bl_idname == 'ShaderNodeGroup':
+ foreach_notree_node(node.node_tree, callback, traversed)
+
+
+def foreach_cycles_node(callback):
+ traversed = set()
+ for material in bpy.data.materials:
+ if check_is_new_shading_material(material):
+ foreach_notree_node(material.node_tree,
+ callback,
+ traversed)
+
+
+def mapping_node_order_flip(node):
+ """
+ Flip euler order of mapping shader node
+ """
+ if node.bl_idname == 'ShaderNodeMapping':
+ rot = node.rotation.copy()
+ rot.order = 'ZYX'
+ quat = rot.to_quaternion()
+ node.rotation = quat.to_euler('XYZ')
+
+
@persistent
def do_versions(self):
# We don't modify startup file because it assumes to
@@ -57,3 +110,7 @@ def do_versions(self):
cscene.caustics_reflective = False
cscene.caustics_refractive = False
+
+ # Euler order was ZYX in previous versions.
+ if bpy.data.version <= (2, 73, 4):
+ foreach_cycles_node(mapping_node_order_flip)