Saturday, April 12, 2014

Testing the UV export

To add to my last post on Alembic, I wanted to also share how you can check if your values got exported. One of the easiest ways is to check this using Alembic's python bindings to traverse you ".abc" file. I'll post an example to show the way to do it using general Alembic python module, but there is also a slightly easier way to access the alembic files via Cask (a module provided with Alembic's examples that helps reading and modifying ".abc" files with python in a more straight forward way). You can find and download it here: http://code.google.com/p/alembic/source/browse/#hg%2Fpython%2Fexamples%2Fcask.

(NOTE - this example is for linux, but can be modified pretty easily for windows)
So lets say you have a file called test_cache.abc located in "/home/userName/alembic_cache/". In the alembic file with have a simple sphere exported, named by default as "pSphere1". The test will look like this:
import imath, alembic

archive = alembic.Abc.IArchive('/home/userName/alembic_cache/test_cache.abc')
      
top = archive.getTop()
mesh = alembic.AbcGeom.IPolyMesh(top.children[0], 'pSphereShape1')
# Should display <class 'alembic.AbcGeom.IPolyMesh'>
print type(mesh)

schema = mesh.getSchema()
# Should display <class 'alembic.AbcGeom.IPolyMeshSchema'>
print type(schema)

arb_params = schema.getArbGeomParams()
# This should show the extra UVs you exported, and, if you did export the
# Vertex colors, those too.
print arb_params.getNumProperties()

# Assuming you didn't export any colors, and only one extra map:
uv_header = arb_params.getPropertyHeader(0)

# Lets make sure that it is indeed the right property, so print the name.
# Should be the same as the UV map in our file (Note, the one that WASN'T the
# active one at the time of export!)
print uv_header.getName()

v2f_param = alembic.AbcGeom.IV2fGeomParam(arb_params, uv_header.getName())

# Lets make sure that what we got back is indeed what we want! Should be "True"
print alembic.AbcGeom.IV2fGeomParam.matches(uv_header)

# Now we get the uv sample that containes the values for the UVs and their
# indices.
uv_sample = v2f_param.getIndexedValue(0)
# Should get <class 'alembic.AbcGeom.IV2fGeomParamSample'>
print type(uv_sample)

uv_values = uv_sample.getVals()
uv_indices = uv_sample.getIndices()

# Lets make sure that what we got back is what it should be.
# Check the type of uv_values: should be <class 'imath.V2fArray'>
print type(uv_values)
# ...and indices: should be <class 'imath.UnsignedIntArray'>
print type(uv_indices)

# Now lets check the values: should get something like V2f(0.432955, 0.681514)
# Note, the values will obviously be different from mine here...
print uv_values[0]
# ...and indices: should just be some integer like 3
print uv_indices[0]
This should get you going and help you test what you exported and see if it worked.

Hope that helps,

Cheers,

DK

No comments:

Post a Comment