[Bf-blender-cvs] [5fa962c7f67] geometry-nodes-mesh-primitives: Expose transform operation and optimize normal transform

Hans Goudey noreply at git.blender.org
Thu Mar 11 23:15:11 CET 2021


Commit: 5fa962c7f673ca8af4ad8cee9ca55c18ab261a53
Author: Hans Goudey
Date:   Mon Mar 8 21:35:58 2021 -0500
Branches: geometry-nodes-mesh-primitives
https://developer.blender.org/rB5fa962c7f673ca8af4ad8cee9ca55c18ab261a53

Expose transform operation and optimize normal transform

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

M	source/blender/nodes/geometry/node_geometry_util.hh
M	source/blender/nodes/geometry/nodes/node_geo_transform.cc

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

diff --git a/source/blender/nodes/geometry/node_geometry_util.hh b/source/blender/nodes/geometry/node_geometry_util.hh
index 271e3771006..ea78611d0dd 100644
--- a/source/blender/nodes/geometry/node_geometry_util.hh
+++ b/source/blender/nodes/geometry/node_geometry_util.hh
@@ -47,4 +47,9 @@ void update_attribute_input_socket_availabilities(bNode &node,
 Array<uint32_t> get_geometry_element_ids_as_uints(const GeometryComponent &component,
                                                   const AttributeDomain domain);
 
+void transform_mesh(Mesh *mesh,
+                    const float3 translation,
+                    const float3 rotation,
+                    const float3 scale);
+
 }  // namespace blender::nodes
diff --git a/source/blender/nodes/geometry/nodes/node_geo_transform.cc b/source/blender/nodes/geometry/nodes/node_geo_transform.cc
index 539a7551be9..64cab50faf9 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_transform.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_transform.cc
@@ -20,6 +20,8 @@
 
 #include "BLI_math_matrix.h"
 
+#include "DNA_mesh_types.h"
+#include "DNA_meshdata_types.h"
 #include "DNA_pointcloud_types.h"
 #include "DNA_volume_types.h"
 
@@ -57,20 +59,29 @@ static bool use_translate(const float3 rotation, const float3 scale)
   return true;
 }
 
-static void transform_mesh(Mesh *mesh,
-                           const float3 translation,
-                           const float3 rotation,
-                           const float3 scale)
+void transform_mesh(Mesh *mesh,
+                    const float3 translation,
+                    const float3 rotation,
+                    const float3 scale)
 {
   /* Use only translation if rotation and scale are zero. */
   if (use_translate(rotation, scale)) {
     BKE_mesh_translate(mesh, translation, true);
   }
   else {
-    float mat[4][4];
-    loc_eul_size_to_mat4(mat, translation, rotation, scale);
-    BKE_mesh_transform(mesh, mat, true);
-    BKE_mesh_calc_normals(mesh);
+    float4x4 matrix;
+    loc_eul_size_to_mat4(matrix.values, translation, rotation, scale);
+    BKE_mesh_transform(mesh, matrix.values, true);
+
+    /* https://www.scratchapixel.com/lessons/mathematics-physics-for-computer-graphics/
+     * geometry/transforming-normals */
+    const float4x4 normal_matrix = matrix.inverted().transposed();
+    for (MVert &vert : MutableSpan(mesh->mvert, mesh->totvert)) {
+      float3 normal;
+      normal_short_to_float_v3(normal, vert.no);
+      normal = normal_matrix * normal;
+      normal_float_to_short_v3(vert.no, normal);
+    }
   }
 }



More information about the Bf-blender-cvs mailing list