Skip to content

Commit e8e446b

Browse files
authored
QuakeMDL: Small fixes (#2145)
* QuakeMDL: Fix disabling animation * QuakeMDL: Fix actor collection
1 parent cb3e9ae commit e8e446b

File tree

4 files changed

+38
-27
lines changed

4 files changed

+38
-27
lines changed

application/testing/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,10 @@ f3d_test(NAME TestQuakeMDLAnimationSimpleFrame DATA zombie.mdl ARGS --animation-
166166
f3d_test(NAME TestQuakeMDLAnimationBetween DATA zombie.mdl ARGS --animation-time=1.42)
167167
f3d_test(NAME TestQuakeMDLAnimationMulti DATA soldier_animations.mdl ARGS --animation-index=2 --animation-time=0.5)
168168
f3d_test(NAME TestQuakeMDLAnimationGroupFrame DATA flame_mixed.mdl ARGS --animation-index=1 --animation-time=0.5)
169+
f3d_test(NAME TestQuakeMDLDisableAnimation DATA zombie.mdl soldier_animations.mdl ARGS --multi-file-mode=all --animation-time=0.5)
170+
if(VTK_VERSION VERSION_GREATER_EQUAL 9.3.20240707)
171+
f3d_test(NAME TestQuakeMDLActorCollection DATA zombie.mdl ARGS --scalar-coloring)
172+
endif()
169173
f3d_test(NAME TestGridX DATA suzanne.ply ARGS -g --up=+X)
170174
f3d_test(NAME TestGridY DATA suzanne.ply ARGS -g --up=+Y)
171175
f3d_test(NAME TestGridZ DATA suzanne.ply ARGS -g --up=+Z)

plugins/native/module/vtkF3DQuakeMDLImporter.cxx

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -413,20 +413,6 @@ struct vtkF3DQuakeMDLImporter::vtkInternals
413413
return ret;
414414
}
415415

416-
//----------------------------------------------------------------------------
417-
void ImportActors(vtkRenderer* renderer)
418-
{
419-
vtkNew<vtkActor> actor;
420-
vtkNew<vtkPolyDataMapper> mapper;
421-
mapper->SetInputData(this->AnimationFrames[0][0]);
422-
actor->SetMapper(mapper);
423-
actor->GetProperty()->SetInterpolationToPBR();
424-
actor->GetProperty()->SetBaseColorTexture(Texture);
425-
actor->GetProperty()->SetBaseIOR(1.0);
426-
renderer->AddActor(actor);
427-
this->Mapper = mapper;
428-
}
429-
430416
//----------------------------------------------------------------------------
431417
vtkF3DQuakeMDLImporter* Parent;
432418
std::string Description;
@@ -437,7 +423,7 @@ struct vtkF3DQuakeMDLImporter::vtkInternals
437423
std::vector<std::vector<double>> AnimationTimes;
438424
std::vector<std::vector<vtkSmartPointer<vtkPolyData>>> AnimationFrames;
439425

440-
vtkIdType ActiveAnimation = 0;
426+
vtkIdType ActiveAnimation = -1;
441427
};
442428

443429
//----------------------------------------------------------------------------
@@ -455,26 +441,41 @@ int vtkF3DQuakeMDLImporter::ImportBegin()
455441
//----------------------------------------------------------------------------
456442
void vtkF3DQuakeMDLImporter::ImportActors(vtkRenderer* renderer)
457443
{
458-
this->Internals->ImportActors(renderer);
444+
vtkNew<vtkActor> actor;
445+
vtkNew<vtkPolyDataMapper> mapper;
446+
mapper->SetInputData(this->Internals->AnimationFrames[0][0]);
447+
actor->SetMapper(mapper);
448+
actor->GetProperty()->SetInterpolationToPBR();
449+
actor->GetProperty()->SetBaseColorTexture(this->Internals->Texture);
450+
actor->GetProperty()->SetBaseIOR(1.0);
451+
renderer->AddActor(actor);
452+
this->Internals->Mapper = mapper;
453+
454+
#if VTK_VERSION_NUMBER >= VTK_VERSION_CHECK(9, 3, 20240707)
455+
this->ActorCollection->AddItem(actor);
456+
#endif
459457
}
460458

461459
//----------------------------------------------------------------------------
462460
bool vtkF3DQuakeMDLImporter::UpdateAtTimeValue(double timeValue)
463461
{
464-
const std::vector<double>& times =
465-
this->Internals->AnimationTimes[this->Internals->ActiveAnimation];
462+
if (this->Internals->ActiveAnimation != -1)
463+
{
464+
const std::vector<double>& times =
465+
this->Internals->AnimationTimes[this->Internals->ActiveAnimation];
466466

467-
// Find frameIndex for the provided timeValue so that t0 <= timeValue < t1
467+
// Find frameIndex for the provided timeValue so that t0 <= timeValue < t1
468468

469-
// First time >= value
470-
const auto found = std::lower_bound(times.begin(), times.end(), timeValue);
471-
// If none, select last, if found, select distance
472-
const size_t i = found == times.end() ? times.size() - 1 : std::distance(times.begin(), found);
473-
// If found time > timeValue, the the previous one
474-
const size_t frameIndex = *found > timeValue && i > 0 ? i - 1 : i;
469+
// First time >= value
470+
const auto found = std::lower_bound(times.begin(), times.end(), timeValue);
471+
// If none, select last, if found, select distance
472+
const size_t i = found == times.end() ? times.size() - 1 : std::distance(times.begin(), found);
473+
// If found time > timeValue, the the previous one
474+
const size_t frameIndex = *found > timeValue && i > 0 ? i - 1 : i;
475475

476-
this->Internals->Mapper->SetInputData(
477-
this->Internals->AnimationFrames[this->Internals->ActiveAnimation][frameIndex]);
476+
this->Internals->Mapper->SetInputData(
477+
this->Internals->AnimationFrames[this->Internals->ActiveAnimation][frameIndex]);
478+
}
478479
return true;
479480
}
480481

Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)