From cee746a6d914fa166b95185b410ede58004aa682 Mon Sep 17 00:00:00 2001 From: Dustinspace217 Date: Wed, 18 Nov 2026 01:22:10 -0800 Subject: [PATCH 1/2] Check collision LOD pieces that have no detail0 partner With $Collision LOD set, collision walked the detail0 tree and swapped each piece for its lower-detail partner, so pieces that exist only in the lower detail model were never checked and shots passed through them. Also walk the collision LOD's children that have no detail0 partner. --- code/model/modelcollide.cpp | 91 ++++++++++++++++++++----------------- 1 file changed, 49 insertions(+), 42 deletions(-) diff --git a/code/model/modelcollide.cpp b/code/model/modelcollide.cpp index ea958f70e0b..5202922b0d1 100644 --- a/code/model/modelcollide.cpp +++ b/code/model/modelcollide.cpp @@ -937,6 +937,20 @@ void mc_check_subobj( int mn ) sm = &Mc_pm->submodel[mn]; if (sm->flags[Model::Submodel_flags::No_collisions]) return; // don't do collisions + + bsp_info* lod_sm = sm; + if (Mc->lod > 0 && sm->num_details > 0) { + for (i = Mc->lod - 1; i >= 0; i--) { + if (sm->details[i] != -1) { + lod_sm = &Mc_pm->submodel[sm->details[i]]; + + // mprintf(("Checking %s collision for %s using %s instead\n", Mc_pm->filename, sm->name, + // lod_sm->name)); + break; + } + } + } + if (sm->flags[Model::Submodel_flags::Nocollide_this_only]) goto NoHit; // Don't collide for this model, but keep checking others if (Mc->flags & MC_RESPECT_DETAIL_BOX_SPHERE) { @@ -1011,23 +1025,7 @@ void mc_check_subobj( int mn ) } else { // The ray intersects this bounding box, so we have to check all the // polygons in this submodel. - if (Mc->lod > 0 && sm->num_details > 0) { - bsp_info* lod_sm = sm; - - for (i = Mc->lod - 1; i >= 0; i--) { - if (sm->details[i] != -1) { - lod_sm = &Mc_pm->submodel[sm->details[i]]; - - // mprintf(("Checking %s collision for %s using %s instead\n", Mc_pm->filename, sm->name, - // lod_sm->name)); - break; - } - } - - model_collide_bsp(model_get_bsp_collision_tree(lod_sm->collision_tree_index), 0); - } else { - model_collide_bsp(model_get_bsp_collision_tree(sm->collision_tree_index), 0); - } + model_collide_bsp(model_get_bsp_collision_tree(lod_sm->collision_tree_index), 0); } } @@ -1040,42 +1038,51 @@ void mc_check_subobj( int mn ) // If this subobject doesn't have any children, we're done checking it. - if ( sm->num_children < 1 ) return; + if (sm->num_children < 1 && lod_sm->num_children < 1) + return; // Save instance (Mc_orient, Mc_base, Mc_point_base) matrix saved_orient = Mc_orient; vec3d saved_base = Mc_base; - // Check all of this subobject's children - i = sm->first_child; - while ( i >= 0 ) { - auto csm = &Mc_pm->submodel[i]; - matrix instance_orient = vmd_identity_matrix; - vec3d instance_offset = csm->offset; - bool blown_off = false; - bool collision_checked = false; - - if ( Mc_pmi ) { - auto csmi = &Mc_pmi->submodel[i]; - instance_orient = csmi->canonical_orient; - vm_vec_add2(&instance_offset, &csmi->canonical_offset); + // Check all of this subobject's children, plus its collision LOD's children that no detail0 piece leads to + for (auto parent : {sm, lod_sm}) { + i = parent->first_child; + while ( i >= 0 ) { + auto csm = &Mc_pm->submodel[i]; + matrix instance_orient = vmd_identity_matrix; + vec3d instance_offset = csm->offset; + bool blown_off = false; + bool collision_checked = false; + bool reached_through_partner = parent != sm && csm->flags[Model::Submodel_flags::Is_lod]; + + if ( Mc_pmi ) { + auto csmi = &Mc_pmi->submodel[i]; + instance_orient = csmi->canonical_orient; + vm_vec_add2(&instance_offset, &csmi->canonical_offset); - blown_off = csmi->blown_off; - collision_checked = !Mc->collision_checked.empty() && Mc->collision_checked[i]; - } + blown_off = csmi->blown_off; + collision_checked = !Mc->collision_checked.empty() && Mc->collision_checked[i]; + } - // Don't check it or its children if it is destroyed - // or if it's set to no collision - if ( !blown_off && !collision_checked && !csm->flags[Model::Submodel_flags::No_collisions] ) { - vm_vec_unrotate(&Mc_base, &instance_offset, &saved_orient); - vm_vec_add2(&Mc_base, &saved_base); + // Don't check it or its children if it is destroyed + // or if it's set to no collision + if (!blown_off && !collision_checked && !reached_through_partner && + !csm->flags[Model::Submodel_flags::No_collisions]) { + vm_vec_unrotate(&Mc_base, &instance_offset, &saved_orient); + vm_vec_add2(&Mc_base, &saved_base); + + vm_matrix_x_matrix(&Mc_orient, &saved_orient, &instance_orient); - vm_matrix_x_matrix(&Mc_orient, &saved_orient, &instance_orient); + mc_check_subobj( i ); + } - mc_check_subobj( i ); + i = csm->next_sibling; } - i = csm->next_sibling; + if (lod_sm == sm) { + break; + } } } From 4c8f2ee156fff5132799aa24524d9f9e1406655a Mon Sep 17 00:00:00 2001 From: Dustinspace217 Date: Wed, 18 Nov 2026 01:34:57 -0800 Subject: [PATCH 2/2] Walk unpartnered collision LOD pieces from the detail0 root only LOD partners are paired by name, so two pieces in the detail0 tree can pair with each other; walking a partner's children from every swapped piece could then revisit the same tree. Only the detail0 root walks its collision LOD's unpartnered children, and inside that tree lower-detail partners are skipped because their detail0 piece already checks them. --- code/model/modelcollide.cpp | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/code/model/modelcollide.cpp b/code/model/modelcollide.cpp index 5202922b0d1..4f4a0d0abcc 100644 --- a/code/model/modelcollide.cpp +++ b/code/model/modelcollide.cpp @@ -924,7 +924,7 @@ void mc_check_shield() // This function recursively checks a submodel and its children // for a collision with a vector. -void mc_check_subobj( int mn ) +void mc_check_subobj(int mn, bool in_lod_tree = false) { vec3d tempv; vec3d hitpt; // used in bounding box check @@ -940,12 +940,9 @@ void mc_check_subobj( int mn ) bsp_info* lod_sm = sm; if (Mc->lod > 0 && sm->num_details > 0) { - for (i = Mc->lod - 1; i >= 0; i--) { - if (sm->details[i] != -1) { - lod_sm = &Mc_pm->submodel[sm->details[i]]; - - // mprintf(("Checking %s collision for %s using %s instead\n", Mc_pm->filename, sm->name, - // lod_sm->name)); + for (int lod = Mc->lod - 1; lod >= 0; lod--) { + if (sm->details[lod] != -1) { + lod_sm = &Mc_pm->submodel[sm->details[lod]]; break; } } @@ -1045,16 +1042,18 @@ void mc_check_subobj( int mn ) matrix saved_orient = Mc_orient; vec3d saved_base = Mc_base; - // Check all of this subobject's children, plus its collision LOD's children that no detail0 piece leads to + // Check all of this subobject's children; the root also checks its collision LOD's unpartnered children for (auto parent : {sm, lod_sm}) { - i = parent->first_child; - while ( i >= 0 ) { + bool lod_tree = in_lod_tree || parent != sm; + for (i = parent->first_child; i >= 0; i = Mc_pm->submodel[i].next_sibling) { auto csm = &Mc_pm->submodel[i]; + // A lower-detail partner is checked through its detail0 piece + if (lod_tree && csm->flags[Model::Submodel_flags::Is_lod]) + continue; matrix instance_orient = vmd_identity_matrix; vec3d instance_offset = csm->offset; bool blown_off = false; bool collision_checked = false; - bool reached_through_partner = parent != sm && csm->flags[Model::Submodel_flags::Is_lod]; if ( Mc_pmi ) { auto csmi = &Mc_pmi->submodel[i]; @@ -1067,20 +1066,17 @@ void mc_check_subobj( int mn ) // Don't check it or its children if it is destroyed // or if it's set to no collision - if (!blown_off && !collision_checked && !reached_through_partner && - !csm->flags[Model::Submodel_flags::No_collisions]) { + if ( !blown_off && !collision_checked && !csm->flags[Model::Submodel_flags::No_collisions] ) { vm_vec_unrotate(&Mc_base, &instance_offset, &saved_orient); vm_vec_add2(&Mc_base, &saved_base); vm_matrix_x_matrix(&Mc_orient, &saved_orient, &instance_orient); - mc_check_subobj( i ); + mc_check_subobj(i, lod_tree); } - - i = csm->next_sibling; } - if (lod_sm == sm) { + if (lod_sm == sm || mn != Mc_pm->detail[0]) { break; } }