USD Export: New Curves/Hair Support #105375
|
@ -1,5 +1,5 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-or-later
|
||||
* Copyright 2022 Blender Foundation. All rights reserved. */
|
||||
* Copyright 2023 Blender Foundation. All rights reserved. */
|
||||
SonnyCampbell_Unity marked this conversation as resolved
Outdated
|
||||
|
||||
#include <numeric>
|
||||
|
||||
|
@ -174,7 +174,6 @@ static void populate_curve_verts_for_bezier(const bke::CurvesGeometry &geometry,
|
|||
{
|
||||
const int bezier_vstep = 3;
|
||||
const OffsetIndices points_by_curve = geometry.points_by_curve();
|
||||
const int start_verts_count = verts.size();
|
||||
|
||||
for (int i_curve = 0; i_curve < geometry.curve_num; i_curve++) {
|
||||
SonnyCampbell_Unity marked this conversation as resolved
Outdated
Hans Goudey
commented
`for (const int i_curve : geometry.curves_range())` is a slightly nicer way to write this, and it allows the iterator variable to be const
|
||||
|
||||
|
@ -182,6 +181,8 @@ static void populate_curve_verts_for_bezier(const bke::CurvesGeometry &geometry,
|
|||
const int start_point_index = curve_points[0];
|
||||
const int last_point_index = curve_points[curve_points.size() - 1];
|
||||
|
||||
const int start_verts_count = verts.size();
|
||||
|
||||
for (int i_point = start_point_index; i_point < last_point_index; i_point++) {
|
||||
SonnyCampbell_Unity marked this conversation as resolved
Outdated
Hans Goudey
commented
If you want to skip the last point, you can use `IndexRange` can be iterated directly here: `for (const int i : points) {`
If you want to skip the last point, you can use `for (const int i : points.drop_back(1)) {`
Matt McLin
commented
Is this a necessary change? Personally I find "i_point < last_point_index" more readable than points.drop_back(1). Is this a necessary change? Personally I find "i_point < last_point_index" more readable than points.drop_back(1).
|
||||
|
||||
/* The order verts in the USD bezier curve representation is [control point 0, right handle
|
||||
|
@ -397,7 +398,8 @@ void USDCurvesWriter::do_write(HierarchyContext &context)
|
|||
}
|
||||
|
||||
if (!all_same_cyclic_type) {
|
||||
WM_report(RPT_WARNING, "Cannot export mixed cyclic and non-cyclic curves in the same Curve object.");
|
||||
WM_report(RPT_WARNING,
|
||||
"Cannot export mixed cyclic and non-cyclic curves in the same Curve object.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -411,6 +413,20 @@ void USDCurvesWriter::do_write(HierarchyContext &context)
|
|||
pxr::TfToken interpolation;
|
||||
|
||||
const int8_t curve_type = geometry.curve_types()[0];
|
||||
|
||||
if (first_frame_curve_type == -1) {
|
||||
first_frame_curve_type = curve_type;
|
||||
}
|
||||
else if (first_frame_curve_type != curve_type) {
|
||||
WM_reportf(RPT_WARNING,
|
||||
"USD does not support animating curve types. The curve type changes from %i to "
|
||||
SonnyCampbell_Unity marked this conversation as resolved
Outdated
Hans Goudey
commented
If you want this to be extra pretty, you could use If you want this to be extra pretty, you could use `rna_enum_curves_types` and `IFACE_(RNA_enum_name_from_value(..)` to print the UI name instead of the integer value.
|
||||
"%i on frame %f",
|
||||
first_frame_curve_type,
|
||||
curve_type,
|
||||
timecode);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (curve_type) {
|
||||
SonnyCampbell_Unity marked this conversation as resolved
Outdated
Hans Goudey
commented
Functional style casts here (and below) (https://wiki.blender.org/wiki/Style_Guide/C_Cpp#C.2B.2B_Type_Cast) `(int)first_frame_curve_type` -> `int(first_frame_curve_type)`
Functional style casts here (and below) (https://wiki.blender.org/wiki/Style_Guide/C_Cpp#C.2B.2B_Type_Cast)
|
||||
case CURVE_TYPE_POLY:
|
||||
usd_curves = DefineUsdGeomBasisCurves(pxr::VtValue(), is_cyclic, false);
|
||||
|
|
|
@ -15,7 +15,6 @@ namespace blender::io::usd {
|
|||
class USDCurvesWriter : public USDAbstractWriter {
|
||||
public:
|
||||
USDCurvesWriter(const USDExporterContext &ctx);
|
||||
USDCurvesWriter(const USDExporterContext &ctx, std::unique_ptr<Curves> converted_legacy_curves);
|
||||
~USDCurvesWriter();
|
||||
|
||||
protected:
|
||||
|
@ -23,6 +22,7 @@ class USDCurvesWriter : public USDAbstractWriter {
|
|||
void assign_materials(const HierarchyContext &context, pxr::UsdGeomCurves usd_curve);
|
||||
|
||||
private:
|
||||
int8_t first_frame_curve_type = -1;
|
||||
pxr::UsdGeomCurves DefineUsdGeomBasisCurves(pxr::VtValue curve_basis, bool cyclic, bool cubic);
|
||||
|
||||
void set_writer_attributes(pxr::UsdGeomCurves &usd_curves,
|
||||
|
|
Loading…
Reference in New Issue
Should be this year.