[Bf-blender-cvs] [10da0539771] soc-2019-fast-io: [Fast import/export] Added unit scaling

Hugo Sales noreply at git.blender.org
Mon Jun 24 12:03:10 CEST 2019


Commit: 10da0539771b73b76af410d82be4435d4c23b0ca
Author: Hugo Sales
Date:   Mon Jun 24 11:03:06 2019 +0100
Branches: soc-2019-fast-io
https://developer.blender.org/rB10da0539771b73b76af410d82be4435d4c23b0ca

[Fast import/export] Added unit scaling

===================================================================

M	source/blender/editors/io/intern/common.cpp
M	source/blender/editors/io/intern/obj.cpp

===================================================================

diff --git a/source/blender/editors/io/intern/common.cpp b/source/blender/editors/io/intern/common.cpp
index d6c6ba59a85..ee6f59cd5c4 100644
--- a/source/blender/editors/io/intern/common.cpp
+++ b/source/blender/editors/io/intern/common.cpp
@@ -124,6 +124,39 @@ void change_orientation(float (&mat)[4][4], int forward, int up)
   change_single_axis_orientation(mat, AXIS_Z, up);
 }
 
+float get_unit_scale(const Scene *const scene)
+{
+  // From collada_internal.cpp
+  PointerRNA scene_ptr, unit_settings;
+  PropertyRNA *system_ptr, *scale_ptr;
+  RNA_id_pointer_create(&scene.id, &scene_ptr);
+
+  unit_settings = RNA_pointer_get(&scene_ptr, "unit_settings");
+  system_ptr = RNA_struct_find_property(&unit_settings, "system");
+  scale_ptr = RNA_struct_find_property(&unit_settings, "scale_length");
+
+  int type = RNA_property_enum_get(&unit_settings, system_ptr);
+  float scale;
+
+  switch (type) {
+    case USER_UNIT_NONE:
+      scale = 1.0;  // map 1 Blender unit to 1 Meter
+      break;
+    case USER_UNIT_METRIC:
+      scale = RNA_property_float_get(&unit_settings, scale_ptr);
+      break;
+    case USER_UNIT_IMPERIAL:
+      scale = RNA_property_float_get(&unit_settings, scale_ptr);
+      // it looks like the conversion to Imperial is done implicitly.
+      // So nothing to do here.
+      break;
+    default:
+      BLI_assert("New unit system added but not handled");
+  }
+
+  return scale;
+}
+
 bool get_final_mesh(const ExportSettings *const settings,
                     const Scene *const escene,
                     const Object *ob,
@@ -137,7 +170,7 @@ bool get_final_mesh(const ExportSettings *const settings,
       md.mode |= eModifierMode_DisableTemporary;
 
   float scale_mat[4][4];
-  scale_m4_fl(scale_mat, settings->global_scale);
+  scale_m4_fl(scale_mat, settings->global_scale * get_unit_scale(scene));
 
   change_orientation(scale_mat, settings->axis_forward, settings->axis_up);
 
diff --git a/source/blender/editors/io/intern/obj.cpp b/source/blender/editors/io/intern/obj.cpp
index 61a19528a2e..598d8eba8c4 100644
--- a/source/blender/editors/io/intern/obj.cpp
+++ b/source/blender/editors/io/intern/obj.cpp
@@ -56,30 +56,30 @@ extern "C" {
 
 /*
   TODO someone: () not done, -- done, # maybe add, ? unsure
-  presets
-  axis remap -- doesn't work. Does it need to update, somehow?
-    DEG_id_tag_update(&mesh->id, 0); obedit->id.recalc & ID_RECALC_ALL
   --selection only
   --animation
   --apply modifiers
   --render modifiers -- mesh_create_derived_{view,render}, deg_get_mode
   --edges
-  smooth groups
-  bitflag smooth groups?
   --normals
   --uvs
   --materials
-  material groups
-  path mode -- needed?
-  --triangulate
-  nurbs
-  polygroups?
+  -- path mode
+  -- triangulate
+  -- nurbs
   --obj objects
   --obj groups
-  -?vertex order
   --scale
-  # units?
-  # removing duplicates with a threshold and as an option
+  --units
+  --removing duplicates with a threshold and as an option
+  presets
+  axis remap -- doesn't work. Does it need to update, somehow?
+    DEG_id_tag_update(&mesh->id, 0); obedit->id.recalc & ID_RECALC_ALL
+  smooth groups
+  bitflag smooth groups?
+  material groups
+  polygroups?
+  -?vertex order
  */
 
 namespace {



More information about the Bf-blender-cvs mailing list