Пример #1
0
    def start(self):
        self.visited_nodes = []
        self.nodes = {}
        self.edges = []
        self.init_edges = []

        layer = Sdf.Layer.FindOrOpen(self.usdfile)
        if not layer:
            return

        # scrub the initial file path
        # to get around upper/lowercase drive letters
        # and junk like that
        layer_path = Sdf.ComputeAssetPathRelativeToLayer(
            layer, os.path.basename(self.usdfile))

        self.usdfile = layer_path

        info = {}
        info['online'] = os.path.isfile(layer_path)
        info['path'] = layer_path
        info['type'] = 'sublayer'
        self.nodes[layer_path] = info

        self.walkStageLayers(layer_path)
Пример #2
0
def dep_2(usdfile, level=1):
    id = '-' * (level)

    sublayers = []
    payloads = []
    references = []

    layer = Sdf.Layer.FindOrOpen(usdfile)
    if not layer:
        return
    print(id, layer.realPath, type(layer))
    root = layer.pseudoRoot
    print(id, 'root', root)
    # print(dir(layer))
    # print(id, 'children'.center(40, '-'))

    child_list = get_flat_child_list(root)

    for child in child_list:
        print(id, child, type(child))

        attributes = child.attributes
        if attributes:
            print('attributes'.center(40, '-'))

            for attr in attributes:
                if attr.typeName == 'asset':
                    value = attr.default
                    if value:
                        print(dir(child))
                        # parent of this object
                        print('realNameParent', child.realNameParent)
                        # path to the thing hosting the attribute
                        print('path', child.path)
                        print('name', child.name)
                        # type of def - eg "shader"
                        print('typeName', child.typeName)

                        print('ASSET')
                        print(attr, type(attr))
                        print(dir(attr))
                        print('attr displayName:', attr.displayName)
                        print('attr path:', attr.path)
                        print('attr name:', attr.name)
                        print('attr typeName:', attr.typeName)
                        print('attr valueType:', attr.valueType)
                        print('attr owner:', attr.owner)
                        print('attr roleName:', attr.roleName)
                        print('attr colorSpace:', attr.colorSpace)

                        print(value, type(value))
                        print(dir(value))
                        print(value.path)
                        if value.path:
                            resolved_path = Sdf.ComputeAssetPathRelativeToLayer(
                                layer, value.path)
                            print(resolved_path, os.path.isfile(resolved_path))
                    # print(dir(attr))
                    # print(attr.GetConciseRelativePaths())
                    # connpaths = attr.connectionPathList
                    # print(connpaths)
                    # # print(type(connpaths))
                    # for itemlist in [connpaths.appendedItems, connpaths.explicitItems, connpaths.addedItems,
                    #                  connpaths.prependedItems, connpaths.orderedItems]:
                    #     for item in itemlist:
                    #         print(item, type(item))
                    # # print(attr.ConnectionPathsKey)
                    # print('assetInfo', attr.assetInfo)
                    # print('allowedTokens', attr.allowedTokens)
                    # print('displayUnit', attr.displayUnit)
                    # print('roleName', attr.roleName)
                    # print('valueType', attr.valueType)
                    # print('name', attr.name)
                    # print('default', attr.default)

                    # print(attr.path)
                    # print(layer.ListTimeSamplesForPath(attr.path))
                    # print(layer.QueryTimeSample(attr.path, 0))
                    # print('assetInfo', attr.typeName, type(attr.typeName))
                    # if attr.HasConnectionPaths():
                    #     print(attr.GetConnectionPathList())

            print('END attributes'.center(40, '-'))
        # print('properties'.center(40, '-'))
        # for prop in child.properties:
        #     print(prop, type(prop))
        #     # print(dir(prop))
        #     # print('assetInfo', prop.assetInfo)
        #     # print('rolename:', prop.roleName)
        #     # print('GetAllowedTokens:', prop.allowedTokens)
        #     connpaths = prop.typeName
        #     connpaths = prop.connectionPathList
        #     print(connpaths)
        #     # print(type(connpaths))
        #     for itemlist in [connpaths.appendedItems, connpaths.explicitItems, connpaths.addedItems,
        #                      connpaths.prependedItems, connpaths.orderedItems]:
        #         for item in itemlist:
        #             print(item, type(item))
        #
        # print('END properties'.center(40, '-'))

        # for key in child.ListInfoKeys():
        #     print(child.GetInfo(key))
        #
        # print(child.GetMetaDataInfoKeys())

        # raise RuntimeError("poo")

        clip_info = child.GetInfo("clips")
        # pprint(clip_info)

        # for clip_set_name in clip_info:
        #     clip_set = clip_info[clip_set_name]
        #     print(clip_set.keys())
        #     pprint(clip_set)
        #     print(clip_set_name, clip_set.get("assetPaths"), clip_set.get("manifestAssetPath"), clip_set.get("primPath"))
        #     for assetPath in clip_set.get("assetPaths"):
        #         print(id, Sdf.ComputeAssetPathRelativeToLayer(layer, assetPath.path))
        #     manifestPath = clip_set.get("manifestAssetPath")
        #     print(manifestPath, type(manifestPath))
        #     print(id, Sdf.ComputeAssetPathRelativeToLayer(layer, manifestPath.path))

        if child.variantSets:
            print('variants'.center(40, '-'))
            for varset in child.variantSets:
                print(varset.name)
                for variant_name in varset.variants.keys():
                    variant = varset.variants[variant_name]
                    print(variant_name)
                    payloadList = variant.primSpec.payloadList
                    print(payloadList)
                    for x in get_flat_child_list(variant.primSpec):
                        print(x.payloadList)
                        print(x.referenceList)

        payloadList = child.payloadList
        for itemlist in [
                payloadList.appendedItems, payloadList.explicitItems,
                payloadList.addedItems, payloadList.prependedItems,
                payloadList.orderedItems
        ]:
            for payload in itemlist:
                pathToResolve = payload.assetPath
                if pathToResolve:
                    refpath = os.path.normpath(
                        os.path.join(os.path.dirname(layer.realPath),
                                     pathToResolve)).replace('\\', '/')
                    # print(id, 'payload:', refpath)
                    payloads.append(refpath)

        referenceList = child.referenceList
        for itemlist in [
                referenceList.appendedItems, referenceList.explicitItems,
                referenceList.addedItems, referenceList.prependedItems,
                referenceList.orderedItems
        ]:
            for reference in itemlist:
                pathToResolve = reference.assetPath
                if pathToResolve:
                    refpath = os.path.normpath(
                        os.path.join(os.path.dirname(layer.realPath),
                                     pathToResolve)).replace('\\', '/')
                    # print(id, 'payload:', refpath)
                    references.append(refpath)

    for rel_sublayer in layer.subLayerPaths:
        refpath = os.path.normpath(
            os.path.join(os.path.dirname(layer.realPath),
                         rel_sublayer)).replace('\\', '/')
        sublayers.append(refpath)
        # print(id, refpath)
        dep_2(refpath, level=level + 1)
        # sub_layer = Sdf.Layer.FindOrOpen(refpath)
        # print(sub_layer)
        #
    sublayers = list(set(sublayers))
    references = list(set(references))
    payloads = list(set(payloads))

    print(id, 'sublayerPaths'.center(40, '-'))
    print(id, sublayers)
    print(id, 'references'.center(40, '-'))
    print(id, references)
    print(id, 'payloads'.center(40, '-'))
    print(id, payloads)