1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
| #include <HAPI/HAPI.h> #include <iostream> #include <string>
#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 std::string getString( HAPI_StringHandle stringHandle );
int main( int argc, char ** argv ) { const char * hdaFile = argc == 2 ? argv[ 1 ] : "examples/SideFX_spaceship.otl"; HAPI_CookOptions cookOptions = HAPI_CookOptions_Create();
HAPI_Session session;
HAPI_CreateInProcessSession( &session );
ENSURE_SUCCESS( HAPI_Initialize( &session, &cookOptions, true, -1, nullptr, nullptr, nullptr, nullptr, nullptr ) );
HAPI_AssetLibraryId assetLibId; ENSURE_SUCCESS( HAPI_LoadAssetLibraryFromFile( &session, hdaFile, true, &assetLibId ) );
int assetCount; ENSURE_SUCCESS( HAPI_GetAvailableAssetCount( &session, assetLibId, &assetCount ) );
if (assetCount > 1) { std::cout << "Should only be loading 1 asset here" << std::endl; exit ( 1 ); } HAPI_StringHandle assetSh; ENSURE_SUCCESS( HAPI_GetAvailableAssets( &session, assetLibId, &assetSh, assetCount ) );
std::string assetName = getString( assetSh );
HAPI_NodeId nodeId; ENSURE_SUCCESS( HAPI_CreateNode( &session, -1, assetName.c_str(), "AnAsset", false, &nodeId ) );
ENSURE_SUCCESS( HAPI_CookNode( &session, nodeId, &cookOptions ) ); int cookStatus; HAPI_Result cookResult;
do { cookResult = HAPI_GetStatus( &session, HAPI_STATUS_COOK_STATE, &cookStatus ); } while (cookStatus > HAPI_STATE_MAX_READY_STATE && cookResult == HAPI_RESULT_SUCCESS);
ENSURE_SUCCESS( cookResult ); ENSURE_COOK_SUCCESS( cookStatus ); HAPI_NodeInfo nodeInfo; ENSURE_SUCCESS( HAPI_GetNodeInfo( &session, nodeId, &nodeInfo ) ); HAPI_ParmInfo * parmInfos = new HAPI_ParmInfo[ nodeInfo.parmCount ]; ENSURE_SUCCESS( HAPI_GetParameters( &session, nodeId, parmInfos, 0, nodeInfo.parmCount ) );
// Print parameter info std::cout << "Parameters: " << std::endl;
for( int i = 0; i < nodeInfo.parmCount; ++i ) { std::cout << "==========" << std::endl;
std::cout << " Name: " << getString( parmInfos[ i ].nameSH ) << std::endl;
std::cout << " Values: (";
if ( HAPI_ParmInfo_IsInt( &parmInfos[ i ] ) ) { int parmIntCount = HAPI_ParmInfo_GetIntValueCount( &parmInfos[ i ] ); int * parmIntValues = new int[ parmIntCount ]; ENSURE_SUCCESS( HAPI_GetParmIntValues( &session, nodeId, parmIntValues, parmInfos[ i ].intValuesIndex, parmIntCount ) );
for ( int v = 0; v < parmIntCount; ++v ) { if ( v != 0 ) std::cout << ", ";
std::cout << parmIntValues[ v ]; } delete [] parmIntValues; } else if ( HAPI_ParmInfo_IsFloat( &parmInfos[ i ] ) ) { int parmFloatCount = HAPI_ParmInfo_GetFloatValueCount( &parmInfos[ i ] );
float * parmFloatValues = new float[ parmFloatCount ]; ENSURE_SUCCESS( HAPI_GetParmFloatValues( &session, nodeId, parmFloatValues, parmInfos[ i ].floatValuesIndex, parmFloatCount ) ); for ( int v = 0; v < parmFloatCount; ++v ) { if ( v != 0 ) std::cout << ", ";
std::cout << parmFloatValues[ v ]; } delete [] parmFloatValues; } else if ( HAPI_ParmInfo_IsString( &parmInfos[ i ] ) ) { int parmStringCount = HAPI_ParmInfo_GetStringValueCount( &parmInfos[ i ] );
HAPI_StringHandle * parmSHValues = new HAPI_StringHandle[ parmStringCount ]; ENSURE_SUCCESS( HAPI_GetParmStringValues( &session, nodeId, true, parmSHValues, parmInfos[ i ].stringValuesIndex, parmStringCount ) ); for ( int v = 0; v < parmStringCount; ++v ) { if ( v != 0 ) std::cout << ", "; std::cout << getString( parmSHValues[ v ] ); }
delete [] parmSHValues; } std::cout << ")" << std::endl; }
delete [] parmInfos;
char in; std::cout << "Press any key to exit" << std::endl; std::cin >> in; HAPI_Cleanup( &session ); return 0; }
static std::string getLastError() { int bufferLength; HAPI_GetStatusStringBufLength( nullptr, HAPI_STATUS_CALL_RESULT, HAPI_STATUSVERBOSITY_ERRORS, &bufferLength );
char * buffer = new char[ bufferLength ];
HAPI_GetStatusString( nullptr, HAPI_STATUS_CALL_RESULT, buffer, bufferLength );
std::string result( buffer ); delete [] buffer;
return result; }
static std::string getLastCookError() { int bufferLength; HAPI_GetStatusStringBufLength( nullptr, HAPI_STATUS_COOK_RESULT, HAPI_STATUSVERBOSITY_ERRORS, &bufferLength );
char * buffer = new char[ bufferLength ];
HAPI_GetStatusString( nullptr, HAPI_STATUS_COOK_RESULT, buffer, bufferLength );
std::string result( buffer ); delete[] buffer;
return result; }
static std::string getString( HAPI_StringHandle stringHandle ) { if ( stringHandle == 0 ) { return ""; }
int bufferLength; HAPI_GetStringBufLength( nullptr, stringHandle, &bufferLength );
char * buffer = new char[ bufferLength ];
HAPI_GetString ( nullptr, stringHandle, buffer, bufferLength );
std::string result( buffer ); delete [] buffer;
return result; }
|