The example below gives an illustration of extracting both the diffuse texture map from the spaceship asset (available from www.orbolt.com).
#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();
int
main( int argc, char ** argv )
{
const char * hdaFile = argc == 2 ? argv[ 1 ] : "examples/SideFX_spaceship.otl";
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(),
"BrandonTest",
false, &nodeId ) );
ENSURE_SUCCESS(
HAPI_CookNode( &session, nodeId, &cookOptions ) );
int cookStatus;
do
{
}
ENSURE_SUCCESS( cookResult );
ENSURE_COOK_SUCCESS( cookStatus );
bool areAllTheSame = false;
std::vector< HAPI_NodeId > materialIds( partInfo.
faceCount );
&materialIds.front(), 0, partInfo.
faceCount ) );
if ( !areAllTheSame )
{
std::cout << "All materials should be the same." << std::endl;
exit ( 1 );
}
for (
int i = 0; i < partInfo.
faceCount; ++i )
{
if ( materialIds[ i ] != materialIds[ 0 ] )
{
std::cout << "All material ids should be the same." << std::endl;
exit ( 1 );
}
}
if ( materialInfo.
nodeId != materialIds[0] ||
materialInfo.
exists !=
true ||
{
std::cout << "Did not successfully extract the first material" << std::endl;
exit ( 1 );
}
std::cout << getString( materialNodeInfo.
nameSH ) << std::endl;
int baseColorMapIndex = -1;
for (
int i = 0; i < materialNodeInfo.
parmCount; ++i )
{
if ( getString( parmInfos[ i ].nameSH ) == "baseColorMap" )
{
baseColorMapIndex = i;
}
}
if ( baseColorMapIndex < 0 )
{
std::cout << "Could not find the base color map parameter" << std::endl;
exit( 1 );
}
0, true, &basePath ) );
std::cout << "Base Color Map Path: " << getString( basePath ) << std::endl;
std::cout <<
"Image Width = " << imgInfo.
xRes << std::endl
<<
"Image Height = " << imgInfo.
yRes << std::endl
int imagePlaneCount;
for ( int j = 0; j < imagePlaneCount; ++j )
{
std::string imagePlaneName = getString( imagePlanes[ j ] );
std::cout << "Image Plane [ " << j << " ] = " << imagePlaneName << std::endl;
int destinationFilePath;
imagePlaneName.c_str(), "./examples/", nullptr, &destinationFilePath ) );
}
char in;
std::cout << "Enter some input to exit" << std::endl;
std::cin >> in;
return 0;
}
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;
}