Blender V5.0
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
22 blender::Map<const pxr::TfToken, bool> primvar_varying_map_;
23
24 /* TODO(makowalski): Is it the best strategy to cache the
25 * mesh geometry in the following members? It appears these
26 * arrays are never cleared, so this might bloat memory. */
27 pxr::VtIntArray face_indices_;
28 pxr::VtIntArray face_counts_;
29 pxr::VtVec3fArray positions_;
30 pxr::VtVec3fArray normals_;
31
32 pxr::TfToken normal_interpolation_;
33 pxr::TfToken orientation_;
34 bool is_left_handed_ = false;
35 bool is_time_varying_ = false;
36
37 /* This is to ensure we load all data once, because we reuse the read_mesh function
38 * in the mesh seq modifier, and in initial load. Ideally, a better fix would be
39 * implemented. Note this will break if faces or positions vary. */
40 bool is_initial_load_ = false;
41
42 public:
43 USDMeshReader(const pxr::UsdPrim &prim,
44 const USDImportParams &import_params,
45 const ImportSettings &settings)
46 : USDGeomReader(prim, import_params, settings), mesh_prim_(prim)
47 {
48 }
49
50 bool valid() const override
51 {
52 return bool(mesh_prim_);
53 }
54
55 void create_object(Main *bmain) override;
56 void read_object_data(Main *bmain, pxr::UsdTimeCode time) override;
57
58 void read_geometry(bke::GeometrySet &geometry_set,
60 const char **r_err_str) override;
61
62 bool topology_changed(const Mesh *existing_mesh, pxr::UsdTimeCode time) override;
63
72 pxr::SdfPath get_skeleton_path() const;
73
74 private:
75 void process_normals_vertex_varying(Mesh *mesh);
76 void process_normals_face_varying(Mesh *mesh) const;
78 void process_normals_uniform(Mesh *mesh) const;
79 void readFaceSetsSample(Main *bmain, Mesh *mesh, pxr::UsdTimeCode time);
80 void assign_facesets_to_material_indices(pxr::UsdTimeCode time,
81 MutableSpan<int> material_indices,
83
84 bool read_faces(Mesh *mesh) const;
85 void read_subdiv();
86 void read_vertex_creases(Mesh *mesh, pxr::UsdTimeCode time);
87 void read_edge_creases(Mesh *mesh, pxr::UsdTimeCode time);
88 void read_velocities(Mesh *mesh, pxr::UsdTimeCode time);
89
90 void read_mesh_sample(ImportSettings *settings,
91 Mesh *mesh,
92 pxr::UsdTimeCode time,
93 bool new_mesh);
94
95 Mesh *read_mesh(struct Mesh *existing_mesh,
97 const char **r_err_str);
98
99 void read_custom_data(const ImportSettings *settings,
100 Mesh *mesh,
101 pxr::UsdTimeCode time,
102 bool new_mesh);
103
104 void read_uv_data_primvar(Mesh *mesh,
105 const pxr::UsdGeomPrimvar &primvar,
106 const pxr::UsdTimeCode time);
107
112 std::optional<XformResult> get_local_usd_xform(pxr::UsdTimeCode time) const override;
113};
114
115} // namespace blender::io::usd
USDGeomReader(const pxr::UsdPrim &prim, const USDImportParams &import_params, const ImportSettings &settings)
bool topology_changed(const Mesh *existing_mesh, pxr::UsdTimeCode time) override
USDMeshReader(const pxr::UsdPrim &prim, const USDImportParams &import_params, const ImportSettings &settings)
pxr::SdfPath get_skeleton_path() const
void read_geometry(bke::GeometrySet &geometry_set, USDMeshReadParams params, const char **r_err_str) override
void create_object(Main *bmain) override
void read_object_data(Main *bmain, pxr::UsdTimeCode time) override
const pxr::UsdPrim & prim() const
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]