[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [54532] trunk/blender/source/blender/ collada/DocumentImporter.cpp: Collada: Fixed import of textures with path settings relative to main import file

Gaia Clary gaia.clary at machinimatrix.org
Wed Feb 13 17:00:46 CET 2013


Revision: 54532
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=54532
Author:   gaiaclary
Date:     2013-02-13 16:00:46 +0000 (Wed, 13 Feb 2013)
Log Message:
-----------
Collada: Fixed import of textures with path settings relative to main import file

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

Modified: trunk/blender/source/blender/collada/DocumentImporter.cpp
===================================================================
--- trunk/blender/source/blender/collada/DocumentImporter.cpp	2013-02-13 15:21:55 UTC (rev 54531)
+++ trunk/blender/source/blender/collada/DocumentImporter.cpp	2013-02-13 16:00:46 UTC (rev 54532)
@@ -54,6 +54,7 @@
 #include "BLI_math.h"
 #include "BLI_string.h"
 #include "BLI_utildefines.h"
+#include "BLI_fileops.h"
 
 #include "BKE_camera.h"
 #include "BKE_main.h"
@@ -1000,17 +1001,29 @@
 	if (mImportStage != General)
 		return true;
 		
-	// XXX maybe it is necessary to check if the path is absolute or relative
-	const std::string& filepath = image->getImageURI().toNativePath();
-	const char *filename = (const char *)filepath.c_str();
+	const std::string& imagepath = image->getImageURI().toNativePath();
+
 	char dir[FILE_MAX];
-	char full_path[FILE_MAX];
-	
-	BLI_split_dir_part(filename, dir, sizeof(dir));
-	BLI_join_dirfile(full_path, sizeof(full_path), dir, filepath.c_str());
-	Image *ima = BKE_image_load_exists(full_path);
+	char absolute_path[FILE_MAX];
+	const char *workpath;
+
+	BLI_split_dir_part(this->import_settings->filepath, dir, sizeof(dir));
+	BLI_join_dirfile(absolute_path, sizeof(absolute_path), dir, imagepath.c_str());
+	if (BLI_exists(absolute_path)) {
+		workpath = absolute_path;
+	} 
+	else {
+		// Maybe imagepath was already absolute ?
+		if (!BLI_exists(imagepath.c_str())) {
+			fprintf(stderr, "Image not found: %s.\n", imagepath.c_str() );
+			return true;
+		}
+		workpath = imagepath.c_str();
+	}
+
+	Image *ima = BKE_image_load_exists(workpath);
 	if (!ima) {
-		fprintf(stderr, "Cannot create image.\n");
+		fprintf(stderr, "Cannot create image: %s\n", workpath);
 		return true;
 	}
 	this->uid_image_map[image->getUniqueId()] = ima;




More information about the Bf-blender-cvs mailing list