writing animated alembic files from python

1,623 views
Skip to first unread message

Kevin Campbell

unread,
Jul 20, 2014, 10:42:09 PM7/20/14
to alembic-d...@googlegroups.com

Hi,
In alembic 1.5.0 on linux, i was expecting the following code to write out
an animated alembic file:


'''
#!/bin/env python

import alembic.Abc as Abc
import alembic.AbcGeom as AbcGeom
import imath
import cask

abc = cask.Archive()
xf = abc.top.children["renderCamXform"] = cask.Xform()
cam = xf.children["renderCamShape"] = cask.Camera()

for i in range(24):
samp = AbcGeom.XformSample()
samp.setTranslation(imath.V3d(i, 2.0, 3.0))
xf.set_sample(samp)

abc.write_to_file("test.abc")

'''

When i try and load this into maya, my camera isn't animated.
Inspecting the alembic file with abcview, i see all the samples
but i am missing a '1.samples' property at the top of the hierarchy.

Can someone point me in the right direction or provide an example please?

Thanks
kevin

--
kevin campbell
director of production technology | kevin.c...@rsp.com.au
rising sun pictures | www.rsp.com.au
phone +61 8 8400 6456 | mobile +61 432 483 166

Ryan Galloway

unread,
Jul 21, 2014, 1:58:48 PM7/21/14
to alembic-d...@googlegroups.com

Hi Kevin,

Thanks for the report. The 1.samples property is not the problem, that's a Maya export- only thing and is not required.

I think this is not working as-is because the camera is invalid because it doesn't have any sample data. Valid objects usually require at least one sample. I was able to fix this by simply adding some samples to the camera, i.e.

for i in range(24):
    samp = AbcGeom.XformSample()
    samp.setTranslation(imath.V3d(i, 2.0, 3.0))
    xf.set_sample(samp)
    samp = AbcGeom.CameraSample()
    cam.set_sample(samp)

When I export that it loads into Maya fine for me.

Ryan


--
You received this message because you are subscribed to the Google Groups "alembic-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to alembic-discuss...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ryan Galloway

unread,
Jul 21, 2014, 2:24:36 PM7/21/14
to alembic-d...@googlegroups.com

I should also point out that I was using the latest version of cask in Alembic 1.5.5, which has a few bug fixes. 

Kevin Campbell

unread,
Jul 21, 2014, 7:18:24 PM7/21/14
to alembic-d...@googlegroups.com


----- Original Message -----
>
>
>
> Hi Kevin,
>
>
> Thanks for the report. The 1.samples property is not the problem,
> that's a Maya export- only thing and is not required.
>
>
> I think this is not working as-is because the camera is invalid
> because it doesn't have any sample data. Valid objects usually
> require at least one sample. I was able to fix this by simply adding
> some samples to the camera, i.e.
>
>
>
> for i in range(24):
> samp = AbcGeom.XformSample()
> samp.setTranslation(imath.V3d(i, 2.0, 3.0))
> xf.set_sample(samp)
> samp = AbcGeom.CameraSample()
> cam.set_sample(samp)
>
>
> When I export that it loads into Maya fine for me.
>
>

Hi Ryan,

Thanks for that, it works for me now.
The 1.samples property had me looking in the wrong direction entirely.

I'd noted the updates in alembic 1.5.5, but i prefer to keep the alembic versions
consistent across maya, nuke, houdini, and python (standalone), and so i'm
keen to stay on the 1.5.0 release that is used in nuke (i can recompile
all the other plugins myself).

Thanks again.

Ryan Galloway

unread,
Jul 21, 2014, 7:36:13 PM7/21/14
to alembic-d...@googlegroups.com

No problem. There's some question about whether cask should automatically create the 0th sample for objects on export if none exist.

The cask.Xform class also has a set_scale method. Not sure why the set_translate and set_rotate methods haven't been implemented yet, but those could easily be added. In that case, your code could be reduced to

for i in range(24):
    xf.set_translate(i, 2, 3)

This is convenient, but the trade-off is that it creates and sets the samples for you as atomic operations. But using matrix transformations is probably preferable anyway (also not implemented yet):

    xf.set_matrix(imath.M44d(...))

Ryan



Kevin Campbell

unread,
Jul 21, 2014, 8:03:01 PM7/21/14
to alembic-d...@googlegroups.com


----- Original Message -----
>
>
>
> No problem. There's some question about whether cask should
> automatically create the 0th sample for objects on export if none
> exist.
>
>
> The cask.Xform class also has a set_scale method. Not sure why the
> set_translate and set_rotate methods haven't been implemented yet,
> but those could easily be added. In that case, your code could be
> reduced to
>
>
>
> for i in range(24):
> xf.set_translate(i, 2, 3)
>
>
> This is convenient, but the trade-off is that it creates and sets the
> samples for you as atomic operations. But using matrix
> transformations is probably preferable anyway (also not implemented
> yet):
>
>
> xf.set_matrix(imath.M44d(...))
>
>
> Ryan
>

Hi,
This is just the simplest example that fails, so i will need more than just the
translations in practice.

The samples are being interpreted as one per second (ie on frames 24, 48, etc in maya).
Do you have a code sample for setting values once per frame
and/or on subframes. Its probably not needed for cameras, but we commonly export
geo with subframe sampling.

thanks

Ryan Galloway

unread,
Jul 21, 2014, 8:27:40 PM7/21/14
to alembic-d...@googlegroups.com

Try using the latest version of cask from Alembic 1.5.5, it should address the time sampling issue you're referring to.

Ryan


Kevin Campbell

unread,
Jul 21, 2014, 11:55:09 PM7/21/14
to alembic-d...@googlegroups.com


----- Original Message -----
>
>
>
>
> Try using the latest version of cask from Alembic 1.5.5, it should
> address the time sampling issue you're referring to.
>
>
>
> Ryan
>
>

Hi,

i saw the discussion about re-writing existing caches, and my case is a little different.

'''
#!/bin/env python

import alembic.AbcCoreAbstract as AbcCoreAbstract
import alembic.Abc as Abc
import alembic.AbcGeom as AbcGeom
import imath
import cask

abc = cask.Archive()

xf = abc.top.children["renderCamXform"] = cask.Xform()
cam = xf.children["renderCamShape"] = cask.Camera()

for i in range(240):
samp = AbcGeom.XformSample()
samp.setTranslation(imath.V3d(i, 2.0, 3.0))
xf.set_sample(samp)

samp = AbcGeom.CameraSample()
cam.set_sample(samp)

abc.write_to_file('test.abc', asOgawa=False)
'''

The asOgawa=False flag ensures i am using the 1.5.5 cask.

With this code, my alembic file is one sample per second.
Ie on frame 48 in maya, renderCamXform.tx == 2.0

Ryan Galloway

unread,
Jul 23, 2014, 2:06:57 PM7/23/14
to alembic-d...@googlegroups.com

I think I have a fix for this, but I'm out of the office today. I'll post it to my development clone tomorrow or the next day.

Ryan


Ryan Galloway

unread,
Jul 24, 2014, 5:43:23 PM7/24/14
to alembic-d...@googlegroups.com

FYI I'm tracking this as issue #349. I'll post any updates here:



Kevin Campbell

unread,
Jul 24, 2014, 7:31:37 PM7/24/14
to alembic-d...@googlegroups.com


----- Original Message -----
>
>
>
>
> FYI I'm tracking this as issue #349. I'll post any updates here:
>
> http://code.google.com/p/alembic/issues/detail?id=349
>
>
>
>
>
>

thank you
Reply all
Reply to author
Forward
0 new messages