Skip to content

Commit

Permalink
EDITOR-#620. Fix some bugs/ Add a few changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ExuberantIris committed Feb 10, 2025
1 parent 92746eb commit d9ca256
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 25 deletions.
6 changes: 1 addition & 5 deletions editor-blender/core/actions/property/partial_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@ def set_loaded_frame_at_full_range():
music_frame = state.partial_load_frames
state.dancer_load_frames = music_frame

state.dancer_load_frames = (music_frame[0], music_frame[1])
set_min_max_frame(music_frame[0], music_frame[1])

if not bpy.context:
return
bpy.context.scene.frame_start = music_frame[0]
bpy.context.scene.frame_end = music_frame[1]


def set_state_of_loaded_frame_range():
Expand All @@ -42,8 +40,6 @@ def set_state_of_loaded_frame_range():

if not bpy.context:
return
bpy.context.scene.frame_start = min_frame
bpy.context.scene.frame_end = max_frame


def init_loaded_frame_range():
Expand Down
14 changes: 13 additions & 1 deletion editor-blender/core/actions/property/timeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ def set_current_frame_index(self: bpy.types.WindowManager, value: str):
current_frame = state.control_map[current_frame_id]
start = current_frame.start

if (
start < state.dancer_load_frames[0]
or start > state.dancer_load_frames[1]
):
return

bpy.context.scene.frame_current = start
state.current_control_index = current_frame_index

Expand All @@ -44,6 +50,12 @@ def set_current_frame_index(self: bpy.types.WindowManager, value: str):
current_frame = state.pos_map[current_frame_id]
start = current_frame.start

if (
start < state.dancer_load_frames[0]
or start > state.dancer_load_frames[1]
):
return

bpy.context.scene.frame_current = start
state.current_pos_index = current_frame_index

Expand Down Expand Up @@ -104,7 +116,7 @@ def set_time(self: bpy.types.WindowManager, value: str):
if not bpy.context:
return
frame = time_to_frame(value)
if frame < 0:
if frame < state.dancer_load_frames[0] or frame > state.dancer_load_frames[1]:
return

self["ld_time"] = value
Expand Down
1 change: 0 additions & 1 deletion editor-blender/core/actions/state/control_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ async def add_control_frame():
set_requesting(False)


# TODO finish this function
async def save_control_frame(start: int | None = None):
if not bpy.context:
return
Expand Down
8 changes: 1 addition & 7 deletions editor-blender/core/actions/state/pos_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from ...log import logger
from ...models import DancerName, EditingData, EditMode, Location
from ...states import state
from ...utils.algorithms import linear_interpolation
from ...utils.notification import notify
from ...utils.ui import redraw_area
from .app_state import set_requesting
Expand Down Expand Up @@ -78,13 +79,6 @@ def pos_frame_neighbors(
)


def linear_interpolation(lval: float, ldist: int, rval: float, rdist: int):
if ldist == 0 and rdist == 0:
return lval
else:
return (lval * float(rdist) + rval * float(ldist)) / float(ldist + rdist)


async def add_pos_frame():
if not bpy.context:
return
Expand Down
39 changes: 39 additions & 0 deletions editor-blender/core/actions/state/timeline.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Literal

import bpy

from ...models import Editor
Expand All @@ -7,18 +9,37 @@
def increase_frame_index():
if not bpy.context:
return

match state.editor:
case Editor.CONTROL_EDITOR:
sorted_ctrl_frames = sorted(
[item[1].start for item in state.control_map.items()]
)
current_frame_index = state.current_control_index

if current_frame_index < len(state.control_record) - 1:
if (
sorted_ctrl_frames[current_frame_index + 1]
>= state.dancer_load_frames[1]
):
return
setattr(
bpy.context.window_manager,
"ld_current_frame_index",
str(current_frame_index + 1),
)
case Editor.POS_EDITOR:
sorted_pos_frames = sorted(
[item[1].start for item in state.pos_map.items()]
)
current_frame_index = state.current_pos_index

if current_frame_index < len(state.pos_record) - 1:
if (
sorted_pos_frames[current_frame_index + 1]
>= state.dancer_load_frames[1]
):
return
setattr(
bpy.context.window_manager,
"ld_current_frame_index",
Expand All @@ -33,16 +54,34 @@ def decrease_frame_index():
return
match state.editor:
case Editor.CONTROL_EDITOR:
sorted_ctrl_frames = sorted(
[item[1].start for item in state.control_map.items()]
)
current_frame_index = state.current_control_index

if current_frame_index > 0:
if (
sorted_ctrl_frames[current_frame_index]
<= state.dancer_load_frames[0]
):
return
setattr(
bpy.context.window_manager,
"ld_current_frame_index",
str(current_frame_index - 1),
)
case Editor.POS_EDITOR:
sorted_pos_frames = sorted(
[item[1].start for item in state.pos_map.items()]
)
current_frame_index = state.current_pos_index

if current_frame_index > 0:
if (
sorted_pos_frames[current_frame_index]
<= state.dancer_load_frames[0]
):
return
setattr(
bpy.context.window_manager,
"ld_current_frame_index",
Expand Down
13 changes: 10 additions & 3 deletions editor-blender/core/utils/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def binary_search(arr: list[int], x: int) -> int:
return r


def _binary_search_with_lr(
def binary_search_for_neighbors(
arr: list[int], x: int
) -> (
tuple[int, int]
Expand Down Expand Up @@ -59,8 +59,8 @@ def binary_search_for_range(arr: list[int], left: int, right: int) -> tuple[int,
:param left, right: designated range
:return: the smallest continuous range in arr that includes [left, right], which is in the form of indexes
"""
search_l = _binary_search_with_lr(arr, left)[0]
search_r = _binary_search_with_lr(arr, right)[1]
search_l = binary_search_for_neighbors(arr, left)[0]
search_r = binary_search_for_neighbors(arr, right)[1]

if search_l == "OutOfRange_Larger":
return (len(arr) - 1, len(arr) - 1)
Expand All @@ -71,3 +71,10 @@ def binary_search_for_range(arr: list[int], left: int, right: int) -> tuple[int,
if search_r == "OutOfRange_Larger":
search_r = len(arr) - 1
return (search_l, search_r)


def linear_interpolation(lval: float, ldist: int, rval: float, rdist: int):
if ldist == 0 and rdist == 0:
return lval
else:
return (lval * float(rdist) + rval * float(ldist)) / float(ldist + rdist)
5 changes: 4 additions & 1 deletion editor-blender/operators/editor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,10 @@ def poll(cls, context: bpy.types.Context | None):
return state.ready and ld_ui_led_editor.edit_effect != ""

else:
return state.ready
shown_all_dancer = reduce(
lambda acc, cur: acc & cur, state.show_dancers, True
)
return state.ready and shown_all_dancer

async def async_execute(self, context: bpy.types.Context):
confirm: bool = getattr(self, "confirm")
Expand Down
4 changes: 1 addition & 3 deletions editor-blender/operators/load/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
# import state
class LoadPartialOperator(AsyncOperator):
bl_idname = "lightdance.load_partial"
bl_label = "Load frames for selected dancers"
# bl_label = "Load frames in selected interval"
bl_label = "Load frames of selected dancers and time interval"

async def async_execute(self, context: bpy.types.Context):
# TODO
set_state_of_dancer_selection()
set_state_of_loaded_frame_range()
await init_load()
Expand Down
3 changes: 3 additions & 0 deletions editor-blender/operators/timeline/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import bpy

from ...core.actions.state.timeline import decrease_frame_index, increase_frame_index
from ...core.models import Editor
from ...core.states import state
from ...core.utils.algorithms import binary_search_for_neighbors


class IncreaseFrameIndex(bpy.types.Operator):
Expand Down
9 changes: 5 additions & 4 deletions editor-blender/panels/lightdance/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from typing import Any

import bpy
from bpy.types import Context, UILayout

from ...core.states import state
from ...properties.types import Preferences
Expand Down Expand Up @@ -44,8 +43,8 @@ class LD_UL_PartialDancerLoad(bpy.types.UIList):

def draw_item(
self,
context: Context | None,
layout: UILayout,
context: bpy.types.Context | None,
layout: bpy.types.UILayout,
data: Any | None,
item: DancerSelectionType | None,
icon: int | None,
Expand All @@ -61,7 +60,9 @@ def draw_item(
row.prop(item, "shown", text="", emboss=True)
row.label(text=item.name)

def draw_filter(self, context: Context | None, layout: UILayout):
def draw_filter(
self, context: bpy.types.Context | None, layout: bpy.types.UILayout
):
row = layout.row()
row.prop(self, "select_all_connect", text="Select all connected RPi")
row.prop(self, "select_all", text="Select all RPi")
Expand Down
7 changes: 7 additions & 0 deletions editor-blender/properties/ui/frame_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ def update_frame_range_min(self, _):
if self.ld_ui_frame_range_min >= self.ld_ui_frame_range_max:
self.ld_ui_frame_range_min = self.ld_ui_frame_range_max - 1

if not bpy.context or not bpy.context.scene:
return
bpy.context.scene.frame_start = self.ld_ui_frame_range_min


def update_frame_range_max(self, _):
if (
Expand All @@ -16,6 +20,9 @@ def update_frame_range_max(self, _):
self.ld_ui_frame_range_max = state.partial_load_frames[1]
elif self.ld_ui_frame_range_max <= self.ld_ui_frame_range_min:
self.ld_ui_frame_range_max = self.ld_ui_frame_range_min + 1
if not bpy.context or not bpy.context.scene:
return
bpy.context.scene.frame_end = self.ld_ui_frame_range_max


def register():
Expand Down

0 comments on commit d9ca256

Please sign in to comment.