-
-
Notifications
You must be signed in to change notification settings - Fork 204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding preliminary Quake1 MDL plugin. #1441
base: master
Are you sure you want to change the base?
Changes from 4 commits
9d96975
31e502a
614385b
802a5ef
bccc126
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
set(classes | ||
vtkF3DSplatReader | ||
vtkQuakeMDLReader | ||
) | ||
|
||
set(_no_install "") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
#include "vtkQuakeMDLReader.h" | ||
|
||
#include <vtkCellArray.h> | ||
#include <vtkCellData.h> | ||
#include <vtkCommand.h> | ||
#include <vtkDemandDrivenPipeline.h> | ||
#include <vtkFloatArray.h> | ||
#include <vtkIdTypeArray.h> | ||
#include <vtkInformation.h> | ||
#include <vtkInformationVector.h> | ||
#include <vtkNew.h> | ||
#include <vtkPointData.h> | ||
#include <vtkPoints.h> | ||
#include <vtkPolyData.h> | ||
#include <vtkUnsignedCharArray.h> | ||
|
||
//---------------------------------------------------------------------------- | ||
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<unsigned char> buffer(std::istreambuf_iterator<char>(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<vtkUnsignedCharArray> IDPOArray; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So you don't really need to create VTK arrays for internal data, it's only useful for data that will be outputted down the pipeline. |
||
IDPOArray->SetNumberOfComponents(4); | ||
IDPOArray->SetNumberOfTuples(nbSplats); | ||
IDPOArray->SetName("identity"); | ||
|
||
// version: 1 int (4 bytes) | ||
vtkNew<vtkIntArray> version; | ||
version->SetNumberOfComponents(1); | ||
version->SetNumberOfTuples(nbSplats); | ||
version->SetName("version"); | ||
|
||
//==================================== | ||
|
||
// scaling factor: 3 floats (12 bytes) | ||
vtkNew<vtkFloatArray> scalingFactor; | ||
scalingFactor->SetNumberOfComponents(3); | ||
scalingFactor->SetNumberOfTuples(nbSplats); | ||
scalingFactor->SetName("scaling factor"); | ||
|
||
// translation vector: 3 floats (12 bytes) | ||
vtkNew<vtkFloatArray> translationVector; | ||
translationVector->SetNumberOfComponents(3); | ||
translationVector->SetNumberOfTuples(nbSplats); | ||
translationVector->SetName("translation vector"); | ||
|
||
// bounding radius: 1 float (4 bytes) | ||
vtkNew<vtkFloatArray> boundingRadius; | ||
boundingRadius->SetNumberOfComponents(1); | ||
boundingRadius->SetNumberOfTuples(nbSplats); | ||
boundingRadius->SetName("bounding radius"); | ||
|
||
// eye position: 3 floats (12 bytes) | ||
vtkNew<vtkFloatArray> eyePosition; | ||
eyePosition->SetNumberOfComponents(3); | ||
eyePosition->SetNumberOfTuples(nbSplats); | ||
eyePosition->SetName("eye position"); | ||
|
||
//==================================== | ||
|
||
// number of textures: 1 int (4 bytes) | ||
vtkNew<vtkIntArray> texturesNum; | ||
texturesNum->SetNumberOfComponents(1); | ||
texturesNum->SetNumberOfTuples(nbSplats); | ||
texturesNum->SetName("number of textures"); | ||
|
||
// texture width: 1 int (4 bytes) | ||
vtkNew<vtkIntArray> textureWidth; | ||
textureWidth->SetNumberOfComponents(1); | ||
textureWidth->SetNumberOfTuples(nbSplats); | ||
textureWidth->SetName("texture width"); | ||
|
||
// texture height: 1 int (4 bytes) | ||
vtkNew<vtkIntArray> textureHeight; | ||
textureHeight->SetNumberOfComponents(1); | ||
textureHeight->SetNumberOfTuples(nbSplats); | ||
textureHeight->SetName("texture height"); | ||
|
||
//==================================== | ||
|
||
// number of vertices: 1 int (4 bytes) | ||
vtkNew<vtkIntArray> verticesNum; | ||
verticesNum->SetNumberOfComponents(1); | ||
verticesNum->SetNumberOfTuples(nbSplats); | ||
verticesNum->SetName("number of vertices"); | ||
|
||
// number of triangles: 1 int (4 bytes) | ||
vtkNew<vtkIntArray> trianglesNum; | ||
trianglesNum->SetNumberOfComponents(1); | ||
trianglesNum->SetNumberOfTuples(nbSplats); | ||
trianglesNum->SetName("number of triangles"); | ||
|
||
// number of frames: 1 int (4 bytes) | ||
vtkNew<vtkIntArray> framesNum; | ||
framesNum->SetNumberOfComponents(1); | ||
framesNum->SetNumberOfTuples(nbSplats); | ||
framesNum->SetName("number of frames"); | ||
|
||
//==================================== | ||
|
||
// sync type (0: synchron, 1: random): 1 int (4 bytes) | ||
vtkNew<vtkIntArray> syncType; | ||
syncType->SetNumberOfComponents(1); | ||
syncType->SetNumberOfTuples(nbSplats); | ||
syncType->SetName("sync type"); | ||
|
||
// state flags: 1 int (4 bytes) | ||
vtkNew<vtkIntArray> stateFlags; | ||
stateFlags->SetNumberOfComponents(1); | ||
stateFlags->SetNumberOfTuples(nbSplats); | ||
stateFlags->SetName("state flags"); | ||
|
||
//==================================== | ||
|
||
// position: 3 floats (12 bytes) | ||
vtkNew<vtkFloatArray> position; | ||
position->SetNumberOfComponents(3); | ||
position->SetNumberOfTuples(nbSplats); | ||
position->SetName("position"); | ||
|
||
// scale: 3 floats (12 bytes) | ||
vtkNew<vtkFloatArray> scale; | ||
scale->SetNumberOfComponents(3); | ||
scale->SetNumberOfTuples(nbSplats); | ||
scale->SetName("scale"); | ||
|
||
// rotation: 4 chars (4 bytes) | ||
vtkNew<vtkUnsignedCharArray> rotation; | ||
rotation->SetNumberOfComponents(4); | ||
rotation->SetNumberOfTuples(nbSplats); | ||
rotation->SetName("rotation"); | ||
|
||
// color+opacity: 4 chars (4 bytes) | ||
vtkNew<vtkUnsignedCharArray> colorAndOpacity; | ||
colorAndOpacity->SetNumberOfComponents(4); | ||
colorAndOpacity->SetNumberOfTuples(nbSplats); | ||
colorAndOpacity->SetName("color and opacity"); | ||
|
||
return 1; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <vtkPolyDataAlgorithm.h> | ||
|
||
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In
vtkF3DSplatReader
, the splats are actually just points with extra information (radius, color, etc...) because they will be drawn as ellipsoids later by F3D.In your case, you just want to have points and triangles.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, so does that means that I can remove all
SetNumberOfTuples()
safely?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, take a look at my other comment, you can just remove all the VTK buffers you have created for now.