Blender V4.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"
13
14#include "WM_types.hh"
15
16#include <pxr/usd/sdf/path.h>
17#include <pxr/usd/usd/prim.h>
18
19#include <string>
20
21struct CacheFile;
22struct Main;
23struct Material;
24struct Object;
25struct ReportList;
26
27namespace blender::io::usd {
28
31 float conversion_mat[4][4];
32
35 float scale;
38
39 /* Length and frame offset of file sequences. */
42
43 /* From MeshSeqCacheModifierData.read_flag */
45
47
48 std::function<CacheFile *()> get_cache_file;
49
50 /* Map a USD material prim path to a Blender material name.
51 * This map is updated by readers during stage traversal.
52 * This field is mutable because it is used to keep track
53 * of what the importer is doing. This is necessary even
54 * when all the other import settings are to remain const. */
56 /* Map a material name to Blender material.
57 * This map is updated by readers during stage traversal,
58 * and is mutable similar to the map above. */
60
61 /* We use the stage metersPerUnit to convert camera properties from USD scene units to the
62 * correct millimeter scale that Blender uses for camera parameters. */
64
65 pxr::SdfPath skip_prefix;
66
69 from_up(0),
70 from_forward(0),
71 scale(1.0f),
74 sequence_len(1),
76 read_flag(0),
78 get_cache_file(nullptr),
80 skip_prefix(pxr::SdfPath{})
81 {
82 }
83};
84
85/* Most generic USD Reader. */
86
88
89 protected:
90 std::string name_;
91 std::string prim_path_;
93 pxr::UsdPrim prim_;
99
100 public:
101 USDPrimReader(const pxr::UsdPrim &prim,
102 const USDImportParams &import_params,
103 const ImportSettings &settings);
104 virtual ~USDPrimReader();
105
106 const pxr::UsdPrim &prim() const;
107
108 virtual bool valid() const;
109
110 virtual void create_object(Main *bmain, double motionSampleTime) = 0;
111 virtual void read_object_data(Main * /*bmain*/, double /*motionSampleTime*/){};
112
113 Object *object() const;
114 void object(Object *ob);
115
117 {
118 return parent_reader_;
119 }
124
130
131 /* Since readers might be referenced through handles
132 * maintained by modifiers and constraints, we provide
133 * a reference count to facilitate managing the object
134 * lifetime.
135 * TODO(makowalski): investigate transitioning to using
136 * smart pointers for readers, or, alternatively look into
137 * making the lifetime management more robust, e.g., by
138 * making the destructors protected and implementing deletion
139 * in decref(), etc. */
140 int refcount() const;
141 void incref();
142 void decref();
143
144 const std::string &name() const
145 {
146 return name_;
147 }
148 const std::string &prim_path() const
149 {
150 return prim_path_;
151 }
152
157
159 {
161 }
162
163 bool is_in_proto() const;
164
165 protected:
184 void set_props(bool merge_with_parent = false,
185 pxr::UsdTimeCode motionSampleTime = pxr::UsdTimeCode::Default());
186};
187
188} // namespace blender::io::usd
virtual void read_object_data(Main *, double)
void parent(USDPrimReader *parent)
USDPrimReader(const pxr::UsdPrim &prim, const USDImportParams &import_params, const ImportSettings &settings)
const std::string & prim_path() const
virtual void create_object(Main *bmain, double motionSampleTime)=0
const pxr::UsdPrim & prim() const
USDPrimReader * parent() const
const ImportSettings * settings_
void set_props(bool merge_with_parent=false, pxr::UsdTimeCode motionSampleTime=pxr::UsdTimeCode::Default())
const USDImportParams & import_params_
const std::string & name() const
static bool merge_with_parent(USDPrimReader *reader)
blender::Map< std::string, Material * > mat_name_to_mat
blender::Map< std::string, std::string > usd_path_to_mat_name
std::function< CacheFile *()> get_cache_file
wmJobWorkerStatus * worker_status
Definition usd.hh:228
ReportList * reports
Definition WM_types.hh:985
uint8_t flag
Definition wm_window.cc:138