Simple example that goes through the 3 different packed primitive instancing modes and prints the resulting part layout for each.
#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/PackedPrimitive.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(),
"PackedPrimitive",
false, &nodeId ) );
char in;
std::cout << "Press enter in terminal to exit." << std::endl;
std::cin >> in;
return 0;
}
static void
{
{
std::cout << indent << "Part " << partId << ":" << std::endl;
std::cout << indent << " Type = Mesh" << std::endl;
std::cout << indent <<
" Point Count = " << partInfo.
pointCount << std::endl;
}
{
std::cout << indent << "Part " << partId << ":" << std::endl;
std::cout << indent << " Type = Curve" << std::endl;
std::cout << indent <<
" Point Count = " << partInfo.
pointCount << std::endl;
}
{
std::cout << indent << "Part " << partId << ":" << std::endl;
std::cout << indent << " Type = Instancer" << std::endl;
std::cout << indent <<
" Point Count = " << partInfo.
pointCount << std::endl;
std::cout << indent <<
" Instance Count = " << partInfo.
instanceCount << std::endl;
std::cout << indent <<
" Instanced Part Count = " << partInfo.
instancedPartCount << std::endl;
std::vector< HAPI_Transform > instanceTransforms( partInfo.
instanceCount );
std::cout << indent << " Instance Transforms:" << std::endl;
for ( auto instanceTransform : instanceTransforms )
{
float * p = &instanceTransform.position[ 0 ];
std::cout << indent << " " << p[ 0 ] << ", " << p[ 1 ] << ", " << p[ 2 ] << std::endl;
}
instancedPartIds.data(), 0,
std::cout << indent << " Instanced Parts:" << std::endl;
for ( auto instancedPartId : instancedPartIds )
printPartInfo( session, nodeId, instancedPartId, " -> ");
}
}
static void
{
switch ( mode )
{
std::cout << "Using: HAPI_PACKEDPRIM_INSTANCING_MODE_DISABLED" << std::endl; break;
std::cout << "Using: HAPI_PACKEDPRIM_INSTANCING_MODE_HIERARCHY" << std::endl; break;
std::cout << "Using: HAPI_PACKEDPRIM_INSTANCING_MODE_FLAT" << std::endl; break;
}
int cookStatus;
do
{
}
ENSURE_SUCCESS( cookResult );
ENSURE_COOK_SUCCESS( cookStatus );
int childCount;
false, &childCount ) );
for ( int i = 0; i < childCount; ++i )
{
std::cout <<
"Part count for geo node " << i <<
": " << geoInfo.
partCount << std::endl;
for (
int j = 0; j < geoInfo.
partCount; ++j )
{
printPartInfo( session, childIds[ i ], j, "");
}
}
}
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;
}