Revision: 21813
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21813
Author:   kazanbas
Date:     2009-07-23 14:55:26 +0200 (Thu, 23 Jul 2009)

Log Message:
-----------
API:
- replaced BKE_copy_images with BKE_export_image, now it handles only one image 
at a time, this is better since for exporters it is 
easier to export one image at a time writing new image path to a file
- exposing BKE_export_image in RNA as Image.export, interestingly, RNA allowed 
me to define a function with PROP_STRING return type 
although it doesn't free memory, will fix that in the next commit
- removed bpy.util.copy_images

Unit tests:
- re-wrote a test for BKE_export_image, it's more compact now
- moved unit tests to the creator module to avoid another executable, now 
running tests with `blender --test`
- as before, unit tests are built only if WITH_BF_UNIT_TEST is non 0

Modified Paths:
--------------
    branches/soc-2009-kazanbas/SConstruct
    branches/soc-2009-kazanbas/release/io/export_fbx.py
    branches/soc-2009-kazanbas/source/blender/blenkernel/BKE_image.h
    branches/soc-2009-kazanbas/source/blender/blenkernel/intern/image.c
    branches/soc-2009-kazanbas/source/blender/makesrna/intern/makesrna.c
    branches/soc-2009-kazanbas/source/blender/makesrna/intern/rna_image.c
    branches/soc-2009-kazanbas/source/blender/python/intern/bpy_interface.c
    branches/soc-2009-kazanbas/source/blender/python/intern/bpy_util.c
    branches/soc-2009-kazanbas/source/creator/SConscript
    branches/soc-2009-kazanbas/source/creator/creator.c
    branches/soc-2009-kazanbas/tools/Blender.py
    branches/soc-2009-kazanbas/tools/btools.py

Added Paths:
-----------
    branches/soc-2009-kazanbas/source/creator/tests/
    branches/soc-2009-kazanbas/source/creator/tests/alltest.c

Removed Paths:
-------------
    branches/soc-2009-kazanbas/tests/

Modified: branches/soc-2009-kazanbas/SConstruct
===================================================================
--- branches/soc-2009-kazanbas/SConstruct       2009-07-23 12:31:45 UTC (rev 
21812)
+++ branches/soc-2009-kazanbas/SConstruct       2009-07-23 12:55:26 UTC (rev 
21813)
@@ -409,14 +409,6 @@
        #env.BlenderProg(B.root_build_dir, "blender", dobj , [], mainlist + 
thestatlibs + thesyslibs, [B.root_build_dir+'/lib'] + thelibincs, 'blender')
        blen = env.BlenderProg(B.root_build_dir, "blender", dobj + mainlist, 
[], thestatlibs + thesyslibs, [B.root_build_dir+'/lib'] + thelibincs, 'blender')
 
-       build_data = {"lib": thestatlibs + thesyslibs, "libpath": thelibincs, 
"blen": blen}
-
-       Export('env')
-       Export('build_data')
-
-       BuildDir(B.root_build_dir+'/tests', 'tests', duplicate=0)
-       SConscript(B.root_build_dir+'/tests/SConscript')
-
 if env['WITH_BF_PLAYER']:
        playerlist = B.create_blender_liblist(env, 'player')
        env.BlenderProg(B.root_build_dir, "blenderplayer", dobj + playerlist, 
[], thestatlibs + thesyslibs, [B.root_build_dir+'/lib'] + thelibincs, 
'blenderplayer')

Modified: branches/soc-2009-kazanbas/release/io/export_fbx.py
===================================================================
--- branches/soc-2009-kazanbas/release/io/export_fbx.py 2009-07-23 12:31:45 UTC 
(rev 21812)
+++ branches/soc-2009-kazanbas/release/io/export_fbx.py 2009-07-23 12:55:26 UTC 
(rev 21813)
@@ -356,7 +356,7 @@
                EXP_OBS_SELECTED =                      True,
                EXP_MESH =                                      True,
                EXP_MESH_APPLY_MOD =            True,
-               EXP_MESH_HQ_NORMALS =           False,
+#              EXP_MESH_HQ_NORMALS =           False,
                EXP_ARMATURE =                          True,
                EXP_LAMP =                                      True,
                EXP_CAMERA =                            True,
@@ -464,7 +464,7 @@
                                False,
                                EXP_MESH,
                                EXP_MESH_APPLY_MOD,
-                               EXP_MESH_HQ_NORMALS,
+#                              EXP_MESH_HQ_NORMALS,
                                EXP_ARMATURE,
                                EXP_LAMP,
                                EXP_CAMERA,
@@ -2306,19 +2306,25 @@
        
        # Build blenObject -> fbxObject mapping
        # this is needed for groups as well as fbxParenting
-       for ob in bpy.data.objects:     ob.tag = False
+#      for ob in bpy.data.objects:     ob.tag = False
 #      bpy.data.objects.tag = False
+
+       # using a list of object names for tagging (Arystan)
+       tagged_objects = []
+
        tmp_obmapping = {}
        for ob_generic in ob_all_typegroups:
                for ob_base in ob_generic:
-                       ob_base.blenObject.tag = True
+                       tagged_objects.append(ob_base.blenObject.name)
+#                      ob_base.blenObject.tag = True
                        tmp_obmapping[ob_base.blenObject] = ob_base
        
        # Build Groups from objects we export
        for blenGroup in bpy.data.groups:
                fbxGroupName = None
                for ob in blenGroup.objects:
-                       if ob.tag:
+                       if ob.name in tagged_objects:
+#                      if ob.tag:
                                if fbxGroupName == None:
                                        fbxGroupName = sane_groupname(blenGroup)
                                        groups.append((fbxGroupName, blenGroup))
@@ -2331,7 +2337,8 @@
        for ob_generic in ob_all_typegroups:
                for my_ob in ob_generic:
                        parent = my_ob.blenObject.parent
-                       if parent and parent.tag: # does it exist and is it in 
the mapping
+                       if parent and parent.name in tagged_objects: # does it 
exist and is it in the mapping
+#                      if parent and parent.tag: # does it exist and is it in 
the mapping
                                my_ob.fbxParent = tmp_obmapping[parent]
        
        
@@ -2734,9 +2741,11 @@
                tmp_actions = [None] # None is the default action
                blenActionDefault = None
                action_lastcompat = None
+
+               # instead of tagging
+               tagged_actions = []
                
                if ANIM_ACTION_ALL:
-                       for a in bpy.data.actions: a.tag = False
 #                      bpy.data.actions.tag = False
                        tmp_actions = list(bpy.data.actions)
                        
@@ -2759,7 +2768,8 @@
                                        
                                        if action_chan_names: # at least one 
channel matches.
                                                
my_arm.blenActionList.append(action)
-                                               action.tag = True
+                                               
tagged_actions.append(action.name)
+#                                              action.tag = True
                                                tmp_act_count += 1
                                                
                                                # incase there is no actions 
applied to armatures
@@ -2786,7 +2796,8 @@
                for blenAction in tmp_actions:
                        # we have tagged all actious that are used be selected 
armatures
                        if blenAction:
-                               if blenAction.tag:
+                               if blenAction.name in tagged_actions:
+#                              if blenAction.tag:
                                        print('\taction: "%s" exporting...' % 
blenAction.name)
                                else:
                                        print('\taction: "%s" has no armature 
using it, skipping' % blenAction.name)
@@ -3065,7 +3076,7 @@
        # copy images if enabled
        if EXP_IMAGE_COPY:
 #              copy_images( basepath,  [ tex[1] for tex in textures if tex[1] 
!= None ])
-               bpy.util.copy_images( basepath,  [ tex[1] for tex in textures 
if tex[1] != None ])      
+               bpy.util.copy_images( [ tex[1] for tex in textures if tex[1] != 
None ], basepath)       
        
        print('export finished in %.4f sec.' % (bpy.sys.time() - start_time))
 #      print 'export finished in %.4f sec.' % (Blender.sys.time() - start_time)
@@ -3393,7 +3404,7 @@
                bpy.props.BoolProperty(attr="ANIM_OPTIMIZE", name="Optimize 
Keyframes", description="Remove double keyframes", default=True),
                bpy.props.FloatProperty(attr="ANIM_OPTIMIZE_PRECISSION", 
name="Precision", description="Tolerence for comparing double keyframes (higher 
for greater accuracy)", min=1, max=16, soft_min=1, soft_max=16, default=6.0),
 #              bpy.props.BoolProperty(attr="ANIM_ACTION_ALL", name="Current 
Action", description="Use actions currently applied to the armatures (use scene 
start/end frame)", default=True),
-               bpy.props.BoolProperty(attr="ANIM_ACTION_ALL", name="All 
Actions", description="Use all actions for armatures", default=False),
+               bpy.props.BoolProperty(attr="ANIM_ACTION_ALL", name="All 
Actions", description="Use all actions for armatures, if false, use current 
action", default=False),
                # batch
                bpy.props.BoolProperty(attr="BATCH_ENABLE", name="Enable 
Batch", description="Automate exporting multiple scenes or groups to files", 
default=False),
                bpy.props.BoolProperty(attr="BATCH_GROUP", name="Group > File", 
description="Export each group as an FBX file, if false, export each scene as 
an FBX file", default=False),
@@ -3421,7 +3432,7 @@
                          self.EXP_OBS_SELECTED,
                          self.EXP_MESH,
                          self.EXP_MESH_APPLY_MOD,
-                         self.EXP_MESH_HQ_NORMALS,
+#                        self.EXP_MESH_HQ_NORMALS,
                          self.EXP_ARMATURE,
                          self.EXP_LAMP,
                          self.EXP_CAMERA,

Modified: branches/soc-2009-kazanbas/source/blender/blenkernel/BKE_image.h
===================================================================
--- branches/soc-2009-kazanbas/source/blender/blenkernel/BKE_image.h    
2009-07-23 12:31:45 UTC (rev 21812)
+++ branches/soc-2009-kazanbas/source/blender/blenkernel/BKE_image.h    
2009-07-23 12:55:26 UTC (rev 21813)
@@ -155,10 +155,9 @@
 /* merge source into dest, and free source */
 void BKE_image_merge(struct Image *dest, struct Image *source);
 
-/* ********************************** FOR EXPORTERS *********************** */
+/* copy image file to a directory rebuilding subdirectory structure */
+int BKE_export_image(struct Image *im, const char *dest_dir, char *out_path, 
int out_path_len);
 
-/* copy images into dest_dir */
-void BKE_copy_images(struct ListBase *images, char *dest_dir, struct ListBase 
*filenames);
 
 #ifdef __cplusplus
 }

Modified: branches/soc-2009-kazanbas/source/blender/blenkernel/intern/image.c
===================================================================
--- branches/soc-2009-kazanbas/source/blender/blenkernel/intern/image.c 
2009-07-23 12:31:45 UTC (rev 21812)
+++ branches/soc-2009-kazanbas/source/blender/blenkernel/intern/image.c 
2009-07-23 12:55:26 UTC (rev 21813)
@@ -2117,30 +2117,27 @@
 }
 
 /*
-  Copy list of images to dest_dir.
+  Copy an image to destination directory rebuilding subdirectory structure if 
needed.
+  Target image path is written to out_path.
+  Returns 1 on success, 0 otherwise.
 
-  paths is optional, if given, image paths for each image will be written in 
it.
-  It will also contain NULLs for images that cannot be copied.
-  If an image file doesn't exist, NULL is added in paths.
-
   Logic:
 
-  For each image if it's "below" current .blend file directory,
-  rebuild the same dir structure in dest_dir.
+  - 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.
+  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.
+  - 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.
-*/
-void BKE_copy_images(ListBase *images, char *dest_dir, ListBase *paths)
+
+ */
+int BKE_export_image(Image *im, const char *dest_dir, char *out_path, int 
out_path_len)
 {
        char path[FILE_MAX];
        char dir[FILE_MAX];
@@ -2148,88 +2145,77 @@
        char blend_dir[FILE_MAX];       /* directory, where current .blend file 
resides */
        char dest_path[FILE_MAX];
        int len;
-       Image *im;
-       LinkData *link;
 
-       if (paths) {
-               memset(paths, 0, sizeof(*paths));
-       }
+       out_path[0]= 0;
 
        BLI_split_dirfile_basic(G.sce, blend_dir, NULL);
-       
-       link= images->first;
 
-       while (link) {
-               im= link->data;
+       if (!strcmp(im->name, "") || im->type != IMA_TYPE_IMAGE) {
+               if (G.f & G_DEBUG) printf("invalid image type\n");
+               return 0;
+       }
 
-               LinkData *ld = MEM_callocN(sizeof(LinkData), "PathLinkData");
-               ld->data= NULL;
-               BLI_addtail(paths, ld);
+       BLI_strncpy(path, im->name, sizeof(path));
 
-               if (!strcmp(im->name, "") || im->type != IMA_TYPE_IMAGE)
-                       goto next;
+       /* expand "//" in filename and get absolute path */
+       BLI_convertstringcode(path, G.sce);
 
-               BLI_strncpy(path, im->name, sizeof(path));
-
-               /* expand "//" in filename and get absolute path */
-               BLI_convertstringcode(path, G.sce);
-
-               /* in unit tests, we don't want to modify the filesystem */
+       /* in unit tests, we don't want to modify the filesystem */
 #ifndef WITH_UNIT_TEST
-               /* proceed only if image file exists */
-               if (!BLI_exists(path))
-                       goto next;
+       /* proceed only if image file exists */
+       if (!BLI_exists(path)) {
+               if (G.f & G_DEBUG) printf("%s doesn't exist\n", path);
+               goto next;
+       }
 #endif
 
-               /* get the directory part */
-               BLI_split_dirfile_basic(path, dir, base);
+       /* get the directory part */
+       BLI_split_dirfile_basic(path, dir, base);
 
-               len= strlen(blend_dir);
+       len= strlen(blend_dir);
 

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to