MStatus TransformationMatrixParameterHandler<T>::doSetValue( IECore::ConstParameterPtr parameter, MPlug &plug ) const
{
	typename IECore::TypedParameter<IECore::TransformationMatrix<T> >::ConstPtr p = IECore::runTimeCast<const IECore::TypedParameter<IECore::TransformationMatrix<T> > >( parameter );
	if( !p )
	{
		return MS::kFailure;
	}

	IECore::TransformationMatrix<T> tMatrix = p->getTypedValue();

	if( tMatrix.rotate.order() != Imath::Euler<T>::XYZ )
	{
		IECore::msg(
			IECore::Msg::Error,
			"TransformationMatrixParameterHandler::doSetValue",
			"The rotation order of the parameter '"+parameter->name()+"' is not XYZ, unable to set value."
		);
		return MS::kFailure;
	}

	if( !setVecValues( plug.child( TRANSLATE_INDEX ), tMatrix.translate ) )
		return MS::kFailure;

	if( !setVecValues( plug.child( ROTATE_INDEX ), tMatrix.rotate ) )
		return MS::kFailure;

	if( !setVecValues( plug.child( SCALE_INDEX ), tMatrix.scale ) )
		return MS::kFailure;

	if( !setVecValues( plug.child( SHEAR_INDEX ), tMatrix.shear ) )
		return MS::kFailure;

	if( !setVecValues( plug.child( SCALEPIVOT_INDEX ), tMatrix.scalePivot ) )
		return MS::kFailure;

	if( !setVecValues( plug.child( SCALEPIVOTTRANS_INDEX ), tMatrix.scalePivotTranslation ) )
		return MS::kFailure;

	if( !setVecValues( plug.child( ROTATEPIVOT_INDEX ), tMatrix.rotatePivot ) )
		return MS::kFailure;

	if( !setVecValues( plug.child( ROTATEPIVOTTRANS_INDEX ), tMatrix.rotatePivotTranslation ) )
		return MS::kFailure;

	return MS::kSuccess;
}
MStatus TransformationMatrixParameterHandler<T>::doSetValue( const MPlug &plug, IECore::ParameterPtr parameter ) const
{
	typename IECore::TypedParameter<IECore::TransformationMatrix<T> >::Ptr p = IECore::runTimeCast<IECore::TypedParameter<IECore::TransformationMatrix<T> > >( parameter );
	if( !p )
	{
		return MS::kFailure;
	}

	IECore::TransformationMatrix<T> tMatrix = p->getTypedValue();

	if( tMatrix.rotate.order() != Imath::Euler<T>::XYZ )
	{
		IECore::msg(
			IECore::Msg::Error,
			"TransformationMatrixParameterHandler::doSetValue",
			"The rotation order of the parameter '"+parameter->name()+"' is not XYZ, unable to set value."
		);
		return MS::kFailure;
	}

	std::vector<Imath::Vec3<T> > v;
	v.resize(8);

	for( unsigned int i=0; i<8; i++ )
	{
		if( !getVecValues( plug.child(i), v[i] ) )
			return MS::kFailure;
	}

	tMatrix.translate = v[ TRANSLATE_INDEX ];
	tMatrix.rotate = Imath::Euler<T>(v[ ROTATE_INDEX ]);
	tMatrix.scale = v[ SCALE_INDEX ];
	tMatrix.shear = v[ SHEAR_INDEX ];
	tMatrix.scalePivot = v[ SCALEPIVOT_INDEX ];
	tMatrix.scalePivotTranslation = v[ SCALEPIVOTTRANS_INDEX ];
	tMatrix.rotatePivot = v[ ROTATEPIVOT_INDEX ];
	tMatrix.rotatePivotTranslation = v[ ROTATEPIVOTTRANS_INDEX ];

	p->setTypedValue( tMatrix );

	return MS::kSuccess;
}
Exemplo n.º 3
0
MStatus BoxParameterHandler<T>::doSetValue( IECore::ConstParameterPtr parameter, MPlug &plug ) const
{
	typename IECore::TypedParameter<Box<T> >::ConstPtr p = IECore::runTimeCast<const IECore::TypedParameter<Box<T> > >( parameter );
	if( !p )
	{
		return MS::kFailure;
	}

	if( plug.numChildren() != 2 )
	{
		return MS::kFailure;
	}

	MPlug minPlug = plug.child( 0 );
	MPlug maxPlug = plug.child( 1 );

	if( minPlug.numChildren()!=T::dimensions() || maxPlug.numChildren()!=T::dimensions() )
	{
		return MS::kFailure;
	}

	Box<T> v = p->getTypedValue();
	for( unsigned i=0; i<minPlug.numChildren(); i++ )
	{
		MStatus s = minPlug.child( i ).setValue( v.min[i] );
		if( !s )
		{
			return s;
		}
		s = maxPlug.child( i ).setValue( v.max[i] );
		if( !s )
		{
			return s;
		}
	}

	return MS::kSuccess;
}
MStatus ColorSplineParameterHandler<S>::doSetValue( IECore::ConstParameterPtr parameter, MPlug &plug ) const
{
	assert( parameter );
	typename IECore::TypedParameter< S >::ConstPtr p = IECore::runTimeCast<const IECore::TypedParameter< S > >( parameter );
	if( !p )
	{
		return MS::kFailure;
	}

	MRampAttribute fnRAttr( plug );
	if ( !fnRAttr.isColorRamp() )
	{
		return MS::kFailure;
	}

	const S &spline = p->getTypedValue();

	MStatus s;
	MIntArray indicesToReuse;
	plug.getExistingArrayAttributeIndices( indicesToReuse, &s );
	assert( s );

	int nextNewLogicalIndex = 0;
	if( indicesToReuse.length() )
	{
		nextNewLogicalIndex = 1 + *std::max_element( MArrayIter<MIntArray>::begin( indicesToReuse ), MArrayIter<MIntArray>::end( indicesToReuse ) );
	}
	
	assert( indicesToReuse.length() == fnRAttr.getNumEntries() );

	size_t pointsSizeMinus2 = spline.points.size() - 2;
	unsigned pointIndex = 0;
	unsigned numExpectedPoints = 0;
	for ( typename S::PointContainer::const_iterator it = spline.points.begin(); it != spline.points.end(); ++it, ++pointIndex )
	{
		// we commonly double up the endpoints on cortex splines to force interpolation to the end.
		// maya does this implicitly, so we skip duplicated endpoints when passing the splines into maya.
		// this avoids users having to be responsible for managing the duplicates, and gives them some consistency
		// with the splines they edit elsewhere in maya.
		if( ( pointIndex==1 && *it == *spline.points.begin() ) || ( pointIndex==pointsSizeMinus2 && *it == *spline.points.rbegin() ) )
		{
			continue;
		}

		MPlug pointPlug;
		if( indicesToReuse.length() )
		{
			pointPlug = plug.elementByLogicalIndex( indicesToReuse[0] );
			indicesToReuse.remove( 0 );
		}
		else
		{
			pointPlug = plug.elementByLogicalIndex( nextNewLogicalIndex++ );		
		}
		
		s = pointPlug.child( 0 ).setValue( it->first ); assert( s );
		MPlug colorPlug = pointPlug.child( 1 );
		colorPlug.child( 0 ).setValue( it->second[0] );
		colorPlug.child( 1 ).setValue( it->second[1] );
		colorPlug.child( 2 ).setValue( it->second[2] );
		// hardcoding interpolation of 3 (spline) because the MRampAttribute::MInterpolation enum values don't actually
		// correspond to the necessary plug values at all.
		s = pointPlug.child( 2 ).setValue( 3 ); assert( s );

		numExpectedPoints++;
	}

	// delete any of the original indices which we didn't reuse. we can't use MRampAttribute::deleteEntries
	// here as it's utterly unreliable.
	if( indicesToReuse.length() )
	{
		MString plugName = plug.name();
		MObject node = plug.node();
		MFnDagNode fnDAGN( node );
		if( fnDAGN.hasObj( node ) )
		{
			plugName = fnDAGN.fullPathName() + "." + plug.partialName();
		}
		for( unsigned i=0; i<indicesToReuse.length(); i++ )
		{
			// using mel because there's no equivalant api method as far as i know.
			MString command = "removeMultiInstance -b true \"" + plugName + "[" + indicesToReuse[i] + "]\"";
			s = MGlobal::executeCommand( command );
			assert( s );
			if( !s )
			{
				return s;
			}
		}
	}

#ifndef NDEBUG
	{
		assert( fnRAttr.getNumEntries() == numExpectedPoints );

		MIntArray indices;
		MFloatArray positions;
		MColorArray colors;
		MIntArray interps;
		fnRAttr.getEntries( indices, positions, colors, interps, &s );
		assert( s );
		assert( numExpectedPoints == positions.length() );
		assert( numExpectedPoints == colors.length() );
		assert( numExpectedPoints == interps.length() );
		assert( numExpectedPoints == indices.length() );

		for ( unsigned i = 0; i < positions.length(); i++ )
		{
			float position = positions[ i ];
			const MVector color( colors[ i ][ 0 ], colors[ i ][ 1 ], colors[ i ][ 2 ] );

			bool found = false;

			for ( typename S::PointContainer::const_iterator it = spline.points.begin(); it != spline.points.end() && !found; ++it )
			{
				MVector color2( it->second[0], it->second[1], it->second[2] );
				if ( fabs( it->first - position ) < 1.e-3f && ( color2 - color ).length() < 1.e-3f )
				{
					found = true;
				}
			}
			assert( found );
		}
	}
#endif

	return MS::kSuccess;
}