IECore::CameraPtr GafferScene::camera( const ScenePlug *scene, const ScenePlug::ScenePath &cameraPath, const IECore::CompoundObject *globals ) { ConstCompoundObjectPtr computedGlobals; if( !globals ) { computedGlobals = scene->globalsPlug()->getValue(); globals = computedGlobals.get(); } std::string cameraName; ScenePlug::pathToString( cameraPath, cameraName ); if( !exists( scene, cameraPath ) ) { throw IECore::Exception( "Camera \"" + cameraName + "\" does not exist" ); } IECore::ConstCameraPtr constCamera = runTimeCast<const IECore::Camera>( scene->object( cameraPath ) ); if( !constCamera ) { std::string path; ScenePlug::pathToString( cameraPath, path ); throw IECore::Exception( "Location \"" + cameraName + "\" is not a camera" ); } IECore::CameraPtr camera = constCamera->copy(); camera->setName( cameraName ); const BoolData *cameraBlurData = globals->member<BoolData>( "option:render:cameraBlur" ); const bool cameraBlur = cameraBlurData ? cameraBlurData->readable() : false; camera->setTransform( transform( scene, cameraPath, shutter( globals ), cameraBlur ) ); applyCameraGlobals( camera.get(), globals ); return camera; }
void Render::outputCamera( const ScenePlug *scene, const IECore::CompoundObject *globals, IECore::Renderer *renderer ) const { // get the camera from the scene const StringData *cameraPathData = globals->member<StringData>( "render:camera" ); IECore::CameraPtr camera = 0; if( cameraPathData ) { ScenePlug::ScenePath cameraPath; ScenePlug::stringToPath( cameraPathData->readable(), cameraPath ); IECore::ConstCameraPtr constCamera = runTimeCast<const IECore::Camera>( scene->object( cameraPath ) ); if( constCamera ) { camera = constCamera->copy(); const BoolData *cameraBlurData = globals->member<BoolData>( "render:cameraBlur" ); const bool cameraBlur = cameraBlurData ? cameraBlurData->readable() : false; camera->setTransform( transform( scene, cameraPath, shutter( globals ), cameraBlur ) ); } } if( !camera ) { camera = new IECore::Camera(); } // apply the resolution const V2iData *resolutionData = globals->member<V2iData>( "render:resolution" ); if( resolutionData ) { camera->parameters()["resolution"] = resolutionData->copy(); } camera->addStandardParameters(); // apply the shutter camera->parameters()["shutter"] = new V2fData( shutter( globals ) ); // and output camera->render( renderer ); }
void SceneView::updateLookThrough() { Context::Scope scopedContext( getContext() ); const ScenePlug *scene = preprocessedInPlug<ScenePlug>(); ConstCompoundObjectPtr globals = scene->globalsPlug()->getValue(); string cameraPathString; IECore::CameraPtr camera; if( lookThroughEnabledPlug()->getValue() ) { cameraPathString = lookThroughCameraPlug()->getValue(); if( cameraPathString.empty() ) { if( const StringData *cameraPathData = globals->member<StringData>( "render:camera" ) ) { cameraPathString = cameraPathData->readable(); } } if( !cameraPathString.empty() ) { ScenePlug::ScenePath cameraPath; ScenePlug::stringToPath( cameraPathString, cameraPath ); try { ConstCameraPtr constCamera = runTimeCast<const IECore::Camera>( scene->object( cameraPath ) ); if( constCamera ) { camera = constCamera->copy(); camera->setTransform( new MatrixTransform( scene->fullTransform( cameraPath ) ) ); // if the camera has an existing screen window, remove it. // if we didn't, it would conflict with the resolution we set // below, yielding squashed/stretched images. /// \todo Properly specify how cameras are represented in Gaffer /// (the Cortex representation is very renderer-centric, with no /// real world parameters like film back) so that this isn't necessary, /// and add nice overlays for resolution gate etc. camera->parameters().erase( "screenWindow" ); } } catch( ... ) { // if an invalid path has been entered for the camera, computation will fail. // we can just ignore that and fall through to lock to the current camera instead. cameraPathString = ""; } } if( !camera ) { // we couldn't find a render camera to lock to, but we can lock to the current // camera instead. camera = viewportGadget()->getCamera()->copy(); } } if( camera ) { camera->parameters()["resolution"] = new V2iData( viewportGadget()->getViewport() ); viewportGadget()->setCamera( camera ); viewportGadget()->setCameraEditable( false ); StringVectorDataPtr invisiblePaths = new StringVectorData(); invisiblePaths->writable().push_back( cameraPathString ); hideFilter()->pathsPlug()->setValue( invisiblePaths ); } else { viewportGadget()->setCameraEditable( true ); hideFilter()->pathsPlug()->setToDefault(); } }