Commit Graph

26 Commits

Author SHA1 Message Date
Hans Goudey f8e8e3ac8c Cleanup: Use utility mixins for AssetRepresentation 2024-03-28 13:43:20 -04:00
Hans Goudey 8ab23f0a6e Assets: Return weak reference by value from asset representation
This is generally more flexible and less error prone. The struct
implements a proper descructorfor this anyway. That also makes the
separate free function unnecessary-- it's redundant with the destructor.
2024-02-16 12:02:08 -05:00
Julian Eisel 6d387b3ba8 Cleanup: Use reference where null asset library is not possible
It should not be possible to end up with an asset representation that
does not have a valid pointer/reference to the asset library owning it,
it's injected via all constructors. So reflect that by using a reference
instead of a (possibly null) pointer.
2024-02-16 16:53:36 +01:00
Julian Eisel a5a3125fe1 Refactor: Remove unused move constructor for asset representation
This shouldn't be needed, and was incorrect anyway: It wasn't copying
the owner asset library pointer.
2024-02-16 16:38:14 +01:00
Thomas Dinges 64fc6d7890 Docs: Replace most wiki links with links to new developer docs
Exceptions:
* Links to personal wiki pages
* Pages that are not in the new developer docs yet (like Human Interface Guidelines)
* tools\check_wiki\check_wiki_file_structure.py needs a refactor
2024-01-18 16:49:38 +01:00
Julian Eisel 567e3b9b19 Assets: Always use guarded allocator for weak references
Although I don't like the idea of using owning raw pointers in new APIs
like this (violates fundamental C++ good practises), this type is mostly
meant for writing to files via DNA. So we have to use Blender's memory
management via the guarded allocator here.

Considered making this an alternative function, but then we'd have to
duplicate logif or duplicate memory or so. Not worth it to me.
2023-08-29 13:49:58 +02:00
Campbell Barton e955c94ed3 License Headers: Set copyright to "Blender Authors", add AUTHORS
Listing the "Blender Foundation" as copyright holder implied the Blender
Foundation holds copyright to files which may include work from many
developers.

While keeping copyright on headers makes sense for isolated libraries,
Blender's own code may be refactored or moved between files in a way
that makes the per file copyright holders less meaningful.

Copyright references to the "Blender Foundation" have been replaced with
"Blender Authors", with the exception of `./extern/` since these this
contains libraries which are more isolated, any changed to license
headers there can be handled on a case-by-case basis.

Some directories in `./intern/` have also been excluded:

- `./intern/cycles/` it's own `AUTHORS` file is planned.
- `./intern/opensubdiv/`.

An "AUTHORS" file has been added, using the chromium projects authors
file as a template.

Design task: #110784

Ref !110783.
2023-08-16 00:20:26 +10:00
Hans Goudey 1b4b90f5f7 Cleanup: Remove unnecessary C API for asset representation
Now that almost all code is in C++, this is unnecessary and
just confuses things with multiple entry points to the same code.

Pull Request: https://projects.blender.org/blender/blender/pulls/109661
2023-07-04 14:46:19 +02:00
Julian Eisel 92ff750bbf Refactor: Get rid of asset handle for drag & drop
`AssetHandle` is meant as temporary design and should be replaced by
`AssetRepresentation`. This moves us another step closer to that.

Rather than taking data from the volatile asset handle and storing that
in the drag data, store the (more persistent) asset representation there
and access data from it where needed.
2023-06-09 15:19:41 +02:00
Julian Eisel 0044c93e84 Cleanup: Use ID type enum instead of unsafe integer
Adds type safety and removes need for explicit casts.
2023-06-09 12:27:23 +02:00
Julian Eisel 631e5d5d4f Asset system: Store ID type in asset representation
No user visible changes expected.

This brings us another step closer to replacing the temporary asset
handle design with the proper asset representation design. I held off
with this a bit because we eventually want to support non-ID assets, but
for now it is fine to consider all assets to be IDs. In future the asset
system can make the necessary distinctions still.

Now only the preview is handled via asset handle still.
2023-06-08 20:55:10 +02:00
Julian Eisel 4394de611f Asset system: Add public functions for asset identifier query
No user visible changes expected.

This is needed in #104831 but makes sense to expose publicly in the
asset system APIs either way. So committing this to the main branch
already.
2023-06-08 18:51:00 +02:00
Sergey Sharybin c1bc70b711 Cleanup: Add a copyright notice to files and use SPDX format
A lot of files were missing copyright field in the header and
the Blender Foundation contributed to them in a sense of bug
fixing and general maintenance.

This change makes it explicit that those files are at least
partially copyrighted by the Blender Foundation.

Note that this does not make it so the Blender Foundation is
the only holder of the copyright in those files, and developers
who do not have a signed contract with the foundation still
hold the copyright as well.

Another aspect of this change is using SPDX format for the
header. We already used it for the license specification,
and now we state it for the copyright as well, following the
FAQ:

    https://reuse.software/faq/
2023-05-31 16:19:06 +02:00
Campbell Barton 823685db76 Cleanup: consistent doxygen comment blocks
Also remove doxygen block for comments in a functions body.
2023-05-27 15:10:58 +10:00
Dalai Felinto 5d0595fded Suport relative path option per-asset library
This option is true by default, but it can be changed for
any asset library (that may be using Link as import method).

This also fix "Reset to Default Value" for the Import Method
since this was originally not using the defaults.

Pull Request: https://projects.blender.org/blender/blender/pulls/107345
2023-04-25 20:56:57 +02:00
Julian Eisel d90795bc3c Asset System: New "weak" asset reference for storing in .blend files
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.

There's further code to resolve a weak reference to file paths and Blender library paths.

Part of #101908.

Co-authored-by: Bastien Montagne <bastien@blender.org>

Pull Request: https://projects.blender.org/blender/blender/pulls/105603
2023-03-30 12:25:42 +02:00
Julian Eisel a958ae36e8 Fix #104305: Crash in node editor with large asset libraries
Various UI code would store the `AssetHandle` in a way that turns out to
be unsafe. The file-data is part of the file browser caching system that
releases file-data when a certain maximum of items is in the cache. So
even while just iterating over the assets, earlier iterated asset
handles may become invalid. Now asset handles are really treated as
volatile, short lived objects.

For the asset-view, the fix was more involved. There we need an RNA
collection of asset-handles, because the UI list code requires that. So
we create a dummy collection and get the asset handles as needed by
index. This again meant that I had to keep the index of the collection
and the asset-list in sync, so all filtering had to be moved to the UI
list.
I tried duplicating the file-data out of the cache instead, but that
caused problems with managing the memory/ownership of the preview
images.

`AssetHandle` should be removed and replaced by `AssetRepresentation`,
but this would be an even more disruptive change (breaking API
compatibility too).

Fixes #104305, #105535.

Pull Request: #105773
2023-03-16 15:40:31 +01:00
Julian Eisel 55811b2919 Assets: Add function to query data-block library path from asset
No user visible change.

This is needed for #105773, but will cause conflicts in the main branch,
so committing it separately.
2023-03-16 15:25:00 +01:00
Julian Eisel ae84a2956e Assets: Preference for default import method for an asset library
The default import method for an asset library can now be determined in
the Preferences. The Asset Browser has a new "Follow Preferences" option
for the importing. The essentials asset library still only uses "Append
(Reuse Data)".

This is part of #104686, which aims at improving the import method
selection, especially for the introduction of the new essentials library
(which doesn't support certain import methods). Further changes are
coming to improve the UI, see #104686.

Pull Request: #104688
2023-02-15 12:51:23 +01:00
Julian Eisel 99e71ec1f2 Assets: Store pointer to owning asset library in asset representation
This is needed to be able to query asset library information from an
asset. This again is relevant especially for the "All" asset library,
where you can't just directly access the library itself, which is
different for different assets.

The current design is that an asset representation is owned by exactly
one asset library, so having this pointer is perfectly compatible with
the design.

Reviewed by: Julian Eisel
2023-02-13 12:57:03 +01:00
Julian Eisel f68da703a5 Asset system: Initial asset identifier type
No user visible changes expected.

`AssetIdentifier` holds information to uniquely identify and locate an
asset. More information:
https://wiki.blender.org/wiki/Source/Architecture/Asset_System/Back_End#Asset_Identifier

For the start this is tied quite a bit to file paths, so that external
assets are assumed to be in the file system.

This is needed to support an "All" asset library (see T102879), which
would contain assets from different locations. Currently the location of
an asset is queried via the file browser backend, which however requires
a common root location. It also moves us further away from the file
browser towards the asset system (see T87235) and allows us to remove
some hacks (see following commit).
2022-11-30 19:44:34 +01:00
Julian Eisel 0151d846e8 Fix MSVC warnings from recent asset system changes
* Mismatching class vs struct forward declaration (one forward
  declaration wasn't needed anymore)
* Unused member warning (`on_load_callback_store_`)
2022-11-18 15:20:16 +01:00
Julian Eisel 61d0f77810 Cleanup: Better follow class layout style guide in asset headers
Move "using" declarations and member variables to the top of the class.
See https://wiki.blender.org/wiki/Style_Guide/C_Cpp#Class_Layout.

Changes access specifiers of some variables from public/protected to
private, there was no point in not having them private.
2022-11-18 12:45:56 +01:00
Julian Eisel e31f282917 Cleanup: Minor cleanups in asset system headers
- Move main comment on class to header comment where it's more visible.
- Improve comment.
- Move stdlib includes first, like we do it usually
- Separate includes my code module
- Remove unnecessary forward declarations
2022-11-18 12:45:56 +01:00
Julian Eisel 59f8061a34 Assets: Refactor asset representation storage
- Move code to manage storage to own class in own file, separates
  concerns and different levels of abstraction better.
- Store local ID assets separately in the storage class for more
  efficient lookups (e.g. for ID remapping).
- Make API function names and comments more complete.
2022-11-17 11:55:38 +01:00
Julian Eisel ea2dda306c Asset system: New asset system code module (with files from BKE)
Adds a new `source/blender/asset_system` directory and moves asset
related files from BKE to it. More asset related code can follow
(e.g. asset indexing, ED_assetlist stuff) but needs further work to
untangle it. I also kept `BKE_asset.h` and `asset.cc` as is, since they
deal with asset DNA data mostly, thus make sense in BKE.

Motivation:
- Makes the asset system design more present (term wasn't even used in
  code before).
- An `asset_system` directory is quite descriptive (trivial to identify
  core asset system features) and makes it easy to find asset code.
- Asset system is mostly runtime data, with little relation to other
  `Main`/BKE/DNA types.
- There's a lot of stuff in BKE already. It shouldn't be just a dump for
  all stuff that seems core enough.
- Being its own directly helps us be more mindful about encapsulating
  the module well, and avoiding dependencies on other modules.
- We can be more free with splitting files here than in BKE.
- In future there might be an asset system BPY module, which would then
  map quite nicely to the `asset_system` directory.

Checked with some other core devs, consensus seems that this makes
sense.
2022-11-14 12:46:34 +01:00