perfume-dev / ofxAlembic

MIT License
59 stars 34 forks source link

save xform data #2

Open ofZach opened 10 years ago

ofZach commented 10 years ago

Is there an easy way to add xform data to to the ofxAlembicWriter? Looked into adding this but I am afraid I didn't totally understand how the writer is setup so it was hard to add myself.

ofZach commented 10 years ago

if it's helpful to anyone, here's some code to save an xform ripped from a test case -- there's obviously alot more complicated stuff you can do:

std::string name = "someOpsXform.abc";
OArchive archive( Alembic::AbcCoreHDF5::WriteArchive(), name );
TimeSampling Ts(1.0 / 24.0, 0);
Alembic::Util::uint32_t tsidx = archive.addTimeSampling(Ts);
OXform a( OObject( archive, kTop ), "a");
a.getSchema().setTimeSampling(tsidx);
XformSample samp;
for (size_t i = 1; i < 180 ; ++i){
    XformOp transop( kTranslateOperation, kTranslateHint );
    XformOp rotatop( kRotateOperation, kRotateHint );
    XformOp scaleop( kScaleOperation, kScaleHint );
    samp.addOp( transop, V3d(i * 5, 0.0, 0.0) );
    samp.addOp( rotatop, V3d(0.0, 0.0, 1.0), 0.0 );
    samp.addOp( rotatop, V3d(0.0, 1.0, 0.0), 0.0 );
    samp.addOp( rotatop, V3d(1.0, 0.0, 0.0), i );
    samp.addOp( scaleop, V3d(1.0, 1.0, 1.0) );
    a.getSchema().set(samp);
}

I think being able to throw ofxMatrix4x4s at ofxAlembic would be great, but this solves my immediate need of saving nulls with translation and orientation.

satoruhiga commented 10 years ago

Hi zach,

I just added xform export. https://github.com/perfume-dev/ofxAlembic/commit/7acdc57e0e957e4f5a8606f2624fec5a68c14bbd

but it do not well tested. if you find some bugs, please let me know