Skip to content

Commit

Permalink
EDITOR-#512 [BLENDER] animation data update (#513)
Browse files Browse the repository at this point in the history
* enabled LED keyframe loading, bugs fixed

* update animation data when applying changes to position map and control map

* bug fixes

* clear viewport before importing models, fetch uncompressed glb files instead of draco.glb files

* fixed type init in load

* display fade in timeline as ld_control_frame keyframes

* added models to asset as collections to enable lazy import

* add rev keyframe

* separate init_control_map from load

* change alpha display, minor fixes

* enabled lazy loading, revision management (untested)

* fixed iteration bug

* add ld_model_name bpy prop
  • Loading branch information
Chalkman071 authored Feb 5, 2024
1 parent 68809aa commit 5b3e443
Show file tree
Hide file tree
Showing 15 changed files with 962 additions and 754 deletions.
642 changes: 642 additions & 0 deletions editor-blender/core/actions/property/animation_data.py

Large diffs are not rendered by default.

19 changes: 13 additions & 6 deletions editor-blender/core/actions/property/lights.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ def update_current_color(self: bpy.types.Object, context: bpy.types.Context):
return

color_id: int = self["ld_color"]
ld_alpha: int = self["ld_alpha"]
color = state.color_map[color_id]
color_float = rgb_to_float(color.rgb)

self.color[0] = color_float[0]
self.color[1] = color_float[1]
self.color[2] = color_float[2]
self.color[0] = color_float[0] * (ld_alpha / 255)
self.color[1] = color_float[1] * (ld_alpha / 255)
self.color[2] = color_float[2] * (ld_alpha / 255)


def update_current_effect(self: bpy.types.Object, context: bpy.types.Context):
Expand Down Expand Up @@ -76,10 +77,16 @@ def update_current_alpha(self: bpy.types.Object, context: bpy.types.Context):

ld_light_type: str = getattr(self, "ld_light_type")
ld_alpha: int = getattr(self, "ld_alpha")

color_id: int = self["ld_color"]
color = state.color_map[color_id]
color_float = rgb_to_float(color.rgb)
if ld_light_type == LightType.LED.value:
led_bulb_objs: List[bpy.types.Object] = getattr(self, "children")
for led_bulb_obj in led_bulb_objs:
led_bulb_obj.color[3] = ld_alpha / 255
led_bulb_obj.color[0] = color_float[0] * (ld_alpha / 255)
led_bulb_obj.color[1] = color_float[1] * (ld_alpha / 255)
led_bulb_obj.color[2] = color_float[2] * (ld_alpha / 255)
else:
self.color[3] = ld_alpha / 255
self.color[0] = color_float[0] * (ld_alpha / 255)
self.color[1] = color_float[1] * (ld_alpha / 255)
self.color[2] = color_float[2] * (ld_alpha / 255)
65 changes: 65 additions & 0 deletions editor-blender/core/actions/property/revision.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
from typing import List

import bpy

from ....properties.revision import KeyframeRevisionItem
from ...models import ControlMap, MapID, PosMap
from .animation_data import (
add_single_ctrl_keyframe,
add_single_pos_keyframe,
delete_single_ctrl_keyframe,
delete_single_pos_keyframe,
edit_single_ctrl_keyframe,
edit_single_pos_keyframe,
)


def update_rev_changes(incoming_pos_map: PosMap, incoming_control_map: ControlMap):
# position
local_rev: List[KeyframeRevisionItem] = getattr(bpy.context.scene, "ld_pos_rev")
incoming_rev = {id: element.rev for id, element in incoming_pos_map.items()}
for rev in local_rev:
local_id: MapID = rev.frame_id
if local_id not in incoming_rev.keys(): # delete
delete_single_pos_keyframe(local_id, rev.frame_start)
del incoming_rev[local_id]
else:
incoming_rev_item = incoming_rev[local_id]
if incoming_rev_item:
if (
incoming_rev_item.data == rev.data
and incoming_rev_item.meta == rev.meta
and rev.data > 0
and rev.meta > 0
): # local animation data matches incoming
continue
else:
edit_single_pos_keyframe(local_id, incoming_pos_map[rev.frame_id])
del incoming_rev[local_id]
for id in incoming_rev.keys():
add_single_pos_keyframe(id, incoming_pos_map[id])
# control
local_rev: List[KeyframeRevisionItem] = getattr(bpy.context.scene, "ld_ctrl_rev")
incoming_rev = {id: element.rev for id, element in incoming_pos_map.items()}
for rev in local_rev:
local_id: MapID = rev.frame_id
if local_id not in incoming_rev.keys(): # delete
delete_single_ctrl_keyframe(local_id, rev.frame_start)
del incoming_rev[local_id]
else:
incoming_rev_item = incoming_rev[local_id]
if incoming_rev_item:
if (
incoming_rev_item.data == rev.data
and incoming_rev_item.meta == rev.meta
and rev.data > 0
and rev.meta > 0
): # local animation data matches incoming
continue
else:
edit_single_ctrl_keyframe(
local_id, incoming_control_map[rev.frame_id]
)
del incoming_rev[local_id]
for id in incoming_rev.keys():
add_single_ctrl_keyframe(id, incoming_control_map[id])
8 changes: 5 additions & 3 deletions editor-blender/core/actions/state/color_map.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from ...models import Color, ColorID, ColorMap, EditMode
import bpy

from ...models import Color, ColorID, ColorMap, EditMode, FiberData, LEDData
from ...states import state
from ...utils.notification import notify
from ...utils.ui import redraw_area
from .color_palette import setup_color_palette_from_state
from .load import set_ctrl_keyframes_from_state


def set_color_map(color_map: ColorMap):
Expand Down Expand Up @@ -87,6 +90,7 @@ def apply_color_map_updates():

for color in color_map_updates.updated:
state.color_map[color.id] = color
set_ctrl_keyframes_from_state() # TODO: test this

for color_id in color_map_updates.deleted:
del state.color_map[color_id]
Expand All @@ -95,8 +99,6 @@ def apply_color_map_updates():
color_map_updates.updated.clear()
color_map_updates.deleted.clear()

# TODO: Update animation data

setup_color_palette_from_state(state.color_map)

state.color_map_pending = False
Expand Down
12 changes: 9 additions & 3 deletions editor-blender/core/actions/state/control_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
from ...states import state
from ...utils.notification import notify
from ...utils.ui import redraw_area
from ..property.animation_data import (
add_single_ctrl_keyframe,
delete_single_ctrl_keyframe,
edit_single_ctrl_keyframe,
)
from .current_status import (
calculate_current_status_index,
update_current_status_by_index,
Expand Down Expand Up @@ -51,7 +56,7 @@ def delete_control(id: MapID):
control_map_updates.deleted.append(id)

if state.edit_state == EditMode.EDITING:
state.pos_map_pending = True
state.control_map_pending = True
redraw_area({"VIEW_3D", "DOPESHEET_EDITOR"})
else:
apply_control_map_updates()
Expand Down Expand Up @@ -86,15 +91,16 @@ def update_control(id: MapID, frame: ControlMapElement):
def apply_control_map_updates():
control_map_updates = state.control_map_updates

# TODO: Update animation data

for status in control_map_updates.added:
add_single_ctrl_keyframe(status[0], status[1])
state.control_map[status[0]] = status[1]

for status in control_map_updates.updated:
edit_single_ctrl_keyframe(status[0], status[1])
state.control_map[status[0]] = status[1]

for id in control_map_updates.deleted:
delete_single_ctrl_keyframe(id)
del state.control_map[id]

control_map_updates.added.clear()
Expand Down
3 changes: 0 additions & 3 deletions editor-blender/core/actions/state/current_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,3 @@ def update_current_status_by_index():

alpha = part_status.alpha
setattr(part_obj, "ld_alpha", alpha)

# WARNING: Testing
break
4 changes: 2 additions & 2 deletions editor-blender/core/actions/state/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def setup_control_editor():
outliner_hide_one_level()
outliner_hide_one_level()

set_dopesheet_filter("control")
set_dopesheet_filter("control_frame")
state.editor = Editor.CONTROL_EDITOR


Expand All @@ -52,7 +52,7 @@ def setup_pos_editor():
outliner_hide_one_level()
outliner_hide_one_level()

set_dopesheet_filter("pos")
set_dopesheet_filter("pos_frame")
state.editor = Editor.POS_EDITOR


Expand Down
Loading

0 comments on commit 5b3e443

Please sign in to comment.