CompuServe Messages

#Select/Deselect

    24-Feb-95 17:19:23
Sb: #Select/Deselect
Fm: MARK A. MEIER 76330,3402
To: All
I have a question about how to select or deselect an object using a PXP. It seems that three things need to happen: – All the objects verticies must be selected – All the objects faces must be selected – The objects selected flag must be set. I have written the code below to try to do this. It does not work however. I can select an object, but I cannot deselect it. If anyone has done something similiar, I'd appreciate if you could review the code below and offer any suggestions. It is assumed a global ItemData structure called item_data exists and is properly loaded with a mesh object… Thanks, Mark int do_toggle_selection(void) { int index, status; // Save the function address for re-execution get_function_index(do_toggle_selection, &last_function); if (! item_loaded("Toggle Selection", last_function)) return(0); if (item_index) { if (item_type == ITEM_MESH) { if (item_data.item.m.flags & MESH_SELECTED) { status = set_object_selected_state(0); // Toggle Off } else { status = set_object_selected_state(1); // Toggle On } if (status) { pxp_erase_item(item_name); pxp_change_item(&item_data, status); pxp_draw_item(item_name); } else { fmsg("Error: Could not Toggle object \"%s\" Selected state", item_name); } } } return(1); } // This function selects/deselects all the objects verticies and faces // and sets/clears the objects selected flag based on the state passed. // Note: The object is selected/deselected in the 'current' // 3ds selection set (A, B or C). // The object to be modified should be loaded into the global item_data. int set_object_selected_state(int select_it) { int i, faces, verts, status; XFData2 *fdata = NULL; XVData *vdata = NULL; // Allocate temp space for the objects verts/faces verts = item_data.item.m.verts; faces = item_data.item.m.faces; if (! (vdata = (XVData *)malloc(faces*sizeof(XVData)))) { return(0); } if (! (fdata = (XFData2 *)malloc(faces*sizeof(XFData2)))) { free(vdata); return(0); } // Set all the verticies pxp_get_verts(item_data.name, 0, verts, vdata, status); if (status == 0) { free(vdata); free(fdata); fmsg("Could not get Vertex Info for object \"%s\"", item_data.name); return(0); } for (i = 0; i < verts; i++) { if (select_it) { // vdata[i].flags |= (unsigned short) (XV_SELECTED | XV_SEL_A); vdata[i].flags |= (unsigned short) XV_SELECTED; } else { // vdata[i].flags &= (unsigned short) ~(XV_SELECTED | XV_SEL_A); vdata[i].flags &= (unsigned short) ~XV_SELECTED; } } pxp_put_verts(item_data.name, 0, verts, vdata, status); // Set all the faces pxp_get_faces2(item_data.name, 0, faces, fdata, status); if (status == 0) { free(vdata); free(fdata); fmsg("Could not get Face Info for object \"%s\"", item_data.name); return(0); } for (i = 0; i < faces; i++) { if (select_it) { // fdata[i].flags |= (unsigned short) (XF_SELECTED | XF_SEL_A); fdata[i].flags |= (unsigned short) XF_SELECTED; } else { // fdata[i].flags &= (unsigned short) ~(XF_SELECTED | XF_SEL_A); fdata[i].flags &= (unsigned short) ~XF_SELECTED; } } pxp_put_faces2(item_data.name, 0, faces, fdata, status); // Set/Clear the object selected flag if (select_it) { item_data.item.m.flags |= (unsigned short) MESH_SELECTED; } else { item_data.item.m.flags &= (unsigned short) ~MESH_SELECTED; } free(vdata); free(fdata); return(status); }