Files
test2/source/blender/io/usd/intern/usd_reader_shape.hh

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

74 lines
2.8 KiB
C++
Raw Normal View History

/* SPDX-FileCopyrightText: 2023 Nvidia. All rights reserved.
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma once
#include "usd.hh"
#include "usd_hash_types.hh"
#include "usd_reader_geom.hh"
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 {
/* 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_;
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;
void apply_primvars_to_mesh(Mesh *mesh, double motionSampleTime) const;
/* 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,
USDMeshReadParams params,
pxr::VtIntArray &face_indices,
pxr::VtIntArray &face_counts) const;
Mesh *read_mesh(Mesh *existing_mesh, USDMeshReadParams params, const char ** /*r_err_str*/);
Alembic/USD: Use GeometrySets to import data This rewrites the Alembic and USD data importers to work with and output GeometrySets instead of Meshes. The main motivation for this change is to be able to import properly point clouds, which are currently imported as Meshes, and curves data, which suffer from a lot of issues due to limitations of legacy curves structures (fixed by the new curves data-block) and are also converted to Meshes. Further, for Curves, it will allow importing arbitrary attributes. This patch was primarily meant for Alembic, but changes to USD import were necessary as they share the same modifier. For Alembic: There should be no behavioral changes for Meshes Curves are imported as the new Curves object type Points are imported as PointClouds For USD: There should be no behavioral changes for Meshes Curves are imported as the new Curves object type Note that the current USD importer does not support loading PointClouds, so this patch does not add support for it. For both Alembic and USD, knots arrays are not read anymore, as the new Curves object does not expose the ability to set them. Improvements can be made in the future if and when example assets are provided. This fixes at least the following: #58704: Animated Alembic curves don't update on render #112308: Curves have offset animations (alembic / USD) #118261: wrong motion blur from usd in cycles and reverting to the first frame when disabeling motion blur Co-authored-by: Jesse Yurkovich <jesse.y@gmail.com> Pull Request: https://projects.blender.org/blender/blender/pulls/115623
2024-02-28 03:02:38 +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;
Alembic/USD: Use GeometrySets to import data This rewrites the Alembic and USD data importers to work with and output GeometrySets instead of Meshes. The main motivation for this change is to be able to import properly point clouds, which are currently imported as Meshes, and curves data, which suffer from a lot of issues due to limitations of legacy curves structures (fixed by the new curves data-block) and are also converted to Meshes. Further, for Curves, it will allow importing arbitrary attributes. This patch was primarily meant for Alembic, but changes to USD import were necessary as they share the same modifier. For Alembic: There should be no behavioral changes for Meshes Curves are imported as the new Curves object type Points are imported as PointClouds For USD: There should be no behavioral changes for Meshes Curves are imported as the new Curves object type Note that the current USD importer does not support loading PointClouds, so this patch does not add support for it. For both Alembic and USD, knots arrays are not read anymore, as the new Curves object does not expose the ability to set them. Improvements can be made in the future if and when example assets are provided. This fixes at least the following: #58704: Animated Alembic curves don't update on render #112308: Curves have offset animations (alembic / USD) #118261: wrong motion blur from usd in cycles and reverting to the first frame when disabeling motion blur Co-authored-by: Jesse Yurkovich <jesse.y@gmail.com> Pull Request: https://projects.blender.org/blender/blender/pulls/115623
2024-02-28 03:02:38 +01:00
void read_geometry(bke::GeometrySet & /*geometry_set*/,
USDMeshReadParams /*params*/,
const char ** /*r_err_str*/) override;
Alembic/USD: Use GeometrySets to import data This rewrites the Alembic and USD data importers to work with and output GeometrySets instead of Meshes. The main motivation for this change is to be able to import properly point clouds, which are currently imported as Meshes, and curves data, which suffer from a lot of issues due to limitations of legacy curves structures (fixed by the new curves data-block) and are also converted to Meshes. Further, for Curves, it will allow importing arbitrary attributes. This patch was primarily meant for Alembic, but changes to USD import were necessary as they share the same modifier. For Alembic: There should be no behavioral changes for Meshes Curves are imported as the new Curves object type Points are imported as PointClouds For USD: There should be no behavioral changes for Meshes Curves are imported as the new Curves object type Note that the current USD importer does not support loading PointClouds, so this patch does not add support for it. For both Alembic and USD, knots arrays are not read anymore, as the new Curves object does not expose the ability to set them. Improvements can be made in the future if and when example assets are provided. This fixes at least the following: #58704: Animated Alembic curves don't update on render #112308: Curves have offset animations (alembic / USD) #118261: wrong motion blur from usd in cycles and reverting to the first frame when disabeling motion blur Co-authored-by: Jesse Yurkovich <jesse.y@gmail.com> Pull Request: https://projects.blender.org/blender/blender/pulls/115623
2024-02-28 03:02:38 +01:00
/* Returns the generated mesh might be affected by time-varying attributes.
* This assumes mesh_from_prim() has been called. */
bool is_time_varying();
bool topology_changed(const Mesh * /*existing_mesh*/, double /*motionSampleTime*/) override
{
return false;
};
};
} // namespace blender::io::usd