Esempio n. 1
0
static
bool
_TranslateUsdAttributeToPlug(
        const UsdAttribute& usdAttr,
        const MFnCamera& cameraFn,
        TfToken plugName,
        const PxrUsdMayaPrimReaderArgs& args,
        PxrUsdMayaPrimReaderContext* context,
        bool millimetersToInches=false)
{
    MStatus status;

    MPlug plug = cameraFn.findPlug(plugName.GetText(), true, &status);
    CHECK_MSTATUS_AND_RETURN(status, false);

    // First check for and translate animation if there is any.
    if (!_TranslateAnimatedUsdAttributeToPlug(usdAttr,
                                                 plug,
                                                 args,
                                                 context,
                                                 millimetersToInches)) {
        // If that fails, then try just setting a static value.
        UsdTimeCode timeCode = UsdTimeCode::EarliestTime();
        float attrValue;
        usdAttr.Get(&attrValue, timeCode);
        if (millimetersToInches) {
            attrValue = PxrUsdMayaUtil::ConvertMMToInches(attrValue);
        }
        status = plug.setFloat(attrValue);
        CHECK_MSTATUS_AND_RETURN(status, false);
    }

    return true;
}
static
bool
_TranslateUsdAttributeToPlug(
        const UsdAttribute& usdAttr,
        const MFnCamera& cameraFn,
        const TfToken& plugName,
        const UsdMayaPrimReaderArgs& args,
        UsdMayaPrimReaderContext* context,
        const MDistance::Unit convertToUnit = MDistance::kMillimeters)
{
    MStatus status;

    MPlug plug = cameraFn.findPlug(plugName.GetText(), true, &status);
    CHECK_MSTATUS_AND_RETURN(status, false);

    // First check for and translate animation if there is any.
    if (!_TranslateAnimatedUsdAttributeToPlug(usdAttr,
                                              plug,
                                              args,
                                              context,
                                              convertToUnit)) {
        // If that fails, then try just setting a static value.
        UsdTimeCode timeCode = UsdTimeCode::EarliestTime();
        float attrValue;
        usdAttr.Get(&attrValue, timeCode);

        switch (convertToUnit) {
            case MDistance::kInches:
                attrValue = UsdMayaUtil::ConvertMMToInches(attrValue);
                break;
            case MDistance::kCentimeters:
                attrValue = UsdMayaUtil::ConvertMMToCM(attrValue);
                break;
            default:
                // The input is expected to be in millimeters.
                break;
        }

        status = plug.setFloat(attrValue);
        CHECK_MSTATUS_AND_RETURN(status, false);
    }

    return true;
}