@@ -1497,6 +1497,7 @@ void GLView::renderBSP(const QString &file, const mbsp_t &bsp, const bspxentries
14971497 {
14981498 const mface_t *face;
14991499 qvec3d model_offset;
1500+ int modelindex;
15001501 };
15011502
15021503 // collect faces grouped by material_key
@@ -1571,7 +1572,7 @@ void GLView::renderBSP(const QString &file, const mbsp_t &bsp, const bspxentries
15711572 }
15721573
15731574 material_key k = {.program = program, .texname = t, .opacity = opacity, .alpha_test = alpha_test};
1574- faces_by_material_key[k].push_back ({.face = &f, .model_offset = origin});
1575+ faces_by_material_key[k].push_back ({.face = &f, .model_offset = origin, . modelindex = mi });
15751576 }
15761577 }
15771578
@@ -1704,7 +1705,7 @@ void GLView::renderBSP(const QString &file, const mbsp_t &bsp, const bspxentries
17041705 qtexture = skybox_texture;
17051706 }
17061707
1707- for (const auto &[f, model_offset] : faces) {
1708+ for (const auto &[f, model_offset, modelindex ] : faces) {
17081709 const int fnum = Face_GetNum (&bsp, f);
17091710 const auto plane_normal = Face_Normal (&bsp, f);
17101711 qvec3f flat_color = qvec3f{Random (), Random (), Random ()};
@@ -1765,12 +1766,19 @@ void GLView::renderBSP(const QString &file, const mbsp_t &bsp, const bspxentries
17651766 }
17661767
17671768 // populate spatial index
1769+
1770+ int worldfaces_begin = bsp.dmodels [0 ].firstface ;
1771+ int worldfaces_end = worldfaces_begin + bsp.dmodels [0 ].numfaces ;
1772+
17681773 for (const auto &[k, faces] : faces_by_material_key) {
17691774 for (const face_payload &facePayload : faces) {
17701775 int face_num = Face_GetNum (&bsp, facePayload.face );
17711776
1777+ bool is_world = (facePayload.modelindex == 0 );
1778+ uint32_t mask = is_world ? GEOM_MASK_WORLD : GEOM_MASK_BMODEL;
1779+
17721780 // FIXME: face offset
1773- m_spatialindex->add_poly (Face_Winding (&bsp, facePayload.face ), std::make_any<int >(face_num));
1781+ m_spatialindex->add_poly (Face_Winding (&bsp, facePayload.face ), std::make_any<int >(face_num), mask );
17741782 }
17751783 }
17761784 m_spatialindex->commit ();
@@ -2258,7 +2266,11 @@ void GLView::clickFace(QMouseEvent *event)
22582266 QVector3D ray_dir = (ws2_a - ws_a).normalized ();
22592267
22602268 // trace a ray
2261- auto hit = m_spatialindex->trace_ray (qvec3f (ws_a[0 ], ws_a[1 ], ws_a[2 ]), qvec3f (ray_dir[0 ], ray_dir[1 ], ray_dir[2 ]));
2269+ uint32_t ray_mask = GEOM_MASK_WORLD;
2270+ if (m_showBmodels)
2271+ ray_mask |= GEOM_MASK_BMODEL;
2272+
2273+ auto hit = m_spatialindex->trace_ray (qvec3f (ws_a[0 ], ws_a[1 ], ws_a[2 ]), qvec3f (ray_dir[0 ], ray_dir[1 ], ray_dir[2 ]), ray_mask);
22622274
22632275 if (hit.hit ) {
22642276 m_selected_face = *std::any_cast<int >(hit.hitpayload );
0 commit comments