[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [14385] trunk/blender/source/blender: Changed BLI_convertstringcode to replace any number of hashes with the frame number .

Campbell Barton ideasman42 at gmail.com
Fri Apr 11 17:47:21 CEST 2008


Revision: 14385
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=14385
Author:   campbellbarton
Date:     2008-04-11 17:47:21 +0200 (Fri, 11 Apr 2008)

Log Message:
-----------
Changed BLI_convertstringcode to replace any number of hashes with the frame number.

somefile_##.png -> somefile_01.png
somefile_########-image.png -> somefile_00000001-image.png

Before, A hash at the end of the string would be replaced by a number with 4 characters. This is still default if no #'s are in the string, so nothing has changed.

To use this function from the python api use scene.render.getFrameFilename()

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/intern/DerivedMesh.c
    trunk/blender/source/blender/blenkernel/intern/effect.c
    trunk/blender/source/blender/blenkernel/intern/image.c
    trunk/blender/source/blender/blenkernel/intern/particle_system.c
    trunk/blender/source/blender/blenlib/intern/util.c
    trunk/blender/source/blender/src/buttons_scene.c
    trunk/blender/source/blender/src/sequence.c

Modified: trunk/blender/source/blender/blenkernel/intern/DerivedMesh.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/DerivedMesh.c	2008-04-11 12:29:29 UTC (rev 14384)
+++ trunk/blender/source/blender/blenkernel/intern/DerivedMesh.c	2008-04-11 15:47:21 UTC (rev 14385)
@@ -3312,9 +3312,9 @@
 		srcob->data = srcob->fluidsimSettings->orgMesh;
 		return;
 	} else if(displaymode==2) {
-		strcat(targetDir,"fluidsurface_preview_#");
+		strcat(targetDir,"fluidsurface_preview_####");
 	} else { // 3
-		strcat(targetDir,"fluidsurface_final_#");
+		strcat(targetDir,"fluidsurface_final_####");
 	}
 	BLI_convertstringcode(targetDir, G.sce, curFrame); // fixed #frame-no 
 	strcpy(targetFile,targetDir);

Modified: trunk/blender/source/blender/blenkernel/intern/effect.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/effect.c	2008-04-11 12:29:29 UTC (rev 14384)
+++ trunk/blender/source/blender/blenkernel/intern/effect.c	2008-04-11 15:47:21 UTC (rev 14385)
@@ -1711,7 +1711,7 @@
 	if( (1) && (ob->fluidsimFlag & OB_FLUIDSIM_ENABLE) &&  // broken, disabled for now!
 	    (ob->fluidsimSettings) && 
 		  (ob->fluidsimSettings->type == OB_FLUIDSIM_PARTICLE)) {
-		char *suffix  = "fluidsurface_particles_#";
+		char *suffix  = "fluidsurface_particles_####";
 		char *suffix2 = ".gz";
 		char filename[256];
 		char debugStrBuffer[256];

Modified: trunk/blender/source/blender/blenkernel/intern/image.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/image.c	2008-04-11 12:29:29 UTC (rev 14384)
+++ trunk/blender/source/blender/blenkernel/intern/image.c	2008-04-11 15:47:21 UTC (rev 14385)
@@ -1236,24 +1236,16 @@
 
 void BKE_makepicstring(char *string, char *base, int frame, int imtype)
 {
-	short i, len, digits= 4;	/* digits in G.scene? */
-	char num[10];
-
 	if (string==NULL) return;
 
 	BLI_strncpy(string, base, FILE_MAX - 10);	/* weak assumption */
+	
+	/* if we dont have any #'s to insert numbers into, use 4 numbers by default */
+	if (strchr(string, '#')==NULL)
+		strcat(string, "####"); /* 4 numbers */
+	
 	BLI_convertstringcode(string, G.sce, frame);
 
-	len= strlen(string);
-			
-	i= digits - sprintf(num, "%d", frame);
-	for(; i>0; i--){
-		string[len]= '0';
-		len++;
-	}
-	string[len]= 0;
-	strcat(string, num);
-
 	if(G.scene->r.scemode & R_EXTENSION) 
 		BKE_add_image_extension(string, imtype);
 		

Modified: trunk/blender/source/blender/blenkernel/intern/particle_system.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/particle_system.c	2008-04-11 12:29:29 UTC (rev 14384)
+++ trunk/blender/source/blender/blenkernel/intern/particle_system.c	2008-04-11 15:47:21 UTC (rev 14385)
@@ -4552,7 +4552,7 @@
 		(ob->fluidsimSettings)) { 
 		ParticleSettings *part = psys->part;
 		ParticleData *pa=0;
-		char *suffix  = "fluidsurface_particles_#";
+		char *suffix  = "fluidsurface_particles_####";
 		char *suffix2 = ".gz";
 		char filename[256];
 		char debugStrBuffer[256];

Modified: trunk/blender/source/blender/blenlib/intern/util.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/util.c	2008-04-11 12:29:29 UTC (rev 14384)
+++ trunk/blender/source/blender/blenlib/intern/util.c	2008-04-11 15:47:21 UTC (rev 14385)
@@ -41,6 +41,7 @@
 #include <string.h>
 #include <stdlib.h>
 #include <stdarg.h>
+#include <math.h> /* for log10 */
 
 #include "MEM_guardedalloc.h"
 
@@ -1027,7 +1028,8 @@
 
 int BLI_convertstringcode(char *path, const char *basepath, int framenum)
 {
-	int len, wasrelative;
+	int wasrelative;
+	int ch_sta, ch_end;
 	char tmp[FILE_MAX];
 	char base[FILE_MAX];
 	char vol[3] = {'\0', '\0', '\0'};
@@ -1082,12 +1084,54 @@
 		
 		MEM_freeN(filepart);
 	}
-
-	len= strlen(tmp);
-	if(len && tmp[len-1]=='#') {
-		sprintf(tmp+len-1, "%04d", framenum);
+	
+	
+	/* Insert current frame: file### -> file001 */
+	ch_end = 0;
+	for (ch_sta = 0; tmp[ch_sta] != '\0'; ch_sta++) {
+		if (tmp[ch_sta] == '#') {
+			ch_end = ch_sta+1;
+			while (tmp[ch_end] == '#') {
+				ch_end++;
+			}			
+			break;
+		}
 	}
-
+	if (ch_end) { /* warning, ch_end is the last # +1 */
+		/* Add the frame number? */
+		short numlen, hashlen;
+		char format[16]; /* 6 is realistically the maxframe (300000), so 8 should be enough, but 16 to be safe. */
+		
+		numlen = 1 + (int)log10((double)framenum); /* this is the number of chars in the number */
+		hashlen = ch_end - ch_sta;
+		
+		sprintf(format, "%d", framenum);
+		
+		if (numlen==hashlen) { /* simple case */
+			memcpy(tmp+ch_sta, format, numlen);
+		} else if (numlen < hashlen) {
+			memcpy(tmp+ch_sta + (hashlen-numlen), format, numlen); /*dont copy the string terminator */
+			memset(tmp+ch_sta, '0', hashlen-numlen);
+		} else {
+			/* number is longer then number of #'s */
+			if (tmp[ch_end] == '\0') { /* hashes are last, no need to move any string*/
+				/* bad juju - not testing string length here :/ */
+				memcpy(tmp+ch_sta, format, numlen+1); /* add 1 to get the string terminator \0 */
+			} else {
+				/* we need to move the end characters */
+				int i = strlen(tmp); /* +1 to copy the string terminator */
+				int j = i + (numlen-hashlen); /* from/to */
+				while (i >= ch_end) {
+					tmp[j] = tmp[i]; 
+					i--;
+					j--;
+				}
+				memcpy(tmp + ch_sta, format, numlen);
+			}
+		}	
+	}
+	/* done with file### stuff */
+	
 	strcpy(path, tmp);
 #ifdef WIN32
 	/* skip first two chars, which in case of

Modified: trunk/blender/source/blender/src/buttons_scene.c
===================================================================
--- trunk/blender/source/blender/src/buttons_scene.c	2008-04-11 12:29:29 UTC (rev 14384)
+++ trunk/blender/source/blender/src/buttons_scene.c	2008-04-11 15:47:21 UTC (rev 14385)
@@ -1998,9 +1998,9 @@
 	if(uiNewPanel(curarea, block, "Output", "Render", 0, 0, 318, 204)==0) return;
 	
 	uiBlockBeginAlign(block);
-	uiDefIconBut(block, BUT, B_FS_PIC, ICON_FILESEL,	10, 190, 20, 20, 0, 0, 0, 0, 0, "Open Fileselect to get Pics dir/name");
-	uiDefBut(block, TEX,0,"",							31, 190, 279, 20,G.scene->r.pic, 0.0,79.0, 0, 0, "Directory/name to save rendered Pics to");
-	uiDefIconBut(block, BUT,B_FS_BACKBUF, ICON_FILESEL, 10, 168, 20, 20, 0, 0, 0, 0, 0, "Open Fileselect to get Backbuf image");
+	uiDefIconBut(block, BUT, B_FS_PIC, ICON_FILESEL,	10, 190, 20, 20, 0, 0, 0, 0, 0, "Select the directory/name for saving animations");
+	uiDefBut(block, TEX,0,"",							31, 190, 279, 20,G.scene->r.pic, 0.0,79.0, 0, 0, "Directory/name to save animations, # characters defines the position and length of frame numbers");
+	uiDefIconBut(block, BUT,B_FS_BACKBUF, ICON_FILESEL, 10, 168, 20, 20, 0, 0, 0, 0, 0, "Select the directory/name for a Backbuf image");
 	uiDefBut(block, TEX,0,"",							31, 168, 279, 20,G.scene->r.backbuf, 0.0,79.0, 0, 0, "Image to use as background for rendering");
 	uiBlockEndAlign(block);
 	

Modified: trunk/blender/source/blender/src/sequence.c
===================================================================
--- trunk/blender/source/blender/src/sequence.c	2008-04-11 12:29:29 UTC (rev 14384)
+++ trunk/blender/source/blender/src/sequence.c	2008-04-11 15:47:21 UTC (rev 14385)
@@ -1059,7 +1059,7 @@
 
 		frameno = tse->nr + seq->anim_startofs;
 
-		snprintf(name, PROXY_MAXFILE, "%s/%s/%d/#", dir,
+		snprintf(name, PROXY_MAXFILE, "%s/%s/%d/####", dir,
 			 seq->strip->stripdata->name,
 			 G.scene->r.size);
 	} else {
@@ -1067,7 +1067,7 @@
 
 		frameno = tse->nr + seq->anim_startofs;
 
-		snprintf(name, PROXY_MAXFILE, "%s/proxy_misc/%d/#", dir,
+		snprintf(name, PROXY_MAXFILE, "%s/proxy_misc/%d/####", dir,
 			 G.scene->r.size);
 	}
 





More information about the Bf-blender-cvs mailing list