bool _ReadToCamera( const UsdGeomCamera& usdCamera, MFnCamera& cameraFn, const UsdMayaPrimReaderArgs& args, UsdMayaPrimReaderContext* context) { MStatus status; // Now translate all of the USD camera attributes over to plugs on the // Maya cameraFn. UsdTimeCode timeCode = UsdTimeCode::EarliestTime(); UsdAttribute usdAttr; TfToken plugName; // Set the type of projection. This is NOT keyable in Maya. TfToken projection; usdCamera.GetProjectionAttr().Get(&projection, timeCode); const bool isOrthographic = (projection == UsdGeomTokens->orthographic); status = cameraFn.setIsOrtho(isOrthographic); CHECK_MSTATUS_AND_RETURN(status, false); // Setup the aperture. usdAttr = usdCamera.GetHorizontalApertureAttr(); plugName = _tokens->MayaCameraAttrNameHorizontalAperture; if (!_TranslateUsdAttributeToPlug(usdAttr, cameraFn, plugName, args, context, /* convertToUnit = */ MDistance::kInches)) { return false; } if (isOrthographic) { // For orthographic cameras, we'll re-use the horizontal aperture value // to fill in Maya's orthographicWidth. The film aperture and film // aperture offset plugs in Maya have no effect on orthographic cameras, // but we author them anyway so that the data is preserved. Note also // that Maya stores the orthographicWidth as centimeters. plugName = _tokens->MayaCameraAttrNameOrthographicWidth; if (!_TranslateUsdAttributeToPlug(usdAttr, cameraFn, plugName, args, context, /* convertToUnit = */ MDistance::kCentimeters)) { return false; } } usdAttr = usdCamera.GetVerticalApertureAttr(); plugName = _tokens->MayaCameraAttrNameVerticalAperture; if (!_TranslateUsdAttributeToPlug(usdAttr, cameraFn, plugName, args, context, /* convertToUnit = */ MDistance::kInches)) { return false; } // XXX: // Lens Squeeze Ratio is DEPRECATED on USD schema. // Writing it out here for backwards compatibility (see bug 123124). cameraFn.setLensSqueezeRatio(1.0); usdAttr = usdCamera.GetHorizontalApertureOffsetAttr(); plugName = _tokens->MayaCameraAttrNameHorizontalApertureOffset; if (!_TranslateUsdAttributeToPlug(usdAttr, cameraFn, plugName, args, context, /* convertToUnit = */ MDistance::kInches)) { return false; } usdAttr = usdCamera.GetVerticalApertureOffsetAttr(); plugName = _tokens->MayaCameraAttrNameVerticalApertureOffset; if (!_TranslateUsdAttributeToPlug(usdAttr, cameraFn, plugName, args, context, /* convertToUnit = */ MDistance::kInches)) { return false; } // Set the lens parameters. usdAttr = usdCamera.GetFocalLengthAttr(); plugName = _tokens->MayaCameraAttrNameFocalLength; if (!_TranslateUsdAttributeToPlug(usdAttr, cameraFn, plugName, args, context)) { return false; } usdAttr = usdCamera.GetFocusDistanceAttr(); plugName = _tokens->MayaCameraAttrNameFocusDistance; if (!_TranslateUsdAttributeToPlug(usdAttr, cameraFn, plugName, args, context)) { return false; } usdAttr = usdCamera.GetFStopAttr(); plugName = _tokens->MayaCameraAttrNameFStop; if (!_TranslateUsdAttributeToPlug(usdAttr, cameraFn, plugName, args, context)) { return false; } // Set the clipping planes. This one is a little different from the others // because it is stored in USD as a single GfVec2f value but in Maya as // separate nearClipPlane and farClipPlane attributes. usdAttr = usdCamera.GetClippingRangeAttr(); MPlug nearClipPlug = cameraFn.findPlug( _tokens->MayaCameraAttrNameNearClippingPlane.GetText(), true, &status); CHECK_MSTATUS_AND_RETURN(status, false); MPlug farClipPlug = cameraFn.findPlug( _tokens->MayaCameraAttrNameFarClippingPlane.GetText(), true, &status); CHECK_MSTATUS_AND_RETURN(status, false); if (!_TranslateAnimatedUsdAttributeToPlugs(usdAttr, nearClipPlug, farClipPlug, args, context)) { GfVec2f clippingRange; usdCamera.GetClippingRangeAttr().Get(&clippingRange, timeCode); status = cameraFn.setNearClippingPlane(clippingRange[0]); CHECK_MSTATUS_AND_RETURN(status, false); status = cameraFn.setFarClippingPlane(clippingRange[1]); CHECK_MSTATUS_AND_RETURN(status, false); } return true; }
/* virtual */ bool MayaCameraWriter::writeCameraAttrs(const UsdTimeCode &usdTime, UsdGeomCamera &primSchema) { // Since write() above will take care of any animation on the camera's // transform, we only want to proceed here if: // - We are at the default time and NO attributes on the shape are animated. // OR // - We are at a non-default time and some attribute on the shape IS animated. if (usdTime.IsDefault() == isShapeAnimated()) { return true; } MStatus status; MFnCamera camFn(getDagPath(), &status); CHECK_MSTATUS_AND_RETURN(status, false); // NOTE: We do not use a GfCamera and then call SetFromCamera() below // because we want the xformOps populated by the parent class to survive. // Using SetFromCamera() would stomp them with a single "transform" xformOp. // Set the type of projection. if (camFn.isOrtho()) { primSchema.GetProjectionAttr().Set(UsdGeomTokens->orthographic, usdTime); } else { primSchema.GetProjectionAttr().Set(UsdGeomTokens->perspective, usdTime); } // Setup the aperture. primSchema.GetHorizontalApertureAttr().Set( float(PxrUsdMayaUtil::ConvertInchesToMM( camFn.horizontalFilmAperture() * camFn.lensSqueezeRatio())), usdTime); primSchema.GetVerticalApertureAttr().Set( float(PxrUsdMayaUtil::ConvertInchesToMM( camFn.verticalFilmAperture() * camFn.lensSqueezeRatio())), usdTime); primSchema.GetHorizontalApertureOffsetAttr().Set( float(camFn.horizontalFilmOffset()), usdTime); primSchema.GetVerticalApertureOffsetAttr().Set( float(camFn.verticalFilmOffset()), usdTime); // Set the lens parameters. primSchema.GetFocalLengthAttr().Set( float(camFn.focalLength()), usdTime); // Always export focus distance and fStop regardless of what // camFn.isDepthOfField() says. Downstream tools can choose to ignore or // override them. primSchema.GetFocusDistanceAttr().Set( float(camFn.focusDistance()), usdTime); primSchema.GetFStopAttr().Set( float(camFn.fStop()), usdTime); // Set the clipping planes. GfVec2f clippingRange(camFn.nearClippingPlane(), camFn.farClippingPlane()); primSchema.GetClippingRangeAttr().Set(clippingRange, usdTime); return true; }