How To: Select invisible vertices and turn visibility ON on selected vertices

This is sample code on how to select invisible vertices and turn ON selected vertices. (3DF)

// only select vertices
    HC_Open_Segment_By_Key(m_pHView->GetModelKey()); {
            HC_Set_Selectability("faces=off,vertices=!on,edges=off");
			HC_Set_Visibility("vertices=off");
    } HC_Close_Segment();

    m_pHView->Update();

// sub-entity selection
    HC_Open_Segment_By_Key(m_pHView->GetViewKey()); {
        HC_Set_Heuristics("selection level = entity, no related selection limit, no internal selection limit");

// select top half of screen
        int count = HC_Compute_Selection_By_Area(".", "./scene/overwrite", "v", -1, 1, 0, 1);

        if (count > 0)
        {

            HC_KEY selectionKey = -1;
            HC_Show_Selection_Elements_Coun(&selectionKey, &count);

            int *vertex1 = new int[count];
            int *vertex2 = new int[count];
            int *faces = new int[count];

            for (int i = 0; i < count; i++) {
                vertex1[i] = -1;
                vertex2[i] = -1;
                faces[i] = -1;
            }
            HC_Show_Selection_Elements(&selectionKey, &count, vertex1, vertex2, faces);

            // create a list of selected vertices			
            int found = 0;
            int *highlight_vertex_list = new int[count];

            // Iterate through vertex1
            // Compare vertex2 to determine if vertices is selected

            // See Link on how to identify selected vertices/edges/faces          //https://docs.techsoft3d.com/3df/latest/api_ref/3dgs/hc__proto_8h.html#_CPPv426HC_Show_Selection_ElementsP3KeyPiA_iA_iA_i
            int ii=0;
            for (ii = 0; ii < count; ii++)

            {            
                if (vertex2[ii] == -1)
                {
                    highlight_vertex_list[found] = vertex1[ii];
                    found++;
                }
            }

            // visibility array, initialize to 1
            char* visbility_on = new char[found];
            std::fill(visbility_on, visbility_on + found, (char)1);
            HC_MSet_Specific_Vertex_Vis(selectionKey, found, highlight_vertex_list, visbility_on);


            // highlight array,  initialize to 0 (black)
            int color_size = found * 3;
            float* highlight_vertex_color = new float[color_size];
            memset(highlight_vertex_color, 0, sizeof(float) * color_size);
            HC_MSet_Specific_Vertex_Colors_By_Value(selectionKey, "vertex", found, highlight_vertex_list, "RGB", highlight_vertex_color);


            // delete all dynamic arrays
            delete[] vertex1;
            delete[] vertex2;
            delete[] faces;
            delete[] visbility_on;
            delete[] highlight_vertex_color;

            m_pHView->Update();

        }
        
    } HC_Close_Segment();

LINK:

HC_Show_Selection_Elements

Video:

2023-12-14_15-54-11

1 Like