1 2def BuildHierarchyRoot(rootNode): 3 #For now delete the existing children. 4 for child in rootNode.children(): 5 child.destroy() 6 7 import _alembic_hom_extensions as ABC 8 9 tree = ABC.alembicGetSceneHierarchy( 10 rootNode.evalParm('fileName'), "") 11 12 pathList = [x for x in rootNode.evalParm('objectPath').strip('/').split('/') if x] 13 14 for entry in tree[2]: 15 WalkHierarchy(rootNode, rootNode, '', entry, pathList) 16 17_primitiveTypes = frozenset(( 18 'polymesh', 19 'subdmesh', 20 'curves', 21 'nupatch', 22 'points', 23)) 24 25def ExpressionToParm(srcParm, dstParm, isString=False): 26 relPath = dstParm.node().relativePathTo(srcParm.node()) 27 dstParm.setExpression('ch%s("%s/%s")' % ( 28 bool(isString)*'s', relPath, srcParm.name())) 29 30def WalkHierarchy(rootNode, parentNode, parentPath, childEntry, pathList): 31 name, typeName, children = childEntry 32 33 34 if pathList: 35 if pathList[0] != name: 36 return 37 pathList = pathList[1:] 38 39 currentPath = parentPath + '/' + name 40 if typeName in _primitiveTypes: 41 currentNode = parentNode.createNode('geo') 42 currentNode.setName(name) 43 for child in currentNode.children(): 44 child.destroy() 45 sopNode = currentNode.createNode('alembic') 46 47 relPath = sopNode.relativePathTo(rootNode) 48 hou.hscript("opmultiparm %s 'abcName#' '%s/abcName#' 'hName#' '%s/hName#'" % ( 49 sopNode.path(), relPath, relPath)) 50 51 ExpressionToParm(rootNode.parm('remapAttributes'), sopNode.parm('remapAttributes'), 52 isString=True) 53 54 ExpressionToParm(rootNode.parm('fileName'), sopNode.parm('fileName'), 55 isString=True) 56 ExpressionToParm(rootNode.parm('frame'), sopNode.parm('frame')) 57 ExpressionToParm(rootNode.parm('fps'), sopNode.parm('fps')) 58 59 sopNode.parm('objectPath').set(currentPath) 60 sopNode.parm('includeXform').set(0) 61 62 63 elif typeName == 'xform' or typeName == 'cxform': 64 currentNode = parentNode.createNode('alembicxform') 65 currentNode.setName(name) 66 67 ExpressionToParm(rootNode.parm('fileName'), currentNode.parm('fileName'), 68 isString=True) 69 if typeName != 'cxform': 70 ExpressionToParm(rootNode.parm('frame'), currentNode.parm('frame')) 71 ExpressionToParm(rootNode.parm('fps'), currentNode.parm('fps')) 72 73 74 currentNode.parm('objectPath').set(currentPath) 75 76 77 for entry in children: 78 WalkHierarchy(rootNode, currentNode, currentPath, entry, pathList) 79 elif typeName == 'camera': 80 currentNode = parentNode.createNode('cam') 81 currentNode.setName(name) 82 currentNode.addSpareParmTuple(rootNode.parm('fileName').parmTemplate(), 83 ('Alembic',), True) 84 currentNode.addSpareParmTuple(rootNode.parm('frame').parmTemplate(), 85 ('Alembic',), True) 86 currentNode.addSpareParmTuple(rootNode.parm('fps').parmTemplate(), 87 ('Alembic',), True) 88 89 ExpressionToParm(rootNode.parm('fileName'), currentNode.parm('fileName'), 90 isString=True) 91 ExpressionToParm(rootNode.parm('frame'), currentNode.parm('frame')) 92 ExpressionToParm(rootNode.parm('fps'), currentNode.parm('fps')) 93 94 for parmName in ( 95 'focal', 96 'near', 97 'far', 98 'focus', 99 'winx', 100 'winy', 101 'winsizex', 102 'winsizey', 103 'aperture'): 104 currentNode.parm(parmName).setExpression( 105 'pwd().alembicGetCameraDict(ch("fileName"), "%s", ch("frame")/ch("fps")).get("%s")' % ( 106 currentPath, parmName), hou.exprLanguage.Python) 107 108 109 else: 110 return 111 112def GetObjectMenu(): 113 return ['b', 'b', 'c', 'c'] 114