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