Beispiel #1
0
static bool
_GatherRibAttributes(
        const UsdPrim &prim, 
        double currentTime,
        FnKat::GroupBuilder& attrsBuilder)
{
    bool hasAttrs = false;

    // USD SHADING STYLE ATTRIBUTES
    UsdRiStatements riStatements(prim);
    if (riStatements) {
        const std::vector<UsdProperty> props = 
            riStatements.GetRiAttributes();
        std::string attrName;
        TF_FOR_ALL(propItr, props) {
            UsdProperty prop = *propItr;
            if (!prop) continue;

            std::string nameSpace = 
                riStatements.GetRiAttributeNameSpace(prop).GetString();
            nameSpace = TfStringReplace(nameSpace, ":", ".") + ".";

            attrName = nameSpace +
                riStatements.GetRiAttributeName(prop).GetString();

            VtValue vtValue;
            UsdAttribute usdAttr = prim.GetAttribute(prop.GetName());
            if (usdAttr) {
                if (not usdAttr.Get(&vtValue, currentTime)) 
                    continue;

                // XXX asShaderParam really means:
                // "For arrays, as a single attr vs a type/value pair group"
                // The type/value pair group is meaningful for attrs who don't
                // have a formal type definition -- like a "user" RiAttribute.
                // 
                // However, other array values (such as two-element shadingrate)
                // are not expecting the type/value pair form and will not
                // generate rib correctly. As such, we'll handle the "user"
                // attribute as a special case.
                bool asShaderParam = true;
                
                if (nameSpace == "user.")
                {
                    asShaderParam = false;
                }

                attrsBuilder.set(attrName, PxrUsdKatanaUtils::ConvertVtValueToKatAttr(vtValue,
                    asShaderParam) );
            }
            else {
                UsdRelationship usdRel = prim.GetRelationship(prop.GetName());
                attrsBuilder.set(attrName, PxrUsdKatanaUtils::ConvertRelTargetsToKatAttr(usdRel,
                    /* asShaderParam */ false) );
            }
            hasAttrs = true;
        }
    }
bool
UsdRiStatementsAPI::IsRiAttribute(const UsdProperty &attr)
{
    // Accept primvar encoding.
    if (TfStringStartsWith(attr.GetName(), _tokens->primvarAttrNamespace)) {
        return true;
    }
    // Optionally accept old-style attribute encoding.
    if (TfStringStartsWith(attr.GetName(), _tokens->fullAttributeNamespace) &&
        TfGetEnvSetting(USDRI_STATEMENTS_READ_OLD_ATTR_ENCODING)) {
        return true;
    }
    return false;
}
Beispiel #3
0
void
PxrUsdKatanaReadBlindData(
        const UsdKatanaBlindDataObject& kbd,
        PxrUsdKatanaAttrMap& attrs)
{
    std::vector<UsdProperty> blindProps = kbd.GetKbdAttributes();
    TF_FOR_ALL(blindPropIter, blindProps) {
        UsdProperty blindProp = *blindPropIter;
        if (blindProp.Is<UsdAttribute>()) {
            UsdAttribute blindAttr = blindProp.As<UsdAttribute>();
            VtValue vtValue;
            if (not blindAttr.Get(&vtValue)) {
                continue;
            }

            std::string attrName = 
                UsdKatanaBlindDataObject::GetKbdAttributeNameSpace(blindProp).GetString();

            // If the attribute has no namespace, then it should be a
            // top-level attribute and the name is simply the property 
            // 'base name'. Otherwise, attrName is the group attribute 
            // name, and we need to append onto it the group builder key.
            //
            if (attrName.empty())
            {
                attrName = blindProp.GetBaseName();
            }
            else
            {
                attrName += ".";
                attrName += UsdKatanaBlindDataObject::GetGroupBuilderKeyForProperty(blindProp);
            }

            // we set asShaderParam=true because we want the attribute to be
            // generated "as is", we *do not* want the prmanStatement style
            // "type"/"value" declaration to be created.
            attrs.set(attrName, 
                PxrUsdKatanaUtils::ConvertVtValueToKatAttr(
                    vtValue, 
                    /* asShaderParam */ true));
        }
    }
TfToken UsdRiStatementsAPI::GetRiAttributeNameSpace(const UsdProperty &prop)
{
    const std::vector<string> names = prop.SplitName();
    // Parse primvar encoding.
    if (TfStringStartsWith(prop.GetName(), _tokens->primvarAttrNamespace)) {
        if (names.size() >= 5) {
            // Primvar with N custom namespaces:
            // "primvars:ri:attributes:$(NS_1):...:$(NS_N):$(NAME)"
            return TfToken(TfStringJoin(names.begin() + 3, names.end()-1, ":"));
        }
        return TfToken();
    }
    // Optionally parse old-style attribute encoding.
    if (TfStringStartsWith(prop.GetName(), _tokens->fullAttributeNamespace) &&
        TfGetEnvSetting(USDRI_STATEMENTS_READ_OLD_ATTR_ENCODING)) {
        if (names.size() >= 4) {
            // Old-style attribute with N custom namespaces:
            // "ri:attributes:$(NS_1):...:$(NS_N):$(NAME)"
            return TfToken(TfStringJoin(names.begin() + 2, names.end()-1, ":"));
        }
    }
    return TfToken();
}
Beispiel #5
0
 bool operator()(UsdProperty const &p1, UsdProperty const &p2){
     return TfDictionaryLessThan()(p1.GetName(), p2.GetName());
 }
Beispiel #6
0
UsdProperty 
UsdProperty::FlattenTo(const UsdProperty &property) const
{
    return _GetStage()->_FlattenProperty(
        *this, property.GetPrim(), property.GetName());
}