Example #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;
        }
    }
Example #2
0
std::vector<UsdShadeParameter>
UsdShadeInterfaceAttribute::GetRecipientParameters(
        const TfToken& renderTarget) const
{
    UsdPrim prim = _attr.GetPrim();
    std::vector<UsdShadeParameter> ret;
    if (UsdRelationship rel = prim.GetRelationship(
                _GetInterfaceAttributeRelName(renderTarget, *this))) {
        std::vector<SdfPath> targets;
        rel.GetTargets(&targets);
        TF_FOR_ALL(targetIter, targets) {
            const SdfPath& target = *targetIter;
            if (target.IsPropertyPath()) {
                if (UsdPrim targetPrim = prim.GetStage()->GetPrimAtPath(
                            target.GetPrimPath())) {
                    if (UsdAttribute attr = targetPrim.GetAttribute(
                                target.GetNameToken())) {
                        ret.push_back(UsdShadeParameter(attr));
                    }
                }
            }
        }
    }