[Bf-blender-cvs] [523ff63] alembic_pointcache: Correct time sampling for Blender frames: The cycle time is 1.0 by default, this needs to be 1/fps. The default frame sampling can be added by writers, Alembic will only create this sampling once internally.

Lukas Tönne noreply at git.blender.org
Thu Oct 16 16:53:11 CEST 2014


Commit: 523ff63a82478291ca58465bca5156dd63585fd8
Author: Lukas Tönne
Date:   Tue Nov 26 11:11:20 2013 +0100
Branches: alembic_pointcache
https://developer.blender.org/rB523ff63a82478291ca58465bca5156dd63585fd8

Correct time sampling for Blender frames: The cycle time is 1.0 by
default, this needs to be 1/fps. The default frame sampling can be added
by writers, Alembic will only create this sampling once internally.

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

M	source/blender/editors/physics/physics_pointcache.c
M	source/blender/pointcache/PTC_api.cpp
M	source/blender/pointcache/PTC_api.h
M	source/blender/pointcache/intern/particles.cpp
M	source/blender/pointcache/intern/particles.h
M	source/blender/pointcache/intern/writer.cpp
M	source/blender/pointcache/intern/writer.h

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

diff --git a/source/blender/editors/physics/physics_pointcache.c b/source/blender/editors/physics/physics_pointcache.c
index 3d807fb..7b10411 100644
--- a/source/blender/editors/physics/physics_pointcache.c
+++ b/source/blender/editors/physics/physics_pointcache.c
@@ -483,7 +483,7 @@ static int ptcache_export_exec(bContext *C, wmOperator *op)
 	PTCacheExportJob *data;
 	wmJob *wm_job;
 	
-	writer = PTC_writer_from_rna(&user_ptr);
+	writer = PTC_writer_from_rna(scene, &user_ptr);
 	if (!writer) {
 		BKE_reportf(op->reports, RPT_ERROR_INVALID_INPUT, "%s is not a valid point cache user type", RNA_struct_identifier(user_ptr.type));
 		return OPERATOR_CANCELLED;
diff --git a/source/blender/pointcache/PTC_api.cpp b/source/blender/pointcache/PTC_api.cpp
index a500876..2c8bcad 100644
--- a/source/blender/pointcache/PTC_api.cpp
+++ b/source/blender/pointcache/PTC_api.cpp
@@ -71,28 +71,28 @@ void PTC_read_sample(struct PTCReader *_reader)
 }
 
 /* get writer/reader from RNA type */
-PTCWriter *PTC_writer_from_rna(PointerRNA *ptr)
+PTCWriter *PTC_writer_from_rna(Scene *scene, PointerRNA *ptr)
 {
 	if (RNA_struct_is_a(ptr->type, &RNA_ParticleSystem)) {
 		Object *ob = (Object *)ptr->id.data;
 		ParticleSystem *psys = (ParticleSystem *)ptr->data;
-		return PTC_writer_particles(ob, psys);
+		return PTC_writer_particles(scene, ob, psys);
 	}
 	return NULL;
 }
 
-PTCReader *PTC_reader_from_rna(PointerRNA *ptr)
+PTCReader *PTC_reader_from_rna(Scene *scene, PointerRNA *ptr)
 {
 	if (RNA_struct_is_a(ptr->type, &RNA_ParticleSystem)) {
 		Object *ob = (Object *)ptr->id.data;
 		ParticleSystem *psys = (ParticleSystem *)ptr->data;
-		return PTC_reader_particles(ob, psys);
+		return PTC_reader_particles(scene, ob, psys);
 	}
 	return NULL;
 }
 
 /* Particles */
-PTCWriter *PTC_writer_particles(Object *ob, ParticleSystem *psys)
+PTCWriter *PTC_writer_particles(Scene *scene, Object *ob, ParticleSystem *psys)
 {
 	PointCache *cache = psys->pointcache;
 	if (!cache)
@@ -102,11 +102,11 @@ PTCWriter *PTC_writer_particles(Object *ob, ParticleSystem *psys)
 	                                        cache->flag & PTCACHE_EXTERNAL,
 	                                        cache->flag & PTCACHE_IGNORE_LIBPATH);
 	
-	PTC::ParticlesWriter *writer = new PTC::ParticlesWriter(filename, ob, psys);
+	PTC::ParticlesWriter *writer = new PTC::ParticlesWriter(filename, scene, ob, psys);
 	return (PTCWriter *)writer;
 }
 
-PTCReader *PTC_reader_particles(Object *ob, ParticleSystem *psys)
+PTCReader *PTC_reader_particles(Scene *scene, Object *ob, ParticleSystem *psys)
 {
 	PointCache *cache = psys->pointcache;
 	if (!cache)
@@ -116,7 +116,7 @@ PTCReader *PTC_reader_particles(Object *ob, ParticleSystem *psys)
 	                                        cache->flag & PTCACHE_EXTERNAL,
 	                                        cache->flag & PTCACHE_IGNORE_LIBPATH);
 
-	PTC::ParticlesReader *reader = new PTC::ParticlesReader(filename, ob, psys);
+	PTC::ParticlesReader *reader = new PTC::ParticlesReader(filename, scene, ob, psys);
 	return (PTCReader *)reader;
 }
 
diff --git a/source/blender/pointcache/PTC_api.h b/source/blender/pointcache/PTC_api.h
index 8b37eee..aefe865 100644
--- a/source/blender/pointcache/PTC_api.h
+++ b/source/blender/pointcache/PTC_api.h
@@ -46,12 +46,12 @@ void PTC_bake(struct Main *bmain, struct Scene *scene, struct PTCWriter *writer,
 
 
 /* get writer/reader from RNA type */
-struct PTCWriter *PTC_writer_from_rna(struct PointerRNA *ptr);
-struct PTCReader *PTC_reader_from_rna(struct PointerRNA *ptr);
+struct PTCWriter *PTC_writer_from_rna(struct Scene *scene, struct PointerRNA *ptr);
+struct PTCReader *PTC_reader_from_rna(struct Scene *scene, struct PointerRNA *ptr);
 
 /* Particles */
-struct PTCWriter *PTC_writer_particles(struct Object *ob, struct ParticleSystem *psys);
-struct PTCReader *PTC_reader_particles(struct Object *ob, struct ParticleSystem *psys);
+struct PTCWriter *PTC_writer_particles(struct Scene *scene, struct Object *ob, struct ParticleSystem *psys);
+struct PTCReader *PTC_reader_particles(struct Scene *scene, struct Object *ob, struct ParticleSystem *psys);
 
 #ifdef __cplusplus
 } /* extern C */
diff --git a/source/blender/pointcache/intern/particles.cpp b/source/blender/pointcache/intern/particles.cpp
index 38c2ebe..104fbec 100644
--- a/source/blender/pointcache/intern/particles.cpp
+++ b/source/blender/pointcache/intern/particles.cpp
@@ -230,13 +230,15 @@ void OParticlesSchema::init(uint32_t iTsIdx)
 #endif
 
 
-ParticlesWriter::ParticlesWriter(const std::string &filename, Object *ob, ParticleSystem *psys) :
+ParticlesWriter::ParticlesWriter(const std::string &filename, Scene *scene, Object *ob, ParticleSystem *psys) :
     Writer(filename),
     m_ob(ob),
     m_psys(psys)
 {
+	uint32_t fs = add_frame_sampling(scene);
+	
 	OObject root = m_archive.getTop();
-	m_points = OPoints(root, m_psys->name);
+	m_points = OPoints(root, m_psys->name, fs);
 }
 
 ParticlesWriter::~ParticlesWriter()
@@ -270,7 +272,7 @@ void ParticlesWriter::write_sample()
 }
 
 
-ParticlesReader::ParticlesReader(const std::string &filename, Object *ob, ParticleSystem *psys) :
+ParticlesReader::ParticlesReader(const std::string &filename, Scene *scene, Object *ob, ParticleSystem *psys) :
     Reader(filename),
     m_ob(ob),
     m_psys(psys)
diff --git a/source/blender/pointcache/intern/particles.h b/source/blender/pointcache/intern/particles.h
index a64995a..6328cad 100644
--- a/source/blender/pointcache/intern/particles.h
+++ b/source/blender/pointcache/intern/particles.h
@@ -478,7 +478,7 @@ typedef Util::shared_ptr< OParticles > OParticlesPtr;
 
 class ParticlesWriter : public Writer {
 public:
-	ParticlesWriter(const std::string &filename, Object *ob, ParticleSystem *psys);
+	ParticlesWriter(const std::string &filename, Scene *scene, Object *ob, ParticleSystem *psys);
 	~ParticlesWriter();
 	
 	void write_sample();
@@ -492,7 +492,7 @@ private:
 
 class ParticlesReader : public Reader {
 public:
-	ParticlesReader(const std::string &filename, Object *ob, ParticleSystem *psys);
+	ParticlesReader(const std::string &filename, Scene *scene, Object *ob, ParticleSystem *psys);
 	~ParticlesReader();
 	
 	void read_sample();
diff --git a/source/blender/pointcache/intern/writer.cpp b/source/blender/pointcache/intern/writer.cpp
index 4a3eff3..8dc9a5b 100644
--- a/source/blender/pointcache/intern/writer.cpp
+++ b/source/blender/pointcache/intern/writer.cpp
@@ -23,6 +23,8 @@
 extern "C" {
 #include "BLI_fileops.h"
 #include "BLI_path_util.h"
+
+#include "DNA_scene_types.h"
 }
 
 namespace PTC {
@@ -47,4 +49,18 @@ Writer::~Writer()
 {
 }
 
+uint32_t Writer::add_frame_sampling(Scene *scene)
+{
+	if (scene->r.frs_sec == 0.0f) {
+		/* Should never happen, just to be safe
+		 * Index 0 is the default time sampling with a step of 1.0
+		 */
+		return 0;
+	}
+	
+	chrono_t cycle_time = (double)scene->r.frs_sec_base / (double)scene->r.frs_sec;
+	chrono_t start_time = 0.0f;
+	return m_archive.addTimeSampling(TimeSampling(cycle_time, start_time));
+}
+
 } /* namespace PTC */
diff --git a/source/blender/pointcache/intern/writer.h b/source/blender/pointcache/intern/writer.h
index 8157e65..b0e39e1 100644
--- a/source/blender/pointcache/intern/writer.h
+++ b/source/blender/pointcache/intern/writer.h
@@ -23,6 +23,8 @@
 
 #include <Alembic/Abc/OArchive.h>
 
+struct Scene;
+
 namespace PTC {
 
 using namespace Alembic;
@@ -32,6 +34,8 @@ public:
 	Writer(const std::string &filename);
 	virtual ~Writer();
 	
+	uint32_t add_frame_sampling(Scene *scene);
+	
 	virtual void write_sample() = 0;
 	
 protected:




More information about the Bf-blender-cvs mailing list