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..15ff7d4a70 --- /dev/null +++ b/plugins/native/module/vtkQuakeMDLReader.cxx @@ -0,0 +1,135 @@ +#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 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