SpiecsEngine
 
Loading...
Searching...
No Matches

◆ Groups_Sample()

static void HoudiniEngine::Groups_Sample ( )
static

Definition at line 714 of file HoudiniTestSource.h.

715 {
716 HAPI_Session session;
717
718 HAPI_ThriftServerOptions serverOptions{ 0 };
719 serverOptions.autoClose = true;
720 serverOptions.timeoutMs = 3000.0f;
721
722 HE_CHECK(HAPI_StartThriftNamedPipeServer(&serverOptions, "hapi", nullptr, nullptr))
723
724 HAPI_SessionInfo sessionInfo = HAPI_SessionInfo_Create();
725
726 HE_CHECK(HAPI_CreateThriftNamedPipeSession(&session, "hapi", &sessionInfo))
727
728 HAPI_CookOptions cookOptions = HAPI_CookOptions_Create();
729 HE_CHECK(HAPI_Initialize(&session, &cookOptions, true, -1, nullptr, nullptr, nullptr, nullptr, nullptr))
730
731 HAPI_NodeId cubeNode;
732
733 HE_CHECK(HAPI_CreateInputNode(&session, -1, &cubeNode, "Cube"))
734 HE_CHECK(HAPI_CookNode(&session, cubeNode, &cookOptions))
735
736 int cookStatus;
737 HAPI_Result cookResult;
738
739 do
740 {
741 cookResult = HAPI_GetStatus(&session, HAPI_STATUS_COOK_STATE, &cookStatus);
742 }
743 while(cookStatus > HAPI_STATE_MAX_READY_STATE && cookResult == HAPI_RESULT_SUCCESS);
744
745 HE_CHECK(cookResult)
746 HE_CHECK_COOK(cookStatus)
747
748 HAPI_PartInfo cubePart = HAPI_PartInfo_Create();
749
750 cubePart.type = HAPI_PARTTYPE_MESH;
751 cubePart.faceCount = 6;
752 cubePart.vertexCount = 24;
753 cubePart.pointCount = 8;
754
755 HE_CHECK(HAPI_SetPartInfo(&session, cubeNode, 0, &cubePart))
756
757 HAPI_AttributeInfo attrInfo = HAPI_AttributeInfo_Create();
758
759 attrInfo.count = 8;
760 attrInfo.tupleSize = 3;
761 attrInfo.exists = true;
762 attrInfo.storage = HAPI_STORAGETYPE_FLOAT;
763 attrInfo.owner = HAPI_ATTROWNER_POINT;
764
765 HE_CHECK(HAPI_AddAttribute(&session, cubeNode, 0, "P", &attrInfo))
766
767 float positions[24] = {
768 0.0f, 0.0f, 0.0f,
769 0.0f, 0.0f, 1.0f,
770 0.0f, 1.0f, 0.0f,
771 0.0f, 1.0f, 1.0f,
772 1.0f, 0.0f, 0.0f,
773 1.0f, 0.0f, 1.0f,
774 1.0f, 1.0f, 0.0f,
775 1.0f, 1.0f, 1.0f
776 };
777
778 HE_CHECK(HAPI_SetAttributeFloatData(&session, cubeNode, 0, "P", &attrInfo, positions, 0, 8))
779
780 int vertices[24] = {
781 0, 2, 6, 4,
782 2, 3, 7, 6,
783 2, 0, 1, 3,
784 1, 5, 7, 3,
785 5, 4, 6, 7,
786 0, 4, 5, 1
787 };
788
789 HE_CHECK(HAPI_SetVertexList(&session, cubeNode, 0, vertices, 0, 24))
790
791 int face_counts[6] = {4, 4, 4, 4, 4, 4};
792 HE_CHECK(HAPI_SetFaceCounts(&session, cubeNode, 0, face_counts, 0, 6))
793
794 HE_CHECK(HAPI_AddGroup(&session, cubeNode, cubePart.id, HAPI_GROUPTYPE_POINT, "pointGroup"))
795 int groupElementCount = HAPI_PartInfo_GetElementCountByGroupType(&cubePart, HAPI_GROUPTYPE_POINT);
796
797 int* pointMembership = new int[groupElementCount];
798 for (int ii = 0; ii < groupElementCount; ++ii)
799 {
800 if (ii % 2)
801 {
802 pointMembership[ii] = 1;
803 }
804 else
805 {
806 pointMembership[ii] = 0;
807 }
808 }
809 HE_CHECK(HAPI_SetGroupMembership(&session, cubeNode, cubePart.id, HAPI_GROUPTYPE_POINT, "pointGroup", pointMembership, 0, groupElementCount))
810 HE_CHECK(HAPI_CommitGeo(&session, cubeNode))
811
812 HAPI_NodeId xformNode;
813 HE_CHECK(HAPI_CreateNode(&session, -1, "Sop/xform", "PointGroupManipulator", false, &xformNode))
814 HE_CHECK(HAPI_ConnectNodeInput(&session, xformNode, 0, cubeNode, 0))
815
816 HAPI_NodeInfo xformInfo;
817 HE_CHECK(HAPI_GetNodeInfo(&session, xformNode, &xformInfo))
818
819 HAPI_ParmInfo* parmInfos = new HAPI_ParmInfo[xformInfo.parmCount];
820 HE_CHECK(HAPI_GetParameters(&session, xformNode, parmInfos, 0, xformInfo.parmCount))
821
822 int groupParmIndex = -1;
823 int tParmIndex = -1;
824
825 for (int ii = 0; ii < xformInfo.parmCount; ++ii)
826 {
827 std::string parmName = GetString(session, parmInfos[ii].nameSH);
828 if (parmName == "group")
829 {
830 groupParmIndex = ii;
831 }
832 if (parmName == "t")
833 {
834 tParmIndex = ii;
835 }
836 }
837
838 if (groupParmIndex < 0 || tParmIndex < 0)
839 {
840 std::stringstream ss;
841 ss << "Could not find coords/type parameter on curve node";
842
843 SPICES_CORE_WARN(ss.str());
844 HE_CHECK(HAPI_Cleanup(&session))
845 return;
846 }
847
848 float tParmValue[3] = { 0.0f, 1.0f, 0.0f };
849 HE_CHECK(HAPI_SetParmFloatValues(&session, xformNode, tParmValue, parmInfos[tParmIndex].floatValuesIndex, 3))
850 HE_CHECK(HAPI_SetParmStringValue(&session, xformNode, "pointGroup", groupParmIndex, 0))
851 HE_CHECK(HAPI_CookNode(&session, xformNode, &cookOptions))
852
853 int xformCookStatus;
854 HAPI_Result xformCookResult;
855
856 do
857 {
858 xformCookResult = HAPI_GetStatus(&session, HAPI_STATUS_COOK_RESULT, &xformCookStatus);
859 }
860 while(xformCookStatus > HAPI_STATE_MAX_READY_STATE && xformCookResult == HAPI_RESULT_SUCCESS);
861
862 HE_CHECK(xformCookResult)
863 HE_CHECK_COOK(xformCookStatus)
864
865 HE_CHECK(HAPI_SaveHIPFile(&session, "C:/Users/Administrator/Desktop/Groups_Sample.hip", false))
866
867 HAPI_GeoInfo xformGeoInfo;
868 HE_CHECK(HAPI_GetGeoInfo(&session, xformNode, &xformGeoInfo))
869
870 int numGroups = HAPI_GeoInfo_GetGroupCountByType(&xformGeoInfo, HAPI_GROUPTYPE_POINT);
871
872 HAPI_PartInfo partInfo;
873 HE_CHECK(HAPI_GetPartInfo(&session, xformNode, 0, &partInfo))
874
875 int numElementsInGroup = HAPI_PartInfo_GetElementCountByGroupType(&partInfo, HAPI_GROUPTYPE_POINT);
876
877 int* memberShip = new int[numElementsInGroup];
878 HE_CHECK(HAPI_GetGroupMembership(&session, xformNode, partInfo.id, HAPI_GROUPTYPE_POINT, "pointGroup", nullptr, memberShip, 0, numElementsInGroup))
879
880 for(int ii = 0; ii < numElementsInGroup; ++ii)
881 {
882 if (memberShip[ii])
883 {
884 std::cout << "Point" << ii << "is in pointGroup" << std::endl;
885 }
886 }
887
888 delete[] pointMembership;
889 delete[] memberShip;
890 HE_CHECK(HAPI_Cleanup(&session))
891
892 return;
893 }
#define HE_CHECK_COOK(expr)
HoudiniEngine Check Cook macro. Verify HoudiniEngine Cook API Effectiveness.
Definition HoudiniCore.h:32
#define HE_CHECK(expr)
HoudiniEngine Check macro. Verify HoudiniEngine API Effectiveness.
Definition HoudiniCore.h:17
static std::string GetString(HAPI_Session &session, HAPI_StringHandle stringHandle)