Blender V5.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
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
22 Main &bmain,
24 const int flags, /* #eFileSel_Params_Flag + #eBLOLibLinkFlags */
25 const std::optional<eAssetImportMethod> import_method,
26 const std::optional<ImportInstantiateContext> instantiate_context,
27 ReportList *reports)
28{
29 if (ID *local_id = asset.local_id()) {
30 return local_id;
31 }
32
33 std::string blend_path = asset.full_library_path();
34 if (blend_path.empty()) {
35 return nullptr;
36 }
37
38 const eAssetImportMethod method = [&]() {
39 const bool no_packing = U.experimental.no_data_block_packing;
40 if (import_method) {
41 return (no_packing && *import_method == ASSET_IMPORT_PACK) ? ASSET_IMPORT_APPEND_REUSE :
42 *import_method;
43 }
44 if (std::optional asset_method = asset.get_import_method()) {
45 return (no_packing && *asset_method == ASSET_IMPORT_PACK) ? ASSET_IMPORT_APPEND_REUSE :
46 *asset_method;
47 }
49 }();
50
51 Scene *scene = instantiate_context ? instantiate_context->scene : nullptr;
52 ViewLayer *view_layer = instantiate_context ? instantiate_context->view_layer : nullptr;
53 View3D *view3d = instantiate_context ? instantiate_context->view3d : nullptr;
54
55 switch (method) {
57 return WM_file_link_datablock(&bmain,
58 scene,
59 view_layer,
60 view3d,
61 blend_path.c_str(),
62 asset.get_id_type(),
63 asset.get_name().c_str(),
64 flags | (asset.get_use_relative_path() ? FILE_RELPATH : 0),
65 reports);
67 return WM_file_link_datablock(&bmain,
68 scene,
69 view_layer,
70 view3d,
71 blend_path.c_str(),
72 asset.get_id_type(),
73 asset.get_name().c_str(),
74 flags | BLO_LIBLINK_PACK |
75 (asset.get_use_relative_path() ? FILE_RELPATH : 0),
76 reports);
78 return WM_file_append_datablock(&bmain,
79 scene,
80 view_layer,
81 view3d,
82 blend_path.c_str(),
83 asset.get_id_type(),
84 asset.get_name().c_str(),
87 (asset.get_use_relative_path() ? FILE_RELPATH : 0),
88 reports);
90 return WM_file_append_datablock(&bmain,
91 scene,
92 view_layer,
93 view3d,
94 blend_path.c_str(),
95 asset.get_id_type(),
96 asset.get_name().c_str(),
100 (asset.get_use_relative_path() ? FILE_RELPATH : 0),
101 reports);
102 }
104 return nullptr;
105}
106
107} // namespace blender::ed::asset
Main runtime representation of an asset.
external readfile function prototypes.
#define BLI_assert_unreachable()
ID * asset_local_id_ensure_imported(Main &bmain, const asset_system::AssetRepresentation &asset, int flags=0, const std::optional< eAssetImportMethod > import_method=std::nullopt, const std::optional< ImportInstantiateContext > instantiate_context=std::nullopt, ReportList *reports=nullptr)
UserDef U
Definition blender.cc:58
ID * WM_file_link_datablock(Main *bmain, Scene *scene, ViewLayer *view_layer, View3D *v3d, const char *filepath, const short id_code, const char *id_name, int flag, ReportList *reports)
@ BLO_LIBLINK_APPEND_LOCAL_ID_REUSE
@ BLO_LIBLINK_APPEND_RECURSIVE
@ BLO_LIBLINK_APPEND_ASSET_DATA_CLEAR
@ ASSET_IMPORT_APPEND
@ ASSET_IMPORT_APPEND_REUSE
ID * WM_file_append_datablock(Main *bmain, Scene *scene, ViewLayer *view_layer, View3D *v3d, const char *filepath, const short id_code, const char *id_name, int flag, ReportList *reports)