Blender V5.0
asset_import.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
10
11#include "DNA_space_types.h"
12
13#include "BLO_readfile.hh"
14
15#include "WM_api.hh"
16
17#include "ED_asset_import.hh"
18
19namespace blender::ed::asset {
20
23 const std::optional<eAssetImportMethod> import_method)
24{
25 if (ID *local_id = asset.local_id()) {
26 return local_id;
27 }
28
29 std::string blend_path = asset.full_library_path();
30 if (blend_path.empty()) {
31 return nullptr;
32 }
33
34 const eAssetImportMethod method = [&]() {
35 const bool no_packing = U.experimental.no_data_block_packing;
36 if (import_method) {
37 return (no_packing && *import_method == ASSET_IMPORT_PACK) ? ASSET_IMPORT_APPEND_REUSE :
38 *import_method;
39 }
40 if (std::optional asset_method = asset.get_import_method()) {
41 return (no_packing && *asset_method == ASSET_IMPORT_PACK) ? ASSET_IMPORT_APPEND_REUSE :
42 *asset_method;
43 }
45 }();
46
47 switch (method) {
49 return WM_file_link_datablock(&bmain,
50 nullptr,
51 nullptr,
52 nullptr,
53 blend_path.c_str(),
54 asset.get_id_type(),
55 asset.get_name().c_str(),
56 (asset.get_use_relative_path() ? FILE_RELPATH : 0));
58 return WM_file_link_datablock(&bmain,
59 nullptr,
60 nullptr,
61 nullptr,
62 blend_path.c_str(),
63 asset.get_id_type(),
64 asset.get_name().c_str(),
66 (asset.get_use_relative_path() ? FILE_RELPATH : 0));
68 return WM_file_append_datablock(&bmain,
69 nullptr,
70 nullptr,
71 nullptr,
72 blend_path.c_str(),
73 asset.get_id_type(),
74 asset.get_name().c_str(),
77 (asset.get_use_relative_path() ? FILE_RELPATH : 0));
79 return WM_file_append_datablock(&bmain,
80 nullptr,
81 nullptr,
82 nullptr,
83 blend_path.c_str(),
84 asset.get_id_type(),
85 asset.get_name().c_str(),
89 (asset.get_use_relative_path() ? FILE_RELPATH : 0));
90 }
92 return nullptr;
93}
94
95} // namespace blender::ed::asset
Main runtime representation of an asset.
#define BLI_assert_unreachable()
Definition BLI_assert.h:93
external readfile function prototypes.
@ BLO_LIBLINK_APPEND_RECURSIVE
@ BLO_LIBLINK_APPEND_ASSET_DATA_CLEAR
@ BLO_LIBLINK_PACK
@ BLO_LIBLINK_APPEND_LOCAL_ID_REUSE
eAssetImportMethod
@ ASSET_IMPORT_PACK
@ ASSET_IMPORT_LINK
@ ASSET_IMPORT_APPEND_REUSE
@ ASSET_IMPORT_APPEND
@ FILE_RELPATH
#define U
ID * asset_local_id_ensure_imported(Main &bmain, const asset_system::AssetRepresentation &asset, const std::optional< eAssetImportMethod > import_method=std::nullopt)
Definition DNA_ID.h:414