Skip to content

QuakeMDL: Small fixes #2145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions application/testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ f3d_test(NAME TestQuakeMDLAnimationSimpleFrame DATA zombie.mdl ARGS --animation-
f3d_test(NAME TestQuakeMDLAnimationBetween DATA zombie.mdl ARGS --animation-time=1.42)
f3d_test(NAME TestQuakeMDLAnimationMulti DATA soldier_animations.mdl ARGS --animation-index=2 --animation-time=0.5)
f3d_test(NAME TestQuakeMDLAnimationGroupFrame DATA flame_mixed.mdl ARGS --animation-index=1 --animation-time=0.5)
f3d_test(NAME TestQuakeMDLDisableAnimation DATA zombie.mdl soldier_animations.mdl ARGS --multi-file-mode=all --animation-time=0.5)
if(VTK_VERSION VERSION_GREATER_EQUAL 9.3.20240707)
f3d_test(NAME TestQuakeMDLActorCollection DATA zombie.mdl ARGS --scalar-coloring)
endif()
f3d_test(NAME TestGridX DATA suzanne.ply ARGS -g --up=+X)
f3d_test(NAME TestGridY DATA suzanne.ply ARGS -g --up=+Y)
f3d_test(NAME TestGridZ DATA suzanne.ply ARGS -g --up=+Z)
Expand Down
55 changes: 28 additions & 27 deletions plugins/native/module/vtkF3DQuakeMDLImporter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -413,20 +413,6 @@ struct vtkF3DQuakeMDLImporter::vtkInternals
return ret;
}

//----------------------------------------------------------------------------
void ImportActors(vtkRenderer* renderer)
{
vtkNew<vtkActor> actor;
vtkNew<vtkPolyDataMapper> mapper;
mapper->SetInputData(this->AnimationFrames[0][0]);
actor->SetMapper(mapper);
actor->GetProperty()->SetInterpolationToPBR();
actor->GetProperty()->SetBaseColorTexture(Texture);
actor->GetProperty()->SetBaseIOR(1.0);
renderer->AddActor(actor);
this->Mapper = mapper;
}

//----------------------------------------------------------------------------
vtkF3DQuakeMDLImporter* Parent;
std::string Description;
Expand All @@ -437,7 +423,7 @@ struct vtkF3DQuakeMDLImporter::vtkInternals
std::vector<std::vector<double>> AnimationTimes;
std::vector<std::vector<vtkSmartPointer<vtkPolyData>>> AnimationFrames;

vtkIdType ActiveAnimation = 0;
vtkIdType ActiveAnimation = -1;
};

//----------------------------------------------------------------------------
Expand All @@ -455,26 +441,41 @@ int vtkF3DQuakeMDLImporter::ImportBegin()
//----------------------------------------------------------------------------
void vtkF3DQuakeMDLImporter::ImportActors(vtkRenderer* renderer)
{
this->Internals->ImportActors(renderer);
vtkNew<vtkActor> actor;
vtkNew<vtkPolyDataMapper> mapper;
mapper->SetInputData(this->Internals->AnimationFrames[0][0]);
actor->SetMapper(mapper);
actor->GetProperty()->SetInterpolationToPBR();
actor->GetProperty()->SetBaseColorTexture(this->Internals->Texture);
actor->GetProperty()->SetBaseIOR(1.0);
renderer->AddActor(actor);
this->Internals->Mapper = mapper;

#if VTK_VERSION_NUMBER >= VTK_VERSION_CHECK(9, 3, 20240707)
this->ActorCollection->AddItem(actor);
#endif
}

//----------------------------------------------------------------------------
bool vtkF3DQuakeMDLImporter::UpdateAtTimeValue(double timeValue)
{
const std::vector<double>& times =
this->Internals->AnimationTimes[this->Internals->ActiveAnimation];
if (this->Internals->ActiveAnimation != -1)
{
const std::vector<double>& times =
this->Internals->AnimationTimes[this->Internals->ActiveAnimation];

// Find frameIndex for the provided timeValue so that t0 <= timeValue < t1
// Find frameIndex for the provided timeValue so that t0 <= timeValue < t1

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

this->Internals->Mapper->SetInputData(
this->Internals->AnimationFrames[this->Internals->ActiveAnimation][frameIndex]);
this->Internals->Mapper->SetInputData(
this->Internals->AnimationFrames[this->Internals->ActiveAnimation][frameIndex]);
}
return true;
}

Expand Down
3 changes: 3 additions & 0 deletions testing/baselines/TestQuakeMDLActorCollection.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions testing/baselines/TestQuakeMDLDisableAnimation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.