From dd415981c4b38a3bf82bb2a7e7b9ed41f96f8e4e Mon Sep 17 00:00:00 2001 From: Marc-Alexandre Espiaut <76531574+malespiaut@users.noreply.github.com> Date: Mon, 27 May 2024 11:02:29 +0200 Subject: [PATCH 01/60] Adding preliminary Quake1 MDL plugin. --- plugins/native/module/CMakeLists.txt | 1 + plugins/native/module/vtkQuakeMDLReader.cxx | 161 ++++++++++++++++++++ plugins/native/module/vtkQuakeMDLReader.h | 35 +++++ 3 files changed, 197 insertions(+) create mode 100644 plugins/native/module/vtkQuakeMDLReader.cxx create mode 100644 plugins/native/module/vtkQuakeMDLReader.h diff --git a/plugins/native/module/CMakeLists.txt b/plugins/native/module/CMakeLists.txt index 8b65c33501..2ffb871e60 100644 --- a/plugins/native/module/CMakeLists.txt +++ b/plugins/native/module/CMakeLists.txt @@ -1,5 +1,6 @@ set(classes vtkF3DSplatReader + vtkQuakeMDLReader ) set(_no_install "") diff --git a/plugins/native/module/vtkQuakeMDLReader.cxx b/plugins/native/module/vtkQuakeMDLReader.cxx new file mode 100644 index 0000000000..daa5d5e419 --- /dev/null +++ b/plugins/native/module/vtkQuakeMDLReader.cxx @@ -0,0 +1,161 @@ +#include "vtkQuakeMDLReader.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//---------------------------------------------------------------------------- +vtkStandardNewMacro(vtkQuakeMDLReader); + +//---------------------------------------------------------------------------- +vtkQuakeMDLReader::vtkQuakeMDLReader() +{ + this->SetNumberOfInputPorts(0); +} + +//---------------------------------------------------------------------------- +int vtkQuakeMDLReader::RequestData( + vtkInformation*, vtkInformationVector**, vtkInformationVector* outputVector) +{ + vtkPolyData* output = vtkPolyData::GetData(outputVector); + + std::ifstream inputStream(this->FileName, std::ios::binary); + + std::vector buffer(std::istreambuf_iterator(inputStream), {}); + + //??? What's a “splat”??? + constexpr size_t splatSize = 32; + + //??? What is nbSplats??? + size_t nbSplats = buffer.size() / splatSize; + + // identity ("IDPO"): 4 chars (4 bytes) + vtkNew IDPOArray; + IDPOArray->SetNumberOfComponents(4); + IDPOArray->SetNumberOfTuples(nbSplats); + IDPOArray->SetName("identity"); + + // version: 1 int (4 bytes) + vtkNew version; + version->SetNumberOfComponents(1); + version->SetNumberOfTuples(nbSplats); + version->SetName("version"); + + //==================================== + + // scaling factor: 3 floats (12 bytes) + vtkNew scalingFactor; + scalingFactor->SetNumberOfComponents(3); + scalingFactor->SetNumberOfTuples(nbSplats); + scalingFactor->SetName("scaling factor"); + + // translation vector: 3 floats (12 bytes) + vtkNew translationVector; + translationVector->SetNumberOfComponents(3); + translationVector->SetNumberOfTuples(nbSplats); + translationVector->SetName("translation vector"); + + // bounding radius: 1 float (4 bytes) + vtkNew boundingRadius; + boundingRadius->SetNumberOfComponents(1); + boundingRadius->SetNumberOfTuples(nbSplats); + boundingRadius->SetName("bounding radius"); + + // eye position: 3 floats (12 bytes) + vtkNew eyePosition; + eyePosition->SetNumberOfComponents(3); + eyePosition->SetNumberOfTuples(nbSplats); + eyePosition->SetName("eye position"); + + //==================================== + + // number of textures: 1 int (4 bytes) + vtkNew texturesNum; + texturesNum->SetNumberOfComponents(1); + texturesNum->SetNumberOfTuples(nbSplats); + texturesNum->SetName("number of textures"); + + // texture width: 1 int (4 bytes) + vtkNew textureWidth; + textureWidth->SetNumberOfComponents(1); + texturesWidth->SetNumberOfTuples(nbSplats); + textureWidth->SetName("texture width"); + + // texture height: 1 int (4 bytes) + vtkNew textureHeight; + textureHeight->SetNumberOfComponents(1); + textureHeight->SetNumberOfTuples(nbSplats); + textureHeight->SetName("texture height"); + + //==================================== + + // number of vertices: 1 int (4 bytes) + vtkNew verticesNum; + verticesNum->SetNumberOfComponents(1); + verticesNum->SetNumberOfTuples(nbSplats); + verticesNum->SetName("number of vertices"); + + // number of triangles: 1 int (4 bytes) + vtkNew trianglesNum; + trianglesNum->SetNumberOfComponents(1); + trianglesNum->SetNumberOfTuples(nbSplats); + trianglesNum->SetName("number of triangles"); + + // number of frames: 1 int (4 bytes) + vtkNew framesNum; + framesNum->SetNumberOfComponents(1); + framesNum->SetNumberOfTuples(nbSplats); + framesNum->SetName("number of frames"); + + //==================================== + + // sync type (0: synchron, 1: random): 1 int (4 bytes) + vtkNew syncType; + syncType->SetNumberOfComponents(1); + syncType->SetNumberOfTuples(nbSplats); + syncType->SetName("sync type"); + + // state flags: 1 int (4 bytes) + vtkNew stateFlags; + stateFlags->SetNumberOfComponents(1); + stateFlags->SetNumberOfTuples(nbSplats); + stateFlags->SetName("state flags"); + + //==================================== + + // position: 3 floats (12 bytes) + vtkNew position; + position->SetNumberOfComponents(3); + position->SetNumberOfTuples(nbSplats); + position->SetName("position"); + + // scale: 3 floats (12 bytes) + vtkNew scale; + scale->SetNumberOfComponents(3); + scale->SetNumberOfTuples(nbSplats); + scale->SetName("scale"); + + // rotation: 4 chars (4 bytes) + vtkNew rotation; + rotation->SetNumberOfComponents(4); + rotation->SetNumberOfTuples(nbSplats); + rotation->SetName("rotation"); + + // color+opacity: 4 chars (4 bytes) + vtkNew colorAndOpacity; + colorAndOpacity->SetNumberOfComponents(4); + colorAndOpacity->SetNumberOfTuples(nbSplats); + colorAndOpacity->SetName("color and opacity"); + + return 1; +} diff --git a/plugins/native/module/vtkQuakeMDLReader.h b/plugins/native/module/vtkQuakeMDLReader.h new file mode 100644 index 0000000000..cee1a4c596 --- /dev/null +++ b/plugins/native/module/vtkQuakeMDLReader.h @@ -0,0 +1,35 @@ +/** + * @class vtkQuakeMDLReader + * @brief VTK Reader for Quake 1 models in binary .mdl file format + */ + +#ifndef vtkQuakeMDLReader_h +#define vtkQuakeMDLReader_h + +#include + +class vtkQuakeMDLReader : public vtkPolyDataAlgorithm +{ +public: + static vtkQuakeMDLReader* New(); + vtkTypeMacro(vtkQuakeMDLReader, vtkPolyDataAlgorithm); + + /** + * Set the file name. + */ + vtkSetMacro(FileName, std::string); + +protected: + vtkQuakeMDLReader(); + ~vtkQuakeMDLReader() override = default; + + int RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) override; + +private: + vtkQuakeMDLReader(const vtkQuakeMDLReader&) = delete; + void operator=(const vtkQuakeMDLReader&) = delete; + + std::string FileName; +}; + +#endif From 22e89412178c5202ac9f803683b6805e76799d85 Mon Sep 17 00:00:00 2001 From: Marc-Alexandre Espiaut <76531574+malespiaut@users.noreply.github.com> Date: Mon, 27 May 2024 11:10:14 +0200 Subject: [PATCH 02/60] Fixing some vector types error in vtkQuakeMDLReader. --- plugins/native/module/vtkQuakeMDLReader.cxx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/native/module/vtkQuakeMDLReader.cxx b/plugins/native/module/vtkQuakeMDLReader.cxx index daa5d5e419..94a407ee74 100644 --- a/plugins/native/module/vtkQuakeMDLReader.cxx +++ b/plugins/native/module/vtkQuakeMDLReader.cxx @@ -40,7 +40,7 @@ int vtkQuakeMDLReader::RequestData( size_t nbSplats = buffer.size() / splatSize; // identity ("IDPO"): 4 chars (4 bytes) - vtkNew IDPOArray; + vtkNew IDPOArray; IDPOArray->SetNumberOfComponents(4); IDPOArray->SetNumberOfTuples(nbSplats); IDPOArray->SetName("identity"); @@ -112,7 +112,7 @@ int vtkQuakeMDLReader::RequestData( trianglesNum->SetName("number of triangles"); // number of frames: 1 int (4 bytes) - vtkNew framesNum; + vtkNew framesNum; framesNum->SetNumberOfComponents(1); framesNum->SetNumberOfTuples(nbSplats); framesNum->SetName("number of frames"); @@ -146,13 +146,13 @@ int vtkQuakeMDLReader::RequestData( scale->SetName("scale"); // rotation: 4 chars (4 bytes) - vtkNew rotation; + vtkNew rotation; rotation->SetNumberOfComponents(4); rotation->SetNumberOfTuples(nbSplats); rotation->SetName("rotation"); // color+opacity: 4 chars (4 bytes) - vtkNew colorAndOpacity; + vtkNew colorAndOpacity; colorAndOpacity->SetNumberOfComponents(4); colorAndOpacity->SetNumberOfTuples(nbSplats); colorAndOpacity->SetName("color and opacity"); From 55309ab6e0655d4ee4ee840296708651ab4ce2fa Mon Sep 17 00:00:00 2001 From: Marc-Alexandre Espiaut <76531574+malespiaut@users.noreply.github.com> Date: Mon, 27 May 2024 11:12:07 +0200 Subject: [PATCH 03/60] Fixing some formatting error (whitespaces) in vtkQuakeMDLReader. --- plugins/native/module/vtkQuakeMDLReader.cxx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/native/module/vtkQuakeMDLReader.cxx b/plugins/native/module/vtkQuakeMDLReader.cxx index 94a407ee74..03f2a1fc0b 100644 --- a/plugins/native/module/vtkQuakeMDLReader.cxx +++ b/plugins/native/module/vtkQuakeMDLReader.cxx @@ -78,19 +78,19 @@ int vtkQuakeMDLReader::RequestData( eyePosition->SetName("eye position"); //==================================== - + // number of textures: 1 int (4 bytes) vtkNew texturesNum; texturesNum->SetNumberOfComponents(1); texturesNum->SetNumberOfTuples(nbSplats); texturesNum->SetName("number of textures"); - + // texture width: 1 int (4 bytes) vtkNew textureWidth; textureWidth->SetNumberOfComponents(1); texturesWidth->SetNumberOfTuples(nbSplats); textureWidth->SetName("texture width"); - + // texture height: 1 int (4 bytes) vtkNew textureHeight; textureHeight->SetNumberOfComponents(1); From 34c719a5edfb2dd622c0d6c2ab8dfd4e6b1ac938 Mon Sep 17 00:00:00 2001 From: Marc-Alexandre Espiaut <76531574+malespiaut@users.noreply.github.com> Date: Mon, 27 May 2024 11:13:13 +0200 Subject: [PATCH 04/60] Fixing typo in vtkQuakeMDLReader. --- plugins/native/module/vtkQuakeMDLReader.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/native/module/vtkQuakeMDLReader.cxx b/plugins/native/module/vtkQuakeMDLReader.cxx index 03f2a1fc0b..aa36a061f7 100644 --- a/plugins/native/module/vtkQuakeMDLReader.cxx +++ b/plugins/native/module/vtkQuakeMDLReader.cxx @@ -88,7 +88,7 @@ int vtkQuakeMDLReader::RequestData( // texture width: 1 int (4 bytes) vtkNew textureWidth; textureWidth->SetNumberOfComponents(1); - texturesWidth->SetNumberOfTuples(nbSplats); + textureWidth->SetNumberOfTuples(nbSplats); textureWidth->SetName("texture width"); // texture height: 1 int (4 bytes) From b01355ed8f56a49d79047594d86da34acbca10bc Mon Sep 17 00:00:00 2001 From: Marc-Alexandre Espiaut <76531574+malespiaut@users.noreply.github.com> Date: Sun, 2 Jun 2024 12:43:26 +0200 Subject: [PATCH 05/60] Cleaning out unnecessary code. --- plugins/native/module/vtkQuakeMDLReader.cxx | 26 --------------------- 1 file changed, 26 deletions(-) diff --git a/plugins/native/module/vtkQuakeMDLReader.cxx b/plugins/native/module/vtkQuakeMDLReader.cxx index aa36a061f7..15ff7d4a70 100644 --- a/plugins/native/module/vtkQuakeMDLReader.cxx +++ b/plugins/native/module/vtkQuakeMDLReader.cxx @@ -31,24 +31,14 @@ int vtkQuakeMDLReader::RequestData( std::ifstream inputStream(this->FileName, std::ios::binary); - std::vector buffer(std::istreambuf_iterator(inputStream), {}); - - //??? What's a “splat”??? - constexpr size_t splatSize = 32; - - //??? What is nbSplats??? - size_t nbSplats = buffer.size() / splatSize; - // identity ("IDPO"): 4 chars (4 bytes) vtkNew IDPOArray; IDPOArray->SetNumberOfComponents(4); - IDPOArray->SetNumberOfTuples(nbSplats); IDPOArray->SetName("identity"); // version: 1 int (4 bytes) vtkNew version; version->SetNumberOfComponents(1); - version->SetNumberOfTuples(nbSplats); version->SetName("version"); //==================================== @@ -56,25 +46,21 @@ int vtkQuakeMDLReader::RequestData( // scaling factor: 3 floats (12 bytes) vtkNew scalingFactor; scalingFactor->SetNumberOfComponents(3); - scalingFactor->SetNumberOfTuples(nbSplats); scalingFactor->SetName("scaling factor"); // translation vector: 3 floats (12 bytes) vtkNew translationVector; translationVector->SetNumberOfComponents(3); - translationVector->SetNumberOfTuples(nbSplats); translationVector->SetName("translation vector"); // bounding radius: 1 float (4 bytes) vtkNew boundingRadius; boundingRadius->SetNumberOfComponents(1); - boundingRadius->SetNumberOfTuples(nbSplats); boundingRadius->SetName("bounding radius"); // eye position: 3 floats (12 bytes) vtkNew eyePosition; eyePosition->SetNumberOfComponents(3); - eyePosition->SetNumberOfTuples(nbSplats); eyePosition->SetName("eye position"); //==================================== @@ -82,19 +68,16 @@ int vtkQuakeMDLReader::RequestData( // number of textures: 1 int (4 bytes) vtkNew texturesNum; texturesNum->SetNumberOfComponents(1); - texturesNum->SetNumberOfTuples(nbSplats); texturesNum->SetName("number of textures"); // texture width: 1 int (4 bytes) vtkNew textureWidth; textureWidth->SetNumberOfComponents(1); - textureWidth->SetNumberOfTuples(nbSplats); textureWidth->SetName("texture width"); // texture height: 1 int (4 bytes) vtkNew textureHeight; textureHeight->SetNumberOfComponents(1); - textureHeight->SetNumberOfTuples(nbSplats); textureHeight->SetName("texture height"); //==================================== @@ -102,19 +85,16 @@ int vtkQuakeMDLReader::RequestData( // number of vertices: 1 int (4 bytes) vtkNew verticesNum; verticesNum->SetNumberOfComponents(1); - verticesNum->SetNumberOfTuples(nbSplats); verticesNum->SetName("number of vertices"); // number of triangles: 1 int (4 bytes) vtkNew trianglesNum; trianglesNum->SetNumberOfComponents(1); - trianglesNum->SetNumberOfTuples(nbSplats); trianglesNum->SetName("number of triangles"); // number of frames: 1 int (4 bytes) vtkNew framesNum; framesNum->SetNumberOfComponents(1); - framesNum->SetNumberOfTuples(nbSplats); framesNum->SetName("number of frames"); //==================================== @@ -122,13 +102,11 @@ int vtkQuakeMDLReader::RequestData( // sync type (0: synchron, 1: random): 1 int (4 bytes) vtkNew syncType; syncType->SetNumberOfComponents(1); - syncType->SetNumberOfTuples(nbSplats); syncType->SetName("sync type"); // state flags: 1 int (4 bytes) vtkNew stateFlags; stateFlags->SetNumberOfComponents(1); - stateFlags->SetNumberOfTuples(nbSplats); stateFlags->SetName("state flags"); //==================================== @@ -136,25 +114,21 @@ int vtkQuakeMDLReader::RequestData( // position: 3 floats (12 bytes) vtkNew position; position->SetNumberOfComponents(3); - position->SetNumberOfTuples(nbSplats); position->SetName("position"); // scale: 3 floats (12 bytes) vtkNew scale; scale->SetNumberOfComponents(3); - scale->SetNumberOfTuples(nbSplats); scale->SetName("scale"); // rotation: 4 chars (4 bytes) vtkNew rotation; rotation->SetNumberOfComponents(4); - rotation->SetNumberOfTuples(nbSplats); rotation->SetName("rotation"); // color+opacity: 4 chars (4 bytes) vtkNew colorAndOpacity; colorAndOpacity->SetNumberOfComponents(4); - colorAndOpacity->SetNumberOfTuples(nbSplats); colorAndOpacity->SetName("color and opacity"); return 1; From 3180bd6e4ba7c18e3272f838a592df370d6cb69c Mon Sep 17 00:00:00 2001 From: Youva Date: Sun, 25 Aug 2024 13:01:15 -0400 Subject: [PATCH 06/60] Add importer --- plugins/alembic/module/vtkF3DAlembicReader.h | 1 - plugins/native/CMakeLists.txt | 9 + plugins/native/module/CMakeLists.txt | 2 +- plugins/native/module/vtkQuakeMDLImporter.cxx | 750 ++++++++++++++++++ plugins/native/module/vtkQuakeMDLImporter.h | 135 ++++ plugins/native/module/vtkQuakeMDLReader.cxx | 135 ---- plugins/native/module/vtkQuakeMDLReader.h | 35 - 7 files changed, 895 insertions(+), 172 deletions(-) create mode 100644 plugins/native/module/vtkQuakeMDLImporter.cxx create mode 100644 plugins/native/module/vtkQuakeMDLImporter.h delete mode 100644 plugins/native/module/vtkQuakeMDLReader.cxx delete mode 100644 plugins/native/module/vtkQuakeMDLReader.h diff --git a/plugins/alembic/module/vtkF3DAlembicReader.h b/plugins/alembic/module/vtkF3DAlembicReader.h index 19940cbbee..cb09a53823 100644 --- a/plugins/alembic/module/vtkF3DAlembicReader.h +++ b/plugins/alembic/module/vtkF3DAlembicReader.h @@ -17,7 +17,6 @@ #include #include #include - #include class vtkF3DAlembicReader : public vtkPolyDataAlgorithm diff --git a/plugins/native/CMakeLists.txt b/plugins/native/CMakeLists.txt index d2e408acf1..49d64fc727 100644 --- a/plugins/native/CMakeLists.txt +++ b/plugins/native/CMakeLists.txt @@ -186,6 +186,15 @@ f3d_plugin_declare_reader( FORMAT_DESCRIPTION "3D Gaussian splats" ) +f3d_plugin_declare_reader( + NAME QuakeMDL + EXTENSIONS mdl + MIMETYPES application/vnd.mdl + VTK_IMPORTER vtkQuakeMDLImporter + FORMAT_DESCRIPTION "Quake 1 MDL model" +) + + f3d_plugin_build( NAME native VERSION 1.0 diff --git a/plugins/native/module/CMakeLists.txt b/plugins/native/module/CMakeLists.txt index 2ffb871e60..60a8ca02c0 100644 --- a/plugins/native/module/CMakeLists.txt +++ b/plugins/native/module/CMakeLists.txt @@ -1,6 +1,6 @@ set(classes vtkF3DSplatReader - vtkQuakeMDLReader + vtkQuakeMDLImporter ) set(_no_install "") diff --git a/plugins/native/module/vtkQuakeMDLImporter.cxx b/plugins/native/module/vtkQuakeMDLImporter.cxx new file mode 100644 index 0000000000..e714f95f4a --- /dev/null +++ b/plugins/native/module/vtkQuakeMDLImporter.cxx @@ -0,0 +1,750 @@ +#include "vtkQuakeMDLImporter.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//---------------------------------------------------------------------------- +vtkStandardNewMacro(vtkQuakeMDLImporter); + + +class vtkQuakeMDLImporter::vtkInternals +{ +public: + //---------------------------------------------------------------------------- + explicit vtkInternals(vtkQuakeMDLImporter* parent) + : Parent(parent) + { + } + + //---------------------------------------------------------------------------- + void ImportCameras(vtkRenderer* renderer) + { + + } + + //---------------------------------------------------------------------------- + void ImportLights(vtkRenderer* renderer) + { + } + + //---------------------------------------------------------------------------- + vtkSmartPointer CreateTexture(std::vector buffer, int& offset, int skinWidth, + int skinHeight, int nbSkins, int selectedSkinIndex) + { + vtkNew texture; + texture->SetWrap(3); + + struct mdl_skin_t + { + int group; /* 0 = single, 1 = group */ + unsigned char* data; /* texture data */ + }; + struct mdl_groupskin_t + { + int group; /* 1 = group */ + int nb; /* number of pics */ + float* time; /* time duration for each pic */ + unsigned char** data; /* texture data */ + }; + struct mixed_pointer_array + { + int group; + unsigned char* skin; + }; + mixed_pointer_array* skins = new mixed_pointer_array[nbSkins]; + unsigned char* skin = reinterpret_cast(buffer.data() + offset + 4); + for (int i = 0; i < nbSkins; i++) + { + int* group = reinterpret_cast(buffer.data() + offset); + if (*group == 0) + { + skins[i].group = 0; + skins[i].skin = reinterpret_cast(buffer.data() + 4 + offset); + offset += 4 + (skinWidth) * (skinHeight); + } + else + { + skins[i].group = 1; + int nb = *reinterpret_cast(buffer.data() + offset + 4); + skins[i].skin = reinterpret_cast(buffer.data() + 4 + nb * 4 + offset); + offset += 4 + nb * 4 + nb * (skinWidth) * (skinHeight); + } + } + vtkNew reader; + reader->SetFileName("C:\\\\Users\\Youva\\Downloads\\quake\\Untitled.png"); + reader->Update(); + + vtkNew writer; + writer->SetFileName("C:\\\\Users\\Youva\\Downloads\\skin2.png"); + vtkNew img; + img->SetDimensions(skinWidth, skinHeight, 1); + img->AllocateScalars(VTK_UNSIGNED_CHAR, 3); + unsigned char* selectedSkin = skins[selectedSkinIndex].skin; + for (int i = 0; i < skinHeight ; i++) + { + for (int j = 0; j < skinWidth; j++) + { + unsigned char index = *reinterpret_cast(selectedSkin + i * skinWidth + j); + unsigned char* ptr = reinterpret_cast(img->GetScalarPointer(j,i,0)); + ptr[0] = DefaultColorMap[index][0]; // R + ptr[1] = DefaultColorMap[index][1]; // G + ptr[2] = DefaultColorMap[index][2]; // B + } + } + + writer->SetInputData(img); + writer->Write(); + texture->SetInputData(img); + // texture->SetInputConnection(reader->GetOutputPort()); + + return texture; + } + + + void CreateMesh(std::vector buffer, int& offset, mdl_header_t* header, int selectedFrameIndex) + { + // Read texture coordinates + struct mdl_texcoord_t + { + int onseam; + int s; + int t; + }; + mdl_texcoord_t* texcoords = reinterpret_cast(buffer.data() + offset); + offset += 12 * header->numVertices; + // Read triangles + struct mdl_triangle_t + { + int facesfront; /* 0 = backface, 1 = frontface */ + int vertex[3]; /* vertex indices */ + }; + mdl_triangle_t* triangles = reinterpret_cast(buffer.data() + offset); + offset += 16 * header->numTriangles; + // Read frames + struct mdl_vertex_t // 4 bytes + { + unsigned char v[3]; + unsigned char normalIndex; + }; + struct mdl_simpleframe_t // 24 + nbVertices bytes + { + mdl_vertex_t bboxmin; + mdl_vertex_t bboxmax; + char name[16]; + mdl_vertex_t verts[1024]; // Maximum capacity is 1024 vertices + }; + struct mdl_frame_t + { + int type; + mdl_simpleframe_t frame; + }; + struct mdl_groupframe_t + { + int type; + int nb; + mdl_vertex_t min; + mdl_vertex_t max; + float* time; // Size is nbFrames ??? + mdl_simpleframe_t* frames; // Size is nbFrames ??? + }; + + struct plugin_frame_pointer + { + int* type; + int* nb; + float* time; + mdl_simpleframe_t* frames; + }; + plugin_frame_pointer* framePtr = new plugin_frame_pointer[header->numFrames]; + for (int i = 0; i < header->numFrames; i++) + { + int* type = reinterpret_cast(buffer.data() + offset); + if (*type == 0) + { + framePtr[i].type = type; + framePtr[i].nb = nullptr; + framePtr[i].time = nullptr; + framePtr[i].frames = reinterpret_cast(buffer.data() + 4 + offset); + offset += 4 + 24 + 4 * (header->numVertices); + } + else + { + framePtr[i].type = type; + framePtr[i].nb = reinterpret_cast(buffer.data() + 4 + offset); + mdl_vertex_t* min = reinterpret_cast(buffer.data() + 8 + offset); + mdl_vertex_t* max = reinterpret_cast(buffer.data() + 12 + offset); + float* time = + framePtr[i].time = reinterpret_cast(buffer.data() + 16 + offset); + framePtr[i].frames = + reinterpret_cast(buffer.data() + 16 + 4 * (*framePtr[i].nb) + offset); + offset += 16 + (*framePtr[i].nb) * 4; + for (int j = 0; j < *framePtr[i].nb; j++) + { + offset += 24 + 4 * header->numVertices; + } + } + } + // Draw cells + vtkNew cells; + cells->Allocate(header->numTriangles); + vtkNew textureCoordinates; + textureCoordinates->SetNumberOfComponents(2); + textureCoordinates->SetName("TextureCoordinates"); + textureCoordinates->Allocate(header->numVertices * 2); + struct plugin_texture_coords + { + float s; + float t; + int id; + }; + plugin_texture_coords* coords = new plugin_texture_coords[header->numVertices]; + for (int i = 0; i < header->numTriangles; i++) + { + vtkIdType* vertexNum = new vtkIdType[3]; + for (int j = 0; j < 3; j++) + { + vertexNum[j] = triangles[i].vertex[j]; + int onseam_correct = 1; + float s = texcoords[vertexNum[j]].s; + float t = texcoords[vertexNum[j]].t; + if ( !triangles[i].facesfront && texcoords[vertexNum[j]].onseam) + { + s = s + header->skinWidth * 0.5f; + } + s = (s + 0.5) / header->skinWidth; + t = (t + 0.5) / header->skinHeight; + coords[vertexNum[j]].s = s; + coords[vertexNum[j]].t = t; + coords[vertexNum[j]].id = vertexNum[j]; + } + cells->InsertNextCell(3, vertexNum); + } + // Add texture coords + for (int i = 0; i < header->numVertices; i++) + { + float* s_t = new float[2]; + s_t[0] = coords[i].s; + s_t[1] = coords[i].t; + textureCoordinates->InsertNextTuple(s_t); + } + + + // Draw vertices + std::string frameName = ""; + int frameIndex = 0; + for (int frameNum = 0; frameNum < header->numFrames; frameNum++) + { + vtkNew vertices; + vertices->Allocate(header->numVertices); + vtkNew normals; + normals->SetNumberOfComponents(3); + normals->Allocate(header->numVertices * 3); + plugin_frame_pointer selectedFrame = framePtr[frameNum]; + if (*selectedFrame.type == 0) + { + for (int i = 0; i < header->numTriangles; i++) + { + vtkIdType* vertexNum = new vtkIdType[3]; + for (int j = 0; j < 3; j++) + { + vertexNum[j] = triangles[i].vertex[j]; + double v[3] = { selectedFrame.frames->verts[vertexNum[j]].v[0], + selectedFrame.frames->verts[vertexNum[j]].v[1], + selectedFrame.frames->verts[vertexNum[j]].v[2] }; + for (int k = 0; k < 3; k++) + { + v[k] = v[k] * header->scale[k] + header->translation[k]; + } + vertices->InsertPoint(vertexNum[j], v); + int normalIndex = selectedFrame.frames->verts[vertexNum[j]].normalIndex; + normals->SetTuple3(vertexNum[j], NormalVectors[normalIndex][0] / 255.0, + NormalVectors[normalIndex][1] / 255.0, NormalVectors[normalIndex][2] / 255.0); + } + } + vtkNew mesh; + mesh->SetPoints(vertices); + mesh->SetPolys(cells); + mesh->GetPointData()->SetTCoords(textureCoordinates); + mesh->GetPointData()->SetNormals(normals); + Mesh.push_back(mesh); + std::string meshName = std::string(selectedFrame.frames->name); + for (int i = 0; i < meshName.size(); i++) + { + if (meshName[i] >= '0' && meshName[i] <= '9') + { + meshName = meshName.substr(0, i); + break; + } + } + if (frameNum == 0) + { + frameName = meshName; + } + else if (meshName != frameName) + { + frameIndex++; + frameName = meshName; + NumberOfAnimations++; + } + std::pair pair = std::make_pair(frameIndex, 0.0); + GroupAndTimeVal.push_back(pair); + } + else + { + for (int groupFrameNum = 0; groupFrameNum < *selectedFrame.nb; groupFrameNum++) + { + for (int i = 0; i < header->numTriangles; i++) + { + vtkIdType* vertexNum = new vtkIdType[3]; + for (int j = 0; j < 3; j++) + { + vertexNum[j] = triangles[i].vertex[j]; + double v[3] = { selectedFrame.frames[groupFrameNum].verts[vertexNum[j]].v[0], + selectedFrame.frames[groupFrameNum].verts[vertexNum[j]].v[1], + selectedFrame.frames[groupFrameNum].verts[vertexNum[j]].v[2] }; + for (int k = 0; k < 3; k++) + { + v[k] = v[k] * header->scale[k] + header->translation[k]; + } + vertices->InsertPoint(vertexNum[j], v); + int normalIndex = selectedFrame.frames[groupFrameNum].verts[vertexNum[j]].normalIndex; + normals->SetTuple3(vertexNum[j], NormalVectors[normalIndex][0] / 255.0, + NormalVectors[normalIndex][1] / 255.0, NormalVectors[normalIndex][2] / 255.0); + } + } + vtkNew mesh; + mesh->SetPoints(vertices); + mesh->SetPolys(cells); + mesh->GetPointData()->SetTCoords(textureCoordinates); + mesh->GetPointData()->SetNormals(normals); + Mesh.push_back(mesh); + std::string meshName = std::string(selectedFrame.frames[groupFrameNum].name); + for (int i = 0; i < meshName.size(); i++) + { + if (meshName[i] >= '0' && meshName[i] <= '9') + { + meshName = meshName.substr(0, i - 1); + break; + } + } + if (frameNum == 0) + { + frameName = meshName; + } + else if (meshName != frameName) + { + frameIndex++; + NumberOfAnimations++; + frameName = meshName; + } + std::pair pair = std::make_pair(frameIndex, selectedFrame.time[groupFrameNum]); + GroupAndTimeVal.push_back(pair); + } + } + } + + // Add interpolated frames + for (int i = 0; i < Mesh.size() - 1; i++) + { + if (GroupAndTimeVal[i + 1].first != GroupAndTimeVal[i].first) + { + continue; + } + else + { + vtkNew vertices; + vertices->Allocate(header->numVertices); + vtkNew normals; + normals->SetNumberOfComponents(3); + normals->Allocate(header->numVertices * 3); + for (int j = 0; j < header->numVertices; j++) + { + double* v_0 = Mesh[i]->GetPoint(j); + double* v_1 = Mesh[i+1]->GetPoint(j); + double* interp = new double[3]; + interp[0] = v_0[0] + 0.5 * (v_1[0] - v_0[0]); + interp[1] = v_0[1] + 0.5 * (v_1[1] - v_0[1]); + interp[2] = v_0[2] + 0.5 * (v_1[2] - v_0[2]); + vertices->InsertPoint(j, interp); + } + vtkNew mesh; + mesh->SetPoints(vertices); + mesh->SetPolys(cells); + mesh->GetPointData()->SetTCoords(textureCoordinates); + Mesh.insert(Mesh.begin() + i, mesh); + std::pair pair = std::make_pair(GroupAndTimeVal[i].first, + (GroupAndTimeVal[i].second + GroupAndTimeVal[i + 1].second) / 2); + GroupAndTimeVal.insert(GroupAndTimeVal.begin() + i, pair); + i++; + } + } + } + + //---------------------------------------------------------------------------- + bool ReadScene(const std::string& filePath) + { + std::ifstream inputStream(filePath, std::ios::binary); + + std::vector buffer(std::istreambuf_iterator(inputStream), {}); + + + // Read header + mdl_header_t* header = reinterpret_cast(buffer.data()); + int offset = 84; + + // Set textures + Texture= this->CreateTexture( + buffer, offset, header->skinWidth, header->skinHeight, header->numSkins, 0); + + + // Set polyData + this->CreateMesh(buffer, offset, header, 0); + + + + return 1; + } + + void UpdateFrame(double timeValue) + { + // Hardcoded frames per second + if (abs(timeValue - LastRenderTime) > 1.0 / 60) + { + Mapper->SetInputData( + Mesh[(CurrentFrameIndex++) % (LastFrameIndex - FirstFrameIndex) + FirstFrameIndex]); + LastRenderTime = timeValue; + } + } + + // Only one animation enabled at a time + void EnableAnimation(vtkIdType animationIndex) + { + int i = 0; + while (i < GroupAndTimeVal.size() && GroupAndTimeVal[++i].first < animationIndex) + { + } + FirstFrameIndex = animationIndex == 0 ? 0 : LastFrameIndex + 1; + while (i < GroupAndTimeVal.size() && GroupAndTimeVal[++i].first == animationIndex) + { + } + LastFrameIndex = i-1; + } + + void ImportActors(vtkRenderer* renderer) + { + vtkNew actor; + vtkNew mapper; + mapper->SetInputData(Mesh[0]); + //Mesh); + actor->SetMapper(mapper); + actor->SetTexture(Texture); + renderer->AddActor(actor); + renderer->SetBackground(0, 0, 0); + + Actor = actor; + Mapper = mapper; + } + + void UpdateNodeTransform() + { + } + + void UpdateCameras() + { + } + + void UpdateLights() + { + + } + + + vtkQuakeMDLImporter* Parent; + std::string Description; + vtkSmartPointer Actor; + vtkSmartPointer Mapper; + std::vector> Mesh; + std::vector > GroupAndTimeVal; + int ActiveAnimationId = 0; + int CurrentFrameIndex = 0; + int FirstFrameIndex = 0; + int LastFrameIndex = 10; + int NumberOfAnimations = 0; + double LastRenderTime = 0.0; + vtkSmartPointer Texture; + vtkSmartPointer TextureCoords; + unsigned char DefaultColorMap[256][3] = { { 0, 0, 0 }, { 15, 15, 15 }, { 31, 31, 31 }, + { 47, 47, 47 }, { 63, 63, 63 }, { 75, 75, 75 }, { 91, 91, 91 }, { 107, 107, 107 }, + { 123, 123, 123 }, { 139, 139, 139 }, { 155, 155, 155 }, { 171, 171, 171 }, { 187, 187, 187 }, + { 203, 203, 203 }, { 219, 219, 219 }, { 235, 235, 235 }, { 15, 11, 7 }, { 23, 15, 11 }, + { 31, 23, 11 }, { 39, 27, 15 }, { 47, 35, 19 }, { 55, 43, 23 }, { 63, 47, 23 }, { 75, 55, 27 }, + { 83, 59, 27 }, { 91, 67, 31 }, { 99, 75, 31 }, { 107, 83, 31 }, { 115, 87, 31 }, + { 123, 95, 35 }, { 131, 103, 35 }, { 143, 111, 35 }, { 11, 11, 15 }, { 19, 19, 27 }, + { 27, 27, 39 }, { 39, 39, 51 }, { 47, 47, 63 }, { 55, 55, 75 }, { 63, 63, 87 }, { 71, 71, 103 }, + { 79, 79, 115 }, { 91, 91, 127 }, { 99, 99, 139 }, { 107, 107, 151 }, { 115, 115, 163 }, + { 123, 123, 175 }, { 131, 131, 187 }, { 139, 139, 203 }, { 0, 0, 0 }, { 7, 7, 0 }, + { 11, 11, 0 }, { 19, 19, 0 }, { 27, 27, 0 }, { 35, 35, 0 }, { 43, 43, 7 }, { 47, 47, 7 }, + { 55, 55, 7 }, { 63, 63, 7 }, { 71, 71, 7 }, { 75, 75, 11 }, { 83, 83, 11 }, { 91, 91, 11 }, + { 99, 99, 11 }, { 107, 107, 15 }, { 7, 0, 0 }, { 15, 0, 0 }, { 23, 0, 0 }, { 31, 0, 0 }, + { 39, 0, 0 }, { 47, 0, 0 }, { 55, 0, 0 }, { 63, 0, 0 }, { 71, 0, 0 }, { 79, 0, 0 }, + { 87, 0, 0 }, { 95, 0, 0 }, { 103, 0, 0 }, { 111, 0, 0 }, { 119, 0, 0 }, { 127, 0, 0 }, + { 19, 19, 0 }, { 27, 27, 0 }, { 35, 35, 0 }, { 47, 43, 0 }, { 55, 47, 0 }, { 67, 55, 0 }, + { 75, 59, 7 }, { 87, 67, 7 }, { 95, 71, 7 }, { 107, 75, 11 }, { 119, 83, 15 }, { 131, 87, 19 }, + { 139, 91, 19 }, { 151, 95, 27 }, { 163, 99, 31 }, { 175, 103, 35 }, { 35, 19, 7 }, + { 47, 23, 11 }, { 59, 31, 15 }, { 75, 35, 19 }, { 87, 43, 23 }, { 99, 47, 31 }, { 115, 55, 35 }, + { 127, 59, 43 }, { 143, 67, 51 }, { 159, 79, 51 }, { 175, 99, 47 }, { 191, 119, 47 }, + { 207, 143, 43 }, { 223, 171, 39 }, { 239, 203, 31 }, { 255, 243, 27 }, { 11, 7, 0 }, + { 27, 19, 0 }, { 43, 35, 15 }, { 55, 43, 19 }, { 71, 51, 27 }, { 83, 55, 35 }, { 99, 63, 43 }, + { 111, 71, 51 }, { 127, 83, 63 }, { 139, 95, 71 }, { 155, 107, 83 }, { 167, 123, 95 }, + { 183, 135, 107 }, { 195, 147, 123 }, { 211, 163, 139 }, { 227, 179, 151 }, { 171, 139, 163 }, + { 159, 127, 151 }, { 147, 115, 135 }, { 139, 103, 123 }, { 127, 91, 111 }, { 119, 83, 99 }, + { 107, 75, 87 }, { 95, 63, 75 }, { 87, 55, 67 }, { 75, 47, 55 }, { 67, 39, 47 }, { 55, 31, 35 }, + { 43, 23, 27 }, { 35, 19, 19 }, { 23, 11, 11 }, { 15, 7, 7 }, { 187, 115, 159 }, + { 175, 107, 143 }, { 163, 95, 131 }, { 151, 87, 119 }, { 139, 79, 107 }, { 127, 75, 95 }, + { 115, 67, 83 }, { 107, 59, 75 }, { 95, 51, 63 }, { 83, 43, 55 }, { 71, 35, 43 }, + { 59, 31, 35 }, { 47, 23, 27 }, { 35, 19, 19 }, { 23, 11, 11 }, { 15, 7, 7 }, { 219, 195, 187 }, + { 203, 179, 167 }, { 191, 163, 155 }, { 175, 151, 139 }, { 163, 135, 123 }, { 151, 123, 111 }, + { 135, 111, 95 }, { 123, 99, 83 }, { 107, 87, 71 }, { 95, 75, 59 }, { 83, 63, 51 }, + { 67, 51, 39 }, { 55, 43, 31 }, { 39, 31, 23 }, { 27, 19, 15 }, { 15, 11, 7 }, + { 111, 131, 123 }, { 103, 123, 111 }, { 95, 115, 103 }, { 87, 107, 95 }, { 79, 99, 87 }, + { 71, 91, 79 }, { 63, 83, 71 }, { 55, 75, 63 }, { 47, 67, 55 }, { 43, 59, 47 }, { 35, 51, 39 }, + { 31, 43, 31 }, { 23, 35, 23 }, { 15, 27, 19 }, { 11, 19, 11 }, { 7, 11, 7 }, { 255, 243, 27 }, + { 239, 223, 23 }, { 219, 203, 19 }, { 203, 183, 15 }, { 187, 167, 15 }, { 171, 151, 11 }, + { 155, 131, 7 }, { 139, 115, 7 }, { 123, 99, 7 }, { 107, 83, 0 }, { 91, 71, 0 }, { 75, 55, 0 }, + { 59, 43, 0 }, { 43, 31, 0 }, { 27, 15, 0 }, { 11, 7, 0 }, { 0, 0, 255 }, { 11, 11, 239 }, + { 19, 19, 223 }, { 27, 27, 207 }, { 35, 35, 191 }, { 43, 43, 175 }, { 47, 47, 159 }, + { 47, 47, 143 }, { 47, 47, 127 }, { 47, 47, 111 }, { 47, 47, 95 }, { 43, 43, 79 }, + { 35, 35, 63 }, { 27, 27, 47 }, { 19, 19, 31 }, { 11, 11, 15 }, { 43, 0, 0 }, { 59, 0, 0 }, + { 75, 7, 0 }, { 95, 7, 0 }, { 111, 15, 0 }, { 127, 23, 7 }, { 147, 31, 7 }, { 163, 39, 11 }, + { 183, 51, 15 }, { 195, 75, 27 }, { 207, 99, 43 }, { 219, 127, 59 }, { 227, 151, 79 }, + { 231, 171, 95 }, { 239, 191, 119 }, { 247, 211, 139 }, { 167, 123, 59 }, { 183, 155, 55 }, + { 199, 195, 55 }, { 231, 227, 87 }, { 127, 191, 255 }, { 171, 231, 255 }, { 215, 255, 255 }, + { 103, 0, 0 }, { 139, 0, 0 }, { 179, 0, 0 }, { 215, 0, 0 }, { 255, 0, 0 }, { 255, 243, 147 }, + { 255, 247, 199 }, { 255, 255, 255 }, { 159, 91, 83 } }; + float NormalVectors[162][3] = { { -0.525731f, 0.000000f, 0.850651f }, + { -0.442863f, 0.238856f, 0.864188f }, { -0.295242f, 0.000000f, 0.955423f }, + { -0.309017f, 0.500000f, 0.809017f }, { -0.162460f, 0.262866f, 0.951056f }, + { 0.000000f, 0.000000f, 1.000000f }, { 0.000000f, 0.850651f, 0.525731f }, + { -0.147621f, 0.716567f, 0.681718f }, { 0.147621f, 0.716567f, 0.681718f }, + { 0.000000f, 0.525731f, 0.850651f }, { 0.309017f, 0.500000f, 0.809017f }, + { 0.525731f, 0.000000f, 0.850651f }, { 0.295242f, 0.000000f, 0.955423f }, + { 0.442863f, 0.238856f, 0.864188f }, { 0.162460f, 0.262866f, 0.951056f }, + { -0.681718f, 0.147621f, 0.716567f }, { -0.809017f, 0.309017f, 0.500000f }, + { -0.587785f, 0.425325f, 0.688191f }, { -0.850651f, 0.525731f, 0.000000f }, + { -0.864188f, 0.442863f, 0.238856f }, { -0.716567f, 0.681718f, 0.147621f }, + { -0.688191f, 0.587785f, 0.425325f }, { -0.500000f, 0.809017f, 0.309017f }, + { -0.238856f, 0.864188f, 0.442863f }, { -0.425325f, 0.688191f, 0.587785f }, + { -0.716567f, 0.681718f, -0.147621f }, { -0.500000f, 0.809017f, -0.309017f }, + { -0.525731f, 0.850651f, 0.000000f }, { 0.000000f, 0.850651f, -0.525731f }, + { -0.238856f, 0.864188f, -0.442863f }, { 0.000000f, 0.955423f, -0.295242f }, + { -0.262866f, 0.951056f, -0.162460f }, { 0.000000f, 1.000000f, 0.000000f }, + { 0.000000f, 0.955423f, 0.295242f }, { -0.262866f, 0.951056f, 0.162460f }, + { 0.238856f, 0.864188f, 0.442863f }, { 0.262866f, 0.951056f, 0.162460f }, + { 0.500000f, 0.809017f, 0.309017f }, { 0.238856f, 0.864188f, -0.442863f }, + { 0.262866f, 0.951056f, -0.162460f }, { 0.500000f, 0.809017f, -0.309017f }, + { 0.850651f, 0.525731f, 0.000000f }, { 0.716567f, 0.681718f, 0.147621f }, + { 0.716567f, 0.681718f, -0.147621f }, { 0.525731f, 0.850651f, 0.000000f }, + { 0.425325f, 0.688191f, 0.587785f }, { 0.864188f, 0.442863f, 0.238856f }, + { 0.688191f, 0.587785f, 0.425325f }, { 0.809017f, 0.309017f, 0.500000f }, + { 0.681718f, 0.147621f, 0.716567f }, { 0.587785f, 0.425325f, 0.688191f }, + { 0.955423f, 0.295242f, 0.000000f }, { 1.000000f, 0.000000f, 0.000000f }, + { 0.951056f, 0.162460f, 0.262866f }, { 0.850651f, -0.525731f, 0.000000f }, + { 0.955423f, -0.295242f, 0.000000f }, { 0.864188f, -0.442863f, 0.238856f }, + { 0.951056f, -0.162460f, 0.262866f }, { 0.809017f, -0.309017f, 0.500000f }, + { 0.681718f, -0.147621f, 0.716567f }, { 0.850651f, 0.000000f, 0.525731f }, + { 0.864188f, 0.442863f, -0.238856f }, { 0.809017f, 0.309017f, -0.500000f }, + { 0.951056f, 0.162460f, -0.262866f }, { 0.525731f, 0.000000f, -0.850651f }, + { 0.681718f, 0.147621f, -0.716567f }, { 0.681718f, -0.147621f, -0.716567f }, + { 0.850651f, 0.000000f, -0.525731f }, { 0.809017f, -0.309017f, -0.500000f }, + { 0.864188f, -0.442863f, -0.238856f }, { 0.951056f, -0.162460f, -0.262866f }, + { 0.147621f, 0.716567f, -0.681718f }, { 0.309017f, 0.500000f, -0.809017f }, + { 0.425325f, 0.688191f, -0.587785f }, { 0.442863f, 0.238856f, -0.864188f }, + { 0.587785f, 0.425325f, -0.688191f }, { 0.688191f, 0.587785f, -0.425325f }, + { -0.147621f, 0.716567f, -0.681718f }, { -0.309017f, 0.500000f, -0.809017f }, + { 0.000000f, 0.525731f, -0.850651f }, { -0.525731f, 0.000000f, -0.850651f }, + { -0.442863f, 0.238856f, -0.864188f }, { -0.295242f, 0.000000f, -0.955423f }, + { -0.162460f, 0.262866f, -0.951056f }, { 0.000000f, 0.000000f, -1.000000f }, + { 0.295242f, 0.000000f, -0.955423f }, { 0.162460f, 0.262866f, -0.951056f }, + { -0.442863f, -0.238856f, -0.864188f }, { -0.309017f, -0.500000f, -0.809017f }, + { -0.162460f, -0.262866f, -0.951056f }, { 0.000000f, -0.850651f, -0.525731f }, + { -0.147621f, -0.716567f, -0.681718f }, { 0.147621f, -0.716567f, -0.681718f }, + { 0.000000f, -0.525731f, -0.850651f }, { 0.309017f, -0.500000f, -0.809017f }, + { 0.442863f, -0.238856f, -0.864188f }, { 0.162460f, -0.262866f, -0.951056f }, + { 0.238856f, -0.864188f, -0.442863f }, { 0.500000f, -0.809017f, -0.309017f }, + { 0.425325f, -0.688191f, -0.587785f }, { 0.716567f, -0.681718f, -0.147621f }, + { 0.688191f, -0.587785f, -0.425325f }, { 0.587785f, -0.425325f, -0.688191f }, + { 0.000000f, -0.955423f, -0.295242f }, { 0.000000f, -1.000000f, 0.000000f }, + { 0.262866f, -0.951056f, -0.162460f }, { 0.000000f, -0.850651f, 0.525731f }, + { 0.000000f, -0.955423f, 0.295242f }, { 0.238856f, -0.864188f, 0.442863f }, + { 0.262866f, -0.951056f, 0.162460f }, { 0.500000f, -0.809017f, 0.309017f }, + { 0.716567f, -0.681718f, 0.147621f }, { 0.525731f, -0.850651f, 0.000000f }, + { -0.238856f, -0.864188f, -0.442863f }, { -0.500000f, -0.809017f, -0.309017f }, + { -0.262866f, -0.951056f, -0.162460f }, { -0.850651f, -0.525731f, 0.000000f }, + { -0.716567f, -0.681718f, -0.147621f }, { -0.716567f, -0.681718f, 0.147621f }, + { -0.525731f, -0.850651f, 0.000000f }, { -0.500000f, -0.809017f, 0.309017f }, + { -0.238856f, -0.864188f, 0.442863f }, { -0.262866f, -0.951056f, 0.162460f }, + { -0.864188f, -0.442863f, 0.238856f }, { -0.809017f, -0.309017f, 0.500000f }, + { -0.688191f, -0.587785f, 0.425325f }, { -0.681718f, -0.147621f, 0.716567f }, + { -0.442863f, -0.238856f, 0.864188f }, { -0.587785f, -0.425325f, 0.688191f }, + { -0.309017f, -0.500000f, 0.809017f }, { -0.147621f, -0.716567f, 0.681718f }, + { -0.425325f, -0.688191f, 0.587785f }, { -0.162460f, -0.262866f, 0.951056f }, + { 0.442863f, -0.238856f, 0.864188f }, { 0.162460f, -0.262866f, 0.951056f }, + { 0.309017f, -0.500000f, 0.809017f }, { 0.147621f, -0.716567f, 0.681718f }, + { 0.000000f, -0.525731f, 0.850651f }, { 0.425325f, -0.688191f, 0.587785f }, + { 0.587785f, -0.425325f, 0.688191f }, { 0.688191f, -0.587785f, 0.425325f }, + { -0.955423f, 0.295242f, 0.000000f }, { -0.951056f, 0.162460f, 0.262866f }, + { -1.000000f, 0.000000f, 0.000000f }, { -0.850651f, 0.000000f, 0.525731f }, + { -0.955423f, -0.295242f, 0.000000f }, { -0.951056f, -0.162460f, 0.262866f }, + { -0.864188f, 0.442863f, -0.238856f }, { -0.951056f, 0.162460f, -0.262866f }, + { -0.809017f, 0.309017f, -0.500000f }, { -0.864188f, -0.442863f, -0.238856f }, + { -0.951056f, -0.162460f, -0.262866f }, { -0.809017f, -0.309017f, -0.500000f }, + { -0.681718f, 0.147621f, -0.716567f }, { -0.681718f, -0.147621f, -0.716567f }, + { -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 } }; +}; + +vtkQuakeMDLImporter::vtkQuakeMDLImporter() + : Internals(new vtkQuakeMDLImporter::vtkInternals(this)){ + + }; + +//---------------------------------------------------------------------------- + + + + +//---------------------------------------------------------------------------- +int vtkQuakeMDLImporter::ImportBegin() +{ + return this->Internals->ReadScene(this->FileName); +} + +//---------------------------------------------------------------------------- +void vtkQuakeMDLImporter::ImportActors(vtkRenderer* renderer) +{ + this->Internals->ImportActors(renderer); +} + +//---------------------------------------------------------------------------- +std::string vtkQuakeMDLImporter::GetOutputsDescription() +{ + return this->Internals->Description; +} + +//---------------------------------------------------------------------------- +void vtkQuakeMDLImporter::UpdateTimeStep(double timeValue) +{ + this->Internals->UpdateFrame(timeValue); + return; +} + +//---------------------------------------------------------------------------- +vtkIdType vtkQuakeMDLImporter::GetNumberOfAnimations() +{ + return this->Internals->NumberOfAnimations; +} + +//---------------------------------------------------------------------------- +std::string vtkQuakeMDLImporter::GetAnimationName(vtkIdType animationIndex) +{ + return ""; +} + +//---------------------------------------------------------------------------- +void vtkQuakeMDLImporter::EnableAnimation(vtkIdType animationIndex) +{ + this->Internals->EnableAnimation(animationIndex); + return; +} + +//---------------------------------------------------------------------------- +void vtkQuakeMDLImporter::DisableAnimation(vtkIdType vtkNotUsed(animationIndex)) +{ + return; +} + +//---------------------------------------------------------------------------- +bool vtkQuakeMDLImporter::IsAnimationEnabled(vtkIdType animationIndex) +{ + return true; +} + + +//---------------------------------------------------------------------------- +bool vtkQuakeMDLImporter::GetTemporalInformation(vtkIdType animationIndex, + double vtkNotUsed(frameRate), int& vtkNotUsed(nbTimeSteps), double timeRange[2], + vtkDoubleArray* vtkNotUsed(timeSteps)) +{ + timeRange[0] = 0.0; + timeRange[1] = 10.0; + return true; +} + +//---------------------------------------------------------------------------- +vtkIdType vtkQuakeMDLImporter::GetNumberOfCameras() +{ + return 1; +} + +//---------------------------------------------------------------------------- +std::string vtkQuakeMDLImporter::GetCameraName(vtkIdType camIndex) +{ + return "Camera"; +} + +//---------------------------------------------------------------------------- +void vtkQuakeMDLImporter::SetCamera(vtkIdType camIndex) +{ + +} + +//---------------------------------------------------------------------------- +void vtkQuakeMDLImporter::ImportCameras(vtkRenderer* renderer) +{ + this->Internals->ImportCameras(renderer); +} + +//---------------------------------------------------------------------------- +void vtkQuakeMDLImporter::ImportLights(vtkRenderer* renderer) +{ + this->Internals->ImportLights(renderer); +} + +//---------------------------------------------------------------------------- +void vtkQuakeMDLImporter::PrintSelf(ostream& os, vtkIndent indent) +{ + this->Superclass::PrintSelf(os, indent); + os << indent << "FileName: " << this->FileName << "\n"; +} diff --git a/plugins/native/module/vtkQuakeMDLImporter.h b/plugins/native/module/vtkQuakeMDLImporter.h new file mode 100644 index 0000000000..5b2e9f43b2 --- /dev/null +++ b/plugins/native/module/vtkQuakeMDLImporter.h @@ -0,0 +1,135 @@ +/** + * @class vtkQuakeMDLImporter + * @brief VTK Importer for Quake 1 models in binary .mdl file format + */ + +#ifndef vtkQuakeMDLImporter_h +#define vtkQuakeMDLImporter_h +#include + +class vtkQuakeMDLImporter : public vtkImporter +{ +public: + static vtkQuakeMDLImporter* New(); + vtkTypeMacro(vtkQuakeMDLImporter, vtkImporter); + + + void PrintSelf(ostream& os, vtkIndent indent) override; + + ///@{ + /** + * Set/Get the file name. + */ + vtkSetMacro(FileName, std::string); + vtkGetMacro(FileName, std::string); + ///@} + + /** + * Update actors at the given time value. + */ + + void UpdateTimeStep(double timeValue); + + /** + * Get the number of available animations. + */ + vtkIdType GetNumberOfAnimations() override; + + /** + * Return the name of the animation. + */ + std::string GetAnimationName(vtkIdType animationIndex) override; + + ///@{ + /** + * Enable/Disable/Get the status of specific animations + * Only one single animation can be enabled + */ + void EnableAnimation(vtkIdType animationIndex) override; + void DisableAnimation(vtkIdType animationIndex) override; + bool IsAnimationEnabled(vtkIdType animationIndex) override; + ///@} + + /** + * Return importer description. + */ + std::string GetOutputsDescription() override; + + ///@{ + /** + * Set/Get collada fixup flag. + */ + vtkSetMacro(ColladaFixup, bool); + vtkGetMacro(ColladaFixup, bool); + ///@} + + /** + * Get temporal information for the currently enabled animation. + * Only defines timerange and ignore provided frameRate. + */ + bool GetTemporalInformation(vtkIdType animationIndex, double frameRate, int& nbTimeSteps, + double timeRange[2], vtkDoubleArray* timeSteps) override; + + /** + * Get the number of available cameras. + */ + vtkIdType GetNumberOfCameras() override; + + /** + * Get the name of a camera. + */ + std::string GetCameraName(vtkIdType camIndex) override; + + /** + * Enable a specific camera. + * If a negative index is provided, no camera from the importer is used. + */ + void SetCamera(vtkIdType camIndex) override; + + +protected: + vtkQuakeMDLImporter(); + ~vtkQuakeMDLImporter() override = default; + + int ImportBegin() override; + void ImportActors(vtkRenderer*) override; + void ImportCameras(vtkRenderer*) override; + void ImportLights(vtkRenderer*) override; + + // Header definition, + struct mdl_header_t + { + int IDPO; + int version; + float scale[3]; + float translation[3]; + float boundingRadius; + float eyePosition[3]; + int numSkins; + int skinWidth; + int skinHeight; + int numVertices; + int numTriangles; + int numFrames; + int syncType; + int stateFlags; + float size; + }; + + ///@{ + /** + * Set/Get the file name. + */ + ///@} + std::string FileName; + bool ColladaFixup = false; + +private: + vtkQuakeMDLImporter(const vtkQuakeMDLImporter&) = delete; + void operator=(const vtkQuakeMDLImporter&) = delete; + + class vtkInternals; + std::unique_ptr Internals; +}; + +#endif diff --git a/plugins/native/module/vtkQuakeMDLReader.cxx b/plugins/native/module/vtkQuakeMDLReader.cxx deleted file mode 100644 index 15ff7d4a70..0000000000 --- a/plugins/native/module/vtkQuakeMDLReader.cxx +++ /dev/null @@ -1,135 +0,0 @@ -#include "vtkQuakeMDLReader.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -//---------------------------------------------------------------------------- -vtkStandardNewMacro(vtkQuakeMDLReader); - -//---------------------------------------------------------------------------- -vtkQuakeMDLReader::vtkQuakeMDLReader() -{ - this->SetNumberOfInputPorts(0); -} - -//---------------------------------------------------------------------------- -int vtkQuakeMDLReader::RequestData( - vtkInformation*, vtkInformationVector**, vtkInformationVector* outputVector) -{ - vtkPolyData* output = vtkPolyData::GetData(outputVector); - - std::ifstream inputStream(this->FileName, std::ios::binary); - - // identity ("IDPO"): 4 chars (4 bytes) - vtkNew IDPOArray; - IDPOArray->SetNumberOfComponents(4); - IDPOArray->SetName("identity"); - - // version: 1 int (4 bytes) - vtkNew version; - version->SetNumberOfComponents(1); - version->SetName("version"); - - //==================================== - - // scaling factor: 3 floats (12 bytes) - vtkNew scalingFactor; - scalingFactor->SetNumberOfComponents(3); - scalingFactor->SetName("scaling factor"); - - // translation vector: 3 floats (12 bytes) - vtkNew translationVector; - translationVector->SetNumberOfComponents(3); - translationVector->SetName("translation vector"); - - // bounding radius: 1 float (4 bytes) - vtkNew boundingRadius; - boundingRadius->SetNumberOfComponents(1); - boundingRadius->SetName("bounding radius"); - - // eye position: 3 floats (12 bytes) - vtkNew eyePosition; - eyePosition->SetNumberOfComponents(3); - eyePosition->SetName("eye position"); - - //==================================== - - // number of textures: 1 int (4 bytes) - vtkNew texturesNum; - texturesNum->SetNumberOfComponents(1); - texturesNum->SetName("number of textures"); - - // texture width: 1 int (4 bytes) - vtkNew textureWidth; - textureWidth->SetNumberOfComponents(1); - textureWidth->SetName("texture width"); - - // texture height: 1 int (4 bytes) - vtkNew textureHeight; - textureHeight->SetNumberOfComponents(1); - textureHeight->SetName("texture height"); - - //==================================== - - // number of vertices: 1 int (4 bytes) - vtkNew verticesNum; - verticesNum->SetNumberOfComponents(1); - verticesNum->SetName("number of vertices"); - - // number of triangles: 1 int (4 bytes) - vtkNew trianglesNum; - trianglesNum->SetNumberOfComponents(1); - trianglesNum->SetName("number of triangles"); - - // number of frames: 1 int (4 bytes) - vtkNew framesNum; - framesNum->SetNumberOfComponents(1); - framesNum->SetName("number of frames"); - - //==================================== - - // sync type (0: synchron, 1: random): 1 int (4 bytes) - vtkNew syncType; - syncType->SetNumberOfComponents(1); - syncType->SetName("sync type"); - - // state flags: 1 int (4 bytes) - vtkNew stateFlags; - stateFlags->SetNumberOfComponents(1); - stateFlags->SetName("state flags"); - - //==================================== - - // position: 3 floats (12 bytes) - vtkNew position; - position->SetNumberOfComponents(3); - position->SetName("position"); - - // scale: 3 floats (12 bytes) - vtkNew scale; - scale->SetNumberOfComponents(3); - scale->SetName("scale"); - - // rotation: 4 chars (4 bytes) - vtkNew rotation; - rotation->SetNumberOfComponents(4); - rotation->SetName("rotation"); - - // color+opacity: 4 chars (4 bytes) - vtkNew colorAndOpacity; - colorAndOpacity->SetNumberOfComponents(4); - colorAndOpacity->SetName("color and opacity"); - - return 1; -} diff --git a/plugins/native/module/vtkQuakeMDLReader.h b/plugins/native/module/vtkQuakeMDLReader.h deleted file mode 100644 index cee1a4c596..0000000000 --- a/plugins/native/module/vtkQuakeMDLReader.h +++ /dev/null @@ -1,35 +0,0 @@ -/** - * @class vtkQuakeMDLReader - * @brief VTK Reader for Quake 1 models in binary .mdl file format - */ - -#ifndef vtkQuakeMDLReader_h -#define vtkQuakeMDLReader_h - -#include - -class vtkQuakeMDLReader : public vtkPolyDataAlgorithm -{ -public: - static vtkQuakeMDLReader* New(); - vtkTypeMacro(vtkQuakeMDLReader, vtkPolyDataAlgorithm); - - /** - * Set the file name. - */ - vtkSetMacro(FileName, std::string); - -protected: - vtkQuakeMDLReader(); - ~vtkQuakeMDLReader() override = default; - - int RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) override; - -private: - vtkQuakeMDLReader(const vtkQuakeMDLReader&) = delete; - void operator=(const vtkQuakeMDLReader&) = delete; - - std::string FileName; -}; - -#endif From ec7995ac64dc5c8f3913e433687a3eadfa2114ff Mon Sep 17 00:00:00 2001 From: Youva Date: Sun, 25 Aug 2024 13:51:00 -0400 Subject: [PATCH 07/60] Removed hardcoded path --- plugins/native/module/vtkQuakeMDLImporter.cxx | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/plugins/native/module/vtkQuakeMDLImporter.cxx b/plugins/native/module/vtkQuakeMDLImporter.cxx index e714f95f4a..ae02791cf1 100644 --- a/plugins/native/module/vtkQuakeMDLImporter.cxx +++ b/plugins/native/module/vtkQuakeMDLImporter.cxx @@ -100,12 +100,14 @@ class vtkQuakeMDLImporter::vtkInternals offset += 4 + nb * 4 + nb * (skinWidth) * (skinHeight); } } - vtkNew reader; - reader->SetFileName("C:\\\\Users\\Youva\\Downloads\\quake\\Untitled.png"); - reader->Update(); - vtkNew writer; - writer->SetFileName("C:\\\\Users\\Youva\\Downloads\\skin2.png"); + // Used while testing to load texture from a PNG file + // vtkNew reader; + // reader->SetFileName("C:\\\\Users\\Youva\\Downloads\\quake\\Untitled.png"); + // reader->Update(); + // Used while testing to check the texture is written correctly + // vtkNew writer; + // writer->SetFileName("C:\\\\Users\\Youva\\Downloads\\skin2.png"); vtkNew img; img->SetDimensions(skinWidth, skinHeight, 1); img->AllocateScalars(VTK_UNSIGNED_CHAR, 3); @@ -121,10 +123,11 @@ class vtkQuakeMDLImporter::vtkInternals ptr[2] = DefaultColorMap[index][2]; // B } } - - writer->SetInputData(img); - writer->Write(); + // Used to write to file + // writer->SetInputData(img); + // writer->Write(); texture->SetInputData(img); + // Used to set texture from image file // texture->SetInputConnection(reader->GetOutputPort()); return texture; @@ -463,7 +466,7 @@ class vtkQuakeMDLImporter::vtkInternals void ImportActors(vtkRenderer* renderer) { vtkNew actor; - vtkNew mapper; + vtkNew mapper; mapper->SetInputData(Mesh[0]); //Mesh); actor->SetMapper(mapper); From 32ae40bc5834e252d648c27636392a58c0a33c22 Mon Sep 17 00:00:00 2001 From: Youva Date: Mon, 2 Sep 2024 14:32:29 -0400 Subject: [PATCH 08/60] Fixed crash due to memory allocation on normals and interpolated frames. Fixed texture coordinates not rendering correctly by adding more vertices. Fixed camera position and lighting, animations display properly but could still be improved. --- plugins/native/module/vtkQuakeMDLImporter.cxx | 126 ++++++++---------- 1 file changed, 59 insertions(+), 67 deletions(-) diff --git a/plugins/native/module/vtkQuakeMDLImporter.cxx b/plugins/native/module/vtkQuakeMDLImporter.cxx index ae02791cf1..cce93d9bd6 100644 --- a/plugins/native/module/vtkQuakeMDLImporter.cxx +++ b/plugins/native/module/vtkQuakeMDLImporter.cxx @@ -1,5 +1,6 @@ #include "vtkQuakeMDLImporter.h" +#include #include #include #include @@ -49,12 +50,32 @@ class vtkQuakeMDLImporter::vtkInternals //---------------------------------------------------------------------------- void ImportCameras(vtkRenderer* renderer) { - + double cameraPosition[3] = { 50.0, 15.0, 0.0 }; + vtkNew roll; + roll->RotateX(270); + roll->RotateZ(270); + renderer->GetActiveCamera()->SetPosition(cameraPosition); + renderer->GetActiveCamera()->SetModelTransformMatrix(roll->GetMatrix()); } //---------------------------------------------------------------------------- void ImportLights(vtkRenderer* renderer) { + // Adds 3 lights, there's already one on the right side. + + vtkNew frontLight; + double frontLightPosition[3] = { 50.0, 50.0, 0.0 }; + frontLight->SetPosition(frontLightPosition); + vtkNew leftLight; + double leftLightPosition[3] = { 50.0, -50.0, 0.0 }; + leftLight->SetPosition(leftLightPosition); + vtkNew backLight; + double backLightPosition[3] = { -50.0, 0.0, 0.0 }; + backLight->SetPosition(backLightPosition); + + renderer->AddLight(frontLight); + renderer->AddLight(leftLight); + renderer->AddLight(backLight); } //---------------------------------------------------------------------------- @@ -62,8 +83,10 @@ class vtkQuakeMDLImporter::vtkInternals int skinHeight, int nbSkins, int selectedSkinIndex) { vtkNew texture; - texture->SetWrap(3); + texture->InterpolateOn(); + + // Read textures. struct mdl_skin_t { int group; /* 0 = single, 1 = group */ @@ -101,13 +124,7 @@ class vtkQuakeMDLImporter::vtkInternals } } - // Used while testing to load texture from a PNG file - // vtkNew reader; - // reader->SetFileName("C:\\\\Users\\Youva\\Downloads\\quake\\Untitled.png"); - // reader->Update(); - // Used while testing to check the texture is written correctly - // vtkNew writer; - // writer->SetFileName("C:\\\\Users\\Youva\\Downloads\\skin2.png"); + // Copy to imageData vtkNew img; img->SetDimensions(skinWidth, skinHeight, 1); img->AllocateScalars(VTK_UNSIGNED_CHAR, 3); @@ -123,13 +140,8 @@ class vtkQuakeMDLImporter::vtkInternals ptr[2] = DefaultColorMap[index][2]; // B } } - // Used to write to file - // writer->SetInputData(img); - // writer->Write(); - texture->SetInputData(img); - // Used to set texture from image file - // texture->SetInputConnection(reader->GetOutputPort()); + texture->SetInputData(img); return texture; } @@ -180,7 +192,6 @@ class vtkQuakeMDLImporter::vtkInternals float* time; // Size is nbFrames ??? mdl_simpleframe_t* frames; // Size is nbFrames ??? }; - struct plugin_frame_pointer { int* type; @@ -223,14 +234,14 @@ class vtkQuakeMDLImporter::vtkInternals vtkNew textureCoordinates; textureCoordinates->SetNumberOfComponents(2); textureCoordinates->SetName("TextureCoordinates"); - textureCoordinates->Allocate(header->numVertices * 2); + textureCoordinates->Allocate(header->numTriangles * 3); struct plugin_texture_coords { float s; float t; int id; }; - plugin_texture_coords* coords = new plugin_texture_coords[header->numVertices]; + plugin_texture_coords* coords = new plugin_texture_coords[header->numTriangles * 3]; for (int i = 0; i < header->numTriangles; i++) { vtkIdType* vertexNum = new vtkIdType[3]; @@ -238,28 +249,24 @@ class vtkQuakeMDLImporter::vtkInternals { vertexNum[j] = triangles[i].vertex[j]; int onseam_correct = 1; - float s = texcoords[vertexNum[j]].s; - float t = texcoords[vertexNum[j]].t; - if ( !triangles[i].facesfront && texcoords[vertexNum[j]].onseam) + float s = texcoords[triangles[i].vertex[j]].s; + float t = texcoords[triangles[i].vertex[j]].t; + if (!triangles[i].facesfront && texcoords[triangles[i].vertex[j]].onseam) { s = s + header->skinWidth * 0.5f; } s = (s + 0.5) / header->skinWidth; t = (t + 0.5) / header->skinHeight; - coords[vertexNum[j]].s = s; - coords[vertexNum[j]].t = t; - coords[vertexNum[j]].id = vertexNum[j]; + coords[3 * i + j].s = s; + coords[3 * i + j].t = t; + coords[3 * i + j].id = triangles[i].vertex[j]; + float st[2] = { s, t }; + textureCoordinates->InsertNextTuple(st); } - cells->InsertNextCell(3, vertexNum); + vtkIdType t[3] = { i * 3, i * 3 + 1, i * 3 + 2 }; + cells->InsertNextCell(3, t); + } - // Add texture coords - for (int i = 0; i < header->numVertices; i++) - { - float* s_t = new float[2]; - s_t[0] = coords[i].s; - s_t[1] = coords[i].t; - textureCoordinates->InsertNextTuple(s_t); - } // Draw vertices @@ -268,10 +275,11 @@ class vtkQuakeMDLImporter::vtkInternals for (int frameNum = 0; frameNum < header->numFrames; frameNum++) { vtkNew vertices; - vertices->Allocate(header->numVertices); + vertices->Allocate(header->numTriangles * 3); vtkNew normals; normals->SetNumberOfComponents(3); - normals->Allocate(header->numVertices * 3); + normals->Allocate(header->numTriangles * 3 * 3); + plugin_frame_pointer selectedFrame = framePtr[frameNum]; if (*selectedFrame.type == 0) { @@ -288,17 +296,17 @@ class vtkQuakeMDLImporter::vtkInternals { v[k] = v[k] * header->scale[k] + header->translation[k]; } - vertices->InsertPoint(vertexNum[j], v); + vertices->InsertPoint(i*3+j, v); int normalIndex = selectedFrame.frames->verts[vertexNum[j]].normalIndex; - normals->SetTuple3(vertexNum[j], NormalVectors[normalIndex][0] / 255.0, - NormalVectors[normalIndex][1] / 255.0, NormalVectors[normalIndex][2] / 255.0); + normals->SetTuple3(i*3+j, NormalVectors[normalIndex][0] / 255.0, + NormalVectors[normalIndex][1] / 255.0, NormalVectors[normalIndex][2] / 255.0); } } vtkNew mesh; mesh->SetPoints(vertices); mesh->SetPolys(cells); mesh->GetPointData()->SetTCoords(textureCoordinates); - mesh->GetPointData()->SetNormals(normals); +// mesh->GetPointData()->SetNormals(normals); Mesh.push_back(mesh); std::string meshName = std::string(selectedFrame.frames->name); for (int i = 0; i < meshName.size(); i++) @@ -339,9 +347,9 @@ class vtkQuakeMDLImporter::vtkInternals { v[k] = v[k] * header->scale[k] + header->translation[k]; } - vertices->InsertPoint(vertexNum[j], v); + vertices->InsertPoint(i*3+j, v); int normalIndex = selectedFrame.frames[groupFrameNum].verts[vertexNum[j]].normalIndex; - normals->SetTuple3(vertexNum[j], NormalVectors[normalIndex][0] / 255.0, + normals->SetTuple3(i*3+j, NormalVectors[normalIndex][0] / 255.0, NormalVectors[normalIndex][1] / 255.0, NormalVectors[normalIndex][2] / 255.0); } } @@ -375,7 +383,8 @@ class vtkQuakeMDLImporter::vtkInternals } } } - + return; + // Add interpolated frames for (int i = 0; i < Mesh.size() - 1; i++) { @@ -386,11 +395,8 @@ class vtkQuakeMDLImporter::vtkInternals else { vtkNew vertices; - vertices->Allocate(header->numVertices); - vtkNew normals; - normals->SetNumberOfComponents(3); - normals->Allocate(header->numVertices * 3); - for (int j = 0; j < header->numVertices; j++) + vertices->Allocate(header->numTriangles * 3); + for (int j = 0; j < header->numTriangles * 3; j++) { double* v_0 = Mesh[i]->GetPoint(j); double* v_1 = Mesh[i+1]->GetPoint(j); @@ -417,10 +423,7 @@ class vtkQuakeMDLImporter::vtkInternals bool ReadScene(const std::string& filePath) { std::ifstream inputStream(filePath, std::ios::binary); - std::vector buffer(std::istreambuf_iterator(inputStream), {}); - - // Read header mdl_header_t* header = reinterpret_cast(buffer.data()); int offset = 84; @@ -440,11 +443,11 @@ class vtkQuakeMDLImporter::vtkInternals void UpdateFrame(double timeValue) { - // Hardcoded frames per second - if (abs(timeValue - LastRenderTime) > 1.0 / 60) + // Hardcoded frames per second, 24FPS seems reasonable + if (abs(timeValue - LastRenderTime) > 1.0 / 24) { Mapper->SetInputData( - Mesh[(CurrentFrameIndex++) % (LastFrameIndex - FirstFrameIndex) + FirstFrameIndex]); + Mesh[(CurrentFrameIndex++) % (LastFrameIndex - FirstFrameIndex) + FirstFrameIndex]); LastRenderTime = timeValue; } } @@ -452,6 +455,8 @@ class vtkQuakeMDLImporter::vtkInternals // Only one animation enabled at a time void EnableAnimation(vtkIdType animationIndex) { + // Animations are divided into groups, but stored as a vector of polydata. + // This functions set the indices for the first and last frames in the group. int i = 0; while (i < GroupAndTimeVal.size() && GroupAndTimeVal[++i].first < animationIndex) { @@ -468,7 +473,6 @@ class vtkQuakeMDLImporter::vtkInternals vtkNew actor; vtkNew mapper; mapper->SetInputData(Mesh[0]); - //Mesh); actor->SetMapper(mapper); actor->SetTexture(Texture); renderer->AddActor(actor); @@ -478,18 +482,6 @@ class vtkQuakeMDLImporter::vtkInternals Mapper = mapper; } - void UpdateNodeTransform() - { - } - - void UpdateCameras() - { - } - - void UpdateLights() - { - - } vtkQuakeMDLImporter* Parent; @@ -676,7 +668,7 @@ void vtkQuakeMDLImporter::UpdateTimeStep(double timeValue) //---------------------------------------------------------------------------- vtkIdType vtkQuakeMDLImporter::GetNumberOfAnimations() { - return this->Internals->NumberOfAnimations; + return this->Internals->NumberOfAnimations; } //---------------------------------------------------------------------------- From 3301f2470c28ab765593dccc96eef042c3a358cc Mon Sep 17 00:00:00 2001 From: Youva Boutora <48061964+Youva@users.noreply.github.com> Date: Sun, 8 Sep 2024 13:52:30 -0400 Subject: [PATCH 09/60] Formatting --- plugins/alembic/module/vtkF3DAlembicReader.h | 2 +- .../alembic/module/vtkF3DAlembicReader.h.rej | 13 + plugins/native/module/vtkQuakeMDLImporter.cxx | 104 +++--- .../native/module/vtkQuakeMDLImporter.cxx.rej | 9 + plugins/native/module/vtkQuakeMDLImporter.h | 7 +- .../native/module/vtkQuakeMDLImporter.h.rej | 17 + style.diff | 344 ++++++++++++++++++ 7 files changed, 433 insertions(+), 63 deletions(-) create mode 100644 plugins/alembic/module/vtkF3DAlembicReader.h.rej create mode 100644 plugins/native/module/vtkQuakeMDLImporter.cxx.rej create mode 100644 plugins/native/module/vtkQuakeMDLImporter.h.rej create mode 100644 style.diff diff --git a/plugins/alembic/module/vtkF3DAlembicReader.h b/plugins/alembic/module/vtkF3DAlembicReader.h index cb09a53823..e8a47dd412 100644 --- a/plugins/alembic/module/vtkF3DAlembicReader.h +++ b/plugins/alembic/module/vtkF3DAlembicReader.h @@ -14,10 +14,10 @@ #ifndef vtkF3DAlembicReader_h #define vtkF3DAlembicReader_h +#include #include #include #include -#include class vtkF3DAlembicReader : public vtkPolyDataAlgorithm { diff --git a/plugins/alembic/module/vtkF3DAlembicReader.h.rej b/plugins/alembic/module/vtkF3DAlembicReader.h.rej new file mode 100644 index 0000000000..913c02343d --- /dev/null +++ b/plugins/alembic/module/vtkF3DAlembicReader.h.rej @@ -0,0 +1,13 @@ +diff a/plugins/alembic/module/vtkF3DAlembicReader.h b/plugins/alembic/module/vtkF3DAlembicReader.h (rejected hunks) +@@ -14,10 +14,10 @@ + #ifndef vtkF3DAlembicReader_h + #define vtkF3DAlembicReader_h + ++#include + #include + #include + #include +-#include + + class vtkF3DAlembicReader : public vtkPolyDataAlgorithm + { diff --git a/plugins/native/module/vtkQuakeMDLImporter.cxx b/plugins/native/module/vtkQuakeMDLImporter.cxx index cce93d9bd6..3c1f92c124 100644 --- a/plugins/native/module/vtkQuakeMDLImporter.cxx +++ b/plugins/native/module/vtkQuakeMDLImporter.cxx @@ -1,43 +1,42 @@ #include "vtkQuakeMDLImporter.h" -#include +#include +#include +#include #include -#include #include #include #include #include #include +#include #include #include +#include +#include +#include #include +#include +#include +#include +#include #include #include #include -#include -#include #include -#include -#include +#include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include -#include +#include +#include #include #include +#include +#include //---------------------------------------------------------------------------- vtkStandardNewMacro(vtkQuakeMDLImporter); - class vtkQuakeMDLImporter::vtkInternals { public: @@ -72,24 +71,23 @@ class vtkQuakeMDLImporter::vtkInternals vtkNew backLight; double backLightPosition[3] = { -50.0, 0.0, 0.0 }; backLight->SetPosition(backLightPosition); - + renderer->AddLight(frontLight); renderer->AddLight(leftLight); renderer->AddLight(backLight); } //---------------------------------------------------------------------------- - vtkSmartPointer CreateTexture(std::vector buffer, int& offset, int skinWidth, - int skinHeight, int nbSkins, int selectedSkinIndex) + vtkSmartPointer CreateTexture(std::vector buffer, int& offset, + int skinWidth, int skinHeight, int nbSkins, int selectedSkinIndex) { vtkNew texture; texture->InterpolateOn(); - // Read textures. struct mdl_skin_t { - int group; /* 0 = single, 1 = group */ + int group; /* 0 = single, 1 = group */ unsigned char* data; /* texture data */ }; struct mdl_groupskin_t @@ -118,7 +116,7 @@ class vtkQuakeMDLImporter::vtkInternals else { skins[i].group = 1; - int nb = *reinterpret_cast(buffer.data() + offset + 4); + int nb = *reinterpret_cast(buffer.data() + offset + 4); skins[i].skin = reinterpret_cast(buffer.data() + 4 + nb * 4 + offset); offset += 4 + nb * 4 + nb * (skinWidth) * (skinHeight); } @@ -129,12 +127,12 @@ class vtkQuakeMDLImporter::vtkInternals img->SetDimensions(skinWidth, skinHeight, 1); img->AllocateScalars(VTK_UNSIGNED_CHAR, 3); unsigned char* selectedSkin = skins[selectedSkinIndex].skin; - for (int i = 0; i < skinHeight ; i++) + for (int i = 0; i < skinHeight; i++) { for (int j = 0; j < skinWidth; j++) { unsigned char index = *reinterpret_cast(selectedSkin + i * skinWidth + j); - unsigned char* ptr = reinterpret_cast(img->GetScalarPointer(j,i,0)); + unsigned char* ptr = reinterpret_cast(img->GetScalarPointer(j, i, 0)); ptr[0] = DefaultColorMap[index][0]; // R ptr[1] = DefaultColorMap[index][1]; // G ptr[2] = DefaultColorMap[index][2]; // B @@ -145,8 +143,8 @@ class vtkQuakeMDLImporter::vtkInternals return texture; } - - void CreateMesh(std::vector buffer, int& offset, mdl_header_t* header, int selectedFrameIndex) + void CreateMesh( + std::vector buffer, int& offset, mdl_header_t* header, int selectedFrameIndex) { // Read texture coordinates struct mdl_texcoord_t @@ -217,9 +215,8 @@ class vtkQuakeMDLImporter::vtkInternals framePtr[i].nb = reinterpret_cast(buffer.data() + 4 + offset); mdl_vertex_t* min = reinterpret_cast(buffer.data() + 8 + offset); mdl_vertex_t* max = reinterpret_cast(buffer.data() + 12 + offset); - float* time = - framePtr[i].time = reinterpret_cast(buffer.data() + 16 + offset); - framePtr[i].frames = + float* time = framePtr[i].time = reinterpret_cast(buffer.data() + 16 + offset); + framePtr[i].frames = reinterpret_cast(buffer.data() + 16 + 4 * (*framePtr[i].nb) + offset); offset += 16 + (*framePtr[i].nb) * 4; for (int j = 0; j < *framePtr[i].nb; j++) @@ -265,10 +262,8 @@ class vtkQuakeMDLImporter::vtkInternals } vtkIdType t[3] = { i * 3, i * 3 + 1, i * 3 + 2 }; cells->InsertNextCell(3, t); - } - // Draw vertices std::string frameName = ""; int frameIndex = 0; @@ -279,7 +274,7 @@ class vtkQuakeMDLImporter::vtkInternals vtkNew normals; normals->SetNumberOfComponents(3); normals->Allocate(header->numTriangles * 3 * 3); - + plugin_frame_pointer selectedFrame = framePtr[frameNum]; if (*selectedFrame.type == 0) { @@ -296,17 +291,17 @@ class vtkQuakeMDLImporter::vtkInternals { v[k] = v[k] * header->scale[k] + header->translation[k]; } - vertices->InsertPoint(i*3+j, v); + vertices->InsertPoint(i * 3 + j, v); int normalIndex = selectedFrame.frames->verts[vertexNum[j]].normalIndex; - normals->SetTuple3(i*3+j, NormalVectors[normalIndex][0] / 255.0, - NormalVectors[normalIndex][1] / 255.0, NormalVectors[normalIndex][2] / 255.0); + normals->SetTuple3(i * 3 + j, NormalVectors[normalIndex][0] / 255.0, + NormalVectors[normalIndex][1] / 255.0, NormalVectors[normalIndex][2] / 255.0); } } vtkNew mesh; mesh->SetPoints(vertices); mesh->SetPolys(cells); mesh->GetPointData()->SetTCoords(textureCoordinates); -// mesh->GetPointData()->SetNormals(normals); + // mesh->GetPointData()->SetNormals(normals); Mesh.push_back(mesh); std::string meshName = std::string(selectedFrame.frames->name); for (int i = 0; i < meshName.size(); i++) @@ -347,9 +342,9 @@ class vtkQuakeMDLImporter::vtkInternals { v[k] = v[k] * header->scale[k] + header->translation[k]; } - vertices->InsertPoint(i*3+j, v); + vertices->InsertPoint(i * 3 + j, v); int normalIndex = selectedFrame.frames[groupFrameNum].verts[vertexNum[j]].normalIndex; - normals->SetTuple3(i*3+j, NormalVectors[normalIndex][0] / 255.0, + normals->SetTuple3(i * 3 + j, NormalVectors[normalIndex][0] / 255.0, NormalVectors[normalIndex][1] / 255.0, NormalVectors[normalIndex][2] / 255.0); } } @@ -378,7 +373,8 @@ class vtkQuakeMDLImporter::vtkInternals NumberOfAnimations++; frameName = meshName; } - std::pair pair = std::make_pair(frameIndex, selectedFrame.time[groupFrameNum]); + std::pair pair = + std::make_pair(frameIndex, selectedFrame.time[groupFrameNum]); GroupAndTimeVal.push_back(pair); } } @@ -399,7 +395,7 @@ class vtkQuakeMDLImporter::vtkInternals for (int j = 0; j < header->numTriangles * 3; j++) { double* v_0 = Mesh[i]->GetPoint(j); - double* v_1 = Mesh[i+1]->GetPoint(j); + double* v_1 = Mesh[i + 1]->GetPoint(j); double* interp = new double[3]; interp[0] = v_0[0] + 0.5 * (v_1[0] - v_0[0]); interp[1] = v_0[1] + 0.5 * (v_1[1] - v_0[1]); @@ -427,17 +423,14 @@ class vtkQuakeMDLImporter::vtkInternals // Read header mdl_header_t* header = reinterpret_cast(buffer.data()); int offset = 84; - + // Set textures - Texture= this->CreateTexture( + Texture = this->CreateTexture( buffer, offset, header->skinWidth, header->skinHeight, header->numSkins, 0); - - + // Set polyData this->CreateMesh(buffer, offset, header, 0); - - - + return 1; } @@ -447,7 +440,7 @@ class vtkQuakeMDLImporter::vtkInternals if (abs(timeValue - LastRenderTime) > 1.0 / 24) { Mapper->SetInputData( - Mesh[(CurrentFrameIndex++) % (LastFrameIndex - FirstFrameIndex) + FirstFrameIndex]); + Mesh[(CurrentFrameIndex++) % (LastFrameIndex - FirstFrameIndex) + FirstFrameIndex]); LastRenderTime = timeValue; } } @@ -465,7 +458,7 @@ class vtkQuakeMDLImporter::vtkInternals while (i < GroupAndTimeVal.size() && GroupAndTimeVal[++i].first == animationIndex) { } - LastFrameIndex = i-1; + LastFrameIndex = i - 1; } void ImportActors(vtkRenderer* renderer) @@ -482,14 +475,12 @@ class vtkQuakeMDLImporter::vtkInternals Mapper = mapper; } - - vtkQuakeMDLImporter* Parent; std::string Description; vtkSmartPointer Actor; vtkSmartPointer Mapper; std::vector> Mesh; - std::vector > GroupAndTimeVal; + std::vector> GroupAndTimeVal; int ActiveAnimationId = 0; int CurrentFrameIndex = 0; int FirstFrameIndex = 0; @@ -637,9 +628,6 @@ vtkQuakeMDLImporter::vtkQuakeMDLImporter() //---------------------------------------------------------------------------- - - - //---------------------------------------------------------------------------- int vtkQuakeMDLImporter::ImportBegin() { @@ -696,7 +684,6 @@ bool vtkQuakeMDLImporter::IsAnimationEnabled(vtkIdType animationIndex) return true; } - //---------------------------------------------------------------------------- bool vtkQuakeMDLImporter::GetTemporalInformation(vtkIdType animationIndex, double vtkNotUsed(frameRate), int& vtkNotUsed(nbTimeSteps), double timeRange[2], @@ -722,9 +709,10 @@ std::string vtkQuakeMDLImporter::GetCameraName(vtkIdType camIndex) //---------------------------------------------------------------------------- void vtkQuakeMDLImporter::SetCamera(vtkIdType camIndex) { - + return; } + //---------------------------------------------------------------------------- void vtkQuakeMDLImporter::ImportCameras(vtkRenderer* renderer) { diff --git a/plugins/native/module/vtkQuakeMDLImporter.cxx.rej b/plugins/native/module/vtkQuakeMDLImporter.cxx.rej new file mode 100644 index 0000000000..b3fc6d37fd --- /dev/null +++ b/plugins/native/module/vtkQuakeMDLImporter.cxx.rej @@ -0,0 +1,9 @@ +diff a/plugins/native/module/vtkQuakeMDLImporter.cxx b/plugins/native/module/vtkQuakeMDLImporter.cxx (rejected hunks) +@@ -722,7 +709,6 @@ + //---------------------------------------------------------------------------- + void vtkQuakeMDLImporter::SetCamera(vtkIdType camIndex) + { +- + } + + //---------------------------------------------------------------------------- diff --git a/plugins/native/module/vtkQuakeMDLImporter.h b/plugins/native/module/vtkQuakeMDLImporter.h index 5b2e9f43b2..1e07702f19 100644 --- a/plugins/native/module/vtkQuakeMDLImporter.h +++ b/plugins/native/module/vtkQuakeMDLImporter.h @@ -5,7 +5,7 @@ #ifndef vtkQuakeMDLImporter_h #define vtkQuakeMDLImporter_h -#include +#include class vtkQuakeMDLImporter : public vtkImporter { @@ -86,17 +86,16 @@ class vtkQuakeMDLImporter : public vtkImporter */ void SetCamera(vtkIdType camIndex) override; - protected: vtkQuakeMDLImporter(); ~vtkQuakeMDLImporter() override = default; - + int ImportBegin() override; void ImportActors(vtkRenderer*) override; void ImportCameras(vtkRenderer*) override; void ImportLights(vtkRenderer*) override; - // Header definition, + // Header definition, struct mdl_header_t { int IDPO; diff --git a/plugins/native/module/vtkQuakeMDLImporter.h.rej b/plugins/native/module/vtkQuakeMDLImporter.h.rej new file mode 100644 index 0000000000..9a24d88285 --- /dev/null +++ b/plugins/native/module/vtkQuakeMDLImporter.h.rej @@ -0,0 +1,17 @@ +diff a/plugins/native/module/vtkQuakeMDLImporter.h b/plugins/native/module/vtkQuakeMDLImporter.h (rejected hunks) +@@ -5,14 +5,13 @@ + + #ifndef vtkQuakeMDLImporter_h + #define vtkQuakeMDLImporter_h +-#include ++#include + + class vtkQuakeMDLImporter : public vtkImporter + { + public: + static vtkQuakeMDLImporter* New(); + vtkTypeMacro(vtkQuakeMDLImporter, vtkImporter); +- + + void PrintSelf(ostream& os, vtkIndent indent) override; + diff --git a/style.diff b/style.diff new file mode 100644 index 0000000000..e80a12c576 --- /dev/null +++ b/style.diff @@ -0,0 +1,344 @@ +--- plugins/alembic/module/vtkF3DAlembicReader.h (original) ++++ plugins/alembic/module/vtkF3DAlembicReader.h (reformatted) +@@ -14,10 +14,10 @@ + #ifndef vtkF3DAlembicReader_h + #define vtkF3DAlembicReader_h + ++#include + #include + #include + #include +-#include + + class vtkF3DAlembicReader : public vtkPolyDataAlgorithm + { +--- plugins/native/module/vtkQuakeMDLImporter.h (original) ++++ plugins/native/module/vtkQuakeMDLImporter.h (reformatted) +@@ -5,14 +5,13 @@ + + #ifndef vtkQuakeMDLImporter_h + #define vtkQuakeMDLImporter_h +-#include ++#include + + class vtkQuakeMDLImporter : public vtkImporter + { + public: + static vtkQuakeMDLImporter* New(); + vtkTypeMacro(vtkQuakeMDLImporter, vtkImporter); +- + + void PrintSelf(ostream& os, vtkIndent indent) override; + +@@ -86,17 +85,16 @@ + */ + void SetCamera(vtkIdType camIndex) override; + +- + protected: + vtkQuakeMDLImporter(); + ~vtkQuakeMDLImporter() override = default; +- ++ + int ImportBegin() override; + void ImportActors(vtkRenderer*) override; + void ImportCameras(vtkRenderer*) override; + void ImportLights(vtkRenderer*) override; + +- // Header definition, ++ // Header definition, + struct mdl_header_t + { + int IDPO; +--- plugins/native/module/vtkQuakeMDLImporter.cxx (original) ++++ plugins/native/module/vtkQuakeMDLImporter.cxx (reformatted) +@@ -1,42 +1,41 @@ + #include "vtkQuakeMDLImporter.h" + +-#include ++#include ++#include ++#include + #include +-#include + #include + #include + #include + #include + #include ++#include + #include + #include ++#include ++#include ++#include + #include ++#include ++#include ++#include ++#include + #include + #include + #include +-#include +-#include + #include +-#include +-#include ++#include + #include +-#include +-#include +-#include +-#include ++#include ++#include + #include +-#include +-#include +-#include +-#include +-#include +-#include + #include + #include ++#include ++#include + + //---------------------------------------------------------------------------- + vtkStandardNewMacro(vtkQuakeMDLImporter); +- + + class vtkQuakeMDLImporter::vtkInternals + { +@@ -72,24 +71,23 @@ + vtkNew backLight; + double backLightPosition[3] = { -50.0, 0.0, 0.0 }; + backLight->SetPosition(backLightPosition); +- ++ + renderer->AddLight(frontLight); + renderer->AddLight(leftLight); + renderer->AddLight(backLight); + } + + //---------------------------------------------------------------------------- +- vtkSmartPointer CreateTexture(std::vector buffer, int& offset, int skinWidth, +- int skinHeight, int nbSkins, int selectedSkinIndex) ++ vtkSmartPointer CreateTexture(std::vector buffer, int& offset, ++ int skinWidth, int skinHeight, int nbSkins, int selectedSkinIndex) + { + vtkNew texture; + texture->InterpolateOn(); + +- + // Read textures. + struct mdl_skin_t + { +- int group; /* 0 = single, 1 = group */ ++ int group; /* 0 = single, 1 = group */ + unsigned char* data; /* texture data */ + }; + struct mdl_groupskin_t +@@ -118,7 +116,7 @@ + else + { + skins[i].group = 1; +- int nb = *reinterpret_cast(buffer.data() + offset + 4); ++ int nb = *reinterpret_cast(buffer.data() + offset + 4); + skins[i].skin = reinterpret_cast(buffer.data() + 4 + nb * 4 + offset); + offset += 4 + nb * 4 + nb * (skinWidth) * (skinHeight); + } +@@ -129,12 +127,12 @@ + img->SetDimensions(skinWidth, skinHeight, 1); + img->AllocateScalars(VTK_UNSIGNED_CHAR, 3); + unsigned char* selectedSkin = skins[selectedSkinIndex].skin; +- for (int i = 0; i < skinHeight ; i++) ++ for (int i = 0; i < skinHeight; i++) + { + for (int j = 0; j < skinWidth; j++) + { + unsigned char index = *reinterpret_cast(selectedSkin + i * skinWidth + j); +- unsigned char* ptr = reinterpret_cast(img->GetScalarPointer(j,i,0)); ++ unsigned char* ptr = reinterpret_cast(img->GetScalarPointer(j, i, 0)); + ptr[0] = DefaultColorMap[index][0]; // R + ptr[1] = DefaultColorMap[index][1]; // G + ptr[2] = DefaultColorMap[index][2]; // B +@@ -145,8 +143,8 @@ + return texture; + } + +- +- void CreateMesh(std::vector buffer, int& offset, mdl_header_t* header, int selectedFrameIndex) ++ void CreateMesh( ++ std::vector buffer, int& offset, mdl_header_t* header, int selectedFrameIndex) + { + // Read texture coordinates + struct mdl_texcoord_t +@@ -217,9 +215,8 @@ + framePtr[i].nb = reinterpret_cast(buffer.data() + 4 + offset); + mdl_vertex_t* min = reinterpret_cast(buffer.data() + 8 + offset); + mdl_vertex_t* max = reinterpret_cast(buffer.data() + 12 + offset); +- float* time = +- framePtr[i].time = reinterpret_cast(buffer.data() + 16 + offset); +- framePtr[i].frames = ++ float* time = framePtr[i].time = reinterpret_cast(buffer.data() + 16 + offset); ++ framePtr[i].frames = + reinterpret_cast(buffer.data() + 16 + 4 * (*framePtr[i].nb) + offset); + offset += 16 + (*framePtr[i].nb) * 4; + for (int j = 0; j < *framePtr[i].nb; j++) +@@ -265,9 +262,7 @@ + } + vtkIdType t[3] = { i * 3, i * 3 + 1, i * 3 + 2 }; + cells->InsertNextCell(3, t); +- +- } +- ++ } + + // Draw vertices + std::string frameName = ""; +@@ -279,7 +274,7 @@ + vtkNew normals; + normals->SetNumberOfComponents(3); + normals->Allocate(header->numTriangles * 3 * 3); +- ++ + plugin_frame_pointer selectedFrame = framePtr[frameNum]; + if (*selectedFrame.type == 0) + { +@@ -296,17 +291,17 @@ + { + v[k] = v[k] * header->scale[k] + header->translation[k]; + } +- vertices->InsertPoint(i*3+j, v); ++ vertices->InsertPoint(i * 3 + j, v); + int normalIndex = selectedFrame.frames->verts[vertexNum[j]].normalIndex; +- normals->SetTuple3(i*3+j, NormalVectors[normalIndex][0] / 255.0, +- NormalVectors[normalIndex][1] / 255.0, NormalVectors[normalIndex][2] / 255.0); ++ normals->SetTuple3(i * 3 + j, NormalVectors[normalIndex][0] / 255.0, ++ NormalVectors[normalIndex][1] / 255.0, NormalVectors[normalIndex][2] / 255.0); + } + } + vtkNew mesh; + mesh->SetPoints(vertices); + mesh->SetPolys(cells); + mesh->GetPointData()->SetTCoords(textureCoordinates); +-// mesh->GetPointData()->SetNormals(normals); ++ // mesh->GetPointData()->SetNormals(normals); + Mesh.push_back(mesh); + std::string meshName = std::string(selectedFrame.frames->name); + for (int i = 0; i < meshName.size(); i++) +@@ -347,9 +342,9 @@ + { + v[k] = v[k] * header->scale[k] + header->translation[k]; + } +- vertices->InsertPoint(i*3+j, v); ++ vertices->InsertPoint(i * 3 + j, v); + int normalIndex = selectedFrame.frames[groupFrameNum].verts[vertexNum[j]].normalIndex; +- normals->SetTuple3(i*3+j, NormalVectors[normalIndex][0] / 255.0, ++ normals->SetTuple3(i * 3 + j, NormalVectors[normalIndex][0] / 255.0, + NormalVectors[normalIndex][1] / 255.0, NormalVectors[normalIndex][2] / 255.0); + } + } +@@ -378,7 +373,8 @@ + NumberOfAnimations++; + frameName = meshName; + } +- std::pair pair = std::make_pair(frameIndex, selectedFrame.time[groupFrameNum]); ++ std::pair pair = ++ std::make_pair(frameIndex, selectedFrame.time[groupFrameNum]); + GroupAndTimeVal.push_back(pair); + } + } +@@ -399,7 +395,7 @@ + for (int j = 0; j < header->numTriangles * 3; j++) + { + double* v_0 = Mesh[i]->GetPoint(j); +- double* v_1 = Mesh[i+1]->GetPoint(j); ++ double* v_1 = Mesh[i + 1]->GetPoint(j); + double* interp = new double[3]; + interp[0] = v_0[0] + 0.5 * (v_1[0] - v_0[0]); + interp[1] = v_0[1] + 0.5 * (v_1[1] - v_0[1]); +@@ -427,17 +423,14 @@ + // Read header + mdl_header_t* header = reinterpret_cast(buffer.data()); + int offset = 84; +- ++ + // Set textures +- Texture= this->CreateTexture( ++ Texture = this->CreateTexture( + buffer, offset, header->skinWidth, header->skinHeight, header->numSkins, 0); +- +- ++ + // Set polyData + this->CreateMesh(buffer, offset, header, 0); +- +- +- ++ + return 1; + } + +@@ -447,7 +440,7 @@ + if (abs(timeValue - LastRenderTime) > 1.0 / 24) + { + Mapper->SetInputData( +- Mesh[(CurrentFrameIndex++) % (LastFrameIndex - FirstFrameIndex) + FirstFrameIndex]); ++ Mesh[(CurrentFrameIndex++) % (LastFrameIndex - FirstFrameIndex) + FirstFrameIndex]); + LastRenderTime = timeValue; + } + } +@@ -465,7 +458,7 @@ + while (i < GroupAndTimeVal.size() && GroupAndTimeVal[++i].first == animationIndex) + { + } +- LastFrameIndex = i-1; ++ LastFrameIndex = i - 1; + } + + void ImportActors(vtkRenderer* renderer) +@@ -482,14 +475,12 @@ + Mapper = mapper; + } + +- +- + vtkQuakeMDLImporter* Parent; + std::string Description; + vtkSmartPointer Actor; + vtkSmartPointer Mapper; + std::vector> Mesh; +- std::vector > GroupAndTimeVal; ++ std::vector> GroupAndTimeVal; + int ActiveAnimationId = 0; + int CurrentFrameIndex = 0; + int FirstFrameIndex = 0; +@@ -637,9 +628,6 @@ + + //---------------------------------------------------------------------------- + +- +- +- + //---------------------------------------------------------------------------- + int vtkQuakeMDLImporter::ImportBegin() + { +@@ -695,7 +683,6 @@ + { + return true; + } +- + + //---------------------------------------------------------------------------- + bool vtkQuakeMDLImporter::GetTemporalInformation(vtkIdType animationIndex, +@@ -722,7 +709,6 @@ + //---------------------------------------------------------------------------- + void vtkQuakeMDLImporter::SetCamera(vtkIdType camIndex) + { +- + } + + //---------------------------------------------------------------------------- From 83e8e682f23da736f72535efde980cd32e0a747a Mon Sep 17 00:00:00 2001 From: Youva Boutora <48061964+Youva@users.noreply.github.com> Date: Sun, 8 Sep 2024 13:55:22 -0400 Subject: [PATCH 10/60] Formatting --- plugins/native/module/vtkQuakeMDLImporter.cxx | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/native/module/vtkQuakeMDLImporter.cxx b/plugins/native/module/vtkQuakeMDLImporter.cxx index 3c1f92c124..98b33b2915 100644 --- a/plugins/native/module/vtkQuakeMDLImporter.cxx +++ b/plugins/native/module/vtkQuakeMDLImporter.cxx @@ -712,7 +712,6 @@ void vtkQuakeMDLImporter::SetCamera(vtkIdType camIndex) return; } - //---------------------------------------------------------------------------- void vtkQuakeMDLImporter::ImportCameras(vtkRenderer* renderer) { From f5e38b7000ece63deceddfa7914c6c953175fdcb Mon Sep 17 00:00:00 2001 From: Youva Boutora <48061964+Youva@users.noreply.github.com> Date: Sun, 8 Sep 2024 13:56:15 -0400 Subject: [PATCH 11/60] Formatting --- plugins/native/module/vtkQuakeMDLImporter.h | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/native/module/vtkQuakeMDLImporter.h b/plugins/native/module/vtkQuakeMDLImporter.h index 1e07702f19..56b26c8e46 100644 --- a/plugins/native/module/vtkQuakeMDLImporter.h +++ b/plugins/native/module/vtkQuakeMDLImporter.h @@ -13,7 +13,6 @@ class vtkQuakeMDLImporter : public vtkImporter static vtkQuakeMDLImporter* New(); vtkTypeMacro(vtkQuakeMDLImporter, vtkImporter); - void PrintSelf(ostream& os, vtkIndent indent) override; ///@{ From aa19fd0ea4ff20bf69da460c3f728a2e9e02d0b8 Mon Sep 17 00:00:00 2001 From: Youva Boutora <48061964+Youva@users.noreply.github.com> Date: Tue, 24 Sep 2024 14:09:07 -0400 Subject: [PATCH 12/60] Fixed build errors w/ strict_build --- plugins/native/module/vtkQuakeMDLImporter.cxx | 43 +++++++++---------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/plugins/native/module/vtkQuakeMDLImporter.cxx b/plugins/native/module/vtkQuakeMDLImporter.cxx index 98b33b2915..ca5ba3a60e 100644 --- a/plugins/native/module/vtkQuakeMDLImporter.cxx +++ b/plugins/native/module/vtkQuakeMDLImporter.cxx @@ -103,7 +103,7 @@ class vtkQuakeMDLImporter::vtkInternals unsigned char* skin; }; mixed_pointer_array* skins = new mixed_pointer_array[nbSkins]; - unsigned char* skin = reinterpret_cast(buffer.data() + offset + 4); + //unsigned char* skin = buffer.data() + offset + 4; for (int i = 0; i < nbSkins; i++) { int* group = reinterpret_cast(buffer.data() + offset); @@ -144,7 +144,7 @@ class vtkQuakeMDLImporter::vtkInternals } void CreateMesh( - std::vector buffer, int& offset, mdl_header_t* header, int selectedFrameIndex) + std::vector buffer, int offset, mdl_header_t* header) { // Read texture coordinates struct mdl_texcoord_t @@ -213,9 +213,9 @@ class vtkQuakeMDLImporter::vtkInternals { framePtr[i].type = type; framePtr[i].nb = reinterpret_cast(buffer.data() + 4 + offset); - mdl_vertex_t* min = reinterpret_cast(buffer.data() + 8 + offset); - mdl_vertex_t* max = reinterpret_cast(buffer.data() + 12 + offset); - float* time = framePtr[i].time = reinterpret_cast(buffer.data() + 16 + offset); + //mdl_vertex_t* min = reinterpret_cast(buffer.data() + 8 + offset); + //mdl_vertex_t* max = reinterpret_cast(buffer.data() + 12 + offset); + //float* time = framePtr[i].time = reinterpret_cast(buffer.data() + 16 + offset); framePtr[i].frames = reinterpret_cast(buffer.data() + 16 + 4 * (*framePtr[i].nb) + offset); offset += 16 + (*framePtr[i].nb) * 4; @@ -245,7 +245,7 @@ class vtkQuakeMDLImporter::vtkInternals for (int j = 0; j < 3; j++) { vertexNum[j] = triangles[i].vertex[j]; - int onseam_correct = 1; + //int onseam_correct = 1; float s = texcoords[triangles[i].vertex[j]].s; float t = texcoords[triangles[i].vertex[j]].t; if (!triangles[i].facesfront && texcoords[triangles[i].vertex[j]].onseam) @@ -284,9 +284,9 @@ class vtkQuakeMDLImporter::vtkInternals for (int j = 0; j < 3; j++) { vertexNum[j] = triangles[i].vertex[j]; - double v[3] = { selectedFrame.frames->verts[vertexNum[j]].v[0], - selectedFrame.frames->verts[vertexNum[j]].v[1], - selectedFrame.frames->verts[vertexNum[j]].v[2] }; + double v[3] = { double(selectedFrame.frames->verts[vertexNum[j]].v[0]), + double(selectedFrame.frames->verts[vertexNum[j]].v[1]), + double(selectedFrame.frames->verts[vertexNum[j]].v[2]) }; for (int k = 0; k < 3; k++) { v[k] = v[k] * header->scale[k] + header->translation[k]; @@ -335,9 +335,9 @@ class vtkQuakeMDLImporter::vtkInternals for (int j = 0; j < 3; j++) { vertexNum[j] = triangles[i].vertex[j]; - double v[3] = { selectedFrame.frames[groupFrameNum].verts[vertexNum[j]].v[0], - selectedFrame.frames[groupFrameNum].verts[vertexNum[j]].v[1], - selectedFrame.frames[groupFrameNum].verts[vertexNum[j]].v[2] }; + double v[3] = { double(selectedFrame.frames[groupFrameNum].verts[vertexNum[j]].v[0]), + double(selectedFrame.frames[groupFrameNum].verts[vertexNum[j]].v[1]), + double(selectedFrame.frames[groupFrameNum].verts[vertexNum[j]].v[2]) }; for (int k = 0; k < 3; k++) { v[k] = v[k] * header->scale[k] + header->translation[k]; @@ -379,8 +379,7 @@ class vtkQuakeMDLImporter::vtkInternals } } } - return; - + // Add interpolated frames for (int i = 0; i < Mesh.size() - 1; i++) { @@ -429,15 +428,15 @@ class vtkQuakeMDLImporter::vtkInternals buffer, offset, header->skinWidth, header->skinHeight, header->numSkins, 0); // Set polyData - this->CreateMesh(buffer, offset, header, 0); + this->CreateMesh(buffer, offset, header); return 1; } void UpdateFrame(double timeValue) { - // Hardcoded frames per second, 24FPS seems reasonable - if (abs(timeValue - LastRenderTime) > 1.0 / 24) + // Hardcoded frames per second, 60FPS + if (abs(timeValue - LastRenderTime) > 1.0 / 60) { Mapper->SetInputData( Mesh[(CurrentFrameIndex++) % (LastFrameIndex - FirstFrameIndex) + FirstFrameIndex]); @@ -662,7 +661,7 @@ vtkIdType vtkQuakeMDLImporter::GetNumberOfAnimations() //---------------------------------------------------------------------------- std::string vtkQuakeMDLImporter::GetAnimationName(vtkIdType animationIndex) { - return ""; + return std::to_string(animationIndex); } //---------------------------------------------------------------------------- @@ -681,11 +680,11 @@ void vtkQuakeMDLImporter::DisableAnimation(vtkIdType vtkNotUsed(animationIndex)) //---------------------------------------------------------------------------- bool vtkQuakeMDLImporter::IsAnimationEnabled(vtkIdType animationIndex) { - return true; + return animationIndex == this->Internals->ActiveAnimationId; } //---------------------------------------------------------------------------- -bool vtkQuakeMDLImporter::GetTemporalInformation(vtkIdType animationIndex, +bool vtkQuakeMDLImporter::GetTemporalInformation(vtkIdType vtkNotUsed(animationIndex), double vtkNotUsed(frameRate), int& vtkNotUsed(nbTimeSteps), double timeRange[2], vtkDoubleArray* vtkNotUsed(timeSteps)) { @@ -701,13 +700,13 @@ vtkIdType vtkQuakeMDLImporter::GetNumberOfCameras() } //---------------------------------------------------------------------------- -std::string vtkQuakeMDLImporter::GetCameraName(vtkIdType camIndex) +std::string vtkQuakeMDLImporter::GetCameraName(vtkIdType vtkNotUsed(camIndex)) { return "Camera"; } //---------------------------------------------------------------------------- -void vtkQuakeMDLImporter::SetCamera(vtkIdType camIndex) +void vtkQuakeMDLImporter::SetCamera(vtkIdType vtkNotUsed(camIndex)) { return; } From 45b8dceb95dd0f8d8c1ca2e052edeb30931d9347 Mon Sep 17 00:00:00 2001 From: Youva Boutora <48061964+Youva@users.noreply.github.com> Date: Tue, 24 Sep 2024 14:19:34 -0400 Subject: [PATCH 13/60] Update vtkQuakeMDLImporter.cxx Fixed incorrect type at line 452. --- plugins/native/module/vtkQuakeMDLImporter.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/native/module/vtkQuakeMDLImporter.cxx b/plugins/native/module/vtkQuakeMDLImporter.cxx index ca5ba3a60e..8635907242 100644 --- a/plugins/native/module/vtkQuakeMDLImporter.cxx +++ b/plugins/native/module/vtkQuakeMDLImporter.cxx @@ -449,7 +449,7 @@ class vtkQuakeMDLImporter::vtkInternals { // Animations are divided into groups, but stored as a vector of polydata. // This functions set the indices for the first and last frames in the group. - int i = 0; + std::size_t i = 0; while (i < GroupAndTimeVal.size() && GroupAndTimeVal[++i].first < animationIndex) { } From 9012a55227a83d58f68e996a72d90f0a8725bd46 Mon Sep 17 00:00:00 2001 From: Youva Boutora <48061964+Youva@users.noreply.github.com> Date: Tue, 24 Sep 2024 14:23:17 -0400 Subject: [PATCH 14/60] Update vtkQuakeMDLImporter.cxx Changed some int variables to size_t. --- plugins/native/module/vtkQuakeMDLImporter.cxx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/native/module/vtkQuakeMDLImporter.cxx b/plugins/native/module/vtkQuakeMDLImporter.cxx index 8635907242..06afcc5f93 100644 --- a/plugins/native/module/vtkQuakeMDLImporter.cxx +++ b/plugins/native/module/vtkQuakeMDLImporter.cxx @@ -304,7 +304,7 @@ class vtkQuakeMDLImporter::vtkInternals // mesh->GetPointData()->SetNormals(normals); Mesh.push_back(mesh); std::string meshName = std::string(selectedFrame.frames->name); - for (int i = 0; i < meshName.size(); i++) + for (std::size_t i = 0; i < meshName.size(); i++) { if (meshName[i] >= '0' && meshName[i] <= '9') { @@ -355,7 +355,7 @@ class vtkQuakeMDLImporter::vtkInternals mesh->GetPointData()->SetNormals(normals); Mesh.push_back(mesh); std::string meshName = std::string(selectedFrame.frames[groupFrameNum].name); - for (int i = 0; i < meshName.size(); i++) + for (std::size_t i = 0; i < meshName.size(); i++) { if (meshName[i] >= '0' && meshName[i] <= '9') { @@ -381,7 +381,7 @@ class vtkQuakeMDLImporter::vtkInternals } // Add interpolated frames - for (int i = 0; i < Mesh.size() - 1; i++) + for (std::size_t i = 0; i < Mesh.size() - 1; i++) { if (GroupAndTimeVal[i + 1].first != GroupAndTimeVal[i].first) { From 985211f7291521705a88c2cfc5dc8607a29267f0 Mon Sep 17 00:00:00 2001 From: Youva Boutora <48061964+Youva@users.noreply.github.com> Date: Tue, 24 Sep 2024 14:51:51 -0400 Subject: [PATCH 15/60] Fixed override updateTimeStep. --- plugins/native/module/vtkQuakeMDLImporter.cxx | 4 ++-- plugins/native/module/vtkQuakeMDLImporter.h | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/plugins/native/module/vtkQuakeMDLImporter.cxx b/plugins/native/module/vtkQuakeMDLImporter.cxx index 06afcc5f93..880d56e21f 100644 --- a/plugins/native/module/vtkQuakeMDLImporter.cxx +++ b/plugins/native/module/vtkQuakeMDLImporter.cxx @@ -457,7 +457,7 @@ class vtkQuakeMDLImporter::vtkInternals while (i < GroupAndTimeVal.size() && GroupAndTimeVal[++i].first == animationIndex) { } - LastFrameIndex = i - 1; + LastFrameIndex = (int) i - 1; } void ImportActors(vtkRenderer* renderer) @@ -646,7 +646,7 @@ std::string vtkQuakeMDLImporter::GetOutputsDescription() } //---------------------------------------------------------------------------- -void vtkQuakeMDLImporter::UpdateTimeStep(double timeValue) +void vtkQuakeMDLImporter::UpdateTimeStep(double timeValue) override { this->Internals->UpdateFrame(timeValue); return; diff --git a/plugins/native/module/vtkQuakeMDLImporter.h b/plugins/native/module/vtkQuakeMDLImporter.h index 56b26c8e46..dda246bdca 100644 --- a/plugins/native/module/vtkQuakeMDLImporter.h +++ b/plugins/native/module/vtkQuakeMDLImporter.h @@ -79,6 +79,11 @@ class vtkQuakeMDLImporter : public vtkImporter */ std::string GetCameraName(vtkIdType camIndex) override; + /** + * Re-render the scene after timestep + */ + void UpdateTimeStep(double timeValue) override; + /** * Enable a specific camera. * If a negative index is provided, no camera from the importer is used. From a5d5cf334b7d767802d30548cf5f25b7952a9957 Mon Sep 17 00:00:00 2001 From: Youva Boutora <48061964+Youva@users.noreply.github.com> Date: Tue, 24 Sep 2024 14:53:46 -0400 Subject: [PATCH 16/60] Removed some warnings --- plugins/native/module/vtkQuakeMDLImporter.cxx | 2 +- plugins/native/module/vtkQuakeMDLImporter.h | 7 +------ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/plugins/native/module/vtkQuakeMDLImporter.cxx b/plugins/native/module/vtkQuakeMDLImporter.cxx index 880d56e21f..d58e7c0c7a 100644 --- a/plugins/native/module/vtkQuakeMDLImporter.cxx +++ b/plugins/native/module/vtkQuakeMDLImporter.cxx @@ -646,7 +646,7 @@ std::string vtkQuakeMDLImporter::GetOutputsDescription() } //---------------------------------------------------------------------------- -void vtkQuakeMDLImporter::UpdateTimeStep(double timeValue) override +void vtkQuakeMDLImporter::UpdateTimeStep(double timeValue) { this->Internals->UpdateFrame(timeValue); return; diff --git a/plugins/native/module/vtkQuakeMDLImporter.h b/plugins/native/module/vtkQuakeMDLImporter.h index dda246bdca..c18d51543d 100644 --- a/plugins/native/module/vtkQuakeMDLImporter.h +++ b/plugins/native/module/vtkQuakeMDLImporter.h @@ -27,7 +27,7 @@ class vtkQuakeMDLImporter : public vtkImporter * Update actors at the given time value. */ - void UpdateTimeStep(double timeValue); + void UpdateTimeStep(double timeValue) override; /** * Get the number of available animations. @@ -79,11 +79,6 @@ class vtkQuakeMDLImporter : public vtkImporter */ std::string GetCameraName(vtkIdType camIndex) override; - /** - * Re-render the scene after timestep - */ - void UpdateTimeStep(double timeValue) override; - /** * Enable a specific camera. * If a negative index is provided, no camera from the importer is used. From 4e614070f8bf462e1137e34f8d28f903525f1d1f Mon Sep 17 00:00:00 2001 From: Youva Boutora <48061964+Youva@users.noreply.github.com> Date: Tue, 24 Sep 2024 14:59:49 -0400 Subject: [PATCH 17/60] Applied style. --- plugins/native/module/vtkQuakeMDLImporter.cxx | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/plugins/native/module/vtkQuakeMDLImporter.cxx b/plugins/native/module/vtkQuakeMDLImporter.cxx index d58e7c0c7a..8f1ed04572 100644 --- a/plugins/native/module/vtkQuakeMDLImporter.cxx +++ b/plugins/native/module/vtkQuakeMDLImporter.cxx @@ -103,7 +103,7 @@ class vtkQuakeMDLImporter::vtkInternals unsigned char* skin; }; mixed_pointer_array* skins = new mixed_pointer_array[nbSkins]; - //unsigned char* skin = buffer.data() + offset + 4; + // unsigned char* skin = buffer.data() + offset + 4; for (int i = 0; i < nbSkins; i++) { int* group = reinterpret_cast(buffer.data() + offset); @@ -143,8 +143,7 @@ class vtkQuakeMDLImporter::vtkInternals return texture; } - void CreateMesh( - std::vector buffer, int offset, mdl_header_t* header) + void CreateMesh(std::vector buffer, int offset, mdl_header_t* header) { // Read texture coordinates struct mdl_texcoord_t @@ -213,9 +212,9 @@ class vtkQuakeMDLImporter::vtkInternals { framePtr[i].type = type; framePtr[i].nb = reinterpret_cast(buffer.data() + 4 + offset); - //mdl_vertex_t* min = reinterpret_cast(buffer.data() + 8 + offset); - //mdl_vertex_t* max = reinterpret_cast(buffer.data() + 12 + offset); - //float* time = framePtr[i].time = reinterpret_cast(buffer.data() + 16 + offset); + // mdl_vertex_t* min = reinterpret_cast(buffer.data() + 8 + offset); + // mdl_vertex_t* max = reinterpret_cast(buffer.data() + 12 + offset); + // float* time = framePtr[i].time = reinterpret_cast(buffer.data() + 16 + offset); framePtr[i].frames = reinterpret_cast(buffer.data() + 16 + 4 * (*framePtr[i].nb) + offset); offset += 16 + (*framePtr[i].nb) * 4; @@ -245,7 +244,7 @@ class vtkQuakeMDLImporter::vtkInternals for (int j = 0; j < 3; j++) { vertexNum[j] = triangles[i].vertex[j]; - //int onseam_correct = 1; + // int onseam_correct = 1; float s = texcoords[triangles[i].vertex[j]].s; float t = texcoords[triangles[i].vertex[j]].t; if (!triangles[i].facesfront && texcoords[triangles[i].vertex[j]].onseam) @@ -379,7 +378,7 @@ class vtkQuakeMDLImporter::vtkInternals } } } - + // Add interpolated frames for (std::size_t i = 0; i < Mesh.size() - 1; i++) { @@ -457,7 +456,7 @@ class vtkQuakeMDLImporter::vtkInternals while (i < GroupAndTimeVal.size() && GroupAndTimeVal[++i].first == animationIndex) { } - LastFrameIndex = (int) i - 1; + LastFrameIndex = (int)i - 1; } void ImportActors(vtkRenderer* renderer) From afc778e76215d77ba7e2951d1bceac2023cd8402 Mon Sep 17 00:00:00 2001 From: Youva Boutora <48061964+Youva@users.noreply.github.com> Date: Tue, 24 Sep 2024 15:23:26 -0400 Subject: [PATCH 18/60] Changed push_back to emplace_back --- plugins/native/module/vtkQuakeMDLImporter.cxx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/native/module/vtkQuakeMDLImporter.cxx b/plugins/native/module/vtkQuakeMDLImporter.cxx index 8f1ed04572..a807e7f742 100644 --- a/plugins/native/module/vtkQuakeMDLImporter.cxx +++ b/plugins/native/module/vtkQuakeMDLImporter.cxx @@ -301,7 +301,7 @@ class vtkQuakeMDLImporter::vtkInternals mesh->SetPolys(cells); mesh->GetPointData()->SetTCoords(textureCoordinates); // mesh->GetPointData()->SetNormals(normals); - Mesh.push_back(mesh); + Mesh.emplace_back(mesh); std::string meshName = std::string(selectedFrame.frames->name); for (std::size_t i = 0; i < meshName.size(); i++) { @@ -322,7 +322,7 @@ class vtkQuakeMDLImporter::vtkInternals NumberOfAnimations++; } std::pair pair = std::make_pair(frameIndex, 0.0); - GroupAndTimeVal.push_back(pair); + GroupAndTimeVal.emplace_back(pair); } else { @@ -352,7 +352,7 @@ class vtkQuakeMDLImporter::vtkInternals mesh->SetPolys(cells); mesh->GetPointData()->SetTCoords(textureCoordinates); mesh->GetPointData()->SetNormals(normals); - Mesh.push_back(mesh); + Mesh.emplace_back(mesh); std::string meshName = std::string(selectedFrame.frames[groupFrameNum].name); for (std::size_t i = 0; i < meshName.size(); i++) { @@ -374,7 +374,7 @@ class vtkQuakeMDLImporter::vtkInternals } std::pair pair = std::make_pair(frameIndex, selectedFrame.time[groupFrameNum]); - GroupAndTimeVal.push_back(pair); + GroupAndTimeVal.emplace_back(pair); } } } From 9cc1cf972c1fb5249bfeeb354d784af20db73761 Mon Sep 17 00:00:00 2001 From: Youva Boutora <48061964+Youva@users.noreply.github.com> Date: Tue, 24 Sep 2024 15:32:22 -0400 Subject: [PATCH 19/60] Return bool l. 432 --- plugins/native/module/vtkQuakeMDLImporter.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/native/module/vtkQuakeMDLImporter.cxx b/plugins/native/module/vtkQuakeMDLImporter.cxx index a807e7f742..f6ff02bcf8 100644 --- a/plugins/native/module/vtkQuakeMDLImporter.cxx +++ b/plugins/native/module/vtkQuakeMDLImporter.cxx @@ -429,7 +429,7 @@ class vtkQuakeMDLImporter::vtkInternals // Set polyData this->CreateMesh(buffer, offset, header); - return 1; + return true; } void UpdateFrame(double timeValue) From 17a22dddb58822c70d1d89708ad3246fc91ce51a Mon Sep 17 00:00:00 2001 From: Youva Boutora <48061964+Youva@users.noreply.github.com> Date: Tue, 24 Sep 2024 16:52:44 -0400 Subject: [PATCH 20/60] Fix unusedStructMember and containerOutOfBounds --- plugins/native/module/vtkQuakeMDLImporter.cxx | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/plugins/native/module/vtkQuakeMDLImporter.cxx b/plugins/native/module/vtkQuakeMDLImporter.cxx index f6ff02bcf8..a87f21a7fe 100644 --- a/plugins/native/module/vtkQuakeMDLImporter.cxx +++ b/plugins/native/module/vtkQuakeMDLImporter.cxx @@ -87,15 +87,16 @@ class vtkQuakeMDLImporter::vtkInternals // Read textures. struct mdl_skin_t { - int group; /* 0 = single, 1 = group */ - unsigned char* data; /* texture data */ + + //int group; /* 0 = single, 1 = group */ + //unsigned char* data; /* texture data */ }; struct mdl_groupskin_t { - int group; /* 1 = group */ - int nb; /* number of pics */ - float* time; /* time duration for each pic */ - unsigned char** data; /* texture data */ + //int group; /* 1 = group */ + //int nb; /* number of pics */ + //float* time; /* time duration for each pic */ + //unsigned char** data; /* texture data */ }; struct mixed_pointer_array { @@ -177,17 +178,17 @@ class vtkQuakeMDLImporter::vtkInternals }; struct mdl_frame_t { - int type; +// int type; mdl_simpleframe_t frame; }; struct mdl_groupframe_t { - int type; - int nb; +// int type; +// int nb; mdl_vertex_t min; mdl_vertex_t max; - float* time; // Size is nbFrames ??? - mdl_simpleframe_t* frames; // Size is nbFrames ??? +// float* time; // Size is nbFrames ??? +// mdl_simpleframe_t* frames; // Size is nbFrames ??? }; struct plugin_frame_pointer { @@ -449,11 +450,11 @@ class vtkQuakeMDLImporter::vtkInternals // Animations are divided into groups, but stored as a vector of polydata. // This functions set the indices for the first and last frames in the group. std::size_t i = 0; - while (i < GroupAndTimeVal.size() && GroupAndTimeVal[++i].first < animationIndex) + while (i < GroupAndTimeVal.size() - 1 && GroupAndTimeVal[++i].first < animationIndex) { } FirstFrameIndex = animationIndex == 0 ? 0 : LastFrameIndex + 1; - while (i < GroupAndTimeVal.size() && GroupAndTimeVal[++i].first == animationIndex) + while (i < GroupAndTimeVal.size() - 1 && GroupAndTimeVal[++i].first == animationIndex) { } LastFrameIndex = (int)i - 1; From 3bca4a6900666ce5d1a4a5ff10690167cad7ec2a Mon Sep 17 00:00:00 2001 From: Youva Boutora <48061964+Youva@users.noreply.github.com> Date: Tue, 24 Sep 2024 16:58:29 -0400 Subject: [PATCH 21/60] Coding style modification. --- plugins/native/module/vtkQuakeMDLImporter.cxx | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/plugins/native/module/vtkQuakeMDLImporter.cxx b/plugins/native/module/vtkQuakeMDLImporter.cxx index a87f21a7fe..1a1e42ace1 100644 --- a/plugins/native/module/vtkQuakeMDLImporter.cxx +++ b/plugins/native/module/vtkQuakeMDLImporter.cxx @@ -88,15 +88,15 @@ class vtkQuakeMDLImporter::vtkInternals struct mdl_skin_t { - //int group; /* 0 = single, 1 = group */ - //unsigned char* data; /* texture data */ + // int group; /* 0 = single, 1 = group */ + // unsigned char* data; /* texture data */ }; struct mdl_groupskin_t { - //int group; /* 1 = group */ - //int nb; /* number of pics */ - //float* time; /* time duration for each pic */ - //unsigned char** data; /* texture data */ + // int group; /* 1 = group */ + // int nb; /* number of pics */ + // float* time; /* time duration for each pic */ + // unsigned char** data; /* texture data */ }; struct mixed_pointer_array { @@ -178,17 +178,17 @@ class vtkQuakeMDLImporter::vtkInternals }; struct mdl_frame_t { -// int type; + // int type; mdl_simpleframe_t frame; }; struct mdl_groupframe_t { -// int type; -// int nb; + // int type; + // int nb; mdl_vertex_t min; mdl_vertex_t max; -// float* time; // Size is nbFrames ??? -// mdl_simpleframe_t* frames; // Size is nbFrames ??? + // float* time; // Size is nbFrames ??? + // mdl_simpleframe_t* frames; // Size is nbFrames ??? }; struct plugin_frame_pointer { From c67fa7645a4e80bc87c9d1ad74cc79680afe5913 Mon Sep 17 00:00:00 2001 From: Youva Boutora <48061964+Youva@users.noreply.github.com> Date: Tue, 17 Dec 2024 11:48:49 -0500 Subject: [PATCH 22/60] Added unit test --- plugins/native/CMakeLists.txt | 2 +- .../native/configs/config.d/10_native.json | 6 + plugins/native/module/CMakeLists.txt | 3 +- plugins/native/module/Testing/CMakeLists.txt | 10 + .../Testing/TestF3DQuakeMDLImporter.cxx | 23 + .../native/module/vtkF3DQuakeMDLImporter.cxx | 616 +++++++++++++++ ...MDLImporter.h => vtkF3DQuakeMDLImporter.h} | 42 +- .../vtkF3DQuakeMDLImporterConstants.cxx | 132 ++++ .../module/vtkF3DQuakeMDLImporterConstants.h | 7 + plugins/native/module/vtkQuakeMDLImporter.cxx | 731 ------------------ .../native/module/vtkQuakeMDLImporter.cxx.rej | 9 - .../native/module/vtkQuakeMDLImporter.h.rej | 17 - style.diff | 344 --------- testing/baselines/TestQuakeMDL.png | 3 + testing/data/glaunch.mdl | 3 + 15 files changed, 820 insertions(+), 1128 deletions(-) create mode 100644 plugins/native/module/Testing/CMakeLists.txt create mode 100644 plugins/native/module/Testing/TestF3DQuakeMDLImporter.cxx create mode 100644 plugins/native/module/vtkF3DQuakeMDLImporter.cxx rename plugins/native/module/{vtkQuakeMDLImporter.h => vtkF3DQuakeMDLImporter.h} (76%) create mode 100644 plugins/native/module/vtkF3DQuakeMDLImporterConstants.cxx create mode 100644 plugins/native/module/vtkF3DQuakeMDLImporterConstants.h delete mode 100644 plugins/native/module/vtkQuakeMDLImporter.cxx delete mode 100644 plugins/native/module/vtkQuakeMDLImporter.cxx.rej delete mode 100644 plugins/native/module/vtkQuakeMDLImporter.h.rej delete mode 100644 style.diff create mode 100644 testing/baselines/TestQuakeMDL.png create mode 100644 testing/data/glaunch.mdl diff --git a/plugins/native/CMakeLists.txt b/plugins/native/CMakeLists.txt index 49d64fc727..e1829b6278 100644 --- a/plugins/native/CMakeLists.txt +++ b/plugins/native/CMakeLists.txt @@ -190,7 +190,7 @@ f3d_plugin_declare_reader( NAME QuakeMDL EXTENSIONS mdl MIMETYPES application/vnd.mdl - VTK_IMPORTER vtkQuakeMDLImporter + VTK_IMPORTER vtkF3DQuakeMDLImporter FORMAT_DESCRIPTION "Quake 1 MDL model" ) diff --git a/plugins/native/configs/config.d/10_native.json b/plugins/native/configs/config.d/10_native.json index 1ba30fca45..539eeb838c 100644 --- a/plugins/native/configs/config.d/10_native.json +++ b/plugins/native/configs/config.d/10_native.json @@ -67,6 +67,12 @@ "grid": false, "anti-aliasing": false, "translucency-support": false + }, + ".*(mdl)": + { + "up": "+Z", + "camera-direction": "-1,0,0", + "grid": false } } ] diff --git a/plugins/native/module/CMakeLists.txt b/plugins/native/module/CMakeLists.txt index 60a8ca02c0..5d7278c968 100644 --- a/plugins/native/module/CMakeLists.txt +++ b/plugins/native/module/CMakeLists.txt @@ -1,6 +1,7 @@ set(classes vtkF3DSplatReader - vtkQuakeMDLImporter + vtkF3DQuakeMDLImporter + vtkF3DQuakeMDLImporterConstants ) set(_no_install "") diff --git a/plugins/native/module/Testing/CMakeLists.txt b/plugins/native/module/Testing/CMakeLists.txt new file mode 100644 index 0000000000..ffb2b19479 --- /dev/null +++ b/plugins/native/module/Testing/CMakeLists.txt @@ -0,0 +1,10 @@ +set(vtkextNative_list + TestF3DQuakeMDLImporter.cxx + ) + +vtk_add_test_cxx(vtkextNativeTests tests + NO_DATA NO_VALID NO_OUTPUT + ${vtkextNative_list} + ${F3D_SOURCE_DIR}/testing/ ${CMAKE_BINARY_DIR}/Testing/Temporary/) + +vtk_test_cxx_executable(vtkextNativeTests tests) \ No newline at end of file diff --git a/plugins/native/module/Testing/TestF3DQuakeMDLImporter.cxx b/plugins/native/module/Testing/TestF3DQuakeMDLImporter.cxx new file mode 100644 index 0000000000..4078f446e6 --- /dev/null +++ b/plugins/native/module/Testing/TestF3DQuakeMDLImporter.cxx @@ -0,0 +1,23 @@ +#include +#include +#include +#include "vtkF3DQuakeMDLImporter.h" + +#include + +int TestF3DQuakeMDLImporter(int vtkNotUsed(argc), char* argv[]) +{ + std::string filename = std::string(argv[1]) + "data/glaunch.mdl"; + vtkNew importer; + importer->SetFileName(filename); + importer->Update(); + importer->Print(cout); + vtkIdType numAnimations = importer->GetNumberOfAnimations(); + for (int i = 0; i < numAnimations; i++) + { + importer->DisableAnimation(i); + } + vtkIdType selectedAnimationIndex = 1; + importer->EnableAnimation(selectedAnimationIndex); + return numAnimations == 2 ? EXIT_SUCCESS : EXIT_FAILURE; +} \ No newline at end of file diff --git a/plugins/native/module/vtkF3DQuakeMDLImporter.cxx b/plugins/native/module/vtkF3DQuakeMDLImporter.cxx new file mode 100644 index 0000000000..8c7406e170 --- /dev/null +++ b/plugins/native/module/vtkF3DQuakeMDLImporter.cxx @@ -0,0 +1,616 @@ +#include "vtkF3DQuakeMDLImporter.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//---------------------------------------------------------------------------- +vtkStandardNewMacro(vtkF3DQuakeMDLImporter); + +//---------------------------------------------------------------------------- +class vtkF3DQuakeMDLImporter::vtkInternals +{ +public: + //---------------------------------------------------------------------------- + explicit vtkInternals(vtkF3DQuakeMDLImporter* parent) + : Parent(parent) + { + } + + //---------------------------------------------------------------------------- + void ImportCameras(vtkRenderer* vtkNotUsed(renderer)) + { + } + + //---------------------------------------------------------------------------- + void ImportLights(vtkRenderer* vtkNotUsed(renderer)) + { + } + + //---------------------------------------------------------------------------- + vtkSmartPointer CreateTexture(const std::vector buffer, int& offset, + int skinWidth, int skinHeight, int nbSkins, int selectedSkinIndex) + { + vtkNew texture; + texture->InterpolateOn(); + + // Read textures. + struct mixed_pointer_array + { + int group; + unsigned char* skin; + }; + std::vector skins = std::vector(nbSkins); + for (int i = 0; i < nbSkins; i++) + { + int* group = (int*) (buffer.data() + offset); + if (*group == 0) + { + skins[i].group = 0; + skins[i].skin = (unsigned char*) (buffer.data() + 4 + offset); + offset += 4 + (skinWidth) * (skinHeight); + } + else + { + skins[i].group = 1; + int nb = *(int*) (buffer.data() + offset + 4); + skins[i].skin = (unsigned char*) (buffer.data() + 4 + nb * 4 + offset); + offset += 4 + nb * 4 + nb * (skinWidth) * (skinHeight); + } + } + + // Copy to imageData + vtkNew img; + img->SetDimensions(skinWidth, skinHeight, 1); + img->AllocateScalars(VTK_UNSIGNED_CHAR, 3); + unsigned char* selectedSkin = skins[selectedSkinIndex].skin; + for (int i = 0; i < skinHeight; i++) + { + for (int j = 0; j < skinWidth; j++) + { + unsigned char index = *(unsigned char*) (selectedSkin + i * skinWidth + j); + unsigned char* ptr = (unsigned char*) (img->GetScalarPointer(j, i, 0)); + ptr[0] = F3DMDLDefaultColorMap[index][0]; // R + ptr[1] = F3DMDLDefaultColorMap[index][1]; // G + ptr[2] = F3DMDLDefaultColorMap[index][2]; // B + } + } + texture->SetInputData(img); + return texture; + } + + //---------------------------------------------------------------------------- + void CreateMesh(std::vector buffer, int offset, mdl_header_t* header) + { + // Read texture coordinates + struct mdl_texcoord_t + { + int onseam; + int s; + int t; + }; + mdl_texcoord_t* texcoords = (mdl_texcoord_t*) (buffer.data() + offset); + offset += 12 * header->numVertices; + // Read triangles + struct mdl_triangle_t + { + int facesfront; /* 0 = backface, 1 = frontface */ + int vertex[3]; /* vertex indices */ + }; + mdl_triangle_t* triangles = (mdl_triangle_t*) (buffer.data() + offset); + offset += 16 * header->numTriangles; + // Read frames + struct mdl_vertex_t // 4 bytes + { + unsigned char v[3]; + unsigned char normalIndex; + }; + struct mdl_simpleframe_t // 24 + nbVertices bytes + { + mdl_vertex_t bboxmin; + mdl_vertex_t bboxmax; + char name[16]; + mdl_vertex_t verts[1024]; // Maximum capacity is 1024 vertices + }; + struct plugin_frame_pointer + { + int* type; + int* nb; + float* time; + mdl_simpleframe_t* frames; + }; + std::vector framePtr = std::vector(header->numFrames); + for (int i = 0; i < header->numFrames; i++) + { + int* type = (int*) (buffer.data() + offset); + if (*type == 0) + { + framePtr[i].type = type; + framePtr[i].nb = nullptr; + framePtr[i].time = nullptr; + framePtr[i].frames = (mdl_simpleframe_t*) (buffer.data() + 4 + offset); + offset += 4 + 24 + 4 * (header->numVertices); + } + else + { + framePtr[i].type = type; + framePtr[i].nb = (int*) (buffer.data() + 4 + offset); + // mdl_vertex_t* min = reinterpret_cast(buffer.data() + 8 + offset); + // mdl_vertex_t* max = reinterpret_cast(buffer.data() + 12 + offset); + // float* time = framePtr[i].time = reinterpret_cast(buffer.data() + 16 + offset); + framePtr[i].frames = + (mdl_simpleframe_t*) (buffer.data() + 16 + 4 * (*framePtr[i].nb) + offset); + offset += 16 + (*framePtr[i].nb) * 4; + for (int j = 0; j < *framePtr[i].nb; j++) + { + offset += 24 + 4 * header->numVertices; + } + } + } + // Draw cells + vtkNew cells; + cells->Allocate(header->numTriangles); + vtkNew textureCoordinates; + textureCoordinates->SetNumberOfComponents(2); + textureCoordinates->SetName("TextureCoordinates"); + textureCoordinates->Allocate(header->numTriangles * 3); + struct plugin_texture_coords + { + float s; + float t; + int id; + }; + std::vector coords = std::vector(header->numTriangles * 3); + for (int i = 0; i < header->numTriangles; i++) + { + vtkIdType vertexNum[3]; + for (int j = 0; j < 3; j++) + { + vertexNum[j] = triangles[i].vertex[j]; + // int onseam_correct = 1; + float s = texcoords[triangles[i].vertex[j]].s; + float t = texcoords[triangles[i].vertex[j]].t; + if (!triangles[i].facesfront && texcoords[triangles[i].vertex[j]].onseam) + { + s = s + header->skinWidth * 0.5f; + } + s = (s + 0.5) / header->skinWidth; + t = (t + 0.5) / header->skinHeight; + coords[3 * i + j].s = s; + coords[3 * i + j].t = t; + coords[3 * i + j].id = triangles[i].vertex[j]; + float st[2] = { s, t }; + textureCoordinates->InsertNextTuple(st); + } + vtkIdType t[3] = { i * 3, i * 3 + 1, i * 3 + 2 }; + cells->InsertNextCell(3, t); + } + + // Draw vertices + std::string frameName = ""; + int frameIndex = 0; + for (int frameNum = 0; frameNum < header->numFrames; frameNum++) + { + vtkNew vertices; + vertices->Allocate(header->numTriangles * 3); + vtkNew normals; + normals->SetNumberOfComponents(3); + normals->Allocate(header->numTriangles * 3 * 3); + + plugin_frame_pointer selectedFrame = framePtr[frameNum]; + if (*selectedFrame.type == 0) + { + for (int i = 0; i < header->numTriangles; i++) + { + vtkIdType vertexNum[3]; + for (int j = 0; j < 3; j++) + { + vertexNum[j] = triangles[i].vertex[j]; + double v[3] = { double(selectedFrame.frames->verts[vertexNum[j]].v[0]), + double(selectedFrame.frames->verts[vertexNum[j]].v[1]), + double(selectedFrame.frames->verts[vertexNum[j]].v[2]) }; + for (int k = 0; k < 3; k++) + { + v[k] = v[k] * header->scale[k] + header->translation[k]; + } + vertices->InsertPoint(i * 3 + j, v); + int normalIndex = selectedFrame.frames->verts[vertexNum[j]].normalIndex; + normals->SetTuple3(i * 3 + j, F3DMDLNormalVectors[normalIndex][0] / 255.0, + F3DMDLNormalVectors[normalIndex][1] / 255.0, F3DMDLNormalVectors[normalIndex][2] / 255.0); + } + } + vtkNew mesh; + mesh->SetPoints(vertices); + mesh->SetPolys(cells); + mesh->GetPointData()->SetTCoords(textureCoordinates); + // mesh->GetPointData()->SetNormals(normals); + Mesh.emplace_back(mesh); + std::string meshName = std::string(selectedFrame.frames->name); + for (std::size_t i = 0; i < meshName.size(); i++) + { + if (meshName[i] >= '0' && meshName[i] <= '9') + { + meshName = meshName.substr(0, i); + break; + } + } + if (frameNum == 0) + { + frameName = meshName; + NumberOfAnimations++; + AnimationNames.emplace_back(meshName); + } + else if (meshName != frameName) + { + frameIndex++; + frameName = meshName; + NumberOfAnimations++; + AnimationNames.emplace_back(meshName); + } + GroupAndTimeVal.emplace_back(std::make_pair( frameIndex, 0.0 )); + } + else + { + for (int groupFrameNum = 0; groupFrameNum < *selectedFrame.nb; groupFrameNum++) + { + for (int i = 0; i < header->numTriangles; i++) + { + vtkIdType vertexNum[3]; + for (int j = 0; j < 3; j++) + { + vertexNum[j] = triangles[i].vertex[j]; + double v[3] = { double(selectedFrame.frames[groupFrameNum].verts[vertexNum[j]].v[0]), + double(selectedFrame.frames[groupFrameNum].verts[vertexNum[j]].v[1]), + double(selectedFrame.frames[groupFrameNum].verts[vertexNum[j]].v[2]) }; + for (int k = 0; k < 3; k++) + { + v[k] = v[k] * header->scale[k] + header->translation[k]; + } + vertices->InsertPoint(i * 3 + j, v); + int normalIndex = selectedFrame.frames[groupFrameNum].verts[vertexNum[j]].normalIndex; + normals->SetTuple3(i * 3 + j, F3DMDLNormalVectors[normalIndex][0] / 255.0, + F3DMDLNormalVectors[normalIndex][1] / 255.0, F3DMDLNormalVectors[normalIndex][2] / 255.0); + } + } + vtkNew mesh; + mesh->SetPoints(vertices); + mesh->SetPolys(cells); + mesh->GetPointData()->SetTCoords(textureCoordinates); + mesh->GetPointData()->SetNormals(normals); + Mesh.emplace_back(mesh); + std::string meshName = std::string(selectedFrame.frames[groupFrameNum].name); + for (std::size_t i = 0; i < meshName.size(); i++) + { + if (meshName[i] >= '0' && meshName[i] <= '9') + { + meshName = meshName.substr(0, i - 1); + break; + } + } + if (frameNum == 0) + { + frameName = meshName; + NumberOfAnimations++; + AnimationNames.emplace_back(meshName); + } + else if (meshName != frameName) + { + frameIndex++; + NumberOfAnimations++; + AnimationNames.emplace_back(meshName); + frameName = meshName; + } + GroupAndTimeVal.emplace_back(std::make_pair(frameIndex, 0.0)); + } + } + } + + // Add interpolated frames + for (std::size_t i = 0; i < Mesh.size() - 1; i++) + { + if (GroupAndTimeVal[i + 1].first != GroupAndTimeVal[i].first) + { + continue; + } + else + { + vtkNew vertices; + vertices->Allocate(header->numTriangles * 3); + for (int j = 0; j < header->numTriangles * 3; j++) + { + double* v_0 = Mesh[i]->GetPoint(j); + double* v_1 = Mesh[i + 1]->GetPoint(j); + double interp[3]; + interp[0] = v_0[0] + 0.5 * (v_1[0] - v_0[0]); + interp[1] = v_0[1] + 0.5 * (v_1[1] - v_0[1]); + interp[2] = v_0[2] + 0.5 * (v_1[2] - v_0[2]); + vertices->InsertPoint(j, interp); + } + vtkNew mesh; + mesh->SetPoints(vertices); + mesh->SetPolys(cells); + mesh->GetPointData()->SetTCoords(textureCoordinates); + Mesh.insert(Mesh.begin() + i, mesh); + std::pair pair = std::make_pair(GroupAndTimeVal[i].first, + (GroupAndTimeVal[i].second + GroupAndTimeVal[i + 1].second) / 2); + GroupAndTimeVal.insert(GroupAndTimeVal.begin() + i, pair); + i++; + } + } + + } + + //---------------------------------------------------------------------------- + bool ReadScene(const std::string& filePath) + { + std::ifstream inputStream(filePath, std::ios::binary); + std::vector buffer(std::istreambuf_iterator(inputStream), {}); + // Read header + mdl_header_t* header = reinterpret_cast(buffer.data()); + int offset = 84; + + // Set textures + Texture = this->CreateTexture( + buffer, offset, header->skinWidth, header->skinHeight, header->numSkins, 0); + + // Set polyData + this->CreateMesh(buffer, offset, header); + + return true; + } + + //---------------------------------------------------------------------------- + void UpdateTimeStep(double timeValue) + { + float framesToSkip = FrameRate * abs(timeValue - LastRenderTime); + if (framesToSkip >= 1.0) + { + CurrentFrameIndex = (CurrentFrameIndex + 1) % (int)ActiveFrames.size(); + int currentFrame = ActiveFrames[CurrentFrameIndex]; + Mapper->SetInputData(Mesh[currentFrame]); + LastRenderTime = timeValue; + } + } + + //---------------------------------------------------------------------------- + void EnableAnimation(vtkIdType animationIndex) + { + int firstFrameIndex = std::distance(GroupAndTimeVal.begin(), + std::find_if(GroupAndTimeVal.begin(), GroupAndTimeVal.end(), + [animationIndex](const std::pair pair) + { return pair.first == animationIndex; })); + int lastFrameIndex = std::distance(GroupAndTimeVal.begin(), + std::find_if(GroupAndTimeVal.begin(), GroupAndTimeVal.end(), + [animationIndex](const std::pair pair) + { return pair.first > animationIndex; })); + firstFrameIndex = firstFrameIndex <= GroupAndTimeVal.size() ? firstFrameIndex : 0; + lastFrameIndex = + lastFrameIndex <= GroupAndTimeVal.size() ? lastFrameIndex - 1 : lastFrameIndex; + for (int i = firstFrameIndex; i <= lastFrameIndex; i++) + { + ActiveFrames.emplace_back(i); + } + CurrentFrameIndex = 0; + ActiveAnimationId.emplace_back(animationIndex); + } + + //---------------------------------------------------------------------------- + void DisableAnimation(vtkIdType animationIndex) + { + int firstFrameIndex = std::distance(GroupAndTimeVal.begin(), + std::find_if(GroupAndTimeVal.begin(), GroupAndTimeVal.end(), + [animationIndex](const std::pair pair) + { return pair.first == animationIndex; })); + int lastFrameIndex = std::distance(GroupAndTimeVal.begin(), + std::find_if(GroupAndTimeVal.begin(), GroupAndTimeVal.end(), + [animationIndex](const std::pair pair) + { return pair.first > animationIndex; })); + firstFrameIndex = firstFrameIndex <= GroupAndTimeVal.size() ? firstFrameIndex : 0; + lastFrameIndex = lastFrameIndex <= GroupAndTimeVal.size() ? lastFrameIndex - 1 : lastFrameIndex; + for (int i = firstFrameIndex; i <= lastFrameIndex; i++) + { + ActiveFrames.erase(std::remove(ActiveFrames.begin(), ActiveFrames.end(), i), ActiveFrames.end()); + } + CurrentFrameIndex = 0; + ActiveAnimationId.erase( + std::remove(ActiveAnimationId.begin(), ActiveAnimationId.end(), animationIndex), ActiveAnimationId.end()); + } + + //---------------------------------------------------------------------------- + void ImportActors(vtkRenderer* renderer) + { + vtkNew actor; + vtkNew mapper; + mapper->SetInputData(Mesh[0]); + actor->SetMapper(mapper); + actor->SetTexture(Texture); + renderer->AddActor(actor); + renderer->SetBackground(0, 0, 0); + Actor = actor; + Mapper = mapper; + } + + //---------------------------------------------------------------------------- + void SetFrameRate(double frameRate) + { + FrameRate = frameRate; + } + + //---------------------------------------------------------------------------- + void GetTimeRange(vtkIdType animationIndex, double timeRange[2]) + { + int firstFrameIndex = std::distance(GroupAndTimeVal.begin(), + std::find_if(GroupAndTimeVal.begin(), GroupAndTimeVal.end(), [animationIndex](const std::pair pair) { return pair.first == animationIndex; })); + int lastFrameIndex = std::distance(GroupAndTimeVal.begin(), + std::find_if(GroupAndTimeVal.begin(), GroupAndTimeVal.end(), [animationIndex](const std::pair pair) { return pair.first > animationIndex; })); + firstFrameIndex = firstFrameIndex < GroupAndTimeVal.size() ? firstFrameIndex : 0; + lastFrameIndex = lastFrameIndex - 1; + timeRange[0] = GroupAndTimeVal[firstFrameIndex].second <= 0.0 ? (1.0 / FrameRate) * firstFrameIndex : GroupAndTimeVal[firstFrameIndex].second; + timeRange[1] = GroupAndTimeVal[lastFrameIndex].second <= 0.0 ? (1.0 / FrameRate) * (lastFrameIndex + 1) : GroupAndTimeVal[lastFrameIndex].second; + } + + vtkF3DQuakeMDLImporter* Parent; + std::string Description; + vtkSmartPointer Actor; + vtkSmartPointer Mapper; + std::vector> Mesh; + std::vector> GroupAndTimeVal; + std::vector AnimationNames; + std::vector ActiveFrames; + std::vector ActiveAnimationId; + int CurrentFrameIndex = 0; + int NumberOfAnimations = 0; + double LastRenderTime = 0.0; + double FrameRate = 60.0; + vtkSmartPointer Texture; + vtkSmartPointer TextureCoords; +}; + +//---------------------------------------------------------------------------- +vtkF3DQuakeMDLImporter::vtkF3DQuakeMDLImporter() + : Internals(new vtkF3DQuakeMDLImporter::vtkInternals(this)){ + + }; + +//---------------------------------------------------------------------------- +int vtkF3DQuakeMDLImporter::ImportBegin() +{ + return this->Internals->ReadScene(this->FileName); +} + +//---------------------------------------------------------------------------- +void vtkF3DQuakeMDLImporter::ImportActors(vtkRenderer* renderer) +{ + this->Internals->ImportActors(renderer); +} + +//---------------------------------------------------------------------------- +std::string vtkF3DQuakeMDLImporter::GetOutputsDescription() +{ + return this->Internals->Description; +} + +//---------------------------------------------------------------------------- +void vtkF3DQuakeMDLImporter::UpdateTimeStep(double timeValue) +{ + return this->Internals->UpdateTimeStep(timeValue); +} + +//---------------------------------------------------------------------------- +vtkIdType vtkF3DQuakeMDLImporter::GetNumberOfAnimations() +{ + return this->Internals->NumberOfAnimations; +} + +//---------------------------------------------------------------------------- +std::string vtkF3DQuakeMDLImporter::GetAnimationName(vtkIdType animationIndex) +{ + if (animationIndex < (int) this->Internals->AnimationNames.size()) + { + return this->Internals->AnimationNames[animationIndex]; + } + else + { + return ""; + } +} + +//---------------------------------------------------------------------------- +void vtkF3DQuakeMDLImporter::EnableAnimation(vtkIdType animationIndex) +{ + this->Internals->EnableAnimation(animationIndex); +} + +//---------------------------------------------------------------------------- +void vtkF3DQuakeMDLImporter::DisableAnimation(vtkIdType animationIndex) +{ + this->Internals->DisableAnimation(animationIndex); +} + +//---------------------------------------------------------------------------- +bool vtkF3DQuakeMDLImporter::IsAnimationEnabled(vtkIdType animationIndex) +{ + return std::count(this->Internals->ActiveAnimationId.begin(), this->Internals->ActiveAnimationId.end(), animationIndex) > 0; +} + +//---------------------------------------------------------------------------- +bool vtkF3DQuakeMDLImporter::GetTemporalInformation(vtkIdType animationIndex, + double frameRate, int& nbTimeSteps, double timeRange[2], + vtkDoubleArray* vtkNotUsed(timeSteps)) +{ + if ((int) Internals->ActiveFrames.size() > 1) + { + Internals->SetFrameRate(frameRate); + Internals->GetTimeRange(animationIndex, timeRange); + nbTimeSteps = (int)Internals->ActiveFrames.size(); + return true; + } + else + { + return false; + } +} + +//---------------------------------------------------------------------------- +vtkIdType vtkF3DQuakeMDLImporter::GetNumberOfCameras() +{ + return 1; +} + +//---------------------------------------------------------------------------- +std::string vtkF3DQuakeMDLImporter::GetCameraName(vtkIdType vtkNotUsed(camIndex)) +{ + return "Camera"; +} + +//---------------------------------------------------------------------------- +void vtkF3DQuakeMDLImporter::SetCamera(vtkIdType vtkNotUsed(camIndex)) +{ +} + +//---------------------------------------------------------------------------- +void vtkF3DQuakeMDLImporter::ImportCameras(vtkRenderer* renderer) +{ + this->Internals->ImportCameras(renderer); +} + +//---------------------------------------------------------------------------- +void vtkF3DQuakeMDLImporter::ImportLights(vtkRenderer* renderer) +{ + this->Internals->ImportLights(renderer); +} + +//---------------------------------------------------------------------------- +void vtkF3DQuakeMDLImporter::PrintSelf(ostream& vtkNotUsed(os), vtkIndent vtkNotUsed(indent)) +{ +} diff --git a/plugins/native/module/vtkQuakeMDLImporter.h b/plugins/native/module/vtkF3DQuakeMDLImporter.h similarity index 76% rename from plugins/native/module/vtkQuakeMDLImporter.h rename to plugins/native/module/vtkF3DQuakeMDLImporter.h index c18d51543d..9f0e3edcde 100644 --- a/plugins/native/module/vtkQuakeMDLImporter.h +++ b/plugins/native/module/vtkF3DQuakeMDLImporter.h @@ -1,17 +1,18 @@ /** - * @class vtkQuakeMDLImporter - * @brief VTK Importer for Quake 1 models in binary .mdl file format + * @class vtkF3DQuakeMDLImporter + * @brief VTK Importer for Quake 1 models in .mdl file format */ -#ifndef vtkQuakeMDLImporter_h -#define vtkQuakeMDLImporter_h +#ifndef vtkF3DQuakeMDLImporter_h +#define vtkF3DQuakeMDLImporter_h #include +#include "vtkF3DQuakeMDLImporterConstants.h" -class vtkQuakeMDLImporter : public vtkImporter +class vtkF3DQuakeMDLImporter : public vtkImporter { public: - static vtkQuakeMDLImporter* New(); - vtkTypeMacro(vtkQuakeMDLImporter, vtkImporter); + static vtkF3DQuakeMDLImporter* New(); + //vtkTypeMacro(vtkF3DQuakeMDLImporter, vtkImporter); void PrintSelf(ostream& os, vtkIndent indent) override; @@ -54,13 +55,7 @@ class vtkQuakeMDLImporter : public vtkImporter */ std::string GetOutputsDescription() override; - ///@{ - /** - * Set/Get collada fixup flag. - */ - vtkSetMacro(ColladaFixup, bool); - vtkGetMacro(ColladaFixup, bool); - ///@} + /** * Get temporal information for the currently enabled animation. @@ -86,8 +81,8 @@ class vtkQuakeMDLImporter : public vtkImporter void SetCamera(vtkIdType camIndex) override; protected: - vtkQuakeMDLImporter(); - ~vtkQuakeMDLImporter() override = default; + vtkF3DQuakeMDLImporter(); + ~vtkF3DQuakeMDLImporter() override = default; int ImportBegin() override; void ImportActors(vtkRenderer*) override; @@ -114,20 +109,17 @@ class vtkQuakeMDLImporter : public vtkImporter float size; }; - ///@{ - /** - * Set/Get the file name. - */ - ///@} - std::string FileName; - bool ColladaFixup = false; private: - vtkQuakeMDLImporter(const vtkQuakeMDLImporter&) = delete; - void operator=(const vtkQuakeMDLImporter&) = delete; + vtkF3DQuakeMDLImporter(const vtkF3DQuakeMDLImporter&) = delete; + void operator=(const vtkF3DQuakeMDLImporter&) = delete; class vtkInternals; + std::string FileName; + std::unique_ptr Internals; + }; + #endif diff --git a/plugins/native/module/vtkF3DQuakeMDLImporterConstants.cxx b/plugins/native/module/vtkF3DQuakeMDLImporterConstants.cxx new file mode 100644 index 0000000000..ec4b6c1ea3 --- /dev/null +++ b/plugins/native/module/vtkF3DQuakeMDLImporterConstants.cxx @@ -0,0 +1,132 @@ +#include "vtkF3DQuakeMDLImporterConstants.h" + +const unsigned char F3DMDLDefaultColorMap[256][3] = { { 0, 0, 0 }, { 15, 15, 15 }, { 31, 31, 31 }, + { 47, 47, 47 }, { 63, 63, 63 }, { 75, 75, 75 }, { 91, 91, 91 }, { 107, 107, 107 }, + { 123, 123, 123 }, { 139, 139, 139 }, { 155, 155, 155 }, { 171, 171, 171 }, { 187, 187, 187 }, + { 203, 203, 203 }, { 219, 219, 219 }, { 235, 235, 235 }, { 15, 11, 7 }, { 23, 15, 11 }, + { 31, 23, 11 }, { 39, 27, 15 }, { 47, 35, 19 }, { 55, 43, 23 }, { 63, 47, 23 }, { 75, 55, 27 }, + { 83, 59, 27 }, { 91, 67, 31 }, { 99, 75, 31 }, { 107, 83, 31 }, { 115, 87, 31 }, + { 123, 95, 35 }, { 131, 103, 35 }, { 143, 111, 35 }, { 11, 11, 15 }, { 19, 19, 27 }, + { 27, 27, 39 }, { 39, 39, 51 }, { 47, 47, 63 }, { 55, 55, 75 }, { 63, 63, 87 }, { 71, 71, 103 }, + { 79, 79, 115 }, { 91, 91, 127 }, { 99, 99, 139 }, { 107, 107, 151 }, { 115, 115, 163 }, + { 123, 123, 175 }, { 131, 131, 187 }, { 139, 139, 203 }, { 0, 0, 0 }, { 7, 7, 0 }, + { 11, 11, 0 }, { 19, 19, 0 }, { 27, 27, 0 }, { 35, 35, 0 }, { 43, 43, 7 }, { 47, 47, 7 }, + { 55, 55, 7 }, { 63, 63, 7 }, { 71, 71, 7 }, { 75, 75, 11 }, { 83, 83, 11 }, { 91, 91, 11 }, + { 99, 99, 11 }, { 107, 107, 15 }, { 7, 0, 0 }, { 15, 0, 0 }, { 23, 0, 0 }, { 31, 0, 0 }, + { 39, 0, 0 }, { 47, 0, 0 }, { 55, 0, 0 }, { 63, 0, 0 }, { 71, 0, 0 }, { 79, 0, 0 }, + { 87, 0, 0 }, { 95, 0, 0 }, { 103, 0, 0 }, { 111, 0, 0 }, { 119, 0, 0 }, { 127, 0, 0 }, + { 19, 19, 0 }, { 27, 27, 0 }, { 35, 35, 0 }, { 47, 43, 0 }, { 55, 47, 0 }, { 67, 55, 0 }, + { 75, 59, 7 }, { 87, 67, 7 }, { 95, 71, 7 }, { 107, 75, 11 }, { 119, 83, 15 }, { 131, 87, 19 }, + { 139, 91, 19 }, { 151, 95, 27 }, { 163, 99, 31 }, { 175, 103, 35 }, { 35, 19, 7 }, + { 47, 23, 11 }, { 59, 31, 15 }, { 75, 35, 19 }, { 87, 43, 23 }, { 99, 47, 31 }, { 115, 55, 35 }, + { 127, 59, 43 }, { 143, 67, 51 }, { 159, 79, 51 }, { 175, 99, 47 }, { 191, 119, 47 }, + { 207, 143, 43 }, { 223, 171, 39 }, { 239, 203, 31 }, { 255, 243, 27 }, { 11, 7, 0 }, + { 27, 19, 0 }, { 43, 35, 15 }, { 55, 43, 19 }, { 71, 51, 27 }, { 83, 55, 35 }, { 99, 63, 43 }, + { 111, 71, 51 }, { 127, 83, 63 }, { 139, 95, 71 }, { 155, 107, 83 }, { 167, 123, 95 }, + { 183, 135, 107 }, { 195, 147, 123 }, { 211, 163, 139 }, { 227, 179, 151 }, { 171, 139, 163 }, + { 159, 127, 151 }, { 147, 115, 135 }, { 139, 103, 123 }, { 127, 91, 111 }, { 119, 83, 99 }, + { 107, 75, 87 }, { 95, 63, 75 }, { 87, 55, 67 }, { 75, 47, 55 }, { 67, 39, 47 }, { 55, 31, 35 }, + { 43, 23, 27 }, { 35, 19, 19 }, { 23, 11, 11 }, { 15, 7, 7 }, { 187, 115, 159 }, + { 175, 107, 143 }, { 163, 95, 131 }, { 151, 87, 119 }, { 139, 79, 107 }, { 127, 75, 95 }, + { 115, 67, 83 }, { 107, 59, 75 }, { 95, 51, 63 }, { 83, 43, 55 }, { 71, 35, 43 }, + { 59, 31, 35 }, { 47, 23, 27 }, { 35, 19, 19 }, { 23, 11, 11 }, { 15, 7, 7 }, { 219, 195, 187 }, + { 203, 179, 167 }, { 191, 163, 155 }, { 175, 151, 139 }, { 163, 135, 123 }, { 151, 123, 111 }, + { 135, 111, 95 }, { 123, 99, 83 }, { 107, 87, 71 }, { 95, 75, 59 }, { 83, 63, 51 }, + { 67, 51, 39 }, { 55, 43, 31 }, { 39, 31, 23 }, { 27, 19, 15 }, { 15, 11, 7 }, + { 111, 131, 123 }, { 103, 123, 111 }, { 95, 115, 103 }, { 87, 107, 95 }, { 79, 99, 87 }, + { 71, 91, 79 }, { 63, 83, 71 }, { 55, 75, 63 }, { 47, 67, 55 }, { 43, 59, 47 }, { 35, 51, 39 }, + { 31, 43, 31 }, { 23, 35, 23 }, { 15, 27, 19 }, { 11, 19, 11 }, { 7, 11, 7 }, { 255, 243, 27 }, + { 239, 223, 23 }, { 219, 203, 19 }, { 203, 183, 15 }, { 187, 167, 15 }, { 171, 151, 11 }, + { 155, 131, 7 }, { 139, 115, 7 }, { 123, 99, 7 }, { 107, 83, 0 }, { 91, 71, 0 }, { 75, 55, 0 }, + { 59, 43, 0 }, { 43, 31, 0 }, { 27, 15, 0 }, { 11, 7, 0 }, { 0, 0, 255 }, { 11, 11, 239 }, + { 19, 19, 223 }, { 27, 27, 207 }, { 35, 35, 191 }, { 43, 43, 175 }, { 47, 47, 159 }, + { 47, 47, 143 }, { 47, 47, 127 }, { 47, 47, 111 }, { 47, 47, 95 }, { 43, 43, 79 }, + { 35, 35, 63 }, { 27, 27, 47 }, { 19, 19, 31 }, { 11, 11, 15 }, { 43, 0, 0 }, { 59, 0, 0 }, + { 75, 7, 0 }, { 95, 7, 0 }, { 111, 15, 0 }, { 127, 23, 7 }, { 147, 31, 7 }, { 163, 39, 11 }, + { 183, 51, 15 }, { 195, 75, 27 }, { 207, 99, 43 }, { 219, 127, 59 }, { 227, 151, 79 }, + { 231, 171, 95 }, { 239, 191, 119 }, { 247, 211, 139 }, { 167, 123, 59 }, { 183, 155, 55 }, + { 199, 195, 55 }, { 231, 227, 87 }, { 127, 191, 255 }, { 171, 231, 255 }, { 215, 255, 255 }, + { 103, 0, 0 }, { 139, 0, 0 }, { 179, 0, 0 }, { 215, 0, 0 }, { 255, 0, 0 }, { 255, 243, 147 }, + { 255, 247, 199 }, { 255, 255, 255 }, { 159, 91, 83 } }; +const float F3DMDLNormalVectors[162][3] = { { -0.525731f, 0.000000f, 0.850651f }, + { -0.442863f, 0.238856f, 0.864188f }, { -0.295242f, 0.000000f, 0.955423f }, + { -0.309017f, 0.500000f, 0.809017f }, { -0.162460f, 0.262866f, 0.951056f }, + { 0.000000f, 0.000000f, 1.000000f }, { 0.000000f, 0.850651f, 0.525731f }, + { -0.147621f, 0.716567f, 0.681718f }, { 0.147621f, 0.716567f, 0.681718f }, + { 0.000000f, 0.525731f, 0.850651f }, { 0.309017f, 0.500000f, 0.809017f }, + { 0.525731f, 0.000000f, 0.850651f }, { 0.295242f, 0.000000f, 0.955423f }, + { 0.442863f, 0.238856f, 0.864188f }, { 0.162460f, 0.262866f, 0.951056f }, + { -0.681718f, 0.147621f, 0.716567f }, { -0.809017f, 0.309017f, 0.500000f }, + { -0.587785f, 0.425325f, 0.688191f }, { -0.850651f, 0.525731f, 0.000000f }, + { -0.864188f, 0.442863f, 0.238856f }, { -0.716567f, 0.681718f, 0.147621f }, + { -0.688191f, 0.587785f, 0.425325f }, { -0.500000f, 0.809017f, 0.309017f }, + { -0.238856f, 0.864188f, 0.442863f }, { -0.425325f, 0.688191f, 0.587785f }, + { -0.716567f, 0.681718f, -0.147621f }, { -0.500000f, 0.809017f, -0.309017f }, + { -0.525731f, 0.850651f, 0.000000f }, { 0.000000f, 0.850651f, -0.525731f }, + { -0.238856f, 0.864188f, -0.442863f }, { 0.000000f, 0.955423f, -0.295242f }, + { -0.262866f, 0.951056f, -0.162460f }, { 0.000000f, 1.000000f, 0.000000f }, + { 0.000000f, 0.955423f, 0.295242f }, { -0.262866f, 0.951056f, 0.162460f }, + { 0.238856f, 0.864188f, 0.442863f }, { 0.262866f, 0.951056f, 0.162460f }, + { 0.500000f, 0.809017f, 0.309017f }, { 0.238856f, 0.864188f, -0.442863f }, + { 0.262866f, 0.951056f, -0.162460f }, { 0.500000f, 0.809017f, -0.309017f }, + { 0.850651f, 0.525731f, 0.000000f }, { 0.716567f, 0.681718f, 0.147621f }, + { 0.716567f, 0.681718f, -0.147621f }, { 0.525731f, 0.850651f, 0.000000f }, + { 0.425325f, 0.688191f, 0.587785f }, { 0.864188f, 0.442863f, 0.238856f }, + { 0.688191f, 0.587785f, 0.425325f }, { 0.809017f, 0.309017f, 0.500000f }, + { 0.681718f, 0.147621f, 0.716567f }, { 0.587785f, 0.425325f, 0.688191f }, + { 0.955423f, 0.295242f, 0.000000f }, { 1.000000f, 0.000000f, 0.000000f }, + { 0.951056f, 0.162460f, 0.262866f }, { 0.850651f, -0.525731f, 0.000000f }, + { 0.955423f, -0.295242f, 0.000000f }, { 0.864188f, -0.442863f, 0.238856f }, + { 0.951056f, -0.162460f, 0.262866f }, { 0.809017f, -0.309017f, 0.500000f }, + { 0.681718f, -0.147621f, 0.716567f }, { 0.850651f, 0.000000f, 0.525731f }, + { 0.864188f, 0.442863f, -0.238856f }, { 0.809017f, 0.309017f, -0.500000f }, + { 0.951056f, 0.162460f, -0.262866f }, { 0.525731f, 0.000000f, -0.850651f }, + { 0.681718f, 0.147621f, -0.716567f }, { 0.681718f, -0.147621f, -0.716567f }, + { 0.850651f, 0.000000f, -0.525731f }, { 0.809017f, -0.309017f, -0.500000f }, + { 0.864188f, -0.442863f, -0.238856f }, { 0.951056f, -0.162460f, -0.262866f }, + { 0.147621f, 0.716567f, -0.681718f }, { 0.309017f, 0.500000f, -0.809017f }, + { 0.425325f, 0.688191f, -0.587785f }, { 0.442863f, 0.238856f, -0.864188f }, + { 0.587785f, 0.425325f, -0.688191f }, { 0.688191f, 0.587785f, -0.425325f }, + { -0.147621f, 0.716567f, -0.681718f }, { -0.309017f, 0.500000f, -0.809017f }, + { 0.000000f, 0.525731f, -0.850651f }, { -0.525731f, 0.000000f, -0.850651f }, + { -0.442863f, 0.238856f, -0.864188f }, { -0.295242f, 0.000000f, -0.955423f }, + { -0.162460f, 0.262866f, -0.951056f }, { 0.000000f, 0.000000f, -1.000000f }, + { 0.295242f, 0.000000f, -0.955423f }, { 0.162460f, 0.262866f, -0.951056f }, + { -0.442863f, -0.238856f, -0.864188f }, { -0.309017f, -0.500000f, -0.809017f }, + { -0.162460f, -0.262866f, -0.951056f }, { 0.000000f, -0.850651f, -0.525731f }, + { -0.147621f, -0.716567f, -0.681718f }, { 0.147621f, -0.716567f, -0.681718f }, + { 0.000000f, -0.525731f, -0.850651f }, { 0.309017f, -0.500000f, -0.809017f }, + { 0.442863f, -0.238856f, -0.864188f }, { 0.162460f, -0.262866f, -0.951056f }, + { 0.238856f, -0.864188f, -0.442863f }, { 0.500000f, -0.809017f, -0.309017f }, + { 0.425325f, -0.688191f, -0.587785f }, { 0.716567f, -0.681718f, -0.147621f }, + { 0.688191f, -0.587785f, -0.425325f }, { 0.587785f, -0.425325f, -0.688191f }, + { 0.000000f, -0.955423f, -0.295242f }, { 0.000000f, -1.000000f, 0.000000f }, + { 0.262866f, -0.951056f, -0.162460f }, { 0.000000f, -0.850651f, 0.525731f }, + { 0.000000f, -0.955423f, 0.295242f }, { 0.238856f, -0.864188f, 0.442863f }, + { 0.262866f, -0.951056f, 0.162460f }, { 0.500000f, -0.809017f, 0.309017f }, + { 0.716567f, -0.681718f, 0.147621f }, { 0.525731f, -0.850651f, 0.000000f }, + { -0.238856f, -0.864188f, -0.442863f }, { -0.500000f, -0.809017f, -0.309017f }, + { -0.262866f, -0.951056f, -0.162460f }, { -0.850651f, -0.525731f, 0.000000f }, + { -0.716567f, -0.681718f, -0.147621f }, { -0.716567f, -0.681718f, 0.147621f }, + { -0.525731f, -0.850651f, 0.000000f }, { -0.500000f, -0.809017f, 0.309017f }, + { -0.238856f, -0.864188f, 0.442863f }, { -0.262866f, -0.951056f, 0.162460f }, + { -0.864188f, -0.442863f, 0.238856f }, { -0.809017f, -0.309017f, 0.500000f }, + { -0.688191f, -0.587785f, 0.425325f }, { -0.681718f, -0.147621f, 0.716567f }, + { -0.442863f, -0.238856f, 0.864188f }, { -0.587785f, -0.425325f, 0.688191f }, + { -0.309017f, -0.500000f, 0.809017f }, { -0.147621f, -0.716567f, 0.681718f }, + { -0.425325f, -0.688191f, 0.587785f }, { -0.162460f, -0.262866f, 0.951056f }, + { 0.442863f, -0.238856f, 0.864188f }, { 0.162460f, -0.262866f, 0.951056f }, + { 0.309017f, -0.500000f, 0.809017f }, { 0.147621f, -0.716567f, 0.681718f }, + { 0.000000f, -0.525731f, 0.850651f }, { 0.425325f, -0.688191f, 0.587785f }, + { 0.587785f, -0.425325f, 0.688191f }, { 0.688191f, -0.587785f, 0.425325f }, + { -0.955423f, 0.295242f, 0.000000f }, { -0.951056f, 0.162460f, 0.262866f }, + { -1.000000f, 0.000000f, 0.000000f }, { -0.850651f, 0.000000f, 0.525731f }, + { -0.955423f, -0.295242f, 0.000000f }, { -0.951056f, -0.162460f, 0.262866f }, + { -0.864188f, 0.442863f, -0.238856f }, { -0.951056f, 0.162460f, -0.262866f }, + { -0.809017f, 0.309017f, -0.500000f }, { -0.864188f, -0.442863f, -0.238856f }, + { -0.951056f, -0.162460f, -0.262866f }, { -0.809017f, -0.309017f, -0.500000f }, + { -0.681718f, 0.147621f, -0.716567f }, { -0.681718f, -0.147621f, -0.716567f }, + { -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 } }; diff --git a/plugins/native/module/vtkF3DQuakeMDLImporterConstants.h b/plugins/native/module/vtkF3DQuakeMDLImporterConstants.h new file mode 100644 index 0000000000..befa221430 --- /dev/null +++ b/plugins/native/module/vtkF3DQuakeMDLImporterConstants.h @@ -0,0 +1,7 @@ +#ifndef vtkF3DQuakeMDLImporterConstants_h +#define vtkF3DQuakeMDLImporterConstants_h + +extern const unsigned char F3DMDLDefaultColorMap[256][3]; +extern const float F3DMDLNormalVectors[162][3]; + +#endif diff --git a/plugins/native/module/vtkQuakeMDLImporter.cxx b/plugins/native/module/vtkQuakeMDLImporter.cxx deleted file mode 100644 index 1a1e42ace1..0000000000 --- a/plugins/native/module/vtkQuakeMDLImporter.cxx +++ /dev/null @@ -1,731 +0,0 @@ -#include "vtkQuakeMDLImporter.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -//---------------------------------------------------------------------------- -vtkStandardNewMacro(vtkQuakeMDLImporter); - -class vtkQuakeMDLImporter::vtkInternals -{ -public: - //---------------------------------------------------------------------------- - explicit vtkInternals(vtkQuakeMDLImporter* parent) - : Parent(parent) - { - } - - //---------------------------------------------------------------------------- - void ImportCameras(vtkRenderer* renderer) - { - double cameraPosition[3] = { 50.0, 15.0, 0.0 }; - vtkNew roll; - roll->RotateX(270); - roll->RotateZ(270); - renderer->GetActiveCamera()->SetPosition(cameraPosition); - renderer->GetActiveCamera()->SetModelTransformMatrix(roll->GetMatrix()); - } - - //---------------------------------------------------------------------------- - void ImportLights(vtkRenderer* renderer) - { - // Adds 3 lights, there's already one on the right side. - - vtkNew frontLight; - double frontLightPosition[3] = { 50.0, 50.0, 0.0 }; - frontLight->SetPosition(frontLightPosition); - vtkNew leftLight; - double leftLightPosition[3] = { 50.0, -50.0, 0.0 }; - leftLight->SetPosition(leftLightPosition); - vtkNew backLight; - double backLightPosition[3] = { -50.0, 0.0, 0.0 }; - backLight->SetPosition(backLightPosition); - - renderer->AddLight(frontLight); - renderer->AddLight(leftLight); - renderer->AddLight(backLight); - } - - //---------------------------------------------------------------------------- - vtkSmartPointer CreateTexture(std::vector buffer, int& offset, - int skinWidth, int skinHeight, int nbSkins, int selectedSkinIndex) - { - vtkNew texture; - texture->InterpolateOn(); - - // Read textures. - struct mdl_skin_t - { - - // int group; /* 0 = single, 1 = group */ - // unsigned char* data; /* texture data */ - }; - struct mdl_groupskin_t - { - // int group; /* 1 = group */ - // int nb; /* number of pics */ - // float* time; /* time duration for each pic */ - // unsigned char** data; /* texture data */ - }; - struct mixed_pointer_array - { - int group; - unsigned char* skin; - }; - mixed_pointer_array* skins = new mixed_pointer_array[nbSkins]; - // unsigned char* skin = buffer.data() + offset + 4; - for (int i = 0; i < nbSkins; i++) - { - int* group = reinterpret_cast(buffer.data() + offset); - if (*group == 0) - { - skins[i].group = 0; - skins[i].skin = reinterpret_cast(buffer.data() + 4 + offset); - offset += 4 + (skinWidth) * (skinHeight); - } - else - { - skins[i].group = 1; - int nb = *reinterpret_cast(buffer.data() + offset + 4); - skins[i].skin = reinterpret_cast(buffer.data() + 4 + nb * 4 + offset); - offset += 4 + nb * 4 + nb * (skinWidth) * (skinHeight); - } - } - - // Copy to imageData - vtkNew img; - img->SetDimensions(skinWidth, skinHeight, 1); - img->AllocateScalars(VTK_UNSIGNED_CHAR, 3); - unsigned char* selectedSkin = skins[selectedSkinIndex].skin; - for (int i = 0; i < skinHeight; i++) - { - for (int j = 0; j < skinWidth; j++) - { - unsigned char index = *reinterpret_cast(selectedSkin + i * skinWidth + j); - unsigned char* ptr = reinterpret_cast(img->GetScalarPointer(j, i, 0)); - ptr[0] = DefaultColorMap[index][0]; // R - ptr[1] = DefaultColorMap[index][1]; // G - ptr[2] = DefaultColorMap[index][2]; // B - } - } - - texture->SetInputData(img); - return texture; - } - - void CreateMesh(std::vector buffer, int offset, mdl_header_t* header) - { - // Read texture coordinates - struct mdl_texcoord_t - { - int onseam; - int s; - int t; - }; - mdl_texcoord_t* texcoords = reinterpret_cast(buffer.data() + offset); - offset += 12 * header->numVertices; - // Read triangles - struct mdl_triangle_t - { - int facesfront; /* 0 = backface, 1 = frontface */ - int vertex[3]; /* vertex indices */ - }; - mdl_triangle_t* triangles = reinterpret_cast(buffer.data() + offset); - offset += 16 * header->numTriangles; - // Read frames - struct mdl_vertex_t // 4 bytes - { - unsigned char v[3]; - unsigned char normalIndex; - }; - struct mdl_simpleframe_t // 24 + nbVertices bytes - { - mdl_vertex_t bboxmin; - mdl_vertex_t bboxmax; - char name[16]; - mdl_vertex_t verts[1024]; // Maximum capacity is 1024 vertices - }; - struct mdl_frame_t - { - // int type; - mdl_simpleframe_t frame; - }; - struct mdl_groupframe_t - { - // int type; - // int nb; - mdl_vertex_t min; - mdl_vertex_t max; - // float* time; // Size is nbFrames ??? - // mdl_simpleframe_t* frames; // Size is nbFrames ??? - }; - struct plugin_frame_pointer - { - int* type; - int* nb; - float* time; - mdl_simpleframe_t* frames; - }; - plugin_frame_pointer* framePtr = new plugin_frame_pointer[header->numFrames]; - for (int i = 0; i < header->numFrames; i++) - { - int* type = reinterpret_cast(buffer.data() + offset); - if (*type == 0) - { - framePtr[i].type = type; - framePtr[i].nb = nullptr; - framePtr[i].time = nullptr; - framePtr[i].frames = reinterpret_cast(buffer.data() + 4 + offset); - offset += 4 + 24 + 4 * (header->numVertices); - } - else - { - framePtr[i].type = type; - framePtr[i].nb = reinterpret_cast(buffer.data() + 4 + offset); - // mdl_vertex_t* min = reinterpret_cast(buffer.data() + 8 + offset); - // mdl_vertex_t* max = reinterpret_cast(buffer.data() + 12 + offset); - // float* time = framePtr[i].time = reinterpret_cast(buffer.data() + 16 + offset); - framePtr[i].frames = - reinterpret_cast(buffer.data() + 16 + 4 * (*framePtr[i].nb) + offset); - offset += 16 + (*framePtr[i].nb) * 4; - for (int j = 0; j < *framePtr[i].nb; j++) - { - offset += 24 + 4 * header->numVertices; - } - } - } - // Draw cells - vtkNew cells; - cells->Allocate(header->numTriangles); - vtkNew textureCoordinates; - textureCoordinates->SetNumberOfComponents(2); - textureCoordinates->SetName("TextureCoordinates"); - textureCoordinates->Allocate(header->numTriangles * 3); - struct plugin_texture_coords - { - float s; - float t; - int id; - }; - plugin_texture_coords* coords = new plugin_texture_coords[header->numTriangles * 3]; - for (int i = 0; i < header->numTriangles; i++) - { - vtkIdType* vertexNum = new vtkIdType[3]; - for (int j = 0; j < 3; j++) - { - vertexNum[j] = triangles[i].vertex[j]; - // int onseam_correct = 1; - float s = texcoords[triangles[i].vertex[j]].s; - float t = texcoords[triangles[i].vertex[j]].t; - if (!triangles[i].facesfront && texcoords[triangles[i].vertex[j]].onseam) - { - s = s + header->skinWidth * 0.5f; - } - s = (s + 0.5) / header->skinWidth; - t = (t + 0.5) / header->skinHeight; - coords[3 * i + j].s = s; - coords[3 * i + j].t = t; - coords[3 * i + j].id = triangles[i].vertex[j]; - float st[2] = { s, t }; - textureCoordinates->InsertNextTuple(st); - } - vtkIdType t[3] = { i * 3, i * 3 + 1, i * 3 + 2 }; - cells->InsertNextCell(3, t); - } - - // Draw vertices - std::string frameName = ""; - int frameIndex = 0; - for (int frameNum = 0; frameNum < header->numFrames; frameNum++) - { - vtkNew vertices; - vertices->Allocate(header->numTriangles * 3); - vtkNew normals; - normals->SetNumberOfComponents(3); - normals->Allocate(header->numTriangles * 3 * 3); - - plugin_frame_pointer selectedFrame = framePtr[frameNum]; - if (*selectedFrame.type == 0) - { - for (int i = 0; i < header->numTriangles; i++) - { - vtkIdType* vertexNum = new vtkIdType[3]; - for (int j = 0; j < 3; j++) - { - vertexNum[j] = triangles[i].vertex[j]; - double v[3] = { double(selectedFrame.frames->verts[vertexNum[j]].v[0]), - double(selectedFrame.frames->verts[vertexNum[j]].v[1]), - double(selectedFrame.frames->verts[vertexNum[j]].v[2]) }; - for (int k = 0; k < 3; k++) - { - v[k] = v[k] * header->scale[k] + header->translation[k]; - } - vertices->InsertPoint(i * 3 + j, v); - int normalIndex = selectedFrame.frames->verts[vertexNum[j]].normalIndex; - normals->SetTuple3(i * 3 + j, NormalVectors[normalIndex][0] / 255.0, - NormalVectors[normalIndex][1] / 255.0, NormalVectors[normalIndex][2] / 255.0); - } - } - vtkNew mesh; - mesh->SetPoints(vertices); - mesh->SetPolys(cells); - mesh->GetPointData()->SetTCoords(textureCoordinates); - // mesh->GetPointData()->SetNormals(normals); - Mesh.emplace_back(mesh); - std::string meshName = std::string(selectedFrame.frames->name); - for (std::size_t i = 0; i < meshName.size(); i++) - { - if (meshName[i] >= '0' && meshName[i] <= '9') - { - meshName = meshName.substr(0, i); - break; - } - } - if (frameNum == 0) - { - frameName = meshName; - } - else if (meshName != frameName) - { - frameIndex++; - frameName = meshName; - NumberOfAnimations++; - } - std::pair pair = std::make_pair(frameIndex, 0.0); - GroupAndTimeVal.emplace_back(pair); - } - else - { - for (int groupFrameNum = 0; groupFrameNum < *selectedFrame.nb; groupFrameNum++) - { - for (int i = 0; i < header->numTriangles; i++) - { - vtkIdType* vertexNum = new vtkIdType[3]; - for (int j = 0; j < 3; j++) - { - vertexNum[j] = triangles[i].vertex[j]; - double v[3] = { double(selectedFrame.frames[groupFrameNum].verts[vertexNum[j]].v[0]), - double(selectedFrame.frames[groupFrameNum].verts[vertexNum[j]].v[1]), - double(selectedFrame.frames[groupFrameNum].verts[vertexNum[j]].v[2]) }; - for (int k = 0; k < 3; k++) - { - v[k] = v[k] * header->scale[k] + header->translation[k]; - } - vertices->InsertPoint(i * 3 + j, v); - int normalIndex = selectedFrame.frames[groupFrameNum].verts[vertexNum[j]].normalIndex; - normals->SetTuple3(i * 3 + j, NormalVectors[normalIndex][0] / 255.0, - NormalVectors[normalIndex][1] / 255.0, NormalVectors[normalIndex][2] / 255.0); - } - } - vtkNew mesh; - mesh->SetPoints(vertices); - mesh->SetPolys(cells); - mesh->GetPointData()->SetTCoords(textureCoordinates); - mesh->GetPointData()->SetNormals(normals); - Mesh.emplace_back(mesh); - std::string meshName = std::string(selectedFrame.frames[groupFrameNum].name); - for (std::size_t i = 0; i < meshName.size(); i++) - { - if (meshName[i] >= '0' && meshName[i] <= '9') - { - meshName = meshName.substr(0, i - 1); - break; - } - } - if (frameNum == 0) - { - frameName = meshName; - } - else if (meshName != frameName) - { - frameIndex++; - NumberOfAnimations++; - frameName = meshName; - } - std::pair pair = - std::make_pair(frameIndex, selectedFrame.time[groupFrameNum]); - GroupAndTimeVal.emplace_back(pair); - } - } - } - - // Add interpolated frames - for (std::size_t i = 0; i < Mesh.size() - 1; i++) - { - if (GroupAndTimeVal[i + 1].first != GroupAndTimeVal[i].first) - { - continue; - } - else - { - vtkNew vertices; - vertices->Allocate(header->numTriangles * 3); - for (int j = 0; j < header->numTriangles * 3; j++) - { - double* v_0 = Mesh[i]->GetPoint(j); - double* v_1 = Mesh[i + 1]->GetPoint(j); - double* interp = new double[3]; - interp[0] = v_0[0] + 0.5 * (v_1[0] - v_0[0]); - interp[1] = v_0[1] + 0.5 * (v_1[1] - v_0[1]); - interp[2] = v_0[2] + 0.5 * (v_1[2] - v_0[2]); - vertices->InsertPoint(j, interp); - } - vtkNew mesh; - mesh->SetPoints(vertices); - mesh->SetPolys(cells); - mesh->GetPointData()->SetTCoords(textureCoordinates); - Mesh.insert(Mesh.begin() + i, mesh); - std::pair pair = std::make_pair(GroupAndTimeVal[i].first, - (GroupAndTimeVal[i].second + GroupAndTimeVal[i + 1].second) / 2); - GroupAndTimeVal.insert(GroupAndTimeVal.begin() + i, pair); - i++; - } - } - } - - //---------------------------------------------------------------------------- - bool ReadScene(const std::string& filePath) - { - std::ifstream inputStream(filePath, std::ios::binary); - std::vector buffer(std::istreambuf_iterator(inputStream), {}); - // Read header - mdl_header_t* header = reinterpret_cast(buffer.data()); - int offset = 84; - - // Set textures - Texture = this->CreateTexture( - buffer, offset, header->skinWidth, header->skinHeight, header->numSkins, 0); - - // Set polyData - this->CreateMesh(buffer, offset, header); - - return true; - } - - void UpdateFrame(double timeValue) - { - // Hardcoded frames per second, 60FPS - if (abs(timeValue - LastRenderTime) > 1.0 / 60) - { - Mapper->SetInputData( - Mesh[(CurrentFrameIndex++) % (LastFrameIndex - FirstFrameIndex) + FirstFrameIndex]); - LastRenderTime = timeValue; - } - } - - // Only one animation enabled at a time - void EnableAnimation(vtkIdType animationIndex) - { - // Animations are divided into groups, but stored as a vector of polydata. - // This functions set the indices for the first and last frames in the group. - std::size_t i = 0; - while (i < GroupAndTimeVal.size() - 1 && GroupAndTimeVal[++i].first < animationIndex) - { - } - FirstFrameIndex = animationIndex == 0 ? 0 : LastFrameIndex + 1; - while (i < GroupAndTimeVal.size() - 1 && GroupAndTimeVal[++i].first == animationIndex) - { - } - LastFrameIndex = (int)i - 1; - } - - void ImportActors(vtkRenderer* renderer) - { - vtkNew actor; - vtkNew mapper; - mapper->SetInputData(Mesh[0]); - actor->SetMapper(mapper); - actor->SetTexture(Texture); - renderer->AddActor(actor); - renderer->SetBackground(0, 0, 0); - - Actor = actor; - Mapper = mapper; - } - - vtkQuakeMDLImporter* Parent; - std::string Description; - vtkSmartPointer Actor; - vtkSmartPointer Mapper; - std::vector> Mesh; - std::vector> GroupAndTimeVal; - int ActiveAnimationId = 0; - int CurrentFrameIndex = 0; - int FirstFrameIndex = 0; - int LastFrameIndex = 10; - int NumberOfAnimations = 0; - double LastRenderTime = 0.0; - vtkSmartPointer Texture; - vtkSmartPointer TextureCoords; - unsigned char DefaultColorMap[256][3] = { { 0, 0, 0 }, { 15, 15, 15 }, { 31, 31, 31 }, - { 47, 47, 47 }, { 63, 63, 63 }, { 75, 75, 75 }, { 91, 91, 91 }, { 107, 107, 107 }, - { 123, 123, 123 }, { 139, 139, 139 }, { 155, 155, 155 }, { 171, 171, 171 }, { 187, 187, 187 }, - { 203, 203, 203 }, { 219, 219, 219 }, { 235, 235, 235 }, { 15, 11, 7 }, { 23, 15, 11 }, - { 31, 23, 11 }, { 39, 27, 15 }, { 47, 35, 19 }, { 55, 43, 23 }, { 63, 47, 23 }, { 75, 55, 27 }, - { 83, 59, 27 }, { 91, 67, 31 }, { 99, 75, 31 }, { 107, 83, 31 }, { 115, 87, 31 }, - { 123, 95, 35 }, { 131, 103, 35 }, { 143, 111, 35 }, { 11, 11, 15 }, { 19, 19, 27 }, - { 27, 27, 39 }, { 39, 39, 51 }, { 47, 47, 63 }, { 55, 55, 75 }, { 63, 63, 87 }, { 71, 71, 103 }, - { 79, 79, 115 }, { 91, 91, 127 }, { 99, 99, 139 }, { 107, 107, 151 }, { 115, 115, 163 }, - { 123, 123, 175 }, { 131, 131, 187 }, { 139, 139, 203 }, { 0, 0, 0 }, { 7, 7, 0 }, - { 11, 11, 0 }, { 19, 19, 0 }, { 27, 27, 0 }, { 35, 35, 0 }, { 43, 43, 7 }, { 47, 47, 7 }, - { 55, 55, 7 }, { 63, 63, 7 }, { 71, 71, 7 }, { 75, 75, 11 }, { 83, 83, 11 }, { 91, 91, 11 }, - { 99, 99, 11 }, { 107, 107, 15 }, { 7, 0, 0 }, { 15, 0, 0 }, { 23, 0, 0 }, { 31, 0, 0 }, - { 39, 0, 0 }, { 47, 0, 0 }, { 55, 0, 0 }, { 63, 0, 0 }, { 71, 0, 0 }, { 79, 0, 0 }, - { 87, 0, 0 }, { 95, 0, 0 }, { 103, 0, 0 }, { 111, 0, 0 }, { 119, 0, 0 }, { 127, 0, 0 }, - { 19, 19, 0 }, { 27, 27, 0 }, { 35, 35, 0 }, { 47, 43, 0 }, { 55, 47, 0 }, { 67, 55, 0 }, - { 75, 59, 7 }, { 87, 67, 7 }, { 95, 71, 7 }, { 107, 75, 11 }, { 119, 83, 15 }, { 131, 87, 19 }, - { 139, 91, 19 }, { 151, 95, 27 }, { 163, 99, 31 }, { 175, 103, 35 }, { 35, 19, 7 }, - { 47, 23, 11 }, { 59, 31, 15 }, { 75, 35, 19 }, { 87, 43, 23 }, { 99, 47, 31 }, { 115, 55, 35 }, - { 127, 59, 43 }, { 143, 67, 51 }, { 159, 79, 51 }, { 175, 99, 47 }, { 191, 119, 47 }, - { 207, 143, 43 }, { 223, 171, 39 }, { 239, 203, 31 }, { 255, 243, 27 }, { 11, 7, 0 }, - { 27, 19, 0 }, { 43, 35, 15 }, { 55, 43, 19 }, { 71, 51, 27 }, { 83, 55, 35 }, { 99, 63, 43 }, - { 111, 71, 51 }, { 127, 83, 63 }, { 139, 95, 71 }, { 155, 107, 83 }, { 167, 123, 95 }, - { 183, 135, 107 }, { 195, 147, 123 }, { 211, 163, 139 }, { 227, 179, 151 }, { 171, 139, 163 }, - { 159, 127, 151 }, { 147, 115, 135 }, { 139, 103, 123 }, { 127, 91, 111 }, { 119, 83, 99 }, - { 107, 75, 87 }, { 95, 63, 75 }, { 87, 55, 67 }, { 75, 47, 55 }, { 67, 39, 47 }, { 55, 31, 35 }, - { 43, 23, 27 }, { 35, 19, 19 }, { 23, 11, 11 }, { 15, 7, 7 }, { 187, 115, 159 }, - { 175, 107, 143 }, { 163, 95, 131 }, { 151, 87, 119 }, { 139, 79, 107 }, { 127, 75, 95 }, - { 115, 67, 83 }, { 107, 59, 75 }, { 95, 51, 63 }, { 83, 43, 55 }, { 71, 35, 43 }, - { 59, 31, 35 }, { 47, 23, 27 }, { 35, 19, 19 }, { 23, 11, 11 }, { 15, 7, 7 }, { 219, 195, 187 }, - { 203, 179, 167 }, { 191, 163, 155 }, { 175, 151, 139 }, { 163, 135, 123 }, { 151, 123, 111 }, - { 135, 111, 95 }, { 123, 99, 83 }, { 107, 87, 71 }, { 95, 75, 59 }, { 83, 63, 51 }, - { 67, 51, 39 }, { 55, 43, 31 }, { 39, 31, 23 }, { 27, 19, 15 }, { 15, 11, 7 }, - { 111, 131, 123 }, { 103, 123, 111 }, { 95, 115, 103 }, { 87, 107, 95 }, { 79, 99, 87 }, - { 71, 91, 79 }, { 63, 83, 71 }, { 55, 75, 63 }, { 47, 67, 55 }, { 43, 59, 47 }, { 35, 51, 39 }, - { 31, 43, 31 }, { 23, 35, 23 }, { 15, 27, 19 }, { 11, 19, 11 }, { 7, 11, 7 }, { 255, 243, 27 }, - { 239, 223, 23 }, { 219, 203, 19 }, { 203, 183, 15 }, { 187, 167, 15 }, { 171, 151, 11 }, - { 155, 131, 7 }, { 139, 115, 7 }, { 123, 99, 7 }, { 107, 83, 0 }, { 91, 71, 0 }, { 75, 55, 0 }, - { 59, 43, 0 }, { 43, 31, 0 }, { 27, 15, 0 }, { 11, 7, 0 }, { 0, 0, 255 }, { 11, 11, 239 }, - { 19, 19, 223 }, { 27, 27, 207 }, { 35, 35, 191 }, { 43, 43, 175 }, { 47, 47, 159 }, - { 47, 47, 143 }, { 47, 47, 127 }, { 47, 47, 111 }, { 47, 47, 95 }, { 43, 43, 79 }, - { 35, 35, 63 }, { 27, 27, 47 }, { 19, 19, 31 }, { 11, 11, 15 }, { 43, 0, 0 }, { 59, 0, 0 }, - { 75, 7, 0 }, { 95, 7, 0 }, { 111, 15, 0 }, { 127, 23, 7 }, { 147, 31, 7 }, { 163, 39, 11 }, - { 183, 51, 15 }, { 195, 75, 27 }, { 207, 99, 43 }, { 219, 127, 59 }, { 227, 151, 79 }, - { 231, 171, 95 }, { 239, 191, 119 }, { 247, 211, 139 }, { 167, 123, 59 }, { 183, 155, 55 }, - { 199, 195, 55 }, { 231, 227, 87 }, { 127, 191, 255 }, { 171, 231, 255 }, { 215, 255, 255 }, - { 103, 0, 0 }, { 139, 0, 0 }, { 179, 0, 0 }, { 215, 0, 0 }, { 255, 0, 0 }, { 255, 243, 147 }, - { 255, 247, 199 }, { 255, 255, 255 }, { 159, 91, 83 } }; - float NormalVectors[162][3] = { { -0.525731f, 0.000000f, 0.850651f }, - { -0.442863f, 0.238856f, 0.864188f }, { -0.295242f, 0.000000f, 0.955423f }, - { -0.309017f, 0.500000f, 0.809017f }, { -0.162460f, 0.262866f, 0.951056f }, - { 0.000000f, 0.000000f, 1.000000f }, { 0.000000f, 0.850651f, 0.525731f }, - { -0.147621f, 0.716567f, 0.681718f }, { 0.147621f, 0.716567f, 0.681718f }, - { 0.000000f, 0.525731f, 0.850651f }, { 0.309017f, 0.500000f, 0.809017f }, - { 0.525731f, 0.000000f, 0.850651f }, { 0.295242f, 0.000000f, 0.955423f }, - { 0.442863f, 0.238856f, 0.864188f }, { 0.162460f, 0.262866f, 0.951056f }, - { -0.681718f, 0.147621f, 0.716567f }, { -0.809017f, 0.309017f, 0.500000f }, - { -0.587785f, 0.425325f, 0.688191f }, { -0.850651f, 0.525731f, 0.000000f }, - { -0.864188f, 0.442863f, 0.238856f }, { -0.716567f, 0.681718f, 0.147621f }, - { -0.688191f, 0.587785f, 0.425325f }, { -0.500000f, 0.809017f, 0.309017f }, - { -0.238856f, 0.864188f, 0.442863f }, { -0.425325f, 0.688191f, 0.587785f }, - { -0.716567f, 0.681718f, -0.147621f }, { -0.500000f, 0.809017f, -0.309017f }, - { -0.525731f, 0.850651f, 0.000000f }, { 0.000000f, 0.850651f, -0.525731f }, - { -0.238856f, 0.864188f, -0.442863f }, { 0.000000f, 0.955423f, -0.295242f }, - { -0.262866f, 0.951056f, -0.162460f }, { 0.000000f, 1.000000f, 0.000000f }, - { 0.000000f, 0.955423f, 0.295242f }, { -0.262866f, 0.951056f, 0.162460f }, - { 0.238856f, 0.864188f, 0.442863f }, { 0.262866f, 0.951056f, 0.162460f }, - { 0.500000f, 0.809017f, 0.309017f }, { 0.238856f, 0.864188f, -0.442863f }, - { 0.262866f, 0.951056f, -0.162460f }, { 0.500000f, 0.809017f, -0.309017f }, - { 0.850651f, 0.525731f, 0.000000f }, { 0.716567f, 0.681718f, 0.147621f }, - { 0.716567f, 0.681718f, -0.147621f }, { 0.525731f, 0.850651f, 0.000000f }, - { 0.425325f, 0.688191f, 0.587785f }, { 0.864188f, 0.442863f, 0.238856f }, - { 0.688191f, 0.587785f, 0.425325f }, { 0.809017f, 0.309017f, 0.500000f }, - { 0.681718f, 0.147621f, 0.716567f }, { 0.587785f, 0.425325f, 0.688191f }, - { 0.955423f, 0.295242f, 0.000000f }, { 1.000000f, 0.000000f, 0.000000f }, - { 0.951056f, 0.162460f, 0.262866f }, { 0.850651f, -0.525731f, 0.000000f }, - { 0.955423f, -0.295242f, 0.000000f }, { 0.864188f, -0.442863f, 0.238856f }, - { 0.951056f, -0.162460f, 0.262866f }, { 0.809017f, -0.309017f, 0.500000f }, - { 0.681718f, -0.147621f, 0.716567f }, { 0.850651f, 0.000000f, 0.525731f }, - { 0.864188f, 0.442863f, -0.238856f }, { 0.809017f, 0.309017f, -0.500000f }, - { 0.951056f, 0.162460f, -0.262866f }, { 0.525731f, 0.000000f, -0.850651f }, - { 0.681718f, 0.147621f, -0.716567f }, { 0.681718f, -0.147621f, -0.716567f }, - { 0.850651f, 0.000000f, -0.525731f }, { 0.809017f, -0.309017f, -0.500000f }, - { 0.864188f, -0.442863f, -0.238856f }, { 0.951056f, -0.162460f, -0.262866f }, - { 0.147621f, 0.716567f, -0.681718f }, { 0.309017f, 0.500000f, -0.809017f }, - { 0.425325f, 0.688191f, -0.587785f }, { 0.442863f, 0.238856f, -0.864188f }, - { 0.587785f, 0.425325f, -0.688191f }, { 0.688191f, 0.587785f, -0.425325f }, - { -0.147621f, 0.716567f, -0.681718f }, { -0.309017f, 0.500000f, -0.809017f }, - { 0.000000f, 0.525731f, -0.850651f }, { -0.525731f, 0.000000f, -0.850651f }, - { -0.442863f, 0.238856f, -0.864188f }, { -0.295242f, 0.000000f, -0.955423f }, - { -0.162460f, 0.262866f, -0.951056f }, { 0.000000f, 0.000000f, -1.000000f }, - { 0.295242f, 0.000000f, -0.955423f }, { 0.162460f, 0.262866f, -0.951056f }, - { -0.442863f, -0.238856f, -0.864188f }, { -0.309017f, -0.500000f, -0.809017f }, - { -0.162460f, -0.262866f, -0.951056f }, { 0.000000f, -0.850651f, -0.525731f }, - { -0.147621f, -0.716567f, -0.681718f }, { 0.147621f, -0.716567f, -0.681718f }, - { 0.000000f, -0.525731f, -0.850651f }, { 0.309017f, -0.500000f, -0.809017f }, - { 0.442863f, -0.238856f, -0.864188f }, { 0.162460f, -0.262866f, -0.951056f }, - { 0.238856f, -0.864188f, -0.442863f }, { 0.500000f, -0.809017f, -0.309017f }, - { 0.425325f, -0.688191f, -0.587785f }, { 0.716567f, -0.681718f, -0.147621f }, - { 0.688191f, -0.587785f, -0.425325f }, { 0.587785f, -0.425325f, -0.688191f }, - { 0.000000f, -0.955423f, -0.295242f }, { 0.000000f, -1.000000f, 0.000000f }, - { 0.262866f, -0.951056f, -0.162460f }, { 0.000000f, -0.850651f, 0.525731f }, - { 0.000000f, -0.955423f, 0.295242f }, { 0.238856f, -0.864188f, 0.442863f }, - { 0.262866f, -0.951056f, 0.162460f }, { 0.500000f, -0.809017f, 0.309017f }, - { 0.716567f, -0.681718f, 0.147621f }, { 0.525731f, -0.850651f, 0.000000f }, - { -0.238856f, -0.864188f, -0.442863f }, { -0.500000f, -0.809017f, -0.309017f }, - { -0.262866f, -0.951056f, -0.162460f }, { -0.850651f, -0.525731f, 0.000000f }, - { -0.716567f, -0.681718f, -0.147621f }, { -0.716567f, -0.681718f, 0.147621f }, - { -0.525731f, -0.850651f, 0.000000f }, { -0.500000f, -0.809017f, 0.309017f }, - { -0.238856f, -0.864188f, 0.442863f }, { -0.262866f, -0.951056f, 0.162460f }, - { -0.864188f, -0.442863f, 0.238856f }, { -0.809017f, -0.309017f, 0.500000f }, - { -0.688191f, -0.587785f, 0.425325f }, { -0.681718f, -0.147621f, 0.716567f }, - { -0.442863f, -0.238856f, 0.864188f }, { -0.587785f, -0.425325f, 0.688191f }, - { -0.309017f, -0.500000f, 0.809017f }, { -0.147621f, -0.716567f, 0.681718f }, - { -0.425325f, -0.688191f, 0.587785f }, { -0.162460f, -0.262866f, 0.951056f }, - { 0.442863f, -0.238856f, 0.864188f }, { 0.162460f, -0.262866f, 0.951056f }, - { 0.309017f, -0.500000f, 0.809017f }, { 0.147621f, -0.716567f, 0.681718f }, - { 0.000000f, -0.525731f, 0.850651f }, { 0.425325f, -0.688191f, 0.587785f }, - { 0.587785f, -0.425325f, 0.688191f }, { 0.688191f, -0.587785f, 0.425325f }, - { -0.955423f, 0.295242f, 0.000000f }, { -0.951056f, 0.162460f, 0.262866f }, - { -1.000000f, 0.000000f, 0.000000f }, { -0.850651f, 0.000000f, 0.525731f }, - { -0.955423f, -0.295242f, 0.000000f }, { -0.951056f, -0.162460f, 0.262866f }, - { -0.864188f, 0.442863f, -0.238856f }, { -0.951056f, 0.162460f, -0.262866f }, - { -0.809017f, 0.309017f, -0.500000f }, { -0.864188f, -0.442863f, -0.238856f }, - { -0.951056f, -0.162460f, -0.262866f }, { -0.809017f, -0.309017f, -0.500000f }, - { -0.681718f, 0.147621f, -0.716567f }, { -0.681718f, -0.147621f, -0.716567f }, - { -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 } }; -}; - -vtkQuakeMDLImporter::vtkQuakeMDLImporter() - : Internals(new vtkQuakeMDLImporter::vtkInternals(this)){ - - }; - -//---------------------------------------------------------------------------- - -//---------------------------------------------------------------------------- -int vtkQuakeMDLImporter::ImportBegin() -{ - return this->Internals->ReadScene(this->FileName); -} - -//---------------------------------------------------------------------------- -void vtkQuakeMDLImporter::ImportActors(vtkRenderer* renderer) -{ - this->Internals->ImportActors(renderer); -} - -//---------------------------------------------------------------------------- -std::string vtkQuakeMDLImporter::GetOutputsDescription() -{ - return this->Internals->Description; -} - -//---------------------------------------------------------------------------- -void vtkQuakeMDLImporter::UpdateTimeStep(double timeValue) -{ - this->Internals->UpdateFrame(timeValue); - return; -} - -//---------------------------------------------------------------------------- -vtkIdType vtkQuakeMDLImporter::GetNumberOfAnimations() -{ - return this->Internals->NumberOfAnimations; -} - -//---------------------------------------------------------------------------- -std::string vtkQuakeMDLImporter::GetAnimationName(vtkIdType animationIndex) -{ - return std::to_string(animationIndex); -} - -//---------------------------------------------------------------------------- -void vtkQuakeMDLImporter::EnableAnimation(vtkIdType animationIndex) -{ - this->Internals->EnableAnimation(animationIndex); - return; -} - -//---------------------------------------------------------------------------- -void vtkQuakeMDLImporter::DisableAnimation(vtkIdType vtkNotUsed(animationIndex)) -{ - return; -} - -//---------------------------------------------------------------------------- -bool vtkQuakeMDLImporter::IsAnimationEnabled(vtkIdType animationIndex) -{ - return animationIndex == this->Internals->ActiveAnimationId; -} - -//---------------------------------------------------------------------------- -bool vtkQuakeMDLImporter::GetTemporalInformation(vtkIdType vtkNotUsed(animationIndex), - double vtkNotUsed(frameRate), int& vtkNotUsed(nbTimeSteps), double timeRange[2], - vtkDoubleArray* vtkNotUsed(timeSteps)) -{ - timeRange[0] = 0.0; - timeRange[1] = 10.0; - return true; -} - -//---------------------------------------------------------------------------- -vtkIdType vtkQuakeMDLImporter::GetNumberOfCameras() -{ - return 1; -} - -//---------------------------------------------------------------------------- -std::string vtkQuakeMDLImporter::GetCameraName(vtkIdType vtkNotUsed(camIndex)) -{ - return "Camera"; -} - -//---------------------------------------------------------------------------- -void vtkQuakeMDLImporter::SetCamera(vtkIdType vtkNotUsed(camIndex)) -{ - return; -} - -//---------------------------------------------------------------------------- -void vtkQuakeMDLImporter::ImportCameras(vtkRenderer* renderer) -{ - this->Internals->ImportCameras(renderer); -} - -//---------------------------------------------------------------------------- -void vtkQuakeMDLImporter::ImportLights(vtkRenderer* renderer) -{ - this->Internals->ImportLights(renderer); -} - -//---------------------------------------------------------------------------- -void vtkQuakeMDLImporter::PrintSelf(ostream& os, vtkIndent indent) -{ - this->Superclass::PrintSelf(os, indent); - os << indent << "FileName: " << this->FileName << "\n"; -} diff --git a/plugins/native/module/vtkQuakeMDLImporter.cxx.rej b/plugins/native/module/vtkQuakeMDLImporter.cxx.rej deleted file mode 100644 index b3fc6d37fd..0000000000 --- a/plugins/native/module/vtkQuakeMDLImporter.cxx.rej +++ /dev/null @@ -1,9 +0,0 @@ -diff a/plugins/native/module/vtkQuakeMDLImporter.cxx b/plugins/native/module/vtkQuakeMDLImporter.cxx (rejected hunks) -@@ -722,7 +709,6 @@ - //---------------------------------------------------------------------------- - void vtkQuakeMDLImporter::SetCamera(vtkIdType camIndex) - { -- - } - - //---------------------------------------------------------------------------- diff --git a/plugins/native/module/vtkQuakeMDLImporter.h.rej b/plugins/native/module/vtkQuakeMDLImporter.h.rej deleted file mode 100644 index 9a24d88285..0000000000 --- a/plugins/native/module/vtkQuakeMDLImporter.h.rej +++ /dev/null @@ -1,17 +0,0 @@ -diff a/plugins/native/module/vtkQuakeMDLImporter.h b/plugins/native/module/vtkQuakeMDLImporter.h (rejected hunks) -@@ -5,14 +5,13 @@ - - #ifndef vtkQuakeMDLImporter_h - #define vtkQuakeMDLImporter_h --#include -+#include - - class vtkQuakeMDLImporter : public vtkImporter - { - public: - static vtkQuakeMDLImporter* New(); - vtkTypeMacro(vtkQuakeMDLImporter, vtkImporter); -- - - void PrintSelf(ostream& os, vtkIndent indent) override; - diff --git a/style.diff b/style.diff deleted file mode 100644 index e80a12c576..0000000000 --- a/style.diff +++ /dev/null @@ -1,344 +0,0 @@ ---- plugins/alembic/module/vtkF3DAlembicReader.h (original) -+++ plugins/alembic/module/vtkF3DAlembicReader.h (reformatted) -@@ -14,10 +14,10 @@ - #ifndef vtkF3DAlembicReader_h - #define vtkF3DAlembicReader_h - -+#include - #include - #include - #include --#include - - class vtkF3DAlembicReader : public vtkPolyDataAlgorithm - { ---- plugins/native/module/vtkQuakeMDLImporter.h (original) -+++ plugins/native/module/vtkQuakeMDLImporter.h (reformatted) -@@ -5,14 +5,13 @@ - - #ifndef vtkQuakeMDLImporter_h - #define vtkQuakeMDLImporter_h --#include -+#include - - class vtkQuakeMDLImporter : public vtkImporter - { - public: - static vtkQuakeMDLImporter* New(); - vtkTypeMacro(vtkQuakeMDLImporter, vtkImporter); -- - - void PrintSelf(ostream& os, vtkIndent indent) override; - -@@ -86,17 +85,16 @@ - */ - void SetCamera(vtkIdType camIndex) override; - -- - protected: - vtkQuakeMDLImporter(); - ~vtkQuakeMDLImporter() override = default; -- -+ - int ImportBegin() override; - void ImportActors(vtkRenderer*) override; - void ImportCameras(vtkRenderer*) override; - void ImportLights(vtkRenderer*) override; - -- // Header definition, -+ // Header definition, - struct mdl_header_t - { - int IDPO; ---- plugins/native/module/vtkQuakeMDLImporter.cxx (original) -+++ plugins/native/module/vtkQuakeMDLImporter.cxx (reformatted) -@@ -1,42 +1,41 @@ - #include "vtkQuakeMDLImporter.h" - --#include -+#include -+#include -+#include - #include --#include - #include - #include - #include - #include - #include -+#include - #include - #include -+#include -+#include -+#include - #include -+#include -+#include -+#include -+#include - #include - #include - #include --#include --#include - #include --#include --#include -+#include - #include --#include --#include --#include --#include -+#include -+#include - #include --#include --#include --#include --#include --#include --#include - #include - #include -+#include -+#include - - //---------------------------------------------------------------------------- - vtkStandardNewMacro(vtkQuakeMDLImporter); -- - - class vtkQuakeMDLImporter::vtkInternals - { -@@ -72,24 +71,23 @@ - vtkNew backLight; - double backLightPosition[3] = { -50.0, 0.0, 0.0 }; - backLight->SetPosition(backLightPosition); -- -+ - renderer->AddLight(frontLight); - renderer->AddLight(leftLight); - renderer->AddLight(backLight); - } - - //---------------------------------------------------------------------------- -- vtkSmartPointer CreateTexture(std::vector buffer, int& offset, int skinWidth, -- int skinHeight, int nbSkins, int selectedSkinIndex) -+ vtkSmartPointer CreateTexture(std::vector buffer, int& offset, -+ int skinWidth, int skinHeight, int nbSkins, int selectedSkinIndex) - { - vtkNew texture; - texture->InterpolateOn(); - -- - // Read textures. - struct mdl_skin_t - { -- int group; /* 0 = single, 1 = group */ -+ int group; /* 0 = single, 1 = group */ - unsigned char* data; /* texture data */ - }; - struct mdl_groupskin_t -@@ -118,7 +116,7 @@ - else - { - skins[i].group = 1; -- int nb = *reinterpret_cast(buffer.data() + offset + 4); -+ int nb = *reinterpret_cast(buffer.data() + offset + 4); - skins[i].skin = reinterpret_cast(buffer.data() + 4 + nb * 4 + offset); - offset += 4 + nb * 4 + nb * (skinWidth) * (skinHeight); - } -@@ -129,12 +127,12 @@ - img->SetDimensions(skinWidth, skinHeight, 1); - img->AllocateScalars(VTK_UNSIGNED_CHAR, 3); - unsigned char* selectedSkin = skins[selectedSkinIndex].skin; -- for (int i = 0; i < skinHeight ; i++) -+ for (int i = 0; i < skinHeight; i++) - { - for (int j = 0; j < skinWidth; j++) - { - unsigned char index = *reinterpret_cast(selectedSkin + i * skinWidth + j); -- unsigned char* ptr = reinterpret_cast(img->GetScalarPointer(j,i,0)); -+ unsigned char* ptr = reinterpret_cast(img->GetScalarPointer(j, i, 0)); - ptr[0] = DefaultColorMap[index][0]; // R - ptr[1] = DefaultColorMap[index][1]; // G - ptr[2] = DefaultColorMap[index][2]; // B -@@ -145,8 +143,8 @@ - return texture; - } - -- -- void CreateMesh(std::vector buffer, int& offset, mdl_header_t* header, int selectedFrameIndex) -+ void CreateMesh( -+ std::vector buffer, int& offset, mdl_header_t* header, int selectedFrameIndex) - { - // Read texture coordinates - struct mdl_texcoord_t -@@ -217,9 +215,8 @@ - framePtr[i].nb = reinterpret_cast(buffer.data() + 4 + offset); - mdl_vertex_t* min = reinterpret_cast(buffer.data() + 8 + offset); - mdl_vertex_t* max = reinterpret_cast(buffer.data() + 12 + offset); -- float* time = -- framePtr[i].time = reinterpret_cast(buffer.data() + 16 + offset); -- framePtr[i].frames = -+ float* time = framePtr[i].time = reinterpret_cast(buffer.data() + 16 + offset); -+ framePtr[i].frames = - reinterpret_cast(buffer.data() + 16 + 4 * (*framePtr[i].nb) + offset); - offset += 16 + (*framePtr[i].nb) * 4; - for (int j = 0; j < *framePtr[i].nb; j++) -@@ -265,9 +262,7 @@ - } - vtkIdType t[3] = { i * 3, i * 3 + 1, i * 3 + 2 }; - cells->InsertNextCell(3, t); -- -- } -- -+ } - - // Draw vertices - std::string frameName = ""; -@@ -279,7 +274,7 @@ - vtkNew normals; - normals->SetNumberOfComponents(3); - normals->Allocate(header->numTriangles * 3 * 3); -- -+ - plugin_frame_pointer selectedFrame = framePtr[frameNum]; - if (*selectedFrame.type == 0) - { -@@ -296,17 +291,17 @@ - { - v[k] = v[k] * header->scale[k] + header->translation[k]; - } -- vertices->InsertPoint(i*3+j, v); -+ vertices->InsertPoint(i * 3 + j, v); - int normalIndex = selectedFrame.frames->verts[vertexNum[j]].normalIndex; -- normals->SetTuple3(i*3+j, NormalVectors[normalIndex][0] / 255.0, -- NormalVectors[normalIndex][1] / 255.0, NormalVectors[normalIndex][2] / 255.0); -+ normals->SetTuple3(i * 3 + j, NormalVectors[normalIndex][0] / 255.0, -+ NormalVectors[normalIndex][1] / 255.0, NormalVectors[normalIndex][2] / 255.0); - } - } - vtkNew mesh; - mesh->SetPoints(vertices); - mesh->SetPolys(cells); - mesh->GetPointData()->SetTCoords(textureCoordinates); --// mesh->GetPointData()->SetNormals(normals); -+ // mesh->GetPointData()->SetNormals(normals); - Mesh.push_back(mesh); - std::string meshName = std::string(selectedFrame.frames->name); - for (int i = 0; i < meshName.size(); i++) -@@ -347,9 +342,9 @@ - { - v[k] = v[k] * header->scale[k] + header->translation[k]; - } -- vertices->InsertPoint(i*3+j, v); -+ vertices->InsertPoint(i * 3 + j, v); - int normalIndex = selectedFrame.frames[groupFrameNum].verts[vertexNum[j]].normalIndex; -- normals->SetTuple3(i*3+j, NormalVectors[normalIndex][0] / 255.0, -+ normals->SetTuple3(i * 3 + j, NormalVectors[normalIndex][0] / 255.0, - NormalVectors[normalIndex][1] / 255.0, NormalVectors[normalIndex][2] / 255.0); - } - } -@@ -378,7 +373,8 @@ - NumberOfAnimations++; - frameName = meshName; - } -- std::pair pair = std::make_pair(frameIndex, selectedFrame.time[groupFrameNum]); -+ std::pair pair = -+ std::make_pair(frameIndex, selectedFrame.time[groupFrameNum]); - GroupAndTimeVal.push_back(pair); - } - } -@@ -399,7 +395,7 @@ - for (int j = 0; j < header->numTriangles * 3; j++) - { - double* v_0 = Mesh[i]->GetPoint(j); -- double* v_1 = Mesh[i+1]->GetPoint(j); -+ double* v_1 = Mesh[i + 1]->GetPoint(j); - double* interp = new double[3]; - interp[0] = v_0[0] + 0.5 * (v_1[0] - v_0[0]); - interp[1] = v_0[1] + 0.5 * (v_1[1] - v_0[1]); -@@ -427,17 +423,14 @@ - // Read header - mdl_header_t* header = reinterpret_cast(buffer.data()); - int offset = 84; -- -+ - // Set textures -- Texture= this->CreateTexture( -+ Texture = this->CreateTexture( - buffer, offset, header->skinWidth, header->skinHeight, header->numSkins, 0); -- -- -+ - // Set polyData - this->CreateMesh(buffer, offset, header, 0); -- -- -- -+ - return 1; - } - -@@ -447,7 +440,7 @@ - if (abs(timeValue - LastRenderTime) > 1.0 / 24) - { - Mapper->SetInputData( -- Mesh[(CurrentFrameIndex++) % (LastFrameIndex - FirstFrameIndex) + FirstFrameIndex]); -+ Mesh[(CurrentFrameIndex++) % (LastFrameIndex - FirstFrameIndex) + FirstFrameIndex]); - LastRenderTime = timeValue; - } - } -@@ -465,7 +458,7 @@ - while (i < GroupAndTimeVal.size() && GroupAndTimeVal[++i].first == animationIndex) - { - } -- LastFrameIndex = i-1; -+ LastFrameIndex = i - 1; - } - - void ImportActors(vtkRenderer* renderer) -@@ -482,14 +475,12 @@ - Mapper = mapper; - } - -- -- - vtkQuakeMDLImporter* Parent; - std::string Description; - vtkSmartPointer Actor; - vtkSmartPointer Mapper; - std::vector> Mesh; -- std::vector > GroupAndTimeVal; -+ std::vector> GroupAndTimeVal; - int ActiveAnimationId = 0; - int CurrentFrameIndex = 0; - int FirstFrameIndex = 0; -@@ -637,9 +628,6 @@ - - //---------------------------------------------------------------------------- - -- -- -- - //---------------------------------------------------------------------------- - int vtkQuakeMDLImporter::ImportBegin() - { -@@ -695,7 +683,6 @@ - { - return true; - } -- - - //---------------------------------------------------------------------------- - bool vtkQuakeMDLImporter::GetTemporalInformation(vtkIdType animationIndex, -@@ -722,7 +709,6 @@ - //---------------------------------------------------------------------------- - void vtkQuakeMDLImporter::SetCamera(vtkIdType camIndex) - { -- - } - - //---------------------------------------------------------------------------- diff --git a/testing/baselines/TestQuakeMDL.png b/testing/baselines/TestQuakeMDL.png new file mode 100644 index 0000000000..679f9ddc2a --- /dev/null +++ b/testing/baselines/TestQuakeMDL.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7b8ebba71f1475f7bf2382b3736ff82147519b71a9d290f3ac43bee4adcb60ed +size 47901 diff --git a/testing/data/glaunch.mdl b/testing/data/glaunch.mdl new file mode 100644 index 0000000000..efc588c940 --- /dev/null +++ b/testing/data/glaunch.mdl @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c8a1b5fe4eb74de34a5e887e5b8624159b2bda11344b7eeeed8b6d13c9fc759a +size 86280 From b4a55324a28adcf88d76ef4752c5357a39a5cd0c Mon Sep 17 00:00:00 2001 From: Youva Boutora <48061964+Youva@users.noreply.github.com> Date: Tue, 17 Dec 2024 18:28:42 -0500 Subject: [PATCH 23/60] Changed UpdateTimeStep --- plugins/alembic/module/vtkF3DAlembicReader.h | 3 +- .../native/configs/config.d/10_native.json | 5 +- .../native/module/vtkF3DQuakeMDLImporter.cxx | 66 ++++++++++--------- .../native/module/vtkF3DQuakeMDLImporter.h | 39 ++--------- 4 files changed, 44 insertions(+), 69 deletions(-) diff --git a/plugins/alembic/module/vtkF3DAlembicReader.h b/plugins/alembic/module/vtkF3DAlembicReader.h index e8a47dd412..19940cbbee 100644 --- a/plugins/alembic/module/vtkF3DAlembicReader.h +++ b/plugins/alembic/module/vtkF3DAlembicReader.h @@ -14,11 +14,12 @@ #ifndef vtkF3DAlembicReader_h #define vtkF3DAlembicReader_h -#include #include #include #include +#include + class vtkF3DAlembicReader : public vtkPolyDataAlgorithm { public: diff --git a/plugins/native/configs/config.d/10_native.json b/plugins/native/configs/config.d/10_native.json index 539eeb838c..0dfcaaeb3e 100644 --- a/plugins/native/configs/config.d/10_native.json +++ b/plugins/native/configs/config.d/10_native.json @@ -68,7 +68,10 @@ "anti-aliasing": false, "translucency-support": false }, - ".*(mdl)": +}, +{ + "match": ".*(mdl)", + "options": { "up": "+Z", "camera-direction": "-1,0,0", diff --git a/plugins/native/module/vtkF3DQuakeMDLImporter.cxx b/plugins/native/module/vtkF3DQuakeMDLImporter.cxx index 8c7406e170..856e937441 100644 --- a/plugins/native/module/vtkF3DQuakeMDLImporter.cxx +++ b/plugins/native/module/vtkF3DQuakeMDLImporter.cxx @@ -109,6 +109,27 @@ class vtkF3DQuakeMDLImporter::vtkInternals return texture; } + // Header definition, + struct mdl_header_t + { + int IDPO; + int version; + float scale[3]; + float translation[3]; + float boundingRadius; + float eyePosition[3]; + int numSkins; + int skinWidth; + int skinHeight; + int numVertices; + int numTriangles; + int numFrames; + int syncType; + int stateFlags; + float size; + }; + + //---------------------------------------------------------------------------- void CreateMesh(std::vector buffer, int offset, mdl_header_t* header) { @@ -392,14 +413,10 @@ class vtkF3DQuakeMDLImporter::vtkInternals //---------------------------------------------------------------------------- void UpdateTimeStep(double timeValue) { - float framesToSkip = FrameRate * abs(timeValue - LastRenderTime); - if (framesToSkip >= 1.0) - { - CurrentFrameIndex = (CurrentFrameIndex + 1) % (int)ActiveFrames.size(); - int currentFrame = ActiveFrames[CurrentFrameIndex]; - Mapper->SetInputData(Mesh[currentFrame]); - LastRenderTime = timeValue; - } + int frameIndex = (int) floor(FrameRate * abs(timeValue)) % (int)ActiveFrames.size(); + int currentFrame = ActiveFrames[frameIndex]; + Mapper->SetInputData(Mesh[currentFrame]); + LastRenderTime = timeValue; } //---------------------------------------------------------------------------- @@ -420,7 +437,6 @@ class vtkF3DQuakeMDLImporter::vtkInternals { ActiveFrames.emplace_back(i); } - CurrentFrameIndex = 0; ActiveAnimationId.emplace_back(animationIndex); } @@ -441,7 +457,6 @@ class vtkF3DQuakeMDLImporter::vtkInternals { ActiveFrames.erase(std::remove(ActiveFrames.begin(), ActiveFrames.end(), i), ActiveFrames.end()); } - CurrentFrameIndex = 0; ActiveAnimationId.erase( std::remove(ActiveAnimationId.begin(), ActiveAnimationId.end(), animationIndex), ActiveAnimationId.end()); } @@ -467,16 +482,10 @@ class vtkF3DQuakeMDLImporter::vtkInternals } //---------------------------------------------------------------------------- - void GetTimeRange(vtkIdType animationIndex, double timeRange[2]) + void GetTimeRange(vtkIdType vtkNotUsed(animationIndex), double timeRange[2]) { - int firstFrameIndex = std::distance(GroupAndTimeVal.begin(), - std::find_if(GroupAndTimeVal.begin(), GroupAndTimeVal.end(), [animationIndex](const std::pair pair) { return pair.first == animationIndex; })); - int lastFrameIndex = std::distance(GroupAndTimeVal.begin(), - std::find_if(GroupAndTimeVal.begin(), GroupAndTimeVal.end(), [animationIndex](const std::pair pair) { return pair.first > animationIndex; })); - firstFrameIndex = firstFrameIndex < GroupAndTimeVal.size() ? firstFrameIndex : 0; - lastFrameIndex = lastFrameIndex - 1; - timeRange[0] = GroupAndTimeVal[firstFrameIndex].second <= 0.0 ? (1.0 / FrameRate) * firstFrameIndex : GroupAndTimeVal[firstFrameIndex].second; - timeRange[1] = GroupAndTimeVal[lastFrameIndex].second <= 0.0 ? (1.0 / FrameRate) * (lastFrameIndex + 1) : GroupAndTimeVal[lastFrameIndex].second; + timeRange[0] = 0.0; + timeRange[1] = (1.0 / FrameRate) * GroupAndTimeVal.size(); } vtkF3DQuakeMDLImporter* Parent; @@ -488,7 +497,6 @@ class vtkF3DQuakeMDLImporter::vtkInternals std::vector AnimationNames; std::vector ActiveFrames; std::vector ActiveAnimationId; - int CurrentFrameIndex = 0; int NumberOfAnimations = 0; double LastRenderTime = 0.0; double FrameRate = 60.0; @@ -568,17 +576,10 @@ bool vtkF3DQuakeMDLImporter::GetTemporalInformation(vtkIdType animationIndex, double frameRate, int& nbTimeSteps, double timeRange[2], vtkDoubleArray* vtkNotUsed(timeSteps)) { - if ((int) Internals->ActiveFrames.size() > 1) - { - Internals->SetFrameRate(frameRate); - Internals->GetTimeRange(animationIndex, timeRange); - nbTimeSteps = (int)Internals->ActiveFrames.size(); - return true; - } - else - { - return false; - } + Internals->SetFrameRate(frameRate); + Internals->GetTimeRange(animationIndex, timeRange); + nbTimeSteps = (int) Internals->ActiveFrames.size(); + return true; } //---------------------------------------------------------------------------- @@ -611,6 +612,7 @@ void vtkF3DQuakeMDLImporter::ImportLights(vtkRenderer* renderer) } //---------------------------------------------------------------------------- -void vtkF3DQuakeMDLImporter::PrintSelf(ostream& vtkNotUsed(os), vtkIndent vtkNotUsed(indent)) +void vtkF3DQuakeMDLImporter::SetFileName(std::string fileName) { + this->FileName = fileName; } diff --git a/plugins/native/module/vtkF3DQuakeMDLImporter.h b/plugins/native/module/vtkF3DQuakeMDLImporter.h index 9f0e3edcde..54990b1746 100644 --- a/plugins/native/module/vtkF3DQuakeMDLImporter.h +++ b/plugins/native/module/vtkF3DQuakeMDLImporter.h @@ -5,29 +5,22 @@ #ifndef vtkF3DQuakeMDLImporter_h #define vtkF3DQuakeMDLImporter_h -#include +#include #include "vtkF3DQuakeMDLImporterConstants.h" -class vtkF3DQuakeMDLImporter : public vtkImporter +class vtkF3DQuakeMDLImporter : public vtkF3DImporter { public: static vtkF3DQuakeMDLImporter* New(); - //vtkTypeMacro(vtkF3DQuakeMDLImporter, vtkImporter); - void PrintSelf(ostream& os, vtkIndent indent) override; - - ///@{ /** - * Set/Get the file name. + * Set the file name. */ - vtkSetMacro(FileName, std::string); - vtkGetMacro(FileName, std::string); - ///@} + void SetFileName(std::string fileName); /** * Update actors at the given time value. */ - void UpdateTimeStep(double timeValue) override; /** @@ -43,7 +36,6 @@ class vtkF3DQuakeMDLImporter : public vtkImporter ///@{ /** * Enable/Disable/Get the status of specific animations - * Only one single animation can be enabled */ void EnableAnimation(vtkIdType animationIndex) override; void DisableAnimation(vtkIdType animationIndex) override; @@ -59,7 +51,6 @@ class vtkF3DQuakeMDLImporter : public vtkImporter /** * Get temporal information for the currently enabled animation. - * Only defines timerange and ignore provided frameRate. */ bool GetTemporalInformation(vtkIdType animationIndex, double frameRate, int& nbTimeSteps, double timeRange[2], vtkDoubleArray* timeSteps) override; @@ -76,7 +67,6 @@ class vtkF3DQuakeMDLImporter : public vtkImporter /** * Enable a specific camera. - * If a negative index is provided, no camera from the importer is used. */ void SetCamera(vtkIdType camIndex) override; @@ -89,27 +79,6 @@ class vtkF3DQuakeMDLImporter : public vtkImporter void ImportCameras(vtkRenderer*) override; void ImportLights(vtkRenderer*) override; - // Header definition, - struct mdl_header_t - { - int IDPO; - int version; - float scale[3]; - float translation[3]; - float boundingRadius; - float eyePosition[3]; - int numSkins; - int skinWidth; - int skinHeight; - int numVertices; - int numTriangles; - int numFrames; - int syncType; - int stateFlags; - float size; - }; - - private: vtkF3DQuakeMDLImporter(const vtkF3DQuakeMDLImporter&) = delete; void operator=(const vtkF3DQuakeMDLImporter&) = delete; From 85ec4f233bad9248a6b4db68fb6a044bdc7187d7 Mon Sep 17 00:00:00 2001 From: Marc-Alexandre Espiaut <76531574+malespiaut@users.noreply.github.com> Date: Mon, 27 May 2024 11:02:29 +0200 Subject: [PATCH 24/60] Adding preliminary Quake1 MDL plugin. --- plugins/native/module/vtkQuakeMDLReader.cxx | 161 ++++++++++++++++++++ plugins/native/module/vtkQuakeMDLReader.h | 35 +++++ 2 files changed, 196 insertions(+) create mode 100644 plugins/native/module/vtkQuakeMDLReader.cxx create mode 100644 plugins/native/module/vtkQuakeMDLReader.h diff --git a/plugins/native/module/vtkQuakeMDLReader.cxx b/plugins/native/module/vtkQuakeMDLReader.cxx new file mode 100644 index 0000000000..daa5d5e419 --- /dev/null +++ b/plugins/native/module/vtkQuakeMDLReader.cxx @@ -0,0 +1,161 @@ +#include "vtkQuakeMDLReader.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//---------------------------------------------------------------------------- +vtkStandardNewMacro(vtkQuakeMDLReader); + +//---------------------------------------------------------------------------- +vtkQuakeMDLReader::vtkQuakeMDLReader() +{ + this->SetNumberOfInputPorts(0); +} + +//---------------------------------------------------------------------------- +int vtkQuakeMDLReader::RequestData( + vtkInformation*, vtkInformationVector**, vtkInformationVector* outputVector) +{ + vtkPolyData* output = vtkPolyData::GetData(outputVector); + + std::ifstream inputStream(this->FileName, std::ios::binary); + + std::vector buffer(std::istreambuf_iterator(inputStream), {}); + + //??? What's a “splat”??? + constexpr size_t splatSize = 32; + + //??? What is nbSplats??? + size_t nbSplats = buffer.size() / splatSize; + + // identity ("IDPO"): 4 chars (4 bytes) + vtkNew IDPOArray; + IDPOArray->SetNumberOfComponents(4); + IDPOArray->SetNumberOfTuples(nbSplats); + IDPOArray->SetName("identity"); + + // version: 1 int (4 bytes) + vtkNew version; + version->SetNumberOfComponents(1); + version->SetNumberOfTuples(nbSplats); + version->SetName("version"); + + //==================================== + + // scaling factor: 3 floats (12 bytes) + vtkNew scalingFactor; + scalingFactor->SetNumberOfComponents(3); + scalingFactor->SetNumberOfTuples(nbSplats); + scalingFactor->SetName("scaling factor"); + + // translation vector: 3 floats (12 bytes) + vtkNew translationVector; + translationVector->SetNumberOfComponents(3); + translationVector->SetNumberOfTuples(nbSplats); + translationVector->SetName("translation vector"); + + // bounding radius: 1 float (4 bytes) + vtkNew boundingRadius; + boundingRadius->SetNumberOfComponents(1); + boundingRadius->SetNumberOfTuples(nbSplats); + boundingRadius->SetName("bounding radius"); + + // eye position: 3 floats (12 bytes) + vtkNew eyePosition; + eyePosition->SetNumberOfComponents(3); + eyePosition->SetNumberOfTuples(nbSplats); + eyePosition->SetName("eye position"); + + //==================================== + + // number of textures: 1 int (4 bytes) + vtkNew texturesNum; + texturesNum->SetNumberOfComponents(1); + texturesNum->SetNumberOfTuples(nbSplats); + texturesNum->SetName("number of textures"); + + // texture width: 1 int (4 bytes) + vtkNew textureWidth; + textureWidth->SetNumberOfComponents(1); + texturesWidth->SetNumberOfTuples(nbSplats); + textureWidth->SetName("texture width"); + + // texture height: 1 int (4 bytes) + vtkNew textureHeight; + textureHeight->SetNumberOfComponents(1); + textureHeight->SetNumberOfTuples(nbSplats); + textureHeight->SetName("texture height"); + + //==================================== + + // number of vertices: 1 int (4 bytes) + vtkNew verticesNum; + verticesNum->SetNumberOfComponents(1); + verticesNum->SetNumberOfTuples(nbSplats); + verticesNum->SetName("number of vertices"); + + // number of triangles: 1 int (4 bytes) + vtkNew trianglesNum; + trianglesNum->SetNumberOfComponents(1); + trianglesNum->SetNumberOfTuples(nbSplats); + trianglesNum->SetName("number of triangles"); + + // number of frames: 1 int (4 bytes) + vtkNew framesNum; + framesNum->SetNumberOfComponents(1); + framesNum->SetNumberOfTuples(nbSplats); + framesNum->SetName("number of frames"); + + //==================================== + + // sync type (0: synchron, 1: random): 1 int (4 bytes) + vtkNew syncType; + syncType->SetNumberOfComponents(1); + syncType->SetNumberOfTuples(nbSplats); + syncType->SetName("sync type"); + + // state flags: 1 int (4 bytes) + vtkNew stateFlags; + stateFlags->SetNumberOfComponents(1); + stateFlags->SetNumberOfTuples(nbSplats); + stateFlags->SetName("state flags"); + + //==================================== + + // position: 3 floats (12 bytes) + vtkNew position; + position->SetNumberOfComponents(3); + position->SetNumberOfTuples(nbSplats); + position->SetName("position"); + + // scale: 3 floats (12 bytes) + vtkNew scale; + scale->SetNumberOfComponents(3); + scale->SetNumberOfTuples(nbSplats); + scale->SetName("scale"); + + // rotation: 4 chars (4 bytes) + vtkNew rotation; + rotation->SetNumberOfComponents(4); + rotation->SetNumberOfTuples(nbSplats); + rotation->SetName("rotation"); + + // color+opacity: 4 chars (4 bytes) + vtkNew colorAndOpacity; + colorAndOpacity->SetNumberOfComponents(4); + colorAndOpacity->SetNumberOfTuples(nbSplats); + colorAndOpacity->SetName("color and opacity"); + + return 1; +} diff --git a/plugins/native/module/vtkQuakeMDLReader.h b/plugins/native/module/vtkQuakeMDLReader.h new file mode 100644 index 0000000000..cee1a4c596 --- /dev/null +++ b/plugins/native/module/vtkQuakeMDLReader.h @@ -0,0 +1,35 @@ +/** + * @class vtkQuakeMDLReader + * @brief VTK Reader for Quake 1 models in binary .mdl file format + */ + +#ifndef vtkQuakeMDLReader_h +#define vtkQuakeMDLReader_h + +#include + +class vtkQuakeMDLReader : public vtkPolyDataAlgorithm +{ +public: + static vtkQuakeMDLReader* New(); + vtkTypeMacro(vtkQuakeMDLReader, vtkPolyDataAlgorithm); + + /** + * Set the file name. + */ + vtkSetMacro(FileName, std::string); + +protected: + vtkQuakeMDLReader(); + ~vtkQuakeMDLReader() override = default; + + int RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) override; + +private: + vtkQuakeMDLReader(const vtkQuakeMDLReader&) = delete; + void operator=(const vtkQuakeMDLReader&) = delete; + + std::string FileName; +}; + +#endif From 19607a5f26b6f64645d1402495bb7c8e284ed485 Mon Sep 17 00:00:00 2001 From: Marc-Alexandre Espiaut <76531574+malespiaut@users.noreply.github.com> Date: Mon, 27 May 2024 11:10:14 +0200 Subject: [PATCH 25/60] Fixing some vector types error in vtkQuakeMDLReader. --- plugins/native/module/vtkQuakeMDLReader.cxx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/native/module/vtkQuakeMDLReader.cxx b/plugins/native/module/vtkQuakeMDLReader.cxx index daa5d5e419..94a407ee74 100644 --- a/plugins/native/module/vtkQuakeMDLReader.cxx +++ b/plugins/native/module/vtkQuakeMDLReader.cxx @@ -40,7 +40,7 @@ int vtkQuakeMDLReader::RequestData( size_t nbSplats = buffer.size() / splatSize; // identity ("IDPO"): 4 chars (4 bytes) - vtkNew IDPOArray; + vtkNew IDPOArray; IDPOArray->SetNumberOfComponents(4); IDPOArray->SetNumberOfTuples(nbSplats); IDPOArray->SetName("identity"); @@ -112,7 +112,7 @@ int vtkQuakeMDLReader::RequestData( trianglesNum->SetName("number of triangles"); // number of frames: 1 int (4 bytes) - vtkNew framesNum; + vtkNew framesNum; framesNum->SetNumberOfComponents(1); framesNum->SetNumberOfTuples(nbSplats); framesNum->SetName("number of frames"); @@ -146,13 +146,13 @@ int vtkQuakeMDLReader::RequestData( scale->SetName("scale"); // rotation: 4 chars (4 bytes) - vtkNew rotation; + vtkNew rotation; rotation->SetNumberOfComponents(4); rotation->SetNumberOfTuples(nbSplats); rotation->SetName("rotation"); // color+opacity: 4 chars (4 bytes) - vtkNew colorAndOpacity; + vtkNew colorAndOpacity; colorAndOpacity->SetNumberOfComponents(4); colorAndOpacity->SetNumberOfTuples(nbSplats); colorAndOpacity->SetName("color and opacity"); From 417e8572b90bac136be25f6755c45272aa4afbfa Mon Sep 17 00:00:00 2001 From: Marc-Alexandre Espiaut <76531574+malespiaut@users.noreply.github.com> Date: Mon, 27 May 2024 11:12:07 +0200 Subject: [PATCH 26/60] Fixing some formatting error (whitespaces) in vtkQuakeMDLReader. --- plugins/native/module/vtkQuakeMDLReader.cxx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/native/module/vtkQuakeMDLReader.cxx b/plugins/native/module/vtkQuakeMDLReader.cxx index 94a407ee74..03f2a1fc0b 100644 --- a/plugins/native/module/vtkQuakeMDLReader.cxx +++ b/plugins/native/module/vtkQuakeMDLReader.cxx @@ -78,19 +78,19 @@ int vtkQuakeMDLReader::RequestData( eyePosition->SetName("eye position"); //==================================== - + // number of textures: 1 int (4 bytes) vtkNew texturesNum; texturesNum->SetNumberOfComponents(1); texturesNum->SetNumberOfTuples(nbSplats); texturesNum->SetName("number of textures"); - + // texture width: 1 int (4 bytes) vtkNew textureWidth; textureWidth->SetNumberOfComponents(1); texturesWidth->SetNumberOfTuples(nbSplats); textureWidth->SetName("texture width"); - + // texture height: 1 int (4 bytes) vtkNew textureHeight; textureHeight->SetNumberOfComponents(1); From 417aa5b06a3ee2e9db70d3a182c792be75f2dc3e Mon Sep 17 00:00:00 2001 From: Marc-Alexandre Espiaut <76531574+malespiaut@users.noreply.github.com> Date: Mon, 27 May 2024 11:13:13 +0200 Subject: [PATCH 27/60] Fixing typo in vtkQuakeMDLReader. --- plugins/native/module/vtkQuakeMDLReader.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/native/module/vtkQuakeMDLReader.cxx b/plugins/native/module/vtkQuakeMDLReader.cxx index 03f2a1fc0b..aa36a061f7 100644 --- a/plugins/native/module/vtkQuakeMDLReader.cxx +++ b/plugins/native/module/vtkQuakeMDLReader.cxx @@ -88,7 +88,7 @@ int vtkQuakeMDLReader::RequestData( // texture width: 1 int (4 bytes) vtkNew textureWidth; textureWidth->SetNumberOfComponents(1); - texturesWidth->SetNumberOfTuples(nbSplats); + textureWidth->SetNumberOfTuples(nbSplats); textureWidth->SetName("texture width"); // texture height: 1 int (4 bytes) From c7ec80715957e5d8b6d92e0c7139891beaf7fcf9 Mon Sep 17 00:00:00 2001 From: Marc-Alexandre Espiaut <76531574+malespiaut@users.noreply.github.com> Date: Sun, 2 Jun 2024 12:43:26 +0200 Subject: [PATCH 28/60] Cleaning out unnecessary code. --- plugins/native/module/vtkQuakeMDLReader.cxx | 26 --------------------- 1 file changed, 26 deletions(-) diff --git a/plugins/native/module/vtkQuakeMDLReader.cxx b/plugins/native/module/vtkQuakeMDLReader.cxx index aa36a061f7..15ff7d4a70 100644 --- a/plugins/native/module/vtkQuakeMDLReader.cxx +++ b/plugins/native/module/vtkQuakeMDLReader.cxx @@ -31,24 +31,14 @@ int vtkQuakeMDLReader::RequestData( std::ifstream inputStream(this->FileName, std::ios::binary); - std::vector buffer(std::istreambuf_iterator(inputStream), {}); - - //??? What's a “splat”??? - constexpr size_t splatSize = 32; - - //??? What is nbSplats??? - size_t nbSplats = buffer.size() / splatSize; - // identity ("IDPO"): 4 chars (4 bytes) vtkNew IDPOArray; IDPOArray->SetNumberOfComponents(4); - IDPOArray->SetNumberOfTuples(nbSplats); IDPOArray->SetName("identity"); // version: 1 int (4 bytes) vtkNew version; version->SetNumberOfComponents(1); - version->SetNumberOfTuples(nbSplats); version->SetName("version"); //==================================== @@ -56,25 +46,21 @@ int vtkQuakeMDLReader::RequestData( // scaling factor: 3 floats (12 bytes) vtkNew scalingFactor; scalingFactor->SetNumberOfComponents(3); - scalingFactor->SetNumberOfTuples(nbSplats); scalingFactor->SetName("scaling factor"); // translation vector: 3 floats (12 bytes) vtkNew translationVector; translationVector->SetNumberOfComponents(3); - translationVector->SetNumberOfTuples(nbSplats); translationVector->SetName("translation vector"); // bounding radius: 1 float (4 bytes) vtkNew boundingRadius; boundingRadius->SetNumberOfComponents(1); - boundingRadius->SetNumberOfTuples(nbSplats); boundingRadius->SetName("bounding radius"); // eye position: 3 floats (12 bytes) vtkNew eyePosition; eyePosition->SetNumberOfComponents(3); - eyePosition->SetNumberOfTuples(nbSplats); eyePosition->SetName("eye position"); //==================================== @@ -82,19 +68,16 @@ int vtkQuakeMDLReader::RequestData( // number of textures: 1 int (4 bytes) vtkNew texturesNum; texturesNum->SetNumberOfComponents(1); - texturesNum->SetNumberOfTuples(nbSplats); texturesNum->SetName("number of textures"); // texture width: 1 int (4 bytes) vtkNew textureWidth; textureWidth->SetNumberOfComponents(1); - textureWidth->SetNumberOfTuples(nbSplats); textureWidth->SetName("texture width"); // texture height: 1 int (4 bytes) vtkNew textureHeight; textureHeight->SetNumberOfComponents(1); - textureHeight->SetNumberOfTuples(nbSplats); textureHeight->SetName("texture height"); //==================================== @@ -102,19 +85,16 @@ int vtkQuakeMDLReader::RequestData( // number of vertices: 1 int (4 bytes) vtkNew verticesNum; verticesNum->SetNumberOfComponents(1); - verticesNum->SetNumberOfTuples(nbSplats); verticesNum->SetName("number of vertices"); // number of triangles: 1 int (4 bytes) vtkNew trianglesNum; trianglesNum->SetNumberOfComponents(1); - trianglesNum->SetNumberOfTuples(nbSplats); trianglesNum->SetName("number of triangles"); // number of frames: 1 int (4 bytes) vtkNew framesNum; framesNum->SetNumberOfComponents(1); - framesNum->SetNumberOfTuples(nbSplats); framesNum->SetName("number of frames"); //==================================== @@ -122,13 +102,11 @@ int vtkQuakeMDLReader::RequestData( // sync type (0: synchron, 1: random): 1 int (4 bytes) vtkNew syncType; syncType->SetNumberOfComponents(1); - syncType->SetNumberOfTuples(nbSplats); syncType->SetName("sync type"); // state flags: 1 int (4 bytes) vtkNew stateFlags; stateFlags->SetNumberOfComponents(1); - stateFlags->SetNumberOfTuples(nbSplats); stateFlags->SetName("state flags"); //==================================== @@ -136,25 +114,21 @@ int vtkQuakeMDLReader::RequestData( // position: 3 floats (12 bytes) vtkNew position; position->SetNumberOfComponents(3); - position->SetNumberOfTuples(nbSplats); position->SetName("position"); // scale: 3 floats (12 bytes) vtkNew scale; scale->SetNumberOfComponents(3); - scale->SetNumberOfTuples(nbSplats); scale->SetName("scale"); // rotation: 4 chars (4 bytes) vtkNew rotation; rotation->SetNumberOfComponents(4); - rotation->SetNumberOfTuples(nbSplats); rotation->SetName("rotation"); // color+opacity: 4 chars (4 bytes) vtkNew colorAndOpacity; colorAndOpacity->SetNumberOfComponents(4); - colorAndOpacity->SetNumberOfTuples(nbSplats); colorAndOpacity->SetName("color and opacity"); return 1; From 54ea9d3c27a52425a66f2bd5d40a61364741f13e Mon Sep 17 00:00:00 2001 From: Youva Date: Sun, 25 Aug 2024 13:01:15 -0400 Subject: [PATCH 29/60] Add importer --- plugins/alembic/module/vtkF3DAlembicReader.h | 1 - plugins/native/module/vtkQuakeMDLImporter.cxx | 750 ++++++++++++++++++ plugins/native/module/vtkQuakeMDLImporter.h | 135 ++++ plugins/native/module/vtkQuakeMDLReader.cxx | 135 ---- plugins/native/module/vtkQuakeMDLReader.h | 35 - 5 files changed, 885 insertions(+), 171 deletions(-) create mode 100644 plugins/native/module/vtkQuakeMDLImporter.cxx create mode 100644 plugins/native/module/vtkQuakeMDLImporter.h delete mode 100644 plugins/native/module/vtkQuakeMDLReader.cxx delete mode 100644 plugins/native/module/vtkQuakeMDLReader.h diff --git a/plugins/alembic/module/vtkF3DAlembicReader.h b/plugins/alembic/module/vtkF3DAlembicReader.h index 19940cbbee..cb09a53823 100644 --- a/plugins/alembic/module/vtkF3DAlembicReader.h +++ b/plugins/alembic/module/vtkF3DAlembicReader.h @@ -17,7 +17,6 @@ #include #include #include - #include class vtkF3DAlembicReader : public vtkPolyDataAlgorithm diff --git a/plugins/native/module/vtkQuakeMDLImporter.cxx b/plugins/native/module/vtkQuakeMDLImporter.cxx new file mode 100644 index 0000000000..e714f95f4a --- /dev/null +++ b/plugins/native/module/vtkQuakeMDLImporter.cxx @@ -0,0 +1,750 @@ +#include "vtkQuakeMDLImporter.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//---------------------------------------------------------------------------- +vtkStandardNewMacro(vtkQuakeMDLImporter); + + +class vtkQuakeMDLImporter::vtkInternals +{ +public: + //---------------------------------------------------------------------------- + explicit vtkInternals(vtkQuakeMDLImporter* parent) + : Parent(parent) + { + } + + //---------------------------------------------------------------------------- + void ImportCameras(vtkRenderer* renderer) + { + + } + + //---------------------------------------------------------------------------- + void ImportLights(vtkRenderer* renderer) + { + } + + //---------------------------------------------------------------------------- + vtkSmartPointer CreateTexture(std::vector buffer, int& offset, int skinWidth, + int skinHeight, int nbSkins, int selectedSkinIndex) + { + vtkNew texture; + texture->SetWrap(3); + + struct mdl_skin_t + { + int group; /* 0 = single, 1 = group */ + unsigned char* data; /* texture data */ + }; + struct mdl_groupskin_t + { + int group; /* 1 = group */ + int nb; /* number of pics */ + float* time; /* time duration for each pic */ + unsigned char** data; /* texture data */ + }; + struct mixed_pointer_array + { + int group; + unsigned char* skin; + }; + mixed_pointer_array* skins = new mixed_pointer_array[nbSkins]; + unsigned char* skin = reinterpret_cast(buffer.data() + offset + 4); + for (int i = 0; i < nbSkins; i++) + { + int* group = reinterpret_cast(buffer.data() + offset); + if (*group == 0) + { + skins[i].group = 0; + skins[i].skin = reinterpret_cast(buffer.data() + 4 + offset); + offset += 4 + (skinWidth) * (skinHeight); + } + else + { + skins[i].group = 1; + int nb = *reinterpret_cast(buffer.data() + offset + 4); + skins[i].skin = reinterpret_cast(buffer.data() + 4 + nb * 4 + offset); + offset += 4 + nb * 4 + nb * (skinWidth) * (skinHeight); + } + } + vtkNew reader; + reader->SetFileName("C:\\\\Users\\Youva\\Downloads\\quake\\Untitled.png"); + reader->Update(); + + vtkNew writer; + writer->SetFileName("C:\\\\Users\\Youva\\Downloads\\skin2.png"); + vtkNew img; + img->SetDimensions(skinWidth, skinHeight, 1); + img->AllocateScalars(VTK_UNSIGNED_CHAR, 3); + unsigned char* selectedSkin = skins[selectedSkinIndex].skin; + for (int i = 0; i < skinHeight ; i++) + { + for (int j = 0; j < skinWidth; j++) + { + unsigned char index = *reinterpret_cast(selectedSkin + i * skinWidth + j); + unsigned char* ptr = reinterpret_cast(img->GetScalarPointer(j,i,0)); + ptr[0] = DefaultColorMap[index][0]; // R + ptr[1] = DefaultColorMap[index][1]; // G + ptr[2] = DefaultColorMap[index][2]; // B + } + } + + writer->SetInputData(img); + writer->Write(); + texture->SetInputData(img); + // texture->SetInputConnection(reader->GetOutputPort()); + + return texture; + } + + + void CreateMesh(std::vector buffer, int& offset, mdl_header_t* header, int selectedFrameIndex) + { + // Read texture coordinates + struct mdl_texcoord_t + { + int onseam; + int s; + int t; + }; + mdl_texcoord_t* texcoords = reinterpret_cast(buffer.data() + offset); + offset += 12 * header->numVertices; + // Read triangles + struct mdl_triangle_t + { + int facesfront; /* 0 = backface, 1 = frontface */ + int vertex[3]; /* vertex indices */ + }; + mdl_triangle_t* triangles = reinterpret_cast(buffer.data() + offset); + offset += 16 * header->numTriangles; + // Read frames + struct mdl_vertex_t // 4 bytes + { + unsigned char v[3]; + unsigned char normalIndex; + }; + struct mdl_simpleframe_t // 24 + nbVertices bytes + { + mdl_vertex_t bboxmin; + mdl_vertex_t bboxmax; + char name[16]; + mdl_vertex_t verts[1024]; // Maximum capacity is 1024 vertices + }; + struct mdl_frame_t + { + int type; + mdl_simpleframe_t frame; + }; + struct mdl_groupframe_t + { + int type; + int nb; + mdl_vertex_t min; + mdl_vertex_t max; + float* time; // Size is nbFrames ??? + mdl_simpleframe_t* frames; // Size is nbFrames ??? + }; + + struct plugin_frame_pointer + { + int* type; + int* nb; + float* time; + mdl_simpleframe_t* frames; + }; + plugin_frame_pointer* framePtr = new plugin_frame_pointer[header->numFrames]; + for (int i = 0; i < header->numFrames; i++) + { + int* type = reinterpret_cast(buffer.data() + offset); + if (*type == 0) + { + framePtr[i].type = type; + framePtr[i].nb = nullptr; + framePtr[i].time = nullptr; + framePtr[i].frames = reinterpret_cast(buffer.data() + 4 + offset); + offset += 4 + 24 + 4 * (header->numVertices); + } + else + { + framePtr[i].type = type; + framePtr[i].nb = reinterpret_cast(buffer.data() + 4 + offset); + mdl_vertex_t* min = reinterpret_cast(buffer.data() + 8 + offset); + mdl_vertex_t* max = reinterpret_cast(buffer.data() + 12 + offset); + float* time = + framePtr[i].time = reinterpret_cast(buffer.data() + 16 + offset); + framePtr[i].frames = + reinterpret_cast(buffer.data() + 16 + 4 * (*framePtr[i].nb) + offset); + offset += 16 + (*framePtr[i].nb) * 4; + for (int j = 0; j < *framePtr[i].nb; j++) + { + offset += 24 + 4 * header->numVertices; + } + } + } + // Draw cells + vtkNew cells; + cells->Allocate(header->numTriangles); + vtkNew textureCoordinates; + textureCoordinates->SetNumberOfComponents(2); + textureCoordinates->SetName("TextureCoordinates"); + textureCoordinates->Allocate(header->numVertices * 2); + struct plugin_texture_coords + { + float s; + float t; + int id; + }; + plugin_texture_coords* coords = new plugin_texture_coords[header->numVertices]; + for (int i = 0; i < header->numTriangles; i++) + { + vtkIdType* vertexNum = new vtkIdType[3]; + for (int j = 0; j < 3; j++) + { + vertexNum[j] = triangles[i].vertex[j]; + int onseam_correct = 1; + float s = texcoords[vertexNum[j]].s; + float t = texcoords[vertexNum[j]].t; + if ( !triangles[i].facesfront && texcoords[vertexNum[j]].onseam) + { + s = s + header->skinWidth * 0.5f; + } + s = (s + 0.5) / header->skinWidth; + t = (t + 0.5) / header->skinHeight; + coords[vertexNum[j]].s = s; + coords[vertexNum[j]].t = t; + coords[vertexNum[j]].id = vertexNum[j]; + } + cells->InsertNextCell(3, vertexNum); + } + // Add texture coords + for (int i = 0; i < header->numVertices; i++) + { + float* s_t = new float[2]; + s_t[0] = coords[i].s; + s_t[1] = coords[i].t; + textureCoordinates->InsertNextTuple(s_t); + } + + + // Draw vertices + std::string frameName = ""; + int frameIndex = 0; + for (int frameNum = 0; frameNum < header->numFrames; frameNum++) + { + vtkNew vertices; + vertices->Allocate(header->numVertices); + vtkNew normals; + normals->SetNumberOfComponents(3); + normals->Allocate(header->numVertices * 3); + plugin_frame_pointer selectedFrame = framePtr[frameNum]; + if (*selectedFrame.type == 0) + { + for (int i = 0; i < header->numTriangles; i++) + { + vtkIdType* vertexNum = new vtkIdType[3]; + for (int j = 0; j < 3; j++) + { + vertexNum[j] = triangles[i].vertex[j]; + double v[3] = { selectedFrame.frames->verts[vertexNum[j]].v[0], + selectedFrame.frames->verts[vertexNum[j]].v[1], + selectedFrame.frames->verts[vertexNum[j]].v[2] }; + for (int k = 0; k < 3; k++) + { + v[k] = v[k] * header->scale[k] + header->translation[k]; + } + vertices->InsertPoint(vertexNum[j], v); + int normalIndex = selectedFrame.frames->verts[vertexNum[j]].normalIndex; + normals->SetTuple3(vertexNum[j], NormalVectors[normalIndex][0] / 255.0, + NormalVectors[normalIndex][1] / 255.0, NormalVectors[normalIndex][2] / 255.0); + } + } + vtkNew mesh; + mesh->SetPoints(vertices); + mesh->SetPolys(cells); + mesh->GetPointData()->SetTCoords(textureCoordinates); + mesh->GetPointData()->SetNormals(normals); + Mesh.push_back(mesh); + std::string meshName = std::string(selectedFrame.frames->name); + for (int i = 0; i < meshName.size(); i++) + { + if (meshName[i] >= '0' && meshName[i] <= '9') + { + meshName = meshName.substr(0, i); + break; + } + } + if (frameNum == 0) + { + frameName = meshName; + } + else if (meshName != frameName) + { + frameIndex++; + frameName = meshName; + NumberOfAnimations++; + } + std::pair pair = std::make_pair(frameIndex, 0.0); + GroupAndTimeVal.push_back(pair); + } + else + { + for (int groupFrameNum = 0; groupFrameNum < *selectedFrame.nb; groupFrameNum++) + { + for (int i = 0; i < header->numTriangles; i++) + { + vtkIdType* vertexNum = new vtkIdType[3]; + for (int j = 0; j < 3; j++) + { + vertexNum[j] = triangles[i].vertex[j]; + double v[3] = { selectedFrame.frames[groupFrameNum].verts[vertexNum[j]].v[0], + selectedFrame.frames[groupFrameNum].verts[vertexNum[j]].v[1], + selectedFrame.frames[groupFrameNum].verts[vertexNum[j]].v[2] }; + for (int k = 0; k < 3; k++) + { + v[k] = v[k] * header->scale[k] + header->translation[k]; + } + vertices->InsertPoint(vertexNum[j], v); + int normalIndex = selectedFrame.frames[groupFrameNum].verts[vertexNum[j]].normalIndex; + normals->SetTuple3(vertexNum[j], NormalVectors[normalIndex][0] / 255.0, + NormalVectors[normalIndex][1] / 255.0, NormalVectors[normalIndex][2] / 255.0); + } + } + vtkNew mesh; + mesh->SetPoints(vertices); + mesh->SetPolys(cells); + mesh->GetPointData()->SetTCoords(textureCoordinates); + mesh->GetPointData()->SetNormals(normals); + Mesh.push_back(mesh); + std::string meshName = std::string(selectedFrame.frames[groupFrameNum].name); + for (int i = 0; i < meshName.size(); i++) + { + if (meshName[i] >= '0' && meshName[i] <= '9') + { + meshName = meshName.substr(0, i - 1); + break; + } + } + if (frameNum == 0) + { + frameName = meshName; + } + else if (meshName != frameName) + { + frameIndex++; + NumberOfAnimations++; + frameName = meshName; + } + std::pair pair = std::make_pair(frameIndex, selectedFrame.time[groupFrameNum]); + GroupAndTimeVal.push_back(pair); + } + } + } + + // Add interpolated frames + for (int i = 0; i < Mesh.size() - 1; i++) + { + if (GroupAndTimeVal[i + 1].first != GroupAndTimeVal[i].first) + { + continue; + } + else + { + vtkNew vertices; + vertices->Allocate(header->numVertices); + vtkNew normals; + normals->SetNumberOfComponents(3); + normals->Allocate(header->numVertices * 3); + for (int j = 0; j < header->numVertices; j++) + { + double* v_0 = Mesh[i]->GetPoint(j); + double* v_1 = Mesh[i+1]->GetPoint(j); + double* interp = new double[3]; + interp[0] = v_0[0] + 0.5 * (v_1[0] - v_0[0]); + interp[1] = v_0[1] + 0.5 * (v_1[1] - v_0[1]); + interp[2] = v_0[2] + 0.5 * (v_1[2] - v_0[2]); + vertices->InsertPoint(j, interp); + } + vtkNew mesh; + mesh->SetPoints(vertices); + mesh->SetPolys(cells); + mesh->GetPointData()->SetTCoords(textureCoordinates); + Mesh.insert(Mesh.begin() + i, mesh); + std::pair pair = std::make_pair(GroupAndTimeVal[i].first, + (GroupAndTimeVal[i].second + GroupAndTimeVal[i + 1].second) / 2); + GroupAndTimeVal.insert(GroupAndTimeVal.begin() + i, pair); + i++; + } + } + } + + //---------------------------------------------------------------------------- + bool ReadScene(const std::string& filePath) + { + std::ifstream inputStream(filePath, std::ios::binary); + + std::vector buffer(std::istreambuf_iterator(inputStream), {}); + + + // Read header + mdl_header_t* header = reinterpret_cast(buffer.data()); + int offset = 84; + + // Set textures + Texture= this->CreateTexture( + buffer, offset, header->skinWidth, header->skinHeight, header->numSkins, 0); + + + // Set polyData + this->CreateMesh(buffer, offset, header, 0); + + + + return 1; + } + + void UpdateFrame(double timeValue) + { + // Hardcoded frames per second + if (abs(timeValue - LastRenderTime) > 1.0 / 60) + { + Mapper->SetInputData( + Mesh[(CurrentFrameIndex++) % (LastFrameIndex - FirstFrameIndex) + FirstFrameIndex]); + LastRenderTime = timeValue; + } + } + + // Only one animation enabled at a time + void EnableAnimation(vtkIdType animationIndex) + { + int i = 0; + while (i < GroupAndTimeVal.size() && GroupAndTimeVal[++i].first < animationIndex) + { + } + FirstFrameIndex = animationIndex == 0 ? 0 : LastFrameIndex + 1; + while (i < GroupAndTimeVal.size() && GroupAndTimeVal[++i].first == animationIndex) + { + } + LastFrameIndex = i-1; + } + + void ImportActors(vtkRenderer* renderer) + { + vtkNew actor; + vtkNew mapper; + mapper->SetInputData(Mesh[0]); + //Mesh); + actor->SetMapper(mapper); + actor->SetTexture(Texture); + renderer->AddActor(actor); + renderer->SetBackground(0, 0, 0); + + Actor = actor; + Mapper = mapper; + } + + void UpdateNodeTransform() + { + } + + void UpdateCameras() + { + } + + void UpdateLights() + { + + } + + + vtkQuakeMDLImporter* Parent; + std::string Description; + vtkSmartPointer Actor; + vtkSmartPointer Mapper; + std::vector> Mesh; + std::vector > GroupAndTimeVal; + int ActiveAnimationId = 0; + int CurrentFrameIndex = 0; + int FirstFrameIndex = 0; + int LastFrameIndex = 10; + int NumberOfAnimations = 0; + double LastRenderTime = 0.0; + vtkSmartPointer Texture; + vtkSmartPointer TextureCoords; + unsigned char DefaultColorMap[256][3] = { { 0, 0, 0 }, { 15, 15, 15 }, { 31, 31, 31 }, + { 47, 47, 47 }, { 63, 63, 63 }, { 75, 75, 75 }, { 91, 91, 91 }, { 107, 107, 107 }, + { 123, 123, 123 }, { 139, 139, 139 }, { 155, 155, 155 }, { 171, 171, 171 }, { 187, 187, 187 }, + { 203, 203, 203 }, { 219, 219, 219 }, { 235, 235, 235 }, { 15, 11, 7 }, { 23, 15, 11 }, + { 31, 23, 11 }, { 39, 27, 15 }, { 47, 35, 19 }, { 55, 43, 23 }, { 63, 47, 23 }, { 75, 55, 27 }, + { 83, 59, 27 }, { 91, 67, 31 }, { 99, 75, 31 }, { 107, 83, 31 }, { 115, 87, 31 }, + { 123, 95, 35 }, { 131, 103, 35 }, { 143, 111, 35 }, { 11, 11, 15 }, { 19, 19, 27 }, + { 27, 27, 39 }, { 39, 39, 51 }, { 47, 47, 63 }, { 55, 55, 75 }, { 63, 63, 87 }, { 71, 71, 103 }, + { 79, 79, 115 }, { 91, 91, 127 }, { 99, 99, 139 }, { 107, 107, 151 }, { 115, 115, 163 }, + { 123, 123, 175 }, { 131, 131, 187 }, { 139, 139, 203 }, { 0, 0, 0 }, { 7, 7, 0 }, + { 11, 11, 0 }, { 19, 19, 0 }, { 27, 27, 0 }, { 35, 35, 0 }, { 43, 43, 7 }, { 47, 47, 7 }, + { 55, 55, 7 }, { 63, 63, 7 }, { 71, 71, 7 }, { 75, 75, 11 }, { 83, 83, 11 }, { 91, 91, 11 }, + { 99, 99, 11 }, { 107, 107, 15 }, { 7, 0, 0 }, { 15, 0, 0 }, { 23, 0, 0 }, { 31, 0, 0 }, + { 39, 0, 0 }, { 47, 0, 0 }, { 55, 0, 0 }, { 63, 0, 0 }, { 71, 0, 0 }, { 79, 0, 0 }, + { 87, 0, 0 }, { 95, 0, 0 }, { 103, 0, 0 }, { 111, 0, 0 }, { 119, 0, 0 }, { 127, 0, 0 }, + { 19, 19, 0 }, { 27, 27, 0 }, { 35, 35, 0 }, { 47, 43, 0 }, { 55, 47, 0 }, { 67, 55, 0 }, + { 75, 59, 7 }, { 87, 67, 7 }, { 95, 71, 7 }, { 107, 75, 11 }, { 119, 83, 15 }, { 131, 87, 19 }, + { 139, 91, 19 }, { 151, 95, 27 }, { 163, 99, 31 }, { 175, 103, 35 }, { 35, 19, 7 }, + { 47, 23, 11 }, { 59, 31, 15 }, { 75, 35, 19 }, { 87, 43, 23 }, { 99, 47, 31 }, { 115, 55, 35 }, + { 127, 59, 43 }, { 143, 67, 51 }, { 159, 79, 51 }, { 175, 99, 47 }, { 191, 119, 47 }, + { 207, 143, 43 }, { 223, 171, 39 }, { 239, 203, 31 }, { 255, 243, 27 }, { 11, 7, 0 }, + { 27, 19, 0 }, { 43, 35, 15 }, { 55, 43, 19 }, { 71, 51, 27 }, { 83, 55, 35 }, { 99, 63, 43 }, + { 111, 71, 51 }, { 127, 83, 63 }, { 139, 95, 71 }, { 155, 107, 83 }, { 167, 123, 95 }, + { 183, 135, 107 }, { 195, 147, 123 }, { 211, 163, 139 }, { 227, 179, 151 }, { 171, 139, 163 }, + { 159, 127, 151 }, { 147, 115, 135 }, { 139, 103, 123 }, { 127, 91, 111 }, { 119, 83, 99 }, + { 107, 75, 87 }, { 95, 63, 75 }, { 87, 55, 67 }, { 75, 47, 55 }, { 67, 39, 47 }, { 55, 31, 35 }, + { 43, 23, 27 }, { 35, 19, 19 }, { 23, 11, 11 }, { 15, 7, 7 }, { 187, 115, 159 }, + { 175, 107, 143 }, { 163, 95, 131 }, { 151, 87, 119 }, { 139, 79, 107 }, { 127, 75, 95 }, + { 115, 67, 83 }, { 107, 59, 75 }, { 95, 51, 63 }, { 83, 43, 55 }, { 71, 35, 43 }, + { 59, 31, 35 }, { 47, 23, 27 }, { 35, 19, 19 }, { 23, 11, 11 }, { 15, 7, 7 }, { 219, 195, 187 }, + { 203, 179, 167 }, { 191, 163, 155 }, { 175, 151, 139 }, { 163, 135, 123 }, { 151, 123, 111 }, + { 135, 111, 95 }, { 123, 99, 83 }, { 107, 87, 71 }, { 95, 75, 59 }, { 83, 63, 51 }, + { 67, 51, 39 }, { 55, 43, 31 }, { 39, 31, 23 }, { 27, 19, 15 }, { 15, 11, 7 }, + { 111, 131, 123 }, { 103, 123, 111 }, { 95, 115, 103 }, { 87, 107, 95 }, { 79, 99, 87 }, + { 71, 91, 79 }, { 63, 83, 71 }, { 55, 75, 63 }, { 47, 67, 55 }, { 43, 59, 47 }, { 35, 51, 39 }, + { 31, 43, 31 }, { 23, 35, 23 }, { 15, 27, 19 }, { 11, 19, 11 }, { 7, 11, 7 }, { 255, 243, 27 }, + { 239, 223, 23 }, { 219, 203, 19 }, { 203, 183, 15 }, { 187, 167, 15 }, { 171, 151, 11 }, + { 155, 131, 7 }, { 139, 115, 7 }, { 123, 99, 7 }, { 107, 83, 0 }, { 91, 71, 0 }, { 75, 55, 0 }, + { 59, 43, 0 }, { 43, 31, 0 }, { 27, 15, 0 }, { 11, 7, 0 }, { 0, 0, 255 }, { 11, 11, 239 }, + { 19, 19, 223 }, { 27, 27, 207 }, { 35, 35, 191 }, { 43, 43, 175 }, { 47, 47, 159 }, + { 47, 47, 143 }, { 47, 47, 127 }, { 47, 47, 111 }, { 47, 47, 95 }, { 43, 43, 79 }, + { 35, 35, 63 }, { 27, 27, 47 }, { 19, 19, 31 }, { 11, 11, 15 }, { 43, 0, 0 }, { 59, 0, 0 }, + { 75, 7, 0 }, { 95, 7, 0 }, { 111, 15, 0 }, { 127, 23, 7 }, { 147, 31, 7 }, { 163, 39, 11 }, + { 183, 51, 15 }, { 195, 75, 27 }, { 207, 99, 43 }, { 219, 127, 59 }, { 227, 151, 79 }, + { 231, 171, 95 }, { 239, 191, 119 }, { 247, 211, 139 }, { 167, 123, 59 }, { 183, 155, 55 }, + { 199, 195, 55 }, { 231, 227, 87 }, { 127, 191, 255 }, { 171, 231, 255 }, { 215, 255, 255 }, + { 103, 0, 0 }, { 139, 0, 0 }, { 179, 0, 0 }, { 215, 0, 0 }, { 255, 0, 0 }, { 255, 243, 147 }, + { 255, 247, 199 }, { 255, 255, 255 }, { 159, 91, 83 } }; + float NormalVectors[162][3] = { { -0.525731f, 0.000000f, 0.850651f }, + { -0.442863f, 0.238856f, 0.864188f }, { -0.295242f, 0.000000f, 0.955423f }, + { -0.309017f, 0.500000f, 0.809017f }, { -0.162460f, 0.262866f, 0.951056f }, + { 0.000000f, 0.000000f, 1.000000f }, { 0.000000f, 0.850651f, 0.525731f }, + { -0.147621f, 0.716567f, 0.681718f }, { 0.147621f, 0.716567f, 0.681718f }, + { 0.000000f, 0.525731f, 0.850651f }, { 0.309017f, 0.500000f, 0.809017f }, + { 0.525731f, 0.000000f, 0.850651f }, { 0.295242f, 0.000000f, 0.955423f }, + { 0.442863f, 0.238856f, 0.864188f }, { 0.162460f, 0.262866f, 0.951056f }, + { -0.681718f, 0.147621f, 0.716567f }, { -0.809017f, 0.309017f, 0.500000f }, + { -0.587785f, 0.425325f, 0.688191f }, { -0.850651f, 0.525731f, 0.000000f }, + { -0.864188f, 0.442863f, 0.238856f }, { -0.716567f, 0.681718f, 0.147621f }, + { -0.688191f, 0.587785f, 0.425325f }, { -0.500000f, 0.809017f, 0.309017f }, + { -0.238856f, 0.864188f, 0.442863f }, { -0.425325f, 0.688191f, 0.587785f }, + { -0.716567f, 0.681718f, -0.147621f }, { -0.500000f, 0.809017f, -0.309017f }, + { -0.525731f, 0.850651f, 0.000000f }, { 0.000000f, 0.850651f, -0.525731f }, + { -0.238856f, 0.864188f, -0.442863f }, { 0.000000f, 0.955423f, -0.295242f }, + { -0.262866f, 0.951056f, -0.162460f }, { 0.000000f, 1.000000f, 0.000000f }, + { 0.000000f, 0.955423f, 0.295242f }, { -0.262866f, 0.951056f, 0.162460f }, + { 0.238856f, 0.864188f, 0.442863f }, { 0.262866f, 0.951056f, 0.162460f }, + { 0.500000f, 0.809017f, 0.309017f }, { 0.238856f, 0.864188f, -0.442863f }, + { 0.262866f, 0.951056f, -0.162460f }, { 0.500000f, 0.809017f, -0.309017f }, + { 0.850651f, 0.525731f, 0.000000f }, { 0.716567f, 0.681718f, 0.147621f }, + { 0.716567f, 0.681718f, -0.147621f }, { 0.525731f, 0.850651f, 0.000000f }, + { 0.425325f, 0.688191f, 0.587785f }, { 0.864188f, 0.442863f, 0.238856f }, + { 0.688191f, 0.587785f, 0.425325f }, { 0.809017f, 0.309017f, 0.500000f }, + { 0.681718f, 0.147621f, 0.716567f }, { 0.587785f, 0.425325f, 0.688191f }, + { 0.955423f, 0.295242f, 0.000000f }, { 1.000000f, 0.000000f, 0.000000f }, + { 0.951056f, 0.162460f, 0.262866f }, { 0.850651f, -0.525731f, 0.000000f }, + { 0.955423f, -0.295242f, 0.000000f }, { 0.864188f, -0.442863f, 0.238856f }, + { 0.951056f, -0.162460f, 0.262866f }, { 0.809017f, -0.309017f, 0.500000f }, + { 0.681718f, -0.147621f, 0.716567f }, { 0.850651f, 0.000000f, 0.525731f }, + { 0.864188f, 0.442863f, -0.238856f }, { 0.809017f, 0.309017f, -0.500000f }, + { 0.951056f, 0.162460f, -0.262866f }, { 0.525731f, 0.000000f, -0.850651f }, + { 0.681718f, 0.147621f, -0.716567f }, { 0.681718f, -0.147621f, -0.716567f }, + { 0.850651f, 0.000000f, -0.525731f }, { 0.809017f, -0.309017f, -0.500000f }, + { 0.864188f, -0.442863f, -0.238856f }, { 0.951056f, -0.162460f, -0.262866f }, + { 0.147621f, 0.716567f, -0.681718f }, { 0.309017f, 0.500000f, -0.809017f }, + { 0.425325f, 0.688191f, -0.587785f }, { 0.442863f, 0.238856f, -0.864188f }, + { 0.587785f, 0.425325f, -0.688191f }, { 0.688191f, 0.587785f, -0.425325f }, + { -0.147621f, 0.716567f, -0.681718f }, { -0.309017f, 0.500000f, -0.809017f }, + { 0.000000f, 0.525731f, -0.850651f }, { -0.525731f, 0.000000f, -0.850651f }, + { -0.442863f, 0.238856f, -0.864188f }, { -0.295242f, 0.000000f, -0.955423f }, + { -0.162460f, 0.262866f, -0.951056f }, { 0.000000f, 0.000000f, -1.000000f }, + { 0.295242f, 0.000000f, -0.955423f }, { 0.162460f, 0.262866f, -0.951056f }, + { -0.442863f, -0.238856f, -0.864188f }, { -0.309017f, -0.500000f, -0.809017f }, + { -0.162460f, -0.262866f, -0.951056f }, { 0.000000f, -0.850651f, -0.525731f }, + { -0.147621f, -0.716567f, -0.681718f }, { 0.147621f, -0.716567f, -0.681718f }, + { 0.000000f, -0.525731f, -0.850651f }, { 0.309017f, -0.500000f, -0.809017f }, + { 0.442863f, -0.238856f, -0.864188f }, { 0.162460f, -0.262866f, -0.951056f }, + { 0.238856f, -0.864188f, -0.442863f }, { 0.500000f, -0.809017f, -0.309017f }, + { 0.425325f, -0.688191f, -0.587785f }, { 0.716567f, -0.681718f, -0.147621f }, + { 0.688191f, -0.587785f, -0.425325f }, { 0.587785f, -0.425325f, -0.688191f }, + { 0.000000f, -0.955423f, -0.295242f }, { 0.000000f, -1.000000f, 0.000000f }, + { 0.262866f, -0.951056f, -0.162460f }, { 0.000000f, -0.850651f, 0.525731f }, + { 0.000000f, -0.955423f, 0.295242f }, { 0.238856f, -0.864188f, 0.442863f }, + { 0.262866f, -0.951056f, 0.162460f }, { 0.500000f, -0.809017f, 0.309017f }, + { 0.716567f, -0.681718f, 0.147621f }, { 0.525731f, -0.850651f, 0.000000f }, + { -0.238856f, -0.864188f, -0.442863f }, { -0.500000f, -0.809017f, -0.309017f }, + { -0.262866f, -0.951056f, -0.162460f }, { -0.850651f, -0.525731f, 0.000000f }, + { -0.716567f, -0.681718f, -0.147621f }, { -0.716567f, -0.681718f, 0.147621f }, + { -0.525731f, -0.850651f, 0.000000f }, { -0.500000f, -0.809017f, 0.309017f }, + { -0.238856f, -0.864188f, 0.442863f }, { -0.262866f, -0.951056f, 0.162460f }, + { -0.864188f, -0.442863f, 0.238856f }, { -0.809017f, -0.309017f, 0.500000f }, + { -0.688191f, -0.587785f, 0.425325f }, { -0.681718f, -0.147621f, 0.716567f }, + { -0.442863f, -0.238856f, 0.864188f }, { -0.587785f, -0.425325f, 0.688191f }, + { -0.309017f, -0.500000f, 0.809017f }, { -0.147621f, -0.716567f, 0.681718f }, + { -0.425325f, -0.688191f, 0.587785f }, { -0.162460f, -0.262866f, 0.951056f }, + { 0.442863f, -0.238856f, 0.864188f }, { 0.162460f, -0.262866f, 0.951056f }, + { 0.309017f, -0.500000f, 0.809017f }, { 0.147621f, -0.716567f, 0.681718f }, + { 0.000000f, -0.525731f, 0.850651f }, { 0.425325f, -0.688191f, 0.587785f }, + { 0.587785f, -0.425325f, 0.688191f }, { 0.688191f, -0.587785f, 0.425325f }, + { -0.955423f, 0.295242f, 0.000000f }, { -0.951056f, 0.162460f, 0.262866f }, + { -1.000000f, 0.000000f, 0.000000f }, { -0.850651f, 0.000000f, 0.525731f }, + { -0.955423f, -0.295242f, 0.000000f }, { -0.951056f, -0.162460f, 0.262866f }, + { -0.864188f, 0.442863f, -0.238856f }, { -0.951056f, 0.162460f, -0.262866f }, + { -0.809017f, 0.309017f, -0.500000f }, { -0.864188f, -0.442863f, -0.238856f }, + { -0.951056f, -0.162460f, -0.262866f }, { -0.809017f, -0.309017f, -0.500000f }, + { -0.681718f, 0.147621f, -0.716567f }, { -0.681718f, -0.147621f, -0.716567f }, + { -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 } }; +}; + +vtkQuakeMDLImporter::vtkQuakeMDLImporter() + : Internals(new vtkQuakeMDLImporter::vtkInternals(this)){ + + }; + +//---------------------------------------------------------------------------- + + + + +//---------------------------------------------------------------------------- +int vtkQuakeMDLImporter::ImportBegin() +{ + return this->Internals->ReadScene(this->FileName); +} + +//---------------------------------------------------------------------------- +void vtkQuakeMDLImporter::ImportActors(vtkRenderer* renderer) +{ + this->Internals->ImportActors(renderer); +} + +//---------------------------------------------------------------------------- +std::string vtkQuakeMDLImporter::GetOutputsDescription() +{ + return this->Internals->Description; +} + +//---------------------------------------------------------------------------- +void vtkQuakeMDLImporter::UpdateTimeStep(double timeValue) +{ + this->Internals->UpdateFrame(timeValue); + return; +} + +//---------------------------------------------------------------------------- +vtkIdType vtkQuakeMDLImporter::GetNumberOfAnimations() +{ + return this->Internals->NumberOfAnimations; +} + +//---------------------------------------------------------------------------- +std::string vtkQuakeMDLImporter::GetAnimationName(vtkIdType animationIndex) +{ + return ""; +} + +//---------------------------------------------------------------------------- +void vtkQuakeMDLImporter::EnableAnimation(vtkIdType animationIndex) +{ + this->Internals->EnableAnimation(animationIndex); + return; +} + +//---------------------------------------------------------------------------- +void vtkQuakeMDLImporter::DisableAnimation(vtkIdType vtkNotUsed(animationIndex)) +{ + return; +} + +//---------------------------------------------------------------------------- +bool vtkQuakeMDLImporter::IsAnimationEnabled(vtkIdType animationIndex) +{ + return true; +} + + +//---------------------------------------------------------------------------- +bool vtkQuakeMDLImporter::GetTemporalInformation(vtkIdType animationIndex, + double vtkNotUsed(frameRate), int& vtkNotUsed(nbTimeSteps), double timeRange[2], + vtkDoubleArray* vtkNotUsed(timeSteps)) +{ + timeRange[0] = 0.0; + timeRange[1] = 10.0; + return true; +} + +//---------------------------------------------------------------------------- +vtkIdType vtkQuakeMDLImporter::GetNumberOfCameras() +{ + return 1; +} + +//---------------------------------------------------------------------------- +std::string vtkQuakeMDLImporter::GetCameraName(vtkIdType camIndex) +{ + return "Camera"; +} + +//---------------------------------------------------------------------------- +void vtkQuakeMDLImporter::SetCamera(vtkIdType camIndex) +{ + +} + +//---------------------------------------------------------------------------- +void vtkQuakeMDLImporter::ImportCameras(vtkRenderer* renderer) +{ + this->Internals->ImportCameras(renderer); +} + +//---------------------------------------------------------------------------- +void vtkQuakeMDLImporter::ImportLights(vtkRenderer* renderer) +{ + this->Internals->ImportLights(renderer); +} + +//---------------------------------------------------------------------------- +void vtkQuakeMDLImporter::PrintSelf(ostream& os, vtkIndent indent) +{ + this->Superclass::PrintSelf(os, indent); + os << indent << "FileName: " << this->FileName << "\n"; +} diff --git a/plugins/native/module/vtkQuakeMDLImporter.h b/plugins/native/module/vtkQuakeMDLImporter.h new file mode 100644 index 0000000000..5b2e9f43b2 --- /dev/null +++ b/plugins/native/module/vtkQuakeMDLImporter.h @@ -0,0 +1,135 @@ +/** + * @class vtkQuakeMDLImporter + * @brief VTK Importer for Quake 1 models in binary .mdl file format + */ + +#ifndef vtkQuakeMDLImporter_h +#define vtkQuakeMDLImporter_h +#include + +class vtkQuakeMDLImporter : public vtkImporter +{ +public: + static vtkQuakeMDLImporter* New(); + vtkTypeMacro(vtkQuakeMDLImporter, vtkImporter); + + + void PrintSelf(ostream& os, vtkIndent indent) override; + + ///@{ + /** + * Set/Get the file name. + */ + vtkSetMacro(FileName, std::string); + vtkGetMacro(FileName, std::string); + ///@} + + /** + * Update actors at the given time value. + */ + + void UpdateTimeStep(double timeValue); + + /** + * Get the number of available animations. + */ + vtkIdType GetNumberOfAnimations() override; + + /** + * Return the name of the animation. + */ + std::string GetAnimationName(vtkIdType animationIndex) override; + + ///@{ + /** + * Enable/Disable/Get the status of specific animations + * Only one single animation can be enabled + */ + void EnableAnimation(vtkIdType animationIndex) override; + void DisableAnimation(vtkIdType animationIndex) override; + bool IsAnimationEnabled(vtkIdType animationIndex) override; + ///@} + + /** + * Return importer description. + */ + std::string GetOutputsDescription() override; + + ///@{ + /** + * Set/Get collada fixup flag. + */ + vtkSetMacro(ColladaFixup, bool); + vtkGetMacro(ColladaFixup, bool); + ///@} + + /** + * Get temporal information for the currently enabled animation. + * Only defines timerange and ignore provided frameRate. + */ + bool GetTemporalInformation(vtkIdType animationIndex, double frameRate, int& nbTimeSteps, + double timeRange[2], vtkDoubleArray* timeSteps) override; + + /** + * Get the number of available cameras. + */ + vtkIdType GetNumberOfCameras() override; + + /** + * Get the name of a camera. + */ + std::string GetCameraName(vtkIdType camIndex) override; + + /** + * Enable a specific camera. + * If a negative index is provided, no camera from the importer is used. + */ + void SetCamera(vtkIdType camIndex) override; + + +protected: + vtkQuakeMDLImporter(); + ~vtkQuakeMDLImporter() override = default; + + int ImportBegin() override; + void ImportActors(vtkRenderer*) override; + void ImportCameras(vtkRenderer*) override; + void ImportLights(vtkRenderer*) override; + + // Header definition, + struct mdl_header_t + { + int IDPO; + int version; + float scale[3]; + float translation[3]; + float boundingRadius; + float eyePosition[3]; + int numSkins; + int skinWidth; + int skinHeight; + int numVertices; + int numTriangles; + int numFrames; + int syncType; + int stateFlags; + float size; + }; + + ///@{ + /** + * Set/Get the file name. + */ + ///@} + std::string FileName; + bool ColladaFixup = false; + +private: + vtkQuakeMDLImporter(const vtkQuakeMDLImporter&) = delete; + void operator=(const vtkQuakeMDLImporter&) = delete; + + class vtkInternals; + std::unique_ptr Internals; +}; + +#endif diff --git a/plugins/native/module/vtkQuakeMDLReader.cxx b/plugins/native/module/vtkQuakeMDLReader.cxx deleted file mode 100644 index 15ff7d4a70..0000000000 --- a/plugins/native/module/vtkQuakeMDLReader.cxx +++ /dev/null @@ -1,135 +0,0 @@ -#include "vtkQuakeMDLReader.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -//---------------------------------------------------------------------------- -vtkStandardNewMacro(vtkQuakeMDLReader); - -//---------------------------------------------------------------------------- -vtkQuakeMDLReader::vtkQuakeMDLReader() -{ - this->SetNumberOfInputPorts(0); -} - -//---------------------------------------------------------------------------- -int vtkQuakeMDLReader::RequestData( - vtkInformation*, vtkInformationVector**, vtkInformationVector* outputVector) -{ - vtkPolyData* output = vtkPolyData::GetData(outputVector); - - std::ifstream inputStream(this->FileName, std::ios::binary); - - // identity ("IDPO"): 4 chars (4 bytes) - vtkNew IDPOArray; - IDPOArray->SetNumberOfComponents(4); - IDPOArray->SetName("identity"); - - // version: 1 int (4 bytes) - vtkNew version; - version->SetNumberOfComponents(1); - version->SetName("version"); - - //==================================== - - // scaling factor: 3 floats (12 bytes) - vtkNew scalingFactor; - scalingFactor->SetNumberOfComponents(3); - scalingFactor->SetName("scaling factor"); - - // translation vector: 3 floats (12 bytes) - vtkNew translationVector; - translationVector->SetNumberOfComponents(3); - translationVector->SetName("translation vector"); - - // bounding radius: 1 float (4 bytes) - vtkNew boundingRadius; - boundingRadius->SetNumberOfComponents(1); - boundingRadius->SetName("bounding radius"); - - // eye position: 3 floats (12 bytes) - vtkNew eyePosition; - eyePosition->SetNumberOfComponents(3); - eyePosition->SetName("eye position"); - - //==================================== - - // number of textures: 1 int (4 bytes) - vtkNew texturesNum; - texturesNum->SetNumberOfComponents(1); - texturesNum->SetName("number of textures"); - - // texture width: 1 int (4 bytes) - vtkNew textureWidth; - textureWidth->SetNumberOfComponents(1); - textureWidth->SetName("texture width"); - - // texture height: 1 int (4 bytes) - vtkNew textureHeight; - textureHeight->SetNumberOfComponents(1); - textureHeight->SetName("texture height"); - - //==================================== - - // number of vertices: 1 int (4 bytes) - vtkNew verticesNum; - verticesNum->SetNumberOfComponents(1); - verticesNum->SetName("number of vertices"); - - // number of triangles: 1 int (4 bytes) - vtkNew trianglesNum; - trianglesNum->SetNumberOfComponents(1); - trianglesNum->SetName("number of triangles"); - - // number of frames: 1 int (4 bytes) - vtkNew framesNum; - framesNum->SetNumberOfComponents(1); - framesNum->SetName("number of frames"); - - //==================================== - - // sync type (0: synchron, 1: random): 1 int (4 bytes) - vtkNew syncType; - syncType->SetNumberOfComponents(1); - syncType->SetName("sync type"); - - // state flags: 1 int (4 bytes) - vtkNew stateFlags; - stateFlags->SetNumberOfComponents(1); - stateFlags->SetName("state flags"); - - //==================================== - - // position: 3 floats (12 bytes) - vtkNew position; - position->SetNumberOfComponents(3); - position->SetName("position"); - - // scale: 3 floats (12 bytes) - vtkNew scale; - scale->SetNumberOfComponents(3); - scale->SetName("scale"); - - // rotation: 4 chars (4 bytes) - vtkNew rotation; - rotation->SetNumberOfComponents(4); - rotation->SetName("rotation"); - - // color+opacity: 4 chars (4 bytes) - vtkNew colorAndOpacity; - colorAndOpacity->SetNumberOfComponents(4); - colorAndOpacity->SetName("color and opacity"); - - return 1; -} diff --git a/plugins/native/module/vtkQuakeMDLReader.h b/plugins/native/module/vtkQuakeMDLReader.h deleted file mode 100644 index cee1a4c596..0000000000 --- a/plugins/native/module/vtkQuakeMDLReader.h +++ /dev/null @@ -1,35 +0,0 @@ -/** - * @class vtkQuakeMDLReader - * @brief VTK Reader for Quake 1 models in binary .mdl file format - */ - -#ifndef vtkQuakeMDLReader_h -#define vtkQuakeMDLReader_h - -#include - -class vtkQuakeMDLReader : public vtkPolyDataAlgorithm -{ -public: - static vtkQuakeMDLReader* New(); - vtkTypeMacro(vtkQuakeMDLReader, vtkPolyDataAlgorithm); - - /** - * Set the file name. - */ - vtkSetMacro(FileName, std::string); - -protected: - vtkQuakeMDLReader(); - ~vtkQuakeMDLReader() override = default; - - int RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) override; - -private: - vtkQuakeMDLReader(const vtkQuakeMDLReader&) = delete; - void operator=(const vtkQuakeMDLReader&) = delete; - - std::string FileName; -}; - -#endif From dbf44ed5895d1abd99db7e8e131c41c49df2c2f4 Mon Sep 17 00:00:00 2001 From: Youva Date: Sun, 25 Aug 2024 13:51:00 -0400 Subject: [PATCH 30/60] Removed hardcoded path --- plugins/native/module/vtkQuakeMDLImporter.cxx | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/plugins/native/module/vtkQuakeMDLImporter.cxx b/plugins/native/module/vtkQuakeMDLImporter.cxx index e714f95f4a..ae02791cf1 100644 --- a/plugins/native/module/vtkQuakeMDLImporter.cxx +++ b/plugins/native/module/vtkQuakeMDLImporter.cxx @@ -100,12 +100,14 @@ class vtkQuakeMDLImporter::vtkInternals offset += 4 + nb * 4 + nb * (skinWidth) * (skinHeight); } } - vtkNew reader; - reader->SetFileName("C:\\\\Users\\Youva\\Downloads\\quake\\Untitled.png"); - reader->Update(); - vtkNew writer; - writer->SetFileName("C:\\\\Users\\Youva\\Downloads\\skin2.png"); + // Used while testing to load texture from a PNG file + // vtkNew reader; + // reader->SetFileName("C:\\\\Users\\Youva\\Downloads\\quake\\Untitled.png"); + // reader->Update(); + // Used while testing to check the texture is written correctly + // vtkNew writer; + // writer->SetFileName("C:\\\\Users\\Youva\\Downloads\\skin2.png"); vtkNew img; img->SetDimensions(skinWidth, skinHeight, 1); img->AllocateScalars(VTK_UNSIGNED_CHAR, 3); @@ -121,10 +123,11 @@ class vtkQuakeMDLImporter::vtkInternals ptr[2] = DefaultColorMap[index][2]; // B } } - - writer->SetInputData(img); - writer->Write(); + // Used to write to file + // writer->SetInputData(img); + // writer->Write(); texture->SetInputData(img); + // Used to set texture from image file // texture->SetInputConnection(reader->GetOutputPort()); return texture; @@ -463,7 +466,7 @@ class vtkQuakeMDLImporter::vtkInternals void ImportActors(vtkRenderer* renderer) { vtkNew actor; - vtkNew mapper; + vtkNew mapper; mapper->SetInputData(Mesh[0]); //Mesh); actor->SetMapper(mapper); From 4d1813d2a48cd644df79187078c98340944abb2e Mon Sep 17 00:00:00 2001 From: Youva Date: Mon, 2 Sep 2024 14:32:29 -0400 Subject: [PATCH 31/60] Fixed crash due to memory allocation on normals and interpolated frames. Fixed texture coordinates not rendering correctly by adding more vertices. Fixed camera position and lighting, animations display properly but could still be improved. --- plugins/native/module/vtkQuakeMDLImporter.cxx | 126 ++++++++---------- 1 file changed, 59 insertions(+), 67 deletions(-) diff --git a/plugins/native/module/vtkQuakeMDLImporter.cxx b/plugins/native/module/vtkQuakeMDLImporter.cxx index ae02791cf1..cce93d9bd6 100644 --- a/plugins/native/module/vtkQuakeMDLImporter.cxx +++ b/plugins/native/module/vtkQuakeMDLImporter.cxx @@ -1,5 +1,6 @@ #include "vtkQuakeMDLImporter.h" +#include #include #include #include @@ -49,12 +50,32 @@ class vtkQuakeMDLImporter::vtkInternals //---------------------------------------------------------------------------- void ImportCameras(vtkRenderer* renderer) { - + double cameraPosition[3] = { 50.0, 15.0, 0.0 }; + vtkNew roll; + roll->RotateX(270); + roll->RotateZ(270); + renderer->GetActiveCamera()->SetPosition(cameraPosition); + renderer->GetActiveCamera()->SetModelTransformMatrix(roll->GetMatrix()); } //---------------------------------------------------------------------------- void ImportLights(vtkRenderer* renderer) { + // Adds 3 lights, there's already one on the right side. + + vtkNew frontLight; + double frontLightPosition[3] = { 50.0, 50.0, 0.0 }; + frontLight->SetPosition(frontLightPosition); + vtkNew leftLight; + double leftLightPosition[3] = { 50.0, -50.0, 0.0 }; + leftLight->SetPosition(leftLightPosition); + vtkNew backLight; + double backLightPosition[3] = { -50.0, 0.0, 0.0 }; + backLight->SetPosition(backLightPosition); + + renderer->AddLight(frontLight); + renderer->AddLight(leftLight); + renderer->AddLight(backLight); } //---------------------------------------------------------------------------- @@ -62,8 +83,10 @@ class vtkQuakeMDLImporter::vtkInternals int skinHeight, int nbSkins, int selectedSkinIndex) { vtkNew texture; - texture->SetWrap(3); + texture->InterpolateOn(); + + // Read textures. struct mdl_skin_t { int group; /* 0 = single, 1 = group */ @@ -101,13 +124,7 @@ class vtkQuakeMDLImporter::vtkInternals } } - // Used while testing to load texture from a PNG file - // vtkNew reader; - // reader->SetFileName("C:\\\\Users\\Youva\\Downloads\\quake\\Untitled.png"); - // reader->Update(); - // Used while testing to check the texture is written correctly - // vtkNew writer; - // writer->SetFileName("C:\\\\Users\\Youva\\Downloads\\skin2.png"); + // Copy to imageData vtkNew img; img->SetDimensions(skinWidth, skinHeight, 1); img->AllocateScalars(VTK_UNSIGNED_CHAR, 3); @@ -123,13 +140,8 @@ class vtkQuakeMDLImporter::vtkInternals ptr[2] = DefaultColorMap[index][2]; // B } } - // Used to write to file - // writer->SetInputData(img); - // writer->Write(); - texture->SetInputData(img); - // Used to set texture from image file - // texture->SetInputConnection(reader->GetOutputPort()); + texture->SetInputData(img); return texture; } @@ -180,7 +192,6 @@ class vtkQuakeMDLImporter::vtkInternals float* time; // Size is nbFrames ??? mdl_simpleframe_t* frames; // Size is nbFrames ??? }; - struct plugin_frame_pointer { int* type; @@ -223,14 +234,14 @@ class vtkQuakeMDLImporter::vtkInternals vtkNew textureCoordinates; textureCoordinates->SetNumberOfComponents(2); textureCoordinates->SetName("TextureCoordinates"); - textureCoordinates->Allocate(header->numVertices * 2); + textureCoordinates->Allocate(header->numTriangles * 3); struct plugin_texture_coords { float s; float t; int id; }; - plugin_texture_coords* coords = new plugin_texture_coords[header->numVertices]; + plugin_texture_coords* coords = new plugin_texture_coords[header->numTriangles * 3]; for (int i = 0; i < header->numTriangles; i++) { vtkIdType* vertexNum = new vtkIdType[3]; @@ -238,28 +249,24 @@ class vtkQuakeMDLImporter::vtkInternals { vertexNum[j] = triangles[i].vertex[j]; int onseam_correct = 1; - float s = texcoords[vertexNum[j]].s; - float t = texcoords[vertexNum[j]].t; - if ( !triangles[i].facesfront && texcoords[vertexNum[j]].onseam) + float s = texcoords[triangles[i].vertex[j]].s; + float t = texcoords[triangles[i].vertex[j]].t; + if (!triangles[i].facesfront && texcoords[triangles[i].vertex[j]].onseam) { s = s + header->skinWidth * 0.5f; } s = (s + 0.5) / header->skinWidth; t = (t + 0.5) / header->skinHeight; - coords[vertexNum[j]].s = s; - coords[vertexNum[j]].t = t; - coords[vertexNum[j]].id = vertexNum[j]; + coords[3 * i + j].s = s; + coords[3 * i + j].t = t; + coords[3 * i + j].id = triangles[i].vertex[j]; + float st[2] = { s, t }; + textureCoordinates->InsertNextTuple(st); } - cells->InsertNextCell(3, vertexNum); + vtkIdType t[3] = { i * 3, i * 3 + 1, i * 3 + 2 }; + cells->InsertNextCell(3, t); + } - // Add texture coords - for (int i = 0; i < header->numVertices; i++) - { - float* s_t = new float[2]; - s_t[0] = coords[i].s; - s_t[1] = coords[i].t; - textureCoordinates->InsertNextTuple(s_t); - } // Draw vertices @@ -268,10 +275,11 @@ class vtkQuakeMDLImporter::vtkInternals for (int frameNum = 0; frameNum < header->numFrames; frameNum++) { vtkNew vertices; - vertices->Allocate(header->numVertices); + vertices->Allocate(header->numTriangles * 3); vtkNew normals; normals->SetNumberOfComponents(3); - normals->Allocate(header->numVertices * 3); + normals->Allocate(header->numTriangles * 3 * 3); + plugin_frame_pointer selectedFrame = framePtr[frameNum]; if (*selectedFrame.type == 0) { @@ -288,17 +296,17 @@ class vtkQuakeMDLImporter::vtkInternals { v[k] = v[k] * header->scale[k] + header->translation[k]; } - vertices->InsertPoint(vertexNum[j], v); + vertices->InsertPoint(i*3+j, v); int normalIndex = selectedFrame.frames->verts[vertexNum[j]].normalIndex; - normals->SetTuple3(vertexNum[j], NormalVectors[normalIndex][0] / 255.0, - NormalVectors[normalIndex][1] / 255.0, NormalVectors[normalIndex][2] / 255.0); + normals->SetTuple3(i*3+j, NormalVectors[normalIndex][0] / 255.0, + NormalVectors[normalIndex][1] / 255.0, NormalVectors[normalIndex][2] / 255.0); } } vtkNew mesh; mesh->SetPoints(vertices); mesh->SetPolys(cells); mesh->GetPointData()->SetTCoords(textureCoordinates); - mesh->GetPointData()->SetNormals(normals); +// mesh->GetPointData()->SetNormals(normals); Mesh.push_back(mesh); std::string meshName = std::string(selectedFrame.frames->name); for (int i = 0; i < meshName.size(); i++) @@ -339,9 +347,9 @@ class vtkQuakeMDLImporter::vtkInternals { v[k] = v[k] * header->scale[k] + header->translation[k]; } - vertices->InsertPoint(vertexNum[j], v); + vertices->InsertPoint(i*3+j, v); int normalIndex = selectedFrame.frames[groupFrameNum].verts[vertexNum[j]].normalIndex; - normals->SetTuple3(vertexNum[j], NormalVectors[normalIndex][0] / 255.0, + normals->SetTuple3(i*3+j, NormalVectors[normalIndex][0] / 255.0, NormalVectors[normalIndex][1] / 255.0, NormalVectors[normalIndex][2] / 255.0); } } @@ -375,7 +383,8 @@ class vtkQuakeMDLImporter::vtkInternals } } } - + return; + // Add interpolated frames for (int i = 0; i < Mesh.size() - 1; i++) { @@ -386,11 +395,8 @@ class vtkQuakeMDLImporter::vtkInternals else { vtkNew vertices; - vertices->Allocate(header->numVertices); - vtkNew normals; - normals->SetNumberOfComponents(3); - normals->Allocate(header->numVertices * 3); - for (int j = 0; j < header->numVertices; j++) + vertices->Allocate(header->numTriangles * 3); + for (int j = 0; j < header->numTriangles * 3; j++) { double* v_0 = Mesh[i]->GetPoint(j); double* v_1 = Mesh[i+1]->GetPoint(j); @@ -417,10 +423,7 @@ class vtkQuakeMDLImporter::vtkInternals bool ReadScene(const std::string& filePath) { std::ifstream inputStream(filePath, std::ios::binary); - std::vector buffer(std::istreambuf_iterator(inputStream), {}); - - // Read header mdl_header_t* header = reinterpret_cast(buffer.data()); int offset = 84; @@ -440,11 +443,11 @@ class vtkQuakeMDLImporter::vtkInternals void UpdateFrame(double timeValue) { - // Hardcoded frames per second - if (abs(timeValue - LastRenderTime) > 1.0 / 60) + // Hardcoded frames per second, 24FPS seems reasonable + if (abs(timeValue - LastRenderTime) > 1.0 / 24) { Mapper->SetInputData( - Mesh[(CurrentFrameIndex++) % (LastFrameIndex - FirstFrameIndex) + FirstFrameIndex]); + Mesh[(CurrentFrameIndex++) % (LastFrameIndex - FirstFrameIndex) + FirstFrameIndex]); LastRenderTime = timeValue; } } @@ -452,6 +455,8 @@ class vtkQuakeMDLImporter::vtkInternals // Only one animation enabled at a time void EnableAnimation(vtkIdType animationIndex) { + // Animations are divided into groups, but stored as a vector of polydata. + // This functions set the indices for the first and last frames in the group. int i = 0; while (i < GroupAndTimeVal.size() && GroupAndTimeVal[++i].first < animationIndex) { @@ -468,7 +473,6 @@ class vtkQuakeMDLImporter::vtkInternals vtkNew actor; vtkNew mapper; mapper->SetInputData(Mesh[0]); - //Mesh); actor->SetMapper(mapper); actor->SetTexture(Texture); renderer->AddActor(actor); @@ -478,18 +482,6 @@ class vtkQuakeMDLImporter::vtkInternals Mapper = mapper; } - void UpdateNodeTransform() - { - } - - void UpdateCameras() - { - } - - void UpdateLights() - { - - } vtkQuakeMDLImporter* Parent; @@ -676,7 +668,7 @@ void vtkQuakeMDLImporter::UpdateTimeStep(double timeValue) //---------------------------------------------------------------------------- vtkIdType vtkQuakeMDLImporter::GetNumberOfAnimations() { - return this->Internals->NumberOfAnimations; + return this->Internals->NumberOfAnimations; } //---------------------------------------------------------------------------- From 48a6e7ea176c838393fd202eb7abce4541ca5674 Mon Sep 17 00:00:00 2001 From: Youva Boutora <48061964+Youva@users.noreply.github.com> Date: Sun, 8 Sep 2024 13:52:30 -0400 Subject: [PATCH 32/60] Formatting --- plugins/alembic/module/vtkF3DAlembicReader.h | 2 +- plugins/native/module/vtkQuakeMDLImporter.cxx | 104 +++--- .../native/module/vtkQuakeMDLImporter.cxx.rej | 9 + plugins/native/module/vtkQuakeMDLImporter.h | 7 +- .../native/module/vtkQuakeMDLImporter.h.rej | 17 + style.diff | 344 ++++++++++++++++++ 6 files changed, 420 insertions(+), 63 deletions(-) create mode 100644 plugins/native/module/vtkQuakeMDLImporter.cxx.rej create mode 100644 plugins/native/module/vtkQuakeMDLImporter.h.rej create mode 100644 style.diff diff --git a/plugins/alembic/module/vtkF3DAlembicReader.h b/plugins/alembic/module/vtkF3DAlembicReader.h index cb09a53823..e8a47dd412 100644 --- a/plugins/alembic/module/vtkF3DAlembicReader.h +++ b/plugins/alembic/module/vtkF3DAlembicReader.h @@ -14,10 +14,10 @@ #ifndef vtkF3DAlembicReader_h #define vtkF3DAlembicReader_h +#include #include #include #include -#include class vtkF3DAlembicReader : public vtkPolyDataAlgorithm { diff --git a/plugins/native/module/vtkQuakeMDLImporter.cxx b/plugins/native/module/vtkQuakeMDLImporter.cxx index cce93d9bd6..3c1f92c124 100644 --- a/plugins/native/module/vtkQuakeMDLImporter.cxx +++ b/plugins/native/module/vtkQuakeMDLImporter.cxx @@ -1,43 +1,42 @@ #include "vtkQuakeMDLImporter.h" -#include +#include +#include +#include #include -#include #include #include #include #include #include +#include #include #include +#include +#include +#include #include +#include +#include +#include +#include #include #include #include -#include -#include #include -#include -#include +#include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include -#include +#include +#include #include #include +#include +#include //---------------------------------------------------------------------------- vtkStandardNewMacro(vtkQuakeMDLImporter); - class vtkQuakeMDLImporter::vtkInternals { public: @@ -72,24 +71,23 @@ class vtkQuakeMDLImporter::vtkInternals vtkNew backLight; double backLightPosition[3] = { -50.0, 0.0, 0.0 }; backLight->SetPosition(backLightPosition); - + renderer->AddLight(frontLight); renderer->AddLight(leftLight); renderer->AddLight(backLight); } //---------------------------------------------------------------------------- - vtkSmartPointer CreateTexture(std::vector buffer, int& offset, int skinWidth, - int skinHeight, int nbSkins, int selectedSkinIndex) + vtkSmartPointer CreateTexture(std::vector buffer, int& offset, + int skinWidth, int skinHeight, int nbSkins, int selectedSkinIndex) { vtkNew texture; texture->InterpolateOn(); - // Read textures. struct mdl_skin_t { - int group; /* 0 = single, 1 = group */ + int group; /* 0 = single, 1 = group */ unsigned char* data; /* texture data */ }; struct mdl_groupskin_t @@ -118,7 +116,7 @@ class vtkQuakeMDLImporter::vtkInternals else { skins[i].group = 1; - int nb = *reinterpret_cast(buffer.data() + offset + 4); + int nb = *reinterpret_cast(buffer.data() + offset + 4); skins[i].skin = reinterpret_cast(buffer.data() + 4 + nb * 4 + offset); offset += 4 + nb * 4 + nb * (skinWidth) * (skinHeight); } @@ -129,12 +127,12 @@ class vtkQuakeMDLImporter::vtkInternals img->SetDimensions(skinWidth, skinHeight, 1); img->AllocateScalars(VTK_UNSIGNED_CHAR, 3); unsigned char* selectedSkin = skins[selectedSkinIndex].skin; - for (int i = 0; i < skinHeight ; i++) + for (int i = 0; i < skinHeight; i++) { for (int j = 0; j < skinWidth; j++) { unsigned char index = *reinterpret_cast(selectedSkin + i * skinWidth + j); - unsigned char* ptr = reinterpret_cast(img->GetScalarPointer(j,i,0)); + unsigned char* ptr = reinterpret_cast(img->GetScalarPointer(j, i, 0)); ptr[0] = DefaultColorMap[index][0]; // R ptr[1] = DefaultColorMap[index][1]; // G ptr[2] = DefaultColorMap[index][2]; // B @@ -145,8 +143,8 @@ class vtkQuakeMDLImporter::vtkInternals return texture; } - - void CreateMesh(std::vector buffer, int& offset, mdl_header_t* header, int selectedFrameIndex) + void CreateMesh( + std::vector buffer, int& offset, mdl_header_t* header, int selectedFrameIndex) { // Read texture coordinates struct mdl_texcoord_t @@ -217,9 +215,8 @@ class vtkQuakeMDLImporter::vtkInternals framePtr[i].nb = reinterpret_cast(buffer.data() + 4 + offset); mdl_vertex_t* min = reinterpret_cast(buffer.data() + 8 + offset); mdl_vertex_t* max = reinterpret_cast(buffer.data() + 12 + offset); - float* time = - framePtr[i].time = reinterpret_cast(buffer.data() + 16 + offset); - framePtr[i].frames = + float* time = framePtr[i].time = reinterpret_cast(buffer.data() + 16 + offset); + framePtr[i].frames = reinterpret_cast(buffer.data() + 16 + 4 * (*framePtr[i].nb) + offset); offset += 16 + (*framePtr[i].nb) * 4; for (int j = 0; j < *framePtr[i].nb; j++) @@ -265,10 +262,8 @@ class vtkQuakeMDLImporter::vtkInternals } vtkIdType t[3] = { i * 3, i * 3 + 1, i * 3 + 2 }; cells->InsertNextCell(3, t); - } - // Draw vertices std::string frameName = ""; int frameIndex = 0; @@ -279,7 +274,7 @@ class vtkQuakeMDLImporter::vtkInternals vtkNew normals; normals->SetNumberOfComponents(3); normals->Allocate(header->numTriangles * 3 * 3); - + plugin_frame_pointer selectedFrame = framePtr[frameNum]; if (*selectedFrame.type == 0) { @@ -296,17 +291,17 @@ class vtkQuakeMDLImporter::vtkInternals { v[k] = v[k] * header->scale[k] + header->translation[k]; } - vertices->InsertPoint(i*3+j, v); + vertices->InsertPoint(i * 3 + j, v); int normalIndex = selectedFrame.frames->verts[vertexNum[j]].normalIndex; - normals->SetTuple3(i*3+j, NormalVectors[normalIndex][0] / 255.0, - NormalVectors[normalIndex][1] / 255.0, NormalVectors[normalIndex][2] / 255.0); + normals->SetTuple3(i * 3 + j, NormalVectors[normalIndex][0] / 255.0, + NormalVectors[normalIndex][1] / 255.0, NormalVectors[normalIndex][2] / 255.0); } } vtkNew mesh; mesh->SetPoints(vertices); mesh->SetPolys(cells); mesh->GetPointData()->SetTCoords(textureCoordinates); -// mesh->GetPointData()->SetNormals(normals); + // mesh->GetPointData()->SetNormals(normals); Mesh.push_back(mesh); std::string meshName = std::string(selectedFrame.frames->name); for (int i = 0; i < meshName.size(); i++) @@ -347,9 +342,9 @@ class vtkQuakeMDLImporter::vtkInternals { v[k] = v[k] * header->scale[k] + header->translation[k]; } - vertices->InsertPoint(i*3+j, v); + vertices->InsertPoint(i * 3 + j, v); int normalIndex = selectedFrame.frames[groupFrameNum].verts[vertexNum[j]].normalIndex; - normals->SetTuple3(i*3+j, NormalVectors[normalIndex][0] / 255.0, + normals->SetTuple3(i * 3 + j, NormalVectors[normalIndex][0] / 255.0, NormalVectors[normalIndex][1] / 255.0, NormalVectors[normalIndex][2] / 255.0); } } @@ -378,7 +373,8 @@ class vtkQuakeMDLImporter::vtkInternals NumberOfAnimations++; frameName = meshName; } - std::pair pair = std::make_pair(frameIndex, selectedFrame.time[groupFrameNum]); + std::pair pair = + std::make_pair(frameIndex, selectedFrame.time[groupFrameNum]); GroupAndTimeVal.push_back(pair); } } @@ -399,7 +395,7 @@ class vtkQuakeMDLImporter::vtkInternals for (int j = 0; j < header->numTriangles * 3; j++) { double* v_0 = Mesh[i]->GetPoint(j); - double* v_1 = Mesh[i+1]->GetPoint(j); + double* v_1 = Mesh[i + 1]->GetPoint(j); double* interp = new double[3]; interp[0] = v_0[0] + 0.5 * (v_1[0] - v_0[0]); interp[1] = v_0[1] + 0.5 * (v_1[1] - v_0[1]); @@ -427,17 +423,14 @@ class vtkQuakeMDLImporter::vtkInternals // Read header mdl_header_t* header = reinterpret_cast(buffer.data()); int offset = 84; - + // Set textures - Texture= this->CreateTexture( + Texture = this->CreateTexture( buffer, offset, header->skinWidth, header->skinHeight, header->numSkins, 0); - - + // Set polyData this->CreateMesh(buffer, offset, header, 0); - - - + return 1; } @@ -447,7 +440,7 @@ class vtkQuakeMDLImporter::vtkInternals if (abs(timeValue - LastRenderTime) > 1.0 / 24) { Mapper->SetInputData( - Mesh[(CurrentFrameIndex++) % (LastFrameIndex - FirstFrameIndex) + FirstFrameIndex]); + Mesh[(CurrentFrameIndex++) % (LastFrameIndex - FirstFrameIndex) + FirstFrameIndex]); LastRenderTime = timeValue; } } @@ -465,7 +458,7 @@ class vtkQuakeMDLImporter::vtkInternals while (i < GroupAndTimeVal.size() && GroupAndTimeVal[++i].first == animationIndex) { } - LastFrameIndex = i-1; + LastFrameIndex = i - 1; } void ImportActors(vtkRenderer* renderer) @@ -482,14 +475,12 @@ class vtkQuakeMDLImporter::vtkInternals Mapper = mapper; } - - vtkQuakeMDLImporter* Parent; std::string Description; vtkSmartPointer Actor; vtkSmartPointer Mapper; std::vector> Mesh; - std::vector > GroupAndTimeVal; + std::vector> GroupAndTimeVal; int ActiveAnimationId = 0; int CurrentFrameIndex = 0; int FirstFrameIndex = 0; @@ -637,9 +628,6 @@ vtkQuakeMDLImporter::vtkQuakeMDLImporter() //---------------------------------------------------------------------------- - - - //---------------------------------------------------------------------------- int vtkQuakeMDLImporter::ImportBegin() { @@ -696,7 +684,6 @@ bool vtkQuakeMDLImporter::IsAnimationEnabled(vtkIdType animationIndex) return true; } - //---------------------------------------------------------------------------- bool vtkQuakeMDLImporter::GetTemporalInformation(vtkIdType animationIndex, double vtkNotUsed(frameRate), int& vtkNotUsed(nbTimeSteps), double timeRange[2], @@ -722,9 +709,10 @@ std::string vtkQuakeMDLImporter::GetCameraName(vtkIdType camIndex) //---------------------------------------------------------------------------- void vtkQuakeMDLImporter::SetCamera(vtkIdType camIndex) { - + return; } + //---------------------------------------------------------------------------- void vtkQuakeMDLImporter::ImportCameras(vtkRenderer* renderer) { diff --git a/plugins/native/module/vtkQuakeMDLImporter.cxx.rej b/plugins/native/module/vtkQuakeMDLImporter.cxx.rej new file mode 100644 index 0000000000..b3fc6d37fd --- /dev/null +++ b/plugins/native/module/vtkQuakeMDLImporter.cxx.rej @@ -0,0 +1,9 @@ +diff a/plugins/native/module/vtkQuakeMDLImporter.cxx b/plugins/native/module/vtkQuakeMDLImporter.cxx (rejected hunks) +@@ -722,7 +709,6 @@ + //---------------------------------------------------------------------------- + void vtkQuakeMDLImporter::SetCamera(vtkIdType camIndex) + { +- + } + + //---------------------------------------------------------------------------- diff --git a/plugins/native/module/vtkQuakeMDLImporter.h b/plugins/native/module/vtkQuakeMDLImporter.h index 5b2e9f43b2..1e07702f19 100644 --- a/plugins/native/module/vtkQuakeMDLImporter.h +++ b/plugins/native/module/vtkQuakeMDLImporter.h @@ -5,7 +5,7 @@ #ifndef vtkQuakeMDLImporter_h #define vtkQuakeMDLImporter_h -#include +#include class vtkQuakeMDLImporter : public vtkImporter { @@ -86,17 +86,16 @@ class vtkQuakeMDLImporter : public vtkImporter */ void SetCamera(vtkIdType camIndex) override; - protected: vtkQuakeMDLImporter(); ~vtkQuakeMDLImporter() override = default; - + int ImportBegin() override; void ImportActors(vtkRenderer*) override; void ImportCameras(vtkRenderer*) override; void ImportLights(vtkRenderer*) override; - // Header definition, + // Header definition, struct mdl_header_t { int IDPO; diff --git a/plugins/native/module/vtkQuakeMDLImporter.h.rej b/plugins/native/module/vtkQuakeMDLImporter.h.rej new file mode 100644 index 0000000000..9a24d88285 --- /dev/null +++ b/plugins/native/module/vtkQuakeMDLImporter.h.rej @@ -0,0 +1,17 @@ +diff a/plugins/native/module/vtkQuakeMDLImporter.h b/plugins/native/module/vtkQuakeMDLImporter.h (rejected hunks) +@@ -5,14 +5,13 @@ + + #ifndef vtkQuakeMDLImporter_h + #define vtkQuakeMDLImporter_h +-#include ++#include + + class vtkQuakeMDLImporter : public vtkImporter + { + public: + static vtkQuakeMDLImporter* New(); + vtkTypeMacro(vtkQuakeMDLImporter, vtkImporter); +- + + void PrintSelf(ostream& os, vtkIndent indent) override; + diff --git a/style.diff b/style.diff new file mode 100644 index 0000000000..e80a12c576 --- /dev/null +++ b/style.diff @@ -0,0 +1,344 @@ +--- plugins/alembic/module/vtkF3DAlembicReader.h (original) ++++ plugins/alembic/module/vtkF3DAlembicReader.h (reformatted) +@@ -14,10 +14,10 @@ + #ifndef vtkF3DAlembicReader_h + #define vtkF3DAlembicReader_h + ++#include + #include + #include + #include +-#include + + class vtkF3DAlembicReader : public vtkPolyDataAlgorithm + { +--- plugins/native/module/vtkQuakeMDLImporter.h (original) ++++ plugins/native/module/vtkQuakeMDLImporter.h (reformatted) +@@ -5,14 +5,13 @@ + + #ifndef vtkQuakeMDLImporter_h + #define vtkQuakeMDLImporter_h +-#include ++#include + + class vtkQuakeMDLImporter : public vtkImporter + { + public: + static vtkQuakeMDLImporter* New(); + vtkTypeMacro(vtkQuakeMDLImporter, vtkImporter); +- + + void PrintSelf(ostream& os, vtkIndent indent) override; + +@@ -86,17 +85,16 @@ + */ + void SetCamera(vtkIdType camIndex) override; + +- + protected: + vtkQuakeMDLImporter(); + ~vtkQuakeMDLImporter() override = default; +- ++ + int ImportBegin() override; + void ImportActors(vtkRenderer*) override; + void ImportCameras(vtkRenderer*) override; + void ImportLights(vtkRenderer*) override; + +- // Header definition, ++ // Header definition, + struct mdl_header_t + { + int IDPO; +--- plugins/native/module/vtkQuakeMDLImporter.cxx (original) ++++ plugins/native/module/vtkQuakeMDLImporter.cxx (reformatted) +@@ -1,42 +1,41 @@ + #include "vtkQuakeMDLImporter.h" + +-#include ++#include ++#include ++#include + #include +-#include + #include + #include + #include + #include + #include ++#include + #include + #include ++#include ++#include ++#include + #include ++#include ++#include ++#include ++#include + #include + #include + #include +-#include +-#include + #include +-#include +-#include ++#include + #include +-#include +-#include +-#include +-#include ++#include ++#include + #include +-#include +-#include +-#include +-#include +-#include +-#include + #include + #include ++#include ++#include + + //---------------------------------------------------------------------------- + vtkStandardNewMacro(vtkQuakeMDLImporter); +- + + class vtkQuakeMDLImporter::vtkInternals + { +@@ -72,24 +71,23 @@ + vtkNew backLight; + double backLightPosition[3] = { -50.0, 0.0, 0.0 }; + backLight->SetPosition(backLightPosition); +- ++ + renderer->AddLight(frontLight); + renderer->AddLight(leftLight); + renderer->AddLight(backLight); + } + + //---------------------------------------------------------------------------- +- vtkSmartPointer CreateTexture(std::vector buffer, int& offset, int skinWidth, +- int skinHeight, int nbSkins, int selectedSkinIndex) ++ vtkSmartPointer CreateTexture(std::vector buffer, int& offset, ++ int skinWidth, int skinHeight, int nbSkins, int selectedSkinIndex) + { + vtkNew texture; + texture->InterpolateOn(); + +- + // Read textures. + struct mdl_skin_t + { +- int group; /* 0 = single, 1 = group */ ++ int group; /* 0 = single, 1 = group */ + unsigned char* data; /* texture data */ + }; + struct mdl_groupskin_t +@@ -118,7 +116,7 @@ + else + { + skins[i].group = 1; +- int nb = *reinterpret_cast(buffer.data() + offset + 4); ++ int nb = *reinterpret_cast(buffer.data() + offset + 4); + skins[i].skin = reinterpret_cast(buffer.data() + 4 + nb * 4 + offset); + offset += 4 + nb * 4 + nb * (skinWidth) * (skinHeight); + } +@@ -129,12 +127,12 @@ + img->SetDimensions(skinWidth, skinHeight, 1); + img->AllocateScalars(VTK_UNSIGNED_CHAR, 3); + unsigned char* selectedSkin = skins[selectedSkinIndex].skin; +- for (int i = 0; i < skinHeight ; i++) ++ for (int i = 0; i < skinHeight; i++) + { + for (int j = 0; j < skinWidth; j++) + { + unsigned char index = *reinterpret_cast(selectedSkin + i * skinWidth + j); +- unsigned char* ptr = reinterpret_cast(img->GetScalarPointer(j,i,0)); ++ unsigned char* ptr = reinterpret_cast(img->GetScalarPointer(j, i, 0)); + ptr[0] = DefaultColorMap[index][0]; // R + ptr[1] = DefaultColorMap[index][1]; // G + ptr[2] = DefaultColorMap[index][2]; // B +@@ -145,8 +143,8 @@ + return texture; + } + +- +- void CreateMesh(std::vector buffer, int& offset, mdl_header_t* header, int selectedFrameIndex) ++ void CreateMesh( ++ std::vector buffer, int& offset, mdl_header_t* header, int selectedFrameIndex) + { + // Read texture coordinates + struct mdl_texcoord_t +@@ -217,9 +215,8 @@ + framePtr[i].nb = reinterpret_cast(buffer.data() + 4 + offset); + mdl_vertex_t* min = reinterpret_cast(buffer.data() + 8 + offset); + mdl_vertex_t* max = reinterpret_cast(buffer.data() + 12 + offset); +- float* time = +- framePtr[i].time = reinterpret_cast(buffer.data() + 16 + offset); +- framePtr[i].frames = ++ float* time = framePtr[i].time = reinterpret_cast(buffer.data() + 16 + offset); ++ framePtr[i].frames = + reinterpret_cast(buffer.data() + 16 + 4 * (*framePtr[i].nb) + offset); + offset += 16 + (*framePtr[i].nb) * 4; + for (int j = 0; j < *framePtr[i].nb; j++) +@@ -265,9 +262,7 @@ + } + vtkIdType t[3] = { i * 3, i * 3 + 1, i * 3 + 2 }; + cells->InsertNextCell(3, t); +- +- } +- ++ } + + // Draw vertices + std::string frameName = ""; +@@ -279,7 +274,7 @@ + vtkNew normals; + normals->SetNumberOfComponents(3); + normals->Allocate(header->numTriangles * 3 * 3); +- ++ + plugin_frame_pointer selectedFrame = framePtr[frameNum]; + if (*selectedFrame.type == 0) + { +@@ -296,17 +291,17 @@ + { + v[k] = v[k] * header->scale[k] + header->translation[k]; + } +- vertices->InsertPoint(i*3+j, v); ++ vertices->InsertPoint(i * 3 + j, v); + int normalIndex = selectedFrame.frames->verts[vertexNum[j]].normalIndex; +- normals->SetTuple3(i*3+j, NormalVectors[normalIndex][0] / 255.0, +- NormalVectors[normalIndex][1] / 255.0, NormalVectors[normalIndex][2] / 255.0); ++ normals->SetTuple3(i * 3 + j, NormalVectors[normalIndex][0] / 255.0, ++ NormalVectors[normalIndex][1] / 255.0, NormalVectors[normalIndex][2] / 255.0); + } + } + vtkNew mesh; + mesh->SetPoints(vertices); + mesh->SetPolys(cells); + mesh->GetPointData()->SetTCoords(textureCoordinates); +-// mesh->GetPointData()->SetNormals(normals); ++ // mesh->GetPointData()->SetNormals(normals); + Mesh.push_back(mesh); + std::string meshName = std::string(selectedFrame.frames->name); + for (int i = 0; i < meshName.size(); i++) +@@ -347,9 +342,9 @@ + { + v[k] = v[k] * header->scale[k] + header->translation[k]; + } +- vertices->InsertPoint(i*3+j, v); ++ vertices->InsertPoint(i * 3 + j, v); + int normalIndex = selectedFrame.frames[groupFrameNum].verts[vertexNum[j]].normalIndex; +- normals->SetTuple3(i*3+j, NormalVectors[normalIndex][0] / 255.0, ++ normals->SetTuple3(i * 3 + j, NormalVectors[normalIndex][0] / 255.0, + NormalVectors[normalIndex][1] / 255.0, NormalVectors[normalIndex][2] / 255.0); + } + } +@@ -378,7 +373,8 @@ + NumberOfAnimations++; + frameName = meshName; + } +- std::pair pair = std::make_pair(frameIndex, selectedFrame.time[groupFrameNum]); ++ std::pair pair = ++ std::make_pair(frameIndex, selectedFrame.time[groupFrameNum]); + GroupAndTimeVal.push_back(pair); + } + } +@@ -399,7 +395,7 @@ + for (int j = 0; j < header->numTriangles * 3; j++) + { + double* v_0 = Mesh[i]->GetPoint(j); +- double* v_1 = Mesh[i+1]->GetPoint(j); ++ double* v_1 = Mesh[i + 1]->GetPoint(j); + double* interp = new double[3]; + interp[0] = v_0[0] + 0.5 * (v_1[0] - v_0[0]); + interp[1] = v_0[1] + 0.5 * (v_1[1] - v_0[1]); +@@ -427,17 +423,14 @@ + // Read header + mdl_header_t* header = reinterpret_cast(buffer.data()); + int offset = 84; +- ++ + // Set textures +- Texture= this->CreateTexture( ++ Texture = this->CreateTexture( + buffer, offset, header->skinWidth, header->skinHeight, header->numSkins, 0); +- +- ++ + // Set polyData + this->CreateMesh(buffer, offset, header, 0); +- +- +- ++ + return 1; + } + +@@ -447,7 +440,7 @@ + if (abs(timeValue - LastRenderTime) > 1.0 / 24) + { + Mapper->SetInputData( +- Mesh[(CurrentFrameIndex++) % (LastFrameIndex - FirstFrameIndex) + FirstFrameIndex]); ++ Mesh[(CurrentFrameIndex++) % (LastFrameIndex - FirstFrameIndex) + FirstFrameIndex]); + LastRenderTime = timeValue; + } + } +@@ -465,7 +458,7 @@ + while (i < GroupAndTimeVal.size() && GroupAndTimeVal[++i].first == animationIndex) + { + } +- LastFrameIndex = i-1; ++ LastFrameIndex = i - 1; + } + + void ImportActors(vtkRenderer* renderer) +@@ -482,14 +475,12 @@ + Mapper = mapper; + } + +- +- + vtkQuakeMDLImporter* Parent; + std::string Description; + vtkSmartPointer Actor; + vtkSmartPointer Mapper; + std::vector> Mesh; +- std::vector > GroupAndTimeVal; ++ std::vector> GroupAndTimeVal; + int ActiveAnimationId = 0; + int CurrentFrameIndex = 0; + int FirstFrameIndex = 0; +@@ -637,9 +628,6 @@ + + //---------------------------------------------------------------------------- + +- +- +- + //---------------------------------------------------------------------------- + int vtkQuakeMDLImporter::ImportBegin() + { +@@ -695,7 +683,6 @@ + { + return true; + } +- + + //---------------------------------------------------------------------------- + bool vtkQuakeMDLImporter::GetTemporalInformation(vtkIdType animationIndex, +@@ -722,7 +709,6 @@ + //---------------------------------------------------------------------------- + void vtkQuakeMDLImporter::SetCamera(vtkIdType camIndex) + { +- + } + + //---------------------------------------------------------------------------- From 778c0d4e2ede8f2e893348eec05cf9b84cbab73c Mon Sep 17 00:00:00 2001 From: Youva Boutora <48061964+Youva@users.noreply.github.com> Date: Sun, 8 Sep 2024 13:55:22 -0400 Subject: [PATCH 33/60] Formatting --- plugins/native/module/vtkQuakeMDLImporter.cxx | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/native/module/vtkQuakeMDLImporter.cxx b/plugins/native/module/vtkQuakeMDLImporter.cxx index 3c1f92c124..98b33b2915 100644 --- a/plugins/native/module/vtkQuakeMDLImporter.cxx +++ b/plugins/native/module/vtkQuakeMDLImporter.cxx @@ -712,7 +712,6 @@ void vtkQuakeMDLImporter::SetCamera(vtkIdType camIndex) return; } - //---------------------------------------------------------------------------- void vtkQuakeMDLImporter::ImportCameras(vtkRenderer* renderer) { From ae15bafa6d2df7fe354cbdbcac0ffade89f77c14 Mon Sep 17 00:00:00 2001 From: Youva Boutora <48061964+Youva@users.noreply.github.com> Date: Sun, 8 Sep 2024 13:56:15 -0400 Subject: [PATCH 34/60] Formatting --- plugins/native/module/vtkQuakeMDLImporter.h | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/native/module/vtkQuakeMDLImporter.h b/plugins/native/module/vtkQuakeMDLImporter.h index 1e07702f19..56b26c8e46 100644 --- a/plugins/native/module/vtkQuakeMDLImporter.h +++ b/plugins/native/module/vtkQuakeMDLImporter.h @@ -13,7 +13,6 @@ class vtkQuakeMDLImporter : public vtkImporter static vtkQuakeMDLImporter* New(); vtkTypeMacro(vtkQuakeMDLImporter, vtkImporter); - void PrintSelf(ostream& os, vtkIndent indent) override; ///@{ From 4af218904e19a3998bbc7bc854487de06e9bdbdc Mon Sep 17 00:00:00 2001 From: Youva Boutora <48061964+Youva@users.noreply.github.com> Date: Tue, 24 Sep 2024 14:09:07 -0400 Subject: [PATCH 35/60] Fixed build errors w/ strict_build --- plugins/native/module/vtkQuakeMDLImporter.cxx | 43 +++++++++---------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/plugins/native/module/vtkQuakeMDLImporter.cxx b/plugins/native/module/vtkQuakeMDLImporter.cxx index 98b33b2915..ca5ba3a60e 100644 --- a/plugins/native/module/vtkQuakeMDLImporter.cxx +++ b/plugins/native/module/vtkQuakeMDLImporter.cxx @@ -103,7 +103,7 @@ class vtkQuakeMDLImporter::vtkInternals unsigned char* skin; }; mixed_pointer_array* skins = new mixed_pointer_array[nbSkins]; - unsigned char* skin = reinterpret_cast(buffer.data() + offset + 4); + //unsigned char* skin = buffer.data() + offset + 4; for (int i = 0; i < nbSkins; i++) { int* group = reinterpret_cast(buffer.data() + offset); @@ -144,7 +144,7 @@ class vtkQuakeMDLImporter::vtkInternals } void CreateMesh( - std::vector buffer, int& offset, mdl_header_t* header, int selectedFrameIndex) + std::vector buffer, int offset, mdl_header_t* header) { // Read texture coordinates struct mdl_texcoord_t @@ -213,9 +213,9 @@ class vtkQuakeMDLImporter::vtkInternals { framePtr[i].type = type; framePtr[i].nb = reinterpret_cast(buffer.data() + 4 + offset); - mdl_vertex_t* min = reinterpret_cast(buffer.data() + 8 + offset); - mdl_vertex_t* max = reinterpret_cast(buffer.data() + 12 + offset); - float* time = framePtr[i].time = reinterpret_cast(buffer.data() + 16 + offset); + //mdl_vertex_t* min = reinterpret_cast(buffer.data() + 8 + offset); + //mdl_vertex_t* max = reinterpret_cast(buffer.data() + 12 + offset); + //float* time = framePtr[i].time = reinterpret_cast(buffer.data() + 16 + offset); framePtr[i].frames = reinterpret_cast(buffer.data() + 16 + 4 * (*framePtr[i].nb) + offset); offset += 16 + (*framePtr[i].nb) * 4; @@ -245,7 +245,7 @@ class vtkQuakeMDLImporter::vtkInternals for (int j = 0; j < 3; j++) { vertexNum[j] = triangles[i].vertex[j]; - int onseam_correct = 1; + //int onseam_correct = 1; float s = texcoords[triangles[i].vertex[j]].s; float t = texcoords[triangles[i].vertex[j]].t; if (!triangles[i].facesfront && texcoords[triangles[i].vertex[j]].onseam) @@ -284,9 +284,9 @@ class vtkQuakeMDLImporter::vtkInternals for (int j = 0; j < 3; j++) { vertexNum[j] = triangles[i].vertex[j]; - double v[3] = { selectedFrame.frames->verts[vertexNum[j]].v[0], - selectedFrame.frames->verts[vertexNum[j]].v[1], - selectedFrame.frames->verts[vertexNum[j]].v[2] }; + double v[3] = { double(selectedFrame.frames->verts[vertexNum[j]].v[0]), + double(selectedFrame.frames->verts[vertexNum[j]].v[1]), + double(selectedFrame.frames->verts[vertexNum[j]].v[2]) }; for (int k = 0; k < 3; k++) { v[k] = v[k] * header->scale[k] + header->translation[k]; @@ -335,9 +335,9 @@ class vtkQuakeMDLImporter::vtkInternals for (int j = 0; j < 3; j++) { vertexNum[j] = triangles[i].vertex[j]; - double v[3] = { selectedFrame.frames[groupFrameNum].verts[vertexNum[j]].v[0], - selectedFrame.frames[groupFrameNum].verts[vertexNum[j]].v[1], - selectedFrame.frames[groupFrameNum].verts[vertexNum[j]].v[2] }; + double v[3] = { double(selectedFrame.frames[groupFrameNum].verts[vertexNum[j]].v[0]), + double(selectedFrame.frames[groupFrameNum].verts[vertexNum[j]].v[1]), + double(selectedFrame.frames[groupFrameNum].verts[vertexNum[j]].v[2]) }; for (int k = 0; k < 3; k++) { v[k] = v[k] * header->scale[k] + header->translation[k]; @@ -379,8 +379,7 @@ class vtkQuakeMDLImporter::vtkInternals } } } - return; - + // Add interpolated frames for (int i = 0; i < Mesh.size() - 1; i++) { @@ -429,15 +428,15 @@ class vtkQuakeMDLImporter::vtkInternals buffer, offset, header->skinWidth, header->skinHeight, header->numSkins, 0); // Set polyData - this->CreateMesh(buffer, offset, header, 0); + this->CreateMesh(buffer, offset, header); return 1; } void UpdateFrame(double timeValue) { - // Hardcoded frames per second, 24FPS seems reasonable - if (abs(timeValue - LastRenderTime) > 1.0 / 24) + // Hardcoded frames per second, 60FPS + if (abs(timeValue - LastRenderTime) > 1.0 / 60) { Mapper->SetInputData( Mesh[(CurrentFrameIndex++) % (LastFrameIndex - FirstFrameIndex) + FirstFrameIndex]); @@ -662,7 +661,7 @@ vtkIdType vtkQuakeMDLImporter::GetNumberOfAnimations() //---------------------------------------------------------------------------- std::string vtkQuakeMDLImporter::GetAnimationName(vtkIdType animationIndex) { - return ""; + return std::to_string(animationIndex); } //---------------------------------------------------------------------------- @@ -681,11 +680,11 @@ void vtkQuakeMDLImporter::DisableAnimation(vtkIdType vtkNotUsed(animationIndex)) //---------------------------------------------------------------------------- bool vtkQuakeMDLImporter::IsAnimationEnabled(vtkIdType animationIndex) { - return true; + return animationIndex == this->Internals->ActiveAnimationId; } //---------------------------------------------------------------------------- -bool vtkQuakeMDLImporter::GetTemporalInformation(vtkIdType animationIndex, +bool vtkQuakeMDLImporter::GetTemporalInformation(vtkIdType vtkNotUsed(animationIndex), double vtkNotUsed(frameRate), int& vtkNotUsed(nbTimeSteps), double timeRange[2], vtkDoubleArray* vtkNotUsed(timeSteps)) { @@ -701,13 +700,13 @@ vtkIdType vtkQuakeMDLImporter::GetNumberOfCameras() } //---------------------------------------------------------------------------- -std::string vtkQuakeMDLImporter::GetCameraName(vtkIdType camIndex) +std::string vtkQuakeMDLImporter::GetCameraName(vtkIdType vtkNotUsed(camIndex)) { return "Camera"; } //---------------------------------------------------------------------------- -void vtkQuakeMDLImporter::SetCamera(vtkIdType camIndex) +void vtkQuakeMDLImporter::SetCamera(vtkIdType vtkNotUsed(camIndex)) { return; } From f049d803a6174281a1c6dd8209a278d4f81eb700 Mon Sep 17 00:00:00 2001 From: Youva Boutora <48061964+Youva@users.noreply.github.com> Date: Tue, 24 Sep 2024 14:19:34 -0400 Subject: [PATCH 36/60] Update vtkQuakeMDLImporter.cxx Fixed incorrect type at line 452. --- plugins/native/module/vtkQuakeMDLImporter.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/native/module/vtkQuakeMDLImporter.cxx b/plugins/native/module/vtkQuakeMDLImporter.cxx index ca5ba3a60e..8635907242 100644 --- a/plugins/native/module/vtkQuakeMDLImporter.cxx +++ b/plugins/native/module/vtkQuakeMDLImporter.cxx @@ -449,7 +449,7 @@ class vtkQuakeMDLImporter::vtkInternals { // Animations are divided into groups, but stored as a vector of polydata. // This functions set the indices for the first and last frames in the group. - int i = 0; + std::size_t i = 0; while (i < GroupAndTimeVal.size() && GroupAndTimeVal[++i].first < animationIndex) { } From c8ce50aa2a48be09407479313daa38559f90879e Mon Sep 17 00:00:00 2001 From: Youva Boutora <48061964+Youva@users.noreply.github.com> Date: Tue, 24 Sep 2024 14:23:17 -0400 Subject: [PATCH 37/60] Update vtkQuakeMDLImporter.cxx Changed some int variables to size_t. --- plugins/native/module/vtkQuakeMDLImporter.cxx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/native/module/vtkQuakeMDLImporter.cxx b/plugins/native/module/vtkQuakeMDLImporter.cxx index 8635907242..06afcc5f93 100644 --- a/plugins/native/module/vtkQuakeMDLImporter.cxx +++ b/plugins/native/module/vtkQuakeMDLImporter.cxx @@ -304,7 +304,7 @@ class vtkQuakeMDLImporter::vtkInternals // mesh->GetPointData()->SetNormals(normals); Mesh.push_back(mesh); std::string meshName = std::string(selectedFrame.frames->name); - for (int i = 0; i < meshName.size(); i++) + for (std::size_t i = 0; i < meshName.size(); i++) { if (meshName[i] >= '0' && meshName[i] <= '9') { @@ -355,7 +355,7 @@ class vtkQuakeMDLImporter::vtkInternals mesh->GetPointData()->SetNormals(normals); Mesh.push_back(mesh); std::string meshName = std::string(selectedFrame.frames[groupFrameNum].name); - for (int i = 0; i < meshName.size(); i++) + for (std::size_t i = 0; i < meshName.size(); i++) { if (meshName[i] >= '0' && meshName[i] <= '9') { @@ -381,7 +381,7 @@ class vtkQuakeMDLImporter::vtkInternals } // Add interpolated frames - for (int i = 0; i < Mesh.size() - 1; i++) + for (std::size_t i = 0; i < Mesh.size() - 1; i++) { if (GroupAndTimeVal[i + 1].first != GroupAndTimeVal[i].first) { From 932e2ba68ab028df9edd4462fd20fa0f37e146a1 Mon Sep 17 00:00:00 2001 From: Youva Boutora <48061964+Youva@users.noreply.github.com> Date: Tue, 24 Sep 2024 14:51:51 -0400 Subject: [PATCH 38/60] Fixed override updateTimeStep. --- plugins/native/module/vtkQuakeMDLImporter.cxx | 4 ++-- plugins/native/module/vtkQuakeMDLImporter.h | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/plugins/native/module/vtkQuakeMDLImporter.cxx b/plugins/native/module/vtkQuakeMDLImporter.cxx index 06afcc5f93..880d56e21f 100644 --- a/plugins/native/module/vtkQuakeMDLImporter.cxx +++ b/plugins/native/module/vtkQuakeMDLImporter.cxx @@ -457,7 +457,7 @@ class vtkQuakeMDLImporter::vtkInternals while (i < GroupAndTimeVal.size() && GroupAndTimeVal[++i].first == animationIndex) { } - LastFrameIndex = i - 1; + LastFrameIndex = (int) i - 1; } void ImportActors(vtkRenderer* renderer) @@ -646,7 +646,7 @@ std::string vtkQuakeMDLImporter::GetOutputsDescription() } //---------------------------------------------------------------------------- -void vtkQuakeMDLImporter::UpdateTimeStep(double timeValue) +void vtkQuakeMDLImporter::UpdateTimeStep(double timeValue) override { this->Internals->UpdateFrame(timeValue); return; diff --git a/plugins/native/module/vtkQuakeMDLImporter.h b/plugins/native/module/vtkQuakeMDLImporter.h index 56b26c8e46..dda246bdca 100644 --- a/plugins/native/module/vtkQuakeMDLImporter.h +++ b/plugins/native/module/vtkQuakeMDLImporter.h @@ -79,6 +79,11 @@ class vtkQuakeMDLImporter : public vtkImporter */ std::string GetCameraName(vtkIdType camIndex) override; + /** + * Re-render the scene after timestep + */ + void UpdateTimeStep(double timeValue) override; + /** * Enable a specific camera. * If a negative index is provided, no camera from the importer is used. From f4c1865a8ae514caa0b51b668f16dc693249b0cc Mon Sep 17 00:00:00 2001 From: Youva Boutora <48061964+Youva@users.noreply.github.com> Date: Tue, 24 Sep 2024 14:53:46 -0400 Subject: [PATCH 39/60] Removed some warnings --- plugins/native/module/vtkQuakeMDLImporter.cxx | 2 +- plugins/native/module/vtkQuakeMDLImporter.h | 7 +------ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/plugins/native/module/vtkQuakeMDLImporter.cxx b/plugins/native/module/vtkQuakeMDLImporter.cxx index 880d56e21f..d58e7c0c7a 100644 --- a/plugins/native/module/vtkQuakeMDLImporter.cxx +++ b/plugins/native/module/vtkQuakeMDLImporter.cxx @@ -646,7 +646,7 @@ std::string vtkQuakeMDLImporter::GetOutputsDescription() } //---------------------------------------------------------------------------- -void vtkQuakeMDLImporter::UpdateTimeStep(double timeValue) override +void vtkQuakeMDLImporter::UpdateTimeStep(double timeValue) { this->Internals->UpdateFrame(timeValue); return; diff --git a/plugins/native/module/vtkQuakeMDLImporter.h b/plugins/native/module/vtkQuakeMDLImporter.h index dda246bdca..c18d51543d 100644 --- a/plugins/native/module/vtkQuakeMDLImporter.h +++ b/plugins/native/module/vtkQuakeMDLImporter.h @@ -27,7 +27,7 @@ class vtkQuakeMDLImporter : public vtkImporter * Update actors at the given time value. */ - void UpdateTimeStep(double timeValue); + void UpdateTimeStep(double timeValue) override; /** * Get the number of available animations. @@ -79,11 +79,6 @@ class vtkQuakeMDLImporter : public vtkImporter */ std::string GetCameraName(vtkIdType camIndex) override; - /** - * Re-render the scene after timestep - */ - void UpdateTimeStep(double timeValue) override; - /** * Enable a specific camera. * If a negative index is provided, no camera from the importer is used. From b203e95d4e88b5a0a47b2cb1c30eb4751d69023a Mon Sep 17 00:00:00 2001 From: Youva Boutora <48061964+Youva@users.noreply.github.com> Date: Tue, 24 Sep 2024 14:59:49 -0400 Subject: [PATCH 40/60] Applied style. --- plugins/native/module/vtkQuakeMDLImporter.cxx | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/plugins/native/module/vtkQuakeMDLImporter.cxx b/plugins/native/module/vtkQuakeMDLImporter.cxx index d58e7c0c7a..8f1ed04572 100644 --- a/plugins/native/module/vtkQuakeMDLImporter.cxx +++ b/plugins/native/module/vtkQuakeMDLImporter.cxx @@ -103,7 +103,7 @@ class vtkQuakeMDLImporter::vtkInternals unsigned char* skin; }; mixed_pointer_array* skins = new mixed_pointer_array[nbSkins]; - //unsigned char* skin = buffer.data() + offset + 4; + // unsigned char* skin = buffer.data() + offset + 4; for (int i = 0; i < nbSkins; i++) { int* group = reinterpret_cast(buffer.data() + offset); @@ -143,8 +143,7 @@ class vtkQuakeMDLImporter::vtkInternals return texture; } - void CreateMesh( - std::vector buffer, int offset, mdl_header_t* header) + void CreateMesh(std::vector buffer, int offset, mdl_header_t* header) { // Read texture coordinates struct mdl_texcoord_t @@ -213,9 +212,9 @@ class vtkQuakeMDLImporter::vtkInternals { framePtr[i].type = type; framePtr[i].nb = reinterpret_cast(buffer.data() + 4 + offset); - //mdl_vertex_t* min = reinterpret_cast(buffer.data() + 8 + offset); - //mdl_vertex_t* max = reinterpret_cast(buffer.data() + 12 + offset); - //float* time = framePtr[i].time = reinterpret_cast(buffer.data() + 16 + offset); + // mdl_vertex_t* min = reinterpret_cast(buffer.data() + 8 + offset); + // mdl_vertex_t* max = reinterpret_cast(buffer.data() + 12 + offset); + // float* time = framePtr[i].time = reinterpret_cast(buffer.data() + 16 + offset); framePtr[i].frames = reinterpret_cast(buffer.data() + 16 + 4 * (*framePtr[i].nb) + offset); offset += 16 + (*framePtr[i].nb) * 4; @@ -245,7 +244,7 @@ class vtkQuakeMDLImporter::vtkInternals for (int j = 0; j < 3; j++) { vertexNum[j] = triangles[i].vertex[j]; - //int onseam_correct = 1; + // int onseam_correct = 1; float s = texcoords[triangles[i].vertex[j]].s; float t = texcoords[triangles[i].vertex[j]].t; if (!triangles[i].facesfront && texcoords[triangles[i].vertex[j]].onseam) @@ -379,7 +378,7 @@ class vtkQuakeMDLImporter::vtkInternals } } } - + // Add interpolated frames for (std::size_t i = 0; i < Mesh.size() - 1; i++) { @@ -457,7 +456,7 @@ class vtkQuakeMDLImporter::vtkInternals while (i < GroupAndTimeVal.size() && GroupAndTimeVal[++i].first == animationIndex) { } - LastFrameIndex = (int) i - 1; + LastFrameIndex = (int)i - 1; } void ImportActors(vtkRenderer* renderer) From ac074e830d398161eb64c28682dcaa64b8aa88ba Mon Sep 17 00:00:00 2001 From: Youva Boutora <48061964+Youva@users.noreply.github.com> Date: Tue, 24 Sep 2024 15:23:26 -0400 Subject: [PATCH 41/60] Changed push_back to emplace_back --- plugins/native/module/vtkQuakeMDLImporter.cxx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/native/module/vtkQuakeMDLImporter.cxx b/plugins/native/module/vtkQuakeMDLImporter.cxx index 8f1ed04572..a807e7f742 100644 --- a/plugins/native/module/vtkQuakeMDLImporter.cxx +++ b/plugins/native/module/vtkQuakeMDLImporter.cxx @@ -301,7 +301,7 @@ class vtkQuakeMDLImporter::vtkInternals mesh->SetPolys(cells); mesh->GetPointData()->SetTCoords(textureCoordinates); // mesh->GetPointData()->SetNormals(normals); - Mesh.push_back(mesh); + Mesh.emplace_back(mesh); std::string meshName = std::string(selectedFrame.frames->name); for (std::size_t i = 0; i < meshName.size(); i++) { @@ -322,7 +322,7 @@ class vtkQuakeMDLImporter::vtkInternals NumberOfAnimations++; } std::pair pair = std::make_pair(frameIndex, 0.0); - GroupAndTimeVal.push_back(pair); + GroupAndTimeVal.emplace_back(pair); } else { @@ -352,7 +352,7 @@ class vtkQuakeMDLImporter::vtkInternals mesh->SetPolys(cells); mesh->GetPointData()->SetTCoords(textureCoordinates); mesh->GetPointData()->SetNormals(normals); - Mesh.push_back(mesh); + Mesh.emplace_back(mesh); std::string meshName = std::string(selectedFrame.frames[groupFrameNum].name); for (std::size_t i = 0; i < meshName.size(); i++) { @@ -374,7 +374,7 @@ class vtkQuakeMDLImporter::vtkInternals } std::pair pair = std::make_pair(frameIndex, selectedFrame.time[groupFrameNum]); - GroupAndTimeVal.push_back(pair); + GroupAndTimeVal.emplace_back(pair); } } } From cff7f92de1ac096769bd9d604fe2e2fe91628651 Mon Sep 17 00:00:00 2001 From: Youva Boutora <48061964+Youva@users.noreply.github.com> Date: Tue, 24 Sep 2024 15:32:22 -0400 Subject: [PATCH 42/60] Return bool l. 432 --- plugins/native/module/vtkQuakeMDLImporter.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/native/module/vtkQuakeMDLImporter.cxx b/plugins/native/module/vtkQuakeMDLImporter.cxx index a807e7f742..f6ff02bcf8 100644 --- a/plugins/native/module/vtkQuakeMDLImporter.cxx +++ b/plugins/native/module/vtkQuakeMDLImporter.cxx @@ -429,7 +429,7 @@ class vtkQuakeMDLImporter::vtkInternals // Set polyData this->CreateMesh(buffer, offset, header); - return 1; + return true; } void UpdateFrame(double timeValue) From 8a4744c4d9c5f2cafb92abb13087a697df3133b7 Mon Sep 17 00:00:00 2001 From: Youva Boutora <48061964+Youva@users.noreply.github.com> Date: Tue, 24 Sep 2024 16:52:44 -0400 Subject: [PATCH 43/60] Fix unusedStructMember and containerOutOfBounds --- plugins/native/module/vtkQuakeMDLImporter.cxx | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/plugins/native/module/vtkQuakeMDLImporter.cxx b/plugins/native/module/vtkQuakeMDLImporter.cxx index f6ff02bcf8..a87f21a7fe 100644 --- a/plugins/native/module/vtkQuakeMDLImporter.cxx +++ b/plugins/native/module/vtkQuakeMDLImporter.cxx @@ -87,15 +87,16 @@ class vtkQuakeMDLImporter::vtkInternals // Read textures. struct mdl_skin_t { - int group; /* 0 = single, 1 = group */ - unsigned char* data; /* texture data */ + + //int group; /* 0 = single, 1 = group */ + //unsigned char* data; /* texture data */ }; struct mdl_groupskin_t { - int group; /* 1 = group */ - int nb; /* number of pics */ - float* time; /* time duration for each pic */ - unsigned char** data; /* texture data */ + //int group; /* 1 = group */ + //int nb; /* number of pics */ + //float* time; /* time duration for each pic */ + //unsigned char** data; /* texture data */ }; struct mixed_pointer_array { @@ -177,17 +178,17 @@ class vtkQuakeMDLImporter::vtkInternals }; struct mdl_frame_t { - int type; +// int type; mdl_simpleframe_t frame; }; struct mdl_groupframe_t { - int type; - int nb; +// int type; +// int nb; mdl_vertex_t min; mdl_vertex_t max; - float* time; // Size is nbFrames ??? - mdl_simpleframe_t* frames; // Size is nbFrames ??? +// float* time; // Size is nbFrames ??? +// mdl_simpleframe_t* frames; // Size is nbFrames ??? }; struct plugin_frame_pointer { @@ -449,11 +450,11 @@ class vtkQuakeMDLImporter::vtkInternals // Animations are divided into groups, but stored as a vector of polydata. // This functions set the indices for the first and last frames in the group. std::size_t i = 0; - while (i < GroupAndTimeVal.size() && GroupAndTimeVal[++i].first < animationIndex) + while (i < GroupAndTimeVal.size() - 1 && GroupAndTimeVal[++i].first < animationIndex) { } FirstFrameIndex = animationIndex == 0 ? 0 : LastFrameIndex + 1; - while (i < GroupAndTimeVal.size() && GroupAndTimeVal[++i].first == animationIndex) + while (i < GroupAndTimeVal.size() - 1 && GroupAndTimeVal[++i].first == animationIndex) { } LastFrameIndex = (int)i - 1; From e9e9b066ebd6ec9bd9b2c149f3cfdf13d3a4fdc6 Mon Sep 17 00:00:00 2001 From: Youva Boutora <48061964+Youva@users.noreply.github.com> Date: Tue, 24 Sep 2024 16:58:29 -0400 Subject: [PATCH 44/60] Coding style modification. --- plugins/native/module/vtkQuakeMDLImporter.cxx | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/plugins/native/module/vtkQuakeMDLImporter.cxx b/plugins/native/module/vtkQuakeMDLImporter.cxx index a87f21a7fe..1a1e42ace1 100644 --- a/plugins/native/module/vtkQuakeMDLImporter.cxx +++ b/plugins/native/module/vtkQuakeMDLImporter.cxx @@ -88,15 +88,15 @@ class vtkQuakeMDLImporter::vtkInternals struct mdl_skin_t { - //int group; /* 0 = single, 1 = group */ - //unsigned char* data; /* texture data */ + // int group; /* 0 = single, 1 = group */ + // unsigned char* data; /* texture data */ }; struct mdl_groupskin_t { - //int group; /* 1 = group */ - //int nb; /* number of pics */ - //float* time; /* time duration for each pic */ - //unsigned char** data; /* texture data */ + // int group; /* 1 = group */ + // int nb; /* number of pics */ + // float* time; /* time duration for each pic */ + // unsigned char** data; /* texture data */ }; struct mixed_pointer_array { @@ -178,17 +178,17 @@ class vtkQuakeMDLImporter::vtkInternals }; struct mdl_frame_t { -// int type; + // int type; mdl_simpleframe_t frame; }; struct mdl_groupframe_t { -// int type; -// int nb; + // int type; + // int nb; mdl_vertex_t min; mdl_vertex_t max; -// float* time; // Size is nbFrames ??? -// mdl_simpleframe_t* frames; // Size is nbFrames ??? + // float* time; // Size is nbFrames ??? + // mdl_simpleframe_t* frames; // Size is nbFrames ??? }; struct plugin_frame_pointer { From ee4b66c3265deeeef39d5ac3c6cbf6e486d7c436 Mon Sep 17 00:00:00 2001 From: Youva Boutora <48061964+Youva@users.noreply.github.com> Date: Tue, 17 Dec 2024 11:48:49 -0500 Subject: [PATCH 45/60] Added unit test --- application/testing/CMakeLists.txt | 1 + .../native/configs/config.d/10_native.json | 2 +- plugins/native/module/vtkQuakeMDLImporter.cxx | 731 ------------------ .../native/module/vtkQuakeMDLImporter.cxx.rej | 9 - plugins/native/module/vtkQuakeMDLImporter.h | 133 ---- .../native/module/vtkQuakeMDLImporter.h.rej | 17 - style.diff | 344 --------- 7 files changed, 2 insertions(+), 1235 deletions(-) delete mode 100644 plugins/native/module/vtkQuakeMDLImporter.cxx delete mode 100644 plugins/native/module/vtkQuakeMDLImporter.cxx.rej delete mode 100644 plugins/native/module/vtkQuakeMDLImporter.h delete mode 100644 plugins/native/module/vtkQuakeMDLImporter.h.rej delete mode 100644 style.diff diff --git a/application/testing/CMakeLists.txt b/application/testing/CMakeLists.txt index f03d6808bb..55a3eb646c 100644 --- a/application/testing/CMakeLists.txt +++ b/application/testing/CMakeLists.txt @@ -150,6 +150,7 @@ f3d_test(NAME TestVTM DATA mb.vtm UI) f3d_test(NAME TestVTK DATA cow.vtk) f3d_test(NAME TestNRRD DATA beach.nrrd ARGS -s) f3d_test(NAME TestSPLAT DATA small.splat ARGS -osy --up=-Y --point-sprites-size=1) +f3d_test(NAME TestQuakeMDL DATA glaunch.mdl) 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) diff --git a/plugins/native/configs/config.d/10_native.json b/plugins/native/configs/config.d/10_native.json index 0dfcaaeb3e..4dc3f5dd10 100644 --- a/plugins/native/configs/config.d/10_native.json +++ b/plugins/native/configs/config.d/10_native.json @@ -67,7 +67,7 @@ "grid": false, "anti-aliasing": false, "translucency-support": false - }, + } }, { "match": ".*(mdl)", diff --git a/plugins/native/module/vtkQuakeMDLImporter.cxx b/plugins/native/module/vtkQuakeMDLImporter.cxx deleted file mode 100644 index 1a1e42ace1..0000000000 --- a/plugins/native/module/vtkQuakeMDLImporter.cxx +++ /dev/null @@ -1,731 +0,0 @@ -#include "vtkQuakeMDLImporter.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -//---------------------------------------------------------------------------- -vtkStandardNewMacro(vtkQuakeMDLImporter); - -class vtkQuakeMDLImporter::vtkInternals -{ -public: - //---------------------------------------------------------------------------- - explicit vtkInternals(vtkQuakeMDLImporter* parent) - : Parent(parent) - { - } - - //---------------------------------------------------------------------------- - void ImportCameras(vtkRenderer* renderer) - { - double cameraPosition[3] = { 50.0, 15.0, 0.0 }; - vtkNew roll; - roll->RotateX(270); - roll->RotateZ(270); - renderer->GetActiveCamera()->SetPosition(cameraPosition); - renderer->GetActiveCamera()->SetModelTransformMatrix(roll->GetMatrix()); - } - - //---------------------------------------------------------------------------- - void ImportLights(vtkRenderer* renderer) - { - // Adds 3 lights, there's already one on the right side. - - vtkNew frontLight; - double frontLightPosition[3] = { 50.0, 50.0, 0.0 }; - frontLight->SetPosition(frontLightPosition); - vtkNew leftLight; - double leftLightPosition[3] = { 50.0, -50.0, 0.0 }; - leftLight->SetPosition(leftLightPosition); - vtkNew backLight; - double backLightPosition[3] = { -50.0, 0.0, 0.0 }; - backLight->SetPosition(backLightPosition); - - renderer->AddLight(frontLight); - renderer->AddLight(leftLight); - renderer->AddLight(backLight); - } - - //---------------------------------------------------------------------------- - vtkSmartPointer CreateTexture(std::vector buffer, int& offset, - int skinWidth, int skinHeight, int nbSkins, int selectedSkinIndex) - { - vtkNew texture; - texture->InterpolateOn(); - - // Read textures. - struct mdl_skin_t - { - - // int group; /* 0 = single, 1 = group */ - // unsigned char* data; /* texture data */ - }; - struct mdl_groupskin_t - { - // int group; /* 1 = group */ - // int nb; /* number of pics */ - // float* time; /* time duration for each pic */ - // unsigned char** data; /* texture data */ - }; - struct mixed_pointer_array - { - int group; - unsigned char* skin; - }; - mixed_pointer_array* skins = new mixed_pointer_array[nbSkins]; - // unsigned char* skin = buffer.data() + offset + 4; - for (int i = 0; i < nbSkins; i++) - { - int* group = reinterpret_cast(buffer.data() + offset); - if (*group == 0) - { - skins[i].group = 0; - skins[i].skin = reinterpret_cast(buffer.data() + 4 + offset); - offset += 4 + (skinWidth) * (skinHeight); - } - else - { - skins[i].group = 1; - int nb = *reinterpret_cast(buffer.data() + offset + 4); - skins[i].skin = reinterpret_cast(buffer.data() + 4 + nb * 4 + offset); - offset += 4 + nb * 4 + nb * (skinWidth) * (skinHeight); - } - } - - // Copy to imageData - vtkNew img; - img->SetDimensions(skinWidth, skinHeight, 1); - img->AllocateScalars(VTK_UNSIGNED_CHAR, 3); - unsigned char* selectedSkin = skins[selectedSkinIndex].skin; - for (int i = 0; i < skinHeight; i++) - { - for (int j = 0; j < skinWidth; j++) - { - unsigned char index = *reinterpret_cast(selectedSkin + i * skinWidth + j); - unsigned char* ptr = reinterpret_cast(img->GetScalarPointer(j, i, 0)); - ptr[0] = DefaultColorMap[index][0]; // R - ptr[1] = DefaultColorMap[index][1]; // G - ptr[2] = DefaultColorMap[index][2]; // B - } - } - - texture->SetInputData(img); - return texture; - } - - void CreateMesh(std::vector buffer, int offset, mdl_header_t* header) - { - // Read texture coordinates - struct mdl_texcoord_t - { - int onseam; - int s; - int t; - }; - mdl_texcoord_t* texcoords = reinterpret_cast(buffer.data() + offset); - offset += 12 * header->numVertices; - // Read triangles - struct mdl_triangle_t - { - int facesfront; /* 0 = backface, 1 = frontface */ - int vertex[3]; /* vertex indices */ - }; - mdl_triangle_t* triangles = reinterpret_cast(buffer.data() + offset); - offset += 16 * header->numTriangles; - // Read frames - struct mdl_vertex_t // 4 bytes - { - unsigned char v[3]; - unsigned char normalIndex; - }; - struct mdl_simpleframe_t // 24 + nbVertices bytes - { - mdl_vertex_t bboxmin; - mdl_vertex_t bboxmax; - char name[16]; - mdl_vertex_t verts[1024]; // Maximum capacity is 1024 vertices - }; - struct mdl_frame_t - { - // int type; - mdl_simpleframe_t frame; - }; - struct mdl_groupframe_t - { - // int type; - // int nb; - mdl_vertex_t min; - mdl_vertex_t max; - // float* time; // Size is nbFrames ??? - // mdl_simpleframe_t* frames; // Size is nbFrames ??? - }; - struct plugin_frame_pointer - { - int* type; - int* nb; - float* time; - mdl_simpleframe_t* frames; - }; - plugin_frame_pointer* framePtr = new plugin_frame_pointer[header->numFrames]; - for (int i = 0; i < header->numFrames; i++) - { - int* type = reinterpret_cast(buffer.data() + offset); - if (*type == 0) - { - framePtr[i].type = type; - framePtr[i].nb = nullptr; - framePtr[i].time = nullptr; - framePtr[i].frames = reinterpret_cast(buffer.data() + 4 + offset); - offset += 4 + 24 + 4 * (header->numVertices); - } - else - { - framePtr[i].type = type; - framePtr[i].nb = reinterpret_cast(buffer.data() + 4 + offset); - // mdl_vertex_t* min = reinterpret_cast(buffer.data() + 8 + offset); - // mdl_vertex_t* max = reinterpret_cast(buffer.data() + 12 + offset); - // float* time = framePtr[i].time = reinterpret_cast(buffer.data() + 16 + offset); - framePtr[i].frames = - reinterpret_cast(buffer.data() + 16 + 4 * (*framePtr[i].nb) + offset); - offset += 16 + (*framePtr[i].nb) * 4; - for (int j = 0; j < *framePtr[i].nb; j++) - { - offset += 24 + 4 * header->numVertices; - } - } - } - // Draw cells - vtkNew cells; - cells->Allocate(header->numTriangles); - vtkNew textureCoordinates; - textureCoordinates->SetNumberOfComponents(2); - textureCoordinates->SetName("TextureCoordinates"); - textureCoordinates->Allocate(header->numTriangles * 3); - struct plugin_texture_coords - { - float s; - float t; - int id; - }; - plugin_texture_coords* coords = new plugin_texture_coords[header->numTriangles * 3]; - for (int i = 0; i < header->numTriangles; i++) - { - vtkIdType* vertexNum = new vtkIdType[3]; - for (int j = 0; j < 3; j++) - { - vertexNum[j] = triangles[i].vertex[j]; - // int onseam_correct = 1; - float s = texcoords[triangles[i].vertex[j]].s; - float t = texcoords[triangles[i].vertex[j]].t; - if (!triangles[i].facesfront && texcoords[triangles[i].vertex[j]].onseam) - { - s = s + header->skinWidth * 0.5f; - } - s = (s + 0.5) / header->skinWidth; - t = (t + 0.5) / header->skinHeight; - coords[3 * i + j].s = s; - coords[3 * i + j].t = t; - coords[3 * i + j].id = triangles[i].vertex[j]; - float st[2] = { s, t }; - textureCoordinates->InsertNextTuple(st); - } - vtkIdType t[3] = { i * 3, i * 3 + 1, i * 3 + 2 }; - cells->InsertNextCell(3, t); - } - - // Draw vertices - std::string frameName = ""; - int frameIndex = 0; - for (int frameNum = 0; frameNum < header->numFrames; frameNum++) - { - vtkNew vertices; - vertices->Allocate(header->numTriangles * 3); - vtkNew normals; - normals->SetNumberOfComponents(3); - normals->Allocate(header->numTriangles * 3 * 3); - - plugin_frame_pointer selectedFrame = framePtr[frameNum]; - if (*selectedFrame.type == 0) - { - for (int i = 0; i < header->numTriangles; i++) - { - vtkIdType* vertexNum = new vtkIdType[3]; - for (int j = 0; j < 3; j++) - { - vertexNum[j] = triangles[i].vertex[j]; - double v[3] = { double(selectedFrame.frames->verts[vertexNum[j]].v[0]), - double(selectedFrame.frames->verts[vertexNum[j]].v[1]), - double(selectedFrame.frames->verts[vertexNum[j]].v[2]) }; - for (int k = 0; k < 3; k++) - { - v[k] = v[k] * header->scale[k] + header->translation[k]; - } - vertices->InsertPoint(i * 3 + j, v); - int normalIndex = selectedFrame.frames->verts[vertexNum[j]].normalIndex; - normals->SetTuple3(i * 3 + j, NormalVectors[normalIndex][0] / 255.0, - NormalVectors[normalIndex][1] / 255.0, NormalVectors[normalIndex][2] / 255.0); - } - } - vtkNew mesh; - mesh->SetPoints(vertices); - mesh->SetPolys(cells); - mesh->GetPointData()->SetTCoords(textureCoordinates); - // mesh->GetPointData()->SetNormals(normals); - Mesh.emplace_back(mesh); - std::string meshName = std::string(selectedFrame.frames->name); - for (std::size_t i = 0; i < meshName.size(); i++) - { - if (meshName[i] >= '0' && meshName[i] <= '9') - { - meshName = meshName.substr(0, i); - break; - } - } - if (frameNum == 0) - { - frameName = meshName; - } - else if (meshName != frameName) - { - frameIndex++; - frameName = meshName; - NumberOfAnimations++; - } - std::pair pair = std::make_pair(frameIndex, 0.0); - GroupAndTimeVal.emplace_back(pair); - } - else - { - for (int groupFrameNum = 0; groupFrameNum < *selectedFrame.nb; groupFrameNum++) - { - for (int i = 0; i < header->numTriangles; i++) - { - vtkIdType* vertexNum = new vtkIdType[3]; - for (int j = 0; j < 3; j++) - { - vertexNum[j] = triangles[i].vertex[j]; - double v[3] = { double(selectedFrame.frames[groupFrameNum].verts[vertexNum[j]].v[0]), - double(selectedFrame.frames[groupFrameNum].verts[vertexNum[j]].v[1]), - double(selectedFrame.frames[groupFrameNum].verts[vertexNum[j]].v[2]) }; - for (int k = 0; k < 3; k++) - { - v[k] = v[k] * header->scale[k] + header->translation[k]; - } - vertices->InsertPoint(i * 3 + j, v); - int normalIndex = selectedFrame.frames[groupFrameNum].verts[vertexNum[j]].normalIndex; - normals->SetTuple3(i * 3 + j, NormalVectors[normalIndex][0] / 255.0, - NormalVectors[normalIndex][1] / 255.0, NormalVectors[normalIndex][2] / 255.0); - } - } - vtkNew mesh; - mesh->SetPoints(vertices); - mesh->SetPolys(cells); - mesh->GetPointData()->SetTCoords(textureCoordinates); - mesh->GetPointData()->SetNormals(normals); - Mesh.emplace_back(mesh); - std::string meshName = std::string(selectedFrame.frames[groupFrameNum].name); - for (std::size_t i = 0; i < meshName.size(); i++) - { - if (meshName[i] >= '0' && meshName[i] <= '9') - { - meshName = meshName.substr(0, i - 1); - break; - } - } - if (frameNum == 0) - { - frameName = meshName; - } - else if (meshName != frameName) - { - frameIndex++; - NumberOfAnimations++; - frameName = meshName; - } - std::pair pair = - std::make_pair(frameIndex, selectedFrame.time[groupFrameNum]); - GroupAndTimeVal.emplace_back(pair); - } - } - } - - // Add interpolated frames - for (std::size_t i = 0; i < Mesh.size() - 1; i++) - { - if (GroupAndTimeVal[i + 1].first != GroupAndTimeVal[i].first) - { - continue; - } - else - { - vtkNew vertices; - vertices->Allocate(header->numTriangles * 3); - for (int j = 0; j < header->numTriangles * 3; j++) - { - double* v_0 = Mesh[i]->GetPoint(j); - double* v_1 = Mesh[i + 1]->GetPoint(j); - double* interp = new double[3]; - interp[0] = v_0[0] + 0.5 * (v_1[0] - v_0[0]); - interp[1] = v_0[1] + 0.5 * (v_1[1] - v_0[1]); - interp[2] = v_0[2] + 0.5 * (v_1[2] - v_0[2]); - vertices->InsertPoint(j, interp); - } - vtkNew mesh; - mesh->SetPoints(vertices); - mesh->SetPolys(cells); - mesh->GetPointData()->SetTCoords(textureCoordinates); - Mesh.insert(Mesh.begin() + i, mesh); - std::pair pair = std::make_pair(GroupAndTimeVal[i].first, - (GroupAndTimeVal[i].second + GroupAndTimeVal[i + 1].second) / 2); - GroupAndTimeVal.insert(GroupAndTimeVal.begin() + i, pair); - i++; - } - } - } - - //---------------------------------------------------------------------------- - bool ReadScene(const std::string& filePath) - { - std::ifstream inputStream(filePath, std::ios::binary); - std::vector buffer(std::istreambuf_iterator(inputStream), {}); - // Read header - mdl_header_t* header = reinterpret_cast(buffer.data()); - int offset = 84; - - // Set textures - Texture = this->CreateTexture( - buffer, offset, header->skinWidth, header->skinHeight, header->numSkins, 0); - - // Set polyData - this->CreateMesh(buffer, offset, header); - - return true; - } - - void UpdateFrame(double timeValue) - { - // Hardcoded frames per second, 60FPS - if (abs(timeValue - LastRenderTime) > 1.0 / 60) - { - Mapper->SetInputData( - Mesh[(CurrentFrameIndex++) % (LastFrameIndex - FirstFrameIndex) + FirstFrameIndex]); - LastRenderTime = timeValue; - } - } - - // Only one animation enabled at a time - void EnableAnimation(vtkIdType animationIndex) - { - // Animations are divided into groups, but stored as a vector of polydata. - // This functions set the indices for the first and last frames in the group. - std::size_t i = 0; - while (i < GroupAndTimeVal.size() - 1 && GroupAndTimeVal[++i].first < animationIndex) - { - } - FirstFrameIndex = animationIndex == 0 ? 0 : LastFrameIndex + 1; - while (i < GroupAndTimeVal.size() - 1 && GroupAndTimeVal[++i].first == animationIndex) - { - } - LastFrameIndex = (int)i - 1; - } - - void ImportActors(vtkRenderer* renderer) - { - vtkNew actor; - vtkNew mapper; - mapper->SetInputData(Mesh[0]); - actor->SetMapper(mapper); - actor->SetTexture(Texture); - renderer->AddActor(actor); - renderer->SetBackground(0, 0, 0); - - Actor = actor; - Mapper = mapper; - } - - vtkQuakeMDLImporter* Parent; - std::string Description; - vtkSmartPointer Actor; - vtkSmartPointer Mapper; - std::vector> Mesh; - std::vector> GroupAndTimeVal; - int ActiveAnimationId = 0; - int CurrentFrameIndex = 0; - int FirstFrameIndex = 0; - int LastFrameIndex = 10; - int NumberOfAnimations = 0; - double LastRenderTime = 0.0; - vtkSmartPointer Texture; - vtkSmartPointer TextureCoords; - unsigned char DefaultColorMap[256][3] = { { 0, 0, 0 }, { 15, 15, 15 }, { 31, 31, 31 }, - { 47, 47, 47 }, { 63, 63, 63 }, { 75, 75, 75 }, { 91, 91, 91 }, { 107, 107, 107 }, - { 123, 123, 123 }, { 139, 139, 139 }, { 155, 155, 155 }, { 171, 171, 171 }, { 187, 187, 187 }, - { 203, 203, 203 }, { 219, 219, 219 }, { 235, 235, 235 }, { 15, 11, 7 }, { 23, 15, 11 }, - { 31, 23, 11 }, { 39, 27, 15 }, { 47, 35, 19 }, { 55, 43, 23 }, { 63, 47, 23 }, { 75, 55, 27 }, - { 83, 59, 27 }, { 91, 67, 31 }, { 99, 75, 31 }, { 107, 83, 31 }, { 115, 87, 31 }, - { 123, 95, 35 }, { 131, 103, 35 }, { 143, 111, 35 }, { 11, 11, 15 }, { 19, 19, 27 }, - { 27, 27, 39 }, { 39, 39, 51 }, { 47, 47, 63 }, { 55, 55, 75 }, { 63, 63, 87 }, { 71, 71, 103 }, - { 79, 79, 115 }, { 91, 91, 127 }, { 99, 99, 139 }, { 107, 107, 151 }, { 115, 115, 163 }, - { 123, 123, 175 }, { 131, 131, 187 }, { 139, 139, 203 }, { 0, 0, 0 }, { 7, 7, 0 }, - { 11, 11, 0 }, { 19, 19, 0 }, { 27, 27, 0 }, { 35, 35, 0 }, { 43, 43, 7 }, { 47, 47, 7 }, - { 55, 55, 7 }, { 63, 63, 7 }, { 71, 71, 7 }, { 75, 75, 11 }, { 83, 83, 11 }, { 91, 91, 11 }, - { 99, 99, 11 }, { 107, 107, 15 }, { 7, 0, 0 }, { 15, 0, 0 }, { 23, 0, 0 }, { 31, 0, 0 }, - { 39, 0, 0 }, { 47, 0, 0 }, { 55, 0, 0 }, { 63, 0, 0 }, { 71, 0, 0 }, { 79, 0, 0 }, - { 87, 0, 0 }, { 95, 0, 0 }, { 103, 0, 0 }, { 111, 0, 0 }, { 119, 0, 0 }, { 127, 0, 0 }, - { 19, 19, 0 }, { 27, 27, 0 }, { 35, 35, 0 }, { 47, 43, 0 }, { 55, 47, 0 }, { 67, 55, 0 }, - { 75, 59, 7 }, { 87, 67, 7 }, { 95, 71, 7 }, { 107, 75, 11 }, { 119, 83, 15 }, { 131, 87, 19 }, - { 139, 91, 19 }, { 151, 95, 27 }, { 163, 99, 31 }, { 175, 103, 35 }, { 35, 19, 7 }, - { 47, 23, 11 }, { 59, 31, 15 }, { 75, 35, 19 }, { 87, 43, 23 }, { 99, 47, 31 }, { 115, 55, 35 }, - { 127, 59, 43 }, { 143, 67, 51 }, { 159, 79, 51 }, { 175, 99, 47 }, { 191, 119, 47 }, - { 207, 143, 43 }, { 223, 171, 39 }, { 239, 203, 31 }, { 255, 243, 27 }, { 11, 7, 0 }, - { 27, 19, 0 }, { 43, 35, 15 }, { 55, 43, 19 }, { 71, 51, 27 }, { 83, 55, 35 }, { 99, 63, 43 }, - { 111, 71, 51 }, { 127, 83, 63 }, { 139, 95, 71 }, { 155, 107, 83 }, { 167, 123, 95 }, - { 183, 135, 107 }, { 195, 147, 123 }, { 211, 163, 139 }, { 227, 179, 151 }, { 171, 139, 163 }, - { 159, 127, 151 }, { 147, 115, 135 }, { 139, 103, 123 }, { 127, 91, 111 }, { 119, 83, 99 }, - { 107, 75, 87 }, { 95, 63, 75 }, { 87, 55, 67 }, { 75, 47, 55 }, { 67, 39, 47 }, { 55, 31, 35 }, - { 43, 23, 27 }, { 35, 19, 19 }, { 23, 11, 11 }, { 15, 7, 7 }, { 187, 115, 159 }, - { 175, 107, 143 }, { 163, 95, 131 }, { 151, 87, 119 }, { 139, 79, 107 }, { 127, 75, 95 }, - { 115, 67, 83 }, { 107, 59, 75 }, { 95, 51, 63 }, { 83, 43, 55 }, { 71, 35, 43 }, - { 59, 31, 35 }, { 47, 23, 27 }, { 35, 19, 19 }, { 23, 11, 11 }, { 15, 7, 7 }, { 219, 195, 187 }, - { 203, 179, 167 }, { 191, 163, 155 }, { 175, 151, 139 }, { 163, 135, 123 }, { 151, 123, 111 }, - { 135, 111, 95 }, { 123, 99, 83 }, { 107, 87, 71 }, { 95, 75, 59 }, { 83, 63, 51 }, - { 67, 51, 39 }, { 55, 43, 31 }, { 39, 31, 23 }, { 27, 19, 15 }, { 15, 11, 7 }, - { 111, 131, 123 }, { 103, 123, 111 }, { 95, 115, 103 }, { 87, 107, 95 }, { 79, 99, 87 }, - { 71, 91, 79 }, { 63, 83, 71 }, { 55, 75, 63 }, { 47, 67, 55 }, { 43, 59, 47 }, { 35, 51, 39 }, - { 31, 43, 31 }, { 23, 35, 23 }, { 15, 27, 19 }, { 11, 19, 11 }, { 7, 11, 7 }, { 255, 243, 27 }, - { 239, 223, 23 }, { 219, 203, 19 }, { 203, 183, 15 }, { 187, 167, 15 }, { 171, 151, 11 }, - { 155, 131, 7 }, { 139, 115, 7 }, { 123, 99, 7 }, { 107, 83, 0 }, { 91, 71, 0 }, { 75, 55, 0 }, - { 59, 43, 0 }, { 43, 31, 0 }, { 27, 15, 0 }, { 11, 7, 0 }, { 0, 0, 255 }, { 11, 11, 239 }, - { 19, 19, 223 }, { 27, 27, 207 }, { 35, 35, 191 }, { 43, 43, 175 }, { 47, 47, 159 }, - { 47, 47, 143 }, { 47, 47, 127 }, { 47, 47, 111 }, { 47, 47, 95 }, { 43, 43, 79 }, - { 35, 35, 63 }, { 27, 27, 47 }, { 19, 19, 31 }, { 11, 11, 15 }, { 43, 0, 0 }, { 59, 0, 0 }, - { 75, 7, 0 }, { 95, 7, 0 }, { 111, 15, 0 }, { 127, 23, 7 }, { 147, 31, 7 }, { 163, 39, 11 }, - { 183, 51, 15 }, { 195, 75, 27 }, { 207, 99, 43 }, { 219, 127, 59 }, { 227, 151, 79 }, - { 231, 171, 95 }, { 239, 191, 119 }, { 247, 211, 139 }, { 167, 123, 59 }, { 183, 155, 55 }, - { 199, 195, 55 }, { 231, 227, 87 }, { 127, 191, 255 }, { 171, 231, 255 }, { 215, 255, 255 }, - { 103, 0, 0 }, { 139, 0, 0 }, { 179, 0, 0 }, { 215, 0, 0 }, { 255, 0, 0 }, { 255, 243, 147 }, - { 255, 247, 199 }, { 255, 255, 255 }, { 159, 91, 83 } }; - float NormalVectors[162][3] = { { -0.525731f, 0.000000f, 0.850651f }, - { -0.442863f, 0.238856f, 0.864188f }, { -0.295242f, 0.000000f, 0.955423f }, - { -0.309017f, 0.500000f, 0.809017f }, { -0.162460f, 0.262866f, 0.951056f }, - { 0.000000f, 0.000000f, 1.000000f }, { 0.000000f, 0.850651f, 0.525731f }, - { -0.147621f, 0.716567f, 0.681718f }, { 0.147621f, 0.716567f, 0.681718f }, - { 0.000000f, 0.525731f, 0.850651f }, { 0.309017f, 0.500000f, 0.809017f }, - { 0.525731f, 0.000000f, 0.850651f }, { 0.295242f, 0.000000f, 0.955423f }, - { 0.442863f, 0.238856f, 0.864188f }, { 0.162460f, 0.262866f, 0.951056f }, - { -0.681718f, 0.147621f, 0.716567f }, { -0.809017f, 0.309017f, 0.500000f }, - { -0.587785f, 0.425325f, 0.688191f }, { -0.850651f, 0.525731f, 0.000000f }, - { -0.864188f, 0.442863f, 0.238856f }, { -0.716567f, 0.681718f, 0.147621f }, - { -0.688191f, 0.587785f, 0.425325f }, { -0.500000f, 0.809017f, 0.309017f }, - { -0.238856f, 0.864188f, 0.442863f }, { -0.425325f, 0.688191f, 0.587785f }, - { -0.716567f, 0.681718f, -0.147621f }, { -0.500000f, 0.809017f, -0.309017f }, - { -0.525731f, 0.850651f, 0.000000f }, { 0.000000f, 0.850651f, -0.525731f }, - { -0.238856f, 0.864188f, -0.442863f }, { 0.000000f, 0.955423f, -0.295242f }, - { -0.262866f, 0.951056f, -0.162460f }, { 0.000000f, 1.000000f, 0.000000f }, - { 0.000000f, 0.955423f, 0.295242f }, { -0.262866f, 0.951056f, 0.162460f }, - { 0.238856f, 0.864188f, 0.442863f }, { 0.262866f, 0.951056f, 0.162460f }, - { 0.500000f, 0.809017f, 0.309017f }, { 0.238856f, 0.864188f, -0.442863f }, - { 0.262866f, 0.951056f, -0.162460f }, { 0.500000f, 0.809017f, -0.309017f }, - { 0.850651f, 0.525731f, 0.000000f }, { 0.716567f, 0.681718f, 0.147621f }, - { 0.716567f, 0.681718f, -0.147621f }, { 0.525731f, 0.850651f, 0.000000f }, - { 0.425325f, 0.688191f, 0.587785f }, { 0.864188f, 0.442863f, 0.238856f }, - { 0.688191f, 0.587785f, 0.425325f }, { 0.809017f, 0.309017f, 0.500000f }, - { 0.681718f, 0.147621f, 0.716567f }, { 0.587785f, 0.425325f, 0.688191f }, - { 0.955423f, 0.295242f, 0.000000f }, { 1.000000f, 0.000000f, 0.000000f }, - { 0.951056f, 0.162460f, 0.262866f }, { 0.850651f, -0.525731f, 0.000000f }, - { 0.955423f, -0.295242f, 0.000000f }, { 0.864188f, -0.442863f, 0.238856f }, - { 0.951056f, -0.162460f, 0.262866f }, { 0.809017f, -0.309017f, 0.500000f }, - { 0.681718f, -0.147621f, 0.716567f }, { 0.850651f, 0.000000f, 0.525731f }, - { 0.864188f, 0.442863f, -0.238856f }, { 0.809017f, 0.309017f, -0.500000f }, - { 0.951056f, 0.162460f, -0.262866f }, { 0.525731f, 0.000000f, -0.850651f }, - { 0.681718f, 0.147621f, -0.716567f }, { 0.681718f, -0.147621f, -0.716567f }, - { 0.850651f, 0.000000f, -0.525731f }, { 0.809017f, -0.309017f, -0.500000f }, - { 0.864188f, -0.442863f, -0.238856f }, { 0.951056f, -0.162460f, -0.262866f }, - { 0.147621f, 0.716567f, -0.681718f }, { 0.309017f, 0.500000f, -0.809017f }, - { 0.425325f, 0.688191f, -0.587785f }, { 0.442863f, 0.238856f, -0.864188f }, - { 0.587785f, 0.425325f, -0.688191f }, { 0.688191f, 0.587785f, -0.425325f }, - { -0.147621f, 0.716567f, -0.681718f }, { -0.309017f, 0.500000f, -0.809017f }, - { 0.000000f, 0.525731f, -0.850651f }, { -0.525731f, 0.000000f, -0.850651f }, - { -0.442863f, 0.238856f, -0.864188f }, { -0.295242f, 0.000000f, -0.955423f }, - { -0.162460f, 0.262866f, -0.951056f }, { 0.000000f, 0.000000f, -1.000000f }, - { 0.295242f, 0.000000f, -0.955423f }, { 0.162460f, 0.262866f, -0.951056f }, - { -0.442863f, -0.238856f, -0.864188f }, { -0.309017f, -0.500000f, -0.809017f }, - { -0.162460f, -0.262866f, -0.951056f }, { 0.000000f, -0.850651f, -0.525731f }, - { -0.147621f, -0.716567f, -0.681718f }, { 0.147621f, -0.716567f, -0.681718f }, - { 0.000000f, -0.525731f, -0.850651f }, { 0.309017f, -0.500000f, -0.809017f }, - { 0.442863f, -0.238856f, -0.864188f }, { 0.162460f, -0.262866f, -0.951056f }, - { 0.238856f, -0.864188f, -0.442863f }, { 0.500000f, -0.809017f, -0.309017f }, - { 0.425325f, -0.688191f, -0.587785f }, { 0.716567f, -0.681718f, -0.147621f }, - { 0.688191f, -0.587785f, -0.425325f }, { 0.587785f, -0.425325f, -0.688191f }, - { 0.000000f, -0.955423f, -0.295242f }, { 0.000000f, -1.000000f, 0.000000f }, - { 0.262866f, -0.951056f, -0.162460f }, { 0.000000f, -0.850651f, 0.525731f }, - { 0.000000f, -0.955423f, 0.295242f }, { 0.238856f, -0.864188f, 0.442863f }, - { 0.262866f, -0.951056f, 0.162460f }, { 0.500000f, -0.809017f, 0.309017f }, - { 0.716567f, -0.681718f, 0.147621f }, { 0.525731f, -0.850651f, 0.000000f }, - { -0.238856f, -0.864188f, -0.442863f }, { -0.500000f, -0.809017f, -0.309017f }, - { -0.262866f, -0.951056f, -0.162460f }, { -0.850651f, -0.525731f, 0.000000f }, - { -0.716567f, -0.681718f, -0.147621f }, { -0.716567f, -0.681718f, 0.147621f }, - { -0.525731f, -0.850651f, 0.000000f }, { -0.500000f, -0.809017f, 0.309017f }, - { -0.238856f, -0.864188f, 0.442863f }, { -0.262866f, -0.951056f, 0.162460f }, - { -0.864188f, -0.442863f, 0.238856f }, { -0.809017f, -0.309017f, 0.500000f }, - { -0.688191f, -0.587785f, 0.425325f }, { -0.681718f, -0.147621f, 0.716567f }, - { -0.442863f, -0.238856f, 0.864188f }, { -0.587785f, -0.425325f, 0.688191f }, - { -0.309017f, -0.500000f, 0.809017f }, { -0.147621f, -0.716567f, 0.681718f }, - { -0.425325f, -0.688191f, 0.587785f }, { -0.162460f, -0.262866f, 0.951056f }, - { 0.442863f, -0.238856f, 0.864188f }, { 0.162460f, -0.262866f, 0.951056f }, - { 0.309017f, -0.500000f, 0.809017f }, { 0.147621f, -0.716567f, 0.681718f }, - { 0.000000f, -0.525731f, 0.850651f }, { 0.425325f, -0.688191f, 0.587785f }, - { 0.587785f, -0.425325f, 0.688191f }, { 0.688191f, -0.587785f, 0.425325f }, - { -0.955423f, 0.295242f, 0.000000f }, { -0.951056f, 0.162460f, 0.262866f }, - { -1.000000f, 0.000000f, 0.000000f }, { -0.850651f, 0.000000f, 0.525731f }, - { -0.955423f, -0.295242f, 0.000000f }, { -0.951056f, -0.162460f, 0.262866f }, - { -0.864188f, 0.442863f, -0.238856f }, { -0.951056f, 0.162460f, -0.262866f }, - { -0.809017f, 0.309017f, -0.500000f }, { -0.864188f, -0.442863f, -0.238856f }, - { -0.951056f, -0.162460f, -0.262866f }, { -0.809017f, -0.309017f, -0.500000f }, - { -0.681718f, 0.147621f, -0.716567f }, { -0.681718f, -0.147621f, -0.716567f }, - { -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 } }; -}; - -vtkQuakeMDLImporter::vtkQuakeMDLImporter() - : Internals(new vtkQuakeMDLImporter::vtkInternals(this)){ - - }; - -//---------------------------------------------------------------------------- - -//---------------------------------------------------------------------------- -int vtkQuakeMDLImporter::ImportBegin() -{ - return this->Internals->ReadScene(this->FileName); -} - -//---------------------------------------------------------------------------- -void vtkQuakeMDLImporter::ImportActors(vtkRenderer* renderer) -{ - this->Internals->ImportActors(renderer); -} - -//---------------------------------------------------------------------------- -std::string vtkQuakeMDLImporter::GetOutputsDescription() -{ - return this->Internals->Description; -} - -//---------------------------------------------------------------------------- -void vtkQuakeMDLImporter::UpdateTimeStep(double timeValue) -{ - this->Internals->UpdateFrame(timeValue); - return; -} - -//---------------------------------------------------------------------------- -vtkIdType vtkQuakeMDLImporter::GetNumberOfAnimations() -{ - return this->Internals->NumberOfAnimations; -} - -//---------------------------------------------------------------------------- -std::string vtkQuakeMDLImporter::GetAnimationName(vtkIdType animationIndex) -{ - return std::to_string(animationIndex); -} - -//---------------------------------------------------------------------------- -void vtkQuakeMDLImporter::EnableAnimation(vtkIdType animationIndex) -{ - this->Internals->EnableAnimation(animationIndex); - return; -} - -//---------------------------------------------------------------------------- -void vtkQuakeMDLImporter::DisableAnimation(vtkIdType vtkNotUsed(animationIndex)) -{ - return; -} - -//---------------------------------------------------------------------------- -bool vtkQuakeMDLImporter::IsAnimationEnabled(vtkIdType animationIndex) -{ - return animationIndex == this->Internals->ActiveAnimationId; -} - -//---------------------------------------------------------------------------- -bool vtkQuakeMDLImporter::GetTemporalInformation(vtkIdType vtkNotUsed(animationIndex), - double vtkNotUsed(frameRate), int& vtkNotUsed(nbTimeSteps), double timeRange[2], - vtkDoubleArray* vtkNotUsed(timeSteps)) -{ - timeRange[0] = 0.0; - timeRange[1] = 10.0; - return true; -} - -//---------------------------------------------------------------------------- -vtkIdType vtkQuakeMDLImporter::GetNumberOfCameras() -{ - return 1; -} - -//---------------------------------------------------------------------------- -std::string vtkQuakeMDLImporter::GetCameraName(vtkIdType vtkNotUsed(camIndex)) -{ - return "Camera"; -} - -//---------------------------------------------------------------------------- -void vtkQuakeMDLImporter::SetCamera(vtkIdType vtkNotUsed(camIndex)) -{ - return; -} - -//---------------------------------------------------------------------------- -void vtkQuakeMDLImporter::ImportCameras(vtkRenderer* renderer) -{ - this->Internals->ImportCameras(renderer); -} - -//---------------------------------------------------------------------------- -void vtkQuakeMDLImporter::ImportLights(vtkRenderer* renderer) -{ - this->Internals->ImportLights(renderer); -} - -//---------------------------------------------------------------------------- -void vtkQuakeMDLImporter::PrintSelf(ostream& os, vtkIndent indent) -{ - this->Superclass::PrintSelf(os, indent); - os << indent << "FileName: " << this->FileName << "\n"; -} diff --git a/plugins/native/module/vtkQuakeMDLImporter.cxx.rej b/plugins/native/module/vtkQuakeMDLImporter.cxx.rej deleted file mode 100644 index b3fc6d37fd..0000000000 --- a/plugins/native/module/vtkQuakeMDLImporter.cxx.rej +++ /dev/null @@ -1,9 +0,0 @@ -diff a/plugins/native/module/vtkQuakeMDLImporter.cxx b/plugins/native/module/vtkQuakeMDLImporter.cxx (rejected hunks) -@@ -722,7 +709,6 @@ - //---------------------------------------------------------------------------- - void vtkQuakeMDLImporter::SetCamera(vtkIdType camIndex) - { -- - } - - //---------------------------------------------------------------------------- diff --git a/plugins/native/module/vtkQuakeMDLImporter.h b/plugins/native/module/vtkQuakeMDLImporter.h deleted file mode 100644 index c18d51543d..0000000000 --- a/plugins/native/module/vtkQuakeMDLImporter.h +++ /dev/null @@ -1,133 +0,0 @@ -/** - * @class vtkQuakeMDLImporter - * @brief VTK Importer for Quake 1 models in binary .mdl file format - */ - -#ifndef vtkQuakeMDLImporter_h -#define vtkQuakeMDLImporter_h -#include - -class vtkQuakeMDLImporter : public vtkImporter -{ -public: - static vtkQuakeMDLImporter* New(); - vtkTypeMacro(vtkQuakeMDLImporter, vtkImporter); - - void PrintSelf(ostream& os, vtkIndent indent) override; - - ///@{ - /** - * Set/Get the file name. - */ - vtkSetMacro(FileName, std::string); - vtkGetMacro(FileName, std::string); - ///@} - - /** - * Update actors at the given time value. - */ - - void UpdateTimeStep(double timeValue) override; - - /** - * Get the number of available animations. - */ - vtkIdType GetNumberOfAnimations() override; - - /** - * Return the name of the animation. - */ - std::string GetAnimationName(vtkIdType animationIndex) override; - - ///@{ - /** - * Enable/Disable/Get the status of specific animations - * Only one single animation can be enabled - */ - void EnableAnimation(vtkIdType animationIndex) override; - void DisableAnimation(vtkIdType animationIndex) override; - bool IsAnimationEnabled(vtkIdType animationIndex) override; - ///@} - - /** - * Return importer description. - */ - std::string GetOutputsDescription() override; - - ///@{ - /** - * Set/Get collada fixup flag. - */ - vtkSetMacro(ColladaFixup, bool); - vtkGetMacro(ColladaFixup, bool); - ///@} - - /** - * Get temporal information for the currently enabled animation. - * Only defines timerange and ignore provided frameRate. - */ - bool GetTemporalInformation(vtkIdType animationIndex, double frameRate, int& nbTimeSteps, - double timeRange[2], vtkDoubleArray* timeSteps) override; - - /** - * Get the number of available cameras. - */ - vtkIdType GetNumberOfCameras() override; - - /** - * Get the name of a camera. - */ - std::string GetCameraName(vtkIdType camIndex) override; - - /** - * Enable a specific camera. - * If a negative index is provided, no camera from the importer is used. - */ - void SetCamera(vtkIdType camIndex) override; - -protected: - vtkQuakeMDLImporter(); - ~vtkQuakeMDLImporter() override = default; - - int ImportBegin() override; - void ImportActors(vtkRenderer*) override; - void ImportCameras(vtkRenderer*) override; - void ImportLights(vtkRenderer*) override; - - // Header definition, - struct mdl_header_t - { - int IDPO; - int version; - float scale[3]; - float translation[3]; - float boundingRadius; - float eyePosition[3]; - int numSkins; - int skinWidth; - int skinHeight; - int numVertices; - int numTriangles; - int numFrames; - int syncType; - int stateFlags; - float size; - }; - - ///@{ - /** - * Set/Get the file name. - */ - ///@} - std::string FileName; - bool ColladaFixup = false; - -private: - vtkQuakeMDLImporter(const vtkQuakeMDLImporter&) = delete; - void operator=(const vtkQuakeMDLImporter&) = delete; - - class vtkInternals; - std::unique_ptr Internals; -}; - -#endif diff --git a/plugins/native/module/vtkQuakeMDLImporter.h.rej b/plugins/native/module/vtkQuakeMDLImporter.h.rej deleted file mode 100644 index 9a24d88285..0000000000 --- a/plugins/native/module/vtkQuakeMDLImporter.h.rej +++ /dev/null @@ -1,17 +0,0 @@ -diff a/plugins/native/module/vtkQuakeMDLImporter.h b/plugins/native/module/vtkQuakeMDLImporter.h (rejected hunks) -@@ -5,14 +5,13 @@ - - #ifndef vtkQuakeMDLImporter_h - #define vtkQuakeMDLImporter_h --#include -+#include - - class vtkQuakeMDLImporter : public vtkImporter - { - public: - static vtkQuakeMDLImporter* New(); - vtkTypeMacro(vtkQuakeMDLImporter, vtkImporter); -- - - void PrintSelf(ostream& os, vtkIndent indent) override; - diff --git a/style.diff b/style.diff deleted file mode 100644 index e80a12c576..0000000000 --- a/style.diff +++ /dev/null @@ -1,344 +0,0 @@ ---- plugins/alembic/module/vtkF3DAlembicReader.h (original) -+++ plugins/alembic/module/vtkF3DAlembicReader.h (reformatted) -@@ -14,10 +14,10 @@ - #ifndef vtkF3DAlembicReader_h - #define vtkF3DAlembicReader_h - -+#include - #include - #include - #include --#include - - class vtkF3DAlembicReader : public vtkPolyDataAlgorithm - { ---- plugins/native/module/vtkQuakeMDLImporter.h (original) -+++ plugins/native/module/vtkQuakeMDLImporter.h (reformatted) -@@ -5,14 +5,13 @@ - - #ifndef vtkQuakeMDLImporter_h - #define vtkQuakeMDLImporter_h --#include -+#include - - class vtkQuakeMDLImporter : public vtkImporter - { - public: - static vtkQuakeMDLImporter* New(); - vtkTypeMacro(vtkQuakeMDLImporter, vtkImporter); -- - - void PrintSelf(ostream& os, vtkIndent indent) override; - -@@ -86,17 +85,16 @@ - */ - void SetCamera(vtkIdType camIndex) override; - -- - protected: - vtkQuakeMDLImporter(); - ~vtkQuakeMDLImporter() override = default; -- -+ - int ImportBegin() override; - void ImportActors(vtkRenderer*) override; - void ImportCameras(vtkRenderer*) override; - void ImportLights(vtkRenderer*) override; - -- // Header definition, -+ // Header definition, - struct mdl_header_t - { - int IDPO; ---- plugins/native/module/vtkQuakeMDLImporter.cxx (original) -+++ plugins/native/module/vtkQuakeMDLImporter.cxx (reformatted) -@@ -1,42 +1,41 @@ - #include "vtkQuakeMDLImporter.h" - --#include -+#include -+#include -+#include - #include --#include - #include - #include - #include - #include - #include -+#include - #include - #include -+#include -+#include -+#include - #include -+#include -+#include -+#include -+#include - #include - #include - #include --#include --#include - #include --#include --#include -+#include - #include --#include --#include --#include --#include -+#include -+#include - #include --#include --#include --#include --#include --#include --#include - #include - #include -+#include -+#include - - //---------------------------------------------------------------------------- - vtkStandardNewMacro(vtkQuakeMDLImporter); -- - - class vtkQuakeMDLImporter::vtkInternals - { -@@ -72,24 +71,23 @@ - vtkNew backLight; - double backLightPosition[3] = { -50.0, 0.0, 0.0 }; - backLight->SetPosition(backLightPosition); -- -+ - renderer->AddLight(frontLight); - renderer->AddLight(leftLight); - renderer->AddLight(backLight); - } - - //---------------------------------------------------------------------------- -- vtkSmartPointer CreateTexture(std::vector buffer, int& offset, int skinWidth, -- int skinHeight, int nbSkins, int selectedSkinIndex) -+ vtkSmartPointer CreateTexture(std::vector buffer, int& offset, -+ int skinWidth, int skinHeight, int nbSkins, int selectedSkinIndex) - { - vtkNew texture; - texture->InterpolateOn(); - -- - // Read textures. - struct mdl_skin_t - { -- int group; /* 0 = single, 1 = group */ -+ int group; /* 0 = single, 1 = group */ - unsigned char* data; /* texture data */ - }; - struct mdl_groupskin_t -@@ -118,7 +116,7 @@ - else - { - skins[i].group = 1; -- int nb = *reinterpret_cast(buffer.data() + offset + 4); -+ int nb = *reinterpret_cast(buffer.data() + offset + 4); - skins[i].skin = reinterpret_cast(buffer.data() + 4 + nb * 4 + offset); - offset += 4 + nb * 4 + nb * (skinWidth) * (skinHeight); - } -@@ -129,12 +127,12 @@ - img->SetDimensions(skinWidth, skinHeight, 1); - img->AllocateScalars(VTK_UNSIGNED_CHAR, 3); - unsigned char* selectedSkin = skins[selectedSkinIndex].skin; -- for (int i = 0; i < skinHeight ; i++) -+ for (int i = 0; i < skinHeight; i++) - { - for (int j = 0; j < skinWidth; j++) - { - unsigned char index = *reinterpret_cast(selectedSkin + i * skinWidth + j); -- unsigned char* ptr = reinterpret_cast(img->GetScalarPointer(j,i,0)); -+ unsigned char* ptr = reinterpret_cast(img->GetScalarPointer(j, i, 0)); - ptr[0] = DefaultColorMap[index][0]; // R - ptr[1] = DefaultColorMap[index][1]; // G - ptr[2] = DefaultColorMap[index][2]; // B -@@ -145,8 +143,8 @@ - return texture; - } - -- -- void CreateMesh(std::vector buffer, int& offset, mdl_header_t* header, int selectedFrameIndex) -+ void CreateMesh( -+ std::vector buffer, int& offset, mdl_header_t* header, int selectedFrameIndex) - { - // Read texture coordinates - struct mdl_texcoord_t -@@ -217,9 +215,8 @@ - framePtr[i].nb = reinterpret_cast(buffer.data() + 4 + offset); - mdl_vertex_t* min = reinterpret_cast(buffer.data() + 8 + offset); - mdl_vertex_t* max = reinterpret_cast(buffer.data() + 12 + offset); -- float* time = -- framePtr[i].time = reinterpret_cast(buffer.data() + 16 + offset); -- framePtr[i].frames = -+ float* time = framePtr[i].time = reinterpret_cast(buffer.data() + 16 + offset); -+ framePtr[i].frames = - reinterpret_cast(buffer.data() + 16 + 4 * (*framePtr[i].nb) + offset); - offset += 16 + (*framePtr[i].nb) * 4; - for (int j = 0; j < *framePtr[i].nb; j++) -@@ -265,9 +262,7 @@ - } - vtkIdType t[3] = { i * 3, i * 3 + 1, i * 3 + 2 }; - cells->InsertNextCell(3, t); -- -- } -- -+ } - - // Draw vertices - std::string frameName = ""; -@@ -279,7 +274,7 @@ - vtkNew normals; - normals->SetNumberOfComponents(3); - normals->Allocate(header->numTriangles * 3 * 3); -- -+ - plugin_frame_pointer selectedFrame = framePtr[frameNum]; - if (*selectedFrame.type == 0) - { -@@ -296,17 +291,17 @@ - { - v[k] = v[k] * header->scale[k] + header->translation[k]; - } -- vertices->InsertPoint(i*3+j, v); -+ vertices->InsertPoint(i * 3 + j, v); - int normalIndex = selectedFrame.frames->verts[vertexNum[j]].normalIndex; -- normals->SetTuple3(i*3+j, NormalVectors[normalIndex][0] / 255.0, -- NormalVectors[normalIndex][1] / 255.0, NormalVectors[normalIndex][2] / 255.0); -+ normals->SetTuple3(i * 3 + j, NormalVectors[normalIndex][0] / 255.0, -+ NormalVectors[normalIndex][1] / 255.0, NormalVectors[normalIndex][2] / 255.0); - } - } - vtkNew mesh; - mesh->SetPoints(vertices); - mesh->SetPolys(cells); - mesh->GetPointData()->SetTCoords(textureCoordinates); --// mesh->GetPointData()->SetNormals(normals); -+ // mesh->GetPointData()->SetNormals(normals); - Mesh.push_back(mesh); - std::string meshName = std::string(selectedFrame.frames->name); - for (int i = 0; i < meshName.size(); i++) -@@ -347,9 +342,9 @@ - { - v[k] = v[k] * header->scale[k] + header->translation[k]; - } -- vertices->InsertPoint(i*3+j, v); -+ vertices->InsertPoint(i * 3 + j, v); - int normalIndex = selectedFrame.frames[groupFrameNum].verts[vertexNum[j]].normalIndex; -- normals->SetTuple3(i*3+j, NormalVectors[normalIndex][0] / 255.0, -+ normals->SetTuple3(i * 3 + j, NormalVectors[normalIndex][0] / 255.0, - NormalVectors[normalIndex][1] / 255.0, NormalVectors[normalIndex][2] / 255.0); - } - } -@@ -378,7 +373,8 @@ - NumberOfAnimations++; - frameName = meshName; - } -- std::pair pair = std::make_pair(frameIndex, selectedFrame.time[groupFrameNum]); -+ std::pair pair = -+ std::make_pair(frameIndex, selectedFrame.time[groupFrameNum]); - GroupAndTimeVal.push_back(pair); - } - } -@@ -399,7 +395,7 @@ - for (int j = 0; j < header->numTriangles * 3; j++) - { - double* v_0 = Mesh[i]->GetPoint(j); -- double* v_1 = Mesh[i+1]->GetPoint(j); -+ double* v_1 = Mesh[i + 1]->GetPoint(j); - double* interp = new double[3]; - interp[0] = v_0[0] + 0.5 * (v_1[0] - v_0[0]); - interp[1] = v_0[1] + 0.5 * (v_1[1] - v_0[1]); -@@ -427,17 +423,14 @@ - // Read header - mdl_header_t* header = reinterpret_cast(buffer.data()); - int offset = 84; -- -+ - // Set textures -- Texture= this->CreateTexture( -+ Texture = this->CreateTexture( - buffer, offset, header->skinWidth, header->skinHeight, header->numSkins, 0); -- -- -+ - // Set polyData - this->CreateMesh(buffer, offset, header, 0); -- -- -- -+ - return 1; - } - -@@ -447,7 +440,7 @@ - if (abs(timeValue - LastRenderTime) > 1.0 / 24) - { - Mapper->SetInputData( -- Mesh[(CurrentFrameIndex++) % (LastFrameIndex - FirstFrameIndex) + FirstFrameIndex]); -+ Mesh[(CurrentFrameIndex++) % (LastFrameIndex - FirstFrameIndex) + FirstFrameIndex]); - LastRenderTime = timeValue; - } - } -@@ -465,7 +458,7 @@ - while (i < GroupAndTimeVal.size() && GroupAndTimeVal[++i].first == animationIndex) - { - } -- LastFrameIndex = i-1; -+ LastFrameIndex = i - 1; - } - - void ImportActors(vtkRenderer* renderer) -@@ -482,14 +475,12 @@ - Mapper = mapper; - } - -- -- - vtkQuakeMDLImporter* Parent; - std::string Description; - vtkSmartPointer Actor; - vtkSmartPointer Mapper; - std::vector> Mesh; -- std::vector > GroupAndTimeVal; -+ std::vector> GroupAndTimeVal; - int ActiveAnimationId = 0; - int CurrentFrameIndex = 0; - int FirstFrameIndex = 0; -@@ -637,9 +628,6 @@ - - //---------------------------------------------------------------------------- - -- -- -- - //---------------------------------------------------------------------------- - int vtkQuakeMDLImporter::ImportBegin() - { -@@ -695,7 +683,6 @@ - { - return true; - } -- - - //---------------------------------------------------------------------------- - bool vtkQuakeMDLImporter::GetTemporalInformation(vtkIdType animationIndex, -@@ -722,7 +709,6 @@ - //---------------------------------------------------------------------------- - void vtkQuakeMDLImporter::SetCamera(vtkIdType camIndex) - { -- - } - - //---------------------------------------------------------------------------- From 84b57f9d35d62ee8cecfc9651561c76fe7e9034f Mon Sep 17 00:00:00 2001 From: Youva Boutora <48061964+Youva@users.noreply.github.com> Date: Wed, 18 Dec 2024 13:58:51 -0500 Subject: [PATCH 46/60] Compiler warning and indentation Also changed test .png for quake mdl. --- .../Testing/TestF3DQuakeMDLImporter.cxx | 24 +++--- .../native/module/vtkF3DQuakeMDLImporter.cxx | 67 ++++++++------- .../native/module/vtkF3DQuakeMDLImporter.h | 6 +- .../vtkF3DQuakeMDLImporterConstants.cxx | 85 +++++++++---------- testing/baselines/TestQuakeMDL.png | 4 +- 5 files changed, 91 insertions(+), 95 deletions(-) diff --git a/plugins/native/module/Testing/TestF3DQuakeMDLImporter.cxx b/plugins/native/module/Testing/TestF3DQuakeMDLImporter.cxx index 4078f446e6..c74e8bac41 100644 --- a/plugins/native/module/Testing/TestF3DQuakeMDLImporter.cxx +++ b/plugins/native/module/Testing/TestF3DQuakeMDLImporter.cxx @@ -1,23 +1,23 @@ +#include "vtkF3DQuakeMDLImporter.h" +#include #include #include -#include -#include "vtkF3DQuakeMDLImporter.h" #include int TestF3DQuakeMDLImporter(int vtkNotUsed(argc), char* argv[]) { - std::string filename = std::string(argv[1]) + "data/glaunch.mdl"; - vtkNew importer; - importer->SetFileName(filename); - importer->Update(); - importer->Print(cout); + std::string filename = std::string(argv[1]) + "data/glaunch.mdl"; + vtkNew importer; + importer->SetFileName(filename); + importer->Update(); + importer->Print(cout); vtkIdType numAnimations = importer->GetNumberOfAnimations(); - for (int i = 0; i < numAnimations; i++) - { - importer->DisableAnimation(i); - } + for (int i = 0; i < numAnimations; i++) + { + importer->DisableAnimation(i); + } vtkIdType selectedAnimationIndex = 1; importer->EnableAnimation(selectedAnimationIndex); - return numAnimations == 2 ? EXIT_SUCCESS : EXIT_FAILURE; + return numAnimations == 2 ? EXIT_SUCCESS : EXIT_FAILURE; } \ No newline at end of file diff --git a/plugins/native/module/vtkF3DQuakeMDLImporter.cxx b/plugins/native/module/vtkF3DQuakeMDLImporter.cxx index 856e937441..222a272490 100644 --- a/plugins/native/module/vtkF3DQuakeMDLImporter.cxx +++ b/plugins/native/module/vtkF3DQuakeMDLImporter.cxx @@ -1,5 +1,4 @@ #include "vtkF3DQuakeMDLImporter.h" -#include #include #include #include @@ -73,18 +72,18 @@ class vtkF3DQuakeMDLImporter::vtkInternals std::vector skins = std::vector(nbSkins); for (int i = 0; i < nbSkins; i++) { - int* group = (int*) (buffer.data() + offset); + int* group = (int*)(buffer.data() + offset); if (*group == 0) { skins[i].group = 0; - skins[i].skin = (unsigned char*) (buffer.data() + 4 + offset); + skins[i].skin = (unsigned char*)(buffer.data() + 4 + offset); offset += 4 + (skinWidth) * (skinHeight); } else { skins[i].group = 1; - int nb = *(int*) (buffer.data() + offset + 4); - skins[i].skin = (unsigned char*) (buffer.data() + 4 + nb * 4 + offset); + int nb = *(int*)(buffer.data() + offset + 4); + skins[i].skin = (unsigned char*)(buffer.data() + 4 + nb * 4 + offset); offset += 4 + nb * 4 + nb * (skinWidth) * (skinHeight); } } @@ -98,8 +97,8 @@ class vtkF3DQuakeMDLImporter::vtkInternals { for (int j = 0; j < skinWidth; j++) { - unsigned char index = *(unsigned char*) (selectedSkin + i * skinWidth + j); - unsigned char* ptr = (unsigned char*) (img->GetScalarPointer(j, i, 0)); + unsigned char index = *(unsigned char*)(selectedSkin + i * skinWidth + j); + unsigned char* ptr = (unsigned char*)(img->GetScalarPointer(j, i, 0)); ptr[0] = F3DMDLDefaultColorMap[index][0]; // R ptr[1] = F3DMDLDefaultColorMap[index][1]; // G ptr[2] = F3DMDLDefaultColorMap[index][2]; // B @@ -140,7 +139,7 @@ class vtkF3DQuakeMDLImporter::vtkInternals int s; int t; }; - mdl_texcoord_t* texcoords = (mdl_texcoord_t*) (buffer.data() + offset); + mdl_texcoord_t* texcoords = (mdl_texcoord_t*)(buffer.data() + offset); offset += 12 * header->numVertices; // Read triangles struct mdl_triangle_t @@ -148,7 +147,7 @@ class vtkF3DQuakeMDLImporter::vtkInternals int facesfront; /* 0 = backface, 1 = frontface */ int vertex[3]; /* vertex indices */ }; - mdl_triangle_t* triangles = (mdl_triangle_t*) (buffer.data() + offset); + mdl_triangle_t* triangles = (mdl_triangle_t*)(buffer.data() + offset); offset += 16 * header->numTriangles; // Read frames struct mdl_vertex_t // 4 bytes @@ -173,24 +172,24 @@ class vtkF3DQuakeMDLImporter::vtkInternals std::vector framePtr = std::vector(header->numFrames); for (int i = 0; i < header->numFrames; i++) { - int* type = (int*) (buffer.data() + offset); + int* type = (int*)(buffer.data() + offset); if (*type == 0) { framePtr[i].type = type; framePtr[i].nb = nullptr; framePtr[i].time = nullptr; - framePtr[i].frames = (mdl_simpleframe_t*) (buffer.data() + 4 + offset); + framePtr[i].frames = (mdl_simpleframe_t*)(buffer.data() + 4 + offset); offset += 4 + 24 + 4 * (header->numVertices); } else { framePtr[i].type = type; - framePtr[i].nb = (int*) (buffer.data() + 4 + offset); + framePtr[i].nb = (int*)(buffer.data() + 4 + offset); // mdl_vertex_t* min = reinterpret_cast(buffer.data() + 8 + offset); // mdl_vertex_t* max = reinterpret_cast(buffer.data() + 12 + offset); // float* time = framePtr[i].time = reinterpret_cast(buffer.data() + 16 + offset); framePtr[i].frames = - (mdl_simpleframe_t*) (buffer.data() + 16 + 4 * (*framePtr[i].nb) + offset); + (mdl_simpleframe_t*)(buffer.data() + 16 + 4 * (*framePtr[i].nb) + offset); offset += 16 + (*framePtr[i].nb) * 4; for (int j = 0; j < *framePtr[i].nb; j++) { @@ -211,14 +210,12 @@ class vtkF3DQuakeMDLImporter::vtkInternals float t; int id; }; - std::vector coords = std::vector(header->numTriangles * 3); + std::vector coords = + std::vector(header->numTriangles * 3); for (int i = 0; i < header->numTriangles; i++) { - vtkIdType vertexNum[3]; for (int j = 0; j < 3; j++) { - vertexNum[j] = triangles[i].vertex[j]; - // int onseam_correct = 1; float s = texcoords[triangles[i].vertex[j]].s; float t = texcoords[triangles[i].vertex[j]].t; if (!triangles[i].facesfront && texcoords[triangles[i].vertex[j]].onseam) @@ -267,7 +264,8 @@ class vtkF3DQuakeMDLImporter::vtkInternals vertices->InsertPoint(i * 3 + j, v); int normalIndex = selectedFrame.frames->verts[vertexNum[j]].normalIndex; normals->SetTuple3(i * 3 + j, F3DMDLNormalVectors[normalIndex][0] / 255.0, - F3DMDLNormalVectors[normalIndex][1] / 255.0, F3DMDLNormalVectors[normalIndex][2] / 255.0); + F3DMDLNormalVectors[normalIndex][1] / 255.0, + F3DMDLNormalVectors[normalIndex][2] / 255.0); } } vtkNew mesh; @@ -298,7 +296,7 @@ class vtkF3DQuakeMDLImporter::vtkInternals NumberOfAnimations++; AnimationNames.emplace_back(meshName); } - GroupAndTimeVal.emplace_back(std::make_pair( frameIndex, 0.0 )); + GroupAndTimeVal.emplace_back(std::make_pair(frameIndex, 0.0)); } else { @@ -320,7 +318,8 @@ class vtkF3DQuakeMDLImporter::vtkInternals vertices->InsertPoint(i * 3 + j, v); int normalIndex = selectedFrame.frames[groupFrameNum].verts[vertexNum[j]].normalIndex; normals->SetTuple3(i * 3 + j, F3DMDLNormalVectors[normalIndex][0] / 255.0, - F3DMDLNormalVectors[normalIndex][1] / 255.0, F3DMDLNormalVectors[normalIndex][2] / 255.0); + F3DMDLNormalVectors[normalIndex][1] / 255.0, + F3DMDLNormalVectors[normalIndex][2] / 255.0); } } vtkNew mesh; @@ -413,7 +412,7 @@ class vtkF3DQuakeMDLImporter::vtkInternals //---------------------------------------------------------------------------- void UpdateTimeStep(double timeValue) { - int frameIndex = (int) floor(FrameRate * abs(timeValue)) % (int)ActiveFrames.size(); + int frameIndex = (int)floor(FrameRate * abs(timeValue)) % (int)ActiveFrames.size(); int currentFrame = ActiveFrames[frameIndex]; Mapper->SetInputData(Mesh[currentFrame]); LastRenderTime = timeValue; @@ -430,9 +429,9 @@ class vtkF3DQuakeMDLImporter::vtkInternals std::find_if(GroupAndTimeVal.begin(), GroupAndTimeVal.end(), [animationIndex](const std::pair pair) { return pair.first > animationIndex; })); - firstFrameIndex = firstFrameIndex <= GroupAndTimeVal.size() ? firstFrameIndex : 0; + firstFrameIndex = firstFrameIndex <= (int)GroupAndTimeVal.size() ? firstFrameIndex : 0; lastFrameIndex = - lastFrameIndex <= GroupAndTimeVal.size() ? lastFrameIndex - 1 : lastFrameIndex; + lastFrameIndex <= (int)GroupAndTimeVal.size() ? lastFrameIndex - 1 : lastFrameIndex; for (int i = firstFrameIndex; i <= lastFrameIndex; i++) { ActiveFrames.emplace_back(i); @@ -451,14 +450,16 @@ class vtkF3DQuakeMDLImporter::vtkInternals std::find_if(GroupAndTimeVal.begin(), GroupAndTimeVal.end(), [animationIndex](const std::pair pair) { return pair.first > animationIndex; })); - firstFrameIndex = firstFrameIndex <= GroupAndTimeVal.size() ? firstFrameIndex : 0; - lastFrameIndex = lastFrameIndex <= GroupAndTimeVal.size() ? lastFrameIndex - 1 : lastFrameIndex; + firstFrameIndex = firstFrameIndex <= (int)GroupAndTimeVal.size() ? firstFrameIndex : 0; + lastFrameIndex = lastFrameIndex <= (int)GroupAndTimeVal.size() ? lastFrameIndex - 1 : lastFrameIndex; for (int i = firstFrameIndex; i <= lastFrameIndex; i++) { - ActiveFrames.erase(std::remove(ActiveFrames.begin(), ActiveFrames.end(), i), ActiveFrames.end()); + ActiveFrames.erase( + std::remove(ActiveFrames.begin(), ActiveFrames.end(), i), ActiveFrames.end()); } ActiveAnimationId.erase( - std::remove(ActiveAnimationId.begin(), ActiveAnimationId.end(), animationIndex), ActiveAnimationId.end()); + std::remove(ActiveAnimationId.begin(), ActiveAnimationId.end(), animationIndex), + ActiveAnimationId.end()); } //---------------------------------------------------------------------------- @@ -543,7 +544,7 @@ vtkIdType vtkF3DQuakeMDLImporter::GetNumberOfAnimations() //---------------------------------------------------------------------------- std::string vtkF3DQuakeMDLImporter::GetAnimationName(vtkIdType animationIndex) { - if (animationIndex < (int) this->Internals->AnimationNames.size()) + if (animationIndex < (int)this->Internals->AnimationNames.size()) { return this->Internals->AnimationNames[animationIndex]; } @@ -568,17 +569,17 @@ void vtkF3DQuakeMDLImporter::DisableAnimation(vtkIdType animationIndex) //---------------------------------------------------------------------------- bool vtkF3DQuakeMDLImporter::IsAnimationEnabled(vtkIdType animationIndex) { - return std::count(this->Internals->ActiveAnimationId.begin(), this->Internals->ActiveAnimationId.end(), animationIndex) > 0; + return std::count(this->Internals->ActiveAnimationId.begin(), + this->Internals->ActiveAnimationId.end(), animationIndex) > 0; } //---------------------------------------------------------------------------- -bool vtkF3DQuakeMDLImporter::GetTemporalInformation(vtkIdType animationIndex, - double frameRate, int& nbTimeSteps, double timeRange[2], - vtkDoubleArray* vtkNotUsed(timeSteps)) +bool vtkF3DQuakeMDLImporter::GetTemporalInformation(vtkIdType animationIndex, double frameRate, + int& nbTimeSteps, double timeRange[2], vtkDoubleArray* vtkNotUsed(timeSteps)) { Internals->SetFrameRate(frameRate); Internals->GetTimeRange(animationIndex, timeRange); - nbTimeSteps = (int) Internals->ActiveFrames.size(); + nbTimeSteps = (int)Internals->ActiveFrames.size(); return true; } diff --git a/plugins/native/module/vtkF3DQuakeMDLImporter.h b/plugins/native/module/vtkF3DQuakeMDLImporter.h index 54990b1746..ba3c8b4c70 100644 --- a/plugins/native/module/vtkF3DQuakeMDLImporter.h +++ b/plugins/native/module/vtkF3DQuakeMDLImporter.h @@ -5,8 +5,8 @@ #ifndef vtkF3DQuakeMDLImporter_h #define vtkF3DQuakeMDLImporter_h -#include #include "vtkF3DQuakeMDLImporterConstants.h" +#include class vtkF3DQuakeMDLImporter : public vtkF3DImporter { @@ -47,8 +47,6 @@ class vtkF3DQuakeMDLImporter : public vtkF3DImporter */ std::string GetOutputsDescription() override; - - /** * Get temporal information for the currently enabled animation. */ @@ -87,8 +85,6 @@ class vtkF3DQuakeMDLImporter : public vtkF3DImporter std::string FileName; std::unique_ptr Internals; - }; - #endif diff --git a/plugins/native/module/vtkF3DQuakeMDLImporterConstants.cxx b/plugins/native/module/vtkF3DQuakeMDLImporterConstants.cxx index ec4b6c1ea3..d3bac5d547 100644 --- a/plugins/native/module/vtkF3DQuakeMDLImporterConstants.cxx +++ b/plugins/native/module/vtkF3DQuakeMDLImporterConstants.cxx @@ -5,49 +5,48 @@ const unsigned char F3DMDLDefaultColorMap[256][3] = { { 0, 0, 0 }, { 15, 15, 15 { 123, 123, 123 }, { 139, 139, 139 }, { 155, 155, 155 }, { 171, 171, 171 }, { 187, 187, 187 }, { 203, 203, 203 }, { 219, 219, 219 }, { 235, 235, 235 }, { 15, 11, 7 }, { 23, 15, 11 }, { 31, 23, 11 }, { 39, 27, 15 }, { 47, 35, 19 }, { 55, 43, 23 }, { 63, 47, 23 }, { 75, 55, 27 }, - { 83, 59, 27 }, { 91, 67, 31 }, { 99, 75, 31 }, { 107, 83, 31 }, { 115, 87, 31 }, - { 123, 95, 35 }, { 131, 103, 35 }, { 143, 111, 35 }, { 11, 11, 15 }, { 19, 19, 27 }, - { 27, 27, 39 }, { 39, 39, 51 }, { 47, 47, 63 }, { 55, 55, 75 }, { 63, 63, 87 }, { 71, 71, 103 }, - { 79, 79, 115 }, { 91, 91, 127 }, { 99, 99, 139 }, { 107, 107, 151 }, { 115, 115, 163 }, - { 123, 123, 175 }, { 131, 131, 187 }, { 139, 139, 203 }, { 0, 0, 0 }, { 7, 7, 0 }, - { 11, 11, 0 }, { 19, 19, 0 }, { 27, 27, 0 }, { 35, 35, 0 }, { 43, 43, 7 }, { 47, 47, 7 }, - { 55, 55, 7 }, { 63, 63, 7 }, { 71, 71, 7 }, { 75, 75, 11 }, { 83, 83, 11 }, { 91, 91, 11 }, - { 99, 99, 11 }, { 107, 107, 15 }, { 7, 0, 0 }, { 15, 0, 0 }, { 23, 0, 0 }, { 31, 0, 0 }, - { 39, 0, 0 }, { 47, 0, 0 }, { 55, 0, 0 }, { 63, 0, 0 }, { 71, 0, 0 }, { 79, 0, 0 }, - { 87, 0, 0 }, { 95, 0, 0 }, { 103, 0, 0 }, { 111, 0, 0 }, { 119, 0, 0 }, { 127, 0, 0 }, - { 19, 19, 0 }, { 27, 27, 0 }, { 35, 35, 0 }, { 47, 43, 0 }, { 55, 47, 0 }, { 67, 55, 0 }, - { 75, 59, 7 }, { 87, 67, 7 }, { 95, 71, 7 }, { 107, 75, 11 }, { 119, 83, 15 }, { 131, 87, 19 }, - { 139, 91, 19 }, { 151, 95, 27 }, { 163, 99, 31 }, { 175, 103, 35 }, { 35, 19, 7 }, - { 47, 23, 11 }, { 59, 31, 15 }, { 75, 35, 19 }, { 87, 43, 23 }, { 99, 47, 31 }, { 115, 55, 35 }, - { 127, 59, 43 }, { 143, 67, 51 }, { 159, 79, 51 }, { 175, 99, 47 }, { 191, 119, 47 }, - { 207, 143, 43 }, { 223, 171, 39 }, { 239, 203, 31 }, { 255, 243, 27 }, { 11, 7, 0 }, - { 27, 19, 0 }, { 43, 35, 15 }, { 55, 43, 19 }, { 71, 51, 27 }, { 83, 55, 35 }, { 99, 63, 43 }, - { 111, 71, 51 }, { 127, 83, 63 }, { 139, 95, 71 }, { 155, 107, 83 }, { 167, 123, 95 }, - { 183, 135, 107 }, { 195, 147, 123 }, { 211, 163, 139 }, { 227, 179, 151 }, { 171, 139, 163 }, - { 159, 127, 151 }, { 147, 115, 135 }, { 139, 103, 123 }, { 127, 91, 111 }, { 119, 83, 99 }, - { 107, 75, 87 }, { 95, 63, 75 }, { 87, 55, 67 }, { 75, 47, 55 }, { 67, 39, 47 }, { 55, 31, 35 }, - { 43, 23, 27 }, { 35, 19, 19 }, { 23, 11, 11 }, { 15, 7, 7 }, { 187, 115, 159 }, - { 175, 107, 143 }, { 163, 95, 131 }, { 151, 87, 119 }, { 139, 79, 107 }, { 127, 75, 95 }, - { 115, 67, 83 }, { 107, 59, 75 }, { 95, 51, 63 }, { 83, 43, 55 }, { 71, 35, 43 }, - { 59, 31, 35 }, { 47, 23, 27 }, { 35, 19, 19 }, { 23, 11, 11 }, { 15, 7, 7 }, { 219, 195, 187 }, - { 203, 179, 167 }, { 191, 163, 155 }, { 175, 151, 139 }, { 163, 135, 123 }, { 151, 123, 111 }, - { 135, 111, 95 }, { 123, 99, 83 }, { 107, 87, 71 }, { 95, 75, 59 }, { 83, 63, 51 }, - { 67, 51, 39 }, { 55, 43, 31 }, { 39, 31, 23 }, { 27, 19, 15 }, { 15, 11, 7 }, - { 111, 131, 123 }, { 103, 123, 111 }, { 95, 115, 103 }, { 87, 107, 95 }, { 79, 99, 87 }, - { 71, 91, 79 }, { 63, 83, 71 }, { 55, 75, 63 }, { 47, 67, 55 }, { 43, 59, 47 }, { 35, 51, 39 }, - { 31, 43, 31 }, { 23, 35, 23 }, { 15, 27, 19 }, { 11, 19, 11 }, { 7, 11, 7 }, { 255, 243, 27 }, - { 239, 223, 23 }, { 219, 203, 19 }, { 203, 183, 15 }, { 187, 167, 15 }, { 171, 151, 11 }, - { 155, 131, 7 }, { 139, 115, 7 }, { 123, 99, 7 }, { 107, 83, 0 }, { 91, 71, 0 }, { 75, 55, 0 }, - { 59, 43, 0 }, { 43, 31, 0 }, { 27, 15, 0 }, { 11, 7, 0 }, { 0, 0, 255 }, { 11, 11, 239 }, - { 19, 19, 223 }, { 27, 27, 207 }, { 35, 35, 191 }, { 43, 43, 175 }, { 47, 47, 159 }, - { 47, 47, 143 }, { 47, 47, 127 }, { 47, 47, 111 }, { 47, 47, 95 }, { 43, 43, 79 }, - { 35, 35, 63 }, { 27, 27, 47 }, { 19, 19, 31 }, { 11, 11, 15 }, { 43, 0, 0 }, { 59, 0, 0 }, - { 75, 7, 0 }, { 95, 7, 0 }, { 111, 15, 0 }, { 127, 23, 7 }, { 147, 31, 7 }, { 163, 39, 11 }, - { 183, 51, 15 }, { 195, 75, 27 }, { 207, 99, 43 }, { 219, 127, 59 }, { 227, 151, 79 }, - { 231, 171, 95 }, { 239, 191, 119 }, { 247, 211, 139 }, { 167, 123, 59 }, { 183, 155, 55 }, - { 199, 195, 55 }, { 231, 227, 87 }, { 127, 191, 255 }, { 171, 231, 255 }, { 215, 255, 255 }, - { 103, 0, 0 }, { 139, 0, 0 }, { 179, 0, 0 }, { 215, 0, 0 }, { 255, 0, 0 }, { 255, 243, 147 }, - { 255, 247, 199 }, { 255, 255, 255 }, { 159, 91, 83 } }; + { 83, 59, 27 }, { 91, 67, 31 }, { 99, 75, 31 }, { 107, 83, 31 }, { 115, 87, 31 }, { 123, 95, 35 }, + { 131, 103, 35 }, { 143, 111, 35 }, { 11, 11, 15 }, { 19, 19, 27 }, { 27, 27, 39 }, + { 39, 39, 51 }, { 47, 47, 63 }, { 55, 55, 75 }, { 63, 63, 87 }, { 71, 71, 103 }, { 79, 79, 115 }, + { 91, 91, 127 }, { 99, 99, 139 }, { 107, 107, 151 }, { 115, 115, 163 }, { 123, 123, 175 }, + { 131, 131, 187 }, { 139, 139, 203 }, { 0, 0, 0 }, { 7, 7, 0 }, { 11, 11, 0 }, { 19, 19, 0 }, + { 27, 27, 0 }, { 35, 35, 0 }, { 43, 43, 7 }, { 47, 47, 7 }, { 55, 55, 7 }, { 63, 63, 7 }, + { 71, 71, 7 }, { 75, 75, 11 }, { 83, 83, 11 }, { 91, 91, 11 }, { 99, 99, 11 }, { 107, 107, 15 }, + { 7, 0, 0 }, { 15, 0, 0 }, { 23, 0, 0 }, { 31, 0, 0 }, { 39, 0, 0 }, { 47, 0, 0 }, { 55, 0, 0 }, + { 63, 0, 0 }, { 71, 0, 0 }, { 79, 0, 0 }, { 87, 0, 0 }, { 95, 0, 0 }, { 103, 0, 0 }, + { 111, 0, 0 }, { 119, 0, 0 }, { 127, 0, 0 }, { 19, 19, 0 }, { 27, 27, 0 }, { 35, 35, 0 }, + { 47, 43, 0 }, { 55, 47, 0 }, { 67, 55, 0 }, { 75, 59, 7 }, { 87, 67, 7 }, { 95, 71, 7 }, + { 107, 75, 11 }, { 119, 83, 15 }, { 131, 87, 19 }, { 139, 91, 19 }, { 151, 95, 27 }, + { 163, 99, 31 }, { 175, 103, 35 }, { 35, 19, 7 }, { 47, 23, 11 }, { 59, 31, 15 }, { 75, 35, 19 }, + { 87, 43, 23 }, { 99, 47, 31 }, { 115, 55, 35 }, { 127, 59, 43 }, { 143, 67, 51 }, + { 159, 79, 51 }, { 175, 99, 47 }, { 191, 119, 47 }, { 207, 143, 43 }, { 223, 171, 39 }, + { 239, 203, 31 }, { 255, 243, 27 }, { 11, 7, 0 }, { 27, 19, 0 }, { 43, 35, 15 }, { 55, 43, 19 }, + { 71, 51, 27 }, { 83, 55, 35 }, { 99, 63, 43 }, { 111, 71, 51 }, { 127, 83, 63 }, { 139, 95, 71 }, + { 155, 107, 83 }, { 167, 123, 95 }, { 183, 135, 107 }, { 195, 147, 123 }, { 211, 163, 139 }, + { 227, 179, 151 }, { 171, 139, 163 }, { 159, 127, 151 }, { 147, 115, 135 }, { 139, 103, 123 }, + { 127, 91, 111 }, { 119, 83, 99 }, { 107, 75, 87 }, { 95, 63, 75 }, { 87, 55, 67 }, + { 75, 47, 55 }, { 67, 39, 47 }, { 55, 31, 35 }, { 43, 23, 27 }, { 35, 19, 19 }, { 23, 11, 11 }, + { 15, 7, 7 }, { 187, 115, 159 }, { 175, 107, 143 }, { 163, 95, 131 }, { 151, 87, 119 }, + { 139, 79, 107 }, { 127, 75, 95 }, { 115, 67, 83 }, { 107, 59, 75 }, { 95, 51, 63 }, + { 83, 43, 55 }, { 71, 35, 43 }, { 59, 31, 35 }, { 47, 23, 27 }, { 35, 19, 19 }, { 23, 11, 11 }, + { 15, 7, 7 }, { 219, 195, 187 }, { 203, 179, 167 }, { 191, 163, 155 }, { 175, 151, 139 }, + { 163, 135, 123 }, { 151, 123, 111 }, { 135, 111, 95 }, { 123, 99, 83 }, { 107, 87, 71 }, + { 95, 75, 59 }, { 83, 63, 51 }, { 67, 51, 39 }, { 55, 43, 31 }, { 39, 31, 23 }, { 27, 19, 15 }, + { 15, 11, 7 }, { 111, 131, 123 }, { 103, 123, 111 }, { 95, 115, 103 }, { 87, 107, 95 }, + { 79, 99, 87 }, { 71, 91, 79 }, { 63, 83, 71 }, { 55, 75, 63 }, { 47, 67, 55 }, { 43, 59, 47 }, + { 35, 51, 39 }, { 31, 43, 31 }, { 23, 35, 23 }, { 15, 27, 19 }, { 11, 19, 11 }, { 7, 11, 7 }, + { 255, 243, 27 }, { 239, 223, 23 }, { 219, 203, 19 }, { 203, 183, 15 }, { 187, 167, 15 }, + { 171, 151, 11 }, { 155, 131, 7 }, { 139, 115, 7 }, { 123, 99, 7 }, { 107, 83, 0 }, { 91, 71, 0 }, + { 75, 55, 0 }, { 59, 43, 0 }, { 43, 31, 0 }, { 27, 15, 0 }, { 11, 7, 0 }, { 0, 0, 255 }, + { 11, 11, 239 }, { 19, 19, 223 }, { 27, 27, 207 }, { 35, 35, 191 }, { 43, 43, 175 }, + { 47, 47, 159 }, { 47, 47, 143 }, { 47, 47, 127 }, { 47, 47, 111 }, { 47, 47, 95 }, + { 43, 43, 79 }, { 35, 35, 63 }, { 27, 27, 47 }, { 19, 19, 31 }, { 11, 11, 15 }, { 43, 0, 0 }, + { 59, 0, 0 }, { 75, 7, 0 }, { 95, 7, 0 }, { 111, 15, 0 }, { 127, 23, 7 }, { 147, 31, 7 }, + { 163, 39, 11 }, { 183, 51, 15 }, { 195, 75, 27 }, { 207, 99, 43 }, { 219, 127, 59 }, + { 227, 151, 79 }, { 231, 171, 95 }, { 239, 191, 119 }, { 247, 211, 139 }, { 167, 123, 59 }, + { 183, 155, 55 }, { 199, 195, 55 }, { 231, 227, 87 }, { 127, 191, 255 }, { 171, 231, 255 }, + { 215, 255, 255 }, { 103, 0, 0 }, { 139, 0, 0 }, { 179, 0, 0 }, { 215, 0, 0 }, { 255, 0, 0 }, + { 255, 243, 147 }, { 255, 247, 199 }, { 255, 255, 255 }, { 159, 91, 83 } }; const float F3DMDLNormalVectors[162][3] = { { -0.525731f, 0.000000f, 0.850651f }, { -0.442863f, 0.238856f, 0.864188f }, { -0.295242f, 0.000000f, 0.955423f }, { -0.309017f, 0.500000f, 0.809017f }, { -0.162460f, 0.262866f, 0.951056f }, diff --git a/testing/baselines/TestQuakeMDL.png b/testing/baselines/TestQuakeMDL.png index 679f9ddc2a..f9f4b68abb 100644 --- a/testing/baselines/TestQuakeMDL.png +++ b/testing/baselines/TestQuakeMDL.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:7b8ebba71f1475f7bf2382b3736ff82147519b71a9d290f3ac43bee4adcb60ed -size 47901 +oid sha256:553d64ee1a25a62af96a2dd8f49715dd57533bf42a3c02afc4cbe22efeba644c +size 25522 From 2f40a6fa758d6293186f35fe1cd0d89f90079fce Mon Sep 17 00:00:00 2001 From: Youva Boutora <48061964+Youva@users.noreply.github.com> Date: Wed, 18 Dec 2024 14:50:49 -0500 Subject: [PATCH 47/60] Formatting --- plugins/native/module/vtkF3DQuakeMDLImporter.cxx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/plugins/native/module/vtkF3DQuakeMDLImporter.cxx b/plugins/native/module/vtkF3DQuakeMDLImporter.cxx index 222a272490..6778b2ae81 100644 --- a/plugins/native/module/vtkF3DQuakeMDLImporter.cxx +++ b/plugins/native/module/vtkF3DQuakeMDLImporter.cxx @@ -128,7 +128,6 @@ class vtkF3DQuakeMDLImporter::vtkInternals float size; }; - //---------------------------------------------------------------------------- void CreateMesh(std::vector buffer, int offset, mdl_header_t* header) { @@ -169,7 +168,8 @@ class vtkF3DQuakeMDLImporter::vtkInternals float* time; mdl_simpleframe_t* frames; }; - std::vector framePtr = std::vector(header->numFrames); + std::vector framePtr = + std::vector(header->numFrames); for (int i = 0; i < header->numFrames; i++) { int* type = (int*)(buffer.data() + offset); @@ -387,7 +387,6 @@ class vtkF3DQuakeMDLImporter::vtkInternals i++; } } - } //---------------------------------------------------------------------------- @@ -427,8 +426,8 @@ class vtkF3DQuakeMDLImporter::vtkInternals { return pair.first == animationIndex; })); int lastFrameIndex = std::distance(GroupAndTimeVal.begin(), std::find_if(GroupAndTimeVal.begin(), GroupAndTimeVal.end(), - [animationIndex](const std::pair pair) - { return pair.first > animationIndex; })); + [animationIndex](const std::pair pair) + { return pair.first > animationIndex; })); firstFrameIndex = firstFrameIndex <= (int)GroupAndTimeVal.size() ? firstFrameIndex : 0; lastFrameIndex = lastFrameIndex <= (int)GroupAndTimeVal.size() ? lastFrameIndex - 1 : lastFrameIndex; @@ -451,7 +450,8 @@ class vtkF3DQuakeMDLImporter::vtkInternals [animationIndex](const std::pair pair) { return pair.first > animationIndex; })); firstFrameIndex = firstFrameIndex <= (int)GroupAndTimeVal.size() ? firstFrameIndex : 0; - lastFrameIndex = lastFrameIndex <= (int)GroupAndTimeVal.size() ? lastFrameIndex - 1 : lastFrameIndex; + lastFrameIndex = + lastFrameIndex <= (int)GroupAndTimeVal.size() ? lastFrameIndex - 1 : lastFrameIndex; for (int i = firstFrameIndex; i <= lastFrameIndex; i++) { ActiveFrames.erase( @@ -570,7 +570,7 @@ void vtkF3DQuakeMDLImporter::DisableAnimation(vtkIdType animationIndex) bool vtkF3DQuakeMDLImporter::IsAnimationEnabled(vtkIdType animationIndex) { return std::count(this->Internals->ActiveAnimationId.begin(), - this->Internals->ActiveAnimationId.end(), animationIndex) > 0; + this->Internals->ActiveAnimationId.end(), animationIndex) > 0; } //---------------------------------------------------------------------------- From 36a374ae3595d0099ba7c458b25288d1061d5184 Mon Sep 17 00:00:00 2001 From: Youva Boutora <48061964+Youva@users.noreply.github.com> Date: Thu, 19 Dec 2024 16:19:54 -0500 Subject: [PATCH 48/60] Added coverage to f3dquakemdlimporter --- plugins/alembic/module/vtkF3DAlembicReader.h | 3 +- .../Testing/TestF3DQuakeMDLImporter.cxx | 4 +- .../native/module/vtkF3DQuakeMDLImporter.cxx | 105 ++++-------------- .../native/module/vtkF3DQuakeMDLImporter.h | 7 +- 4 files changed, 28 insertions(+), 91 deletions(-) diff --git a/plugins/alembic/module/vtkF3DAlembicReader.h b/plugins/alembic/module/vtkF3DAlembicReader.h index e8a47dd412..19940cbbee 100644 --- a/plugins/alembic/module/vtkF3DAlembicReader.h +++ b/plugins/alembic/module/vtkF3DAlembicReader.h @@ -14,11 +14,12 @@ #ifndef vtkF3DAlembicReader_h #define vtkF3DAlembicReader_h -#include #include #include #include +#include + class vtkF3DAlembicReader : public vtkPolyDataAlgorithm { public: diff --git a/plugins/native/module/Testing/TestF3DQuakeMDLImporter.cxx b/plugins/native/module/Testing/TestF3DQuakeMDLImporter.cxx index c74e8bac41..8a05d2eeca 100644 --- a/plugins/native/module/Testing/TestF3DQuakeMDLImporter.cxx +++ b/plugins/native/module/Testing/TestF3DQuakeMDLImporter.cxx @@ -19,5 +19,7 @@ int TestF3DQuakeMDLImporter(int vtkNotUsed(argc), char* argv[]) } vtkIdType selectedAnimationIndex = 1; importer->EnableAnimation(selectedAnimationIndex); - return numAnimations == 2 ? EXIT_SUCCESS : EXIT_FAILURE; + std::string animationName = importer->GetAnimationName(2); + importer->UpdateTimeStep(0.0); + return numAnimations == 2 && animationName == "" ? EXIT_SUCCESS : EXIT_FAILURE; } \ No newline at end of file diff --git a/plugins/native/module/vtkF3DQuakeMDLImporter.cxx b/plugins/native/module/vtkF3DQuakeMDLImporter.cxx index 6778b2ae81..b962495f67 100644 --- a/plugins/native/module/vtkF3DQuakeMDLImporter.cxx +++ b/plugins/native/module/vtkF3DQuakeMDLImporter.cxx @@ -57,7 +57,7 @@ class vtkF3DQuakeMDLImporter::vtkInternals } //---------------------------------------------------------------------------- - vtkSmartPointer CreateTexture(const std::vector buffer, int& offset, + vtkSmartPointer CreateTexture(const std::vector& buffer, int& offset, int skinWidth, int skinHeight, int nbSkins, int selectedSkinIndex) { vtkNew texture; @@ -129,7 +129,7 @@ class vtkF3DQuakeMDLImporter::vtkInternals }; //---------------------------------------------------------------------------- - void CreateMesh(std::vector buffer, int offset, mdl_header_t* header) + void CreateMesh(const std::vector& buffer, int offset, mdl_header_t* header) { // Read texture coordinates struct mdl_texcoord_t @@ -170,6 +170,8 @@ class vtkF3DQuakeMDLImporter::vtkInternals }; std::vector framePtr = std::vector(header->numFrames); + std::vector> frameOffsets = + std::vector>(); for (int i = 0; i < header->numFrames; i++) { int* type = (int*)(buffer.data() + offset); @@ -185,16 +187,15 @@ class vtkF3DQuakeMDLImporter::vtkInternals { framePtr[i].type = type; framePtr[i].nb = (int*)(buffer.data() + 4 + offset); - // mdl_vertex_t* min = reinterpret_cast(buffer.data() + 8 + offset); - // mdl_vertex_t* max = reinterpret_cast(buffer.data() + 12 + offset); - // float* time = framePtr[i].time = reinterpret_cast(buffer.data() + 16 + offset); - framePtr[i].frames = - (mdl_simpleframe_t*)(buffer.data() + 16 + 4 * (*framePtr[i].nb) + offset); - offset += 16 + (*framePtr[i].nb) * 4; + // float* time = framePtr[i].time = (float*)(buffer.data() + 16 + offset); + frameOffsets.emplace_back(std::vector()); for (int j = 0; j < *framePtr[i].nb; j++) { - offset += 24 + 4 * header->numVertices; + frameOffsets[i].emplace_back( + 16 + 4 * (*framePtr[i].nb) + j * 4 * (header->numVertices + 6) + offset); } + offset += 16 + (*framePtr[i].nb) * 4; + offset += (24 + 4 * header->numVertices) * (*framePtr[i].nb); } } // Draw cells @@ -246,23 +247,27 @@ class vtkF3DQuakeMDLImporter::vtkInternals normals->Allocate(header->numTriangles * 3 * 3); plugin_frame_pointer selectedFrame = framePtr[frameNum]; - if (*selectedFrame.type == 0) + int numGroupFrames = *selectedFrame.type == 0 ? 1 : *selectedFrame.nb; + for (int groupFrameNum = 0; groupFrameNum < numGroupFrames; groupFrameNum++) { + mdl_simpleframe_t* selectedSimpleFrame = numGroupFrames > 1 + ? (mdl_simpleframe_t*)(buffer.data() + frameOffsets[frameNum][groupFrameNum]) + : selectedFrame.frames; for (int i = 0; i < header->numTriangles; i++) { vtkIdType vertexNum[3]; for (int j = 0; j < 3; j++) { vertexNum[j] = triangles[i].vertex[j]; - double v[3] = { double(selectedFrame.frames->verts[vertexNum[j]].v[0]), - double(selectedFrame.frames->verts[vertexNum[j]].v[1]), - double(selectedFrame.frames->verts[vertexNum[j]].v[2]) }; + double v[3] = { double(selectedSimpleFrame->verts[vertexNum[j]].v[0]), + double(selectedSimpleFrame->verts[vertexNum[j]].v[1]), + double(selectedSimpleFrame->verts[vertexNum[j]].v[2]) }; for (int k = 0; k < 3; k++) { v[k] = v[k] * header->scale[k] + header->translation[k]; } vertices->InsertPoint(i * 3 + j, v); - int normalIndex = selectedFrame.frames->verts[vertexNum[j]].normalIndex; + int normalIndex = selectedSimpleFrame->verts[vertexNum[j]].normalIndex; normals->SetTuple3(i * 3 + j, F3DMDLNormalVectors[normalIndex][0] / 255.0, F3DMDLNormalVectors[normalIndex][1] / 255.0, F3DMDLNormalVectors[normalIndex][2] / 255.0); @@ -272,9 +277,9 @@ class vtkF3DQuakeMDLImporter::vtkInternals mesh->SetPoints(vertices); mesh->SetPolys(cells); mesh->GetPointData()->SetTCoords(textureCoordinates); - // mesh->GetPointData()->SetNormals(normals); + mesh->GetPointData()->SetNormals(normals); Mesh.emplace_back(mesh); - std::string meshName = std::string(selectedFrame.frames->name); + std::string meshName = std::string(selectedSimpleFrame->name); for (std::size_t i = 0; i < meshName.size(); i++) { if (meshName[i] >= '0' && meshName[i] <= '9') @@ -283,7 +288,7 @@ class vtkF3DQuakeMDLImporter::vtkInternals break; } } - if (frameNum == 0) + if (frameNum == 0 && groupFrameNum == 0) { frameName = meshName; NumberOfAnimations++; @@ -298,61 +303,6 @@ class vtkF3DQuakeMDLImporter::vtkInternals } GroupAndTimeVal.emplace_back(std::make_pair(frameIndex, 0.0)); } - else - { - for (int groupFrameNum = 0; groupFrameNum < *selectedFrame.nb; groupFrameNum++) - { - for (int i = 0; i < header->numTriangles; i++) - { - vtkIdType vertexNum[3]; - for (int j = 0; j < 3; j++) - { - vertexNum[j] = triangles[i].vertex[j]; - double v[3] = { double(selectedFrame.frames[groupFrameNum].verts[vertexNum[j]].v[0]), - double(selectedFrame.frames[groupFrameNum].verts[vertexNum[j]].v[1]), - double(selectedFrame.frames[groupFrameNum].verts[vertexNum[j]].v[2]) }; - for (int k = 0; k < 3; k++) - { - v[k] = v[k] * header->scale[k] + header->translation[k]; - } - vertices->InsertPoint(i * 3 + j, v); - int normalIndex = selectedFrame.frames[groupFrameNum].verts[vertexNum[j]].normalIndex; - normals->SetTuple3(i * 3 + j, F3DMDLNormalVectors[normalIndex][0] / 255.0, - F3DMDLNormalVectors[normalIndex][1] / 255.0, - F3DMDLNormalVectors[normalIndex][2] / 255.0); - } - } - vtkNew mesh; - mesh->SetPoints(vertices); - mesh->SetPolys(cells); - mesh->GetPointData()->SetTCoords(textureCoordinates); - mesh->GetPointData()->SetNormals(normals); - Mesh.emplace_back(mesh); - std::string meshName = std::string(selectedFrame.frames[groupFrameNum].name); - for (std::size_t i = 0; i < meshName.size(); i++) - { - if (meshName[i] >= '0' && meshName[i] <= '9') - { - meshName = meshName.substr(0, i - 1); - break; - } - } - if (frameNum == 0) - { - frameName = meshName; - NumberOfAnimations++; - AnimationNames.emplace_back(meshName); - } - else if (meshName != frameName) - { - frameIndex++; - NumberOfAnimations++; - AnimationNames.emplace_back(meshName); - frameName = meshName; - } - GroupAndTimeVal.emplace_back(std::make_pair(frameIndex, 0.0)); - } - } } // Add interpolated frames @@ -595,11 +545,6 @@ std::string vtkF3DQuakeMDLImporter::GetCameraName(vtkIdType vtkNotUsed(camIndex) return "Camera"; } -//---------------------------------------------------------------------------- -void vtkF3DQuakeMDLImporter::SetCamera(vtkIdType vtkNotUsed(camIndex)) -{ -} - //---------------------------------------------------------------------------- void vtkF3DQuakeMDLImporter::ImportCameras(vtkRenderer* renderer) { @@ -611,9 +556,3 @@ void vtkF3DQuakeMDLImporter::ImportLights(vtkRenderer* renderer) { this->Internals->ImportLights(renderer); } - -//---------------------------------------------------------------------------- -void vtkF3DQuakeMDLImporter::SetFileName(std::string fileName) -{ - this->FileName = fileName; -} diff --git a/plugins/native/module/vtkF3DQuakeMDLImporter.h b/plugins/native/module/vtkF3DQuakeMDLImporter.h index ba3c8b4c70..26cab0b989 100644 --- a/plugins/native/module/vtkF3DQuakeMDLImporter.h +++ b/plugins/native/module/vtkF3DQuakeMDLImporter.h @@ -16,7 +16,7 @@ class vtkF3DQuakeMDLImporter : public vtkF3DImporter /** * Set the file name. */ - void SetFileName(std::string fileName); + vtkSetMacro(FileName, std::string); /** * Update actors at the given time value. @@ -63,11 +63,6 @@ class vtkF3DQuakeMDLImporter : public vtkF3DImporter */ std::string GetCameraName(vtkIdType camIndex) override; - /** - * Enable a specific camera. - */ - void SetCamera(vtkIdType camIndex) override; - protected: vtkF3DQuakeMDLImporter(); ~vtkF3DQuakeMDLImporter() override = default; From dda2a6a70d2d91e05bf820a39b4ea7c6e5914756 Mon Sep 17 00:00:00 2001 From: Youva Boutora <48061964+Youva@users.noreply.github.com> Date: Fri, 20 Dec 2024 16:35:21 -0500 Subject: [PATCH 49/60] Coverage, added comments --- .../alembic/module/vtkF3DAlembicReader.h.rej | 13 - .../native/configs/config.d/10_native.json | 3 +- plugins/native/module/Testing/CMakeLists.txt | 2 +- .../Testing/TestF3DQuakeMDLImporter.cxx | 2 +- .../native/module/vtkF3DQuakeMDLImporter.cxx | 264 ++++++++---------- .../native/module/vtkF3DQuakeMDLImporter.h | 8 +- 6 files changed, 124 insertions(+), 168 deletions(-) delete mode 100644 plugins/alembic/module/vtkF3DAlembicReader.h.rej diff --git a/plugins/alembic/module/vtkF3DAlembicReader.h.rej b/plugins/alembic/module/vtkF3DAlembicReader.h.rej deleted file mode 100644 index 913c02343d..0000000000 --- a/plugins/alembic/module/vtkF3DAlembicReader.h.rej +++ /dev/null @@ -1,13 +0,0 @@ -diff a/plugins/alembic/module/vtkF3DAlembicReader.h b/plugins/alembic/module/vtkF3DAlembicReader.h (rejected hunks) -@@ -14,10 +14,10 @@ - #ifndef vtkF3DAlembicReader_h - #define vtkF3DAlembicReader_h - -+#include - #include - #include - #include --#include - - class vtkF3DAlembicReader : public vtkPolyDataAlgorithm - { diff --git a/plugins/native/configs/config.d/10_native.json b/plugins/native/configs/config.d/10_native.json index 4dc3f5dd10..eb05839770 100644 --- a/plugins/native/configs/config.d/10_native.json +++ b/plugins/native/configs/config.d/10_native.json @@ -74,8 +74,7 @@ "options": { "up": "+Z", - "camera-direction": "-1,0,0", - "grid": false + "camera-direction": "-1,0,0" } } ] diff --git a/plugins/native/module/Testing/CMakeLists.txt b/plugins/native/module/Testing/CMakeLists.txt index ffb2b19479..2a1deff2ce 100644 --- a/plugins/native/module/Testing/CMakeLists.txt +++ b/plugins/native/module/Testing/CMakeLists.txt @@ -7,4 +7,4 @@ vtk_add_test_cxx(vtkextNativeTests tests ${vtkextNative_list} ${F3D_SOURCE_DIR}/testing/ ${CMAKE_BINARY_DIR}/Testing/Temporary/) -vtk_test_cxx_executable(vtkextNativeTests tests) \ No newline at end of file +vtk_test_cxx_executable(vtkextNativeTests tests) diff --git a/plugins/native/module/Testing/TestF3DQuakeMDLImporter.cxx b/plugins/native/module/Testing/TestF3DQuakeMDLImporter.cxx index 8a05d2eeca..da0886590b 100644 --- a/plugins/native/module/Testing/TestF3DQuakeMDLImporter.cxx +++ b/plugins/native/module/Testing/TestF3DQuakeMDLImporter.cxx @@ -22,4 +22,4 @@ int TestF3DQuakeMDLImporter(int vtkNotUsed(argc), char* argv[]) std::string animationName = importer->GetAnimationName(2); importer->UpdateTimeStep(0.0); return numAnimations == 2 && animationName == "" ? EXIT_SUCCESS : EXIT_FAILURE; -} \ No newline at end of file +} diff --git a/plugins/native/module/vtkF3DQuakeMDLImporter.cxx b/plugins/native/module/vtkF3DQuakeMDLImporter.cxx index b962495f67..0751424f9c 100644 --- a/plugins/native/module/vtkF3DQuakeMDLImporter.cxx +++ b/plugins/native/module/vtkF3DQuakeMDLImporter.cxx @@ -1,37 +1,13 @@ #include "vtkF3DQuakeMDLImporter.h" -#include -#include -#include -#include -#include -#include -#include +#include "vtkF3DQuakeMDLImporterConstants.h" + #include -#include #include -#include -#include -#include -#include -#include -#include #include -#include -#include -#include #include -#include #include #include -#include -#include -#include #include -#include -#include -#include -#include -#include //---------------------------------------------------------------------------- vtkStandardNewMacro(vtkF3DQuakeMDLImporter); @@ -46,16 +22,6 @@ class vtkF3DQuakeMDLImporter::vtkInternals { } - //---------------------------------------------------------------------------- - void ImportCameras(vtkRenderer* vtkNotUsed(renderer)) - { - } - - //---------------------------------------------------------------------------- - void ImportLights(vtkRenderer* vtkNotUsed(renderer)) - { - } - //---------------------------------------------------------------------------- vtkSmartPointer CreateTexture(const std::vector& buffer, int& offset, int skinWidth, int skinHeight, int nbSkins, int selectedSkinIndex) @@ -67,24 +33,22 @@ class vtkF3DQuakeMDLImporter::vtkInternals struct mixed_pointer_array { int group; - unsigned char* skin; + const unsigned char* skin; }; std::vector skins = std::vector(nbSkins); for (int i = 0; i < nbSkins; i++) { - int* group = (int*)(buffer.data() + offset); - if (*group == 0) + skins[i].group = *reinterpret_cast(buffer.data() + offset); + if (skins[i].group == 0) { - skins[i].group = 0; - skins[i].skin = (unsigned char*)(buffer.data() + 4 + offset); - offset += 4 + (skinWidth) * (skinHeight); + skins[i].skin = buffer.data() + 4 + offset; + offset += 4 + skinWidth * skinHeight; } else { - skins[i].group = 1; - int nb = *(int*)(buffer.data() + offset + 4); - skins[i].skin = (unsigned char*)(buffer.data() + 4 + nb * 4 + offset); - offset += 4 + nb * 4 + nb * (skinWidth) * (skinHeight); + int nb = *reinterpret_cast(buffer.data() + offset + 4); + skins[i].skin = buffer.data() + 4 + nb * 4 + offset; + offset += 4 + nb * 4 + nb * skinWidth * skinHeight; } } @@ -92,13 +56,13 @@ class vtkF3DQuakeMDLImporter::vtkInternals vtkNew img; img->SetDimensions(skinWidth, skinHeight, 1); img->AllocateScalars(VTK_UNSIGNED_CHAR, 3); - unsigned char* selectedSkin = skins[selectedSkinIndex].skin; + const unsigned char* selectedSkin = skins[selectedSkinIndex].skin; for (int i = 0; i < skinHeight; i++) { for (int j = 0; j < skinWidth; j++) { - unsigned char index = *(unsigned char*)(selectedSkin + i * skinWidth + j); - unsigned char* ptr = (unsigned char*)(img->GetScalarPointer(j, i, 0)); + unsigned char index = *(selectedSkin + i * skinWidth + j); + unsigned char* ptr = static_cast(img->GetScalarPointer(j, i, 0)); ptr[0] = F3DMDLDefaultColorMap[index][0]; // R ptr[1] = F3DMDLDefaultColorMap[index][1]; // G ptr[2] = F3DMDLDefaultColorMap[index][2]; // B @@ -108,7 +72,7 @@ class vtkF3DQuakeMDLImporter::vtkInternals return texture; } - // Header definition, + // Header definition struct mdl_header_t { int IDPO; @@ -138,67 +102,69 @@ class vtkF3DQuakeMDLImporter::vtkInternals int s; int t; }; - mdl_texcoord_t* texcoords = (mdl_texcoord_t*)(buffer.data() + offset); + const mdl_texcoord_t* texcoords = reinterpret_cast(buffer.data() + offset); offset += 12 * header->numVertices; + // Read triangles - struct mdl_triangle_t + struct mdl_triangle_t { - int facesfront; /* 0 = backface, 1 = frontface */ - int vertex[3]; /* vertex indices */ + int facesfront; // 0 = backface, 1 = frontface + int vertex[3]; // vertex indices }; - mdl_triangle_t* triangles = (mdl_triangle_t*)(buffer.data() + offset); + const mdl_triangle_t* triangles = reinterpret_cast(buffer.data() + offset); offset += 16 * header->numTriangles; - // Read frames - struct mdl_vertex_t // 4 bytes + + // Simple vertex and normal + struct mdl_vertex_t { unsigned char v[3]; unsigned char normalIndex; }; + // Simple frame struct mdl_simpleframe_t // 24 + nbVertices bytes { - mdl_vertex_t bboxmin; - mdl_vertex_t bboxmax; - char name[16]; - mdl_vertex_t verts[1024]; // Maximum capacity is 1024 vertices + mdl_vertex_t bboxmin; // bouding box min + mdl_vertex_t bboxmax; // bouding box max + char name[16]; // frame name + mdl_vertex_t verts[1024]; // vertex list of the frame, maximum capacity is 1024 }; + // Struct containing frame type and data struct plugin_frame_pointer { - int* type; - int* nb; - float* time; - mdl_simpleframe_t* frames; + const int* type; // 0 = simple frame, !0 = group frames + const int* nb; // "number", size of *time and *frames arrays + const float* time; // time duration for each frame + const mdl_simpleframe_t* frames; // simple frame list }; + // Read frames std::vector framePtr = std::vector(header->numFrames); - std::vector> frameOffsets = - std::vector>(); + std::vector> frameOffsets = std::vector>(); for (int i = 0; i < header->numFrames; i++) { - int* type = (int*)(buffer.data() + offset); - if (*type == 0) + framePtr[i].type = reinterpret_cast(buffer.data() + offset); + if (*framePtr[i].type == 0) { - framePtr[i].type = type; framePtr[i].nb = nullptr; framePtr[i].time = nullptr; - framePtr[i].frames = (mdl_simpleframe_t*)(buffer.data() + 4 + offset); + framePtr[i].frames = reinterpret_cast(buffer.data() + 4 + offset); offset += 4 + 24 + 4 * (header->numVertices); } else { - framePtr[i].type = type; - framePtr[i].nb = (int*)(buffer.data() + 4 + offset); - // float* time = framePtr[i].time = (float*)(buffer.data() + 16 + offset); + framePtr[i].nb = reinterpret_cast(buffer.data() + 4 + offset); + framePtr[i].time = reinterpret_cast(buffer.data() + 16 + offset); frameOffsets.emplace_back(std::vector()); for (int j = 0; j < *framePtr[i].nb; j++) { frameOffsets[i].emplace_back( 16 + 4 * (*framePtr[i].nb) + j * 4 * (header->numVertices + 6) + offset); } - offset += 16 + (*framePtr[i].nb) * 4; - offset += (24 + 4 * header->numVertices) * (*framePtr[i].nb); + offset += 16 + (*framePtr[i].nb) * 4 + (24 + 4 * header->numVertices) * (*framePtr[i].nb); } } - // Draw cells + + // Draw cells and scale texture coordinates vtkNew cells; cells->Allocate(header->numTriangles); vtkNew textureCoordinates; @@ -209,7 +175,6 @@ class vtkF3DQuakeMDLImporter::vtkInternals { float s; float t; - int id; }; std::vector coords = std::vector(header->numTriangles * 3); @@ -221,13 +186,13 @@ class vtkF3DQuakeMDLImporter::vtkInternals float t = texcoords[triangles[i].vertex[j]].t; if (!triangles[i].facesfront && texcoords[triangles[i].vertex[j]].onseam) { - s = s + header->skinWidth * 0.5f; + s = s + header->skinWidth * 0.5f; // Backface } + // Scale s and t to range from 0.0 to 1.0 s = (s + 0.5) / header->skinWidth; t = (t + 0.5) / header->skinHeight; coords[3 * i + j].s = s; coords[3 * i + j].t = t; - coords[3 * i + j].id = triangles[i].vertex[j]; float st[2] = { s, t }; textureCoordinates->InsertNextTuple(st); } @@ -235,23 +200,22 @@ class vtkF3DQuakeMDLImporter::vtkInternals cells->InsertNextCell(3, t); } - // Draw vertices + // Draw frames std::string frameName = ""; - int frameIndex = 0; + int animationId = 0; for (int frameNum = 0; frameNum < header->numFrames; frameNum++) { - vtkNew vertices; - vertices->Allocate(header->numTriangles * 3); - vtkNew normals; - normals->SetNumberOfComponents(3); - normals->Allocate(header->numTriangles * 3 * 3); - plugin_frame_pointer selectedFrame = framePtr[frameNum]; int numGroupFrames = *selectedFrame.type == 0 ? 1 : *selectedFrame.nb; for (int groupFrameNum = 0; groupFrameNum < numGroupFrames; groupFrameNum++) { - mdl_simpleframe_t* selectedSimpleFrame = numGroupFrames > 1 - ? (mdl_simpleframe_t*)(buffer.data() + frameOffsets[frameNum][groupFrameNum]) + vtkNew vertices; + vertices->Allocate(header->numTriangles * 3); + vtkNew normals; + normals->SetNumberOfComponents(3); + normals->Allocate(header->numTriangles * 3 * 3); + const mdl_simpleframe_t* selectedSimpleFrame = numGroupFrames > 1 + ? reinterpret_cast(buffer.data() + frameOffsets[frameNum][groupFrameNum]) : selectedFrame.frames; for (int i = 0; i < header->numTriangles; i++) { @@ -262,11 +226,13 @@ class vtkF3DQuakeMDLImporter::vtkInternals double v[3] = { double(selectedSimpleFrame->verts[vertexNum[j]].v[0]), double(selectedSimpleFrame->verts[vertexNum[j]].v[1]), double(selectedSimpleFrame->verts[vertexNum[j]].v[2]) }; + // Calculate real vertex position for (int k = 0; k < 3; k++) { v[k] = v[k] * header->scale[k] + header->translation[k]; } vertices->InsertPoint(i * 3 + j, v); + // Normal vector int normalIndex = selectedSimpleFrame->verts[vertexNum[j]].normalIndex; normals->SetTuple3(i * 3 + j, F3DMDLNormalVectors[normalIndex][0] / 255.0, F3DMDLNormalVectors[normalIndex][1] / 255.0, @@ -278,7 +244,9 @@ class vtkF3DQuakeMDLImporter::vtkInternals mesh->SetPolys(cells); mesh->GetPointData()->SetTCoords(textureCoordinates); mesh->GetPointData()->SetNormals(normals); - Mesh.emplace_back(mesh); + this->Mesh.emplace_back(mesh); + // Group meshes by animation name + // Another array contains animation ids and time values std::string meshName = std::string(selectedSimpleFrame->name); for (std::size_t i = 0; i < meshName.size(); i++) { @@ -291,24 +259,27 @@ class vtkF3DQuakeMDLImporter::vtkInternals if (frameNum == 0 && groupFrameNum == 0) { frameName = meshName; - NumberOfAnimations++; - AnimationNames.emplace_back(meshName); + this->NumberOfAnimations++; + this->AnimationNames.emplace_back(meshName); } else if (meshName != frameName) { - frameIndex++; + animationId++; frameName = meshName; - NumberOfAnimations++; - AnimationNames.emplace_back(meshName); + this->NumberOfAnimations++; + this->AnimationNames.emplace_back(meshName); } - GroupAndTimeVal.emplace_back(std::make_pair(frameIndex, 0.0)); + float time = selectedFrame.time == nullptr ? frameNum * (1.0 / this->FrameRate) + : selectedFrame.time[groupFrameNum]; + this->AnimationIds.emplace_back(std::make_pair(animationId, time)); } } // Add interpolated frames - for (std::size_t i = 0; i < Mesh.size() - 1; i++) + // Linear interpolation between frames in the same animation. + for (std::size_t i = 0; i < this->Mesh.size() - 1; i++) { - if (GroupAndTimeVal[i + 1].first != GroupAndTimeVal[i].first) + if (this->AnimationIds[i + 1].first != this->AnimationIds[i].first) { continue; } @@ -318,8 +289,8 @@ class vtkF3DQuakeMDLImporter::vtkInternals vertices->Allocate(header->numTriangles * 3); for (int j = 0; j < header->numTriangles * 3; j++) { - double* v_0 = Mesh[i]->GetPoint(j); - double* v_1 = Mesh[i + 1]->GetPoint(j); + double* v_0 = this->Mesh[i]->GetPoint(j); + double* v_1 = this->Mesh[i + 1]->GetPoint(j); double interp[3]; interp[0] = v_0[0] + 0.5 * (v_1[0] - v_0[0]); interp[1] = v_0[1] + 0.5 * (v_1[1] - v_0[1]); @@ -330,11 +301,12 @@ class vtkF3DQuakeMDLImporter::vtkInternals mesh->SetPoints(vertices); mesh->SetPolys(cells); mesh->GetPointData()->SetTCoords(textureCoordinates); - Mesh.insert(Mesh.begin() + i, mesh); - std::pair pair = std::make_pair(GroupAndTimeVal[i].first, - (GroupAndTimeVal[i].second + GroupAndTimeVal[i + 1].second) / 2); - GroupAndTimeVal.insert(GroupAndTimeVal.begin() + i, pair); - i++; + // Inserts frame between i and i+1 + this->Mesh.insert(this->Mesh.begin() + i, mesh); + std::pair pair = std::make_pair(this->AnimationIds[i].first, + (this->AnimationIds[i].second + this->AnimationIds[i + 1].second) / 2); + // Increments i to avoid infinite loop + this->AnimationIds.insert(this->AnimationIds.begin() + i++, pair); } } } @@ -347,9 +319,8 @@ class vtkF3DQuakeMDLImporter::vtkInternals // Read header mdl_header_t* header = reinterpret_cast(buffer.data()); int offset = 84; - // Set textures - Texture = this->CreateTexture( + this->Texture = this->CreateTexture( buffer, offset, header->skinWidth, header->skinHeight, header->numSkins, 0); // Set polyData @@ -361,55 +332,54 @@ class vtkF3DQuakeMDLImporter::vtkInternals //---------------------------------------------------------------------------- void UpdateTimeStep(double timeValue) { - int frameIndex = (int)floor(FrameRate * abs(timeValue)) % (int)ActiveFrames.size(); - int currentFrame = ActiveFrames[frameIndex]; - Mapper->SetInputData(Mesh[currentFrame]); - LastRenderTime = timeValue; + int frameIndex = (int)floor(FrameRate * abs(timeValue)) % (int)this->ActiveFrames.size(); + int currentFrame = this->ActiveFrames[frameIndex]; + this->Mapper->SetInputData(this->Mesh[currentFrame]); } //---------------------------------------------------------------------------- void EnableAnimation(vtkIdType animationIndex) { - int firstFrameIndex = std::distance(GroupAndTimeVal.begin(), - std::find_if(GroupAndTimeVal.begin(), GroupAndTimeVal.end(), + int firstFrameIndex = std::distance(this->AnimationIds.begin(), + std::find_if(this->AnimationIds.begin(), this->AnimationIds.end(), [animationIndex](const std::pair pair) { return pair.first == animationIndex; })); - int lastFrameIndex = std::distance(GroupAndTimeVal.begin(), - std::find_if(GroupAndTimeVal.begin(), GroupAndTimeVal.end(), + int lastFrameIndex = std::distance(this->AnimationIds.begin(), + std::find_if(this->AnimationIds.begin(), this->AnimationIds.end(), [animationIndex](const std::pair pair) { return pair.first > animationIndex; })); - firstFrameIndex = firstFrameIndex <= (int)GroupAndTimeVal.size() ? firstFrameIndex : 0; + firstFrameIndex = firstFrameIndex <= (int)this->AnimationIds.size() ? firstFrameIndex : 0; lastFrameIndex = - lastFrameIndex <= (int)GroupAndTimeVal.size() ? lastFrameIndex - 1 : lastFrameIndex; + lastFrameIndex <= (int)this->AnimationIds.size() ? lastFrameIndex - 1 : lastFrameIndex; for (int i = firstFrameIndex; i <= lastFrameIndex; i++) { - ActiveFrames.emplace_back(i); + this->ActiveFrames.emplace_back(i); } - ActiveAnimationId.emplace_back(animationIndex); + this->ActiveAnimationIds.emplace_back(animationIndex); } //---------------------------------------------------------------------------- void DisableAnimation(vtkIdType animationIndex) { - int firstFrameIndex = std::distance(GroupAndTimeVal.begin(), - std::find_if(GroupAndTimeVal.begin(), GroupAndTimeVal.end(), + int firstFrameIndex = std::distance(this->AnimationIds.begin(), + std::find_if(this->AnimationIds.begin(), this->AnimationIds.end(), [animationIndex](const std::pair pair) { return pair.first == animationIndex; })); - int lastFrameIndex = std::distance(GroupAndTimeVal.begin(), - std::find_if(GroupAndTimeVal.begin(), GroupAndTimeVal.end(), + int lastFrameIndex = std::distance(this->AnimationIds.begin(), + std::find_if(this->AnimationIds.begin(), this->AnimationIds.end(), [animationIndex](const std::pair pair) { return pair.first > animationIndex; })); - firstFrameIndex = firstFrameIndex <= (int)GroupAndTimeVal.size() ? firstFrameIndex : 0; + firstFrameIndex = firstFrameIndex <= (int)this->AnimationIds.size() ? firstFrameIndex : 0; lastFrameIndex = - lastFrameIndex <= (int)GroupAndTimeVal.size() ? lastFrameIndex - 1 : lastFrameIndex; + lastFrameIndex <= (int)this->AnimationIds.size() ? lastFrameIndex - 1 : lastFrameIndex; for (int i = firstFrameIndex; i <= lastFrameIndex; i++) { - ActiveFrames.erase( - std::remove(ActiveFrames.begin(), ActiveFrames.end(), i), ActiveFrames.end()); + this->ActiveFrames.erase( + std::remove(this->ActiveFrames.begin(), this->ActiveFrames.end(), i), this->ActiveFrames.end()); } - ActiveAnimationId.erase( - std::remove(ActiveAnimationId.begin(), ActiveAnimationId.end(), animationIndex), - ActiveAnimationId.end()); + this->ActiveAnimationIds.erase( + std::remove(this->ActiveAnimationIds.begin(), this->ActiveAnimationIds.end(), animationIndex), + this->ActiveAnimationIds.end()); } //---------------------------------------------------------------------------- @@ -422,37 +392,33 @@ class vtkF3DQuakeMDLImporter::vtkInternals actor->SetTexture(Texture); renderer->AddActor(actor); renderer->SetBackground(0, 0, 0); - Actor = actor; - Mapper = mapper; + this->Mapper = mapper; } //---------------------------------------------------------------------------- void SetFrameRate(double frameRate) { - FrameRate = frameRate; + this->FrameRate = frameRate; } //---------------------------------------------------------------------------- void GetTimeRange(vtkIdType vtkNotUsed(animationIndex), double timeRange[2]) { timeRange[0] = 0.0; - timeRange[1] = (1.0 / FrameRate) * GroupAndTimeVal.size(); + timeRange[1] = (1.0 / this->FrameRate) * this->AnimationIds.size(); } vtkF3DQuakeMDLImporter* Parent; std::string Description; - vtkSmartPointer Actor; vtkSmartPointer Mapper; std::vector> Mesh; - std::vector> GroupAndTimeVal; + std::vector> AnimationIds; std::vector AnimationNames; std::vector ActiveFrames; - std::vector ActiveAnimationId; + std::vector ActiveAnimationIds; int NumberOfAnimations = 0; - double LastRenderTime = 0.0; double FrameRate = 60.0; vtkSmartPointer Texture; - vtkSmartPointer TextureCoords; }; //---------------------------------------------------------------------------- @@ -519,24 +485,24 @@ void vtkF3DQuakeMDLImporter::DisableAnimation(vtkIdType animationIndex) //---------------------------------------------------------------------------- bool vtkF3DQuakeMDLImporter::IsAnimationEnabled(vtkIdType animationIndex) { - return std::count(this->Internals->ActiveAnimationId.begin(), - this->Internals->ActiveAnimationId.end(), animationIndex) > 0; + return std::count(this->Internals->ActiveAnimationIds.begin(), + this->Internals->ActiveAnimationIds.end(), animationIndex) > 0; } //---------------------------------------------------------------------------- bool vtkF3DQuakeMDLImporter::GetTemporalInformation(vtkIdType animationIndex, double frameRate, int& nbTimeSteps, double timeRange[2], vtkDoubleArray* vtkNotUsed(timeSteps)) { - Internals->SetFrameRate(frameRate); - Internals->GetTimeRange(animationIndex, timeRange); - nbTimeSteps = (int)Internals->ActiveFrames.size(); + this->Internals->SetFrameRate(frameRate); + this->Internals->GetTimeRange(animationIndex, timeRange); + nbTimeSteps = (int)this->Internals->ActiveFrames.size(); return true; } //---------------------------------------------------------------------------- vtkIdType vtkF3DQuakeMDLImporter::GetNumberOfCameras() { - return 1; + return 0; } //---------------------------------------------------------------------------- @@ -546,13 +512,11 @@ std::string vtkF3DQuakeMDLImporter::GetCameraName(vtkIdType vtkNotUsed(camIndex) } //---------------------------------------------------------------------------- -void vtkF3DQuakeMDLImporter::ImportCameras(vtkRenderer* renderer) +void vtkF3DQuakeMDLImporter::ImportCameras(vtkRenderer* vtkNotUsed(renderer)) { - this->Internals->ImportCameras(renderer); } //---------------------------------------------------------------------------- -void vtkF3DQuakeMDLImporter::ImportLights(vtkRenderer* renderer) +void vtkF3DQuakeMDLImporter::ImportLights(vtkRenderer* vtkNotUsed(renderer)) { - this->Internals->ImportLights(renderer); } diff --git a/plugins/native/module/vtkF3DQuakeMDLImporter.h b/plugins/native/module/vtkF3DQuakeMDLImporter.h index 26cab0b989..c991ab27d0 100644 --- a/plugins/native/module/vtkF3DQuakeMDLImporter.h +++ b/plugins/native/module/vtkF3DQuakeMDLImporter.h @@ -1,11 +1,15 @@ /** * @class vtkF3DQuakeMDLImporter * @brief VTK Importer for Quake 1 models in .mdl file format + * + * This reader is based on implementations of Quake 1's MDL, defined in https://book.leveldesignbook.com/appendix/resources/formats/mdl + * It reads vertices, normals and texture coordinate data from .mdl files. + * Supports animations. */ + #ifndef vtkF3DQuakeMDLImporter_h #define vtkF3DQuakeMDLImporter_h -#include "vtkF3DQuakeMDLImporterConstants.h" #include class vtkF3DQuakeMDLImporter : public vtkF3DImporter @@ -55,11 +59,13 @@ class vtkF3DQuakeMDLImporter : public vtkF3DImporter /** * Get the number of available cameras. + * Not implemented, multiple cameras are not specified. */ vtkIdType GetNumberOfCameras() override; /** * Get the name of a camera. + * Not implemented, not specified. */ std::string GetCameraName(vtkIdType camIndex) override; From bb76163f8ed4ce5c9d671c58c452a9f8907afbd1 Mon Sep 17 00:00:00 2001 From: Youva Boutora <48061964+Youva@users.noreply.github.com> Date: Sat, 21 Dec 2024 11:00:33 -0500 Subject: [PATCH 50/60] Added asset file for coverage --- plugins/native/module/Testing/TestF3DQuakeMDLImporter.cxx | 6 ++++-- plugins/native/module/vtkF3DQuakeMDLImporter.cxx | 8 +++++--- testing/data/glaunch_2.mdl | 3 +++ 3 files changed, 12 insertions(+), 5 deletions(-) create mode 100644 testing/data/glaunch_2.mdl diff --git a/plugins/native/module/Testing/TestF3DQuakeMDLImporter.cxx b/plugins/native/module/Testing/TestF3DQuakeMDLImporter.cxx index da0886590b..c6bccb9363 100644 --- a/plugins/native/module/Testing/TestF3DQuakeMDLImporter.cxx +++ b/plugins/native/module/Testing/TestF3DQuakeMDLImporter.cxx @@ -7,7 +7,7 @@ int TestF3DQuakeMDLImporter(int vtkNotUsed(argc), char* argv[]) { - std::string filename = std::string(argv[1]) + "data/glaunch.mdl"; + std::string filename = std::string(argv[1]) + "data/glaunch_2.mdl"; // File was modified to add coverage. vtkNew importer; importer->SetFileName(filename); importer->Update(); @@ -20,6 +20,8 @@ int TestF3DQuakeMDLImporter(int vtkNotUsed(argc), char* argv[]) vtkIdType selectedAnimationIndex = 1; importer->EnableAnimation(selectedAnimationIndex); std::string animationName = importer->GetAnimationName(2); + std::string cameraName = importer->GetCameraName(0); importer->UpdateTimeStep(0.0); - return numAnimations == 2 && animationName == "" ? EXIT_SUCCESS : EXIT_FAILURE; + return numAnimations == 2 && animationName == "" && cameraName == "Camera" ? EXIT_SUCCESS + : EXIT_FAILURE; } diff --git a/plugins/native/module/vtkF3DQuakeMDLImporter.cxx b/plugins/native/module/vtkF3DQuakeMDLImporter.cxx index 0751424f9c..e2f742300e 100644 --- a/plugins/native/module/vtkF3DQuakeMDLImporter.cxx +++ b/plugins/native/module/vtkF3DQuakeMDLImporter.cxx @@ -123,8 +123,8 @@ class vtkF3DQuakeMDLImporter::vtkInternals // Simple frame struct mdl_simpleframe_t // 24 + nbVertices bytes { - mdl_vertex_t bboxmin; // bouding box min - mdl_vertex_t bboxmax; // bouding box max + mdl_vertex_t bboxmin; // bounding box min + mdl_vertex_t bboxmax; // bounding box max char name[16]; // frame name mdl_vertex_t verts[1024]; // vertex list of the frame, maximum capacity is 1024 }; @@ -148,12 +148,14 @@ class vtkF3DQuakeMDLImporter::vtkInternals framePtr[i].nb = nullptr; framePtr[i].time = nullptr; framePtr[i].frames = reinterpret_cast(buffer.data() + 4 + offset); - offset += 4 + 24 + 4 * (header->numVertices); + offset += 4 + 24 + 4 * header->numVertices; } else { framePtr[i].nb = reinterpret_cast(buffer.data() + 4 + offset); framePtr[i].time = reinterpret_cast(buffer.data() + 16 + offset); + framePtr[i].frames = reinterpret_cast( + buffer.data() + 16 + 4 * (*framePtr[i].nb) + offset); frameOffsets.emplace_back(std::vector()); for (int j = 0; j < *framePtr[i].nb; j++) { diff --git a/testing/data/glaunch_2.mdl b/testing/data/glaunch_2.mdl new file mode 100644 index 0000000000..8006f9515f --- /dev/null +++ b/testing/data/glaunch_2.mdl @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a61ddbaeb423a837d9430164394296ae561f5401e1bb93819d5a496d4248c22b +size 86312 From 1eaca5bff214c6c25ca00b10352d2ad56b5b40d7 Mon Sep 17 00:00:00 2001 From: Youva Boutora <48061964+Youva@users.noreply.github.com> Date: Sat, 21 Dec 2024 13:14:32 -0500 Subject: [PATCH 51/60] Changed pointer cast, formatting. --- .../native/module/vtkF3DQuakeMDLImporter.cxx | 36 ++++++++++--------- .../native/module/vtkF3DQuakeMDLImporter.h | 8 ++--- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/plugins/native/module/vtkF3DQuakeMDLImporter.cxx b/plugins/native/module/vtkF3DQuakeMDLImporter.cxx index e2f742300e..8c852a7dd7 100644 --- a/plugins/native/module/vtkF3DQuakeMDLImporter.cxx +++ b/plugins/native/module/vtkF3DQuakeMDLImporter.cxx @@ -102,16 +102,18 @@ class vtkF3DQuakeMDLImporter::vtkInternals int s; int t; }; - const mdl_texcoord_t* texcoords = reinterpret_cast(buffer.data() + offset); + const mdl_texcoord_t* texcoords = + reinterpret_cast(buffer.data() + offset); offset += 12 * header->numVertices; // Read triangles - struct mdl_triangle_t + struct mdl_triangle_t { int facesfront; // 0 = backface, 1 = frontface int vertex[3]; // vertex indices }; - const mdl_triangle_t* triangles = reinterpret_cast(buffer.data() + offset); + const mdl_triangle_t* triangles = + reinterpret_cast(buffer.data() + offset); offset += 16 * header->numTriangles; // Simple vertex and normal @@ -123,18 +125,18 @@ class vtkF3DQuakeMDLImporter::vtkInternals // Simple frame struct mdl_simpleframe_t // 24 + nbVertices bytes { - mdl_vertex_t bboxmin; // bounding box min - mdl_vertex_t bboxmax; // bounding box max - char name[16]; // frame name - mdl_vertex_t verts[1024]; // vertex list of the frame, maximum capacity is 1024 + mdl_vertex_t bboxmin; // bounding box min + mdl_vertex_t bboxmax; // bounding box max + char name[16]; // frame name + mdl_vertex_t verts[1024]; // vertex list of the frame, maximum capacity is 1024 }; // Struct containing frame type and data struct plugin_frame_pointer { - const int* type; // 0 = simple frame, !0 = group frames - const int* nb; // "number", size of *time and *frames arrays - const float* time; // time duration for each frame - const mdl_simpleframe_t* frames; // simple frame list + const int* type; // 0 = simple frame, !0 = group frames + const int* nb; // "number", size of *time and *frames arrays + const float* time; // time duration for each frame + const mdl_simpleframe_t* frames; // simple frame list }; // Read frames std::vector framePtr = @@ -153,7 +155,8 @@ class vtkF3DQuakeMDLImporter::vtkInternals else { framePtr[i].nb = reinterpret_cast(buffer.data() + 4 + offset); - framePtr[i].time = reinterpret_cast(buffer.data() + 16 + offset); + framePtr[i].time = reinterpret_cast( + reinterpret_cast(buffer.data() + 16 + offset)); framePtr[i].frames = reinterpret_cast( buffer.data() + 16 + 4 * (*framePtr[i].nb) + offset); frameOffsets.emplace_back(std::vector()); @@ -217,7 +220,8 @@ class vtkF3DQuakeMDLImporter::vtkInternals normals->SetNumberOfComponents(3); normals->Allocate(header->numTriangles * 3 * 3); const mdl_simpleframe_t* selectedSimpleFrame = numGroupFrames > 1 - ? reinterpret_cast(buffer.data() + frameOffsets[frameNum][groupFrameNum]) + ? reinterpret_cast( + buffer.data() + frameOffsets[frameNum][groupFrameNum]) : selectedFrame.frames; for (int i = 0; i < header->numTriangles; i++) { @@ -308,7 +312,7 @@ class vtkF3DQuakeMDLImporter::vtkInternals std::pair pair = std::make_pair(this->AnimationIds[i].first, (this->AnimationIds[i].second + this->AnimationIds[i + 1].second) / 2); // Increments i to avoid infinite loop - this->AnimationIds.insert(this->AnimationIds.begin() + i++, pair); + this->AnimationIds.insert(this->AnimationIds.begin() + i++, pair); } } } @@ -376,8 +380,8 @@ class vtkF3DQuakeMDLImporter::vtkInternals lastFrameIndex <= (int)this->AnimationIds.size() ? lastFrameIndex - 1 : lastFrameIndex; for (int i = firstFrameIndex; i <= lastFrameIndex; i++) { - this->ActiveFrames.erase( - std::remove(this->ActiveFrames.begin(), this->ActiveFrames.end(), i), this->ActiveFrames.end()); + this->ActiveFrames.erase(std::remove(this->ActiveFrames.begin(), this->ActiveFrames.end(), i), + this->ActiveFrames.end()); } this->ActiveAnimationIds.erase( std::remove(this->ActiveAnimationIds.begin(), this->ActiveAnimationIds.end(), animationIndex), diff --git a/plugins/native/module/vtkF3DQuakeMDLImporter.h b/plugins/native/module/vtkF3DQuakeMDLImporter.h index c991ab27d0..fb86253f81 100644 --- a/plugins/native/module/vtkF3DQuakeMDLImporter.h +++ b/plugins/native/module/vtkF3DQuakeMDLImporter.h @@ -1,10 +1,10 @@ /** * @class vtkF3DQuakeMDLImporter * @brief VTK Importer for Quake 1 models in .mdl file format - * - * This reader is based on implementations of Quake 1's MDL, defined in https://book.leveldesignbook.com/appendix/resources/formats/mdl - * It reads vertices, normals and texture coordinate data from .mdl files. - * Supports animations. + * + * This reader is based on implementations of Quake 1's MDL, defined in + * https://book.leveldesignbook.com/appendix/resources/formats/mdl It reads vertices, normals and + * texture coordinate data from .mdl files. Supports animations. */ From 38558303572322cb78b2810b8bb98e751f4ca716 Mon Sep 17 00:00:00 2001 From: Youva Boutora <48061964+Youva@users.noreply.github.com> Date: Sat, 21 Dec 2024 17:06:39 -0500 Subject: [PATCH 52/60] Added constexpr variables for offset calculation --- .../native/configs/config.d/10_native.json | 3 +- .../native/configs/thumbnail.d/10_native.json | 7 + plugins/native/f3d-3d-formats.xml | 4 + plugins/native/module/CMakeLists.txt | 1 - .../Testing/TestF3DQuakeMDLImporter.cxx | 9 +- .../native/module/vtkF3DQuakeMDLImporter.cxx | 166 +++++++++--------- .../native/module/vtkF3DQuakeMDLImporter.h | 9 - .../vtkF3DQuakeMDLImporterConstants.cxx | 131 -------------- .../module/vtkF3DQuakeMDLImporterConstants.h | 131 +++++++++++++- testing/data/glaunch_2.mdl | 4 +- 10 files changed, 234 insertions(+), 231 deletions(-) delete mode 100644 plugins/native/module/vtkF3DQuakeMDLImporterConstants.cxx diff --git a/plugins/native/configs/config.d/10_native.json b/plugins/native/configs/config.d/10_native.json index eb05839770..4b3846e2a9 100644 --- a/plugins/native/configs/config.d/10_native.json +++ b/plugins/native/configs/config.d/10_native.json @@ -73,8 +73,7 @@ "match": ".*(mdl)", "options": { - "up": "+Z", - "camera-direction": "-1,0,0" + "up": "+Z" } } ] diff --git a/plugins/native/configs/thumbnail.d/10_native.json b/plugins/native/configs/thumbnail.d/10_native.json index 4526a3b8f7..911dea4413 100644 --- a/plugins/native/configs/thumbnail.d/10_native.json +++ b/plugins/native/configs/thumbnail.d/10_native.json @@ -49,5 +49,12 @@ "anti-aliasing": false, "translucency-support": false } +}, +{ + "match": ".*(mdl)", + "options": + { + "up": "+Z" + } } ] diff --git a/plugins/native/f3d-3d-formats.xml b/plugins/native/f3d-3d-formats.xml index 714d926cb4..59da107542 100644 --- a/plugins/native/f3d-3d-formats.xml +++ b/plugins/native/f3d-3d-formats.xml @@ -37,4 +37,8 @@ 3D Gaussians Splat File Format + + Quake 1 MDL File Format + + diff --git a/plugins/native/module/CMakeLists.txt b/plugins/native/module/CMakeLists.txt index 5d7278c968..48b72931af 100644 --- a/plugins/native/module/CMakeLists.txt +++ b/plugins/native/module/CMakeLists.txt @@ -1,7 +1,6 @@ set(classes vtkF3DSplatReader vtkF3DQuakeMDLImporter - vtkF3DQuakeMDLImporterConstants ) set(_no_install "") diff --git a/plugins/native/module/Testing/TestF3DQuakeMDLImporter.cxx b/plugins/native/module/Testing/TestF3DQuakeMDLImporter.cxx index c6bccb9363..89a81cd302 100644 --- a/plugins/native/module/Testing/TestF3DQuakeMDLImporter.cxx +++ b/plugins/native/module/Testing/TestF3DQuakeMDLImporter.cxx @@ -1,4 +1,5 @@ #include "vtkF3DQuakeMDLImporter.h" + #include #include #include @@ -7,7 +8,8 @@ int TestF3DQuakeMDLImporter(int vtkNotUsed(argc), char* argv[]) { - std::string filename = std::string(argv[1]) + "data/glaunch_2.mdl"; // File was modified to add coverage. + std::string filename = + std::string(argv[1]) + "data/glaunch_2.mdl"; // File was modified to add coverage. vtkNew importer; importer->SetFileName(filename); importer->Update(); @@ -20,8 +22,5 @@ int TestF3DQuakeMDLImporter(int vtkNotUsed(argc), char* argv[]) vtkIdType selectedAnimationIndex = 1; importer->EnableAnimation(selectedAnimationIndex); std::string animationName = importer->GetAnimationName(2); - std::string cameraName = importer->GetCameraName(0); - importer->UpdateTimeStep(0.0); - return numAnimations == 2 && animationName == "" && cameraName == "Camera" ? EXIT_SUCCESS - : EXIT_FAILURE; + return numAnimations == 2 && animationName == "" ? EXIT_SUCCESS : EXIT_FAILURE; } diff --git a/plugins/native/module/vtkF3DQuakeMDLImporter.cxx b/plugins/native/module/vtkF3DQuakeMDLImporter.cxx index 8c852a7dd7..dfa9c20639 100644 --- a/plugins/native/module/vtkF3DQuakeMDLImporter.cxx +++ b/plugins/native/module/vtkF3DQuakeMDLImporter.cxx @@ -26,6 +26,8 @@ class vtkF3DQuakeMDLImporter::vtkInternals vtkSmartPointer CreateTexture(const std::vector& buffer, int& offset, int skinWidth, int skinHeight, int nbSkins, int selectedSkinIndex) { + constexpr int char_size = 1; + constexpr int int_size = 4; vtkNew texture; texture->InterpolateOn(); @@ -41,14 +43,14 @@ class vtkF3DQuakeMDLImporter::vtkInternals skins[i].group = *reinterpret_cast(buffer.data() + offset); if (skins[i].group == 0) { - skins[i].skin = buffer.data() + 4 + offset; - offset += 4 + skinWidth * skinHeight; + skins[i].skin = buffer.data() + int_size + offset; + offset += int_size + skinWidth * skinHeight * char_size; } else { int nb = *reinterpret_cast(buffer.data() + offset + 4); skins[i].skin = buffer.data() + 4 + nb * 4 + offset; - offset += 4 + nb * 4 + nb * skinWidth * skinHeight; + offset += int_size + nb * int_size + nb * skinWidth * skinHeight * char_size; } } @@ -93,49 +95,60 @@ class vtkF3DQuakeMDLImporter::vtkInternals }; //---------------------------------------------------------------------------- - void CreateMesh(const std::vector& buffer, int offset, mdl_header_t* header) + void CreateMesh(const std::vector& buffer, int offset, const mdl_header_t* header) { + constexpr char char_size = 1; // Size of char in file + constexpr int int_size = 4; // Size of int in file + constexpr int float_size = 4; // Size of float in file // Read texture coordinates struct mdl_texcoord_t { int onseam; - int s; - int t; + int coord_s; + int coord_t; }; + constexpr int mdl_texcoord_t_size = 3 * int_size; // Size of struct const mdl_texcoord_t* texcoords = reinterpret_cast(buffer.data() + offset); - offset += 12 * header->numVertices; + offset += mdl_texcoord_t_size * header->numVertices; // Size of mdl_texcoord_t array // Read triangles struct mdl_triangle_t { - int facesfront; // 0 = backface, 1 = frontface + int facesFront; // 0 = backface, 1 = frontface int vertex[3]; // vertex indices }; + constexpr int mdl_triangle_t_size = 4 * int_size; // Size of struct const mdl_triangle_t* triangles = reinterpret_cast(buffer.data() + offset); - offset += 16 * header->numTriangles; + offset += mdl_triangle_t_size * header->numTriangles; // Size of mdl_triangle_t array // Simple vertex and normal struct mdl_vertex_t { - unsigned char v[3]; + unsigned char xyz[3]; unsigned char normalIndex; }; + constexpr int mdl_vertex_t_size = 4; // Simple frame struct mdl_simpleframe_t // 24 + nbVertices bytes { - mdl_vertex_t bboxmin; // bounding box min - mdl_vertex_t bboxmax; // bounding box max - char name[16]; // frame name - mdl_vertex_t verts[1024]; // vertex list of the frame, maximum capacity is 1024 + mdl_vertex_t bboxmin; // bounding box min + mdl_vertex_t bboxmax; // bounding box max + char name[16]; // frame name + mdl_vertex_t verts[1024]; // vertex list of the frame, maximum capacity is 1024 }; + constexpr int mdl_simpleframe_t_fixed_size = + 2 * mdl_vertex_t_size + 16 * char_size; // Size of bboxmin, bboxmax and name. // Struct containing frame type and data + // Used to read mdl_frame_t and mdl_groupframe_t struct plugin_frame_pointer { - const int* type; // 0 = simple frame, !0 = group frames - const int* nb; // "number", size of *time and *frames arrays - const float* time; // time duration for each frame + const int* type; // 0 = simple frame, !0 = group frames + const int* nb; // "number", size of *time and *frames arrays, optional + // const mdl_vertex_t* min; // min pos in all simple frames, optional + // const mdl_vertex_t* max; // max pos in all simple frames, optional + const float* time; // time duration for each frame, optional const mdl_simpleframe_t* frames; // simple frame list }; // Read frames @@ -150,22 +163,26 @@ class vtkF3DQuakeMDLImporter::vtkInternals framePtr[i].nb = nullptr; framePtr[i].time = nullptr; framePtr[i].frames = reinterpret_cast(buffer.data() + 4 + offset); - offset += 4 + 24 + 4 * header->numVertices; + // Size of a frame is 24 + 4 * numVertices, + 4 bytes for the int + offset += int_size + mdl_simpleframe_t_fixed_size + mdl_vertex_t_size * header->numVertices; } else { - framePtr[i].nb = reinterpret_cast(buffer.data() + 4 + offset); - framePtr[i].time = reinterpret_cast( - reinterpret_cast(buffer.data() + 16 + offset)); - framePtr[i].frames = reinterpret_cast( - buffer.data() + 16 + 4 * (*framePtr[i].nb) + offset); + framePtr[i].nb = reinterpret_cast(buffer.data() + int_size + offset); + // Skips parameters min and max. + framePtr[i].time = reinterpret_cast(reinterpret_cast( + buffer.data() + 2 * int_size + 2 * mdl_vertex_t_size + offset)); + // Points to the first frame, 4 * nbFrames for the float array + framePtr[i].frames = reinterpret_cast(buffer.data() + + 2 * int_size + 2 * mdl_vertex_t_size + (*framePtr[i].nb) * float_size + offset); + offset += 2 * int_size + 2 * mdl_vertex_t_size + (*framePtr[i].nb) * float_size; frameOffsets.emplace_back(std::vector()); for (int j = 0; j < *framePtr[i].nb; j++) { - frameOffsets[i].emplace_back( - 16 + 4 * (*framePtr[i].nb) + j * 4 * (header->numVertices + 6) + offset); + // Offset for each frame + frameOffsets[i].emplace_back(offset); + offset += mdl_simpleframe_t_fixed_size + mdl_vertex_t_size * header->numVertices; } - offset += 16 + (*framePtr[i].nb) * 4 + (24 + 4 * header->numVertices) * (*framePtr[i].nb); } } @@ -178,8 +195,8 @@ class vtkF3DQuakeMDLImporter::vtkInternals textureCoordinates->Allocate(header->numTriangles * 3); struct plugin_texture_coords { - float s; - float t; + float coord_s; + float coord_t; }; std::vector coords = std::vector(header->numTriangles * 3); @@ -187,26 +204,26 @@ class vtkF3DQuakeMDLImporter::vtkInternals { for (int j = 0; j < 3; j++) { - float s = texcoords[triangles[i].vertex[j]].s; - float t = texcoords[triangles[i].vertex[j]].t; - if (!triangles[i].facesfront && texcoords[triangles[i].vertex[j]].onseam) + float coord_s = texcoords[triangles[i].vertex[j]].coord_s; + float coord_t = texcoords[triangles[i].vertex[j]].coord_t; + if (!triangles[i].facesFront && texcoords[triangles[i].vertex[j]].onseam) { - s = s + header->skinWidth * 0.5f; // Backface + coord_s = coord_s + header->skinWidth * 0.5f; // Backface } // Scale s and t to range from 0.0 to 1.0 - s = (s + 0.5) / header->skinWidth; - t = (t + 0.5) / header->skinHeight; - coords[3 * i + j].s = s; - coords[3 * i + j].t = t; - float st[2] = { s, t }; - textureCoordinates->InsertNextTuple(st); + coord_s = (coord_s + 0.5) / header->skinWidth; + coord_t = (coord_t + 0.5) / header->skinHeight; + coords[3 * i + j].coord_s = coord_s; + coords[3 * i + j].coord_t = coord_t; + float coords_st[2] = { coord_s, coord_t }; + textureCoordinates->InsertNextTuple(coords_st); } - vtkIdType t[3] = { i * 3, i * 3 + 1, i * 3 + 2 }; - cells->InsertNextCell(3, t); + vtkIdType triangle[3] = { i * 3, i * 3 + 1, i * 3 + 2 }; + cells->InsertNextCell(3, triangle); } // Draw frames - std::string frameName = ""; + std::string frameName; int animationId = 0; for (int frameNum = 0; frameNum < header->numFrames; frameNum++) { @@ -229,15 +246,15 @@ class vtkF3DQuakeMDLImporter::vtkInternals for (int j = 0; j < 3; j++) { vertexNum[j] = triangles[i].vertex[j]; - double v[3] = { double(selectedSimpleFrame->verts[vertexNum[j]].v[0]), - double(selectedSimpleFrame->verts[vertexNum[j]].v[1]), - double(selectedSimpleFrame->verts[vertexNum[j]].v[2]) }; + double xyz[3] = { double(selectedSimpleFrame->verts[vertexNum[j]].xyz[0]), + double(selectedSimpleFrame->verts[vertexNum[j]].xyz[1]), + double(selectedSimpleFrame->verts[vertexNum[j]].xyz[2]) }; // Calculate real vertex position for (int k = 0; k < 3; k++) { - v[k] = v[k] * header->scale[k] + header->translation[k]; + xyz[k] = xyz[k] * header->scale[k] + header->translation[k]; } - vertices->InsertPoint(i * 3 + j, v); + vertices->InsertPoint(i * 3 + j, xyz); // Normal vector int normalIndex = selectedSimpleFrame->verts[vertexNum[j]].normalIndex; normals->SetTuple3(i * 3 + j, F3DMDLNormalVectors[normalIndex][0] / 255.0, @@ -295,12 +312,12 @@ class vtkF3DQuakeMDLImporter::vtkInternals vertices->Allocate(header->numTriangles * 3); for (int j = 0; j < header->numTriangles * 3; j++) { - double* v_0 = this->Mesh[i]->GetPoint(j); - double* v_1 = this->Mesh[i + 1]->GetPoint(j); + double* vertex0 = this->Mesh[i]->GetPoint(j); + double* vertex1 = this->Mesh[i + 1]->GetPoint(j); double interp[3]; - interp[0] = v_0[0] + 0.5 * (v_1[0] - v_0[0]); - interp[1] = v_0[1] + 0.5 * (v_1[1] - v_0[1]); - interp[2] = v_0[2] + 0.5 * (v_1[2] - v_0[2]); + interp[0] = vertex0[0] + 0.5 * (vertex1[0] - vertex0[0]); + interp[1] = vertex0[1] + 0.5 * (vertex1[1] - vertex0[1]); + interp[2] = vertex0[2] + 0.5 * (vertex1[2] - vertex0[2]); vertices->InsertPoint(j, interp); } vtkNew mesh; @@ -323,8 +340,10 @@ class vtkF3DQuakeMDLImporter::vtkInternals std::ifstream inputStream(filePath, std::ios::binary); std::vector buffer(std::istreambuf_iterator(inputStream), {}); // Read header - mdl_header_t* header = reinterpret_cast(buffer.data()); - int offset = 84; + int offset = 0; + const mdl_header_t* header = reinterpret_cast(buffer.data()); + constexpr int mdl_header_t_size = 84; // Size of the header struct in the file. + offset += mdl_header_t_size; // Set textures this->Texture = this->CreateTexture( buffer, offset, header->skinWidth, header->skinHeight, header->numSkins, 0); @@ -338,7 +357,8 @@ class vtkF3DQuakeMDLImporter::vtkInternals //---------------------------------------------------------------------------- void UpdateTimeStep(double timeValue) { - int frameIndex = (int)floor(FrameRate * abs(timeValue)) % (int)this->ActiveFrames.size(); + int frameIndex = static_cast(floor(FrameRate * abs(timeValue))) % + static_cast(this->ActiveFrames.size()); int currentFrame = this->ActiveFrames[frameIndex]; this->Mapper->SetInputData(this->Mesh[currentFrame]); } @@ -354,9 +374,11 @@ class vtkF3DQuakeMDLImporter::vtkInternals std::find_if(this->AnimationIds.begin(), this->AnimationIds.end(), [animationIndex](const std::pair pair) { return pair.first > animationIndex; })); - firstFrameIndex = firstFrameIndex <= (int)this->AnimationIds.size() ? firstFrameIndex : 0; - lastFrameIndex = - lastFrameIndex <= (int)this->AnimationIds.size() ? lastFrameIndex - 1 : lastFrameIndex; + firstFrameIndex = + firstFrameIndex <= static_cast(this->AnimationIds.size()) ? firstFrameIndex : 0; + lastFrameIndex = lastFrameIndex <= static_cast(this->AnimationIds.size()) + ? lastFrameIndex - 1 + : lastFrameIndex; for (int i = firstFrameIndex; i <= lastFrameIndex; i++) { this->ActiveFrames.emplace_back(i); @@ -375,9 +397,11 @@ class vtkF3DQuakeMDLImporter::vtkInternals std::find_if(this->AnimationIds.begin(), this->AnimationIds.end(), [animationIndex](const std::pair pair) { return pair.first > animationIndex; })); - firstFrameIndex = firstFrameIndex <= (int)this->AnimationIds.size() ? firstFrameIndex : 0; - lastFrameIndex = - lastFrameIndex <= (int)this->AnimationIds.size() ? lastFrameIndex - 1 : lastFrameIndex; + firstFrameIndex = + firstFrameIndex <= static_cast(this->AnimationIds.size()) ? firstFrameIndex : 0; + lastFrameIndex = lastFrameIndex <= static_cast(this->AnimationIds.size()) + ? lastFrameIndex - 1 + : lastFrameIndex; for (int i = firstFrameIndex; i <= lastFrameIndex; i++) { this->ActiveFrames.erase(std::remove(this->ActiveFrames.begin(), this->ActiveFrames.end(), i), @@ -429,7 +453,7 @@ class vtkF3DQuakeMDLImporter::vtkInternals //---------------------------------------------------------------------------- vtkF3DQuakeMDLImporter::vtkF3DQuakeMDLImporter() - : Internals(new vtkF3DQuakeMDLImporter::vtkInternals(this)){ + : Internals(new vtkF3DQuakeMDLImporter::vtkInternals(this)) { }; @@ -466,7 +490,7 @@ vtkIdType vtkF3DQuakeMDLImporter::GetNumberOfAnimations() //---------------------------------------------------------------------------- std::string vtkF3DQuakeMDLImporter::GetAnimationName(vtkIdType animationIndex) { - if (animationIndex < (int)this->Internals->AnimationNames.size()) + if (animationIndex < static_cast(this->Internals->AnimationNames.size())) { return this->Internals->AnimationNames[animationIndex]; } @@ -501,7 +525,7 @@ bool vtkF3DQuakeMDLImporter::GetTemporalInformation(vtkIdType animationIndex, do { this->Internals->SetFrameRate(frameRate); this->Internals->GetTimeRange(animationIndex, timeRange); - nbTimeSteps = (int)this->Internals->ActiveFrames.size(); + nbTimeSteps = static_cast(this->Internals->ActiveFrames.size()); return true; } @@ -510,19 +534,3 @@ vtkIdType vtkF3DQuakeMDLImporter::GetNumberOfCameras() { return 0; } - -//---------------------------------------------------------------------------- -std::string vtkF3DQuakeMDLImporter::GetCameraName(vtkIdType vtkNotUsed(camIndex)) -{ - return "Camera"; -} - -//---------------------------------------------------------------------------- -void vtkF3DQuakeMDLImporter::ImportCameras(vtkRenderer* vtkNotUsed(renderer)) -{ -} - -//---------------------------------------------------------------------------- -void vtkF3DQuakeMDLImporter::ImportLights(vtkRenderer* vtkNotUsed(renderer)) -{ -} diff --git a/plugins/native/module/vtkF3DQuakeMDLImporter.h b/plugins/native/module/vtkF3DQuakeMDLImporter.h index fb86253f81..2ab2b1871c 100644 --- a/plugins/native/module/vtkF3DQuakeMDLImporter.h +++ b/plugins/native/module/vtkF3DQuakeMDLImporter.h @@ -7,7 +7,6 @@ * texture coordinate data from .mdl files. Supports animations. */ - #ifndef vtkF3DQuakeMDLImporter_h #define vtkF3DQuakeMDLImporter_h #include @@ -63,20 +62,12 @@ class vtkF3DQuakeMDLImporter : public vtkF3DImporter */ vtkIdType GetNumberOfCameras() override; - /** - * Get the name of a camera. - * Not implemented, not specified. - */ - std::string GetCameraName(vtkIdType camIndex) override; - protected: vtkF3DQuakeMDLImporter(); ~vtkF3DQuakeMDLImporter() override = default; int ImportBegin() override; void ImportActors(vtkRenderer*) override; - void ImportCameras(vtkRenderer*) override; - void ImportLights(vtkRenderer*) override; private: vtkF3DQuakeMDLImporter(const vtkF3DQuakeMDLImporter&) = delete; diff --git a/plugins/native/module/vtkF3DQuakeMDLImporterConstants.cxx b/plugins/native/module/vtkF3DQuakeMDLImporterConstants.cxx deleted file mode 100644 index d3bac5d547..0000000000 --- a/plugins/native/module/vtkF3DQuakeMDLImporterConstants.cxx +++ /dev/null @@ -1,131 +0,0 @@ -#include "vtkF3DQuakeMDLImporterConstants.h" - -const unsigned char F3DMDLDefaultColorMap[256][3] = { { 0, 0, 0 }, { 15, 15, 15 }, { 31, 31, 31 }, - { 47, 47, 47 }, { 63, 63, 63 }, { 75, 75, 75 }, { 91, 91, 91 }, { 107, 107, 107 }, - { 123, 123, 123 }, { 139, 139, 139 }, { 155, 155, 155 }, { 171, 171, 171 }, { 187, 187, 187 }, - { 203, 203, 203 }, { 219, 219, 219 }, { 235, 235, 235 }, { 15, 11, 7 }, { 23, 15, 11 }, - { 31, 23, 11 }, { 39, 27, 15 }, { 47, 35, 19 }, { 55, 43, 23 }, { 63, 47, 23 }, { 75, 55, 27 }, - { 83, 59, 27 }, { 91, 67, 31 }, { 99, 75, 31 }, { 107, 83, 31 }, { 115, 87, 31 }, { 123, 95, 35 }, - { 131, 103, 35 }, { 143, 111, 35 }, { 11, 11, 15 }, { 19, 19, 27 }, { 27, 27, 39 }, - { 39, 39, 51 }, { 47, 47, 63 }, { 55, 55, 75 }, { 63, 63, 87 }, { 71, 71, 103 }, { 79, 79, 115 }, - { 91, 91, 127 }, { 99, 99, 139 }, { 107, 107, 151 }, { 115, 115, 163 }, { 123, 123, 175 }, - { 131, 131, 187 }, { 139, 139, 203 }, { 0, 0, 0 }, { 7, 7, 0 }, { 11, 11, 0 }, { 19, 19, 0 }, - { 27, 27, 0 }, { 35, 35, 0 }, { 43, 43, 7 }, { 47, 47, 7 }, { 55, 55, 7 }, { 63, 63, 7 }, - { 71, 71, 7 }, { 75, 75, 11 }, { 83, 83, 11 }, { 91, 91, 11 }, { 99, 99, 11 }, { 107, 107, 15 }, - { 7, 0, 0 }, { 15, 0, 0 }, { 23, 0, 0 }, { 31, 0, 0 }, { 39, 0, 0 }, { 47, 0, 0 }, { 55, 0, 0 }, - { 63, 0, 0 }, { 71, 0, 0 }, { 79, 0, 0 }, { 87, 0, 0 }, { 95, 0, 0 }, { 103, 0, 0 }, - { 111, 0, 0 }, { 119, 0, 0 }, { 127, 0, 0 }, { 19, 19, 0 }, { 27, 27, 0 }, { 35, 35, 0 }, - { 47, 43, 0 }, { 55, 47, 0 }, { 67, 55, 0 }, { 75, 59, 7 }, { 87, 67, 7 }, { 95, 71, 7 }, - { 107, 75, 11 }, { 119, 83, 15 }, { 131, 87, 19 }, { 139, 91, 19 }, { 151, 95, 27 }, - { 163, 99, 31 }, { 175, 103, 35 }, { 35, 19, 7 }, { 47, 23, 11 }, { 59, 31, 15 }, { 75, 35, 19 }, - { 87, 43, 23 }, { 99, 47, 31 }, { 115, 55, 35 }, { 127, 59, 43 }, { 143, 67, 51 }, - { 159, 79, 51 }, { 175, 99, 47 }, { 191, 119, 47 }, { 207, 143, 43 }, { 223, 171, 39 }, - { 239, 203, 31 }, { 255, 243, 27 }, { 11, 7, 0 }, { 27, 19, 0 }, { 43, 35, 15 }, { 55, 43, 19 }, - { 71, 51, 27 }, { 83, 55, 35 }, { 99, 63, 43 }, { 111, 71, 51 }, { 127, 83, 63 }, { 139, 95, 71 }, - { 155, 107, 83 }, { 167, 123, 95 }, { 183, 135, 107 }, { 195, 147, 123 }, { 211, 163, 139 }, - { 227, 179, 151 }, { 171, 139, 163 }, { 159, 127, 151 }, { 147, 115, 135 }, { 139, 103, 123 }, - { 127, 91, 111 }, { 119, 83, 99 }, { 107, 75, 87 }, { 95, 63, 75 }, { 87, 55, 67 }, - { 75, 47, 55 }, { 67, 39, 47 }, { 55, 31, 35 }, { 43, 23, 27 }, { 35, 19, 19 }, { 23, 11, 11 }, - { 15, 7, 7 }, { 187, 115, 159 }, { 175, 107, 143 }, { 163, 95, 131 }, { 151, 87, 119 }, - { 139, 79, 107 }, { 127, 75, 95 }, { 115, 67, 83 }, { 107, 59, 75 }, { 95, 51, 63 }, - { 83, 43, 55 }, { 71, 35, 43 }, { 59, 31, 35 }, { 47, 23, 27 }, { 35, 19, 19 }, { 23, 11, 11 }, - { 15, 7, 7 }, { 219, 195, 187 }, { 203, 179, 167 }, { 191, 163, 155 }, { 175, 151, 139 }, - { 163, 135, 123 }, { 151, 123, 111 }, { 135, 111, 95 }, { 123, 99, 83 }, { 107, 87, 71 }, - { 95, 75, 59 }, { 83, 63, 51 }, { 67, 51, 39 }, { 55, 43, 31 }, { 39, 31, 23 }, { 27, 19, 15 }, - { 15, 11, 7 }, { 111, 131, 123 }, { 103, 123, 111 }, { 95, 115, 103 }, { 87, 107, 95 }, - { 79, 99, 87 }, { 71, 91, 79 }, { 63, 83, 71 }, { 55, 75, 63 }, { 47, 67, 55 }, { 43, 59, 47 }, - { 35, 51, 39 }, { 31, 43, 31 }, { 23, 35, 23 }, { 15, 27, 19 }, { 11, 19, 11 }, { 7, 11, 7 }, - { 255, 243, 27 }, { 239, 223, 23 }, { 219, 203, 19 }, { 203, 183, 15 }, { 187, 167, 15 }, - { 171, 151, 11 }, { 155, 131, 7 }, { 139, 115, 7 }, { 123, 99, 7 }, { 107, 83, 0 }, { 91, 71, 0 }, - { 75, 55, 0 }, { 59, 43, 0 }, { 43, 31, 0 }, { 27, 15, 0 }, { 11, 7, 0 }, { 0, 0, 255 }, - { 11, 11, 239 }, { 19, 19, 223 }, { 27, 27, 207 }, { 35, 35, 191 }, { 43, 43, 175 }, - { 47, 47, 159 }, { 47, 47, 143 }, { 47, 47, 127 }, { 47, 47, 111 }, { 47, 47, 95 }, - { 43, 43, 79 }, { 35, 35, 63 }, { 27, 27, 47 }, { 19, 19, 31 }, { 11, 11, 15 }, { 43, 0, 0 }, - { 59, 0, 0 }, { 75, 7, 0 }, { 95, 7, 0 }, { 111, 15, 0 }, { 127, 23, 7 }, { 147, 31, 7 }, - { 163, 39, 11 }, { 183, 51, 15 }, { 195, 75, 27 }, { 207, 99, 43 }, { 219, 127, 59 }, - { 227, 151, 79 }, { 231, 171, 95 }, { 239, 191, 119 }, { 247, 211, 139 }, { 167, 123, 59 }, - { 183, 155, 55 }, { 199, 195, 55 }, { 231, 227, 87 }, { 127, 191, 255 }, { 171, 231, 255 }, - { 215, 255, 255 }, { 103, 0, 0 }, { 139, 0, 0 }, { 179, 0, 0 }, { 215, 0, 0 }, { 255, 0, 0 }, - { 255, 243, 147 }, { 255, 247, 199 }, { 255, 255, 255 }, { 159, 91, 83 } }; -const float F3DMDLNormalVectors[162][3] = { { -0.525731f, 0.000000f, 0.850651f }, - { -0.442863f, 0.238856f, 0.864188f }, { -0.295242f, 0.000000f, 0.955423f }, - { -0.309017f, 0.500000f, 0.809017f }, { -0.162460f, 0.262866f, 0.951056f }, - { 0.000000f, 0.000000f, 1.000000f }, { 0.000000f, 0.850651f, 0.525731f }, - { -0.147621f, 0.716567f, 0.681718f }, { 0.147621f, 0.716567f, 0.681718f }, - { 0.000000f, 0.525731f, 0.850651f }, { 0.309017f, 0.500000f, 0.809017f }, - { 0.525731f, 0.000000f, 0.850651f }, { 0.295242f, 0.000000f, 0.955423f }, - { 0.442863f, 0.238856f, 0.864188f }, { 0.162460f, 0.262866f, 0.951056f }, - { -0.681718f, 0.147621f, 0.716567f }, { -0.809017f, 0.309017f, 0.500000f }, - { -0.587785f, 0.425325f, 0.688191f }, { -0.850651f, 0.525731f, 0.000000f }, - { -0.864188f, 0.442863f, 0.238856f }, { -0.716567f, 0.681718f, 0.147621f }, - { -0.688191f, 0.587785f, 0.425325f }, { -0.500000f, 0.809017f, 0.309017f }, - { -0.238856f, 0.864188f, 0.442863f }, { -0.425325f, 0.688191f, 0.587785f }, - { -0.716567f, 0.681718f, -0.147621f }, { -0.500000f, 0.809017f, -0.309017f }, - { -0.525731f, 0.850651f, 0.000000f }, { 0.000000f, 0.850651f, -0.525731f }, - { -0.238856f, 0.864188f, -0.442863f }, { 0.000000f, 0.955423f, -0.295242f }, - { -0.262866f, 0.951056f, -0.162460f }, { 0.000000f, 1.000000f, 0.000000f }, - { 0.000000f, 0.955423f, 0.295242f }, { -0.262866f, 0.951056f, 0.162460f }, - { 0.238856f, 0.864188f, 0.442863f }, { 0.262866f, 0.951056f, 0.162460f }, - { 0.500000f, 0.809017f, 0.309017f }, { 0.238856f, 0.864188f, -0.442863f }, - { 0.262866f, 0.951056f, -0.162460f }, { 0.500000f, 0.809017f, -0.309017f }, - { 0.850651f, 0.525731f, 0.000000f }, { 0.716567f, 0.681718f, 0.147621f }, - { 0.716567f, 0.681718f, -0.147621f }, { 0.525731f, 0.850651f, 0.000000f }, - { 0.425325f, 0.688191f, 0.587785f }, { 0.864188f, 0.442863f, 0.238856f }, - { 0.688191f, 0.587785f, 0.425325f }, { 0.809017f, 0.309017f, 0.500000f }, - { 0.681718f, 0.147621f, 0.716567f }, { 0.587785f, 0.425325f, 0.688191f }, - { 0.955423f, 0.295242f, 0.000000f }, { 1.000000f, 0.000000f, 0.000000f }, - { 0.951056f, 0.162460f, 0.262866f }, { 0.850651f, -0.525731f, 0.000000f }, - { 0.955423f, -0.295242f, 0.000000f }, { 0.864188f, -0.442863f, 0.238856f }, - { 0.951056f, -0.162460f, 0.262866f }, { 0.809017f, -0.309017f, 0.500000f }, - { 0.681718f, -0.147621f, 0.716567f }, { 0.850651f, 0.000000f, 0.525731f }, - { 0.864188f, 0.442863f, -0.238856f }, { 0.809017f, 0.309017f, -0.500000f }, - { 0.951056f, 0.162460f, -0.262866f }, { 0.525731f, 0.000000f, -0.850651f }, - { 0.681718f, 0.147621f, -0.716567f }, { 0.681718f, -0.147621f, -0.716567f }, - { 0.850651f, 0.000000f, -0.525731f }, { 0.809017f, -0.309017f, -0.500000f }, - { 0.864188f, -0.442863f, -0.238856f }, { 0.951056f, -0.162460f, -0.262866f }, - { 0.147621f, 0.716567f, -0.681718f }, { 0.309017f, 0.500000f, -0.809017f }, - { 0.425325f, 0.688191f, -0.587785f }, { 0.442863f, 0.238856f, -0.864188f }, - { 0.587785f, 0.425325f, -0.688191f }, { 0.688191f, 0.587785f, -0.425325f }, - { -0.147621f, 0.716567f, -0.681718f }, { -0.309017f, 0.500000f, -0.809017f }, - { 0.000000f, 0.525731f, -0.850651f }, { -0.525731f, 0.000000f, -0.850651f }, - { -0.442863f, 0.238856f, -0.864188f }, { -0.295242f, 0.000000f, -0.955423f }, - { -0.162460f, 0.262866f, -0.951056f }, { 0.000000f, 0.000000f, -1.000000f }, - { 0.295242f, 0.000000f, -0.955423f }, { 0.162460f, 0.262866f, -0.951056f }, - { -0.442863f, -0.238856f, -0.864188f }, { -0.309017f, -0.500000f, -0.809017f }, - { -0.162460f, -0.262866f, -0.951056f }, { 0.000000f, -0.850651f, -0.525731f }, - { -0.147621f, -0.716567f, -0.681718f }, { 0.147621f, -0.716567f, -0.681718f }, - { 0.000000f, -0.525731f, -0.850651f }, { 0.309017f, -0.500000f, -0.809017f }, - { 0.442863f, -0.238856f, -0.864188f }, { 0.162460f, -0.262866f, -0.951056f }, - { 0.238856f, -0.864188f, -0.442863f }, { 0.500000f, -0.809017f, -0.309017f }, - { 0.425325f, -0.688191f, -0.587785f }, { 0.716567f, -0.681718f, -0.147621f }, - { 0.688191f, -0.587785f, -0.425325f }, { 0.587785f, -0.425325f, -0.688191f }, - { 0.000000f, -0.955423f, -0.295242f }, { 0.000000f, -1.000000f, 0.000000f }, - { 0.262866f, -0.951056f, -0.162460f }, { 0.000000f, -0.850651f, 0.525731f }, - { 0.000000f, -0.955423f, 0.295242f }, { 0.238856f, -0.864188f, 0.442863f }, - { 0.262866f, -0.951056f, 0.162460f }, { 0.500000f, -0.809017f, 0.309017f }, - { 0.716567f, -0.681718f, 0.147621f }, { 0.525731f, -0.850651f, 0.000000f }, - { -0.238856f, -0.864188f, -0.442863f }, { -0.500000f, -0.809017f, -0.309017f }, - { -0.262866f, -0.951056f, -0.162460f }, { -0.850651f, -0.525731f, 0.000000f }, - { -0.716567f, -0.681718f, -0.147621f }, { -0.716567f, -0.681718f, 0.147621f }, - { -0.525731f, -0.850651f, 0.000000f }, { -0.500000f, -0.809017f, 0.309017f }, - { -0.238856f, -0.864188f, 0.442863f }, { -0.262866f, -0.951056f, 0.162460f }, - { -0.864188f, -0.442863f, 0.238856f }, { -0.809017f, -0.309017f, 0.500000f }, - { -0.688191f, -0.587785f, 0.425325f }, { -0.681718f, -0.147621f, 0.716567f }, - { -0.442863f, -0.238856f, 0.864188f }, { -0.587785f, -0.425325f, 0.688191f }, - { -0.309017f, -0.500000f, 0.809017f }, { -0.147621f, -0.716567f, 0.681718f }, - { -0.425325f, -0.688191f, 0.587785f }, { -0.162460f, -0.262866f, 0.951056f }, - { 0.442863f, -0.238856f, 0.864188f }, { 0.162460f, -0.262866f, 0.951056f }, - { 0.309017f, -0.500000f, 0.809017f }, { 0.147621f, -0.716567f, 0.681718f }, - { 0.000000f, -0.525731f, 0.850651f }, { 0.425325f, -0.688191f, 0.587785f }, - { 0.587785f, -0.425325f, 0.688191f }, { 0.688191f, -0.587785f, 0.425325f }, - { -0.955423f, 0.295242f, 0.000000f }, { -0.951056f, 0.162460f, 0.262866f }, - { -1.000000f, 0.000000f, 0.000000f }, { -0.850651f, 0.000000f, 0.525731f }, - { -0.955423f, -0.295242f, 0.000000f }, { -0.951056f, -0.162460f, 0.262866f }, - { -0.864188f, 0.442863f, -0.238856f }, { -0.951056f, 0.162460f, -0.262866f }, - { -0.809017f, 0.309017f, -0.500000f }, { -0.864188f, -0.442863f, -0.238856f }, - { -0.951056f, -0.162460f, -0.262866f }, { -0.809017f, -0.309017f, -0.500000f }, - { -0.681718f, 0.147621f, -0.716567f }, { -0.681718f, -0.147621f, -0.716567f }, - { -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 } }; diff --git a/plugins/native/module/vtkF3DQuakeMDLImporterConstants.h b/plugins/native/module/vtkF3DQuakeMDLImporterConstants.h index befa221430..eb99722185 100644 --- a/plugins/native/module/vtkF3DQuakeMDLImporterConstants.h +++ b/plugins/native/module/vtkF3DQuakeMDLImporterConstants.h @@ -1,7 +1,134 @@ #ifndef vtkF3DQuakeMDLImporterConstants_h #define vtkF3DQuakeMDLImporterConstants_h -extern const unsigned char F3DMDLDefaultColorMap[256][3]; -extern const float F3DMDLNormalVectors[162][3]; +constexpr unsigned char F3DMDLDefaultColorMap[256][3] = { { 0, 0, 0 }, { 15, 15, 15 }, + { 31, 31, 31 }, { 47, 47, 47 }, { 63, 63, 63 }, { 75, 75, 75 }, { 91, 91, 91 }, { 107, 107, 107 }, + { 123, 123, 123 }, { 139, 139, 139 }, { 155, 155, 155 }, { 171, 171, 171 }, { 187, 187, 187 }, + { 203, 203, 203 }, { 219, 219, 219 }, { 235, 235, 235 }, { 15, 11, 7 }, { 23, 15, 11 }, + { 31, 23, 11 }, { 39, 27, 15 }, { 47, 35, 19 }, { 55, 43, 23 }, { 63, 47, 23 }, { 75, 55, 27 }, + { 83, 59, 27 }, { 91, 67, 31 }, { 99, 75, 31 }, { 107, 83, 31 }, { 115, 87, 31 }, { 123, 95, 35 }, + { 131, 103, 35 }, { 143, 111, 35 }, { 11, 11, 15 }, { 19, 19, 27 }, { 27, 27, 39 }, + { 39, 39, 51 }, { 47, 47, 63 }, { 55, 55, 75 }, { 63, 63, 87 }, { 71, 71, 103 }, { 79, 79, 115 }, + { 91, 91, 127 }, { 99, 99, 139 }, { 107, 107, 151 }, { 115, 115, 163 }, { 123, 123, 175 }, + { 131, 131, 187 }, { 139, 139, 203 }, { 0, 0, 0 }, { 7, 7, 0 }, { 11, 11, 0 }, { 19, 19, 0 }, + { 27, 27, 0 }, { 35, 35, 0 }, { 43, 43, 7 }, { 47, 47, 7 }, { 55, 55, 7 }, { 63, 63, 7 }, + { 71, 71, 7 }, { 75, 75, 11 }, { 83, 83, 11 }, { 91, 91, 11 }, { 99, 99, 11 }, { 107, 107, 15 }, + { 7, 0, 0 }, { 15, 0, 0 }, { 23, 0, 0 }, { 31, 0, 0 }, { 39, 0, 0 }, { 47, 0, 0 }, { 55, 0, 0 }, + { 63, 0, 0 }, { 71, 0, 0 }, { 79, 0, 0 }, { 87, 0, 0 }, { 95, 0, 0 }, { 103, 0, 0 }, + { 111, 0, 0 }, { 119, 0, 0 }, { 127, 0, 0 }, { 19, 19, 0 }, { 27, 27, 0 }, { 35, 35, 0 }, + { 47, 43, 0 }, { 55, 47, 0 }, { 67, 55, 0 }, { 75, 59, 7 }, { 87, 67, 7 }, { 95, 71, 7 }, + { 107, 75, 11 }, { 119, 83, 15 }, { 131, 87, 19 }, { 139, 91, 19 }, { 151, 95, 27 }, + { 163, 99, 31 }, { 175, 103, 35 }, { 35, 19, 7 }, { 47, 23, 11 }, { 59, 31, 15 }, { 75, 35, 19 }, + { 87, 43, 23 }, { 99, 47, 31 }, { 115, 55, 35 }, { 127, 59, 43 }, { 143, 67, 51 }, + { 159, 79, 51 }, { 175, 99, 47 }, { 191, 119, 47 }, { 207, 143, 43 }, { 223, 171, 39 }, + { 239, 203, 31 }, { 255, 243, 27 }, { 11, 7, 0 }, { 27, 19, 0 }, { 43, 35, 15 }, { 55, 43, 19 }, + { 71, 51, 27 }, { 83, 55, 35 }, { 99, 63, 43 }, { 111, 71, 51 }, { 127, 83, 63 }, { 139, 95, 71 }, + { 155, 107, 83 }, { 167, 123, 95 }, { 183, 135, 107 }, { 195, 147, 123 }, { 211, 163, 139 }, + { 227, 179, 151 }, { 171, 139, 163 }, { 159, 127, 151 }, { 147, 115, 135 }, { 139, 103, 123 }, + { 127, 91, 111 }, { 119, 83, 99 }, { 107, 75, 87 }, { 95, 63, 75 }, { 87, 55, 67 }, + { 75, 47, 55 }, { 67, 39, 47 }, { 55, 31, 35 }, { 43, 23, 27 }, { 35, 19, 19 }, { 23, 11, 11 }, + { 15, 7, 7 }, { 187, 115, 159 }, { 175, 107, 143 }, { 163, 95, 131 }, { 151, 87, 119 }, + { 139, 79, 107 }, { 127, 75, 95 }, { 115, 67, 83 }, { 107, 59, 75 }, { 95, 51, 63 }, + { 83, 43, 55 }, { 71, 35, 43 }, { 59, 31, 35 }, { 47, 23, 27 }, { 35, 19, 19 }, { 23, 11, 11 }, + { 15, 7, 7 }, { 219, 195, 187 }, { 203, 179, 167 }, { 191, 163, 155 }, { 175, 151, 139 }, + { 163, 135, 123 }, { 151, 123, 111 }, { 135, 111, 95 }, { 123, 99, 83 }, { 107, 87, 71 }, + { 95, 75, 59 }, { 83, 63, 51 }, { 67, 51, 39 }, { 55, 43, 31 }, { 39, 31, 23 }, { 27, 19, 15 }, + { 15, 11, 7 }, { 111, 131, 123 }, { 103, 123, 111 }, { 95, 115, 103 }, { 87, 107, 95 }, + { 79, 99, 87 }, { 71, 91, 79 }, { 63, 83, 71 }, { 55, 75, 63 }, { 47, 67, 55 }, { 43, 59, 47 }, + { 35, 51, 39 }, { 31, 43, 31 }, { 23, 35, 23 }, { 15, 27, 19 }, { 11, 19, 11 }, { 7, 11, 7 }, + { 255, 243, 27 }, { 239, 223, 23 }, { 219, 203, 19 }, { 203, 183, 15 }, { 187, 167, 15 }, + { 171, 151, 11 }, { 155, 131, 7 }, { 139, 115, 7 }, { 123, 99, 7 }, { 107, 83, 0 }, { 91, 71, 0 }, + { 75, 55, 0 }, { 59, 43, 0 }, { 43, 31, 0 }, { 27, 15, 0 }, { 11, 7, 0 }, { 0, 0, 255 }, + { 11, 11, 239 }, { 19, 19, 223 }, { 27, 27, 207 }, { 35, 35, 191 }, { 43, 43, 175 }, + { 47, 47, 159 }, { 47, 47, 143 }, { 47, 47, 127 }, { 47, 47, 111 }, { 47, 47, 95 }, + { 43, 43, 79 }, { 35, 35, 63 }, { 27, 27, 47 }, { 19, 19, 31 }, { 11, 11, 15 }, { 43, 0, 0 }, + { 59, 0, 0 }, { 75, 7, 0 }, { 95, 7, 0 }, { 111, 15, 0 }, { 127, 23, 7 }, { 147, 31, 7 }, + { 163, 39, 11 }, { 183, 51, 15 }, { 195, 75, 27 }, { 207, 99, 43 }, { 219, 127, 59 }, + { 227, 151, 79 }, { 231, 171, 95 }, { 239, 191, 119 }, { 247, 211, 139 }, { 167, 123, 59 }, + { 183, 155, 55 }, { 199, 195, 55 }, { 231, 227, 87 }, { 127, 191, 255 }, { 171, 231, 255 }, + { 215, 255, 255 }, { 103, 0, 0 }, { 139, 0, 0 }, { 179, 0, 0 }, { 215, 0, 0 }, { 255, 0, 0 }, + { 255, 243, 147 }, { 255, 247, 199 }, { 255, 255, 255 }, { 159, 91, 83 } }; +constexpr float F3DMDLNormalVectors[162][3] = { { -0.525731f, 0.000000f, 0.850651f }, + { -0.442863f, 0.238856f, 0.864188f }, { -0.295242f, 0.000000f, 0.955423f }, + { -0.309017f, 0.500000f, 0.809017f }, { -0.162460f, 0.262866f, 0.951056f }, + { 0.000000f, 0.000000f, 1.000000f }, { 0.000000f, 0.850651f, 0.525731f }, + { -0.147621f, 0.716567f, 0.681718f }, { 0.147621f, 0.716567f, 0.681718f }, + { 0.000000f, 0.525731f, 0.850651f }, { 0.309017f, 0.500000f, 0.809017f }, + { 0.525731f, 0.000000f, 0.850651f }, { 0.295242f, 0.000000f, 0.955423f }, + { 0.442863f, 0.238856f, 0.864188f }, { 0.162460f, 0.262866f, 0.951056f }, + { -0.681718f, 0.147621f, 0.716567f }, { -0.809017f, 0.309017f, 0.500000f }, + { -0.587785f, 0.425325f, 0.688191f }, { -0.850651f, 0.525731f, 0.000000f }, + { -0.864188f, 0.442863f, 0.238856f }, { -0.716567f, 0.681718f, 0.147621f }, + { -0.688191f, 0.587785f, 0.425325f }, { -0.500000f, 0.809017f, 0.309017f }, + { -0.238856f, 0.864188f, 0.442863f }, { -0.425325f, 0.688191f, 0.587785f }, + { -0.716567f, 0.681718f, -0.147621f }, { -0.500000f, 0.809017f, -0.309017f }, + { -0.525731f, 0.850651f, 0.000000f }, { 0.000000f, 0.850651f, -0.525731f }, + { -0.238856f, 0.864188f, -0.442863f }, { 0.000000f, 0.955423f, -0.295242f }, + { -0.262866f, 0.951056f, -0.162460f }, { 0.000000f, 1.000000f, 0.000000f }, + { 0.000000f, 0.955423f, 0.295242f }, { -0.262866f, 0.951056f, 0.162460f }, + { 0.238856f, 0.864188f, 0.442863f }, { 0.262866f, 0.951056f, 0.162460f }, + { 0.500000f, 0.809017f, 0.309017f }, { 0.238856f, 0.864188f, -0.442863f }, + { 0.262866f, 0.951056f, -0.162460f }, { 0.500000f, 0.809017f, -0.309017f }, + { 0.850651f, 0.525731f, 0.000000f }, { 0.716567f, 0.681718f, 0.147621f }, + { 0.716567f, 0.681718f, -0.147621f }, { 0.525731f, 0.850651f, 0.000000f }, + { 0.425325f, 0.688191f, 0.587785f }, { 0.864188f, 0.442863f, 0.238856f }, + { 0.688191f, 0.587785f, 0.425325f }, { 0.809017f, 0.309017f, 0.500000f }, + { 0.681718f, 0.147621f, 0.716567f }, { 0.587785f, 0.425325f, 0.688191f }, + { 0.955423f, 0.295242f, 0.000000f }, { 1.000000f, 0.000000f, 0.000000f }, + { 0.951056f, 0.162460f, 0.262866f }, { 0.850651f, -0.525731f, 0.000000f }, + { 0.955423f, -0.295242f, 0.000000f }, { 0.864188f, -0.442863f, 0.238856f }, + { 0.951056f, -0.162460f, 0.262866f }, { 0.809017f, -0.309017f, 0.500000f }, + { 0.681718f, -0.147621f, 0.716567f }, { 0.850651f, 0.000000f, 0.525731f }, + { 0.864188f, 0.442863f, -0.238856f }, { 0.809017f, 0.309017f, -0.500000f }, + { 0.951056f, 0.162460f, -0.262866f }, { 0.525731f, 0.000000f, -0.850651f }, + { 0.681718f, 0.147621f, -0.716567f }, { 0.681718f, -0.147621f, -0.716567f }, + { 0.850651f, 0.000000f, -0.525731f }, { 0.809017f, -0.309017f, -0.500000f }, + { 0.864188f, -0.442863f, -0.238856f }, { 0.951056f, -0.162460f, -0.262866f }, + { 0.147621f, 0.716567f, -0.681718f }, { 0.309017f, 0.500000f, -0.809017f }, + { 0.425325f, 0.688191f, -0.587785f }, { 0.442863f, 0.238856f, -0.864188f }, + { 0.587785f, 0.425325f, -0.688191f }, { 0.688191f, 0.587785f, -0.425325f }, + { -0.147621f, 0.716567f, -0.681718f }, { -0.309017f, 0.500000f, -0.809017f }, + { 0.000000f, 0.525731f, -0.850651f }, { -0.525731f, 0.000000f, -0.850651f }, + { -0.442863f, 0.238856f, -0.864188f }, { -0.295242f, 0.000000f, -0.955423f }, + { -0.162460f, 0.262866f, -0.951056f }, { 0.000000f, 0.000000f, -1.000000f }, + { 0.295242f, 0.000000f, -0.955423f }, { 0.162460f, 0.262866f, -0.951056f }, + { -0.442863f, -0.238856f, -0.864188f }, { -0.309017f, -0.500000f, -0.809017f }, + { -0.162460f, -0.262866f, -0.951056f }, { 0.000000f, -0.850651f, -0.525731f }, + { -0.147621f, -0.716567f, -0.681718f }, { 0.147621f, -0.716567f, -0.681718f }, + { 0.000000f, -0.525731f, -0.850651f }, { 0.309017f, -0.500000f, -0.809017f }, + { 0.442863f, -0.238856f, -0.864188f }, { 0.162460f, -0.262866f, -0.951056f }, + { 0.238856f, -0.864188f, -0.442863f }, { 0.500000f, -0.809017f, -0.309017f }, + { 0.425325f, -0.688191f, -0.587785f }, { 0.716567f, -0.681718f, -0.147621f }, + { 0.688191f, -0.587785f, -0.425325f }, { 0.587785f, -0.425325f, -0.688191f }, + { 0.000000f, -0.955423f, -0.295242f }, { 0.000000f, -1.000000f, 0.000000f }, + { 0.262866f, -0.951056f, -0.162460f }, { 0.000000f, -0.850651f, 0.525731f }, + { 0.000000f, -0.955423f, 0.295242f }, { 0.238856f, -0.864188f, 0.442863f }, + { 0.262866f, -0.951056f, 0.162460f }, { 0.500000f, -0.809017f, 0.309017f }, + { 0.716567f, -0.681718f, 0.147621f }, { 0.525731f, -0.850651f, 0.000000f }, + { -0.238856f, -0.864188f, -0.442863f }, { -0.500000f, -0.809017f, -0.309017f }, + { -0.262866f, -0.951056f, -0.162460f }, { -0.850651f, -0.525731f, 0.000000f }, + { -0.716567f, -0.681718f, -0.147621f }, { -0.716567f, -0.681718f, 0.147621f }, + { -0.525731f, -0.850651f, 0.000000f }, { -0.500000f, -0.809017f, 0.309017f }, + { -0.238856f, -0.864188f, 0.442863f }, { -0.262866f, -0.951056f, 0.162460f }, + { -0.864188f, -0.442863f, 0.238856f }, { -0.809017f, -0.309017f, 0.500000f }, + { -0.688191f, -0.587785f, 0.425325f }, { -0.681718f, -0.147621f, 0.716567f }, + { -0.442863f, -0.238856f, 0.864188f }, { -0.587785f, -0.425325f, 0.688191f }, + { -0.309017f, -0.500000f, 0.809017f }, { -0.147621f, -0.716567f, 0.681718f }, + { -0.425325f, -0.688191f, 0.587785f }, { -0.162460f, -0.262866f, 0.951056f }, + { 0.442863f, -0.238856f, 0.864188f }, { 0.162460f, -0.262866f, 0.951056f }, + { 0.309017f, -0.500000f, 0.809017f }, { 0.147621f, -0.716567f, 0.681718f }, + { 0.000000f, -0.525731f, 0.850651f }, { 0.425325f, -0.688191f, 0.587785f }, + { 0.587785f, -0.425325f, 0.688191f }, { 0.688191f, -0.587785f, 0.425325f }, + { -0.955423f, 0.295242f, 0.000000f }, { -0.951056f, 0.162460f, 0.262866f }, + { -1.000000f, 0.000000f, 0.000000f }, { -0.850651f, 0.000000f, 0.525731f }, + { -0.955423f, -0.295242f, 0.000000f }, { -0.951056f, -0.162460f, 0.262866f }, + { -0.864188f, 0.442863f, -0.238856f }, { -0.951056f, 0.162460f, -0.262866f }, + { -0.809017f, 0.309017f, -0.500000f }, { -0.864188f, -0.442863f, -0.238856f }, + { -0.951056f, -0.162460f, -0.262866f }, { -0.809017f, -0.309017f, -0.500000f }, + { -0.681718f, 0.147621f, -0.716567f }, { -0.681718f, -0.147621f, -0.716567f }, + { -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 } }; #endif diff --git a/testing/data/glaunch_2.mdl b/testing/data/glaunch_2.mdl index 8006f9515f..c627ec08bb 100644 --- a/testing/data/glaunch_2.mdl +++ b/testing/data/glaunch_2.mdl @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:a61ddbaeb423a837d9430164394296ae561f5401e1bb93819d5a496d4248c22b -size 86312 +oid sha256:8187ee0045b2a170c4abab74cbe4f8b9cccac1f9c404dd5098f5f65ea8ef9a58 +size 86316 From 3b6d59acc3ad53a126204d8b359f84db83a13edf Mon Sep 17 00:00:00 2001 From: Youva Boutora <48061964+Youva@users.noreply.github.com> Date: Sat, 21 Dec 2024 17:20:00 -0500 Subject: [PATCH 53/60] Added license --- testing/data/DATA_LICENSES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/testing/data/DATA_LICENSES.md b/testing/data/DATA_LICENSES.md index 91cacf8c0e..851ca20010 100644 --- a/testing/data/DATA_LICENSES.md +++ b/testing/data/DATA_LICENSES.md @@ -27,6 +27,7 @@ - duck.fbx: assimp test models: BSD-3-Clause - Duck0.bin: Copyright 2006 Sony Computer Entertainment Inc.: SCEA Shared Source License - duck_invalid.gltf: Copyright 2006 Sony Computer Entertainment Inc.: SCEA Shared Source License +- glaunch*.mdl : Preach: CC-BY-NC 4.0 - HeadMRVolume*: VTK Data: BSD-3-Clause - icosahedron.vdb: OpenVDB: [MPL-2.0](http://www.mozilla.org/MPL/2.0/) - iflamigm.3ds: VTK Data: BSD-3-Clause From 60c64d92c23d4206a0cd9612e8e25c23f6155dcb Mon Sep 17 00:00:00 2001 From: Youva Boutora <48061964+Youva@users.noreply.github.com> Date: Sat, 4 Jan 2025 14:17:57 -0500 Subject: [PATCH 54/60] Test coverage for animations --- application/testing/CMakeLists.txt | 2 +- plugins/native/CMakeLists.txt | 2 -- plugins/native/module/vtkF3DQuakeMDLImporter.cxx | 8 ++++---- plugins/native/module/vtkF3DQuakeMDLImporter.h | 1 + 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/application/testing/CMakeLists.txt b/application/testing/CMakeLists.txt index 55a3eb646c..3354bf9b38 100644 --- a/application/testing/CMakeLists.txt +++ b/application/testing/CMakeLists.txt @@ -150,7 +150,7 @@ f3d_test(NAME TestVTM DATA mb.vtm UI) f3d_test(NAME TestVTK DATA cow.vtk) f3d_test(NAME TestNRRD DATA beach.nrrd ARGS -s) f3d_test(NAME TestSPLAT DATA small.splat ARGS -osy --up=-Y --point-sprites-size=1) -f3d_test(NAME TestQuakeMDL DATA glaunch.mdl) +f3d_test(NAME TestQuakeMDL DATA glaunch.mdl ARGS --animation-index=1 --animation-autoplay=true) 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) diff --git a/plugins/native/CMakeLists.txt b/plugins/native/CMakeLists.txt index e1829b6278..9a6b83e6c3 100644 --- a/plugins/native/CMakeLists.txt +++ b/plugins/native/CMakeLists.txt @@ -176,7 +176,6 @@ f3d_plugin_declare_reader( FORMAT_DESCRIPTION "VTK XML MultiBlock" ) - f3d_plugin_declare_reader( NAME Splat SCORE 90 @@ -194,7 +193,6 @@ f3d_plugin_declare_reader( FORMAT_DESCRIPTION "Quake 1 MDL model" ) - f3d_plugin_build( NAME native VERSION 1.0 diff --git a/plugins/native/module/vtkF3DQuakeMDLImporter.cxx b/plugins/native/module/vtkF3DQuakeMDLImporter.cxx index dfa9c20639..2f56185a30 100644 --- a/plugins/native/module/vtkF3DQuakeMDLImporter.cxx +++ b/plugins/native/module/vtkF3DQuakeMDLImporter.cxx @@ -246,9 +246,9 @@ class vtkF3DQuakeMDLImporter::vtkInternals for (int j = 0; j < 3; j++) { vertexNum[j] = triangles[i].vertex[j]; - double xyz[3] = { double(selectedSimpleFrame->verts[vertexNum[j]].xyz[0]), - double(selectedSimpleFrame->verts[vertexNum[j]].xyz[1]), - double(selectedSimpleFrame->verts[vertexNum[j]].xyz[2]) }; + double xyz[3] = { static_cast(selectedSimpleFrame->verts[vertexNum[j]].xyz[0]), + static_cast(selectedSimpleFrame->verts[vertexNum[j]].xyz[1]), + static_cast(selectedSimpleFrame->verts[vertexNum[j]].xyz[2]) }; // Calculate real vertex position for (int k = 0; k < 3; k++) { @@ -453,7 +453,7 @@ class vtkF3DQuakeMDLImporter::vtkInternals //---------------------------------------------------------------------------- vtkF3DQuakeMDLImporter::vtkF3DQuakeMDLImporter() - : Internals(new vtkF3DQuakeMDLImporter::vtkInternals(this)) { + : Internals(new vtkF3DQuakeMDLImporter::vtkInternals(this)){ }; diff --git a/plugins/native/module/vtkF3DQuakeMDLImporter.h b/plugins/native/module/vtkF3DQuakeMDLImporter.h index 2ab2b1871c..4abd538aef 100644 --- a/plugins/native/module/vtkF3DQuakeMDLImporter.h +++ b/plugins/native/module/vtkF3DQuakeMDLImporter.h @@ -9,6 +9,7 @@ #ifndef vtkF3DQuakeMDLImporter_h #define vtkF3DQuakeMDLImporter_h + #include class vtkF3DQuakeMDLImporter : public vtkF3DImporter From f26d21a276dbefb7aa06c104a86145eb79a80d89 Mon Sep 17 00:00:00 2001 From: Youva Boutora <48061964+Youva@users.noreply.github.com> Date: Sat, 4 Jan 2025 15:52:02 -0500 Subject: [PATCH 55/60] Coverage for animations. --- application/testing/CMakeLists.txt | 2 +- testing/baselines/TestQuakeMDL.png | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/application/testing/CMakeLists.txt b/application/testing/CMakeLists.txt index 3354bf9b38..ceff086c3d 100644 --- a/application/testing/CMakeLists.txt +++ b/application/testing/CMakeLists.txt @@ -150,7 +150,7 @@ f3d_test(NAME TestVTM DATA mb.vtm UI) f3d_test(NAME TestVTK DATA cow.vtk) f3d_test(NAME TestNRRD DATA beach.nrrd ARGS -s) f3d_test(NAME TestSPLAT DATA small.splat ARGS -osy --up=-Y --point-sprites-size=1) -f3d_test(NAME TestQuakeMDL DATA glaunch.mdl ARGS --animation-index=1 --animation-autoplay=true) +f3d_test(NAME TestQuakeMDL DATA glaunch.mdl ARGS --animation-index=1 --animation-autoplay=true --animation-time=0.5) 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) diff --git a/testing/baselines/TestQuakeMDL.png b/testing/baselines/TestQuakeMDL.png index f9f4b68abb..f561c8667b 100644 --- a/testing/baselines/TestQuakeMDL.png +++ b/testing/baselines/TestQuakeMDL.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:553d64ee1a25a62af96a2dd8f49715dd57533bf42a3c02afc4cbe22efeba644c -size 25522 +oid sha256:2543a4ffb2b14c05385eaf1af83fd995f24c7fa06539b97df336008e60ce0b38 +size 27612 From 32bff66fde41af65b3dfa6c6079ab44db68fd9ea Mon Sep 17 00:00:00 2001 From: Youva Boutora <48061964+Youva@users.noreply.github.com> Date: Sat, 4 Jan 2025 17:48:38 -0500 Subject: [PATCH 56/60] Added coverage --- testing/data/glaunch_2.mdl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/data/glaunch_2.mdl b/testing/data/glaunch_2.mdl index c627ec08bb..86e2a6b7d9 100644 --- a/testing/data/glaunch_2.mdl +++ b/testing/data/glaunch_2.mdl @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:8187ee0045b2a170c4abab74cbe4f8b9cccac1f9c404dd5098f5f65ea8ef9a58 +oid sha256:05e57067fed28f97bdedbe5068fa418d678c7fa0260cf453cdcec2c3deb96ef4 size 86316 From e935a120521611ad249de1ef587a745fc381574a Mon Sep 17 00:00:00 2001 From: Youva Boutora <48061964+Youva@users.noreply.github.com> Date: Sat, 4 Jan 2025 18:25:18 -0500 Subject: [PATCH 57/60] Update TestQuakeMDL.png --- testing/baselines/TestQuakeMDL.png | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testing/baselines/TestQuakeMDL.png b/testing/baselines/TestQuakeMDL.png index f561c8667b..be23b5c407 100644 --- a/testing/baselines/TestQuakeMDL.png +++ b/testing/baselines/TestQuakeMDL.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:2543a4ffb2b14c05385eaf1af83fd995f24c7fa06539b97df336008e60ce0b38 -size 27612 +oid sha256:290dcfe0861f9a3bddf80c6738b1f05c77b8c0ecbb37c2ac4af9cda854cbb059 +size 25055 From 07cbe8c2d11c37fd571683a01374676b9140ce34 Mon Sep 17 00:00:00 2001 From: Youva Boutora <48061964+Youva@users.noreply.github.com> Date: Sat, 4 Jan 2025 18:29:07 -0500 Subject: [PATCH 58/60] Changed animation time --- application/testing/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/testing/CMakeLists.txt b/application/testing/CMakeLists.txt index ceff086c3d..fd99fe217f 100644 --- a/application/testing/CMakeLists.txt +++ b/application/testing/CMakeLists.txt @@ -150,7 +150,7 @@ f3d_test(NAME TestVTM DATA mb.vtm UI) f3d_test(NAME TestVTK DATA cow.vtk) f3d_test(NAME TestNRRD DATA beach.nrrd ARGS -s) f3d_test(NAME TestSPLAT DATA small.splat ARGS -osy --up=-Y --point-sprites-size=1) -f3d_test(NAME TestQuakeMDL DATA glaunch.mdl ARGS --animation-index=1 --animation-autoplay=true --animation-time=0.5) +f3d_test(NAME TestQuakeMDL DATA glaunch.mdl ARGS --animation-index=1 --animation-autoplay=true --animation-time=0.1) 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) From 825a55ad45bf5a2d2d887cfb018af1e651b5c3f1 Mon Sep 17 00:00:00 2001 From: Youva Boutora <48061964+Youva@users.noreply.github.com> Date: Sat, 4 Jan 2025 21:22:31 -0500 Subject: [PATCH 59/60] Added UpdateAtTimeValue --- plugins/native/module/vtkF3DQuakeMDLImporter.cxx | 8 ++++++++ plugins/native/module/vtkF3DQuakeMDLImporter.h | 1 + 2 files changed, 9 insertions(+) diff --git a/plugins/native/module/vtkF3DQuakeMDLImporter.cxx b/plugins/native/module/vtkF3DQuakeMDLImporter.cxx index 2f56185a30..00c46c01db 100644 --- a/plugins/native/module/vtkF3DQuakeMDLImporter.cxx +++ b/plugins/native/module/vtkF3DQuakeMDLImporter.cxx @@ -481,6 +481,14 @@ void vtkF3DQuakeMDLImporter::UpdateTimeStep(double timeValue) return this->Internals->UpdateTimeStep(timeValue); } +//---------------------------------------------------------------------------- +bool vtkF3DQuakeMDLImporter::UpdateAtTimeValue(double timeValue) +{ + this->Internals->UpdateTimeStep(timeValue); + return timeValue <= this->Internals->FrameRate * this->Internals->AnimationIds.size(); +} + + //---------------------------------------------------------------------------- vtkIdType vtkF3DQuakeMDLImporter::GetNumberOfAnimations() { diff --git a/plugins/native/module/vtkF3DQuakeMDLImporter.h b/plugins/native/module/vtkF3DQuakeMDLImporter.h index 4abd538aef..78d6ac7802 100644 --- a/plugins/native/module/vtkF3DQuakeMDLImporter.h +++ b/plugins/native/module/vtkF3DQuakeMDLImporter.h @@ -26,6 +26,7 @@ class vtkF3DQuakeMDLImporter : public vtkF3DImporter * Update actors at the given time value. */ void UpdateTimeStep(double timeValue) override; + bool UpdateAtTimeValue(double timeValue) override; /** * Get the number of available animations. From 1e3f44ac34d56bdfb5cdd785528ec86ba17dd313 Mon Sep 17 00:00:00 2001 From: Youva Boutora <48061964+Youva@users.noreply.github.com> Date: Sun, 5 Jan 2025 09:00:30 -0500 Subject: [PATCH 60/60] Formatting --- plugins/native/module/vtkF3DQuakeMDLImporter.cxx | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/native/module/vtkF3DQuakeMDLImporter.cxx b/plugins/native/module/vtkF3DQuakeMDLImporter.cxx index 00c46c01db..e090e5c3b5 100644 --- a/plugins/native/module/vtkF3DQuakeMDLImporter.cxx +++ b/plugins/native/module/vtkF3DQuakeMDLImporter.cxx @@ -488,7 +488,6 @@ bool vtkF3DQuakeMDLImporter::UpdateAtTimeValue(double timeValue) return timeValue <= this->Internals->FrameRate * this->Internals->AnimationIds.size(); } - //---------------------------------------------------------------------------- vtkIdType vtkF3DQuakeMDLImporter::GetNumberOfAnimations() {