[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [27153] trunk/blender: remove rna functions image.get_export_path() and image.get_abs_filename(), filename functions should not be spesific to images.

Campbell Barton ideasman42 at gmail.com
Fri Feb 26 12:50:59 CET 2010


Revision: 27153
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=27153
Author:   campbellbarton
Date:     2010-02-26 12:50:59 +0100 (Fri, 26 Feb 2010)

Log Message:
-----------
remove rna functions image.get_export_path() and image.get_abs_filename(), filename functions should not be spesific to images.
rename BKE_get_image_export_path() to BKE_rebase_path() and take a filename arg rather then an image.

obj export file copy was also not working because of a missing import.

Modified Paths:
--------------
    trunk/blender/release/scripts/io/export_fbx.py
    trunk/blender/release/scripts/io/export_obj.py
    trunk/blender/release/scripts/io/export_x3d.py
    trunk/blender/source/blender/blenkernel/BKE_image.h
    trunk/blender/source/blender/blenkernel/intern/image.c
    trunk/blender/source/blender/blenlib/BLI_path_util.h
    trunk/blender/source/blender/blenlib/intern/path_util.c
    trunk/blender/source/blender/collada/DocumentExporter.cpp
    trunk/blender/source/blender/makesrna/intern/rna_image_api.c

Modified: trunk/blender/release/scripts/io/export_fbx.py
===================================================================
--- trunk/blender/release/scripts/io/export_fbx.py	2010-02-26 10:01:49 UTC (rev 27152)
+++ trunk/blender/release/scripts/io/export_fbx.py	2010-02-26 11:50:59 UTC (rev 27153)
@@ -1293,16 +1293,18 @@
         file.write('\n\t}')
 
     def copy_image(image):
+        fn = bpy.utils.expandpath(image.filename)
+        fn_strip = os.path.basename(fn)
 
-        rel = image.get_export_path(basepath, True)
-        base = os.path.basename(rel)
-
         if EXP_IMAGE_COPY:
-            absp = image.get_export_path(basepath, False)
-            if not os.path.exists(absp):
-                shutil.copy(image.get_abs_filename(), absp)
+            rel = fn_strip
+            fn_abs_dest = os.path.join(basepath, fn_strip)
+            if not os.path.exists(fn_abs_dest):
+                shutil.copy(fn, fn_abs_dest)
+        else:
+            rel = os.path.relpath(fn, basepath)
 
-        return (rel, base)
+        return (rel, fn_strip)
 
     # tex is an Image (Arystan)
     def write_video(texname, tex):

Modified: trunk/blender/release/scripts/io/export_obj.py
===================================================================
--- trunk/blender/release/scripts/io/export_obj.py	2010-02-26 10:01:49 UTC (rev 27152)
+++ trunk/blender/release/scripts/io/export_obj.py	2010-02-26 11:50:59 UTC (rev 27153)
@@ -44,6 +44,7 @@
 # import math
 import os
 import time
+import shutil
 
 import bpy
 import Mathutils
@@ -76,12 +77,15 @@
     dest_dir = os.path.dirname(filename)
 
     def copy_image(image):
-        rel = image.get_export_path(dest_dir, True)
-
+        fn = bpy.utils.expandpath(image.filename)
+        fn_strip = os.path.basename(fn)
         if copy_images:
-            abspath = image.get_export_path(dest_dir, False)
-            if not os.path.exists(abs_path):
-                shutil.copy(image.get_abs_filename(), abs_path)
+            rel = fn_strip
+            fn_abs_dest = os.path.join(dest_dir, fn_strip)
+            if not os.path.exists(fn_abs_dest):
+                shutil.copy(fn, fn_abs_dest)
+        else:
+            rel = fn
 
         return rel
 

Modified: trunk/blender/release/scripts/io/export_x3d.py
===================================================================
--- trunk/blender/release/scripts/io/export_x3d.py	2010-02-26 10:01:49 UTC (rev 27152)
+++ trunk/blender/release/scripts/io/export_x3d.py	2010-02-26 11:50:59 UTC (rev 27153)
@@ -794,7 +794,7 @@
             pic = tex.image
 
             # using .expandpath just in case, os.path may not expect //
-            basename = os.path.basename(pic.get_abs_filename())
+            basename = os.path.basename(bpy.utils.expandpath(pic.filename))
 
             pic = alltextures[i].image
             # pic = alltextures[i].getImage()

Modified: trunk/blender/source/blender/blenkernel/BKE_image.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_image.h	2010-02-26 10:01:49 UTC (rev 27152)
+++ trunk/blender/source/blender/blenkernel/BKE_image.h	2010-02-26 11:50:59 UTC (rev 27153)
@@ -130,9 +130,6 @@
 /* called on frame change or before render */
 void BKE_image_user_calc_frame(struct ImageUser *iuser, int cfra, int fieldnr);
 
-/* produce image export path */
-int BKE_get_image_export_path(struct Image *im, const char *dest_dir, char *abs, int abs_size, char *rel, int rel_size);
-
 /* fix things in ImageUser when new image gets assigned */
 void BKE_image_user_new_image(struct Image *ima, struct ImageUser *iuser);
 

Modified: trunk/blender/source/blender/blenkernel/intern/image.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/image.c	2010-02-26 10:01:49 UTC (rev 27152)
+++ trunk/blender/source/blender/blenkernel/intern/image.c	2010-02-26 11:50:59 UTC (rev 27153)
@@ -2260,104 +2260,3 @@
 		if(iuser->ok==0) iuser->ok= 1;
 	}
 }
-
-/*
-  Produce image export path.
-
-  Fails returning 0 if image filename is empty or if destination path
-  matches image path (i.e. both are the same file).
-
-  Trailing slash in dest_dir is optional.
-
-  Logic:
-
-  - if an image is "below" current .blend file directory, rebuild the
-    same dir structure in dest_dir
-
-  For example //textures/foo/bar.png becomes
-  [dest_dir]/textures/foo/bar.png.
-
-  - if an image is not "below" current .blend file directory,
-  disregard it's path and copy it in the same directory where 3D file
-  goes.
-
-  For example //../foo/bar.png becomes [dest_dir]/bar.png.
-
-  This logic will help ensure that all image paths are relative and
-  that a user gets his images in one place. It'll also provide
-  consistent behaviour across exporters.
- */
-int BKE_get_image_export_path(struct Image *im, const char *dest_dir, char *abs, int abs_size, char *rel, int rel_size)
-{
-	char path[FILE_MAX];
-	char dir[FILE_MAX];
-	char base[FILE_MAX];
-	char blend_dir[FILE_MAX];	/* directory, where current .blend file resides */
-	char dest_path[FILE_MAX];
-	char rel_dir[FILE_MAX];
-	int len;
-
-	if (abs)
-		abs[0]= 0;
-
-	if (rel)
-		rel[0]= 0;
-
-	BLI_split_dirfile_basic(G.sce, blend_dir, NULL);
-
-	if (!strlen(im->name)) {
-		if (G.f & G_DEBUG) printf("Invalid image type.\n");
-		return 0;
-	}
-
-	BLI_strncpy(path, im->name, sizeof(path));
-
-	/* expand "//" in filename and get absolute path */
-	BLI_convertstringcode(path, G.sce);
-
-	/* get the directory part */
-	BLI_split_dirfile_basic(path, dir, base);
-
-	len= strlen(blend_dir);
-
-	rel_dir[0] = 0;
-
-	/* if image is "below" current .blend file directory */
-	if (!strncmp(path, blend_dir, len)) {
-
-		/* if image is _in_ current .blend file directory */
-		if (!strcmp(dir, blend_dir)) {
-			BLI_join_dirfile(dest_path, dest_dir, base);
-		}
-		/* "below" */
-		else {
-			/* rel = image_path_dir - blend_dir */
-			BLI_strncpy(rel_dir, dir + len, sizeof(rel_dir));
-
-			BLI_join_dirfile(dest_path, dest_dir, rel_dir);
-			BLI_join_dirfile(dest_path, dest_path, base);
-		}
-			
-	}
-	/* image is out of current directory */
-	else {
-		BLI_join_dirfile(dest_path, dest_dir, base);
-	}
-
-	if (abs)
-		BLI_strncpy(abs, dest_path, abs_size);
-
-	if (rel) {
-		strncat(rel, rel_dir, rel_size);
-		strncat(rel, base, rel_size);
-	}
-
-	/* return 2 if src=dest */
-	if (!strcmp(path, dest_path)) {
-		if (G.f & G_DEBUG) printf("%s and %s are the same file\n", path, dest_path);
-		return 2;
-	}
-
-	return 1;
-}
-

Modified: trunk/blender/source/blender/blenlib/BLI_path_util.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_path_util.h	2010-02-26 10:01:49 UTC (rev 27152)
+++ trunk/blender/source/blender/blenlib/BLI_path_util.h	2010-02-26 11:50:59 UTC (rev 27153)
@@ -59,6 +59,7 @@
 void BLI_split_dirfile(char *string, char *dir, char *file);
 void BLI_split_dirfile_basic(const char *string, char *dir, char *file);
 void BLI_join_dirfile(char *string, const char *dir, const char *file);
+int BKE_rebase_path(char *abs, int abs_size, char *rel, int rel_size, const char *base_dir, const char *src_dir, const char *dest_dir);
 void BLI_getlastdir(const char* dir, char *last, int maxlen);
 int BLI_testextensie(const char *str, const char *ext);
 void BLI_uniquename(struct ListBase *list, void *vlink, const char defname[], char delim, short name_offs, short len);

Modified: trunk/blender/source/blender/blenlib/intern/path_util.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/path_util.c	2010-02-26 10:01:49 UTC (rev 27152)
+++ trunk/blender/source/blender/blenlib/intern/path_util.c	2010-02-26 11:50:59 UTC (rev 27153)
@@ -1320,6 +1320,106 @@
 	}
 }
 
+
+/*
+  Produce image export path.
+
+  Fails returning 0 if image filename is empty or if destination path
+  matches image path (i.e. both are the same file).
+
+  Trailing slash in dest_dir is optional.
+
+  Logic:
+
+  - if an image is "below" current .blend file directory, rebuild the
+    same dir structure in dest_dir
+
+  For example //textures/foo/bar.png becomes
+  [dest_dir]/textures/foo/bar.png.
+
+  - if an image is not "below" current .blend file directory,
+  disregard it's path and copy it in the same directory where 3D file
+  goes.
+
+  For example //../foo/bar.png becomes [dest_dir]/bar.png.
+
+  This logic will help ensure that all image paths are relative and
+  that a user gets his images in one place. It'll also provide
+  consistent behaviour across exporters.
+ */
+int BKE_rebase_path(char *abs, int abs_size, char *rel, int rel_size, const char *base_dir, const char *src_dir, const char *dest_dir)
+{
+	char path[FILE_MAX];
+	char dir[FILE_MAX];
+	char base[FILE_MAX];
+	char blend_dir[FILE_MAX];	/* directory, where current .blend file resides */
+	char dest_path[FILE_MAX];
+	char rel_dir[FILE_MAX];
+	int len;
+
+	if (abs)
+		abs[0]= 0;
+
+	if (rel)
+		rel[0]= 0;
+
+	BLI_split_dirfile_basic(base_dir, blend_dir, NULL);
+
+	if (src_dir[0]=='\0')
+		return 0;
+
+	BLI_strncpy(path, src_dir, sizeof(path));
+
+	/* expand "//" in filename and get absolute path */
+	BLI_convertstringcode(path, base_dir);
+
+	/* get the directory part */
+	BLI_split_dirfile_basic(path, dir, base);
+
+	len= strlen(blend_dir);
+
+	rel_dir[0] = 0;
+
+	/* if image is "below" current .blend file directory */
+	if (!strncmp(path, blend_dir, len)) {
+
+		/* if image is _in_ current .blend file directory */
+		if (!strcmp(dir, blend_dir)) {
+			BLI_join_dirfile(dest_path, dest_dir, base);
+		}
+		/* "below" */
+		else {
+			/* rel = image_path_dir - blend_dir */
+			BLI_strncpy(rel_dir, dir + len, sizeof(rel_dir));
+
+			BLI_join_dirfile(dest_path, dest_dir, rel_dir);
+			BLI_join_dirfile(dest_path, dest_path, base);
+		}
+
+	}
+	/* image is out of current directory */
+	else {
+		BLI_join_dirfile(dest_path, dest_dir, base);
+	}
+
+	if (abs)
+		BLI_strncpy(abs, dest_path, abs_size);
+
+	if (rel) {
+		strncat(rel, rel_dir, rel_size);
+		strncat(rel, base, rel_size);
+	}
+
+	/* return 2 if src=dest */
+	if (!strcmp(path, dest_path)) {
+		// if (G.f & G_DEBUG) printf("%s and %s are the same file\n", path, dest_path);
+		return 2;
+	}
+
+	return 1;
+}
+
+
 static int add_win32_extension(char *name)
 {
 	int retval = 0;

Modified: trunk/blender/source/blender/collada/DocumentExporter.cpp
===================================================================

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list