Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAras Pranckevicius <aras@nesnausk.org>2022-04-17 21:59:55 +0300
committerAras Pranckevicius <aras@nesnausk.org>2022-04-17 21:59:55 +0300
commita3eb4027c2383827b9f5beed709c54c53c7d6d20 (patch)
treef2b73785a7e54190fd22598659f71fb019b7030d /source/blender/io/wavefront_obj/exporter
parentb32cb0266c61abb333906dc6848d252f6f4dbd20 (diff)
Fix T97095: export of Poly curves, export crash when object contains multiple curve types
- Was not exporting "Poly" curves at all, - Had a crash when a single object contains multiple curves of different types -- it had a check for "is this nurbs compatible?" only for the first curve, and then proceeded to treat the other curves as nurbs as well, without checking for validity. Fixed both issues by doing the same logic as in the old python exporter: - Poly curves are supported, - Treat object as "nurbs compatible" only if all the curves within it are nurbs compatible. Added test coverage in the gtest suite. While at it, made "all_curves" test use the "golden obj file template" style test, instead of a manually coded test that checks intermediate objects but does not check the final exported result. Reviewed By: Howard Trickey Differential Revision: https://developer.blender.org/D14611
Diffstat (limited to 'source/blender/io/wavefront_obj/exporter')
-rw-r--r--source/blender/io/wavefront_obj/exporter/obj_export_nurbs.cc6
-rw-r--r--source/blender/io/wavefront_obj/exporter/obj_exporter.cc39
2 files changed, 21 insertions, 24 deletions
diff --git a/source/blender/io/wavefront_obj/exporter/obj_export_nurbs.cc b/source/blender/io/wavefront_obj/exporter/obj_export_nurbs.cc
index 17069c18295..c247048ce13 100644
--- a/source/blender/io/wavefront_obj/exporter/obj_export_nurbs.cc
+++ b/source/blender/io/wavefront_obj/exporter/obj_export_nurbs.cc
@@ -72,12 +72,12 @@ float3 OBJCurve::vertex_coordinates(const int spline_index,
int OBJCurve::total_spline_control_points(const int spline_index) const
{
const Nurb *const nurb = static_cast<Nurb *>(BLI_findlink(&export_curve_->nurb, spline_index));
- const int r_nurbs_degree = nurb->orderu - 1;
+ int degree = nurb->type == CU_POLY ? 1 : nurb->orderu - 1;
/* Total control points = Number of points in the curve (+ degree of the
* curve if it is cyclic). */
int r_tot_control_points = nurb->pntsv * nurb->pntsu;
if (nurb->flagu & CU_NURB_CYCLIC) {
- r_tot_control_points += r_nurbs_degree;
+ r_tot_control_points += degree;
}
return r_tot_control_points;
}
@@ -85,7 +85,7 @@ int OBJCurve::total_spline_control_points(const int spline_index) const
int OBJCurve::get_nurbs_degree(const int spline_index) const
{
const Nurb *const nurb = static_cast<Nurb *>(BLI_findlink(&export_curve_->nurb, spline_index));
- return nurb->orderu - 1;
+ return nurb->type == CU_POLY ? 1 : nurb->orderu - 1;
}
short OBJCurve::get_nurbs_flagu(const int spline_index) const
diff --git a/source/blender/io/wavefront_obj/exporter/obj_exporter.cc b/source/blender/io/wavefront_obj/exporter/obj_exporter.cc
index 584d8ae4ec0..78b709c884a 100644
--- a/source/blender/io/wavefront_obj/exporter/obj_exporter.cc
+++ b/source/blender/io/wavefront_obj/exporter/obj_exporter.cc
@@ -68,6 +68,17 @@ static void print_exception_error(const std::system_error &ex)
<< std::endl;
}
+static bool is_curve_nurbs_compatible(const Nurb *nurb)
+{
+ while (nurb) {
+ if (nurb->type == CU_BEZIER || nurb->pntsv != 1) {
+ return false;
+ }
+ nurb = nurb->next;
+ }
+ return true;
+}
+
/**
* Filter supported objects from the Scene.
*
@@ -104,27 +115,13 @@ filter_supported_objects(Depsgraph *depsgraph, const OBJExportParams &export_par
}
break;
}
- switch (nurb->type) {
- case CU_NURBS:
- if (export_params.export_curves_as_nurbs) {
- /* Export in parameter form: control points. */
- r_exportable_nurbs.append(
- std::make_unique<OBJCurve>(depsgraph, export_params, object));
- }
- else {
- /* Export in mesh form: edges and vertices. */
- r_exportable_meshes.append(
- std::make_unique<OBJMesh>(depsgraph, export_params, object));
- }
- break;
- case CU_BEZIER:
- /* Always export in mesh form: edges and vertices. */
- r_exportable_meshes.append(
- std::make_unique<OBJMesh>(depsgraph, export_params, object));
- break;
- default:
- /* Other curve types are not supported. */
- break;
+ if (export_params.export_curves_as_nurbs && is_curve_nurbs_compatible(nurb)) {
+ /* Export in parameter form: control points. */
+ r_exportable_nurbs.append(std::make_unique<OBJCurve>(depsgraph, export_params, object));
+ }
+ else {
+ /* Export in mesh form: edges and vertices. */
+ r_exportable_meshes.append(std::make_unique<OBJMesh>(depsgraph, export_params, object));
}
break;
}