Пример #1
0
// When mantra determines that the bounding box needs to be rendered, the 
// render method is called. At this point, the procedural can either 
// generate geometry (VRAY_Procedural::openGeometryObject()) or it can 
// generate further procedurals (VRAY_Procedural::openProceduralObject()).
void
VRAY_ieProcedural::render()
{
	initialisePython();
	ParameterisedProceduralPtr parameterisedProcedural = 0;
	ScopedGILLock giLock;
	try
	{
		object ieCore = g_mainModuleNamespace["IECore"];
		object classLoader = ieCore.attr( "ClassLoader" ).attr( "defaultProceduralLoader" )();
		object procedural = classLoader.attr( "load" )( m_className.buffer(), m_classVersion )();
		boost::python::list params;
		UT_WorkArgs argv;
		if (m_parameterString.tokenize(argv, ","))
		{
            // The Cortex Mantra Inject otl parses the parameters of a 
            // SOP_ProceduralHolder and replaces empty values with a '!' 
            // character to make them easier to parse here.
            // 
            // This hack is upsetting, a pure python procedural in the style 
            // of IECoreRI iePython.dso could parse these parameters correctly
            // like python/IECoreRI/ExecuteProcedural.py
			for (int i = 0; i < argv.getArgc(); i++) 
			{
				std::string s(argv[i]);
				if (s == "!")
				{
					params.append(std::string(""));
				}
				else
				{
					params.append(s);
				}
			}
		}
		object parameterParser = ieCore.attr( "ParameterParser" )();
		parameterParser.attr( "parse" )( params, procedural.attr( "parameters" )() );
		parameterisedProcedural = extract<ParameterisedProceduralPtr>( procedural );
	}
	catch( const error_already_set &e )
	{
		PyErr_Print();
	}
	catch( const std::exception &e )
	{
		msg( Msg::Error, "VRAY_ieProcedural", e.what() );
	}
	catch( ... )
	{
		msg( Msg::Error, "VRAY_ieProcedural", "Caught unknown exception" );
	}
	if( parameterisedProcedural )
	{
		IECoreMantra::RendererPtr renderer = new IECoreMantra::Renderer( this );
		parameterisedProcedural->render( renderer.get(), false, false, true, true ); 
	}
}
Пример #2
0
ConstObjectPtr SOP_SceneCacheSource::modifyObject( const IECore::Object *object, Parameters &params )
{
	ConstObjectPtr result = object;
	
	if ( params.attributeCopy != "" )
	{
		if ( const Primitive *primitive = IECore::runTimeCast<const Primitive>( object ) )
		{
			PrimitivePtr modified = 0;
			const PrimitiveVariableMap &variables = primitive->variables;
			
			UT_WorkArgs pairs;
			UT_String args( params.attributeCopy );
			args.tokenize( pairs, " " );
			for ( int i = 0; i < pairs.entries(); ++i )
			{
				UT_WorkArgs values;
				UT_String pair( pairs[i] );
				pair.tokenize( values, ":" );
				if ( values.entries() != 2 )
				{
					continue;
				}
				
				PrimitiveVariableMap::const_iterator it = variables.find( values[0] );
				if ( it != variables.end() )
				{
					if ( !modified )
					{
						modified = primitive->copy();
					}
					
					// we need to copy the data in case either copy will be modified later on
					const PrimitiveVariable &orig = modified->variables[values[0]];
					modified->variables[values[1]] = PrimitiveVariable( orig.interpolation, orig.data->copy() );
				}
			}
			
			if ( modified )
			{
				result = modified;
			}
		}
	}
	
	return result;
}
Пример #3
0
void HoudiniScene::readTags( NameList &tags, bool includeChildren ) const
{
	tags.clear();
	
	const OP_Node *node = retrieveNode();
	if ( !node )
	{
		return;
	}
	
	// add user supplied tags if we're not inside a SOP
	if ( !m_contentIndex && node->hasParm( pTags.getToken() ) )
	{
		UT_String parmTagStr;
		node->evalString( parmTagStr, pTags.getToken(), 0, 0 );
		if ( !parmTagStr.equal( UT_String::getEmptyString() ) )
		{
			UT_WorkArgs tokens;
			parmTagStr.tokenize( tokens, " " );
			for ( int i = 0; i < tokens.getArgc(); ++i )
			{
				tags.push_back( tokens[i] );
			}
		}
	}
	
	// add tags from the registered tag readers
	std::vector<CustomTagReader> &tagReaders = customTagReaders();
	for ( std::vector<CustomTagReader>::const_iterator it = tagReaders.begin(); it != tagReaders.end(); ++it )
	{
		NameList values;
		it->m_read( node, values, includeChildren );
		tags.insert( tags.end(), values.begin(), values.end() );
	}
	
	// add tags based on primitive groups
	OBJ_Node *contentNode = retrieveNode( true )->castToOBJNode();
	if ( contentNode && contentNode->getObjectType() == OBJ_GEOMETRY && m_splitter )
	{
		GU_DetailHandle newHandle = m_splitter->split( contentPathValue() );
		if ( !newHandle.isNull() )
		{
			GU_DetailHandleAutoReadLock readHandle( newHandle );
			if ( const GU_Detail *geo = readHandle.getGdp() )
			{
				GA_Range prims = geo->getPrimitiveRange();
				for ( GA_GroupTable::iterator<GA_ElementGroup> it=geo->primitiveGroups().beginTraverse(); !it.atEnd(); ++it )
				{
					GA_PrimitiveGroup *group = static_cast<GA_PrimitiveGroup*>( it.group() );
					if ( group->getInternal() || group->isEmpty() )
					{
						continue;
					}
					
					const UT_String &groupName = group->getName();
					if ( groupName.startsWith( tagGroupPrefix ) && group->containsAny( prims ) )
					{
						UT_String tag;
						groupName.substr( tag, tagGroupPrefix.length() );
						tag.substitute( "_", ":" );
						tags.push_back( tag.buffer() );
					}
				}
			}
		}
	}
}
Пример #4
0
OP_ERROR
SOP_IdBlast::cookMySop(OP_Context &context)
{
    fpreal 		        now;
    exint                       id; 

    GA_Offset                   start, end;

    GA_PointGroup               *group;

    GA_ROAttributeRef           id_gah;
    GA_ROPageHandleI            id_ph;

    UT_String                   pattern;
    UT_WorkArgs                 tokens;

    IdOffsetMap                 id_map, srcid_map;
    GroupIdMapPair              pair;

    now = context.getTime();

    if (lockInputs(context) >= UT_ERROR_ABORT)
        return error();

    // Duplicate the incoming geometry.
    duplicateSource(0, context);

    // Get the id pattern.
    IDS(pattern, now);
    // If it's emptry, don't do anything.
    if (pattern.length() == 0)
    {
        unlockInputs();
        return error();
    }

    // Tokenize the range so we can handle multiple blocks.
    pattern.tokenize(tokens, " ");

    // Try to find the 'id' point attribute on the 1st input geometry.
    id_gah = gdp->findPointAttribute(GA_SCOPE_PUBLIC, "id");
    // If it doesn't exist, display a node error message and exit.
    if (id_gah.isInvalid())
    {
        addError(SOP_MESSAGE, "Input geometry has no 'id' attribute.");
        unlockInputs();
        return error();
    }
  
    // Bind the page handles to the attributes.
    id_ph.bind(id_gah.getAttribute());

    // Iterate over all the points we selected.
    for (GA_Iterator it(gdp->getPointRange()); it.blockAdvance(start, end); )
    {
        // Set the page handle to the start of this block.
        id_ph.setPage(start);
        
        // Iterate over all the points in the block.
        for (GA_Offset pt = start; pt < end; ++pt)
        {
            // Get the 'id' value for the point.
            id = id_ph.get(pt);
            id_map[id] = pt;
        }
    }

    // Create the group.
    group = createAdhocPointGroup(*gdp);

    //  Add the group and the id map to the pair.
    pair.first = group;
    pair.second = &id_map;

    // Iterate over each block in the tokens and add any ids to the group.
    for (int i=0; i < tokens.getArgc(); ++i)
    {
        UT_String id_range(tokens[i]);
        id_range.traversePattern(-1, &pair, addOffsetToGroup);
    }

    // Destroy the points.
    gdp->destroyPointOffsets(GA_Range(*group));

    unlockInputs();
    return error();
}
Пример #5
0
void HoudiniScene::calculatePath( const Path &contentPath, const Path &rootPath )
{
	OP_Node *node = retrieveNode();
	if ( node->isManager() )
	{
		return;
	}
	
	UT_String tmp( m_nodePath );
	UT_WorkArgs workArgs;
	tmp.tokenize( workArgs, "/" );
	
	OP_Node *current = dynamic_cast<MOT_Director *>( OPgetDirector() )->getObjectManager();
	// skipping the token for the OBJ manager
	for ( int i = 1; i < workArgs.getArgc(); ++i )
	{
		current = current->getChild( workArgs[i] );
		
		/// recursively collect all input connections
		OP_Node *parent = current->getInput( 0 );
		UT_StringArray parentNames;
		while ( parent )
		{
			parentNames.append( parent->getName() );
			parent = parent->getInput( 0 );
		}
		
		// add them in reverse order
		for ( int j = parentNames.entries() - 1; j >= 0; --j )
		{
			m_path.push_back( Name( parentNames( j ) ) );
		}
		
		if ( ( i < workArgs.getArgc() - 1 ) || Name( workArgs[i] ) != contentName )
		{
			m_path.push_back( Name( workArgs[i] ) );
		}
	}
	
	if ( !contentPath.empty() )
	{
		m_contentIndex = m_path.size();
		m_path.resize( m_path.size() + contentPath.size() );
		std::copy( contentPath.begin(), contentPath.end(), m_path.begin() + m_contentIndex );
	}
	
	if ( m_path.size() < rootPath.size() )
	{
		std::string pStr, rStr;
		pathToString( m_path, pStr );
		pathToString( rootPath, rStr );
		throw Exception( "IECoreHoudini::HoudiniScene: Path \"" + pStr + "\" is not a valid child of root \"" + rStr + "\"." );
	}
	
	for ( size_t i = 0; i < rootPath.size(); ++i )
	{
		if ( rootPath[i] != m_path[i] )
		{
			std::string pStr, rStr;
			pathToString( m_path, pStr );
			pathToString( rootPath, rStr );
			throw Exception( "IECoreHoudini::HoudiniScene: Path \"" + pStr + "\" is not a valid child of root \"" + rStr + "\"." );
		}
	}
	
	m_rootIndex = rootPath.size();
}