Exemplo n.º 1
0
// XXX: i don't even know if it's important to distinguish where
// these asset paths are coming from..  if it's not important, maybe this
// should just go into Sdf's _GatherPrimAssetReferences?  if it is important,
// we could also have another function that takes 3 vectors.
static void
_ExtractDependenciesForBinary(
    const std::string& filePath,
    std::vector<std::string>* sublayers,
    std::vector<std::string>* references,
    std::vector<std::string>* payloads)
{
    TRACE_FUNCTION();

    SdfLayerRefPtr layer = SdfLayer::OpenAsAnonymous(filePath);
    if (not TF_VERIFY(layer))
        return;

    *sublayers = layer->GetSubLayerPaths();

    std::stack<SdfPrimSpecHandle> dfs;
    dfs.push(layer->GetPseudoRoot());

    while (not dfs.empty()) {
        SdfPrimSpecHandle curr = dfs.top();
        dfs.pop();

        if (curr != layer->GetPseudoRoot()) {
            // references
            const SdfReferencesProxy refList = curr->GetReferenceList();
            for (const SdfReference& ref :
                refList.GetAddedOrExplicitItems()) {
                _AppendAssetPathIfNotEmpty(ref, references);
            }

            // payloads
            if (curr->HasPayload()) {
                const SdfPayload payload = curr->GetPayload();
                _AppendAssetPathIfNotEmpty(payload, payloads);
            }

            // attributes
            //
            // XXX:2016-04-14 Note that we use the field access API
            // here rather than calling GetAttributes, as creating specs for
            // large numbers of attributes, most of which are *not* asset
            // path-valued and therefore not useful here, is expensive.
            //
            const VtValue propertyNames =
                curr->GetField(SdfChildrenKeys->PropertyChildren);
            if (propertyNames.IsHolding<vector<TfToken>>()) {
                for (const auto& name :
                        propertyNames.UncheckedGet<vector<TfToken>>()) {
                    const SdfPath path = curr->GetPath().AppendProperty(name);
                    const VtValue vtTypeName = layer->GetField(
                        path, SdfFieldKeys->TypeName);
                    if (not vtTypeName.IsHolding<TfToken>())
                        continue;

                    const TfToken typeName =
                        vtTypeName.UncheckedGet<TfToken>();
                    if (typeName == SdfValueTypeNames->Asset or
                        typeName == SdfValueTypeNames->AssetArray) {
                        _AppendAssetValue(layer->GetField(
                            path, SdfFieldKeys->Default), references);
                    }
                }
            }

            // meta data
            for (const TfToken& infoKey : curr->GetMetaDataInfoKeys()) {
                _AppendAssetValue(curr->GetInfo(infoKey), references);
            }
        }

        // variants "children"
        for (const SdfVariantSetsProxy::value_type& p :
            curr->GetVariantSets()) {
            for (const SdfVariantSpecHandle& variantSpec :
                p.second->GetVariantList()) {
                dfs.push(variantSpec->GetPrimSpec());
            }
        }

        // children
        for (const SdfPrimSpecHandle& child : curr->GetNameChildren()) {
            dfs.push(child);
        }
    }
}