Search code examples
openinventor

How to get clicked face object from SoIndexedFaceSet node in Open Inventor


I have a SoIndexedFaceSet object rendered in 3D window, and a SoEventCallback is also added. I can get that SoIndexedFaceSet node object from event callback when it's clicked. Is it possible to get which face is clicked? I do some research about that event, but no found. Is it possible to do that? if yes, how to do that? If no, any suggestions about how to implement ?

Thanks


Solution

  • Yes, this is possible and is a classic Open Inventor pattern. Short answer: Query the SoFaceDetail, then query the face index. Example below. Note that I omitted a lot of related code you probably already have, like getting the pick path and picked node.

    void onMouseEvent(void* data, SoEventCallback* node)
    {
      . . .
      auto pick = node->getPickedPoint();
      if (pick != nullptr) {
        auto faceDetail = dynamic_cast<const SoFaceDetail*>(pick->getDetail());
        if (faceDetail != nullptr) {
          int faceIndex = faceDetail->getFaceIndex();