2023-05-31 16:19:06 +02:00
|
|
|
/* SPDX-FileCopyrightText: 2023 Nvidia. All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2023-02-13 19:49:24 +01:00
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2024-02-06 13:03:28 +01:00
|
|
|
#include "usd.hh"
|
2024-05-15 05:44:26 +02:00
|
|
|
#include "usd_hash_types.hh"
|
2024-02-05 19:02:00 +01:00
|
|
|
#include "usd_reader_geom.hh"
|
2023-02-13 19:49:24 +01:00
|
|
|
|
|
|
|
|
struct Mesh;
|
|
|
|
|
|
|
|
|
|
namespace blender::io::usd {
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Read USDGeom primitive shapes as Blender Meshes. This class uses the same adapter functions
|
|
|
|
|
* as the GL viewport to generate geometry for each of the supported types.
|
|
|
|
|
*/
|
|
|
|
|
class USDShapeReader : public USDGeomReader {
|
2024-04-24 20:58:53 +02:00
|
|
|
/* A cache to record whether a given primvar is time-varying, so that static primvars are not
|
|
|
|
|
* read more than once when the mesh is evaluated for animation by the cache file modifier.
|
|
|
|
|
* The map is mutable so that it can be updated in const functions. */
|
|
|
|
|
mutable blender::Map<const pxr::TfToken, bool> primvar_time_varying_map_;
|
|
|
|
|
|
2023-02-13 19:49:24 +01:00
|
|
|
private:
|
|
|
|
|
/* Template required to read mesh information out of Shape prims,
|
|
|
|
|
* as each prim type has a separate subclass. */
|
|
|
|
|
template<typename Adapter>
|
|
|
|
|
void read_values(double motionSampleTime,
|
|
|
|
|
pxr::VtVec3fArray &positions,
|
|
|
|
|
pxr::VtIntArray &face_indices,
|
|
|
|
|
pxr::VtIntArray &face_counts) const;
|
|
|
|
|
|
|
|
|
|
/* Wrapper for the templated method read_values, calling the correct template
|
|
|
|
|
* instantiation based on the introspected prim type. */
|
|
|
|
|
bool read_mesh_values(double motionSampleTime,
|
|
|
|
|
pxr::VtVec3fArray &positions,
|
|
|
|
|
pxr::VtIntArray &face_indices,
|
|
|
|
|
pxr::VtIntArray &face_counts) const;
|
|
|
|
|
|
2024-04-24 20:58:53 +02:00
|
|
|
void apply_primvars_to_mesh(Mesh *mesh, double motionSampleTime) const;
|
|
|
|
|
|
2023-02-13 19:49:24 +01:00
|
|
|
/* Read the pxr:UsdGeomMesh values and convert them to a Blender Mesh,
|
|
|
|
|
* also returning face_indices and counts for further loop processing. */
|
|
|
|
|
Mesh *mesh_from_prim(Mesh *existing_mesh,
|
2024-04-24 20:58:53 +02:00
|
|
|
USDMeshReadParams params,
|
2023-02-13 19:49:24 +01:00
|
|
|
pxr::VtIntArray &face_indices,
|
|
|
|
|
pxr::VtIntArray &face_counts) const;
|
|
|
|
|
|
2024-08-23 13:09:20 +10:00
|
|
|
Mesh *read_mesh(Mesh *existing_mesh, USDMeshReadParams params, const char ** /*r_err_str*/);
|
2024-02-28 03:02:38 +01:00
|
|
|
|
2023-02-13 19:49:24 +01:00
|
|
|
public:
|
|
|
|
|
USDShapeReader(const pxr::UsdPrim &prim,
|
|
|
|
|
const USDImportParams &import_params,
|
|
|
|
|
const ImportSettings &settings);
|
|
|
|
|
|
|
|
|
|
void create_object(Main *bmain, double /*motionSampleTime*/) override;
|
|
|
|
|
void read_object_data(Main *bmain, double motionSampleTime) override;
|
2024-02-28 03:02:38 +01:00
|
|
|
void read_geometry(bke::GeometrySet & /*geometry_set*/,
|
|
|
|
|
USDMeshReadParams /*params*/,
|
2024-08-23 13:09:20 +10:00
|
|
|
const char ** /*r_err_str*/) override;
|
2024-02-28 03:02:38 +01:00
|
|
|
|
2024-04-24 20:58:53 +02:00
|
|
|
/* Returns the generated mesh might be affected by time-varying attributes.
|
|
|
|
|
* This assumes mesh_from_prim() has been called. */
|
2023-02-13 19:49:24 +01:00
|
|
|
bool is_time_varying();
|
|
|
|
|
|
2025-01-26 20:08:04 +01:00
|
|
|
bool topology_changed(const Mesh * /*existing_mesh*/, double /*motionSampleTime*/) override
|
2023-02-13 19:49:24 +01:00
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace blender::io::usd
|