Skip to content

Instantly share code, notes, and snippets.

@BigRoy
Created September 22, 2020 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BigRoy/eea07a0fb60437eb5cecd9fc6c4fd324 to your computer and use it in GitHub Desktop.
Save BigRoy/eea07a0fb60437eb5cecd9fc6c4fd324 to your computer and use it in GitHub Desktop.
Debug print out Alembic PolyMesh attributes
import alembic
def _print_properties(property, depth=1):
# Property name
print ("\t" * depth) + property.getName()
# Metadata
metadata = property.getMetaData()
if metadata.size():
# Can hold things like "sourceName" for UVs
print ("\t" * depth) + " - metadata -> %s" % metadata
# Header (check whether it's marked as UVs)
header = property.getHeader()
if hasattr(header, "isUV"):
is_uv = header.isUV()
if is_uv:
print ("\t" * depth) + " - " + "header -> isUV=%s" % header.isUV()
print("")
# CompoundProperty print children
if isinstance(property, alembic.Abc.ICompoundProperty):
num_sub_properties = property.getNumProperties()
for i in range(num_sub_properties):
sub_property = property.getProperty(i)
_print_properties(sub_property, depth+1)
def print_alembic_shape_attributes(filename):
filename = str(filename) # ensure str
archive = alembic.Abc.IArchive(filename)
root = archive.getTop()
iterator = list(root.children)
for obj in iterator:
md = obj.getMetaData()
if alembic.AbcGeom.IPolyMesh.matches(md):
polymesh = alembic.AbcGeom.IPolyMesh(obj, alembic.Abc.WrapExistingFlag.kWrapExisting)
schema = polymesh.getSchema()
print obj
uv = schema.getUVsParam()
if uv.valid():
print "\t", "polymesh (UV parm)"
_print_properties(uv)
# Arbitrary Geometry Parms
arbgeomparms = schema.getArbGeomParams()
if arbgeomparms.valid():
# Should always be valid
_print_properties(arbgeomparms)
# User Properties
user_properties = schema.getUserProperties()
if user_properties.valid():
_print_properties(user_properties)
print("")
# include children for coming iterations
iterator.extend(obj.children)
path = "path/to/alembic.abc"
print_alembic_shape_attributes(path)
@BigRoy
Copy link
Author

BigRoy commented Sep 22, 2020

Example output:

/group/mesh/meshShape
	polymesh (UV parm)
	uv
	      - metadata -> arrayExtent=1;geoScope=fvr;interpretation=vector;isGeomParam=true;podExtent=2;podName=float32_t;sourceName=uvSet
	      - header -> isUV=True

	.arbGeomParams

		cbId
		      - metadata -> arrayExtent=1;isGeomParam=true;podExtent=1;podName=string

		map1
		      - metadata -> arrayExtent=1;geoScope=fvr;interpretation=vector;isGeomParam=true;podExtent=2;podName=float32_t
		      - header -> isUV=True

			.vals
			      - metadata -> arrayExtent=1;geoScope=fvr;interpretation=vector;isGeomParam=true;podExtent=2;podName=float32_t
			      - header -> isUV=True

			.indices

	.userProperties


/group/mesh2/mesh2Shape
	polymesh (UV parm)
	uv
	      - metadata -> arrayExtent=1;geoScope=fvr;interpretation=vector;isGeomParam=true;podExtent=2;podName=float32_t
	      - header -> isUV=True

	.arbGeomParams

		cbId
		      - metadata -> arrayExtent=1;isGeomParam=true;podExtent=1;podName=string

		uvSet
		      - metadata -> arrayExtent=1;geoScope=fvr;interpretation=vector;isGeomParam=true;podExtent=2;podName=float32_t
		      - header -> isUV=True

			.vals
			      - metadata -> arrayExtent=1;geoScope=fvr;interpretation=vector;isGeomParam=true;podExtent=2;podName=float32_t
			      - header -> isUV=True

			.indices

	.userProperties

...

@BigRoy
Copy link
Author

BigRoy commented Sep 22, 2020

This was related to debugging why Houdini <-> Maya Alembic exports started behaving differently with the exported UVs, like Houdini reading Maya's map1 uv as uv, etc.

Related topics:

  • https://www.sidefx.com/forum/topic/75144/

  • https://www.sidefx.com/forum/topic/72628/

    • As mentioned there, Maya indeed export writes the "Current UV set" as uv and passes along a "sourceName" for the UV set. However it only does so when the UV set is not! map1 which makes the behavior very confusing. So, Houdini will "know" about the source UV set name as it is saved in the Alembic file (as long as it was not map1).

@jpvfx2
Copy link

jpvfx2 commented Dec 9, 2020

Hi there,

Thanks for this! Extremely helpful for a beginner with alembic! One question (forgive me if its a noob question). I have the script working and printing the shape Attributes, but I cant figure out how to print the value of the attribute - I'm expecting the attribute "myMaterialTag" to return string of "test". what am i missing? Output below:

print_alembic_shape_attributes(path)
/pSphere1/pSphereShape1
.arbGeomParams
- metadata -> .arbGeomParams

	myMaterialTag
	      - metadata -> arrayExtent=1;isGeomParam=true;podExtent=1;podName=string

Thanks in advance for your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment