896 {
897 const char* hdaFile = "";
898
899 HAPI_Session session;
900
901 HAPI_ThriftServerOptions serverOptions{ 0 };
902 serverOptions.autoClose = true;
903 serverOptions.timeoutMs = 3000.0f;
904
905 HE_CHECK(HAPI_StartThriftNamedPipeServer(&serverOptions,
"hapi",
nullptr,
nullptr))
906
907 HAPI_SessionInfo sessionInfo = HAPI_SessionInfo_Create();
908 HE_CHECK(HAPI_CreateThriftNamedPipeSession(&session, "hapi", &sessionInfo))
909
910 HAPI_CookOptions cookOptions = HAPI_CookOptions_Create();
911 HE_CHECK(HAPI_Initialize(&session, &cookOptions, true, -1,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr))
912
913 HAPI_AssetLibraryId assetLibId;
914 HE_CHECK(HAPI_LoadAssetLibraryFromFile(&session, hdaFile, true, &assetLibId));
915
916 int assetCount;
917 HE_CHECK(HAPI_GetAvailableAssetCount(&session, assetLibId, &assetCount))
918
919 if (assetCount > 1)
920 {
921 std::cout << "Should only be loading 1 asset here" << std::endl;
922 }
923
924 HAPI_StringHandle assetSh;
925 HE_CHECK(HAPI_GetAvailableAssets(&session, assetLibId, &assetSh, assetCount))
926
927 std::string assetName =
GetString(session, assetSh);
928
929 HAPI_NodeId nodeId;
930 HE_CHECK(HAPI_CreateNode(&session, -1, assetName.c_str(),
"BrandonTest",
false, &nodeId))
931
932 HE_CHECK(HAPI_CookNode(&session, nodeId, &cookOptions))
933
934 int cookStatus;
935 HAPI_Result cookResult;
936
937 do
938 {
939 cookResult = HAPI_GetStatus(&session, HAPI_STATUS_COOK_STATE, &cookStatus);
940 }
941 while (cookStatus > HAPI_STATE_MAX_READY_STATE && cookResult == HAPI_RESULT_SUCCESS);
942
945
946 HAPI_GeoInfo geoInfo;
947 HE_CHECK(HAPI_GetDisplayGeoInfo(&session, nodeId, &geoInfo))
948
949 HAPI_PartInfo partInfo;
950 HE_CHECK(HAPI_GetPartInfo(&session, geoInfo.nodeId, 0, &partInfo))
951
952 bool areAllTheSame = false;
953 std::vector<HAPI_NodeId> materialIds(partInfo.faceCount);
954 HE_CHECK(HAPI_GetMaterialNodeIdsOnFaces(&session, geoInfo.nodeId, partInfo.id, &areAllTheSame, &materialIds.front(), 0, partInfo.faceCount))
955
956 if(!areAllTheSame)
957 {
958 std::cout << "All materials should be the same." << std::endl;
959 }
960
961 for (int i = 0; i < partInfo.faceCount; ++i)
962 {
963 if (materialIds[i] != materialIds[0])
964 {
965 std::cout << "All material ids should be the same." << std::endl;
966 }
967 }
968
969 HAPI_MaterialInfo materialInfo;
970 HE_CHECK(HAPI_GetMaterialInfo(&session, materialIds[0], &materialInfo))
971
972 if (materialInfo.nodeId != materialIds[0] ||
973 materialInfo.nodeId < 0 ||
974 materialInfo.exists != true ||
975 materialInfo.hasChanged != true)
976 {
977 std::cout << "Did not successfully extract the first material" << std::endl;
978 }
979
980 HAPI_NodeInfo materialNodeInfo;
981 HE_CHECK(HAPI_GetNodeInfo(&session, materialInfo.nodeId, &materialNodeInfo))
982
983 std::cout <<
GetString(session, materialNodeInfo.nameSH) << std::endl;
984
985 std::vector<HAPI_ParmInfo> parmInfos(materialNodeInfo.parmCount);
986 HE_CHECK(HAPI_GetParameters(&session, materialNodeInfo.id, parmInfos.data(), 0, materialNodeInfo.parmCount))
987
988 int baseColorMapIndex = -1;
989 for (int i = 0; i < materialNodeInfo.parmCount; ++i)
990 {
991 if (
GetString(session, parmInfos[i].nameSH) ==
"baseColorMap")
992 {
993 baseColorMapIndex = i;
994 break;
995 }
996 }
997
998 if (baseColorMapIndex < 0)
999 {
1000 std::cout << "Could not find the base color map parameter" << std::endl;
1001 }
1002
1003 HAPI_StringHandle basePath;
1004 HE_CHECK(HAPI_GetParmStringValue(&session, materialNodeInfo.id,
"baseColorMap", 0,
true, &basePath))
1005
1006 std::cout <<
"Base Color Map Path: " <<
GetString(session, basePath) << std::endl;
1007
1008 HE_CHECK(HAPI_RenderTextureToImage(&session, materialNodeInfo.id, baseColorMapIndex))
1009
1010 HAPI_ImageInfo imgInfo;
1011 HE_CHECK(HAPI_GetImageInfo(&session, materialNodeInfo.id, &imgInfo))
1012
1013 std::cout << "Image Width = " << imgInfo.xRes << std::endl
1014 << "Image Height = " << imgInfo.yRes << std::endl
1015 <<
"Image Format = " <<
GetString(session, imgInfo.imageFileFormatNameSH) << std::endl;
1016
1017 HE_CHECK(HAPI_SetImageInfo(&session, materialNodeInfo.id, &imgInfo))
1018
1019 int imagePlaneCount;
1020 HE_CHECK(HAPI_GetImagePlaneCount(&session, materialNodeInfo.id, &imagePlaneCount))
1021
1022 std::vector<HAPI_StringHandle> imagePlanes(imagePlaneCount);
1023 HE_CHECK(HAPI_GetImagePlanes(&session, materialNodeInfo.id, imagePlanes.data(), imagePlaneCount))
1024
1025 for (int j = 0; j < imagePlaneCount; ++j)
1026 {
1027 std::string imagePlaneName =
GetString(session, imagePlanes[j]);
1028 std::cout << "Image Plane [ " << j << " ] = " << imagePlaneName << std::endl;
1029
1030 int destinationFilePath;
1031 HE_CHECK(HAPI_ExtractImageToFile(&session, materialNodeInfo.id,
nullptr, imagePlaneName.c_str(),
"./examples/",
nullptr, &destinationFilePath))
1032 }
1033
1035 }
#define HE_CHECK_COOK(expr)
HoudiniEngine Check Cook macro. Verify HoudiniEngine Cook API Effectiveness.
#define HE_CHECK(expr)
HoudiniEngine Check macro. Verify HoudiniEngine API Effectiveness.
static std::string GetString(HAPI_Session &session, HAPI_StringHandle stringHandle)