Blender V5.3
usd_reader_prim.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2021 Tangent Animation. All rights reserved.
2 * SPDX-FileCopyrightText: 2023 Blender Authors
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 *
6 * Adapted from the Blender Alembic importer implementation. */
7
8#pragma once
9
10#include "usd.hh"
11
12#include "BLI_map.hh"
14#include "BLI_set.hh"
15
16#include <pxr/usd/sdf/path.h>
17#include <pxr/usd/usd/prim.h>
18
19#include <string>
20
21namespace blender {
22
23struct CacheFile;
24struct Main;
25struct Material;
26struct Object;
27struct ReportList;
28
29namespace io::usd {
30
33 bool do_convert_mat = false;
35
36 /* From MeshSeqCacheModifierData.read_flag */
37 int read_flag = 0;
38
39 std::function<CacheFile *()> get_cache_file{};
40
41 /*
42 * The fields below are mutable because they are used to keep track
43 * of what the importer is doing. This is necessary even when all
44 * the other import settings are to remain const.
45 */
46
47 /* Map a USD material prim path to a Blender material.
48 * This map is updated by readers during stage traversal. */
50 /* Map a material name to Blender material.
51 * This map is updated by readers during stage traversal. */
53 /* Map a USD material prim path to a Blender material to be
54 * converted by invoking the 'on_material_import' USD hook.
55 * This map is updated by readers during stage traversal. */
57 /* Set of paths to USD material primitives that can be converted by the
58 * 'on_material_import' USD hook. For efficiency this set should
59 * be populated prior to stage traversal. */
61
62 /* We use the stage metersPerUnit to convert camera properties from USD scene units to the
63 * correct millimeter scale that Blender uses for camera parameters. */
65
66 pxr::SdfPath skip_prefix{};
67
68 /* Combined user-specified and unit conversion scales. */
69 double scene_scale = 1.0;
70};
71
72/* Most generic USD Reader. */
73
75
76 protected:
79 pxr::UsdPrim prim_;
85
86 public:
87 USDPrimReader(const pxr::UsdPrim &prim,
88 const USDImportParams &import_params,
89 const ImportSettings &settings);
90 virtual ~USDPrimReader();
91
92 const pxr::UsdPrim &prim() const;
93
94 virtual bool valid() const;
95
96 virtual void create_object(Main *bmain) = 0;
97 virtual void read_object_data(Main * /*bmain*/, pxr::UsdTimeCode /*time*/) {};
98
99 Object *object() const;
100 void object(Object *ob);
101
103 {
104 return parent_reader_;
105 }
110
112 ReportList *reports() const;
113
114 /* Since readers might be referenced through handles
115 * maintained by modifiers and constraints, we provide
116 * a reference count to facilitate managing the object
117 * lifetime.
118 * TODO(makowalski): investigate transitioning to using
119 * smart pointers for readers, or, alternatively look into
120 * making the lifetime management more robust, e.g., by
121 * making the destructors protected and implementing deletion
122 * in decref(), etc. */
123 int refcount() const;
124 void incref();
125 void decref();
126
128 {
129 return name_;
130 }
131 pxr::SdfPath prim_path() const
132 {
133 return prim_.GetPrimPath();
134 }
135
136 virtual pxr::SdfPath object_prim_path() const
137 {
138 return prim_path();
139 }
140
141 virtual pxr::SdfPath data_prim_path() const
142 {
143 return prim_path();
144 }
145
147 {
149 }
150
152 {
154 }
155
156 bool is_in_proto() const;
157
158 protected:
177 void set_props(bool merge_with_parent = false,
178 pxr::UsdTimeCode time = pxr::UsdTimeCode::Default());
179};
180
181} // namespace io::usd
182} // namespace blender
void parent(USDPrimReader *parent)
USDPrimReader(const pxr::UsdPrim &prim, const USDImportParams &import_params, const ImportSettings &settings)
const pxr::UsdPrim & prim() const
virtual pxr::SdfPath data_prim_path() const
virtual void create_object(Main *bmain)=0
USDPrimReader * parent() const
virtual pxr::SdfPath object_prim_path() const
const ImportSettings * settings_
void set_props(bool merge_with_parent=false, pxr::UsdTimeCode time=pxr::UsdTimeCode::Default())
const USDImportParams & import_params_
virtual void read_object_data(Main *, pxr::UsdTimeCode)
BMesh Iterators.
MatBase< float, 4, 4 > float4x4
Set< pxr::SdfPath > mat_import_hook_sources
Map< pxr::SdfPath, Material * > usd_path_to_mat_for_hook
Map< std::string, Material * > mat_name_to_mat
Map< pxr::SdfPath, Material * > usd_path_to_mat
std::function< CacheFile *()> get_cache_file