[Bf-blender-cvs] [8c21b0a] alembic: New operator for 'splicing' Alembic data, i.e. writing part of the frame range to a new archive.

Lukas Tönne noreply at git.blender.org
Mon May 18 20:36:01 CEST 2015


Commit: 8c21b0a9439204194b08ff4cb156cfe70355fe58
Author: Lukas Tönne
Date:   Mon May 18 19:43:01 2015 +0200
Branches: alembic
https://developer.blender.org/rB8c21b0a9439204194b08ff4cb156cfe70355fe58

New operator for 'splicing' Alembic data, i.e. writing part of the frame
range to a new archive.

This feature is useful when cache size becomes to big and unwieldy.
For sending shots to a render farm a large cache can now be split into
smaller parts, which are spliced off and can be sent individually.

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

M	release/scripts/startup/bl_ui/space_view3d.py
M	source/blender/editors/io/io_cache_library.c
M	source/blender/editors/io/io_cache_library.h
M	source/blender/editors/io/io_ops.c
M	source/blender/pointcache/PTC_api.cpp
M	source/blender/pointcache/PTC_api.h
M	source/blender/pointcache/alembic/CMakeLists.txt
M	source/blender/pointcache/alembic/abc_reader.h
A	source/blender/pointcache/alembic/abc_split.cpp
M	source/blender/pointcache/alembic/abc_writer.h
M	source/blender/pointcache/alembic/alembic.cpp
M	source/blender/pointcache/alembic/alembic.h
M	source/blender/pointcache/intern/ptc_types.h

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

diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index a27cab1..5dc6b0b 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -1150,6 +1150,7 @@ class VIEW3D_MT_object(Menu):
         layout.menu("VIEW3D_MT_object_parent")
         layout.menu("VIEW3D_MT_object_track")
         layout.menu("VIEW3D_MT_object_group")
+        layout.menu("VIEW3D_MT_object_cachelib")
         layout.menu("VIEW3D_MT_object_constraints")
 
         layout.separator()
@@ -1416,6 +1417,29 @@ class VIEW3D_MT_object_group(Menu):
         layout.operator("group.objects_remove_active")
 
 
+class VIEW3D_MT_object_cachelib(Menu):
+    bl_label = "Cache Library"
+
+    @classmethod
+    def poll(cls, context):
+        ob = context.active_object
+        if not (ob and ob.cache_library):
+            return False
+        return True
+
+    def draw(self, context):
+        layout = self.layout
+        scene = context.scene
+        ob = context.active_object
+        cachelib = ob.cache_library
+
+        layout.operator("cachelibrary.bake", text="Bake")
+        props = layout.operator("cachelibrary.archive_slice", text="Slice")
+        props.input_filepath = cachelib.input_filepath
+        props.start_frame = scene.frame_start
+        props.end_frame = scene.frame_end
+
+
 class VIEW3D_MT_object_constraints(Menu):
     bl_label = "Constraints"
 
diff --git a/source/blender/editors/io/io_cache_library.c b/source/blender/editors/io/io_cache_library.c
index e85c6ea..0ed76fc 100644
--- a/source/blender/editors/io/io_cache_library.c
+++ b/source/blender/editors/io/io_cache_library.c
@@ -332,12 +332,8 @@ static void cache_library_bake_do(CacheLibraryBakeJob *data)
 }
 
 /* Warning! Deletes existing files if possible, operator should show confirm dialog! */
-static bool cache_library_bake_ensure_file_target(CacheLibrary *cachelib)
+static bool cache_library_bake_ensure_file_target(const char *filename)
 {
-	char filename[FILE_MAX];
-	
-	BKE_cache_archive_output_path(cachelib, filename, sizeof(filename));
-	
 	if (BLI_exists(filename)) {
 		if (BLI_is_dir(filename)) {
 			return false;
@@ -426,7 +422,9 @@ static void cache_library_bake_init(CacheLibraryBakeJob *data, bContext *C, wmOp
 	Scene *scene = CTX_data_scene(C);
 	
 	/* make sure we can write */
-	cache_library_bake_ensure_file_target(cachelib);
+	char filename[FILE_MAX];
+	BKE_cache_archive_output_path(cachelib, filename, sizeof(filename));
+	cache_library_bake_ensure_file_target(filename);
 	
 	/* XXX annoying hack: needed to prevent data corruption when changing
 	 * scene frame in separate threads
@@ -597,6 +595,139 @@ void CACHELIBRARY_OT_bake(wmOperatorType *ot)
 
 /* ========================================================================= */
 
+static int cache_library_archive_slice_exec(bContext *C, wmOperator *op)
+{
+	Object *ob = CTX_data_active_object(C);
+	CacheLibrary *cachelib = ob->cache_library;
+	Scene *scene = CTX_data_scene(C);
+	
+	const int start_frame = RNA_int_get(op->ptr, "start_frame");
+	const int end_frame = RNA_int_get(op->ptr, "end_frame");
+	
+	char input_filepath[FILE_MAX], input_filename[FILE_MAX];
+	char output_filepath[FILE_MAX], output_filename[FILE_MAX];
+	struct PTCReaderArchive *input_archive;
+	struct PTCWriterArchive *output_archive;
+	
+	RNA_string_get(op->ptr, "input_filepath", input_filepath);
+	if (input_filepath[0] == '\0')
+		return OPERATOR_CANCELLED;
+	RNA_string_get(op->ptr, "output_filepath", output_filepath);
+	if (output_filepath[0] == '\0')
+		return OPERATOR_CANCELLED;
+	
+	BKE_cache_archive_path_ex(input_filepath, cachelib->id.lib, NULL, input_filename, sizeof(input_filename));
+	BKE_cache_archive_path_ex(output_filepath, cachelib->id.lib, NULL, output_filename, sizeof(output_filename));
+	
+	/* make sure we can write */
+	cache_library_bake_ensure_file_target(output_filename);
+	
+	input_archive = PTC_open_reader_archive(scene, input_filename);
+	if (!input_archive) {
+		BKE_reportf(op->reports, RPT_ERROR, "Cannot open cache file at '%s'", input_filepath);
+		return OPERATOR_CANCELLED;
+	}
+	
+	output_archive = PTC_open_writer_archive(scene, output_filename);
+	if (!output_archive) {
+		BKE_reportf(op->reports, RPT_ERROR, "Cannot write to cache file at '%s'", output_filepath);
+		return OPERATOR_CANCELLED;
+	}
+	
+	PTC_archive_slice(input_archive, output_archive, start_frame, end_frame);
+	
+	PTC_close_reader_archive(input_archive);
+	PTC_close_writer_archive(output_archive);
+	
+	return OPERATOR_FINISHED;
+}
+
+static int cache_library_archive_slice_invoke(bContext *C, wmOperator *op, const wmEvent *event)
+{
+	return WM_operator_props_popup_confirm(C, op, event);
+	
+#if 0
+	Object *ob = CTX_data_active_object(C);
+	CacheLibrary *cachelib = ob->cache_library;
+	
+	char output_filename[FILE_MAX];
+	
+	if (!cachelib)
+		return OPERATOR_CANCELLED;
+	
+	/* make sure we run a job when exec is called after confirm popup */
+	RNA_boolean_set(op->ptr, "use_job", true);
+	
+	RNA_string_get(op->ptr, "output_filepath", output_filepath);
+	if (output_filepath[0] == '\0')
+		return OPERATOR_CANCELLED;
+	BKE_cache_archive_output_path(cachelib, output_filename, sizeof(output_filename));
+	
+	if (!BKE_cache_archive_path_test(cachelib, output_filepath)) {
+		BKE_reportf(op->reports, RPT_ERROR, "Cannot create file path for cache library %200s", cachelib->id.name+2);
+		return OPERATOR_CANCELLED;
+	}
+	
+	if (BLI_exists(output_filename)) {
+		if (BLI_is_dir(output_filename)) {
+			BKE_reportf(op->reports, RPT_ERROR, "Cache Library target is a directory: %200s", output_filename);
+			return OPERATOR_CANCELLED;
+		}
+		else if (BLI_is_file(output_filename)) {
+			if (BLI_file_is_writable(output_filename)) {
+				return WM_operator_confirm_message(C, op, "Overwrite?");
+			}
+			else {
+				BKE_reportf(op->reports, RPT_ERROR, "Cannot overwrite Cache Library target: %200s", output_filename);
+				return OPERATOR_CANCELLED;
+			}
+			
+		}
+		else {
+			BKE_reportf(op->reports, RPT_ERROR, "Invalid Cache Library target: %200s", output_filename);
+			return OPERATOR_CANCELLED;
+		}
+	}
+	else {
+		return cache_library_bake_exec(C, op);
+	}
+#endif
+}
+
+void CACHELIBRARY_OT_archive_slice(wmOperatorType *ot)
+{
+	PropertyRNA *prop;
+	
+	/* identifiers */
+	ot->name = "Archive Slice";
+	ot->description = "Copy a range of frames to a new cache archive";
+	ot->idname = "CACHELIBRARY_OT_archive_slice";
+	
+	/* api callbacks */
+	ot->exec = cache_library_archive_slice_exec;
+	ot->invoke = cache_library_archive_slice_invoke;
+	ot->poll = ED_cache_library_active_object_poll;
+	
+	/* flags */
+	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+	
+	prop = RNA_def_boolean(ot->srna, "use_job", false, "Use Job", "Run operator as a job");
+	/* This is in internal property set by the invoke function.
+	 * It allows the exec function to be called from both the confirm popup
+	 * as well as a direct exec call for running a blocking operator in background mode.
+	 */
+	RNA_def_property_flag(prop, PROP_HIDDEN);
+	
+	prop = RNA_def_string(ot->srna, "input_filepath", NULL, FILE_MAX, "Input File Path", "Path to the source cache archive");
+	RNA_def_property_subtype(prop, PROP_FILEPATH);
+	prop = RNA_def_string(ot->srna, "output_filepath", NULL, FILE_MAX, "Output File Path", "Path to the target cache archive");
+	RNA_def_property_subtype(prop, PROP_FILEPATH);
+	RNA_def_int(ot->srna, "start_frame", 1, INT_MIN, INT_MAX, "Start Frame", "First frame to copy", 1, 10000);
+	RNA_def_int(ot->srna, "end_frame", 250, INT_MIN, INT_MAX, "End Frame", "Last frame to copy", 1, 10000);
+}
+
+/* ========================================================================= */
+
 #if 0
 static void ui_item_nlabel(uiLayout *layout, const char *s, size_t len)
 {
diff --git a/source/blender/editors/io/io_cache_library.h b/source/blender/editors/io/io_cache_library.h
index 6ad5548..78959e6 100644
--- a/source/blender/editors/io/io_cache_library.h
+++ b/source/blender/editors/io/io_cache_library.h
@@ -38,6 +38,7 @@ void CACHELIBRARY_OT_delete(struct wmOperatorType *ot);
 void CACHELIBRARY_OT_bake(struct wmOperatorType *ot);
 
 void CACHELIBRARY_OT_archive_info(struct wmOperatorType *ot);
+void CACHELIBRARY_OT_archive_slice(struct wmOperatorType *ot);
 
 /* ------------------------------------------------------------------------- */
 /* Cache Modifiers */
diff --git a/source/blender/editors/io/io_ops.c b/source/blender/editors/io/io_ops.c
index c67d6a3..49b1553 100644
--- a/source/blender/editors/io/io_ops.c
+++ b/source/blender/editors/io/io_ops.c
@@ -43,6 +43,7 @@ void ED_operatortypes_io(void)
 	WM_operatortype_append(CACHELIBRARY_OT_delete);
 	WM_operatortype_append(CACHELIBRARY_OT_bake);
 	WM_operatortype_append(CACHELIBRARY_OT_archive_info);
+	WM_operatortype_append(CACHELIBRARY_OT_archive_slice);
 
 	WM_operatortype_append(CACHELIBRARY_OT_add_modifier);
 	WM_operatortype_append(CACHELIBRARY_OT_remove_modifier);
diff --git a/source/blender/pointcache/PTC_api.cpp b/source/blender/pointcache/PTC_api.cpp
index 77f378f..69e3d21 100644
--- a/source/blender/pointcache/PTC_api.cpp
+++ b/source/blender/pointcache/PTC_api.cpp
@@ -247,6 +247,14 @@ void PTC_get_archive_info_nodes(PTCReaderArchive *_archive, struct CacheArchiveI
 	archive->get_info_nodes(info, calc_bytes_size);
 }
 
+void PTC_archive_slice(PTCReaderArchive *_in, PTCWriterArchive *_out, float start_frame, float end_frame)
+{
+	PTC::ReaderArchive *in = (PTC::ReaderArchive *)_in;
+	PTC::WriterArchive *out = (PTC::WriterArchive *)_out;
+	
+	PTC::Factory::alembic->slice(in, out, start_frame, end_frame);
+}
+
 
 PTCWriter *PTC_writer_dupligroup(const char *name, struct EvaluationContext *eval_ctx, struct Scene *scene, struct Group *group, struct CacheLibrary *cachelib)
 {
diff --git a/source/blender/pointcache/PTC_api.h b/source/blender/pointcache/PTC_api.h
index 4437015..6c531c9 100644
--- a/source/blender/pointcache/PTC_api.h
+++ b/source/blender/pointcache/PTC_api.h
@@ -84,6 +84,8 @@ PTCReadSampleResult PTC_test_sample(struct PTCReader *reader, float frame);
 void PTC_get_archive_info_stream(struct PTCReaderArchive *archive, void (*stream)(void *, const char *), void 

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list