Blender V4.3
usd_reader_mesh.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later
4 * Adapted from the Blender Alembic importer implementation.
5 * Modifications Copyright 2021 Tangent Animation and. NVIDIA Corporation. All rights reserved. */
6#pragma once
7
8#include "BLI_map.hh"
9#include "BLI_span.hh"
10
11#include "usd.hh"
12#include "usd_reader_geom.hh"
13
14#include <pxr/usd/usdGeom/mesh.h>
15
16namespace blender::io::usd {
17
19 private:
20 pxr::UsdGeomMesh mesh_prim_;
21
23 blender::Map<const pxr::TfToken, bool> primvar_varying_map_;
24
25 /* TODO(makowalski): Is it the best strategy to cache the
26 * mesh geometry in the following members? It appears these
27 * arrays are never cleared, so this might bloat memory. */
28 pxr::VtIntArray face_indices_;
29 pxr::VtIntArray face_counts_;
30 pxr::VtVec3fArray positions_;
31 pxr::VtVec3fArray normals_;
32
33 pxr::TfToken normal_interpolation_;
34 pxr::TfToken orientation_;
35 bool is_left_handed_;
36 bool is_time_varying_;
37
38 /* This is to ensure we load all data once, because we reuse the read_mesh function
39 * in the mesh seq modifier, and in initial load. Ideally, a better fix would be
40 * implemented. Note this will break if faces or positions vary. */
41 bool is_initial_load_;
42
43 public:
44 USDMeshReader(const pxr::UsdPrim &prim,
45 const USDImportParams &import_params,
46 const ImportSettings &settings);
47
48 bool valid() const override;
49
50 void create_object(Main *bmain, double motionSampleTime) override;
51 void read_object_data(Main *bmain, double motionSampleTime) override;
52
53 void read_geometry(bke::GeometrySet &geometry_set,
55 const char **r_err_str) override;
56
57 bool topology_changed(const Mesh *existing_mesh, double motionSampleTime) override;
58
67 std::string get_skeleton_path() const;
68
69 private:
70 void process_normals_vertex_varying(Mesh *mesh);
71 void process_normals_face_varying(Mesh *mesh) const;
73 void process_normals_uniform(Mesh *mesh) const;
74 void readFaceSetsSample(Main *bmain, Mesh *mesh, double motionSampleTime);
75 void assign_facesets_to_material_indices(double motionSampleTime,
76 MutableSpan<int> material_indices,
78
79 void read_mpolys(Mesh *mesh) const;
80 void read_vertex_creases(Mesh *mesh, double motionSampleTime);
81 void read_velocities(Mesh *mesh, double motionSampleTime);
82
83 void read_mesh_sample(ImportSettings *settings,
84 Mesh *mesh,
85 double motionSampleTime,
86 bool new_mesh);
87
88 Mesh *read_mesh(struct Mesh *existing_mesh,
90 const char **r_err_str);
91
92 void read_custom_data(const ImportSettings *settings,
93 Mesh *mesh,
94 double motionSampleTime,
95 bool new_mesh);
96
97 void read_uv_data_primvar(Mesh *mesh,
98 const pxr::UsdGeomPrimvar &primvar,
99 const double motionSampleTime);
100
105 std::optional<XformResult> get_local_usd_xform(float time) const override;
106};
107
108} // namespace blender::io::usd
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)
std::string get_skeleton_path() const
void read_geometry(bke::GeometrySet &geometry_set, USDMeshReadParams params, const char **r_err_str) override
bool topology_changed(const Mesh *existing_mesh, double motionSampleTime) override
const pxr::UsdPrim & prim() const
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]