Example #1
0
void Warp::fromXml( const XmlTree &xml )
{
	mControlsX = xml.getAttributeValue<int>( "width", 2 );
	mControlsY = xml.getAttributeValue<int>( "height", 2 );
	mBrightness = xml.getAttributeValue<float>( "brightness", 1.0f );

	// load control points
	mPoints.clear();
	for( auto child = xml.begin( "controlpoint" ); child != xml.end(); ++child ) {
		float x = child->getAttributeValue<float>( "x", 0.0f );
		float y = child->getAttributeValue<float>( "y", 0.0f );
		mPoints.push_back( vec2( x, y ) );
	}

	// load blend params
	auto blend = xml.find( "blend" );
	if( blend != xml.end() ) {
		mExponent = blend->getAttributeValue<float>( "exponent", mExponent );

		auto edges = blend->find( "edges" );
		if( edges != blend->end() ) {
			mEdges.x = edges->getAttributeValue<float>( "left", mEdges.x );
			mEdges.y = edges->getAttributeValue<float>( "top", mEdges.y );
			mEdges.z = edges->getAttributeValue<float>( "right", mEdges.z );
			mEdges.w = edges->getAttributeValue<float>( "bottom", mEdges.w );
		}

		auto gamma = blend->find( "gamma" );
		if( gamma != blend->end() ) {
			mGamma.x = gamma->getAttributeValue<float>( "red", mGamma.x );
			mGamma.y = gamma->getAttributeValue<float>( "green", mGamma.y );
			mGamma.z = gamma->getAttributeValue<float>( "blue", mGamma.z );
		}

		auto luminance = blend->find( "luminance" );
		if( luminance != blend->end() ) {
			mLuminance.x = luminance->getAttributeValue<float>( "red", mLuminance.x );
			mLuminance.y = luminance->getAttributeValue<float>( "green", mLuminance.y );
			mLuminance.z = luminance->getAttributeValue<float>( "blue", mLuminance.z );
		}
	}

	// reconstruct warp
	mIsDirty = true;
}