- modified BKE_get_image_export_path so that it writes relative path if src file...
authorArystanbek Dyussenov <arystan.d@gmail.com>
Wed, 5 Aug 2009 07:59:49 +0000 (07:59 +0000)
committerArystanbek Dyussenov <arystan.d@gmail.com>
Wed, 5 Aug 2009 07:59:49 +0000 (07:59 +0000)
- modified unit tests for ^ firstly
- incorporated Image.get_export_path into FBX exporter script

release/io/export_fbx.py
source/blender/blenkernel/intern/image.c
source/blender/makesrna/intern/rna_image_api.c
source/creator/tests/alltest.c

index a81dea4d909fcc54a8565fb8db24818f08870861..c50b60fd97e421a2415ec137b6b8db1ffd45c9c1 100644 (file)
@@ -39,6 +39,7 @@ http://wiki.blender.org/index.php/Scripts/Manual/Export/autodesk_fbx
 import os
 import time
 import math # math.pi
+import shutil # for file copying
 
 # try:
 #      import time
@@ -1324,8 +1325,6 @@ def write(filename, batch_objects = None, \
 
        # tex is an Image (Arystan)
        def write_video(texname, tex):
-               if not EXP_IMAGE_COPY: return
-
                # Same as texture really!
                file.write('\n\tVideo: "Video::%s", "Clip" {' % texname)
                
@@ -1337,9 +1336,15 @@ def write(filename, batch_objects = None, \
                        Property: "Width", "int", "",0
                        Property: "Height", "int", "",0''')
                if tex:
-                       abspath = tex.export(basepath)
-                       fname_rel = os.path.relpath(abspath, basepath)
-                       fname_strip = os.path.basename(abspath)
+                       src = bpy.sys.expandpath(tex.filename)
+                       fname_rel = tex.get_export_path(basepath, True)
+                       fname_abs = tex.get_export_path(basepath, False)
+                       fname_strip = os.path.basename(fname_rel)
+
+                       if EXP_IMAGE_COPY:
+                               if !os.path.exists(fname_abs):
+                                       shutil.copy(src, fname_abs)
+
 #                      fname, fname_strip, fname_rel = derived_paths(tex.filename, basepath, EXP_IMAGE_COPY)
                else:
                        fname = fname_strip = fname_rel = ''
@@ -1404,11 +1409,14 @@ def write(filename, batch_objects = None, \
                file.write('\n\t\tMedia: "Video::%s"' % texname)
                
                if tex:
-                       fname_rel = tex.get_export_path(relpath, True)
+                       src = bpy.sys.expandpath(tex.filename)
+                       fname_rel = tex.get_export_path(basepath, True)
+                       fname_abs = tex.get_export_path(basepath, False)
                        fname_strip = os.path.basename(fname_rel)
 
                        if EXP_IMAGE_COPY:
-                               
+                               if !os.path.exists(fname_abs):
+                                       shutil.copy(src, fname_abs)
 
 #                      fname, fname_strip, fname_rel = derived_paths(tex.filename, basepath, EXP_IMAGE_COPY)
                else:
index b66213ffbc2f474e444da4d81e76bf5edfcef031..4a355640d8b88a999c460a064819fc79b4debd87 100644 (file)
@@ -2206,12 +2206,6 @@ int BKE_get_image_export_path(struct Image *im, const char *dest_dir, char *abs,
                BLI_join_dirfile(dest_path, dest_dir, base);
        }
 
-       /* only return 1 if paths differ */
-       if (!strcmp(path, dest_path)) {
-               if (G.f & G_DEBUG) printf("%s and %s are the same file\n", path, dest_path);
-               return 0;
-       }
-
        if (abs)
                BLI_strncpy(abs, dest_path, abs_size);
 
@@ -2220,5 +2214,11 @@ int BKE_get_image_export_path(struct Image *im, const char *dest_dir, char *abs,
                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;
 }
index 20770ef29571495ae05cde7985797a84dbdd518c..af059b435b3c0dcd6df48647fc30431a8fc65e0d 100644 (file)
 #include "BKE_utildefines.h"
 #include "BKE_image.h"
 
+/*
+  User should check if returned path exists before copying a file there.
+
+  TODO: it would be better to return a (abs, rel) tuple.
+*/
 static char *rna_Image_get_export_path(Image *image, char *dest_dir, int rel)
 {
        int length = FILE_MAX;
index 99e0d2f5b2687e01cab91306bd829bb2e86cc9c3..89a58a08dfda0d0e6e6eebe38fe4435a5fb46971 100644 (file)
@@ -60,19 +60,19 @@ START_TEST(test_copy_images)
                {"//image.png", {{"/home/user/image.png", "image.png", 1},
                                                 {"/home/user/image.png", "image.png", 1},
                                                 {"/home/user/export/image.png", "image.png", 1},
-                                                {"", "", 0},}},
+                                                {"/home/user/foo/image.png", "image.png", 2},}},
 
                /* relative, 1 level deep */
                {"//bar/image.png", {{"/home/user/bar/image.png", "bar/image.png", 1},
                                                         {"/home/user/bar/image.png", "bar/image.png", 1},
                                                         {"/home/user/export/bar/image.png", "bar/image.png", 1},
-                                                        {"", "", 0},}},
+                                                        {"/home/user/foo/bar/image.png", "bar/image.png", 2},}},
 
                /* relative, 2 level deep */
                {"//bar/foo/image.png", {{"/home/user/bar/foo/image.png", "bar/foo/image.png", 1},
                                                                 {"/home/user/bar/foo/image.png", "bar/foo/image.png", 1},
                                                                 {"/home/user/export/bar/foo/image.png", "bar/foo/image.png", 1},
-                                                                {"", "", 0},}},
+                                                                {"/home/user/foo/bar/foo/image.png", "bar/foo/image.png", 2},}},
 
                /* absolute, not under .blend dir */
                {"/home/user/bar/image.png", {{"/home/user/image.png", "image.png", 1},
@@ -84,19 +84,19 @@ START_TEST(test_copy_images)
                {"/home/user/foo/image.png", {{"/home/user/image.png", "image.png", 1},
                                                                          {"/home/user/image.png", "image.png", 1},
                                                                          {"/home/user/export/image.png", "image.png", 1},
-                                                                         {"", "", 0},}},
+                                                                         {"/home/user/foo/image.png", "image.png", 2},}},
 
                /* absolute, under .blend dir, 1 level deep */
                {"/home/user/foo/bar/image.png", {{"/home/user/bar/image.png", "bar/image.png", 1},
                                                                                  {"/home/user/bar/image.png", "bar/image.png", 1},
                                                                                  {"/home/user/export/bar/image.png", "bar/image.png", 1},
-                                                                                 {"", "", 0},}},
+                                                                                 {"/home/user/foo/bar/image.png", "bar/image.png", 2},}},
 
                /* absolute, under .blend dir, 2 level deep */
                {"/home/user/foo/bar/foo/image.png", {{"/home/user/bar/foo/image.png", "bar/foo/image.png", 1},
                                                                                          {"/home/user/bar/foo/image.png", "bar/foo/image.png", 1},
                                                                                          {"/home/user/export/bar/foo/image.png", "bar/foo/image.png", 1},
-                                                                                         {"", "", 0},}},
+                                                                                         {"/home/user/foo/bar/foo/image.png", "bar/foo/image.png", 2},}},
 
                /* empty image path, don't let these pass! */
                {"", {{"", 0},