[Bf-blender-cvs] [afe7583] alembic_basic_io: Determine programatically whether or not an imported alembic archive is part of sequence of files.

Kévin Dietrich noreply at git.blender.org
Sat Jun 11 14:59:39 CEST 2016


Commit: afe7583ffa944af24374206c0429aab35946f704
Author: Kévin Dietrich
Date:   Sat Jun 11 14:46:28 2016 +0200
Branches: alembic_basic_io
https://developer.blender.org/rBafe7583ffa944af24374206c0429aab35946f704

Determine programatically whether or not an imported alembic archive is
part of sequence of files.

This removes the checkbox in the importer's UI, and also allows to set
the scene start and end frames based on the sequence length if desired.

===================================================================

M	source/blender/alembic/ABC_alembic.h
M	source/blender/alembic/intern/abc_object.h
M	source/blender/alembic/intern/alembic_capi.cc
M	source/blender/editors/io/io_alembic.c

===================================================================

diff --git a/source/blender/alembic/ABC_alembic.h b/source/blender/alembic/ABC_alembic.h
index 77ec954..1d17b79 100644
--- a/source/blender/alembic/ABC_alembic.h
+++ b/source/blender/alembic/ABC_alembic.h
@@ -57,7 +57,7 @@ int ABC_export(struct Scene *scene, struct bContext *C, const char *filepath,
                int geogroups, int compression,
                bool packuv, float scale);
 
-void ABC_import(struct bContext *C, const char *filepath, float scale, bool is_sequence, bool set_frame_range);
+void ABC_import(struct bContext *C, const char *filepath, float scale, bool is_sequence, bool set_frame_range, int sequence_len, int offset);
 
 void ABC_get_vertex_cache(const char *filepath, float time, void *verts, int max_verts, const char *object_path, int is_mvert);
 
diff --git a/source/blender/alembic/intern/abc_object.h b/source/blender/alembic/intern/abc_object.h
index df0cbe3..62fd121 100644
--- a/source/blender/alembic/intern/abc_object.h
+++ b/source/blender/alembic/intern/abc_object.h
@@ -98,6 +98,10 @@ struct ImportSettings {
 	bool is_sequence;
 	bool set_frame_range;
 
+	/* Length and frame offset of file sequences. */
+	int sequence_len;
+	int offset;
+
 	CacheFile *cache_file;
 };
 
diff --git a/source/blender/alembic/intern/alembic_capi.cc b/source/blender/alembic/intern/alembic_capi.cc
index f759307..bd5552f 100644
--- a/source/blender/alembic/intern/alembic_capi.cc
+++ b/source/blender/alembic/intern/alembic_capi.cc
@@ -516,6 +516,7 @@ static void import_startjob(void *cjv, short *stop, short *do_update, float *pro
 		if (reader->valid()) {
 			reader->readObjectData(data->bmain, scene, 0.0f);
 			reader->readObjectMatrix(0.0f);
+
 			min_time = std::min(min_time, reader->minTime());
 			max_time = std::max(max_time, reader->maxTime());
 		}
@@ -523,10 +524,17 @@ static void import_startjob(void *cjv, short *stop, short *do_update, float *pro
 		*data->progress = 0.1f + 0.6f * (++i / size);
 	}
 
-	if (data->settings.set_frame_range && (min_time < max_time)) {
-		SFRA = min_time * FPS;
-		EFRA = max_time * FPS;
-		CFRA = SFRA;
+	if (data->settings.set_frame_range) {
+		if (data->settings.is_sequence) {
+			SFRA = data->settings.offset;
+			EFRA = SFRA + (data->settings.sequence_len - 1);
+			CFRA = SFRA;
+		}
+		else if (min_time < max_time) {
+			SFRA = min_time * FPS;
+			EFRA = max_time * FPS;
+			CFRA = SFRA;
+		}
 	}
 
 	i = 0;
@@ -573,7 +581,7 @@ static void import_startjob(void *cjv, short *stop, short *do_update, float *pro
 	WM_main_add_notifier(NC_SCENE | ND_FRAME, scene);
 }
 
-void ABC_import(bContext *C, const char *filepath, float scale, bool is_sequence, bool set_frame_range)
+void ABC_import(bContext *C, const char *filepath, float scale, bool is_sequence, bool set_frame_range, int sequence_len, int offset)
 {
 	ImportJobData *job = static_cast<ImportJobData *>(MEM_mallocN(sizeof(ImportJobData), "ImportJobData"));
 	job->bmain = CTX_data_main(C);
@@ -583,6 +591,8 @@ void ABC_import(bContext *C, const char *filepath, float scale, bool is_sequence
 	job->settings.scale = scale;
 	job->settings.is_sequence = is_sequence;
 	job->settings.set_frame_range = set_frame_range;
+	job->settings.sequence_len = sequence_len;
+	job->settings.offset = offset;
 
 	wmJob *wm_job = WM_jobs_get(CTX_wm_manager(C),
 	                            CTX_wm_window(C),
diff --git a/source/blender/editors/io/io_alembic.c b/source/blender/editors/io/io_alembic.c
index 4ad85f5..e3ba05f 100644
--- a/source/blender/editors/io/io_alembic.c
+++ b/source/blender/editors/io/io_alembic.c
@@ -24,6 +24,10 @@
 
 #ifdef WITH_ALEMBIC
 
+#include <dirent.h>
+
+#include "MEM_guardedalloc.h"
+
 #include "DNA_mesh_types.h"
 #include "DNA_object_types.h"
 #include "DNA_scene_types.h"
@@ -34,6 +38,7 @@
 #include "BKE_main.h"
 #include "BKE_report.h"
 
+#include "BLI_listbase.h"
 #include "BLI_math_vector.h"
 #include "BLI_path_util.h"
 #include "BLI_string.h"
@@ -291,6 +296,89 @@ void WM_OT_alembic_export(wmOperatorType *ot)
 	RNA_def_float(ot->srna, "scale", 1.0f, 0.0f, 1000.0f, "Scale", "", 0.0f, 1000.0f);
 }
 
+/* ************************************************************************** */
+
+/* TODO(kevin): check on de-duplicating all this with code in image_ops.c */
+
+typedef struct CacheFrame {
+	struct CacheFrame *next, *prev;
+	int framenr;
+} CacheFrame;
+
+static int cmp_frame(const void *a, const void *b)
+{
+	const CacheFrame *frame_a = a;
+	const CacheFrame *frame_b = b;
+
+	if (frame_a->framenr < frame_b->framenr) return -1;
+	if (frame_a->framenr > frame_b->framenr) return 1;
+	return 0;
+}
+
+static int get_seqeunce_len(char *filename, int *ofs)
+{
+	int frame;
+	int numdigit;
+
+	if (!BLI_path_frame_get(filename, &frame, &numdigit)) {
+		return 1;
+	}
+
+	char path[FILE_MAX];
+	BLI_split_dir_part(filename, path, FILE_MAX);
+
+	DIR *dir = opendir(path);
+
+	const char *ext = ".abc";
+	const char *basename = BLI_path_basename(filename);
+	const int len = strlen(basename) - (numdigit + strlen(ext));
+
+	ListBase frames;
+	BLI_listbase_clear(&frames);
+
+	struct dirent *fname;
+	while ((fname = readdir(dir)) != NULL) {
+		/* do we have the right extension? */
+		if (!strstr(fname->d_name, ext)) {
+			continue;
+		}
+
+		if (!STREQLEN(basename, fname->d_name, len)) {
+			continue;
+		}
+
+		CacheFrame *cache_frame = MEM_callocN(sizeof(CacheFrame), "abc_frame");
+
+		BLI_path_frame_get(fname->d_name, &cache_frame->framenr, &numdigit);
+
+		BLI_addtail(&frames, cache_frame);
+	}
+
+	closedir(dir);
+
+	BLI_listbase_sort(&frames, cmp_frame);
+
+	CacheFrame *cache_frame = frames.first;
+
+	if (cache_frame) {
+		int frame_curr = cache_frame->framenr;
+		(*ofs) = frame_curr;
+
+		while (cache_frame && (cache_frame->framenr == frame_curr)) {
+			++frame_curr;
+			cache_frame = cache_frame->next;
+		}
+
+		BLI_freelistN(&frames);
+
+		return frame_curr - (*ofs);
+	}
+
+	return 1;
+}
+
+/* ************************************************************************** */
+
 static void ui_alembic_import_settings(uiLayout *layout, PointerRNA *imfptr)
 {
 	uiLayout *box = uiLayoutBox(layout);
@@ -306,9 +394,6 @@ static void ui_alembic_import_settings(uiLayout *layout, PointerRNA *imfptr)
 
 	row = uiLayoutRow(box, false);
 	uiItemR(row, imfptr, "set_frame_range", 0, NULL, ICON_NONE);
-
-	row = uiLayoutRow(box, false);
-	uiItemR(row, imfptr, "is_sequence", 0, NULL, ICON_NONE);
 }
 
 static void wm_alembic_import_draw(bContext *UNUSED(C), wmOperator *op)
@@ -330,10 +415,13 @@ static int wm_alembic_import_exec(bContext *C, wmOperator *op)
 	RNA_string_get(op->ptr, "filepath", filename);
 
 	const float scale = RNA_float_get(op->ptr, "scale");
-	const bool is_sequence = RNA_boolean_get(op->ptr, "is_sequence");
 	const bool set_frame_range = RNA_boolean_get(op->ptr, "set_frame_range");
 
-	ABC_import(C, filename, scale, is_sequence, set_frame_range);
+	int offset;
+	int sequence_len = get_seqeunce_len(filename, &offset);
+	const bool is_sequence = (sequence_len > 1);
+
+	ABC_import(C, filename, scale, is_sequence, set_frame_range, sequence_len, offset);
 
 	return OPERATOR_FINISHED;
 }
@@ -353,9 +441,6 @@ void WM_OT_alembic_import(wmOperatorType *ot)
 
 	RNA_def_float(ot->srna, "scale", 1.0f, 0.0f, 1000.0f, "Scale", "", 0.0f, 1000.0f);
 
-	RNA_def_boolean(ot->srna, "is_sequence", false,
-	                "Sequence", "Whether the cache is separated in a series of file");
-
 	RNA_def_boolean(ot->srna, "set_frame_range", true,
 	                "Set Frame Range",
 	                "If checked, update scene's start and end frame to match those of the Alembic archive");




More information about the Bf-blender-cvs mailing list