[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [58726] trunk/blender/source/blender/ collada: Collada: Import now always rotates input to match blender' s Z_UP axis

Gaia Clary gaia.clary at machinimatrix.org
Mon Jul 29 23:51:54 CEST 2013


Revision: 58726
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=58726
Author:   gaiaclary
Date:     2013-07-29 21:51:53 +0000 (Mon, 29 Jul 2013)
Log Message:
-----------
Collada: Import now always rotates input to match blender's Z_UP axis

Modified Paths:
--------------
    trunk/blender/source/blender/collada/DocumentImporter.cpp
    trunk/blender/source/blender/collada/collada_utils.cpp
    trunk/blender/source/blender/collada/collada_utils.h

Modified: trunk/blender/source/blender/collada/DocumentImporter.cpp
===================================================================
--- trunk/blender/source/blender/collada/DocumentImporter.cpp	2013-07-29 21:22:59 UTC (rev 58725)
+++ trunk/blender/source/blender/collada/DocumentImporter.cpp	2013-07-29 21:51:53 UTC (rev 58726)
@@ -185,6 +185,7 @@
 	Main *bmain = CTX_data_main(mContext);
 	// TODO: create a new scene except the selected <visual_scene> - use current blender scene for it
 	Scene *sce = CTX_data_scene(mContext);
+	unit_converter.calculate_scale(*sce);
 
 	/** TODO Break up and put into 2-pass parsing of DAE */
 	std::vector<const COLLADAFW::VisualScene *>::iterator it;
@@ -224,10 +225,8 @@
 			std::vector<Object *> *objects_done;
 			objects_done = write_node(roots[i], NULL, sce, NULL, false);
 			
-			if (!this->import_settings->import_units) {
-				// Match incoming scene with current unit settings
-				bc_match_scale(objects_done, *sce, unit_converter);
-			}
+			// Match incoming scene with current unit settings
+			bc_match_scale(objects_done, unit_converter, !this->import_settings->import_units);
 		}
 
 		// update scene

Modified: trunk/blender/source/blender/collada/collada_utils.cpp
===================================================================
--- trunk/blender/source/blender/collada/collada_utils.cpp	2013-07-29 21:22:59 UTC (rev 58725)
+++ trunk/blender/source/blender/collada/collada_utils.cpp	2013-07-29 21:51:53 UTC (rev 58726)
@@ -324,65 +324,30 @@
  * Calculate a rescale factor such that the imported scene's scale
  * is preserved. I.e. 1 meter in the import will also be
  * 1 meter in the current scene.
- * XXX : I am not sure if it is correct to map 1 Blender Unit
- * to 1 Meter for unit type NONE. But it looks reasonable to me.
  */
-void bc_match_scale(std::vector<Object *> *objects_done, 
-                    Scene &sce,
-                    UnitConverter &bc_unit)
-{
-	Object *ob = NULL;
 
-	PointerRNA scene_ptr, unit_settings;
-	PropertyRNA *system_ptr, *scale_ptr;
-	RNA_id_pointer_create(&sce.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 bl_scale;
-	
-	switch (type) {
-		case USER_UNIT_NONE:
-			bl_scale = 1.0; // map 1 Blender unit to 1 Meter
-			break;
-
-		case USER_UNIT_METRIC:
-			bl_scale = RNA_property_float_get(&unit_settings, scale_ptr);
-			break;
-
-		default :
-			bl_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;
+void bc_match_scale(Object *ob, UnitConverter &bc_unit, bool scale_to_scene)
+{
+	if (scale_to_scene) {
+		mul_m4_m4m4(ob->obmat, bc_unit.get_scale(), ob->obmat);
 	}
-	
-	float scale_conv = bc_unit.getLinearMeter() / bl_scale;
+	mul_m4_m4m4(ob->obmat, bc_unit.get_rotation(), ob->obmat);
+	BKE_object_apply_mat4(ob, ob->obmat, 0, 0);
+}
 
-	float rescale[3];
-	rescale[0] = rescale[1] = rescale[2] = scale_conv;
-
-	float size_mat4[4][4];
-
-	float axis_mat4[4][4];
-	unit_m4(axis_mat4);
-
-	size_to_mat4(size_mat4, rescale);
-
+void bc_match_scale(std::vector<Object *> *objects_done, 
+	                UnitConverter &bc_unit,
+	                bool scale_to_scene)
+{
 	for (std::vector<Object *>::iterator it = objects_done->begin();
 			it != objects_done->end();
 			++it) 
 	{
-		ob = *it;
-		mul_m4_m4m4(ob->obmat, size_mat4, ob->obmat);
-		mul_m4_m4m4(ob->obmat, bc_unit.get_rotation(), ob->obmat);
-		BKE_object_apply_mat4(ob, ob->obmat, 0, 0);
+		Object *ob = *it;
+		if (ob -> parent == NULL) {
+			bc_match_scale(*it, bc_unit, scale_to_scene);
+		}
 	}
-
 }
 
 void bc_triangulate_mesh(Mesh *me)

Modified: trunk/blender/source/blender/collada/collada_utils.h
===================================================================
--- trunk/blender/source/blender/collada/collada_utils.h	2013-07-29 21:22:59 UTC (rev 58725)
+++ trunk/blender/source/blender/collada/collada_utils.h	2013-07-29 21:51:53 UTC (rev 58726)
@@ -83,7 +83,8 @@
 
 extern std::string bc_replace_string(std::string data, const std::string& pattern, const std::string& replacement); 
 extern std::string bc_url_encode(std::string data); 
-extern void bc_match_scale(std::vector<Object *> *objects_done, Scene &sce, UnitConverter &unit_converter);
+extern void bc_match_scale(Object *ob, UnitConverter &bc_unit, bool scale_to_scene);
+extern void bc_match_scale(std::vector<Object *> *objects_done, UnitConverter &unit_converter, bool scale_to_scene);
 
 extern void bc_triangulate_mesh(Mesh *me);
 




More information about the Bf-blender-cvs mailing list