Skip to content

Commit

Permalink
Add camera shift and shake
Browse files Browse the repository at this point in the history
  • Loading branch information
est77 committed Aug 30, 2018
1 parent a888c0b commit 672d476
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
31 changes: 24 additions & 7 deletions src/appleseedmaya/exporters/cameraexporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@ void CameraExporter::createEntities(
const AppleseedSession::Options& options,
const AppleseedSession::MotionBlurSampleTimes& motionBlurSampleTimes)
{
MFnCamera camera(dagPath());
MFnCamera cameraFn(dagPath());

const asr::CameraFactoryRegistrar& cameraFactories =
project().get_factory_registrar<asr::Camera>();

const asr::ICameraFactory* cameraFactory = nullptr;
asr::ParamArray cameraParams;

if (camera.isOrtho())
if (cameraFn.isOrtho())
{
cameraFactory = cameraFactories.lookup("orthographic_camera");
// TODO: fetch ortho camera params here.
Expand All @@ -107,15 +107,14 @@ void CameraExporter::createEntities(
else
cameraFactory = cameraFactories.lookup("pinhole_camera");

// Maya's aperture is given in inches so convert to cm and then to meters.
double horizontalFilmAperture = camera.horizontalFilmAperture() * 2.54 * 0.01;
double verticalFilmAperture = camera.verticalFilmAperture() * 2.54 * 0.01;
double horizontalFilmAperture = inchesToMeters(cameraFn.horizontalFilmAperture());
double verticalFilmAperture = inchesToMeters(cameraFn.verticalFilmAperture());

const double imageAspect = static_cast<double>(options.m_width) / options.m_height;

// Handle film fits.
// Reference: http://around-the-corner.typepad.com/adn/2012/11/maya-stereoscopic.html
MFnCamera::FilmFit filmFit = camera.filmFit();
MFnCamera::FilmFit filmFit = cameraFn.filmFit();
const double filmAspect = horizontalFilmAperture / verticalFilmAperture;

if (filmFit == MFnCamera::kFillFilmFit)
Expand All @@ -140,8 +139,21 @@ void CameraExporter::createEntities(
"film_dimensions",
asf::Vector2d(horizontalFilmAperture, verticalFilmAperture));

// Shift and camera shake.
double shift_x = inchesToMeters(cameraFn.horizontalFilmOffset());
double shift_y = inchesToMeters(cameraFn.verticalFilmOffset());

if (cameraFn.shakeEnabled())
{
shift_x += cameraFn.horizontalShake();
shift_y += cameraFn.verticalShake();
}

cameraParams.insert("shift_x", shift_x);
cameraParams.insert("shift_y", shift_y);

// Maya's focal_length is given in mm so we convert it to meters.
cameraParams.insert("focal_length", camera.focalLength() * 0.001);
cameraParams.insert("focal_length", cameraFn.focalLength() * 0.001);

if (dofEnabled)
{
Expand Down Expand Up @@ -172,3 +184,8 @@ bool CameraExporter::isRenderable(const MDagPath& path)
AttributeUtils::get(path.node(), "renderable", isRenderable);
return isRenderable;
}

double CameraExporter::inchesToMeters(const double x)
{
return x * 2.54 * 0.01;
}
2 changes: 2 additions & 0 deletions src/appleseedmaya/exporters/cameraexporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class CameraExporter

static bool isRenderable(const MDagPath& path);

static double inchesToMeters(const double x);

AppleseedEntityPtr<renderer::Camera> m_camera;
};

Expand Down

0 comments on commit 672d476

Please sign in to comment.