1 # SPDX-License-Identifier: GPL-2.0-or-later
6 from collections
import namedtuple
8 from bpy
.props
import (
16 ScatterSettings
= namedtuple("ScatterSettings",
17 ["seed", "density", "radius", "scale", "random_scale",
18 "rotation", "normal_offset", "use_normal_rotation"])
20 class ObjectScatterProperties(bpy
.types
.PropertyGroup
):
24 description
="Change it to get a different scatter pattern",
27 density
: FloatProperty(
32 description
="The amount of objects per unit on the line",
35 radius
: FloatProperty(
42 description
="Maximum distance of the objects to the line",
50 description
="Size of the generated objects",
53 random_scale_percentage
: FloatProperty(
54 name
="Random Scale Percentage",
60 description
="Increase to get a larger range of sizes",
63 rotation
: FloatProperty(
71 description
="Maximum rotation of the generated objects",
74 normal_offset
: FloatProperty(
79 description
="Distance from the surface",
82 use_normal_rotation
: BoolProperty(
83 name
="Use Normal Rotation",
85 description
="Rotate the instances according to the surface normals",
88 def to_settings(self
):
89 return ScatterSettings(
94 random_scale
=self
.random_scale_percentage
/ 100,
95 rotation
=self
.rotation
,
96 normal_offset
=self
.normal_offset
,
97 use_normal_rotation
=self
.use_normal_rotation
,
101 class ObjectScatterPanel(bpy
.types
.Panel
):
102 bl_idname
= "OBJECT_PT_object_scatter"
103 bl_label
= "Object Scatter"
104 bl_space_type
= 'VIEW_3D'
105 bl_region_type
= 'UI'
108 def draw(self
, context
):
110 layout
.use_property_split
= True
111 scatter
= context
.scene
.scatter_properties
113 layout
.prop(scatter
, "density", slider
=True)
114 layout
.prop(scatter
, "radius", slider
=True)
116 col
= layout
.column(align
=True)
117 col
.prop(scatter
, "scale", slider
=True)
118 col
.prop(scatter
, "random_scale_percentage", text
="Randomness", slider
=True)
120 layout
.prop(scatter
, "use_normal_rotation")
121 layout
.prop(scatter
, "rotation", slider
=True)
122 layout
.prop(scatter
, "normal_offset", text
="Offset", slider
=True)
123 layout
.prop(scatter
, "seed")
125 def draw_menu(self
, context
):
127 layout
.operator("object.scatter")
130 ObjectScatterProperties
,
136 bpy
.utils
.register_class(cls
)
137 bpy
.types
.Scene
.scatter_properties
= PointerProperty(type=ObjectScatterProperties
)
138 bpy
.types
.VIEW3D_MT_object
.append(draw_menu
)
142 bpy
.utils
.unregister_class(cls
)
143 del bpy
.types
.Scene
.scatter_properties
144 bpy
.types
.VIEW3D_MT_object
.remove(draw_menu
)