Пример #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 ); 
	}
}
void
SOP_PrimGroupCentroid::buildGroupData(UT_String &pattern,
                                      const GU_Detail *input_geo,
                                      UT_Array<GA_Range> &range_array,
                                      UT_StringArray &string_values)
{
    GA_Range                    pr_range;
    const GA_PrimitiveGroup     *group;
    GA_ElementGroupTable::ordered_iterator group_it;

    UT_String                   group_name;
    UT_WorkArgs                 tokens;

    // Tokenize the pattern.
    pattern.tokenize(tokens);

    // Get all the primitive groups.
    const GA_ElementGroupTable &prim_groups = input_geo->primitiveGroups();

    // For each primitive group in order.
    for (group_it=prim_groups.obegin(); !group_it.atEnd(); ++group_it)
    {
        // Get the group.
        group = static_cast<GA_PrimitiveGroup *>(*group_it);

        // Ensure the group is valid.
        if (!group)
            continue;

        // Skip internal groups.
        if (group->getInternal())
            continue;

        // Check to see if this group name matches the pattern.
        group_name = group->getName();
        if (!group_name.matchPattern(tokens))
            continue;

        // Get a range for the primitives in the group.
        pr_range = input_geo->getPrimitiveRange(group);

        // Add the primitive range and the group name to the arrays.
        range_array.append(pr_range);
        string_values.append(group_name);
    }
}
Пример #3
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();
}
Пример #4
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() );
					}
				}
			}
		}
	}
}
void
SOP_PrimGroupCentroid::buildRefMap(GA_AttributeRefMap &hmap,
                                   UT_String &pattern,
                                   GU_Detail *gdp,
                                   const GU_Detail *input_geo,
                                   int mode,
                                   GA_AttributeOwner owner)
{
    const GA_AttributeDict      *dict;
    GA_AttributeDict::iterator  a_it;

    const GA_Attribute          *source_attr;
    GA_ROAttributeRef           attr_gah;

    UT_String                   attr_name;
    UT_WorkArgs                 tokens;

    // Tokenize the pattern.
    pattern.tokenize(tokens, " ");

    // Select the appropriate attribute dictionary to use.
    if (owner == GA_ATTRIB_PRIMITIVE)
        dict = &input_geo->primitiveAttribs();
    // GA_ATTRIB_POINT
    else
        dict = &input_geo->pointAttribs();

    // Iterate over all the point attributes.
    for (a_it=dict->begin(GA_SCOPE_PUBLIC); !a_it.atEnd(); ++a_it)
    {
        // The current attribute.
        source_attr = a_it.attrib();
        // Get the attribute name.
        attr_name = source_attr->getName();

        // If the name doesn't match our pattern, skip it.
        if (!attr_name.matchPattern(tokens))
            continue;

        // Skip attribute names matching our current mode.  These are left
        // to the 'store' parm setting.
        if (mode == 1 and attr_name == "name")
            continue;
        else if (mode == 2 and attr_name == "class")
            continue;

        // Select the appropriate attribute type to search for.
        if (owner == GA_ATTRIB_PRIMITIVE)
        {
            // Try to find the point attribute on the geometry.
            attr_gah = gdp->findPointAttrib(*source_attr);
        }
        // GA_ATTRIB_POINT
        else
        {
            // If we are doing points, we can ignore P.
            if (attr_name == "P")
                continue;

            // Try to find the primitive attribute on the geometry.
            attr_gah = gdp->findPrimAttrib(*source_attr);
        }

        // If it doesn't exist, create a new attribute.
        if (attr_gah.isInvalid())
        {
            if (owner == GA_ATTRIB_PRIMITIVE)
            {
                // Create a new point attribute on the current geometry
                // that is the same as the source attribute.  Append it and
                // the source to the map.
                hmap.append(gdp->addPointAttrib(source_attr).getAttribute(),
                            source_attr);
            }
            else
            {
                // Create a new point attribute on the current geometry
                // that is the same as the source attribute.  Append it and
                // the source to the map.
                hmap.append(gdp->addPrimAttrib(source_attr).getAttribute(),
                            source_attr);
            }
        }
    }
}