OBJ: add global scale factor import setting
Requested in D16095 proposal - also USD & Alembic have import scale option; OBJ has an export scale object but the import scale was not there for some reason.
This commit is contained in:
parent
a24f11e0ec
commit
42b1a7d4c6
|
@ -81,7 +81,7 @@ static int wm_obj_export_exec(bContext *C, wmOperator *op)
|
|||
|
||||
export_params.forward_axis = RNA_enum_get(op->ptr, "forward_axis");
|
||||
export_params.up_axis = RNA_enum_get(op->ptr, "up_axis");
|
||||
export_params.scaling_factor = RNA_float_get(op->ptr, "scaling_factor");
|
||||
export_params.global_scale = RNA_float_get(op->ptr, "global_scale");
|
||||
export_params.apply_modifiers = RNA_boolean_get(op->ptr, "apply_modifiers");
|
||||
export_params.export_eval_mode = RNA_enum_get(op->ptr, "export_eval_mode");
|
||||
|
||||
|
@ -122,7 +122,7 @@ static void ui_obj_export_settings(uiLayout *layout, PointerRNA *imfptr)
|
|||
col = uiLayoutColumn(box, false);
|
||||
sub = uiLayoutColumnWithHeading(col, false, IFACE_("Limit to"));
|
||||
uiItemR(sub, imfptr, "export_selected_objects", 0, IFACE_("Selected Only"), ICON_NONE);
|
||||
uiItemR(sub, imfptr, "scaling_factor", 0, NULL, ICON_NONE);
|
||||
uiItemR(sub, imfptr, "global_scale", 0, NULL, ICON_NONE);
|
||||
|
||||
row = uiLayoutRow(box, false);
|
||||
uiItemR(row, imfptr, "forward_axis", UI_ITEM_R_EXPAND, IFACE_("Forward Axis"), ICON_NONE);
|
||||
|
@ -301,15 +301,16 @@ void WM_OT_obj_export(struct wmOperatorType *ot)
|
|||
RNA_def_property_update_runtime(prop, (void *)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_float(ot->srna,
|
||||
"scaling_factor",
|
||||
1.0f,
|
||||
0.001f,
|
||||
10000.0f,
|
||||
"Scale",
|
||||
"Upscale the object by this factor",
|
||||
0.01,
|
||||
1000.0f);
|
||||
RNA_def_float(
|
||||
ot->srna,
|
||||
"global_scale",
|
||||
1.0f,
|
||||
0.0001f,
|
||||
10000.0f,
|
||||
"Scale",
|
||||
"Value by which to enlarge or shrink the objects with respect to the world's origin",
|
||||
0.0001f,
|
||||
10000.0f);
|
||||
/* File Writer options. */
|
||||
RNA_def_boolean(
|
||||
ot->srna, "apply_modifiers", true, "Apply Modifiers", "Apply modifiers to exported meshes");
|
||||
|
@ -405,6 +406,7 @@ static int wm_obj_import_exec(bContext *C, wmOperator *op)
|
|||
{
|
||||
struct OBJImportParams import_params;
|
||||
RNA_string_get(op->ptr, "filepath", import_params.filepath);
|
||||
import_params.global_scale = RNA_float_get(op->ptr, "global_scale");
|
||||
import_params.clamp_size = RNA_float_get(op->ptr, "clamp_size");
|
||||
import_params.forward_axis = RNA_enum_get(op->ptr, "forward_axis");
|
||||
import_params.up_axis = RNA_enum_get(op->ptr, "up_axis");
|
||||
|
@ -459,6 +461,7 @@ static void ui_obj_import_settings(uiLayout *layout, PointerRNA *imfptr)
|
|||
uiItemL(box, IFACE_("Transform"), ICON_OBJECT_DATA);
|
||||
uiLayout *col = uiLayoutColumn(box, false);
|
||||
uiLayout *sub = uiLayoutColumn(col, false);
|
||||
uiItemR(sub, imfptr, "global_scale", 0, NULL, ICON_NONE);
|
||||
uiItemR(sub, imfptr, "clamp_size", 0, NULL, ICON_NONE);
|
||||
sub = uiLayoutColumn(col, false);
|
||||
|
||||
|
@ -504,6 +507,16 @@ void WM_OT_obj_import(struct wmOperatorType *ot)
|
|||
WM_FILESEL_DIRECTORY | WM_FILESEL_FILES,
|
||||
FILE_DEFAULTDISPLAY,
|
||||
FILE_SORT_DEFAULT);
|
||||
RNA_def_float(
|
||||
ot->srna,
|
||||
"global_scale",
|
||||
1.0f,
|
||||
0.0001f,
|
||||
10000.0f,
|
||||
"Scale",
|
||||
"Value by which to enlarge or shrink the objects with respect to the world's origin",
|
||||
0.0001f,
|
||||
10000.0f);
|
||||
RNA_def_float(
|
||||
ot->srna,
|
||||
"clamp_size",
|
||||
|
|
|
@ -35,7 +35,7 @@ struct OBJExportParams {
|
|||
/* Geometry Transform options. */
|
||||
eIOAxis forward_axis;
|
||||
eIOAxis up_axis;
|
||||
float scaling_factor;
|
||||
float global_scale;
|
||||
|
||||
/* File Write Options. */
|
||||
bool export_selected_objects;
|
||||
|
@ -65,6 +65,7 @@ struct OBJImportParams {
|
|||
char filepath[FILE_MAX];
|
||||
/** Value 0 disables clamping. */
|
||||
float clamp_size;
|
||||
float global_scale;
|
||||
eIOAxis forward_axis;
|
||||
eIOAxis up_axis;
|
||||
bool import_vertex_groups;
|
||||
|
|
|
@ -261,7 +261,7 @@ void OBJWriter::write_vertex_coords(FormatHandler &fh,
|
|||
|
||||
BLI_assert(tot_count == attribute.size());
|
||||
obj_parallel_chunked_output(fh, tot_count, [&](FormatHandler &buf, int i) {
|
||||
float3 vertex = obj_mesh_data.calc_vertex_coords(i, export_params_.scaling_factor);
|
||||
float3 vertex = obj_mesh_data.calc_vertex_coords(i, export_params_.global_scale);
|
||||
ColorGeometry4f linear = attribute.get(i);
|
||||
float srgb[3];
|
||||
linearrgb_to_srgb_v3_v3(srgb, linear);
|
||||
|
@ -270,7 +270,7 @@ void OBJWriter::write_vertex_coords(FormatHandler &fh,
|
|||
}
|
||||
else {
|
||||
obj_parallel_chunked_output(fh, tot_count, [&](FormatHandler &buf, int i) {
|
||||
float3 vertex = obj_mesh_data.calc_vertex_coords(i, export_params_.scaling_factor);
|
||||
float3 vertex = obj_mesh_data.calc_vertex_coords(i, export_params_.global_scale);
|
||||
buf.write_obj_vertex(vertex[0], vertex[1], vertex[2]);
|
||||
});
|
||||
}
|
||||
|
@ -435,7 +435,7 @@ void OBJWriter::write_nurbs_curve(FormatHandler &fh, const OBJCurve &obj_nurbs_d
|
|||
const int total_vertices = obj_nurbs_data.total_spline_vertices(spline_idx);
|
||||
for (int vertex_idx = 0; vertex_idx < total_vertices; vertex_idx++) {
|
||||
const float3 vertex_coords = obj_nurbs_data.vertex_coordinates(
|
||||
spline_idx, vertex_idx, export_params_.scaling_factor);
|
||||
spline_idx, vertex_idx, export_params_.global_scale);
|
||||
fh.write_obj_vertex(vertex_coords[0], vertex_coords[1], vertex_coords[2]);
|
||||
}
|
||||
|
||||
|
|
|
@ -265,13 +265,13 @@ const char *OBJMesh::get_object_material_name(const int16_t mat_nr) const
|
|||
return mat->id.name + 2;
|
||||
}
|
||||
|
||||
float3 OBJMesh::calc_vertex_coords(const int vert_index, const float scaling_factor) const
|
||||
float3 OBJMesh::calc_vertex_coords(const int vert_index, const float global_scale) const
|
||||
{
|
||||
float3 r_coords;
|
||||
const Span<MVert> verts = export_mesh_eval_->verts();
|
||||
copy_v3_v3(r_coords, verts[vert_index].co);
|
||||
mul_m4_v3(world_and_axes_transform_, r_coords);
|
||||
mul_v3_fl(r_coords, scaling_factor);
|
||||
mul_v3_fl(r_coords, global_scale);
|
||||
return r_coords;
|
||||
}
|
||||
|
||||
|
|
|
@ -161,7 +161,7 @@ class OBJMesh : NonCopyable {
|
|||
/**
|
||||
* Calculate coordinates of the vertex at the given index.
|
||||
*/
|
||||
float3 calc_vertex_coords(int vert_index, float scaling_factor) const;
|
||||
float3 calc_vertex_coords(int vert_index, float global_scale) const;
|
||||
/**
|
||||
* Calculate vertex indices of all vertices of the polygon at the given index.
|
||||
*/
|
||||
|
|
|
@ -55,14 +55,14 @@ int OBJCurve::total_spline_vertices(const int spline_index) const
|
|||
|
||||
float3 OBJCurve::vertex_coordinates(const int spline_index,
|
||||
const int vertex_index,
|
||||
const float scaling_factor) const
|
||||
const float global_scale) const
|
||||
{
|
||||
const Nurb *const nurb = static_cast<Nurb *>(BLI_findlink(&export_curve_->nurb, spline_index));
|
||||
float3 r_coord;
|
||||
const BPoint &bpoint = nurb->bp[vertex_index];
|
||||
copy_v3_v3(r_coord, bpoint.vec);
|
||||
mul_m4_v3(world_axes_transform_, r_coord);
|
||||
mul_v3_fl(r_coord, scaling_factor);
|
||||
mul_v3_fl(r_coord, global_scale);
|
||||
return r_coord;
|
||||
}
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ class OBJCurve : NonCopyable {
|
|||
/**
|
||||
* Get coordinates of the vertex at the given index on the given spline.
|
||||
*/
|
||||
float3 vertex_coordinates(int spline_index, int vertex_index, float scaling_factor) const;
|
||||
float3 vertex_coordinates(int spline_index, int vertex_index, float global_scale) const;
|
||||
/**
|
||||
* Get total control points of the NURBS spline at the given index. This is different than total
|
||||
* vertices of a spline.
|
||||
|
|
|
@ -103,6 +103,9 @@ void transform_object(Object *object, const OBJImportParams &import_params)
|
|||
IO_AXIS_Y, IO_AXIS_Z, import_params.forward_axis, import_params.up_axis, axes_transform);
|
||||
copy_m4_m3(obmat, axes_transform);
|
||||
|
||||
float scale_vec[3] = {
|
||||
import_params.global_scale, import_params.global_scale, import_params.global_scale};
|
||||
rescale_m4(obmat, scale_vec);
|
||||
BKE_object_apply_mat4(object, obmat, true, false);
|
||||
|
||||
if (import_params.clamp_size != 0.0f) {
|
||||
|
|
|
@ -306,7 +306,7 @@ TEST_F(obj_exporter_regression_test, all_tris)
|
|||
TEST_F(obj_exporter_regression_test, all_quads)
|
||||
{
|
||||
OBJExportParamsDefault _export;
|
||||
_export.params.scaling_factor = 2.0f;
|
||||
_export.params.global_scale = 2.0f;
|
||||
_export.params.export_materials = false;
|
||||
compare_obj_export_to_golden(
|
||||
"io_tests/blend_geometry/all_quads.blend", "io_tests/obj/all_quads.obj", "", _export.params);
|
||||
|
@ -429,7 +429,7 @@ TEST_F(obj_exporter_regression_test, cubes_positioned)
|
|||
{
|
||||
OBJExportParamsDefault _export;
|
||||
_export.params.export_materials = false;
|
||||
_export.params.scaling_factor = 2.0f;
|
||||
_export.params.global_scale = 2.0f;
|
||||
compare_obj_export_to_golden("io_tests/blend_geometry/cubes_positioned.blend",
|
||||
"io_tests/obj/cubes_positioned.obj",
|
||||
"",
|
||||
|
|
|
@ -19,7 +19,7 @@ struct OBJExportParamsDefault {
|
|||
|
||||
params.forward_axis = IO_AXIS_NEGATIVE_Z;
|
||||
params.up_axis = IO_AXIS_Y;
|
||||
params.scaling_factor = 1.f;
|
||||
params.global_scale = 1.f;
|
||||
|
||||
params.apply_modifiers = true;
|
||||
params.export_eval_mode = DAG_EVAL_VIEWPORT;
|
||||
|
|
|
@ -60,6 +60,7 @@ class obj_importer_test : public BlendfileLoadingBaseTest {
|
|||
}
|
||||
|
||||
OBJImportParams params;
|
||||
params.global_scale = 1.0f;
|
||||
params.clamp_size = 0;
|
||||
params.forward_axis = IO_AXIS_NEGATIVE_Z;
|
||||
params.up_axis = IO_AXIS_Y;
|
||||
|
|
Loading…
Reference in New Issue