Blender V5.0
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#include "usd_hash_types.hh"
12
13#include "BLI_map.hh"
14#include "BLI_set.hh"
15
16#include "WM_types.hh"
17
18#include <pxr/usd/sdf/path.h>
19#include <pxr/usd/usd/prim.h>
20
21#include <string>
22
23struct CacheFile;
24struct Main;
25struct Material;
26struct Object;
27struct ReportList;
28
29namespace blender::io::usd {
30
33 bool do_convert_mat = false;
34 float conversion_mat[4][4] = {};
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
113 {
114 return import_params_.worker_status ? import_params_.worker_status->reports : nullptr;
115 }
116
117 /* Since readers might be referenced through handles
118 * maintained by modifiers and constraints, we provide
119 * a reference count to facilitate managing the object
120 * lifetime.
121 * TODO(makowalski): investigate transitioning to using
122 * smart pointers for readers, or, alternatively look into
123 * making the lifetime management more robust, e.g., by
124 * making the destructors protected and implementing deletion
125 * in decref(), etc. */
126 int refcount() const;
127 void incref();
128 void decref();
129
131 {
132 return name_;
133 }
134 pxr::SdfPath prim_path() const
135 {
136 return prim_.GetPrimPath();
137 }
138
139 virtual pxr::SdfPath object_prim_path() const
140 {
141 return prim_path();
142 }
143
144 virtual pxr::SdfPath data_prim_path() const
145 {
146 return prim_path();
147 }
148
153
155 {
157 }
158
159 bool is_in_proto() const;
160
161 protected:
180 void set_props(bool merge_with_parent = false,
181 pxr::UsdTimeCode time = pxr::UsdTimeCode::Default());
182};
183
184} // namespace blender::io::usd
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)
blender::Map< std::string, Material * > mat_name_to_mat
blender::Set< pxr::SdfPath > mat_import_hook_sources
blender::Map< pxr::SdfPath, Material * > usd_path_to_mat_for_hook
blender::Map< pxr::SdfPath, Material * > usd_path_to_mat
std::function< CacheFile *()> get_cache_file
uint8_t flag
Definition wm_window.cc:145