Combined storage of render and realtime data in caches.

Caches now create 2 new roots below the main 'top' object of Alembic:
root and root_render for realtime and render data respectively.
This makes it easy to switch the whole archive to either of the modes
during baking and for constructing dupli caches.

Alternatively individual objects could store hires versions of their
data. This would also be more efficient if the cache contains many
simple objects which don't have 2 different variants. However, such
design decisions are difficult to make at this point and the
implementation can be modifier later.
This commit is contained in:
2015-03-19 20:58:21 +01:00
parent 168867f3b0
commit 88718c7252
11 changed files with 93 additions and 36 deletions

View File

@@ -305,11 +305,13 @@ static void cache_library_bake_startjob(void *customdata, short *stop, short *do
if (data->cachelib->eval_mode & CACHE_LIBRARY_EVAL_REALTIME) {
data->eval_ctx.mode = DAG_EVAL_VIEWPORT;
PTC_writer_archive_use_render(data->archive, false);
cache_library_bake_do(data, stop, do_update, progress);
}
if (data->cachelib->eval_mode & CACHE_LIBRARY_EVAL_RENDER) {
data->eval_ctx.mode = DAG_EVAL_RENDER;
PTC_writer_archive_use_render(data->archive, true);
cache_library_bake_do(data, stop, do_update, progress);
}

View File

@@ -106,6 +106,12 @@ void PTC_close_writer_archive(PTCWriterArchive *_archive)
delete archive;
}
void PTC_writer_archive_use_render(PTCWriterArchive *_archive, bool enable)
{
PTC::WriterArchive *archive = (PTC::WriterArchive *)_archive;
archive->use_render(enable);
}
PTCReaderArchive *PTC_open_reader_archive(Scene *scene, const char *path)
{
return (PTCReaderArchive *)PTC::Factory::alembic->open_reader_archive(scene, path, NULL);
@@ -117,6 +123,12 @@ void PTC_close_reader_archive(PTCReaderArchive *_archive)
delete archive;
}
void PTC_reader_archive_use_render(PTCReaderArchive *_archive, bool enable)
{
PTC::ReaderArchive *archive = (PTC::ReaderArchive *)_archive;
archive->use_render(enable);
}
void PTC_writer_init(PTCWriter *_writer, PTCWriterArchive *_archive)
{
PTC::Writer *writer = (PTC::Writer *)_writer;

View File

@@ -65,9 +65,11 @@ const char *PTC_get_default_archive_extension(void);
struct PTCWriterArchive *PTC_open_writer_archive(struct Scene *scene, const char *path);
void PTC_close_writer_archive(struct PTCWriterArchive *archive);
void PTC_writer_archive_use_render(struct PTCWriterArchive *archive, bool enable);
struct PTCReaderArchive *PTC_open_reader_archive(struct Scene *scene, const char *path);
void PTC_close_reader_archive(struct PTCReaderArchive *archive);
void PTC_reader_archive_use_render(struct PTCReaderArchive *archive, bool enable);
void PTC_writer_init(struct PTCWriter *writer, struct PTCWriterArchive *archive);
void PTC_writer_create_refs(struct PTCWriter *writer);

View File

@@ -73,7 +73,7 @@ void AbcGroupWriter::create_refs()
void AbcGroupWriter::write_sample()
{
if (!abc_archive()->archive)
if (!m_abc_object)
return;
}
@@ -284,7 +284,7 @@ PTCReadSampleResult AbcDupligroupReader::read_sample(float frame)
{
ISampleSelector ss = abc_archive()->get_frame_sample_selector(frame);
IObject abc_top = abc_archive()->archive.getTop();
IObject abc_top = abc_archive()->root();
IObject abc_group = abc_archive()->get_id_object((ID *)m_group);
if (!abc_group)
return PTC_READ_SAMPLE_INVALID;

View File

@@ -53,7 +53,7 @@ void AbcParticlesWriter::init_abc(OObject parent)
void AbcParticlesWriter::write_sample()
{
if (!abc_archive()->archive)
if (!m_points)
return;
OPointsSchema &schema = m_points.getSchema();

View File

@@ -51,38 +51,49 @@ AbcReaderArchive *AbcReaderArchive::open(Scene *scene, const std::string &filena
AbcReaderArchive::AbcReaderArchive(Scene *scene, ErrorHandler *error_handler, IArchive abc_archive) :
FrameMapper(scene),
archive(abc_archive),
m_error_handler(error_handler)
m_error_handler(error_handler),
m_use_render(false),
m_abc_archive(abc_archive)
{
m_abc_root = IObject(m_abc_archive.getTop(), "root");
m_abc_root_render = IObject(m_abc_archive.getTop(), "root_render");
}
AbcReaderArchive::~AbcReaderArchive()
{
}
Abc::IObject AbcReaderArchive::root()
{
if (m_use_render)
return m_abc_root_render;
else
return m_abc_root;
}
IObject AbcReaderArchive::get_id_object(ID *id)
{
if (!archive)
if (!m_abc_archive)
return IObject();
IObject root = archive.getTop();
IObject root = this->root();
return root.getChild(id->name);
}
bool AbcReaderArchive::has_id_object(ID *id)
{
if (!archive)
if (!m_abc_archive)
return false;
IObject root = archive.getTop();
IObject root = this->root();
return root.getChild(id->name).valid();
}
bool AbcReaderArchive::get_frame_range(int &start_frame, int &end_frame)
{
if (archive) {
if (m_abc_archive) {
double start_time, end_time;
GetArchiveStartAndEndTime(archive, start_time, end_time);
GetArchiveStartAndEndTime(m_abc_archive, start_time, end_time);
start_frame = (int)time_to_frame(start_time);
end_frame = (int)time_to_frame(end_time);
return true;
@@ -95,8 +106,8 @@ bool AbcReaderArchive::get_frame_range(int &start_frame, int &end_frame)
std::string AbcReaderArchive::get_info()
{
if (archive)
return abc_archive_info(archive);
if (m_abc_archive)
return abc_archive_info(m_abc_archive);
else
return "";
}

View File

@@ -44,6 +44,10 @@ public:
static AbcReaderArchive *open(Scene *scene, const std::string &filename, ErrorHandler *error_handler);
void use_render(bool enable) { m_use_render = enable; }
Abc::IObject root();
Abc::IObject get_id_object(ID *id);
bool has_id_object(ID *id);
@@ -52,13 +56,16 @@ public:
std::string get_info();
Abc::IArchive archive;
protected:
AbcReaderArchive(Scene *scene, ErrorHandler *error_handler, Abc::IArchive abc_archive);
protected:
ErrorHandler *m_error_handler;
bool m_use_render;
Abc::IArchive m_abc_archive;
Abc::IObject m_abc_root;
Abc::IObject m_abc_root_render;
};
class AbcReader : public Reader {

View File

@@ -61,13 +61,17 @@ AbcWriterArchive *AbcWriterArchive::open(Scene *scene, const std::string &filena
AbcWriterArchive::AbcWriterArchive(Scene *scene, ErrorHandler *error_handler, OArchive abc_archive) :
FrameMapper(scene),
archive(abc_archive),
m_error_handler(error_handler)
m_error_handler(error_handler),
m_use_render(false),
m_abc_archive(abc_archive)
{
if (archive) {
if (m_abc_archive) {
chrono_t cycle_time = this->seconds_per_frame();
chrono_t start_time = this->start_time();
m_frame_sampling = archive.addTimeSampling(TimeSampling(cycle_time, start_time));
m_frame_sampling = m_abc_archive.addTimeSampling(TimeSampling(cycle_time, start_time));
m_abc_root = OObject(m_abc_archive.getTop(), "root");
m_abc_root_render = OObject(m_abc_archive.getTop(), "root_render");
}
}
@@ -77,37 +81,45 @@ AbcWriterArchive::~AbcWriterArchive()
OObject AbcWriterArchive::get_id_object(ID *id)
{
if (!archive)
if (!m_abc_archive)
return OObject();
ObjectWriterPtr root = archive.getTop().getPtr();
ObjectWriterPtr root_ptr = root().getPtr();
ObjectWriterPtr child = root->getChild(id->name);
ObjectWriterPtr child = root_ptr->getChild(id->name);
if (child)
return OObject(child, kWrapExisting);
else {
const ObjectHeader *child_header = root->getChildHeader(id->name);
const ObjectHeader *child_header = root_ptr->getChildHeader(id->name);
if (child_header)
return OObject(root->createChild(*child_header), kWrapExisting);
return OObject(root_ptr->createChild(*child_header), kWrapExisting);
else {
return OObject();
}
}
}
OObject AbcWriterArchive::root()
{
if (m_use_render)
return m_abc_root_render;
else
return m_abc_root;
}
bool AbcWriterArchive::has_id_object(ID *id)
{
if (!archive)
if (!m_abc_archive)
return false;
ObjectWriterPtr root = archive.getTop().getPtr();
ObjectWriterPtr root_ptr = root().getPtr();
return root->getChildHeader(id->name) != NULL;
return root_ptr->getChildHeader(id->name) != NULL;
}
TimeSamplingPtr AbcWriterArchive::frame_sampling()
{
return archive.getTimeSampling(m_frame_sampling);
return m_abc_archive.getTimeSampling(m_frame_sampling);
}
} /* namespace PTC */

View File

@@ -48,6 +48,10 @@ public:
static AbcWriterArchive *open(Scene *scene, const std::string &filename, ErrorHandler *error_handler);
void use_render(bool enable) { m_use_render = enable; }
Abc::OObject root();
Abc::OObject get_id_object(ID *id);
bool has_id_object(ID *id);
@@ -57,14 +61,17 @@ public:
uint32_t frame_sampling_index() const { return m_frame_sampling; }
Abc::TimeSamplingPtr frame_sampling();
Abc::OArchive archive;
protected:
AbcWriterArchive(Scene *scene, ErrorHandler *error_handler, Abc::OArchive abc_archive);
protected:
ErrorHandler *m_error_handler;
uint32_t m_frame_sampling;
bool m_use_render;
Abc::OArchive m_abc_archive;
Abc::OObject m_abc_root;
Abc::OObject m_abc_root_render;
};
class AbcWriter : public Writer {
@@ -95,20 +102,20 @@ OObjectT AbcWriterArchive::add_id_object(ID *id)
{
using namespace Abc;
if (!archive)
if (!m_abc_archive)
return OObjectT();
ObjectWriterPtr root = archive.getTop().getPtr();
ObjectWriterPtr root_ptr = this->root().getPtr();
ObjectWriterPtr child = root->getChild(id->name);
ObjectWriterPtr child = root_ptr->getChild(id->name);
if (child)
return OObjectT(child, kWrapExisting);
else {
const ObjectHeader *child_header = root->getChildHeader(id->name);
const ObjectHeader *child_header = root_ptr->getChildHeader(id->name);
if (child_header)
return OObjectT(root->createChild(*child_header), kWrapExisting);
return OObjectT(root_ptr->createChild(*child_header), kWrapExisting);
else {
return OObjectT(root, id->name, frame_sampling_index());
return OObjectT(root_ptr, id->name, frame_sampling_index());
}
}
}

View File

@@ -33,6 +33,8 @@ class ReaderArchive {
public:
virtual ~ReaderArchive() {}
virtual void use_render(bool enable) = 0;
virtual bool get_frame_range(int &start_frame, int &end_frame) = 0;
virtual std::string get_info() = 0;
};

View File

@@ -30,6 +30,8 @@ namespace PTC {
class WriterArchive {
public:
virtual ~WriterArchive() {}
virtual void use_render(bool enable) = 0;
};
class Writer {