[Bf-blender-cvs] [a1ffb49] master: Fix T43120: Cycles mapping node rotation order is different from viewport

Sergey Sharybin noreply at git.blender.org
Thu Jan 22 10:14:45 CET 2015


Commit: a1ffb49e494deac6cf6d3bcca45c046d9acdfad1
Author: Sergey Sharybin
Date:   Thu Jan 15 13:23:33 2015 +0500
Branches: master
https://developer.blender.org/rBa1ffb49e494deac6cf6d3bcca45c046d9acdfad1

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

===================================================================

M	intern/cycles/blender/addon/version_update.py
M	intern/cycles/util/util_transform.h
M	source/blender/blenkernel/BKE_blender.h

===================================================================

diff --git a/intern/cycles/blender/addon/version_update.py b/intern/cycles/blender/addon/version_update.py
index 8441412..741c201 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)
diff --git a/intern/cycles/util/util_transform.h b/intern/cycles/util/util_transform.h
index 453d44b..ac97fa5 100644
--- a/intern/cycles/util/util_transform.h
+++ b/intern/cycles/util/util_transform.h
@@ -216,12 +216,13 @@ ccl_device_inline Transform transform_rotate(float angle, float3 axis)
 		0.0f, 0.0f, 0.0f, 1.0f);
 }
 
+/* Euler is assumed to be in XYZ order. */
 ccl_device_inline Transform transform_euler(float3 euler)
 {
 	return
-		transform_rotate(euler.x, make_float3(1.0f, 0.0f, 0.0f)) *
+		transform_rotate(euler.z, make_float3(0.0f, 0.0f, 1.0f)) *
 		transform_rotate(euler.y, make_float3(0.0f, 1.0f, 0.0f)) *
-		transform_rotate(euler.z, make_float3(0.0f, 0.0f, 1.0f));
+		transform_rotate(euler.x, make_float3(1.0f, 0.0f, 0.0f));
 }
 
 ccl_device_inline Transform transform_orthographic(float znear, float zfar)
diff --git a/source/blender/blenkernel/BKE_blender.h b/source/blender/blenkernel/BKE_blender.h
index 3053c99..cb8a68d 100644
--- a/source/blender/blenkernel/BKE_blender.h
+++ b/source/blender/blenkernel/BKE_blender.h
@@ -42,7 +42,7 @@ extern "C" {
  * and keep comment above the defines.
  * Use STRINGIFY() rather than defining with quotes */
 #define BLENDER_VERSION         273
-#define BLENDER_SUBVERSION      3
+#define BLENDER_SUBVERSION      4
 /* 262 was the last editmesh release but it has compatibility code for bmesh data */
 #define BLENDER_MINVERSION      270
 #define BLENDER_MINSUBVERSION   5




More information about the Bf-blender-cvs mailing list