Example #1
0
void wendy_GIO_ROP::save_gdp_to_disk( char *arnold_dso_path,OP_Context &context,char *savePath)
{
    OP_Node * node = this->getInput(0);
    if(node)
    {
        SOP_Node * getNode = node->castToSOPNode();

        std::cout<<"the node name is"<<getNode->getName()<<std::endl;
        GU_Detail *sop_detail = (GU_Detail *)getNode->getCookedGeo(context);
        // save the geometry into desk
        g_global_io global_io;
        updateAttributeList(global_io,sop_detail);
        ofstream fout;
        fout.open(savePath,std::ios_base::binary);
        global_io.save(fout);
        fout.close();

        // mata data for the ass
        save_mata_ass(arnold_dso_path,savePath,sop_detail);

    }

    else
    {
        std::cout<<"No Sop Geometry Connect!\n";
        return ;
    }
}
Example #2
0
OP_Node *HoudiniScene::retrieveNode( bool content, MissingBehaviour missingBehaviour ) const
{
	OP_Node *node = OPgetDirector()->findNode( m_nodePath );
	if ( node && content )
	{
		if ( OP_Node *contentNode = locateContent( node ) )
		{
			node = contentNode;
		}
	}
	
	if ( missingBehaviour == ThrowIfMissing )
	{
		if ( !node )
		{
			throw Exception( "IECoreHoudini::HoudiniScene: Node \"" + m_nodePath.toStdString() + "\" no longer exists." );
		}

		if ( !node->isManager() && !node->castToOBJNode() )
		{
			throw Exception( "IECoreHoudini::HoudiniScene: Node \"" + m_nodePath.toStdString() + "\" is not a valid OBJ." );
		}
	}
	
	return node;
}
Example #3
0
Imath::M44d HoudiniScene::readTransformAsMatrix( double time ) const
{
	OP_Node *node = retrieveNode();	
	if ( node->isManager() )
	{
		return Imath::M44d();
	}
	
	OBJ_Node *objNode = node->castToOBJNode();
	if ( !objNode )
	{
		return Imath::M44d();
	}
	
	// paths embedded within a sop always have identity transforms
	if ( m_contentIndex )
	{
		return Imath::M44d();
	}
	
	UT_DMatrix4 matrix;
	OP_Context context( time );
	if ( !objNode->getLocalTransform( context, matrix ) )
	{
		return Imath::M44d();
	}
	
	return IECore::convert<Imath::M44d>( matrix );
}
Example #4
0
Imath::Box3d HoudiniScene::readBound( double time ) const
{
	OP_Node *node = retrieveNode( true );
	
	Imath::Box3d bounds;
	UT_BoundingBox box;
	OP_Context context( time );
	/// \todo: this doesn't account for SOPs containing multiple shapes
	/// if we fix it, we need to fix the condition below as well
	if ( node->getBoundingBox( box, context ) )
	{
		bounds = IECore::convert<Imath::Box3d>( box );
	}
	
	// paths embedded within a sop already have bounds accounted for
	if ( m_contentIndex )
	{
		return bounds;
	}
	
	NameList children;
	childNames( children );
	for ( NameList::iterator it=children.begin(); it != children.end(); ++it )
	{
		ConstSceneInterfacePtr childScene = child( *it );
		Imath::Box3d childBound = childScene->readBound( time );
		if ( !childBound.isEmpty() )
		{
			bounds.extendBy( Imath::transform( childBound, childScene->readTransformAsMatrix( time ) ) );
		}
	}
	
	return bounds;
}
Example #5
0
void Daemon::SetupCVEX(UT_String script)
{
        vexsrc=script;

        SHOP_Node *shop = caller->findSHOPNode(vexsrc);
        caller->addExtraInput(shop, OP_INTEREST_DATA);

        shop->buildVexCommand(vexsrc, shop->getSpareParmTemplates(), now);
        shop->buildShaderString(script, now, 0);

        UT_String op = "op:";
        op += vexsrc;
        vexsrc=op;

        char *argv[4096];
        int argc = vexsrc.parse(argv, 4096);

        //OP_Caller       C(caller);
        //context.setOpCaller(&C);
        //context.setTime(now);
        context.addInput("P",CVEX_TYPE_VECTOR3,true);

        context.load(argc, argv );
        useVex = context.isLoaded();

        if(useVex)
        {
                CVEX_Value* inv = context.findInput("P",CVEX_TYPE_VECTOR3);
                inv->setData(in,1);

                CVEX_Value* outv = context.findOutput("P",CVEX_TYPE_VECTOR3);
                outv->setData(out,1);
        };
};
Example #6
0
bool HoudiniScene::hasObject() const
{
	OP_Node *node = retrieveNode( true );
	if ( node->isManager() )
	{
		return false;
	}
	
	OBJ_Node *objNode = node->castToOBJNode();
	if ( !objNode )
	{
		return false;
	}
	
	OBJ_OBJECT_TYPE type = objNode->getObjectType();
	if ( type == OBJ_GEOMETRY  )
	{
		OP_Context context( getDefaultTime() );
		const GU_Detail *geo = objNode->getRenderGeometry( context, false );
		// multiple named shapes define children that contain each object
		/// \todo: similar attribute logic is repeated in several places. unify in a single function if possible
		GA_ROAttributeRef nameAttrRef = geo->findStringTuple( GA_ATTRIB_PRIMITIVE, "name" );
		if ( !nameAttrRef.isValid() )
		{
			return true;
		}
		
		const GA_Attribute *nameAttr = nameAttrRef.getAttribute();
		const GA_AIFSharedStringTuple *tuple = nameAttr->getAIFSharedStringTuple();
		GA_Size numShapes = tuple->getTableEntries( nameAttr );
		if ( !numShapes )
		{
			return true;
		}
		
		for ( GA_Size i=0; i < numShapes; ++i )
		{
			const char *currentName = tuple->getTableString( nameAttr, tuple->validateTableHandle( nameAttr, i ) );
			const char *match = matchPath( currentName );
			if ( match && *match == *emptyString )
			{
				// exact match
				return true;
			}
		}
		
		return false;
	}
	
	/// \todo: need to account for OBJ_CAMERA and OBJ_LIGHT
	
	return false;
}
Example #7
0
SceneInterfacePtr HoudiniScene::child( const Name &name, MissingBehaviour missingBehaviour )
{
	Path contentPath;
	OP_Node *child = retrieveChild( name, contentPath, missingBehaviour );
	if ( !child )
	{
		return 0;
	}
	
	UT_String nodePath;
	child->getFullPath( nodePath );
	
	Path rootPath;
	rootPath.resize( m_rootIndex );
	std::copy( m_path.begin(), m_path.begin() + m_rootIndex, rootPath.begin() );
	
	/// \todo: is this really what we want? can we just pass rootIndex and contentIndex instead?
	return new HoudiniScene( nodePath, contentPath, rootPath, m_defaultTime, m_splitter );
}
Example #8
0
OP_Node *HoudiniScene::locateContent( OP_Node *node ) const
{
	OBJ_Node *objNode = node->castToOBJNode();
	if ( node->isManager() || ( objNode && objNode->getObjectType() == OBJ_SUBNET ) )
	{
		for ( int i=0; i < node->getNchildren(); ++i )
		{
			OP_Node *child = node->getChild( i );
			if ( child->getName().equal( contentName.c_str() ) )
			{
				return child;
			}
		}
	}
	else if ( objNode && objNode->getObjectType() == OBJ_GEOMETRY )
	{
		return objNode;
	}
	
	return 0;
}
Example #9
0
SceneInterfacePtr LiveScene::retrieveScene( const Path &path, MissingBehaviour missingBehaviour ) const
{
	Path rootPath, emptyPath;
	rootPath.resize( m_rootIndex );
	std::copy( m_path.begin(), m_path.begin() + m_rootIndex, rootPath.begin() );
	
	LiveScenePtr rootScene = new LiveScene();
	rootScene->setDefaultTime( m_defaultTime );
	for ( Path::const_iterator it = rootPath.begin(); it != rootPath.end(); ++it )
	{
		rootScene = IECore::runTimeCast<LiveScene>( rootScene->child( *it ) );
		if ( !rootScene )
		{
			return 0;
		}
	}
	
	UT_String rootNodePath;
	OP_Node *node = rootScene->retrieveNode();
	if ( !node )
	{
		return 0;
	}
	node->getFullPath( rootNodePath );
	
	/// \todo: is this really what we want? can we just pass rootIndex and contentIndex instead?
	SceneInterfacePtr scene = new LiveScene( rootNodePath, emptyPath, rootPath, m_defaultTime, m_splitter.get() );
	for ( Path::const_iterator it = path.begin(); it != path.end(); ++it )
	{
		scene = scene->child( *it, missingBehaviour );
		if ( !scene )
		{
			return 0;
		}
	}
	
	return scene;
}
Example #10
0
Imath::M44d LiveScene::readWorldTransformAsMatrix( double time ) const
{
	OP_Node *node = retrieveNode();	
	if ( node->isManager() )
	{
		return Imath::M44d();
	}
	
	OBJ_Node *objNode = node->castToOBJNode();
	if ( !objNode )
	{
		return Imath::M44d();
	}
	
	UT_DMatrix4 matrix;
	OP_Context context( adjustTime( time ) );
	if ( !objNode->getWorldTransform( matrix, context ) )
	{
		return Imath::M44d();
	}
	
	return IECore::convert<Imath::M44d>( matrix );
}
Example #11
0
ROP_RENDER_CODE
ROP_DopField::renderFrame(fpreal time, UT_Interrupt *)
{
    OP_Node		*op;
    DOP_Parent		*dopparent;
    UT_String		 doppath, savepath;
    UT_String		 dopobject, dopdata;

    if( !executePreFrameScript(time) )
	return ROP_ABORT_RENDER;

    DOPPATH(doppath, time);

    if( !doppath.isstring() )
    {
	addError(ROP_MESSAGE, "Invalid DOP path");
	return ROP_ABORT_RENDER;
    }

    op = findNode(doppath);
    if (!op)
    {
	addError(ROP_COOK_ERROR, (const char *)doppath);
	return ROP_ABORT_RENDER;
    }

    dopparent = op ? op->castToDOPParent() : 0;
    if( !dopparent )
    {
	addError(ROP_COOK_ERROR, (const char *)doppath);
	return ROP_ABORT_RENDER;
    }

    DOPOBJECT(dopobject, time);
    DOPDATA(dopdata, time);
    OUTPUT(savepath, time);


    time = DOPsetBestTime(dopparent, time);

    OP_Context		context(time);

    const SIM_Object		*object;
    object = dopparent->findObjectFromString(dopobject, 0, 0, time);

    if (!object)
    {
	addError(ROP_COOK_ERROR, (const char *)dopobject);
	return ROP_ABORT_RENDER;
    }

    const SIM_Data		*data;

    data = object->getConstNamedSubData(dopdata);

    if (!data)
    {
	addError(ROP_COOK_ERROR, (const char *) dopdata);
	return ROP_ABORT_RENDER;
    }

    // Create our GDP.
    GU_Detail			*gdp = new GU_Detail();

    const SIM_ScalarField	*scalarfield = SIM_DATA_CASTCONST(data, SIM_ScalarField);
    if (scalarfield)
    {
	addField(gdp, scalarfield->getField());
    }
    const SIM_VectorField	*vectorfield = SIM_DATA_CASTCONST(data, SIM_VectorField);
    if (vectorfield)
    {
	for (int i = 0; i < 3; i++)
	{
	    addField(gdp, vectorfield->getField(i));
	}
    }
    const SIM_MatrixField	*matrixfield = SIM_DATA_CASTCONST(data, SIM_MatrixField);
    if (matrixfield)
    {
	for (int i = 0; i < 3; i++)
	    for (int j = 0; j < 3; j++)
	    {
		addField(gdp, matrixfield->getField(i, j));
	    }
    }

    if (!gdp->save((const char *)savepath, 0, 0).success())
    {
	addError(ROP_SAVE_ERROR, (const char *)savepath);
	return ROP_ABORT_RENDER;
    }

    // DO NOT delete gdp if we are stealing the voxels!
    // delete gdp;

    if (ALFPROGRESS() && (myEndTime != myStartTime))
    {
	fpreal		fpercent = (time - myStartTime) / (myEndTime - myStartTime);
	int		percent = (int)SYSrint(fpercent * 100);
	percent = SYSclamp(percent, 0, 100);
	fprintf(stdout, "ALF_PROGRESS %d%%\n", percent);
	fflush(stdout);
    }
    
    if (error() < UT_ERROR_ABORT)
    {
	if( !executePostFrameScript(time) )
	    return ROP_ABORT_RENDER;
    }

    return ROP_CONTINUE_RENDER;
}
Example #12
0
OP_Node *HoudiniScene::retrieveChild( const Name &name, Path &contentPath, MissingBehaviour missingBehaviour ) const
{
	OP_Node *node = retrieveNode( false, missingBehaviour );
	OP_Node *contentBaseNode = retrieveNode( true, missingBehaviour );
	if ( !node || !contentBaseNode )
	{
		return 0;
	}
	
	OBJ_Node *objNode = node->castToOBJNode();
	OBJ_Node *contentNode = contentBaseNode->castToOBJNode();
	
	// check subnet children
	if ( node->isManager() || ( objNode && objNode->getObjectType() == OBJ_SUBNET ) )
	{
		for ( int i=0; i < node->getNchildren(); ++i )
		{
			OP_Node *child = node->getChild( i );
			// the contentNode is actually an extension of ourself
			if ( child == contentNode )
			{
				continue;
			}
			
			if ( child->getName().equal( name.c_str() ) && !hasInput( child ) )
			{
				return child;
			}
		}
	}
	
	if ( contentNode )
	{
		// check connected outputs
		for ( unsigned i=0; i < contentNode->nOutputs(); ++i )
		{
			OP_Node *child = contentNode->getOutput( i );
			if ( child->getName().equal( name.c_str() ) )
			{
				return child;
			}
		}
		
		// check child shapes within the geo
		if ( contentNode->getObjectType() == OBJ_GEOMETRY )
		{
			OP_Context context( getDefaultTime() );
			const GU_Detail *geo = contentNode->getRenderGeometry( context, false );
			GA_ROAttributeRef nameAttrRef = geo->findStringTuple( GA_ATTRIB_PRIMITIVE, "name" );
			if ( nameAttrRef.isValid() )
			{
				const GA_Attribute *nameAttr = nameAttrRef.getAttribute();
				const GA_AIFSharedStringTuple *tuple = nameAttr->getAIFSharedStringTuple();
				GA_Size numShapes = tuple->getTableEntries( nameAttr );
				for ( GA_Size i=0; i < numShapes; ++i )
				{
					const char *currentName = tuple->getTableString( nameAttr, tuple->validateTableHandle( nameAttr, i ) );
					const char *match = matchPath( currentName );
					if ( match && *match != *emptyString )
					{
						std::pair<const char *, size_t> childMarker = nextWord( match );
						std::string child( childMarker.first, childMarker.second );
						if ( name == child )
						{
							size_t contentSize = ( m_contentIndex ) ? m_path.size() - m_contentIndex : 0;
							if ( contentSize )
							{
								contentPath.resize( contentSize );
								std::copy( m_path.begin() + m_contentIndex, m_path.end(), contentPath.begin() );
							}
							
							contentPath.push_back( name );
							
							return contentNode;
						}
					}
				}
			}
		}
	}
	
	if ( missingBehaviour == SceneInterface::ThrowIfMissing )
	{
		Path p;
		path( p );
		std::string pStr;
		pathToString( p, pStr );
		throw Exception( "IECoreHoudini::HoudiniScene::retrieveChild: Path \"" + pStr + "\" has no child named " + name.string() + "." );
	}
	
	return 0;
}
Example #13
0
void HoudiniScene::childNames( NameList &childNames ) const
{
	OP_Node *node = retrieveNode();
	OBJ_Node *objNode = node->castToOBJNode();
	OBJ_Node *contentNode = retrieveNode( true )->castToOBJNode();
	
	// add subnet children
	if ( node->isManager() || ( objNode && objNode->getObjectType() == OBJ_SUBNET ) )
	{
		for ( int i=0; i < node->getNchildren(); ++i )
		{
			OP_Node *child = node->getChild( i );
			
			// ignore children that have incoming connections, as those are actually grandchildren
			// also ignore the contentNode, which is actually an extension of ourself
			if ( child != contentNode && !hasInput( child ) )
			{
				childNames.push_back( Name( child->getName() ) );
			}
		}
	}
	
	if ( !contentNode )
	{
		return;
	}
	
	// add connected outputs
	for ( unsigned i=0; i < contentNode->nOutputs(); ++i )
	{
		childNames.push_back( Name( contentNode->getOutput( i )->getName() ) );
	}
	
	// add child shapes within the geometry
	if ( contentNode->getObjectType() == OBJ_GEOMETRY )
	{
		OP_Context context( getDefaultTime() );
		const GU_Detail *geo = contentNode->getRenderGeometry( context, false );
		GA_ROAttributeRef nameAttrRef = geo->findStringTuple( GA_ATTRIB_PRIMITIVE, "name" );
		if ( !nameAttrRef.isValid() )
		{
			return;
		}
		
		const GA_Attribute *nameAttr = nameAttrRef.getAttribute();
		const GA_AIFSharedStringTuple *tuple = nameAttr->getAIFSharedStringTuple();
		GA_Size numShapes = tuple->getTableEntries( nameAttr );
		for ( GA_Size i=0; i < numShapes; ++i )
		{
			const char *currentName = tuple->getTableString( nameAttr, tuple->validateTableHandle( nameAttr, i ) );
			const char *match = matchPath( currentName );
			if ( match && *match != *emptyString )
			{
				std::pair<const char *, size_t> childMarker = nextWord( match );
				std::string child( childMarker.first, childMarker.second );
				if ( std::find( childNames.begin(), childNames.end(), child ) == childNames.end() )
				{
					childNames.push_back( child );
				}
			}
		}
	}
}
Example #14
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();
}