Пример #1
0
MStatus MeshParameterHandler::doSetValue( IECore::ConstParameterPtr parameter, MPlug &plug ) const
{
	IECore::ConstObjectParameterPtr p = IECore::runTimeCast<const IECore::ObjectParameter>( parameter );
	if( !p )
	{
		return MS::kFailure;
	}

	MFnMeshData fnData;
	MObject data = fnData.create();

	/// \todo Pull in userData from parameter to set up conversion parameters
	ToMayaObjectConverterPtr converter = ToMayaObjectConverter::create( p->getValue(), MFn::kMeshData );
	assert(converter);
	bool conversionSuccess = converter->convert( data );

	if ( !conversionSuccess )
	{
		return MS::kFailure;
	}

	/// \todo It seems like this can occassionally fail, usually with an empty mesh, but sometimes not. Try to establish exactly why.
	plug.setValue( data );

	return MS::kSuccess;
}
MStatus ObjectParameterHandler::doSetValue( IECore::ConstParameterPtr parameter, MPlug &plug ) const
{
	IECore::ConstObjectParameterPtr p = IECore::runTimeCast<const IECore::ObjectParameter>( parameter );
	if( !p )
	{
		return MS::kFailure;
	}

	// Keep trying all the available handlers until we find one that works.
	/// \todo Investigate whether we can do a parameter->getValue() here and just get the handler which represents it
	for (IECore::ObjectParameter::TypeIdSet::const_iterator it = p->validTypes().begin(); it != p->validTypes().end(); ++it)
	{
		ConstParameterHandlerPtr h = ParameterHandler::create( *it );
		if (h)
		{
			if ( h->doSetValue( parameter, plug) )
			{
				return MS::kSuccess;
			}
		}
	}

	MStatus s;

	MFnPluginData fnData;
	MObject plugData = fnData.create( ObjectData::id );
	assert( plugData != MObject::kNullObj );

	s = fnData.setObject( plugData );
	assert(s);

	ObjectData* data = dynamic_cast<ObjectData *>( fnData.data(&s) );
	assert(s);
	assert(data);

	data->setObject( p->getValue()->copy() );
	return plug.setValue( plugData );
}
MStatus ObjectParameterHandler::doUpdate( IECore::ConstParameterPtr parameter, MPlug &plug ) const
{
	IECore::ConstObjectParameterPtr p = IECore::runTimeCast<const IECore::ObjectParameter>( parameter );
	if( !p )
	{
		return MS::kFailure;
	}

	MObject attribute = plug.attribute();
	MFnGenericAttribute fnGAttr( attribute );
	if( !fnGAttr.hasObj( attribute ) )
	{
		return MS::kFailure;
	}

	fnGAttr.addAccept( ObjectData::id );
	// maya has an odd behaviour whereby a generic attribute with only one accepted datatype will
	// transform itself into a typed attribute after file save and load. here we add an accept
	// for a second dummy datatype to ensure that the attribute will still be a generic attribute
	// when saved and loaded.
	fnGAttr.addAccept( DummyDataId );

	for (IECore::ObjectParameter::TypeIdSet::const_iterator it = p->validTypes().begin(); it != p->validTypes().end(); ++it)
	{
		ConstParameterHandlerPtr h = ParameterHandler::create( *it );
		if (h)
		{
			if ( !h->doUpdate( parameter, plug ) )
			{
				return MS::kFailure;
			}
		}
	}

	return finishUpdating( parameter, plug );
}