Example #1
0
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;
}
Example #2
0
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 );
	
}