Writing ABC with a simple polymesh (python)

180 views
Skip to first unread message

lui...@gmail.com

unread,
Nov 8, 2022, 3:15:35 PM11/8/22
to alembic-discussion
Hi all,

I am trying to read/write abc files from a python script. In my case the ABC files are simple, and only contain one animated mesh. I managed to write the code to read the files using cask (getting a list of faces and list of arrays of vertex positions - see below), but I am struggling to write the code to write information to an abc file - are there any examples on how to do so? (it doesn't need to be in cask) From what I understand so far, I'd need to create a polymesh, with a schema containing the face indices, and a sequence of samples containing vertex positions.

I am trying to create the hierarchy I see in the files I am reading, but I get stuck on how to define the faces and the samples:

a = cask.Archive()
a.top.children['xform'] = cask.Xform()
polymesh = a.top.children['xform'].children['polymesh'] = cask.PolyMesh()
polymesh.schema = alembic.AbcGeom.OPolyMeshSchema()
# how to specify the face indices?

If it helps, here is my code to read the ABC file:

a = cask.Archive(fname)   # cask.Archive
root = a.top  # cast.Top
xform = root.children[xform_name]  #cask.Xform
polymesh = xform.children[polymesh_name]  #cask.PolyMesh

# This is how I extract the information of the faces (later I parse these to a list of vertex idx)
schema = polymesh.schema.getValue()
face_indices = np.array(schema.getFaceIndices())
n_vertex_per_face = np.array(schema.getFaceCounts())

# This is how I extract the vertex positions over time (btw this is very slow, not sure if I'm using it right)
points = []
for item in polymesh.samples:
    points.append(np.array(item.getPositions()))

Thanks in advance for any help on this!

Luiz Gustavo Hafemann

Ryan Galloway

unread,
Nov 10, 2022, 6:18:20 PM11/10/22
to alembic-discussion
Hey Luiz,

It's been a while, and I think these docs are a couple versions behind now, but you can check out this section of the cask docs. Hopefully it's a little helpful. 


You might also look here which also appears to be a couple versions behind, but probably not much has changed:


Ryan

lui...@gmail.com

unread,
Nov 19, 2022, 10:51:21 AM11/19/22
to alembic-discussion
Hi Ryan, thanks for the reply.

I got it working on my end, thanks to the code in the test files in pyalembic, that export a mesh:

Btw, I actually started from the test code in Cask that exports a mesh, but the resulting .abc seems to be problematic (it opens ok in my 3dsmax 2018, but crashes maya 2020):

Anyway, the pyalembic tests were sufficient for me to get what I wanted (just a simple animated mesh).

Thanks again!
Reply all
Reply to author
Forward
0 new messages