Skip to content

Commit

Permalink
feat: add optional separate column spacing for takeoff grid and reorg…
Browse files Browse the repository at this point in the history
…anize some params to advanced section
  • Loading branch information
vasarhelyi committed Oct 9, 2024
1 parent 5bbfefa commit c113296
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 24 deletions.
35 changes: 25 additions & 10 deletions src/modules/sbstudio/plugin/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@
DEFAULT_LIGHT_EFFECT_DURATION = 10
"""Default duration of newly created light effects, in seconds"""

DRONE_RADIUS = 0.5
"""Drone radius"""
DEFAULT_INDOOR_DRONE_RADIUS = 0.1
"""Default outdoor drone radius"""

DEFAULT_OUTDOOR_DRONE_RADIUS = 0.5
"""Default outdoor drone radius"""

RANDOM_SEED_MAX = 0x7FFFFFFF
"""Maximum allowed value of the random seed. Note that Blender does not support
Expand Down Expand Up @@ -203,38 +206,50 @@ class Templates:
"""Name of the drone template object"""

@classmethod
def find_drone(cls, *, create: bool = True, template: str = "SPHERE"):
def find_drone(
cls,
*,
create: bool = True,
template: str = "SPHERE",
drone_radius: float = DEFAULT_OUTDOOR_DRONE_RADIUS,
):
"""Returns the Blender object that serves as a template for newly
created drones.
Args:
create: whether to create the template if it does not exist yet
template: the drone template to use.
Possible values: SPHERE, CONE, SELECTED
create: whether to create the template if it does not exist yet
drone_radius: the radius of the newly created drone object
"""
templates = Collections.find_templates()
coll = templates.objects
if create:
drone, _ = ensure_object_exists_in_collection(
coll,
cls.DRONE,
factory=partial(cls._create_drone_template, template=template),
factory=partial(
cls._create_drone_template,
template=template,
drone_radius=drone_radius,
),
)
return drone
else:
return get_object_in_collection(coll, cls.DRONE)

@staticmethod
def _create_drone_template(template: str = "SPHERE"):
def _create_drone_template(
template: str = "SPHERE", drone_radius: float = DEFAULT_OUTDOOR_DRONE_RADIUS
):
if template == "SPHERE":
object = create_icosphere(radius=DRONE_RADIUS)
object = create_icosphere(radius=drone_radius)
elif template == "CONE":
object = create_cone(radius=DRONE_RADIUS)
object = create_cone(radius=drone_radius)
elif template == "SELECTED":
objects = bpy.context.selected_objects
if not objects:
object = create_icosphere(radius=DRONE_RADIUS)
object = create_icosphere(radius=drone_radius)
else:
object = objects[0]
else:
Expand Down
41 changes: 40 additions & 1 deletion src/modules/sbstudio/plugin/model/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
from bpy.types import Collection, PropertyGroup

from sbstudio.math.rng import RandomSequence
from sbstudio.plugin.constants import DEFAULT_EMISSION_STRENGTH, RANDOM_SEED_MAX
from sbstudio.plugin.constants import (
DEFAULT_INDOOR_DRONE_RADIUS,
DEFAULT_OUTDOOR_DRONE_RADIUS,
DEFAULT_EMISSION_STRENGTH,
RANDOM_SEED_MAX,
)
from sbstudio.plugin.utils.bloom import (
set_bloom_effect_enabled,
update_emission_strength,
Expand All @@ -18,6 +23,9 @@

__all__ = ("DroneShowAddonFileSpecificSettings",)

_drone_radius_updated_by_user: bool = False
"""Shows whether the drone radius has been updated by the user already."""


def use_bloom_effect_updated(self, context):
set_bloom_effect_enabled(self.use_bloom_effect)
Expand All @@ -27,6 +35,26 @@ def emission_strength_updated(self, context):
update_emission_strength(self.emission_strength)


def show_type_updated(self, context):
"""Called when the show type is updated by the user."""
global _drone_radius_updated_by_user

if not _drone_radius_updated_by_user:
if self.show_type == "INDOOR":
self.drone_radius = DEFAULT_INDOOR_DRONE_RADIUS
else:
self.drone_radius = DEFAULT_OUTDOOR_DRONE_RADIUS
# need to set it back to False after previous updates
_drone_radius_updated_by_user = False


def drone_radius_updated(self, context):
"""Called when the drone radius is updated by the user."""
global _drone_radius_updated_by_user

_drone_radius_updated_by_user = True


class DroneShowAddonFileSpecificSettings(PropertyGroup):
"""Property group that stores the generic settings of a drone show in the
addon that do not belong elsewhere.
Expand All @@ -38,6 +66,16 @@ class DroneShowAddonFileSpecificSettings(PropertyGroup):
description="The collection that contains all the objects that are to be treated as drones",
)

drone_radius = FloatProperty(
name="Drone radius",
description="The radius of the drone template to create.",
default=DEFAULT_OUTDOOR_DRONE_RADIUS,
unit="LENGTH",
soft_min=0.1,
soft_max=1,
update=drone_radius_updated,
)

drone_template = EnumProperty(
items=[
("SPHERE", "Sphere", "", 1),
Expand Down Expand Up @@ -92,6 +130,7 @@ class DroneShowAddonFileSpecificSettings(PropertyGroup):
2,
),
],
update=show_type_updated,
)

use_bloom_effect = BoolProperty(
Expand Down
6 changes: 5 additions & 1 deletion src/modules/sbstudio/plugin/operators/create_takeoff_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,11 @@ def _run(self, context):
intra_slot_spacing_col=self.intra_slot_spacing_col,
)[: self.drones]

drone_template = Templates.find_drone()
settings = context.scene.skybrush.settings
drone_template = Templates.find_drone(
template=settings.drone_template,
drone_radius=settings.drone_radius,
)
drone_collection = Collections.find_drones()

template_material = get_material_for_led_light_color(drone_template)
Expand Down
4 changes: 2 additions & 2 deletions src/modules/sbstudio/plugin/operators/prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def execute(self, context):
link_object_to_scene(formations, allow_nested=True)
link_object_to_scene(templates, allow_nested=True)

# Create the drone template as well
Templates.find_drone(template=context.scene.skybrush.settings.drone_template)
# Note that we do not create the drone template here yet as
# its size might depend on later takeoff grid parameters

return {"FINISHED"}
6 changes: 0 additions & 6 deletions src/modules/sbstudio/plugin/panels/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,8 @@ class ExportPanel(Panel):
bl_category = "Safety & Export"

def draw(self, context):
scene = context.scene
settings = scene.skybrush.settings

layout = self.layout

if settings:
layout.prop(settings, "show_type")

formats = get_supported_file_formats()

for format in formats:
Expand Down
12 changes: 9 additions & 3 deletions src/modules/sbstudio/plugin/panels/swarm.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,20 @@ def draw(self, context):

layout = self.layout

layout.prop(settings, "show_type", text="Show")
layout.prop(settings, "drone_collection", text="Drones")
layout.prop(settings, "max_acceleration", slider=True)

layout.separator()

if Collections.find_templates(create=False) is None:
layout.prop(settings, "drone_template", text="Drone")
row = layout.row(heading="Drone radius")
row.prop(settings, "drone_radius", text="")
if settings.drone_template not in ["SPHERE", "CONE"]:
row.enabled = False

layout.prop(settings, "max_acceleration", slider=True)

layout.separator()
layout.separator()

layout.operator(CreateTakeoffGridOperator.bl_idname, icon="ADD")

Expand Down
2 changes: 1 addition & 1 deletion src/modules/sbstudio/plugin/utils/bloom.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def update_emission_strength(value: float) -> None:
material = get_material_for_led_light_color(drone)
set_emission_strength_of_material(material, value)

template = Templates.find_drone()
template = Templates.find_drone(create=False)
if template:
material = get_material_for_led_light_color(template)
set_emission_strength_of_material(material, value)

0 comments on commit c113296

Please sign in to comment.