2023-08-15 16:20:26 +02:00
|
|
|
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2020-12-11 18:15:25 +01:00
|
|
|
|
|
|
|
/** \file
|
|
|
|
* \ingroup bke
|
|
|
|
*/
|
|
|
|
|
2021-01-04 03:10:22 +01:00
|
|
|
#pragma once
|
|
|
|
|
2021-10-25 13:02:08 +02:00
|
|
|
#include "BLI_compiler_attrs.h"
|
2020-12-11 18:15:25 +01:00
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
|
Assets: add Asset Catalog system
Catalogs work like directories on disk (without hard-/symlinks), in that
an asset is only contained in one catalog.
See T90066 for design considerations.
#### Known Limitations
Only a single catalog definition file (CDF), is supported, at
`${ASSET_LIBRARY_ROOT}/blender_assets.cats.txt`. In the future this is
to be expanded to support arbitrary CDFs (like one per blend file, one
per subdirectory, etc.).
The current implementation is based on the asset browser, which in
practice means that the asset browser owns the `AssetCatalogService`
instance for the selected asset library. In the future these instances
will be accessible via a less UI-bound asset system.
The UI is still very rudimentary, only showing the catalog ID for the
currently selected asset. Most notably, the loaded catalogs are not
shown yet. The UI is being implemented and will be merged soon.
#### Catalog Identifiers
Catalogs are internally identified by UUID. In older designs this was a
human-readable name, which has the problem that it has to be kept in
sync with its semantics (so when renaming a catalog from X to Y, the
UUID can be kept the same).
Since UUIDs don't communicate any human-readable information, the
mapping from catalog UUID to its path (stored in the Catalog Definition
File, CDF) is critical for understanding which asset is stored in which
human-readable catalog. To make this less critical, and to allow manual
data reconstruction after a CDF is lost/corrupted, each catalog also has
a "simple name" that's stored along with the UUID. This is also stored
on each asset, next to the catalog UUID.
#### Writing to Disk
Before saving asset catalogs to disk, the to-be-overwritten file gets
inspected. Any new catalogs that are found thre are loaded to memory
before writing the catalogs back to disk:
- Changed catalog path: in-memory data wins
- Catalogs deleted on disk: they are recreated based on in-memory data
- Catalogs deleted in memory: deleted on disk as well
- New catalogs on disk: are loaded and thus survive the overwriting
#### Tree Design
This implements the initial tree structure to load catalogs into. See
T90608, and the basic design in T90066.
Reviewed By: Severin
Maniphest Tasks: T91552
Differential Revision: https://developer.blender.org/D12589
2021-09-23 14:56:45 +02:00
|
|
|
#include "DNA_asset_types.h"
|
|
|
|
|
2021-07-08 22:16:50 +02:00
|
|
|
struct AssetLibraryReference;
|
2021-10-25 13:02:08 +02:00
|
|
|
struct AssetMetaData;
|
2023-11-16 12:00:12 +01:00
|
|
|
struct AssetTag;
|
2020-12-11 18:15:25 +01:00
|
|
|
struct BlendDataReader;
|
2020-12-16 06:26:23 +01:00
|
|
|
struct BlendWriter;
|
2020-12-11 18:15:25 +01:00
|
|
|
struct ID;
|
2021-10-25 13:02:08 +02:00
|
|
|
struct IDProperty;
|
2020-12-11 18:15:25 +01:00
|
|
|
struct PreviewImage;
|
|
|
|
|
2023-11-16 12:00:12 +01:00
|
|
|
using PreSaveFn = void (*)(void *asset_ptr, AssetMetaData *asset_data);
|
|
|
|
using OnMarkAssetFn = void (*)(void *asset_ptr, AssetMetaData *asset_data);
|
2021-10-25 13:02:08 +02:00
|
|
|
|
2023-11-16 12:00:12 +01:00
|
|
|
struct AssetTypeInfo {
|
2021-10-25 13:02:08 +02:00
|
|
|
/**
|
|
|
|
* For local assets (assets in the current .blend file), a callback to execute before the file is
|
|
|
|
* saved.
|
|
|
|
*/
|
|
|
|
PreSaveFn pre_save_fn;
|
2023-09-26 16:38:50 +02:00
|
|
|
OnMarkAssetFn on_mark_asset_fn;
|
2023-11-16 12:00:12 +01:00
|
|
|
};
|
2021-10-25 13:02:08 +02:00
|
|
|
|
2024-01-04 21:07:48 +01:00
|
|
|
AssetMetaData *BKE_asset_metadata_create();
|
2023-11-16 12:00:12 +01:00
|
|
|
void BKE_asset_metadata_free(AssetMetaData **asset_data);
|
2020-12-11 18:15:25 +01:00
|
|
|
|
Assets: allow copying asset data from one ID to another
Asset data can now be copied in Python via assignment to
`id.asset_data`, so for example `dest.asset_data = source.asset_data`.
This copies the description, license, author, etc. fields, as well as
the tags and the asset catalog assignment.
This is intended to be used in the pose library, when updating a pose by
simply creating a new asset and having that replace the old one.
This is intentionally taking a copy, even though the above use case
could have sufficed with a higher-level 'move' function. By exposing
this as a copy, it can be used in a wider range of situations, from
whatever Python code wants to use it. This could include copying the
asset data from the active asset to all the other selected ones.
Any pre-existing asset data is freed before the copy is assigned. The
target ID MUST be marked as asset already for the assignment to work.
Assigning `None` to clear the asset status is not allowed. Instead
`.asset_mark()` resp. `.asset_clear()` should be used. This limitation
is in place to simplify the API, and to ensure that there is only one
way in which assets are marked/cleared, making it easier to change the
internals of the asset system without API changes.
Example code:
```python
src = bpy.data.objects['Suzanne']
dst = bpy.data.objects['Cube']
dst.asset_mark()
dst.asset_data = src.asset_data
```
Pull Request: https://projects.blender.org/blender/blender/pulls/108547
2023-06-02 16:07:41 +02:00
|
|
|
/**
|
|
|
|
* Create a copy of the #AssetMetaData so that it can be assigned to another asset.
|
|
|
|
*
|
|
|
|
* The caller becomes the owner of the returned pointer.
|
|
|
|
*/
|
2023-11-16 12:00:12 +01:00
|
|
|
AssetMetaData *BKE_asset_metadata_copy(const AssetMetaData *source);
|
Assets: allow copying asset data from one ID to another
Asset data can now be copied in Python via assignment to
`id.asset_data`, so for example `dest.asset_data = source.asset_data`.
This copies the description, license, author, etc. fields, as well as
the tags and the asset catalog assignment.
This is intended to be used in the pose library, when updating a pose by
simply creating a new asset and having that replace the old one.
This is intentionally taking a copy, even though the above use case
could have sufficed with a higher-level 'move' function. By exposing
this as a copy, it can be used in a wider range of situations, from
whatever Python code wants to use it. This could include copying the
asset data from the active asset to all the other selected ones.
Any pre-existing asset data is freed before the copy is assigned. The
target ID MUST be marked as asset already for the assignment to work.
Assigning `None` to clear the asset status is not allowed. Instead
`.asset_mark()` resp. `.asset_clear()` should be used. This limitation
is in place to simplify the API, and to ensure that there is only one
way in which assets are marked/cleared, making it easier to change the
internals of the asset system without API changes.
Example code:
```python
src = bpy.data.objects['Suzanne']
dst = bpy.data.objects['Cube']
dst.asset_mark()
dst.asset_data = src.asset_data
```
Pull Request: https://projects.blender.org/blender/blender/pulls/108547
2023-06-02 16:07:41 +02:00
|
|
|
|
2020-12-11 18:15:25 +01:00
|
|
|
struct AssetTagEnsureResult {
|
2023-11-16 12:00:12 +01:00
|
|
|
AssetTag *tag;
|
2020-12-11 18:15:25 +01:00
|
|
|
/* Set to false if a tag of this name was already present. */
|
|
|
|
bool is_new;
|
|
|
|
};
|
|
|
|
|
2023-11-16 12:00:12 +01:00
|
|
|
AssetTag *BKE_asset_metadata_tag_add(AssetMetaData *asset_data, const char *name)
|
2023-05-03 02:23:00 +02:00
|
|
|
ATTR_NONNULL(1, 2);
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Make sure there is a tag with name \a name, create one if needed.
|
|
|
|
*/
|
2023-11-16 12:00:12 +01:00
|
|
|
AssetTagEnsureResult BKE_asset_metadata_tag_ensure(AssetMetaData *asset_data, const char *name);
|
|
|
|
void BKE_asset_metadata_tag_remove(AssetMetaData *asset_data, AssetTag *tag);
|
2020-12-11 18:15:25 +01:00
|
|
|
|
2021-09-24 03:31:23 +02:00
|
|
|
/** Clean up the catalog ID (white-spaces removed, length reduced, etc.) and assign it. */
|
2023-11-16 12:00:12 +01:00
|
|
|
void BKE_asset_metadata_catalog_id_clear(AssetMetaData *asset_data);
|
|
|
|
void BKE_asset_metadata_catalog_id_set(AssetMetaData *asset_data,
|
Assets: add Asset Catalog system
Catalogs work like directories on disk (without hard-/symlinks), in that
an asset is only contained in one catalog.
See T90066 for design considerations.
#### Known Limitations
Only a single catalog definition file (CDF), is supported, at
`${ASSET_LIBRARY_ROOT}/blender_assets.cats.txt`. In the future this is
to be expanded to support arbitrary CDFs (like one per blend file, one
per subdirectory, etc.).
The current implementation is based on the asset browser, which in
practice means that the asset browser owns the `AssetCatalogService`
instance for the selected asset library. In the future these instances
will be accessible via a less UI-bound asset system.
The UI is still very rudimentary, only showing the catalog ID for the
currently selected asset. Most notably, the loaded catalogs are not
shown yet. The UI is being implemented and will be merged soon.
#### Catalog Identifiers
Catalogs are internally identified by UUID. In older designs this was a
human-readable name, which has the problem that it has to be kept in
sync with its semantics (so when renaming a catalog from X to Y, the
UUID can be kept the same).
Since UUIDs don't communicate any human-readable information, the
mapping from catalog UUID to its path (stored in the Catalog Definition
File, CDF) is critical for understanding which asset is stored in which
human-readable catalog. To make this less critical, and to allow manual
data reconstruction after a CDF is lost/corrupted, each catalog also has
a "simple name" that's stored along with the UUID. This is also stored
on each asset, next to the catalog UUID.
#### Writing to Disk
Before saving asset catalogs to disk, the to-be-overwritten file gets
inspected. Any new catalogs that are found thre are loaded to memory
before writing the catalogs back to disk:
- Changed catalog path: in-memory data wins
- Catalogs deleted on disk: they are recreated based on in-memory data
- Catalogs deleted in memory: deleted on disk as well
- New catalogs on disk: are loaded and thus survive the overwriting
#### Tree Design
This implements the initial tree structure to load catalogs into. See
T90608, and the basic design in T90066.
Reviewed By: Severin
Maniphest Tasks: T91552
Differential Revision: https://developer.blender.org/D12589
2021-09-23 14:56:45 +02:00
|
|
|
bUUID catalog_id,
|
|
|
|
const char *catalog_simple_name);
|
|
|
|
|
2023-11-16 12:00:12 +01:00
|
|
|
void BKE_asset_library_reference_init_default(AssetLibraryReference *library_ref);
|
2021-07-08 22:16:50 +02:00
|
|
|
|
2023-11-16 12:00:12 +01:00
|
|
|
void BKE_asset_metadata_idprop_ensure(AssetMetaData *asset_data, IDProperty *prop);
|
|
|
|
IDProperty *BKE_asset_metadata_idprop_find(const AssetMetaData *asset_data,
|
|
|
|
const char *name) ATTR_WARN_UNUSED_RESULT;
|
2021-10-25 13:02:08 +02:00
|
|
|
|
2023-11-16 12:00:12 +01:00
|
|
|
PreviewImage *BKE_asset_metadata_preview_get_from_id(const AssetMetaData *asset_data,
|
|
|
|
const ID *owner_id);
|
2020-12-11 23:16:29 +01:00
|
|
|
|
2023-11-16 12:00:12 +01:00
|
|
|
void BKE_asset_metadata_write(BlendWriter *writer, AssetMetaData *asset_data);
|
|
|
|
void BKE_asset_metadata_read(BlendDataReader *reader, AssetMetaData *asset_data);
|
2020-12-11 18:15:25 +01:00
|
|
|
|
2023-11-16 12:00:12 +01:00
|
|
|
void BKE_asset_weak_reference_write(BlendWriter *writer, const AssetWeakReference *weak_ref);
|
|
|
|
void BKE_asset_weak_reference_read(BlendDataReader *reader, AssetWeakReference *weak_ref);
|