[Bf-blender-cvs] [72f6853] alembic_basic_io: Add option to setup scene's frame range based on that of the imported archive.

Kévin Dietrich noreply at git.blender.org
Tue Jun 7 10:59:22 CEST 2016


Commit: 72f685386569dfa630c599fd7c48398a0438123a
Author: Kévin Dietrich
Date:   Tue Jun 7 10:06:22 2016 +0200
Branches: alembic_basic_io
https://developer.blender.org/rB72f685386569dfa630c599fd7c48398a0438123a

Add option to setup scene's frame range based on that of the imported
archive.

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

M	source/blender/alembic/ABC_alembic.h
M	source/blender/alembic/intern/abc_camera.cc
M	source/blender/alembic/intern/abc_hair.cc
M	source/blender/alembic/intern/abc_mesh.cc
M	source/blender/alembic/intern/abc_nurbs.cc
M	source/blender/alembic/intern/abc_object.cc
M	source/blender/alembic/intern/abc_object.h
M	source/blender/alembic/intern/abc_points.cc
M	source/blender/alembic/intern/abc_transform.cc
M	source/blender/alembic/intern/abc_util.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 70fa85f..819e487 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);
+void ABC_import(struct bContext *C, const char *filepath, float scale, bool is_sequence, bool set_frame_range);
 
 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_camera.cc b/source/blender/alembic/intern/abc_camera.cc
index df0273b..2b627b2 100644
--- a/source/blender/alembic/intern/abc_camera.cc
+++ b/source/blender/alembic/intern/abc_camera.cc
@@ -116,6 +116,8 @@ AbcCameraReader::AbcCameraReader(const Alembic::Abc::IObject &object, ImportSett
 {
 	ICamera abc_cam(m_iobject, kWrapExisting);
 	m_schema = abc_cam.getSchema();
+
+	get_min_max_time(m_schema, m_min_time, m_max_time);
 }
 
 bool AbcCameraReader::valid() const
diff --git a/source/blender/alembic/intern/abc_hair.cc b/source/blender/alembic/intern/abc_hair.cc
index 6cca00d..9ea344e 100644
--- a/source/blender/alembic/intern/abc_hair.cc
+++ b/source/blender/alembic/intern/abc_hair.cc
@@ -304,6 +304,8 @@ AbcHairReader::AbcHairReader(const Alembic::Abc::IObject &object, ImportSettings
 {
 	ICurves abc_curves(object, kWrapExisting);
 	m_curves_schema = abc_curves.getSchema();
+
+	get_min_max_time(m_curves_schema, m_min_time, m_max_time);
 }
 
 bool AbcHairReader::valid() const
diff --git a/source/blender/alembic/intern/abc_mesh.cc b/source/blender/alembic/intern/abc_mesh.cc
index 4ef0c07..bff4345 100644
--- a/source/blender/alembic/intern/abc_mesh.cc
+++ b/source/blender/alembic/intern/abc_mesh.cc
@@ -1074,6 +1074,8 @@ AbcMeshReader::AbcMeshReader(const IObject &object, ImportSettings &settings, bo
 		IPolyMesh ipoly_mesh(m_iobject, kWrapExisting);
 		m_schema = ipoly_mesh.getSchema();
 	}
+
+	get_min_max_time(m_schema, m_min_time, m_max_time);
 }
 
 bool AbcMeshReader::valid() const
diff --git a/source/blender/alembic/intern/abc_nurbs.cc b/source/blender/alembic/intern/abc_nurbs.cc
index fdf374d..c55e5aa 100644
--- a/source/blender/alembic/intern/abc_nurbs.cc
+++ b/source/blender/alembic/intern/abc_nurbs.cc
@@ -210,6 +210,7 @@ AbcNurbsReader::AbcNurbsReader(const IObject &object, ImportSettings &settings)
     : AbcObjectReader(object, settings)
 {
 	getNurbsPatches(m_iobject);
+	get_min_max_time(m_schemas[0].first, m_min_time, m_max_time);
 }
 
 bool AbcNurbsReader::valid() const
diff --git a/source/blender/alembic/intern/abc_object.cc b/source/blender/alembic/intern/abc_object.cc
index f6508db..12c2452 100644
--- a/source/blender/alembic/intern/abc_object.cc
+++ b/source/blender/alembic/intern/abc_object.cc
@@ -347,6 +347,8 @@ AbcObjectReader::AbcObjectReader(const IObject &object, ImportSettings &settings
     , m_object(NULL)
     , m_iobject(object)
     , m_settings(&settings)
+    , m_min_time(std::numeric_limits<chrono_t>::max())
+    , m_max_time(std::numeric_limits<chrono_t>::min())
 {
 	m_name = object.getFullName();
 	std::vector<std::string> parts;
@@ -420,3 +422,13 @@ void AbcObjectReader::addDefaultModifier(Main *bmain) const
 	DAG_id_tag_update(&m_object->id, OB_RECALC_DATA);
 	DAG_relations_tag_update(bmain);
 }
+
+chrono_t AbcObjectReader::minTime() const
+{
+	return m_min_time;
+}
+
+chrono_t AbcObjectReader::maxTime() const
+{
+	return m_max_time;
+}
diff --git a/source/blender/alembic/intern/abc_object.h b/source/blender/alembic/intern/abc_object.h
index db45334..c050286 100644
--- a/source/blender/alembic/intern/abc_object.h
+++ b/source/blender/alembic/intern/abc_object.h
@@ -94,10 +94,13 @@ struct ImportSettings {
 	int from_forward;
 	float scale;
 	bool is_sequence;
+	bool set_frame_range;
 };
 
 /* ************************************************************************** */
 
+using Alembic::AbcCoreAbstract::chrono_t;
+
 class AbcObjectReader {
 protected:
 	std::string m_name;
@@ -108,6 +111,9 @@ protected:
 
 	ImportSettings *m_settings;
 
+	chrono_t m_min_time;
+	chrono_t m_max_time;
+
 public:
 	explicit AbcObjectReader(const Alembic::Abc::IObject &object, ImportSettings &settings);
 
@@ -124,4 +130,7 @@ public:
 	void readObjectMatrix(const float time);
 
 	void addDefaultModifier(Main *bmain) const;
+
+	chrono_t minTime() const;
+	chrono_t maxTime() const;
 };
diff --git a/source/blender/alembic/intern/abc_points.cc b/source/blender/alembic/intern/abc_points.cc
index ef66140..184ce86 100644
--- a/source/blender/alembic/intern/abc_points.cc
+++ b/source/blender/alembic/intern/abc_points.cc
@@ -28,6 +28,7 @@
 
 #include "abc_mesh.h"
 #include "abc_transform.h"
+#include "abc_util.h"
 
 extern "C" {
 #include "DNA_mesh_types.h"
@@ -139,6 +140,7 @@ AbcPointsReader::AbcPointsReader(const Alembic::Abc::IObject &object, ImportSett
 {
 	IPoints ipoints(m_iobject, kWrapExisting);
 	m_schema = ipoints.getSchema();
+	get_min_max_time(m_schema, m_min_time, m_max_time);
 }
 
 bool AbcPointsReader::valid() const
diff --git a/source/blender/alembic/intern/abc_transform.cc b/source/blender/alembic/intern/abc_transform.cc
index 4c07abf..a69c4fa 100644
--- a/source/blender/alembic/intern/abc_transform.cc
+++ b/source/blender/alembic/intern/abc_transform.cc
@@ -116,7 +116,9 @@ bool AbcTransformWriter::hasAnimation(Object */*ob*/) const
 
 AbcEmptyReader::AbcEmptyReader(const Alembic::Abc::IObject &object, ImportSettings &settings)
     : AbcObjectReader(object, settings)
-{}
+{
+	get_min_max_time(m_schema, m_min_time, m_max_time);
+}
 
 bool AbcEmptyReader::valid() const
 {
diff --git a/source/blender/alembic/intern/abc_util.h b/source/blender/alembic/intern/abc_util.h
index 368035a..219e190 100644
--- a/source/blender/alembic/intern/abc_util.h
+++ b/source/blender/alembic/intern/abc_util.h
@@ -53,3 +53,25 @@ bool is_locator(const Alembic::AbcGeom::IObject &object);
 void create_input_transform(const Alembic::AbcGeom::ISampleSelector &sample_sel,
                             const Alembic::AbcGeom::IXform &ixform, Object *ob,
                             float r_mat[4][4]);
+
+using Alembic::Abc::chrono_t;
+
+template <typename Schema>
+void get_min_max_time(const Schema &schema, chrono_t &min, chrono_t &max)
+{
+	using Alembic::Abc::TimeSamplingPtr;
+
+	TimeSamplingPtr time_samp = schema.getTimeSampling();
+
+    if (!schema.isConstant()) {
+        const size_t num_samps = schema.getNumSamples();
+
+        if (num_samps > 0) {
+            const chrono_t min_time = time_samp->getSampleTime(0);
+            min = std::min(min, min_time);
+
+            const chrono_t max_time = time_samp->getSampleTime(num_samps - 1);
+            max = std::max(max, max_time);
+        }
+    }
+}
diff --git a/source/blender/alembic/intern/alembic_capi.cc b/source/blender/alembic/intern/alembic_capi.cc
index 8fa1f26..3f33eef 100644
--- a/source/blender/alembic/intern/alembic_capi.cc
+++ b/source/blender/alembic/intern/alembic_capi.cc
@@ -473,19 +473,31 @@ static void import_startjob(void *cjv, short *stop, short *do_update, float *pro
 	const float size = static_cast<float>(readers.size());
 	size_t i = 0;
 
-	std::vector<AbcObjectReader *>::iterator iter;
+	Scene *scene = data->scene;
+
+	chrono_t min_time = std::numeric_limits<chrono_t>::max();
+	chrono_t max_time = std::numeric_limits<chrono_t>::min();
 
+	std::vector<AbcObjectReader *>::iterator iter;
 	for (iter = readers.begin(); iter != readers.end(); ++iter) {
 		AbcObjectReader *reader = *iter;
 
 		if (reader->valid()) {
-			reader->readObjectData(data->bmain, data->scene, 0.0f);
+			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());
 		}
 
 		*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;
+	}
+
 	i = 0;
 	for (iter = readers.begin(); iter != readers.end(); ++iter) {
 		const AbcObjectReader *reader = *iter;
@@ -527,10 +539,10 @@ static void import_startjob(void *cjv, short *stop, short *do_update, float *pro
 
 	BLI_ghash_free(parent_map, NULL, NULL);
 
-	WM_main_add_notifier(NC_SCENE | ND_FRAME, data->scene);
+	WM_main_add_notifier(NC_SCENE | ND_FRAME, scene);
 }
 
-void ABC_import(bContext *C, const char *filepath, float scale, bool is_sequence)
+void ABC_import(bContext *C, const char *filepath, float scale, bool is_sequence, bool set_frame_range)
 {
 	ImportJobData *job = static_cast<ImportJobData *>(MEM_mallocN(sizeof(ImportJobData), "ImportJobData"));
 	job->bmain = CTX_data_main(C);
@@ -539,6 +551,7 @@ 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;
 
 	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 f9d544e..4ad85f5 100644
--- a/source/blender/editors/io/io_alembic.c
+++ b/source/blender/editors/io/io_alembic.c
@@ -305,6 +305,9 @@ static void ui_alembic_import_settings(uiLayout *layout, PointerRNA *imfptr)
 	uiItemL(row, IFACE_("Options:"), ICON_NONE);
 
 	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);
 }
 
@@ -328,8 +331,9 @@ static int wm_alembic_import_exec(bContext *C, wmOperator *op)
 
 	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);
+	ABC_import(C, filename, scale, is_sequence, set_frame_range);
 
 	

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list