[Bf-extensions-cvs] [dbfabe38] master: Object Scatter: new Use Normal Rotation option

Jacques Lucke noreply at git.blender.org
Tue Oct 29 10:46:41 CET 2019


Commit: dbfabe387097a7bdb8d7d73bc0c9cd0311d9926a
Author: Jacques Lucke
Date:   Tue Oct 29 10:44:07 2019 +0100
Branches: master
https://developer.blender.org/rBAdbfabe387097a7bdb8d7d73bc0c9cd0311d9926a

Object Scatter: new Use Normal Rotation option

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

M	object_scatter/operator.py
M	object_scatter/ui.py

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

diff --git a/object_scatter/operator.py b/object_scatter/operator.py
index 742eec95..a01ca765 100644
--- a/object_scatter/operator.py
+++ b/object_scatter/operator.py
@@ -318,6 +318,8 @@ def scatter_from_source_point(bvhtree, point, seed, settings):
     assert location is not None
     normal.normalize()
 
+    up_direction = normal if settings.use_normal_rotation else Vector((0, 0, 1))
+
     # Scale
     min_scale = settings.scale * (1 - settings.random_scale)
     max_scale = settings.scale
@@ -328,9 +330,9 @@ def scatter_from_source_point(bvhtree, point, seed, settings):
 
     # Rotation
     z_rotation = Euler((0, 0, random_uniform(sub_seed(seed, 3), 0, 2 * math.pi))).to_matrix()
-    normal_rotation = normal.to_track_quat('Z', 'X').to_matrix()
+    up_rotation = up_direction.to_track_quat('Z', 'X').to_matrix()
     local_rotation = random_euler(sub_seed(seed, 3), settings.rotation).to_matrix()
-    rotation = local_rotation @ normal_rotation @ z_rotation
+    rotation = local_rotation @ up_rotation @ z_rotation
 
     return Matrix.Translation(location) @ rotation.to_4x4() @ scale_matrix(scale)
 
diff --git a/object_scatter/ui.py b/object_scatter/ui.py
index d62b8e38..b021bf3d 100644
--- a/object_scatter/ui.py
+++ b/object_scatter/ui.py
@@ -22,6 +22,7 @@ import math
 from collections import namedtuple
 
 from bpy.props import (
+    BoolProperty,
     IntProperty,
     FloatProperty,
     PointerProperty
@@ -30,7 +31,7 @@ from bpy.props import (
 
 ScatterSettings = namedtuple("ScatterSettings",
     ["seed", "density", "radius", "scale", "random_scale",
-     "rotation", "normal_offset"])
+     "rotation", "normal_offset", "use_normal_rotation"])
 
 class ObjectScatterProperties(bpy.types.PropertyGroup):
     seed: IntProperty(
@@ -94,6 +95,12 @@ class ObjectScatterProperties(bpy.types.PropertyGroup):
         description="Distance from the surface",
     )
 
+    use_normal_rotation: BoolProperty(
+        name="Use Normal Rotation",
+        default=True,
+        description="Rotate the instances according to the surface normals",
+    )
+
     def to_settings(self):
         return ScatterSettings(
             seed=self.seed,
@@ -103,6 +110,7 @@ class ObjectScatterProperties(bpy.types.PropertyGroup):
             random_scale=self.random_scale_percentage / 100,
             rotation=self.rotation,
             normal_offset=self.normal_offset,
+            use_normal_rotation=self.use_normal_rotation,
         )
 
 
@@ -125,6 +133,7 @@ class ObjectScatterPanel(bpy.types.Panel):
         col.prop(scatter, "scale", slider=True)
         col.prop(scatter, "random_scale_percentage", text="Randomness", slider=True)
 
+        layout.prop(scatter, "use_normal_rotation")
         layout.prop(scatter, "rotation", slider=True)
         layout.prop(scatter, "normal_offset", text="Offset", slider=True)
         layout.prop(scatter, "seed")



More information about the Bf-extensions-cvs mailing list