IO: factor out axis validation logic between OBJ and PLY

The up_axis_update/forward_axis_update was the same logic between
the two, so factor that out.

Also use the same time reporting logic in PLY as in OBJ/USD/Alembic.
This commit is contained in:
2023-03-06 10:21:38 +02:00
parent 62c4dce83b
commit 08db6bf215
5 changed files with 56 additions and 69 deletions

View File

@@ -221,29 +221,6 @@ static bool wm_obj_export_check(bContext *C, wmOperator *op)
return changed;
}
/* Both forward and up axes cannot be along the same direction. */
static void forward_axis_update(struct Main *UNUSED(main),
struct Scene *UNUSED(scene),
struct PointerRNA *ptr)
{
int forward = RNA_enum_get(ptr, "forward_axis");
int up = RNA_enum_get(ptr, "up_axis");
if ((forward % 3) == (up % 3)) {
RNA_enum_set(ptr, "up_axis", (up + 1) % 6);
}
}
static void up_axis_update(struct Main *UNUSED(main),
struct Scene *UNUSED(scene),
struct PointerRNA *ptr)
{
int forward = RNA_enum_get(ptr, "forward_axis");
int up = RNA_enum_get(ptr, "up_axis");
if ((forward % 3) == (up % 3)) {
RNA_enum_set(ptr, "forward_axis", (forward + 1) % 6);
}
}
void WM_OT_obj_export(struct wmOperatorType *ot)
{
PropertyRNA *prop;
@@ -295,9 +272,9 @@ void WM_OT_obj_export(struct wmOperatorType *ot)
/* Object transform options. */
prop = RNA_def_enum(
ot->srna, "forward_axis", io_transform_axis, IO_AXIS_NEGATIVE_Z, "Forward Axis", "");
RNA_def_property_update_runtime(prop, (void *)forward_axis_update);
RNA_def_property_update_runtime(prop, (void *)io_ui_forward_axis_update);
prop = RNA_def_enum(ot->srna, "up_axis", io_transform_axis, IO_AXIS_Y, "Up Axis", "");
RNA_def_property_update_runtime(prop, (void *)up_axis_update);
RNA_def_property_update_runtime(prop, (void *)io_ui_up_axis_update);
RNA_def_float(
ot->srna,
"global_scale",
@@ -527,9 +504,9 @@ void WM_OT_obj_import(struct wmOperatorType *ot)
1000.0f);
prop = RNA_def_enum(
ot->srna, "forward_axis", io_transform_axis, IO_AXIS_NEGATIVE_Z, "Forward Axis", "");
RNA_def_property_update_runtime(prop, (void *)forward_axis_update);
RNA_def_property_update_runtime(prop, (void *)io_ui_forward_axis_update);
prop = RNA_def_enum(ot->srna, "up_axis", io_transform_axis, IO_AXIS_Y, "Up Axis", "");
RNA_def_property_update_runtime(prop, (void *)up_axis_update);
RNA_def_property_update_runtime(prop, (void *)io_ui_up_axis_update);
RNA_def_boolean(ot->srna,
"use_split_objects",
true,

View File

@@ -144,29 +144,6 @@ static bool wm_ply_export_check(bContext *UNUSED(C), wmOperator *op)
return changed;
}
/* Both forward and up axes cannot be along the same direction. */
static void forward_axis_update(struct Main *UNUSED(main),
struct Scene *UNUSED(scene),
struct PointerRNA *ptr)
{
int forward = RNA_enum_get(ptr, "forward_axis");
int up = RNA_enum_get(ptr, "up_axis");
if ((forward % 3) == (up % 3)) {
RNA_enum_set(ptr, "up_axis", (up + 1) % 6);
}
}
static void up_axis_update(struct Main *UNUSED(main),
struct Scene *UNUSED(scene),
struct PointerRNA *ptr)
{
int forward = RNA_enum_get(ptr, "forward_axis");
int up = RNA_enum_get(ptr, "up_axis");
if ((forward % 3) == (up % 3)) {
RNA_enum_set(ptr, "forward_axis", (forward + 1) % 6);
}
}
void WM_OT_ply_export(struct wmOperatorType *ot)
{
PropertyRNA *prop;
@@ -193,9 +170,9 @@ void WM_OT_ply_export(struct wmOperatorType *ot)
/* Object transform options. */
prop = RNA_def_enum(ot->srna, "forward_axis", io_transform_axis, IO_AXIS_Y, "Forward Axis", "");
RNA_def_property_update_runtime(prop, (void *)forward_axis_update);
RNA_def_property_update_runtime(prop, (void *)io_ui_forward_axis_update);
prop = RNA_def_enum(ot->srna, "up_axis", io_transform_axis, IO_AXIS_Z, "Up Axis", "");
RNA_def_property_update_runtime(prop, (void *)up_axis_update);
RNA_def_property_update_runtime(prop, (void *)io_ui_up_axis_update);
RNA_def_float(
ot->srna,
"global_scale",
@@ -295,18 +272,6 @@ static int wm_ply_import_execute(bContext *C, wmOperator *op)
return OPERATOR_FINISHED;
}
static bool wm_ply_import_check(bContext *UNUSED(C), wmOperator *op)
{
const int num_axes = 3;
/* Both forward and up axes cannot be the same (or same except opposite sign). */
if (RNA_enum_get(op->ptr, "forward_axis") % num_axes ==
(RNA_enum_get(op->ptr, "up_axis") % num_axes)) {
RNA_enum_set(op->ptr, "up_axis", RNA_enum_get(op->ptr, "up_axis") % num_axes + 1);
return true;
}
return false;
}
void WM_OT_ply_import(struct wmOperatorType *ot)
{
PropertyRNA *prop;
@@ -318,7 +283,6 @@ void WM_OT_ply_import(struct wmOperatorType *ot)
ot->invoke = wm_ply_import_invoke;
ot->exec = wm_ply_import_execute;
ot->poll = WM_operator_winactive;
ot->check = wm_ply_import_check;
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_PRESET;
WM_operator_properties_filesel(ot,
@@ -336,8 +300,10 @@ void WM_OT_ply_import(struct wmOperatorType *ot)
false,
"Scene Unit",
"Apply current scene's unit (as defined by unit scale) to imported data");
RNA_def_enum(ot->srna, "forward_axis", io_transform_axis, IO_AXIS_Y, "Forward Axis", "");
RNA_def_enum(ot->srna, "up_axis", io_transform_axis, IO_AXIS_Z, "Up Axis", "");
prop = RNA_def_enum(ot->srna, "forward_axis", io_transform_axis, IO_AXIS_Y, "Forward Axis", "");
RNA_def_property_update_runtime(prop, (void *)io_ui_forward_axis_update);
prop = RNA_def_enum(ot->srna, "up_axis", io_transform_axis, IO_AXIS_Z, "Up Axis", "");
RNA_def_property_update_runtime(prop, (void *)io_ui_up_axis_update);
RNA_def_boolean(ot->srna, "merge_verts", false, "Merge Vertices", "Merges vertices by distance");
RNA_def_enum(ot->srna,
"import_colors",

View File

@@ -4,6 +4,9 @@
#include "RNA_types.h"
struct Main;
struct Scene;
typedef enum {
IO_AXIS_X = 0,
IO_AXIS_Y = 1,
@@ -14,3 +17,6 @@ typedef enum {
} eIOAxis;
extern const EnumPropertyItem io_transform_axis[];
void io_ui_forward_axis_update(struct Main *main, struct Scene *scene, struct PointerRNA *ptr);
void io_ui_up_axis_update(struct Main *main, struct Scene *scene, struct PointerRNA *ptr);

View File

@@ -1,5 +1,8 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
#include "BKE_main.h"
#include "DNA_scene_types.h"
#include "RNA_access.h"
#include "RNA_types.h"
#include "IO_orientation.h"
@@ -12,3 +15,26 @@ const EnumPropertyItem io_transform_axis[] = {
{IO_AXIS_NEGATIVE_Y, "NEGATIVE_Y", 0, "-Y", "Negative Y axis"},
{IO_AXIS_NEGATIVE_Z, "NEGATIVE_Z", 0, "-Z", "Negative Z axis"},
{0, NULL, 0, NULL, NULL}};
/* Both forward and up axes cannot be along the same direction. */
void io_ui_forward_axis_update(struct Main *UNUSED(main),
struct Scene *UNUSED(scene),
struct PointerRNA *ptr)
{
int forward = RNA_enum_get(ptr, "forward_axis");
int up = RNA_enum_get(ptr, "up_axis");
if ((forward % 3) == (up % 3)) {
RNA_enum_set(ptr, "up_axis", (up + 1) % 6);
}
}
void io_ui_up_axis_update(struct Main *UNUSED(main),
struct Scene *UNUSED(scene),
struct PointerRNA *ptr)
{
int forward = RNA_enum_get(ptr, "forward_axis");
int up = RNA_enum_get(ptr, "up_axis");
if ((forward % 3) == (up % 3)) {
RNA_enum_set(ptr, "forward_axis", (forward + 1) % 6);
}
}

View File

@@ -11,14 +11,26 @@
#include "ply_export.hh"
#include "ply_import.hh"
using namespace blender::timeit;
static void report_duration(const char *job, const TimePoint &start_time, const char *path)
{
Nanoseconds duration = Clock::now() - start_time;
std::cout << "PLY " << job << " of '" << BLI_path_basename(path) << "' took ";
print_duration(duration);
std::cout << '\n';
}
void PLY_export(bContext *C, const PLYExportParams *export_params)
{
SCOPED_TIMER("PLY Export");
TimePoint start_time = Clock::now();
blender::io::ply::exporter_main(C, *export_params);
report_duration("export", start_time, export_params->filepath);
}
void PLY_import(bContext *C, const PLYImportParams *import_params, wmOperator *op)
{
SCOPED_TIMER("PLY Import");
TimePoint start_time = Clock::now();
blender::io::ply::importer_main(C, *import_params, op);
report_duration("import", start_time, import_params->filepath);
}