Asset System: New "weak" asset reference for storing in .blend files #105603

Merged
Julian Eisel merged 41 commits from JulianEisel/blender:temp-asset-weak-reference into main 2023-03-30 12:25:54 +02:00
Member

No user visible changes expected.

For brush assets, we need a way to store a reference to a brush in .blend files, so that the last active brush can be restored from the file. See #101908. It seems like a generally useful thing to have.

Adds a new DNA struct to store a "weak" asset reference, that is, a reference that can break under a number of circumstances, but should work reliably enough under normal usage. There's no way to reliably reference an asset currently, so this works on a "best effort" basis. It can break when assets are moved inside the asset library, asset libraries are unregistered from the Preferences, or a file is opened on a different machine with different Preferences, for example. It can also break currently if an asset library is renamed.
It contains:

  • Information to identify the asset library the asset can be found in.
  • A relative "identifier" (currently a relative path) for the asset within the asset library.

Part of #101908.


Notes:

  • A bunch of changes were needed to store a name in the asset library. Not too happy with this, hopefully this can be improved with custom asset library loaders instead of the current confusing loading code.
  • Includes unit tests
  • I included C++ methods in DNA structs inside #ifdef __cplusplus blocks. Some node files do this and I think it's handy here too.
No user visible changes expected. For brush assets, we need a way to store a reference to a brush in .blend files, so that the last active brush can be restored from the file. See #101908. It seems like a generally useful thing to have. Adds a new DNA struct to store a "weak" asset reference, that is, a reference that can break under a number of circumstances, but should work reliably enough under normal usage. There's no way to reliably reference an asset currently, so this works on a "best effort" basis. It can break when assets are moved inside the asset library, asset libraries are unregistered from the Preferences, or a file is opened on a different machine with different Preferences, for example. It can also break currently if an asset library is renamed. It contains: - Information to identify the asset library the asset can be found in. - A relative "identifier" (currently a relative path) for the asset within the asset library. Part of #101908. --- Notes: - A bunch of changes were needed to store a name in the asset library. Not too happy with this, hopefully this can be improved with custom asset library loaders instead of the current confusing loading code. - Includes unit tests - I included C++ methods in DNA structs inside `#ifdef __cplusplus` blocks. Some node files do this and I think it's handy here too.
Julian Eisel added 9 commits 2023-03-09 15:56:30 +01:00
Julian Eisel requested review from Bastien Montagne 2023-03-09 16:11:30 +01:00
Julian Eisel added the
Interest
Asset Browser
Module
Pipeline, Assets & IO
labels 2023-03-09 16:11:48 +01:00
Julian Eisel added this to the Brush Assets & Asset Shelf project 2023-03-09 16:11:53 +01:00
Author
Member

@blender-bot build

@blender-bot build
Julian Eisel added 1 commit 2023-03-09 16:45:21 +01:00
buildbot/vexp-code-patch-coordinator Build done. Details
3e844fb2dc
Attempt to fix linker error on GCC
Author
Member

@blender-bot build

@blender-bot build
Julian Eisel added 1 commit 2023-03-16 15:10:14 +01:00
Julian Eisel added 2 commits 2023-03-16 18:02:50 +01:00
Julian Eisel added 3 commits 2023-03-22 12:44:05 +01:00
693be95b2d Some refactoring for function to resolve to an exploded path
- Use (arguably) more readable return type instead of return arguments.
- Update function API comment.
- Use more clear (because more direct) return values
Bastien Montagne approved these changes 2023-03-22 14:43:06 +01:00
Bastien Montagne left a comment
Owner

Generally LGTM, besides minor notes below.

Would be good to thin, about a better, more resiliant way to identify asset repositories and their assets, but this is out of scope of this patch.

Generally LGTM, besides minor notes below. Would be good to thin, about a better, more resiliant way to identify asset repositories and their assets, but this is out of scope of this patch.
@ -46,0 +50,4 @@
* path is not guaranteed to exist on disk. On failure to resolve the reference, return arguments
* will point to null.
*
* \note Only works for asset libraries on disk (others can't be resolved).

also for the current file actually ;)

also for the current file actually ;)
JulianEisel marked this conversation as resolved
@ -130,0 +147,4 @@
if (r_name) {
*r_name = nullptr;
}
return;

Should set r_path_buffer to empty string (r_path_buffer[0] = '\0';)

Should set `r_path_buffer` to empty string (`r_path_buffer[0] = '\0';`)
JulianEisel marked this conversation as resolved
@ -79,0 +90,4 @@
struct ExplodedPath {
/* The string buffer containing the fully resolved path, if resolving was successful. */
std::string full_path = "";
/* Reference into the part of #full_path that is the directory path. */

(i.e. the path to the library .blend file included)?

`(i.e. the path to the library .blend file included)`?
JulianEisel marked this conversation as resolved

@blender-bot build

@blender-bot build

@blender-bot build

@blender-bot build
Julian Eisel added 1 commit 2023-03-23 11:42:30 +01:00
Julian Eisel added 1 commit 2023-03-23 12:11:54 +01:00
Julian Eisel added 1 commit 2023-03-23 12:21:36 +01:00
Julian Eisel added 1 commit 2023-03-23 12:22:13 +01:00
buildbot/vexp-code-patch-coordinator Build done. Details
974ebe4864
Merge branch 'main' into temp-asset-weak-reference
Author
Member

@blender-bot build

@blender-bot build
Bastien Montagne added 1 commit 2023-03-23 17:51:56 +01:00
buildbot/vexp-code-patch-coordinator Build done. Details
ce2ef6b9cc
Merge branch 'main' into temp-asset-weak-reference

@blender-bot build

@blender-bot build
Julian Eisel added 1 commit 2023-03-24 11:47:19 +01:00
Julian Eisel added 2 commits 2023-03-24 15:15:20 +01:00
buildbot/vexp-code-patch-coordinator Build done. Details
4710dc0337
Fix test failure on macOS because of short string optimization of moved result
Since we pass around a struct with a string, and multiple string-references
into this string, we have to make sure the memory address of the string buffer
never changes. It would seem that move semantics give this behavior, but it
wouldn't work for short strings. When moving a string, short string
optimization would still require the string to be copied, not moved, causing a
change in the memory address. GCC and Clang use different definitions of "short
string", causing differences in behavior.

Wrap the string in a unique pointer, so the string itself is never moved or
copied.
Author
Member

@blender-bot build

@blender-bot build
Bastien Montagne added 2 commits 2023-03-28 15:18:22 +02:00

@blender-bot build

@blender-bot build
Bastien Montagne added 1 commit 2023-03-28 16:57:35 +02:00
buildbot/vexp-code-patch-coordinator Build done. Details
ba73275532
Further fixes to path handling.
debug prints are intended for now.

@blender-bot build

@blender-bot build

@blender-bot build

@blender-bot build

@blender-bot build windows

@blender-bot build windows

@blender-bot build windows

@blender-bot build windows
Bastien Montagne added 1 commit 2023-03-28 20:12:35 +02:00
Bastien Montagne added 1 commit 2023-03-28 20:19:40 +02:00
Bastien Montagne added 1 commit 2023-03-28 20:32:27 +02:00
buildbot/vexp-code-patch-coordinator Build done. Details
3dc872af0e
More fixes.

@blender-bot build

@blender-bot build
Bastien Montagne added 1 commit 2023-03-29 11:04:53 +02:00
Bastien Montagne added 1 commit 2023-03-29 11:05:10 +02:00
buildbot/vexp-code-patch-coordinator Build done. Details
e8bd93685b
Cleanup.

@blender-bot build

@blender-bot build
Julian Eisel added 1 commit 2023-03-29 15:20:28 +02:00
Julian Eisel added 5 commits 2023-03-29 18:21:08 +02:00
a943c68d42 Avoid unsigned <-> signed integer casts
No need for these, just use `StringRef`/`StringRefNull` for string
queries. These use signed integers only.
Unit tests fail now, unveiling an issue hidden by the casts. Fix
incoming.
e58fa6de99 Fix failing unit tests after previous fix, was hidden by casts
Casting `StringRef::not_found` which is -1 to an unsigned int would make
the `std::min()` check behave as intended when no path separator was
found, but without the casts it would always give the -1.
e93f1868ec Cleanup: More clear naming, comments, etc
Attempt at making code generally more readable (arguably). Also fix
wrong integer type use.
Julian Eisel added 1 commit 2023-03-29 18:32:32 +02:00
buildbot/vexp-code-patch-coordinator Build done. Details
a2597f98ab
Small readability improvement
Author
Member

@blender-bot build

@blender-bot build
Julian Eisel added 1 commit 2023-03-30 11:15:44 +02:00
Julian Eisel added 1 commit 2023-03-30 11:26:22 +02:00
buildbot/vexp-code-patch-coordinator Build done. Details
aac318fe3c
Fix crash in unit tests
Own error in a2597f98ab.
Author
Member

@blender-bot build

@blender-bot build
Julian Eisel merged commit d90795bc3c into main 2023-03-30 12:25:54 +02:00
Julian Eisel deleted branch temp-asset-weak-reference 2023-03-30 12:25:55 +02: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 Assignees
2 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#105603
No description provided.