Blender V5.0
usd_reader_stage.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2021 Tangent Animation and. NVIDIA Corporation. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4#pragma once
5
6#include "BLI_map.hh"
7#include "BLI_set.hh"
8#include "BLI_vector.hh"
9
10#include "usd.hh"
11#include "usd_hash_types.hh"
13#include "usd_reader_prim.hh"
14
15#include <pxr/usd/usdGeom/imageable.h>
16
17struct Collection;
18struct ImportSettings;
19struct Main;
20struct ReportList;
21
22namespace blender::io::usd {
23
25
31
33
35
36 protected:
37 pxr::UsdStageRefPtr stage_;
40
42
43 /* USD dome lights are converted to a world material,
44 * rather than light objects, so are handled differently */
46
47 /* USD material prim paths encountered during stage
48 * traversal, for importing unused materials. */
50
51 /* Readers for scene-graph instance prototypes. */
53
54 /* Readers for point instancer prototypes. */
56
57 public:
58 USDStageReader(pxr::UsdStageRefPtr stage,
60 const std::function<CacheFile *()> &get_cache_file_fn = {});
61
63
64 USDPrimReader *create_reader_if_allowed(const pxr::UsdPrim &prim);
65
66 USDPrimReader *create_reader(const pxr::UsdPrim &prim);
67
68 void collect_readers();
69
75 void process_armature_modifiers() const;
76
77 /* Convert every material prim on the stage to a Blender
78 * material, including materials not used by any geometry.
79 * Note that collect_readers() must be called before calling
80 * import_all_materials(). */
81 void import_all_materials(struct Main *bmain);
82
83 /* Add fake users for any imported materials with no
84 * users. This is typically required when importing all
85 * materials. */
87
93
99 void call_material_import_hooks(struct Main *bmain) const;
100
101 bool valid() const;
102
103 pxr::UsdStageRefPtr stage()
104 {
105 return stage_;
106 }
107 const USDImportParams &params() const
108 {
109 return params_;
110 }
111
113 {
114 return settings_;
115 }
116
119 {
120 return params_.worker_status ? params_.worker_status->reports : nullptr;
121 }
122
124 void clear_readers();
125
127 {
128 return readers_;
129 };
130
135
136 void sort_readers();
137
141 void create_proto_collections(Main *bmain, Collection *parent_collection);
142
143 private:
161 USDPrimReader *collect_readers(const pxr::UsdPrim &prim,
162 const UsdPathSet &pruned_prims,
163 bool defined_prims_only,
165
173 bool include_by_visibility(const pxr::UsdGeomImageable &imageable) const;
174
182 bool include_by_purpose(const pxr::UsdGeomImageable &imageable) const;
183
189 bool merge_with_parent(USDPrimReader *reader) const;
190
195 bool is_primitive_prim(const pxr::UsdPrim &prim) const;
196
204 UsdPathSet collect_point_instancer_proto_paths() const;
205 void collect_point_instancer_proto_paths(const pxr::UsdPrim &prim, UsdPathSet &r_paths) const;
206
213 void create_point_instancer_proto_readers(const UsdPathSet &proto_paths);
214};
215
216}; // namespace blender::io::usd
USDPrimReader * create_reader(const pxr::UsdPrim &prim)
void call_material_import_hooks(struct Main *bmain) const
const USDImportParams & params() const
USDPrimReader * create_reader_if_allowed(const pxr::UsdPrim &prim)
blender::Vector< USDPrimReader * > readers_
const ImportSettings & settings() const
const blender::Vector< USDPrimReader * > & readers() const
blender::Vector< pxr::SdfPath > material_paths_
USDStageReader(pxr::UsdStageRefPtr stage, const USDImportParams &params, const std::function< CacheFile *()> &get_cache_file_fn={})
blender::Vector< USDDomeLightReader * > dome_light_readers_
void create_proto_collections(Main *bmain, Collection *parent_collection)
const blender::Vector< USDDomeLightReader * > & dome_light_readers() const
void import_all_materials(struct Main *bmain)
blender::Set< pxr::SdfPath > UsdPathSet
blender::Map< pxr::SdfPath, blender::Vector< USDPrimReader * > > ProtoReaderMap