Blender V5.0
usd_reader_shape.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Nvidia. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
7#include "usd.hh"
8#include "usd_hash_types.hh"
9#include "usd_reader_geom.hh"
10
11struct Mesh;
12
13namespace blender::io::usd {
14
15/*
16 * Read USDGeom primitive shapes as Blender Meshes. This class uses the same adapter functions
17 * as the GL viewport to generate geometry for each of the supported types.
18 */
20 /* A cache to record whether a given primvar is time-varying, so that static primvars are not
21 * read more than once when the mesh is evaluated for animation by the cache file modifier.
22 * The map is mutable so that it can be updated in const functions. */
23 mutable blender::Map<const pxr::TfToken, bool> primvar_time_varying_map_;
24
25 private:
26 /* Template required to read mesh information out of Shape prims,
27 * as each prim type has a separate subclass. */
28 template<typename Adapter>
29 void read_values(pxr::UsdTimeCode time,
30 pxr::VtVec3fArray &positions,
31 pxr::VtIntArray &face_indices,
32 pxr::VtIntArray &face_counts) const;
33
34 /* Wrapper for the templated method read_values, calling the correct template
35 * instantiation based on the introspected prim type. */
36 bool read_mesh_values(pxr::UsdTimeCode time,
37 pxr::VtVec3fArray &positions,
38 pxr::VtIntArray &face_indices,
39 pxr::VtIntArray &face_counts) const;
40
41 void apply_primvars_to_mesh(Mesh *mesh, pxr::UsdTimeCode time) const;
42
43 /* Read the pxr:UsdGeomMesh values and convert them to a Blender Mesh,
44 * also returning face_indices and counts for further loop processing. */
45 Mesh *mesh_from_prim(Mesh *existing_mesh,
47 pxr::VtIntArray &face_indices,
48 pxr::VtIntArray &face_counts) const;
49
50 Mesh *read_mesh(Mesh *existing_mesh, USDMeshReadParams params, const char ** /*r_err_str*/);
51
52 public:
53 USDShapeReader(const pxr::UsdPrim &prim,
54 const USDImportParams &import_params,
55 const ImportSettings &settings);
56
57 void create_object(Main *bmain) override;
58 void read_object_data(Main *bmain, pxr::UsdTimeCode time) override;
59 void read_geometry(bke::GeometrySet & /*geometry_set*/,
60 USDMeshReadParams /*params*/,
61 const char ** /*r_err_str*/) override;
62
63 /* Returns the generated mesh might be affected by time-varying attributes.
64 * This assumes mesh_from_prim() has been called. */
65 bool is_time_varying();
66
67 bool topology_changed(const Mesh * /*existing_mesh*/, pxr::UsdTimeCode /*time*/) override
68 {
69 return false;
70 };
71};
72
73} // namespace blender::io::usd
USDGeomReader(const pxr::UsdPrim &prim, const USDImportParams &import_params, const ImportSettings &settings)
const pxr::UsdPrim & prim() const
void create_object(Main *bmain) override
USDShapeReader(const pxr::UsdPrim &prim, const USDImportParams &import_params, const ImportSettings &settings)
bool topology_changed(const Mesh *, pxr::UsdTimeCode) override
void read_geometry(bke::GeometrySet &, USDMeshReadParams, const char **) override
void read_object_data(Main *bmain, pxr::UsdTimeCode time) override
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]