Simple example that checks for editable node networks, queries child nodes, creates a node, renames it, connects it to existing nodes, and then deletes it.
#include <iostream>
#include <string>
#include <vector>
#define ENSURE_SUCCESS( result ) \
if ( (result) != HAPI_RESULT_SUCCESS ) \
{ \
std::cout << "Failure at " << __FILE__ << ": " << __LINE__ << std::endl; \
std::cout << getLastError() << std::endl; \
exit( 1 ); \
}
#define ENSURE_COOK_SUCCESS( result ) \
if ( (result) != HAPI_RESULT_SUCCESS ) \
{ \
std::cout << "Failure at " << __FILE__ << ": " << __LINE__ << std::endl; \
std::cout << getLastCookError() << std::endl; \
exit( 1 ); \
}
static std::string getLastError();
static std::string getLastCookError();
static void printChildNodeInfo(
HAPI_Session &session, std::vector< HAPI_NodeId > &childrenNodes);
int
main( int argc, char ** argv )
{
const char * hdaFile = argc == 2 ? argv[ 1 ] : "examples/FourShapes.hda";
bool bUseInProcess = false;
if(bUseInProcess)
{
}
else
{
serverOptions.timeoutMs = 3000.0f;
}
&cookOptions,
true,
-1,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr ) );
int assetCount;
if (assetCount > 1)
{
std::cout << "Should only be loading 1 asset here" << std::endl;
exit ( 1 );
}
std::string assetName = getString( assetSh );
ENSURE_SUCCESS(
HAPI_CreateNode( &session, -1, assetName.c_str(),
"FourShapes",
false, &editableNetworkId ) );
ENSURE_SUCCESS(
HAPI_CookNode( &session, editableNetworkId, &cookOptions ) );
int cookStatus;
do
{
}
ENSURE_SUCCESS( cookResult );
ENSURE_COOK_SUCCESS( cookStatus );
int childCount;
false, &childCount ) );
std::cout << "Editable Node Network Child Count: "
<< childCount << std::endl;
std::vector< HAPI_NodeId > childNodeIds( childCount );
&childNodeIds.front(), childCount ) );
printChildNodeInfo( session, childNodeIds );
"ProgrammaticBox", false, &anotherBoxNode ) );
ENSURE_SUCCESS(
HAPI_CookNode( &session, anotherBoxNode, &cookOptions ) );
int boxCookStatus;
do
{
}
ENSURE_SUCCESS( boxCookResult );
ENSURE_COOK_SUCCESS( boxCookStatus );
if ( connectedNodeId != childNodeIds[ 0 ] )
{
std::cout << "The connected node id is " << connectedNodeId << " when it should be "
<< editableNetworkId << std::endl;
exit ( 1 );
}
false, &childCount ) );
std::vector < HAPI_NodeId > newChildNodes ( childCount );
&newChildNodes.front(), childCount ) );
std::cout << "After CONNECT NODE" << std::endl;
printChildNodeInfo( session, newChildNodes );
ENSURE_SUCCESS(
HAPI_SaveHIPFile( &session,
"examples/modifiedScene.hip",
false ) );
std::cout << "After DELETING NODE" << std::endl;
false, &childCount ) );
std::vector < HAPI_NodeId > finalChildList ( childCount );
&finalChildList.front(), childCount ) );
printChildNodeInfo( session, finalChildList );
char in;
std::cout << "Press any key to exit" << std::endl;
std::cin >> in;
return 0;
}
static void printChildNodeInfo(
HAPI_Session &session, std::vector< HAPI_NodeId > &childrenNodes )
{
std::cout << "Child Node Ids" << std::endl;
for ( int i = 0; i < childrenNodes.size(); ++i )
{
std::cout << " "
<< childrenNodes[ i ]
<< " - "
<< std::endl;
}
}
static std::string
getLastError()
{
int bufferLength;
&bufferLength );
char * buffer = new char[ bufferLength ];
std::string result( buffer );
delete [] buffer;
return result;
}
static std::string
getLastCookError()
{
int bufferLength;
&bufferLength );
char * buffer = new char[ bufferLength ];
std::string result( buffer );
delete[] buffer;
return result;
}
static std::string
{
if ( stringHandle == 0 )
{
return "";
}
int bufferLength;
stringHandle,
&bufferLength );
char * buffer = new char[ bufferLength ];
std::string result( buffer );
delete [] buffer;
return result;
}