Пример #1
0
		/// Returns the arnold shader to assign to the procedural.
		AtNode *arnoldShader()
		{	
			bool overrideShaders = false;
			MPlug plug = FindMayaObjectPlug( "overrideProceduralShaders" );
			if( !plug.isNull() )
			{
				// if we've been told explicitly not to override the shaders
				// in the procedurals, then early out.
				overrideShaders = plug.asBool();
				if( !overrideShaders )
				{
					return 0;
				}
			}
			
			unsigned instNumber = m_dagPath.isInstanced() ? m_dagPath.instanceNumber() : 0;
			MPlug shadingGroupPlug = GetNodeShadingGroup(m_dagPath.node(), instNumber);
			
			if( !overrideShaders )
			{
				// if we weren't explicitly told to override the shaders, then
				// decide whether to or not based on whether a non-default
				// shader has been applied to the shape by the user.
				MObject shadingGroupNode = shadingGroupPlug.node();
				MFnDependencyNode fnShadingGroupNode( shadingGroupNode );
				if( fnShadingGroupNode.name() != "initialShadingGroup" )
				{
					overrideShaders = true;
				}
			}
			
			if( overrideShaders )
			{
				return ExportNode( shadingGroupPlug );
			}
			else
			{
				return 0;
			}
		}
                virtual void ExportUserAttrs( AtNode *node )
                {
                        // Get the optional attributes and export them as user vars

                        MPlug plug = FindMayaObjectPlug( "shaderAssignation" );
                        if( !plug.isNull() )
                        {
                                AiNodeDeclare( node, "shaderAssignation", "constant STRING" );
                                AiNodeSetStr( node, "shaderAssignation", plug.asString().asChar() );
                        }

                        plug = FindMayaObjectPlug( "displacementAssignation" );
                        if( !plug.isNull() )
                        {
                                AiNodeDeclare( node, "displacementAssignation", "constant STRING" );
                                AiNodeSetStr( node, "displacementAssignation", plug.asString().asChar() );
                        }

                        plug = FindMayaObjectPlug( "shaderAssignmentfile" );
                        if( !plug.isNull() )
                        {
                                AiNodeDeclare( node, "shaderAssignmentfile", "constant STRING" );
                                AiNodeSetStr( node, "shaderAssignmentfile", plug.asString().asChar() );
                        }

                        plug = FindMayaObjectPlug( "overrides" );
                        if( !plug.isNull() )
                        {
                                AiNodeDeclare( node, "overrides", "constant STRING" );
                                AiNodeSetStr( node, "overrides", plug.asString().asChar() );
                        }

                        plug = FindMayaObjectPlug( "overridefile" );
                        if( !plug.isNull() )
                        {
                                AiNodeDeclare( node, "overridefile", "constant STRING" );
                                AiNodeSetStr( node, "overridefile", plug.asString().asChar() );
                        }

                        plug = FindMayaObjectPlug( "userAttributes" );
                        if( !plug.isNull() )
                        {
                                AiNodeDeclare( node, "userAttributes", "constant STRING" );
                                AiNodeSetStr( node, "userAttributes", plug.asString().asChar() );
                        }

                        plug = FindMayaObjectPlug( "userAttributesfile" );
                        if( !plug.isNull() )
                        {
                                AiNodeDeclare( node, "userAttributesfile", "constant STRING" );
                                AiNodeSetStr( node, "userAttributesfile", plug.asString().asChar() );
                        }

                        plug = FindMayaObjectPlug( "skipJson" );
                        if( !plug.isNull() )
                        {
                                AiNodeDeclare( node, "skipJson", "constant BOOL" );   
                                AiNodeSetBool( node, "skipJson", plug.asBool() );
                        }

                        plug = FindMayaObjectPlug( "skipShaders" );
                        if( !plug.isNull() )
                        {
                                AiNodeDeclare( node, "skipShaders", "constant BOOL" );   
                                AiNodeSetBool( node, "skipShaders", plug.asBool() );
                        }

                        plug = FindMayaObjectPlug( "skipOverrides" );
                        if( !plug.isNull() )
                        {
                                AiNodeDeclare( node, "skipOverrides", "constant BOOL" );   
                                AiNodeSetBool( node, "skipOverrides", plug.asBool() );
                        }

                        plug = FindMayaObjectPlug( "skipUserAttributes" );
                        if( !plug.isNull() )
                        {
                                AiNodeDeclare( node, "skipUserAttributes", "constant BOOL" );   
                                AiNodeSetBool( node, "skipUserAttributes", plug.asBool() );
                        }

                        plug = FindMayaObjectPlug( "skipDisplacements" );
                        if( !plug.isNull() )
                        {
                                AiNodeDeclare( node, "skipDisplacements", "constant BOOL" );                          
                                AiNodeSetBool( node, "skipDisplacements", plug.asBool() );
                        }

                        plug = FindMayaObjectPlug( "objectPattern" );
                        if( !plug.isNull() )
                        {
                                AiNodeDeclare( node, "objectPattern", "constant STRING" );
                                AiNodeSetStr( node, "objectPattern", plug.asString().asChar() );
                        }                       
                        
                        plug = FindMayaObjectPlug( "assShaders" );
                        if( !plug.isNull() )
                        {
                                AiNodeDeclare( node, "assShaders", "constant STRING" );
                                AiNodeSetStr( node, "assShaders", plug.asString().asChar() );
                        }

                        plug = FindMayaObjectPlug( "radiusPoint" );
                        if( !plug.isNull() )
                        {
                                AiNodeDeclare( node, "radiusPoint", "constant FLOAT" );
                                AiNodeSetFlt( node, "radiusPoint", plug.asFloat() );
                        }

                        plug = FindMayaObjectPlug( "radiusCurve" );
                        if( !plug.isNull() )
                        {
                                AiNodeDeclare( node, "radiusCurve", "constant FLOAT" );
                                AiNodeSetFlt( node, "radiusCurve", plug.asFloat() );
                        }

                        plug = FindMayaObjectPlug( "modeCurve" );
                        if( !plug.isNull() )
                        {
                                AiNodeDeclare( node, "modeCurve", "constant STRING" );

                                int modeCurveInt = plug.asInt();

                                if (modeCurveInt == 1)
                                   AiNodeSetStr(node, "modeCurve", "thick");
                                else if (modeCurveInt == 2)
                                   AiNodeSetStr(node, "modeCurve", "oriented");
                                else
                                   AiNodeSetStr(node, "modeCurve", "ribbon");                               
                        }

                        plug = FindMayaObjectPlug( "scaleVelocity" );
                        if( !plug.isNull() )
                        {
                                AiNodeDeclare( node, "scaleVelocity", "constant FLOAT" );
                                AiNodeSetFlt( node, "scaleVelocity", plug.asFloat() );
                        }

                }
Пример #3
0
		virtual void ExportProcedural( AtNode *node )
		{
			// do basic node export
			
			ExportMatrix( node, 0 );
			
			AtNode *shader = arnoldShader();
			if( shader )
			{
				AiNodeSetPtr( node, "shader", shader );
			}
			
			AiNodeSetInt( node, "visibility", ComputeVisibility() );
			
			MPlug plug = FindMayaObjectPlug( "receiveShadows" );
			if( !plug.isNull() )
			{
				AiNodeSetBool( node, "receive_shadows", plug.asBool() );
			}
			
			plug = FindMayaObjectPlug( "aiSelfShadows" );
			if( !plug.isNull() )
			{
				AiNodeSetBool( node, "self_shadows", plug.asBool() );
			}
			
			plug = FindMayaObjectPlug( "aiOpaque" );
			if( !plug.isNull() )
			{
				AiNodeSetBool( node, "opaque", plug.asBool() );
			}
			
			// export any shading groups or displacement shaders which look like they
			// may be connected to procedural parameters. this ensures that maya shaders
			// the procedural will expect to find at rendertime will be exported to the
			// ass file (they otherwise might not be if they're not assigned to any objects).
			
			exportShadingInputs();
			
			// now set the procedural-specific parameters
			
			MFnDagNode fnDagNode( m_dagPath );
			MBoundingBox bound = fnDagNode.boundingBox();
			
			AiNodeSetPnt( node, "min", bound.min().x, bound.min().y, bound.min().z );
			AiNodeSetPnt( node, "max", bound.max().x, bound.max().y, bound.max().z );
			
			const char *dsoPath = getenv( "IECOREARNOLD_PROCEDURAL_PATH" );
			AiNodeSetStr( node, "dso", dsoPath ? dsoPath : "ieProcedural.so" );
			
			AiNodeDeclare( node, "className", "constant STRING" );
			AiNodeDeclare( node, "classVersion", "constant INT" );
			AiNodeDeclare( node, "parameterValues", "constant ARRAY STRING" );
			
			// cast should be ok as we're registered to only work on procedural holders
			IECoreMaya::ProceduralHolder *pHolder = static_cast<IECoreMaya::ProceduralHolder *>( fnDagNode.userNode() );
			
			std::string className;
			int classVersion;
			IECore::ParameterisedProceduralPtr procedural = pHolder->getProcedural( &className, &classVersion );
			
			AiNodeSetStr( node, "className", className.c_str() );
			AiNodeSetInt( node, "classVersion", classVersion );
			
			IECorePython::ScopedGILLock gilLock;
			try
			{
				boost::python::object parser = IECoreMaya::PythonCmd::globalContext()["IECore"].attr( "ParameterParser" )();
				boost::python::object serialised = parser.attr( "serialise" )( procedural->parameters() );
				
				size_t numStrings = IECorePython::len( serialised );
				AtArray *stringArray = AiArrayAllocate( numStrings, 1, AI_TYPE_STRING );
				for( size_t i=0; i<numStrings; i++ )
				{
					std::string s = boost::python::extract<std::string>( serialised[i] );
					// hack to workaround ass parsing errors
					/// \todo Remove when we get the Arnold version that fixes this
					for( size_t c = 0; c<s.size(); c++ )
					{
						if( s[c] == '#' )
						{
							s[c] = '@';
						}
					}
					AiArraySetStr( stringArray, i, s.c_str() );
				}
				
				AiNodeSetArray( node, "parameterValues", stringArray );
			}
			catch( boost::python::error_already_set )
			{
				PyErr_Print();
			}
		
		}
                virtual void ExportProcedural( AtNode *node )
                {
                        // do basic node export
                        ExportMatrix( node, 0 );

                        // AiNodeSetPtr( node, "shader", arnoldShader(node) );


                        AiNodeSetInt( node, "visibility", ComputeVisibility() );

                        MPlug plug = FindMayaObjectPlug( "receiveShadows" );
                        if( !plug.isNull() )
                        {
                                AiNodeSetBool( node, "receive_shadows", plug.asBool() );
                        }

                        plug = FindMayaObjectPlug( "aiSelfShadows" );
                        if( !plug.isNull() )
                        {
                                AiNodeSetBool( node, "self_shadows", plug.asBool() );
                        }

                        plug = FindMayaObjectPlug( "aiOpaque" );
                        if( !plug.isNull() )
                        {
                                AiNodeSetBool( node, "opaque", plug.asBool() );
                        }

                        // now set the procedural-specific parameters

                        AiNodeSetBool( node, "load_at_init", true ); // just for now so that it can load the shaders at the right time

                        MFnDagNode fnDagNode( m_dagPath );
                        MBoundingBox bound = fnDagNode.boundingBox();

                        AiNodeSetPnt( node, "min", bound.min().x-m_dispPadding, bound.min().y-m_dispPadding, bound.min().z-m_dispPadding );
                        AiNodeSetPnt( node, "max", bound.max().x+m_dispPadding, bound.max().y, bound.max().z+m_dispPadding );

                        const char *dsoPath = getenv( "ALEMBIC_ARNOLD_PROCEDURAL_PATH" );
                        AiNodeSetStr( node, "dso",  dsoPath ? dsoPath : "bb_AlembicArnoldProcedural.so" );

                        // Set the parameters for the procedural

                        //abcFile path
                        MString abcFile = fnDagNode.findPlug("cacheFileName").asString().expandEnvironmentVariablesAndTilde();

                        //object path
                        MString objectPath = fnDagNode.findPlug("cacheGeomPath").asString();

                        //object pattern
                        MString objectPattern = "*";

                        plug = FindMayaObjectPlug( "objectPattern" );
                        if (!plug.isNull() )
                        {
                              if (plug.asString() != "")
                              {
                                objectPattern = plug.asString();
                              }
                        }

                        //object pattern
                        MString excludePattern = "";

                        plug = FindMayaObjectPlug( "excludePattern" );
                        if (!plug.isNull() )
                        {
                              if (plug.asString() != "")
                              {
                                excludePattern = plug.asString();
                              }
                        }

                        float shutterOpen = 0.0;
                        plug = FindMayaObjectPlug( "shutterOpen" );
                        if (!plug.isNull() )
                        {
                                shutterOpen = plug.asFloat();
                        }

                        float shutterClose = 0.0;
                        plug = FindMayaObjectPlug( "shutterClose" );
                        if (!plug.isNull() )
                        {
                                shutterClose = plug.asFloat();
                        }

                        float timeOffset = 0.0;
                        plug = FindMayaObjectPlug( "timeOffset" );
                        if (!plug.isNull() )
                        {
                                timeOffset = plug.asFloat();
                        }

                        int subDIterations = 0;
                        plug = FindMayaObjectPlug( "ai_subDIterations" );
                        if (!plug.isNull() )
                        {
                                subDIterations = plug.asInt();
                        }

                        MString nameprefix = "";
                        plug = FindMayaObjectPlug( "namePrefix" );
                        if (!plug.isNull() )
                        {
                                nameprefix = plug.asString();
                        }

                        // bool exportFaceIds = fnDagNode.findPlug("exportFaceIds").asBool();

                        bool makeInstance = true; // always on for now
                        plug = FindMayaObjectPlug( "makeInstance" );
                        if (!plug.isNull() )
                        {
                                makeInstance = plug.asBool();
                        }
                        
                        bool flipv = false; 
                        plug = FindMayaObjectPlug( "flipv" );
                        if (!plug.isNull() )
                        {
                                flipv = plug.asBool();
                        }

                        bool invertNormals = false; 
                        plug = FindMayaObjectPlug( "invertNormals" );
                        if (!plug.isNull() )
                        {
                                invertNormals = plug.asBool();
                        }
                        
                        short i_subDUVSmoothing = 1;
                        plug = FindMayaObjectPlug( "ai_subDUVSmoothing" );
                        if (!plug.isNull() )
                        {
                                i_subDUVSmoothing = plug.asShort();
                        }

                        MString  subDUVSmoothing;

                        switch (i_subDUVSmoothing)
                        {
                          case 0:
                            subDUVSmoothing = "pin_corners";
                            break;
                          case 1:
                            subDUVSmoothing = "pin_borders";
                            break;
                          case 2:
                            subDUVSmoothing = "linear";
                            break;
                          case 3:
                            subDUVSmoothing = "smooth";
                            break;
                          default :
                            subDUVSmoothing = "pin_corners";
                            break;
                        }

                        MTime curTime = MAnimControl::currentTime();
                        // fnDagNode.findPlug("time").getValue( frame );

                        // MTime frameOffset;
                        // fnDagNode.findPlug("timeOffset").getValue( frameOffset );

                        float time = curTime.as(MTime::kFilm)+timeOffset;

                        MString argsString;
                        if (objectPath != "|"){
                                argsString += "-objectpath ";
                                // convert "|" to "/"

                                argsString += MString(replace_all(objectPath,"|","/").c_str());
                        }
                        if (objectPattern != "*"){
                                argsString += "-pattern ";
                                argsString += objectPattern;
                        }
                        if (excludePattern != ""){
                                argsString += "-excludepattern ";
                                argsString += excludePattern;
                        }
                        if (shutterOpen != 0.0){
                                argsString += " -shutteropen ";
                                argsString += shutterOpen;
                        }
                        if (shutterClose != 0.0){
                                argsString += " -shutterclose ";
                                argsString += shutterClose;
                        }
                        if (subDIterations != 0){
                                argsString += " -subditerations ";
                                argsString += subDIterations;
                                argsString += " -subduvsmoothing ";
                                argsString += subDUVSmoothing;
                        }
                        if (makeInstance){
                                argsString += " -makeinstance ";
                        }
                        if (nameprefix != ""){
                                argsString += " -nameprefix ";
                                argsString += nameprefix;
                        }
                        if (flipv){
                                argsString += " -flipv ";
                        }
                        if (invertNormals){
                                argsString += " -invertNormals ";
                        }
                        argsString += " -filename ";
                        argsString += abcFile;
                        argsString += " -frame ";
                        argsString += time;

                        if (m_displaced){

                            argsString += " -disp_map ";
                            argsString += AiNodeGetName(m_dispNode);

                        }

                        AiNodeSetStr(node, "data", argsString.asChar());

                        ExportUserAttrs(node);

                        // Export light linking per instance
                        ExportLightLinking(node);

                }