[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [41305] trunk/blender/source/blender: bpath

Campbell Barton ideasman42 at gmail.com
Thu Oct 27 05:40:16 CEST 2011


Revision: 41305
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=41305
Author:   campbellbarton
Date:     2011-10-27 03:40:12 +0000 (Thu, 27 Oct 2011)
Log Message:
-----------
bpath
- loop over all sequence images and pointcache
- option not to loop over library / packed data, expose in bpy.utils.blend_paths()

Modified Paths:
--------------
    trunk/blender/source/blender/blenlib/BLI_bpath.h
    trunk/blender/source/blender/blenlib/intern/bpath.c
    trunk/blender/source/blender/python/intern/bpy.c

Modified: trunk/blender/source/blender/blenlib/BLI_bpath.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_bpath.h	2011-10-27 01:55:10 UTC (rev 41304)
+++ trunk/blender/source/blender/blenlib/BLI_bpath.h	2011-10-27 03:40:12 UTC (rev 41305)
@@ -42,12 +42,14 @@
    path has changed, and in that case, should write the result to pathOut. */
 typedef int (*BPathVisitor)(void *userdata, char *path_dst, const char *path_src);
 /* Executes 'visit' for each path associated with 'id'. */
-void bpath_traverse_id(struct Main *bmain, struct ID *id, BPathVisitor visit_cb, int flag, void *userdata);
-void bpath_traverse_id_list(struct Main *bmain, struct ListBase *lb, BPathVisitor visit_cb, int flag, void *userdata);
-void bpath_traverse_main(struct Main *bmain, BPathVisitor visit_cb, int flag, void *userdata);
+void bpath_traverse_id(struct Main *bmain, struct ID *id, BPathVisitor visit_cb, const int flag, void *userdata);
+void bpath_traverse_id_list(struct Main *bmain, struct ListBase *lb, BPathVisitor visit_cb, const int flag, void *userdata);
+void bpath_traverse_main(struct Main *bmain, BPathVisitor visit_cb, const int flag, void *userdata);
 int bpath_relocate_visitor(void *oldbasepath, char *path_dst, const char *path_src);
 
-#define BPATH_TRAVERSE_ABS 1 /* convert paths to absolute */
+#define BPATH_TRAVERSE_ABS          (1<<0) /* convert paths to absolute */
+#define BPATH_TRAVERSE_SKIP_LIBRARY (1<<2) /* skip library paths */
+#define BPATH_TRAVERSE_SKIP_PACKED  (1<<3) /* skip packed data */
 
 /* high level funcs */
 
@@ -57,6 +59,4 @@
 void makeFilesAbsolute(struct Main *bmain, const char *basedir, struct ReportList *reports);
 void findMissingFiles(struct Main *bmain, const char *searchpath, struct ReportList *reports);
 
-#define BPATH_USE_PACKED 1
-
 #endif // BLI_BPATH_H

Modified: trunk/blender/source/blender/blenlib/intern/bpath.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/bpath.c	2011-10-27 01:55:10 UTC (rev 41304)
+++ trunk/blender/source/blender/blenlib/intern/bpath.c	2011-10-27 03:40:12 UTC (rev 41305)
@@ -20,7 +20,7 @@
  *
  * The Original Code is: all of this file.
  *
- * Contributor(s): Campbell barton
+ * Contributor(s): Campbell barton, Alex Fraser
  *
  * ***** END GPL LICENSE BLOCK *****
  */
@@ -29,6 +29,12 @@
  *  \ingroup bli
  */
 
+/* TODO,
+ * currently there are some cases we dont support.
+ * - passing output paths to the visitor?, like render out.
+ * - passing sequence strips with many images.
+ * - passing directory paths - visitors dont know which path is a dir or a file.
+ * */
 
 #include <sys/stat.h>
 
@@ -46,27 +52,32 @@
 
 #include "MEM_guardedalloc.h"
 
+#include "DNA_brush_types.h"
+#include "DNA_image_types.h"
 #include "DNA_mesh_types.h"
-#include "DNA_scene_types.h" /* to get the current frame */
-#include "DNA_image_types.h"
+#include "DNA_modifier_types.h"
+#include "DNA_object_fluidsim.h"
+#include "DNA_object_force.h"
+#include "DNA_object_types.h"
+#include "DNA_particle_types.h"
+#include "DNA_sequence_types.h"
+#include "DNA_sound_types.h"
+#include "DNA_text_types.h"
 #include "DNA_texture_types.h"
-#include "DNA_text_types.h"
-#include "DNA_sound_types.h"
-#include "DNA_sequence_types.h"
 #include "DNA_vfont_types.h"
-#include "DNA_object_types.h"
-#include "DNA_object_fluidsim.h"
+#include "DNA_scene_types.h"
+#include "DNA_smoke_types.h"
 
 #include "BLI_blenlib.h"
 #include "BLI_bpath.h"
 #include "BLI_utildefines.h"
 
-#include "BKE_image.h" /* so we can check the image's type */
+#include "BKE_library.h"
+#include "BKE_main.h"
+#include "BKE_report.h"
 #include "BKE_sequencer.h"
-#include "BKE_main.h"
 #include "BKE_utildefines.h"
-#include "BKE_report.h"
-#include "BKE_library.h"
+#include "BKE_image.h" /* so we can check the image's type */
 
 static int checkMissingFiles_visit_cb(void *userdata, char *UNUSED(path_dst), const char *path_src)
 {
@@ -349,29 +360,96 @@
 }
 
 /* Run visitor function 'visit' on all paths contained in 'id'. */
-void bpath_traverse_id(Main *bmain, ID *id, BPathVisitor visit_cb, int flag, void *userdata)
+void bpath_traverse_id(Main *bmain, ID *id, BPathVisitor visit_cb, const int flag, void *userdata)
 {
 	Image *ima;
 	const char *absbase= (flag & BPATH_TRAVERSE_ABS) ? (id->lib ? id->lib->filepath : bmain->name) : NULL;
 
+	if ((flag & BPATH_TRAVERSE_SKIP_LIBRARY) && id->lib) {
+		return;
+	}
 
 	switch(GS(id->name)) {
 	case ID_IM:
-		ima = (Image *)id;
-		if (ELEM3(ima->source, IMA_SRC_FILE, IMA_SRC_MOVIE, IMA_SRC_SEQUENCE))
-			rewrite_path_fixed(ima->name, visit_cb, absbase, userdata);
+		ima= (Image *)id;
+		if (ima->packedfile == NULL || (flag & BPATH_TRAVERSE_SKIP_PACKED) == 0) {
+			if (ELEM3(ima->source, IMA_SRC_FILE, IMA_SRC_MOVIE, IMA_SRC_SEQUENCE)) {
+				rewrite_path_fixed(ima->name, visit_cb, absbase, userdata);
+			}
+		}
 		break;
+	case ID_BR:
+		{
+			Brush *brush= (Brush *)id;
+			if (brush->icon_filepath[0]) {
+				rewrite_path_fixed(brush->icon_filepath, visit_cb, absbase, userdata);
+			}
+		}
+		break;
 	case ID_OB:
+
+#define BPATH_TRAVERSE_POINTCACHE(ptcaches)                                    \
+	{                                                                          \
+		PointCache *cache;                                                     \
+		for(cache= (ptcaches).first; cache; cache= cache->next) {              \
+			if(cache->flag & PTCACHE_DISK_CACHE) {                             \
+				rewrite_path_fixed(cache->path, visit_cb, absbase, userdata);  \
+			}                                                                  \
+		}                                                                      \
+	}                                                                          \
+
+
 		{
 			Object *ob= (Object *)id;
+			ModifierData *md;
+			ParticleSystem *psys;
+
+
+			/* do via modifiers instead */
+#if 0
 			if (ob->fluidsimSettings) {
 				rewrite_path_fixed(ob->fluidsimSettings->surfdataPath, visit_cb, absbase, userdata);
 			}
-			/* TODO: add modifiers, e.g. point cache for particles. */
+#endif
+
+			for (md= ob->modifiers.first; md; md= md->next) {
+				if (md->type == eModifierType_Fluidsim) {
+					FluidsimModifierData *fluidmd= (FluidsimModifierData *)md;
+					if (fluidmd->fss) {
+						rewrite_path_fixed(fluidmd->fss->surfdataPath, visit_cb, absbase, userdata);
+					}
+				}
+				else if (md->type == eModifierType_Smoke) {
+					SmokeModifierData *smd= (SmokeModifierData *)md;
+					if(smd->type & MOD_SMOKE_TYPE_DOMAIN) {
+						BPATH_TRAVERSE_POINTCACHE(smd->domain->ptcaches[0]);
+					}
+				}
+				else if (md->type==eModifierType_Cloth) {
+					ClothModifierData *clmd= (ClothModifierData*) md;
+					BPATH_TRAVERSE_POINTCACHE(clmd->ptcaches);
+				}
+			}
+
+			if (ob->soft) {
+				BPATH_TRAVERSE_POINTCACHE(ob->soft->ptcaches);
+			}
+
+			for (psys= ob->particlesystem.first; psys; psys= psys->next) {
+				BPATH_TRAVERSE_POINTCACHE(psys->ptcaches);
+			}
 		}
+
+#undef BPATH_TRAVERSE_POINTCACHE
+
 		break;
 	case ID_SO:
-		rewrite_path_fixed(((bSound *)id)->name, visit_cb, absbase, userdata);
+		{
+			bSound *sound= (bSound *)id;
+			if (sound->packedfile == NULL || (flag & BPATH_TRAVERSE_SKIP_PACKED) == 0) {
+				rewrite_path_fixed(sound->name, visit_cb, absbase, userdata);
+			}
+		}
 		break;
 	case ID_TXT:
 		if (((Text*)id)->name) {
@@ -379,8 +457,13 @@
 		}
 		break;
 	case ID_VF:
-		if (strcmp(((VFont*)id)->name, FO_BUILTIN_NAME) != 0) {
-			rewrite_path_fixed(((VFont *)id)->name, visit_cb, absbase, userdata);
+		{
+			VFont *vf= (VFont *)id;
+			if (vf->packedfile == NULL || (flag & BPATH_TRAVERSE_SKIP_PACKED) == 0) {
+				if (strcmp(vf->name, FO_BUILTIN_NAME) != 0) {
+					rewrite_path_fixed(((VFont *)id)->name, visit_cb, absbase, userdata);
+				}
+			}
 		}
 		break;
 	case ID_TE:
@@ -405,9 +488,19 @@
 
 				SEQ_BEGIN(scene->ed, seq) {
 					if (SEQ_HAS_PATH(seq)) {
-						if (ELEM3(seq->type, SEQ_IMAGE, SEQ_MOVIE, SEQ_SOUND)) {
+						if (ELEM(seq->type, SEQ_MOVIE, SEQ_SOUND)) {
 							rewrite_path_fixed_dirfile(seq->strip->dir, seq->strip->stripdata->name, visit_cb, absbase, userdata);
 						}
+						else if (seq->type == SEQ_IMAGE) {
+							/* might want an option not to loop over all strips */
+							StripElem *se= seq->strip->stripdata;
+							int len= MEM_allocN_len(se) / sizeof(*se);
+							int i;
+
+							for(i= 0; i < len; i++, se++) {
+								rewrite_path_fixed_dirfile(seq->strip->dir, se->name, visit_cb, absbase, userdata);
+							}
+						}
 						else {
 							/* simple case */
 							rewrite_path_fixed(seq->strip->dir, visit_cb, absbase, userdata);
@@ -438,14 +531,13 @@
 			}
 		}
 		break;
-	/* TODO: add other ID types e.g. object (modifiers) */
 	default:
 		/* Nothing to do for other IDs that don't contain file paths. */
 		break;
 	}
 }
 
-void bpath_traverse_id_list(Main *bmain, ListBase *lb, BPathVisitor visit_cb, int flag, void *userdata)
+void bpath_traverse_id_list(Main *bmain, ListBase *lb, BPathVisitor visit_cb, const int flag, void *userdata)
 {
 	ID *id;
 	for(id= lb->first; id; id= id->next) {
@@ -453,7 +545,7 @@
 	}
 }
 
-void bpath_traverse_main(Main *bmain, BPathVisitor visit_cb, int flag, void *userdata)
+void bpath_traverse_main(Main *bmain, BPathVisitor visit_cb, const int flag, void *userdata)
 {
 	ListBase *lbarray[MAX_LIBARRAY];
 	int a= set_listbasepointers(bmain, lbarray);
@@ -472,7 +564,7 @@
 	if (strncmp(base_old, "//", 2) == 0) {
 		printf("%s: error, old base path '%s' is not absolute.\n",
 		       __func__, base_old);
-		return 0;
+		return FALSE;
 	}
 
 	/* Make referenced file absolute. This would be a side-effect of
@@ -485,10 +577,10 @@
 		BLI_cleanup_file(base_new, filepath);
 		BLI_path_rel(filepath, base_new);
 		BLI_strncpy(path_dst, filepath, FILE_MAX);
-		return 1;
+		return TRUE;
 	}
 	else {
 		/* Path was not relative to begin with. */
-		return 0;
+		return FALSE;
 	}
 }

Modified: trunk/blender/source/blender/python/intern/bpy.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy.c	2011-10-27 01:55:10 UTC (rev 41304)
+++ trunk/blender/source/blender/python/intern/bpy.c	2011-10-27 03:40:12 UTC (rev 41305)
@@ -91,12 +91,16 @@
 }
 
 PyDoc_STRVAR(bpy_blend_paths_doc,
-".. function:: blend_paths(absolute=False)\n"
+".. function:: blend_paths(absolute=False, packed=False, local=False)\n"
 "\n"

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list