Blender  V3.3
usd_reader_mesh.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 and. NVIDIA Corporation. All rights reserved. */
4 #pragma once
5 
6 #include "usd.h"
7 #include "usd_reader_geom.h"
8 
9 #include "pxr/usd/usdGeom/mesh.h"
10 
11 struct MPoly;
12 
13 namespace blender::io::usd {
14 
15 class USDMeshReader : public USDGeomReader {
16  private:
17  pxr::UsdGeomMesh mesh_prim_;
18 
19  std::unordered_map<std::string, pxr::TfToken> uv_token_map_;
20  std::map<const pxr::TfToken, bool> primvar_varying_map_;
21 
22  /* TODO(makowalski): Is it the best strategy to cache the
23  * mesh geometry in the following members? It appears these
24  * arrays are never cleared, so this might bloat memory. */
25  pxr::VtIntArray face_indices_;
26  pxr::VtIntArray face_counts_;
27  pxr::VtVec3fArray positions_;
28  pxr::VtVec3fArray normals_;
29 
30  pxr::TfToken normal_interpolation_;
31  pxr::TfToken orientation_;
32  bool is_left_handed_;
33  bool has_uvs_;
34  bool is_time_varying_;
35 
36  /* This is to ensure we load all data once, because we reuse the read_mesh function
37  * in the mesh seq modifier, and in initial load. Ideally, a better fix would be
38  * implemented. Note this will break if faces or positions vary. */
39  bool is_initial_load_;
40 
41  public:
42  USDMeshReader(const pxr::UsdPrim &prim,
43  const USDImportParams &import_params,
44  const ImportSettings &settings);
45 
46  bool valid() const override;
47 
48  void create_object(Main *bmain, double motionSampleTime) override;
49  void read_object_data(Main *bmain, double motionSampleTime) override;
50 
51  struct Mesh *read_mesh(struct Mesh *existing_mesh,
52  double motionSampleTime,
53  int read_flag,
54  const char **err_str) override;
55 
56  bool topology_changed(const Mesh *existing_mesh, double motionSampleTime) override;
57 
58  private:
59  void process_normals_vertex_varying(Mesh *mesh);
60  void process_normals_face_varying(Mesh *mesh);
62  void process_normals_uniform(Mesh *mesh);
63  void readFaceSetsSample(Main *bmain, Mesh *mesh, double motionSampleTime);
64  void assign_facesets_to_mpoly(double motionSampleTime,
65  struct MPoly *mpoly,
66  int totpoly,
67  std::map<pxr::SdfPath, int> *r_mat_map);
68 
69  void read_mpolys(Mesh *mesh);
70  void read_uvs(Mesh *mesh, double motionSampleTime, bool load_uvs = false);
71  void read_colors(Mesh *mesh, double motionSampleTime);
72  void read_vertex_creases(Mesh *mesh, double motionSampleTime);
73 
74  void read_mesh_sample(ImportSettings *settings,
75  Mesh *mesh,
76  double motionSampleTime,
77  bool new_mesh);
78 };
79 
80 } // namespace blender::io::usd
struct Mesh * read_mesh(struct Mesh *existing_mesh, double motionSampleTime, int read_flag, const char **err_str) override
void read_object_data(Main *bmain, double motionSampleTime) override
void create_object(Main *bmain, double motionSampleTime) override
USDMeshReader(const pxr::UsdPrim &prim, const USDImportParams &import_params, const ImportSettings &settings)
bool topology_changed(const Mesh *existing_mesh, double motionSampleTime) override
const pxr::UsdPrim & prim() const
static void read_mesh_sample(const std::string &iobject_full_name, ImportSettings *settings, const IPolyMeshSchema &schema, const ISampleSelector &selector, CDStreamConfig &config)
static void read_vertex_creases(Mesh *mesh, const Int32ArraySamplePtr &indices, const FloatArraySamplePtr &sharpnesses)
static void read_mpolys(CDStreamConfig &config, const AbcMeshData &mesh_data)
static void read_uvs(const CDStreamConfig &config, void *data, const AbcUvScope uv_scope, const Alembic::AbcGeom::V2fArraySamplePtr &uvs, const UInt32ArraySamplePtr &indices)
Definition: BKE_main.h:121
int totpoly
struct MPoly * mpoly