Blender V4.3
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
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
22{
23 if (ID *local_id = asset.local_id()) {
24 return local_id;
25 }
26
27 std::string blend_path = asset.full_library_path();
28 if (blend_path.empty()) {
29 return nullptr;
30 }
31
32 switch (asset.get_import_method().value_or(ASSET_IMPORT_APPEND_REUSE)) {
34 return WM_file_link_datablock(&bmain,
35 nullptr,
36 nullptr,
37 nullptr,
38 blend_path.c_str(),
39 asset.get_id_type(),
40 asset.get_name().c_str(),
41 (asset.get_use_relative_path() ? FILE_RELPATH : 0));
43 return WM_file_append_datablock(&bmain,
44 nullptr,
45 nullptr,
46 nullptr,
47 blend_path.c_str(),
48 asset.get_id_type(),
49 asset.get_name().c_str(),
52 (asset.get_use_relative_path() ? FILE_RELPATH : 0));
54 return WM_file_append_datablock(&bmain,
55 nullptr,
56 nullptr,
57 nullptr,
58 blend_path.c_str(),
59 asset.get_id_type(),
60 asset.get_name().c_str(),
64 (asset.get_use_relative_path() ? FILE_RELPATH : 0));
65 }
67 return nullptr;
68}
69
70} // namespace blender::ed::asset
Main runtime representation of an asset.
#define BLI_assert_unreachable()
Definition BLI_assert.h:97
external readfile function prototypes.
@ BLO_LIBLINK_APPEND_RECURSIVE
@ BLO_LIBLINK_APPEND_ASSET_DATA_CLEAR
@ BLO_LIBLINK_APPEND_LOCAL_ID_REUSE
@ ASSET_IMPORT_LINK
@ ASSET_IMPORT_APPEND_REUSE
@ ASSET_IMPORT_APPEND
@ FILE_RELPATH
constexpr const char * c_str() const
std::optional< eAssetImportMethod > get_import_method() const
ID * asset_local_id_ensure_imported(Main &bmain, const asset_system::AssetRepresentation &asset)
Definition DNA_ID.h:413