animation_animall: remove workaround for T68666
[blender-addons.git] / object_scatter / ui.py
blobd62b8e3868769aa54c15bb8833df8f42d4f4c068
1 # ##### BEGIN GPL LICENSE BLOCK #####
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # ##### END GPL LICENSE BLOCK #####
19 import bpy
20 import math
22 from collections import namedtuple
24 from bpy.props import (
25 IntProperty,
26 FloatProperty,
27 PointerProperty
31 ScatterSettings = namedtuple("ScatterSettings",
32 ["seed", "density", "radius", "scale", "random_scale",
33 "rotation", "normal_offset"])
35 class ObjectScatterProperties(bpy.types.PropertyGroup):
36 seed: IntProperty(
37 name="Seed",
38 default=0,
39 description="Change it to get a different scatter pattern",
42 density: FloatProperty(
43 name="Density",
44 default=10,
45 min=0,
46 soft_max=50,
47 description="The amount of objects per unit on the line",
50 radius: FloatProperty(
51 name="Radius",
52 default=1,
53 min=0,
54 soft_max=5,
55 subtype='DISTANCE',
56 unit='LENGTH',
57 description="Maximum distance of the objects to the line",
60 scale: FloatProperty(
61 name="Scale",
62 default=0.3,
63 min=0.00001,
64 soft_max=1,
65 description="Size of the generated objects",
68 random_scale_percentage: FloatProperty(
69 name="Random Scale Percentage",
70 default=80,
71 min=0,
72 max=100,
73 subtype='PERCENTAGE',
74 precision=0,
75 description="Increase to get a larger range of sizes",
78 rotation: FloatProperty(
79 name="Rotation",
80 default=0.5,
81 min=0,
82 max=math.pi * 2,
83 soft_max=math.pi / 2,
84 subtype='ANGLE',
85 unit='ROTATION',
86 description="Maximum rotation of the generated objects",
89 normal_offset: FloatProperty(
90 name="Normal Offset",
91 default=0,
92 soft_min=-1.0,
93 soft_max=1.0,
94 description="Distance from the surface",
97 def to_settings(self):
98 return ScatterSettings(
99 seed=self.seed,
100 density=self.density,
101 radius=self.radius,
102 scale=self.scale,
103 random_scale=self.random_scale_percentage / 100,
104 rotation=self.rotation,
105 normal_offset=self.normal_offset,
109 class ObjectScatterPanel(bpy.types.Panel):
110 bl_idname = "OBJECT_PT_object_scatter"
111 bl_label = "Object Scatter"
112 bl_space_type = 'VIEW_3D'
113 bl_region_type = 'UI'
114 bl_category = "Tool"
116 def draw(self, context):
117 layout = self.layout
118 layout.use_property_split = True
119 scatter = context.scene.scatter_properties
121 layout.prop(scatter, "density", slider=True)
122 layout.prop(scatter, "radius", slider=True)
124 col = layout.column(align=True)
125 col.prop(scatter, "scale", slider=True)
126 col.prop(scatter, "random_scale_percentage", text="Randomness", slider=True)
128 layout.prop(scatter, "rotation", slider=True)
129 layout.prop(scatter, "normal_offset", text="Offset", slider=True)
130 layout.prop(scatter, "seed")
133 classes = (
134 ObjectScatterProperties,
135 ObjectScatterPanel,
138 def register():
139 for cls in classes:
140 bpy.utils.register_class(cls)
141 bpy.types.Scene.scatter_properties = PointerProperty(type=ObjectScatterProperties)
143 def unregister():
144 for cls in classes:
145 bpy.utils.unregister_class(cls)
146 del bpy.types.Scene.scatter_properties