Blender  V3.3
usd_reader_prim.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Adapted from the Blender Alembic importer implementation.
3  * Modifications Copyright 2021 Tangent Animation. All rights reserved. */
4 #pragma once
5 
6 #include "usd.h"
7 
8 #include <pxr/usd/usd/prim.h>
9 
10 #include <map>
11 #include <string>
12 
13 struct Main;
14 struct Material;
15 struct Object;
16 
17 namespace blender::io::usd {
18 
21  float conversion_mat[4][4];
22 
23  int from_up;
25  float scale;
28 
29  /* Length and frame offset of file sequences. */
32 
33  /* From MeshSeqCacheModifierData.read_flag */
34  int read_flag;
35 
37 
39 
40  /* Map a USD material prim path to a Blender material name.
41  * This map is updated by readers during stage traversal.
42  * This field is mutable because it is used to keep track
43  * of what the importer is doing. This is necessary even
44  * when all the other import settings are to remain const. */
45  mutable std::map<std::string, std::string> usd_path_to_mat_name;
46  /* Map a material name to Blender material.
47  * This map is updated by readers during stage traversal,
48  * and is mutable similar to the map above. */
49  mutable std::map<std::string, Material *> mat_name_to_mat;
50 
52  : do_convert_mat(false),
53  from_up(0),
54  from_forward(0),
55  scale(1.0f),
56  is_sequence(false),
57  set_frame_range(false),
58  sequence_len(1),
59  sequence_offset(0),
60  read_flag(0),
61  validate_meshes(false),
63  {
64  }
65 };
66 
67 /* Most generic USD Reader. */
68 
70 
71  protected:
72  std::string name_;
73  std::string prim_path_;
75  pxr::UsdPrim prim_;
79  int refcount_;
80 
81  public:
82  USDPrimReader(const pxr::UsdPrim &prim,
83  const USDImportParams &import_params,
84  const ImportSettings &settings);
85  virtual ~USDPrimReader();
86 
87  const pxr::UsdPrim &prim() const;
88 
89  virtual bool valid() const;
90 
91  virtual void create_object(Main *bmain, double motionSampleTime) = 0;
92  virtual void read_object_data(Main * /* bmain */, double /* motionSampleTime */){};
93 
94  Object *object() const;
95  void object(Object *ob);
96 
98  {
99  return parent_reader_;
100  }
102  {
104  }
105 
106  /* Since readers might be referenced through handles
107  * maintained by modifiers and constraints, we provide
108  * a reference count to facilitate managing the object
109  * lifetime.
110  * TODO(makowalski): investigate transitioning to using
111  * smart pointers for readers, or, alternatively look into
112  * making the lifetime management more robust, e.g., by
113  * making the destructors protected and implementing deletion
114  * in decref(), etc. */
115  int refcount() const;
116  void incref();
117  void decref();
118 
119  const std::string &name() const
120  {
121  return name_;
122  }
123  const std::string &prim_path() const
124  {
125  return prim_path_;
126  }
127 };
128 
129 } // 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_
const USDImportParams & import_params_
const std::string & name() const
Definition: BKE_main.h:121
std::map< std::string, std::string > usd_path_to_mat_name
std::map< std::string, Material * > mat_name_to_mat