Skip to content
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

Quake MDL feature #1591

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open

Quake MDL feature #1591

wants to merge 24 commits into from

Conversation

Youva
Copy link

@Youva Youva commented Aug 25, 2024

Adds class vtkQuakeMDLImporter that reads .MDL files.

The class :

  • Reads vertices and triangle data from the format to display a model.
  • Reads a texture and texture coordinates from the format to display onto the model.
  • Reads animations, stored as an array of vertices in the file, and saves them as a vector of polydata.
  • Groups animations and displays them.
  • Adds light sources to the scene.

Copy link

codecov bot commented Sep 24, 2024

Codecov Report

Attention: Patch coverage is 0% with 267 lines in your changes missing coverage. Please review.

Project coverage is 93.58%. Comparing base (5f3745f) to head (98f7e72).
Report is 9 commits behind head on master.

Files with missing lines Patch % Lines
plugins/native/module/vtkQuakeMDLImporter.cxx 0.00% 261 Missing ⚠️
plugins/native/module/vtkQuakeMDLImporter.h 0.00% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1591      +/-   ##
==========================================
- Coverage   96.82%   93.58%   -3.24%     
==========================================
  Files         108      110       +2     
  Lines        7643     7938     +295     
==========================================
+ Hits         7400     7429      +29     
- Misses        243      509     +266     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

#include <vtkNew.h>
#include <vtkPolyDataAlgorithm.h>
#include <vtkVersion.h>

#include <memory>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to move this

-#include <memory>

class vtkF3DAlembicReader : public vtkPolyDataAlgorithm
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can remove this file

-
}

//----------------------------------------------------------------------------
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can remove this file

f3d_plugin_declare_reader(
NAME QuakeMDL
EXTENSIONS mdl
MIMETYPES application/vnd.mdl
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you have a small .mdl file with a creative commons license ?

-
}

//----------------------------------------------------------------------------
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can remove this file


renderer->AddLight(frontLight);
renderer->AddLight(leftLight);
renderer->AddLight(backLight);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any specific reason for adding lights ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same question, I don't think it's needed.

{ -0.850651f, 0.000000f, -0.525731f }, { -0.688191f, 0.587785f, -0.425325f },
{ -0.587785f, 0.425325f, -0.688191f }, { -0.425325f, 0.688191f, -0.587785f },
{ -0.425325f, -0.688191f, -0.587785f }, { -0.587785f, -0.425325f, -0.688191f },
{ -0.688191f, -0.587785f, -0.425325f } };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what are those big number lists ?

//----------------------------------------------------------------------------
std::string vtkQuakeMDLImporter::GetAnimationName(vtkIdType animationIndex)
{
return std::to_string(animationIndex);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

animation are not named ?

//----------------------------------------------------------------------------
void vtkQuakeMDLImporter::DisableAnimation(vtkIdType vtkNotUsed(animationIndex))
{
return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing an implementation

}

// Only one animation enabled at a time
void EnableAnimation(vtkIdType animationIndex)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only one animation can be enabled at a time ?

{
this->Superclass::PrintSelf(os, indent);
os << indent << "FileName: " << this->FileName << "\n";
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can remove PrintSelf method imo

* Set/Get the file name.
*/
vtkSetMacro(FileName, std::string);
vtkGetMacro(FileName, std::string);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can remove this method

///@{
/**
* Enable/Disable/Get the status of specific animations
* Only one single animation can be enabled
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a limitation of the assimp importer, but can it be implemented correctly here ?

* Set/Get collada fixup flag.
*/
vtkSetMacro(ColladaFixup, bool);
vtkGetMacro(ColladaFixup, bool);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can remove this

roll->RotateX(270);
roll->RotateZ(270);
renderer->GetActiveCamera()->SetPosition(cameraPosition);
renderer->GetActiveCamera()->SetModelTransformMatrix(roll->GetMatrix());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why adding a camera ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably to correct the actor orientation. Are MDL files +Z up by default? Then you just need to specify it in the config files (improvements of config file is missing by the way).

-

void PrintSelf(ostream& os, vtkIndent indent) override;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can remove this file

Copy link
Contributor

@mwestphal mwestphal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changes needed

Copy link
Contributor

@Meakk Meakk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work @Youva !!
There is still some clean-up to do, especially memory leaks to fix, but they will appear in the CI when you will add a test.
90% of the job is done, and there's the annoying, yet important, finalization left :)

roll->RotateX(270);
roll->RotateZ(270);
renderer->GetActiveCamera()->SetPosition(cameraPosition);
renderer->GetActiveCamera()->SetModelTransformMatrix(roll->GetMatrix());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably to correct the actor orientation. Are MDL files +Z up by default? Then you just need to specify it in the config files (improvements of config file is missing by the way).


renderer->AddLight(frontLight);
renderer->AddLight(leftLight);
renderer->AddLight(backLight);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same question, I don't think it's needed.

}

//----------------------------------------------------------------------------
vtkSmartPointer<vtkTexture> CreateTexture(std::vector<unsigned char> buffer, int& offset,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid a copy

Suggested change
vtkSmartPointer<vtkTexture> CreateTexture(std::vector<unsigned char> buffer, int& offset,
vtkSmartPointer<vtkTexture> CreateTexture(const std::vector<unsigned char>& buffer, int& offset,

int group;
unsigned char* skin;
};
mixed_pointer_array* skins = new mixed_pointer_array[nbSkins];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not deleted. But let's use a std::vector instead.

return texture;
}

void CreateMesh(std::vector<unsigned char> buffer, int offset, mdl_header_t* header)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
void CreateMesh(std::vector<unsigned char> buffer, int offset, mdl_header_t* header)
void CreateMesh(const std::vector<unsigned char>& buffer, int offset, mdl_header_t* header)

Comment on lines +325 to +326
std::pair<int, float> pair = std::make_pair(frameIndex, 0.0);
GroupAndTimeVal.emplace_back(pair);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be simplified to

Suggested change
std::pair<int, float> pair = std::make_pair(frameIndex, 0.0);
GroupAndTimeVal.emplace_back(pair);
GroupAndTimeVal.emplace_back({ frameIndex, 0.0 });

{
for (int i = 0; i < header->numTriangles; i++)
{
vtkIdType* vertexNum = new vtkIdType[3];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

memory leak? Why not using that?

Suggested change
vtkIdType* vertexNum = new vtkIdType[3];
vtkIdType vertexNum[3];

{
double* v_0 = Mesh[i]->GetPoint(j);
double* v_1 = Mesh[i + 1]->GetPoint(j);
double* interp = new double[3];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leak again

Suggested change
double* interp = new double[3];
double interp[3];


void UpdateFrame(double timeValue)
{
// Hardcoded frames per second, 60FPS
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it always 60fps in the MDL specifications?

void ImportLights(vtkRenderer*) override;

// Header definition,
struct mdl_header_t
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be moved to the cpp file in the internals

@mwestphal
Copy link
Contributor

@Youva any news on this ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants