def test_find(self): filename = os.path.join(TEMPDIR, "cask_write_mesh.abc") a = cask.Archive(filename) r = cask.find(a.top, name="meshy") self.assertEqual(len(r), 1) self.assertEqual(r[0].name, "meshy") self.assertEqual(r[0].type(), "PolyMesh") r = cask.find(a.top, name=".*hy") self.assertEqual(len(r), 1) self.assertEqual(r[0].name, "meshy") self.assertEqual(r[0].type(), "PolyMesh") r = cask.find(a.top, types=["PolyMesh"]) self.assertEqual(len(r), 1) self.assertEqual(r[0].name, "meshy") self.assertEqual(r[0].type(), "PolyMesh") a.close() filename = os.path.join(TEMPDIR, "cask_deep_dict.abc") a = cask.Archive(filename) r = cask.find(a.top, types=["Xform"]) self.assertEqual(len(r), 15) r = cask.find(a.top, types=["Light"]) self.assertEqual(len(r), 0) r = cask.find(a.top, name="J") self.assertEqual(len(r), 1) r = cask.find(a.top, name="D") self.assertEqual(len(r), 2) self.assertEqual(r[0].name, "D") self.assertEqual(r[0].type(), "Xform") r = cask.find(a.top, name="nurby") self.assertEqual(len(r), 1) self.assertEqual(r[0].name, "nurby") self.assertEqual(r[0].type(), "NuPatch") r = cask.find(a.top, types=["NuPatch"]) self.assertEqual(len(r), 1) self.assertEqual(r[0].name, "nurby") self.assertEqual(r[0].type(), "NuPatch") a.close()
def get_future_dag_path(transform, parent_under, archive): """ Find the selected transforms matching our name, loop over them and construct the future dag path """ importxform = cask.find(archive.top, transform, 'Xform') # importxform should only match one for foundnode in importxform: node_hierarchy = build_path(foundnode, []) node_hierarchy.append(foundnode.name) return parent_under + '|' + '|'.join(node_hierarchy)
def test_read_lights(self): filepath = lights_out() a = cask.Archive(filepath) self.assertEqual(a.path(), filepath) self.assertEqual(a.name, os.path.basename(filepath)) # test the top node t = a.top self.assertEqual(type(t), cask.Top) self.assertEqual(t.name, "ABC") self.assertEqual(t.parent, a) self.assertEqual(t.path(), "/") self.assertEqual(t.archive(), a) # child accessors l1 = t.children["lightA"] self.assertEqual(type(l1.parent), cask.Top) self.assertEqual(l1.name, "lightA") self.assertEqual(l1.archive(), a) self.assertEqual(type(l1), cask.Light) # get next child l2 = t.children["lightB"] self.assertEqual(type(l2), cask.Light) self.assertEqual(l2.name, "lightB") self.assertEqual(l2.archive(), a) self.assertEqual(type(l2.parent), cask.Top) # find lights (w/ deferred schemification) self.assertEqual(len(cask.find(a.top, "light.*")), 2) # schema accessor (schemifies object on demand) self.assertEqual(type(l2.iobject), alembic.Abc.IObject) self.assertEqual(len(l2.properties[".geom/.camera/.core"].properties), 0) self.assertEqual( len(l2.properties["shader/prman.light.params"].properties), 2) self.assertEqual( len(l2.properties["shader/prman.light.params/exposure"].values), 11) self.assertEqual( len(l2.properties["shader/prman.light.params/specular"].values), 11) self.assertAlmostEqual( l2.properties["shader/prman.light.params/exposure"].values[0], 1.0) self.assertAlmostEqual( l2.properties["shader/prman.light.params/specular"].values[0], 0.1) self.assertEqual(type(l2.schema), alembic.AbcGeom.ILightSchema) self.assertEqual(type(l2.iobject), alembic.AbcGeom.ILight)
def test_extract_light(self): filename = os.path.join(TEMPDIR, "cask_exract_light.abc") # open light archive and create new empty archive a = cask.Archive(lights_out()) b = cask.Archive() # find a light and assign it to b's hierarchy results = cask.find(a.top, "lightB") self.assertEqual(len(results), 1) b.top.children["lightB"] = results[0] # write new archive to disk b.write_to_file(filename) self.assertTrue(os.path.isfile(filename))
def get_previously_imported_transforms(abcfile, root): """ Return a list of transform that are present under 'root' that are also present in the given alembic file """ archive = cask.Archive(abcfile) previous = [] lowest_transforms = [] descendents = cmds.listRelatives(root, f=True, allDescendents=True) if descendents: for d in descendents: children = cmds.listRelatives(d, children=True) if not children: # the xform doesnt have any children last = d.split('|')[-1] if last not in lowest_transforms: lowest_transforms.append(last) # OR - the xform does have children, but none that are from the alembic if children: for c in children: if cask.find(archive.top, str(c)) != []: last = c.split('|')[-1] if last not in lowest_transforms: lowest_transforms.append(last) for i in lowest_transforms: # if the descendent transform is in the alembic archive # safe to say its been imported before if cask.find(archive.top, str(i)) != []: previous.append(i) return previous
def test_read_lights(self): filepath = lights_out() a = cask.Archive(filepath) self.assertEqual(a.path(), filepath) self.assertEqual(a.name, os.path.basename(filepath)) # test the top node t = a.top self.assertEqual(type(t), cask.Top) self.assertEqual(t.name, "ABC") self.assertEqual(t.parent, a) self.assertEqual(t.path(), "/") self.assertEqual(t.archive(), a) # child accessors l1 = t.children["lightA"] self.assertEqual(type(l1.parent), cask.Top) self.assertEqual(l1.name, "lightA") self.assertEqual(l1.archive(), a) self.assertEqual(type(l1), cask.Light) # get next child l2 = t.children["lightB"] self.assertEqual(type(l2), cask.Light) self.assertEqual(l2.name, "lightB") self.assertEqual(l2.archive(), a) self.assertEqual(type(l2.parent), cask.Top) # find lights (w/ deferred schemification) self.assertEqual(len(cask.find(a.top, "light.*")), 2) # schema accessor (schemifies object on demand) self.assertEqual(type(l2.iobject), alembic.Abc.IObject) self.assertEqual(len(l2.properties[".geom/.camera/.core"].properties), 0) self.assertEqual(len(l2.properties["shader/prman.light.params"].properties), 2) self.assertEqual(len(l2.properties["shader/prman.light.params/exposure"].values), 11) self.assertEqual(len(l2.properties["shader/prman.light.params/specular"].values), 11) self.assertAlmostEqual(l2.properties["shader/prman.light.params/exposure"].values[0], 1.0) self.assertAlmostEqual(l2.properties["shader/prman.light.params/specular"].values[0], 0.1) self.assertEqual(type(l2.schema), alembic.AbcGeom.ILightSchema) self.assertEqual(type(l2.iobject), alembic.AbcGeom.ILight)
:return: None """ # extract the mesh animation vertices and mesh indices mesh_animation_frame_verts, mesh_indices = extract_animation_data(polymesh) # if the path is not given, the vertices will be saved to the current directory # set the vertices file path if not verts_path: verts_path = os.path.join(os.getcwd(), "verts.npy") # set the face indices file path if not face_indices_path: face_indices_path = os.path.join(os.getcwd(), "face_indices.npy") # save the tensors to .npy files using numpy np.save(verts_path, mesh_animation_frame_verts) np.save(face_indices_path, mesh_indices) if __name__ == "__main__": # load an alembic archive from .abc file arch = cask.Archive("data/alembic/Running_T-pose.abc") # extract a PolyMesh called "BodyShape" from the archive shapes = cask.find(arch.top, "BodyShape") bodyshape = shapes[0] # save its animation vertices and face indices to numpy array files (.npy) save_alembic_animation_to_npy(bodyshape)