Swap actor body to _lod_ meshes by camera distance

Port CGrannyLODController level selection: _lod_01.._03 are queued
{lod_03, lod_02, lod_01, main}, loaded lazily, and chosen from the
camera-target/camera distance bands (actors) or the building factor.
Parts, skins and the current motion follow the drawn instance.

Shipped LODs that drop an attaching bone in use (lion2_lod_02/03 lose
"saddle", shaman_miyeom_lod_* lose equip_left/right) stay on PART_MAIN,
and bone queries fall back to PART_MAIN for bones a LOD lacks.
Weapon item LODs are not ported.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shenlei
2026-10-12 17:56:41 +09:00
co-authored by Claude Opus 5.5
parent 6282199179
commit bfd42bd776
3 changed files with 167 additions and 22 deletions
+30 -7
View File
@@ -829,31 +829,54 @@ int main(int argc, char** argv) {
assert(!actor.IsVisible(cullCamera.GetViewMatrix(),cullCamera.GetProjMatrix()));
assert(actor.GetModel()->GetImpl()->GetPoseEvaluationCount()==poseBeforeCull);
// CGrannyLODController: warrior_assasin1 has _lod_ models, so far from the camera it animates at
// ANIFPS_MIN (pose re-sampled every 4/120 s) and near the camera target at full rate.
// CGrannyLODController: warrior_assasin1 has _lod_01.._03, queued {lod_03, lod_02, lod_01, main}.
// Far from the camera it draws the coarsest LOD at ANIFPS_MIN (pose re-sampled every 4/120 s);
// near the camera target it draws the main model at full rate.
actor.SetPosition(0,0,0);
assert(actor.GetLODCount()==4);
actor.UpdateLODLevel(0,200,-300,0,0);
assert(actor.GetLODAniFPS()==120);
assert(actor.GetLODAniFPS()==120 && actor.GetLODLevel()==3 && actor.GetDrawModel()==actor.GetModel());
actor.UpdateLODLevel(0,200,-1000,2000,0);
assert(actor.GetLODLevel()==2 && actor.GetDrawModel()->GetFilePath().find("_lod_01.gr2")!=std::string::npos);
actor.UpdateLODLevel(0,200,-2000,2000,0);
assert(actor.GetLODLevel()==1 && actor.GetDrawModel()->GetFilePath().find("_lod_02.gr2")!=std::string::npos);
actor.UpdateLODLevel(0,200,-4900,2000,0);
assert(actor.GetLODAniFPS()==30);
assert(actor.GetLODAniFPS()==30 && actor.GetLODLevel()==0);
assert(actor.GetDrawModel()->GetFilePath().find("_lod_03.gr2")!=std::string::npos);
assert(!actor.BuildDrawCommands().empty());
float lodBone[16];
assert(actor.GetBoneWorldTransform("Bip01 Spine",lodBone));
const auto poseBeforeLod=actor.GetModel()->GetImpl()->GetPoseEvaluationCount();
const auto poseBeforeLod=actor.GetDrawModel()->GetImpl()->GetPoseEvaluationCount();
for(int frame=0;frame<24;++frame){
actor.Update(1.0f/60.0f,&terrain);
actor.UpdateLODLevel(0,200,-4900,2000,0);
assert(actor.GetBoneWorldTransform("Bip01 Spine",lodBone));
}
const auto farEvaluations=actor.GetModel()->GetImpl()->GetPoseEvaluationCount()-poseBeforeLod;
const auto farEvaluations=actor.GetDrawModel()->GetImpl()->GetPoseEvaluationCount()-poseBeforeLod;
assert(farEvaluations>=10 && farEvaluations<=14 && "30 FPS animation over 0.4 s");
actor.UpdateLODLevel(0,200,-300,0,0);
assert(actor.GetDrawModel()==actor.GetModel());
const auto poseNear=actor.GetModel()->GetImpl()->GetPoseEvaluationCount();
for(int frame=0;frame<24;++frame){
actor.Update(1.0f/60.0f,&terrain);
actor.UpdateLODLevel(0,200,-300,0,0);
assert(actor.GetBoneWorldTransform("Bip01 Spine",lodBone));
}
assert(actor.GetModel()->GetImpl()->GetPoseEvaluationCount()-poseBeforeLod-farEvaluations==24);
assert(actor.GetModel()->GetImpl()->GetPoseEvaluationCount()-poseNear==24);
assert(actor.IsVisible(nullptr,nullptr));
// lion2_lod_02/03 dropped the "saddle" bone the rider attaches to: those levels stay on PART_MAIN.
{
ava2::ActorInstance mount;
assert(mount.SetModel("ymir work/npc/lion_2/lion2.gr2") && mount.GetLODCount()==4);
mount.UpdateLODLevel(0,200,-1000,2000,0);
assert(mount.GetLODLevel()==2 && mount.GetDrawModel()!=mount.GetModel());
mount.UpdateLODLevel(0,200,-4900,2000,0);
assert(mount.GetLODLevel()==3 && mount.GetDrawModel()==mount.GetModel());
float saddle[16];
assert(mount.GetBoneWorldTransform("saddle",saddle));
}
// Test movement driving
actor.SetPosition(0.0f, 0.0f, 0.0f);
actor.MoveInDirection(90.0f, 0.2f, &terrain); // Move East