Refactor: Move asset editing code into own file and refactor #119888

Merged
Brecht Van Lommel merged 2 commits from brecht/blender:refactor-brush into brush-assets-project 2024-03-29 17:23:39 +01:00
  • Move from paint_ops.cc and asset_weak_reference.cc into asset_edit.cc
  • Rename AssetWeakReferenceMain to AssetEditBlend
  • Change some functions to be based on ID instead of main pointer
  • Make most of save as and update code no longer brush specific
* Move from paint_ops.cc and asset_weak_reference.cc into asset_edit.cc * Rename AssetWeakReferenceMain to AssetEditBlend * Change some functions to be based on ID instead of main pointer * Make most of save as and update code no longer brush specific
Brecht Van Lommel added 1 commit 2024-03-25 18:32:33 +01:00
ab3dbdc048 Refactor: Move asset editing code into own file and refactor
* Move from paint_ops.cc and asset_weak_reference.cc into asset_edit.cc
* Rename AssetWeakReferenceMain to AssetEditBlend
* Change some functions to be based on ID instead of main pointer
* Make most of save as and update code no longer brush specific.
Brecht Van Lommel requested review from Julian Eisel 2024-03-25 18:33:27 +01:00
Brecht Van Lommel requested review from Hans Goudey 2024-03-25 18:33:27 +01:00
Hans Goudey approved these changes 2024-03-25 19:04:56 +01:00
Hans Goudey left a comment
Member

Just a few sort of nitpicky comments

Just a few sort of nitpicky comments
@ -0,0 +51,4 @@
const ID *id,
const char *name,
std::optional<blender::asset_system::CatalogID> catalog_id,
std::optional<const std::string> catalog_simple_name,
Member

Not sure const is meaningful here, since it's passed by value

Not sure `const` is meaningful here, since it's passed by value
brecht marked this conversation as resolved
@ -0,0 +37,4 @@
#include "MEM_guardedalloc.h"
using namespace blender;
Member

I'd rather put all the new code in the blender::bke namespace (replacing the BKE_ prefix on the functions. It could even be a nested namespace like blender::bke::asset_edit, though I don't feel strongly about that.

Could also be done separately from this commit though

I'd rather put all the new code in the `blender::bke` namespace (replacing the `BKE_` prefix on the functions. It could even be a nested namespace like `blender::bke::asset_edit`, though I don't feel strongly about that. Could also be done separately from this commit though
brecht marked this conversation as resolved
@ -0,0 +42,4 @@
/**
* Asset library blend file, with editable contents.
*/
Member

Unnecessary newline

Unnecessary newline
brecht marked this conversation as resolved
@ -0,0 +405,4 @@
return final_full_asset_filepath;
}
bool BKE_asset_edit_id_save(Main & /* global_main */, const ID *id, ReportList *reports)
Member

/* global_main */ -> /*global_main*/

`/* global_main */` -> `/*global_main*/`
brecht marked this conversation as resolved
Julian Eisel reviewed 2024-03-26 15:45:29 +01:00
Julian Eisel left a comment
Member

Nice, definitely an improvement. Quick check with minor comments.

One thing I'm not too fond of (and this is already an issue in the original code) is that this adds more ad hoc asset importing code. I'd hope we'd be able to just call a virtual import function on the asset library that takes care of everything. If for every use case we have own importing code there's more potential for error, and it gets complicated if more asset types are introduced. For now it's mostly IDs imported from disk, but that will hopefully change in future.
But I guess that's something for later.

Nice, definitely an improvement. Quick check with minor comments. One thing I'm not too fond of (and this is already an issue in the original code) is that this adds more ad hoc asset importing code. I'd hope we'd be able to just call a virtual import function on the asset library that takes care of everything. If for every use case we have own importing code there's more potential for error, and it gets complicated if more asset types are introduced. For now it's mostly IDs imported from disk, but that will hopefully change in future. But I guess that's something for later.
@ -0,0 +29,4 @@
#include "AS_asset_catalog.hh"
#include "DNA_ID_enums.h"
#include "DNA_asset_types.h"
Member

Don't think this is needed?

Don't think this is needed?
brecht marked this conversation as resolved
@ -0,0 +36,4 @@
struct Main;
struct ReportList;
/* Get datablock from weak reference, loading the blend file as needed. */
Member

Would make these doxygen comments.

Would make these doxygen comments.
brecht marked this conversation as resolved
@ -0,0 +179,4 @@
while (BLI_is_file((root_path + SEP + base_name_filesafe + "_" + std::to_string(i++) +
BLENDER_ASSET_FILE_SUFFIX)
.c_str()))
;
Member

The guidelines are to always use braces. To make this more readable, I'd suggest this:

int i = 1;
while (...) {
  i++;
}

Also, I'd hope that the compiler optimizes this, but this could potentially allocate multiple strings for each iteration, so maybe better to create some const base path string.

The guidelines are to [always use braces](https://developer.blender.org/docs/handbook/guidelines/c_cpp/#always-use-braces). To make this more readable, I'd suggest this: ```c int i = 1; while (...) { i++; } ``` Also, I'd hope that the compiler optimizes this, but this could potentially allocate multiple strings for each iteration, so maybe better to create some `const` base path string.
brecht marked this conversation as resolved
Brecht Van Lommel added 1 commit 2024-03-29 17:22:27 +01:00
Brecht Van Lommel merged commit ba71fa3909 into brush-assets-project 2024-03-29 17:23:39 +01:00
Brecht Van Lommel deleted branch refactor-brush 2024-03-29 17:23:44 +01:00
Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#119888
No description provided.