-
Notifications
You must be signed in to change notification settings - Fork 48
WIP: speedup light effects by using shared material for drones #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
vasarhelyi
wants to merge
16
commits into
main
Choose a base branch
from
feat/speedup-light-effects
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
34722df
feat: speedup light effects by using shared material of drones
vasarhelyi 69d63cb
fix: fix find_all_f_curves_for_data_path() to return curves sorted by…
vasarhelyi 1d4c33c
feat: add migration operator to convert old blender files with one ma…
vasarhelyi a92784e
fix: set both solid and wireframe color to object color in all views …
vasarhelyi b512593
fixup! fix: set both solid and wireframe color to object color in all…
vasarhelyi 827a44f
fix: add logging to migration operator
vasarhelyi 5a1bf1a
fix: configure logging explicitly as in Blender 4.5 default log level…
vasarhelyi f435f3b
feat: add MigrationOperator for automatic user-confirmed migration op…
vasarhelyi addb96f
feat: add internal version number for automating migration handling
vasarhelyi 67e43cf
fix: do not mess around with logging as a default init call
vasarhelyi a6ed36f
fix: update viewport object and wireframe colors properly on all acti…
vasarhelyi 3e22659
feat: add warnings to panels on version, formation size or shading co…
vasarhelyi 9e5e14e
Merge branch 'main' into feat/speedup-light-effects
vasarhelyi 63f56d9
Merge branch 'main' into feat/speedup-light-effects
vasarhelyi a391b29
fix: do not use __annotations__ when getting latest version
vasarhelyi 77a6a85
fix: several small fixes based on review from @ntamas
vasarhelyi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import bpy | ||
|
||
from sbstudio.model.types import RGBAColor, RGBAColorLike | ||
from sbstudio.plugin.actions import ensure_action_exists_for_object | ||
from sbstudio.plugin.keyframes import set_keyframes | ||
|
||
__all__ = ( | ||
"create_keyframe_for_color_of_drone", | ||
"get_color_of_drone", | ||
"set_color_of_drone", | ||
) | ||
|
||
is_blender_4 = bpy.app.version >= (4, 0, 0) | ||
|
||
|
||
def create_keyframe_for_color_of_drone( | ||
drone, | ||
color: tuple[float, float, float] | tuple[float, float, float, float] | RGBAColor, | ||
*, | ||
frame: int | None = None, | ||
step: bool = False, | ||
): | ||
"""Creates color keyframes for the given drone to set | ||
in the given frame. | ||
|
||
Parameters: | ||
drone: the drone object to modify | ||
color: the RGB color to use for the color of the drone | ||
frame: the frame to apply the color on; `None` means the | ||
current frame | ||
step: whether to insert an additional keyframe in the preceding frame to | ||
ensure an abrupt transition | ||
""" | ||
if frame is None: | ||
frame = bpy.context.scene.frame_current | ||
|
||
ensure_action_exists_for_object(drone) | ||
|
||
if hasattr(color, "r"): | ||
color_as_rgba = color.r, color.g, color.b, 1.0 | ||
else: | ||
color_as_rgba = color[0], color[1], color[2], 1.0 | ||
|
||
keyframes = [(frame, color_as_rgba)] | ||
if step and frame > bpy.context.scene.frame_start: | ||
keyframes.insert(0, (frame - 1, None)) | ||
|
||
set_keyframes(drone, "color", keyframes, interpolation="LINEAR") | ||
|
||
|
||
def get_color_of_drone(drone) -> RGBAColor: | ||
"""Returns the color of the LED light on the given drone. | ||
|
||
Parameters: | ||
drone: the drone to query | ||
color: the color to apply to the LED light of the drone | ||
""" | ||
if drone.color is not None: | ||
return drone.color | ||
|
||
return (0.0, 0.0, 0.0, 0.0) | ||
|
||
|
||
def set_color_of_drone(drone, color: RGBAColorLike): | ||
"""Sets the color of the LED light on the given drone. | ||
|
||
Parameters: | ||
drone: the drone to update | ||
color: the color to apply to the LED light of the drone | ||
""" | ||
drone.color = color |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm I wonder whether this will be okay this way. On one hand, we need to make sure that any already-saved Blender file without this property starts from version 1 because they do not have a shared material so we need to upgrade them. On the other hand, we also need to make sure that newly created Blender files start from version 2.
Can you check whether this is how it works at the moment? I'm afraid that newly created files will start from version 1 and won't go through an upgrade cycle until they are saved first and loaded back again.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I double checked this, it is OK I think. I deliberately start with version 1 on empty as well to be able to go though all migrations properly on init. And confirmed that when I open a new Blender file then
bpy.context.scene.skybrush.version
will be 2 after init. Seeperform_migrations()
inInitializationTask
. Theneeds_migration()
property ofUseSharedMaterialForAllDronesMigrationOperator
returns False if there are no drones yet (empty Blender file), and thus theMigrationOperator
sexecute()
will simply return{"FINISHED"}
without callingexecute_migration()
.