1 /* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */ 2 3 #ifndef S3O_PARSER_H 4 #define S3O_PARSER_H 5 6 #include <map> 7 #include "IModelParser.h" 8 #include "System/type2.h" 9 10 enum { 11 S3O_PRIMTYPE_TRIANGLES = 0, 12 S3O_PRIMTYPE_TRIANGLE_STRIP = 1, 13 S3O_PRIMTYPE_QUADS = 2, 14 }; 15 16 struct SS3OVertex { 17 float3 pos; 18 float3 normal; 19 float2 texCoord; 20 float3 sTangent; 21 float3 tTangent; 22 char unused[8]; //Note: ATi wants 64 _byte_ aligned data in VBOs for optimal performance 23 }; 24 25 struct SS3OPiece: public S3DModelPiece { SS3OPieceSS3OPiece26 SS3OPiece(): primType(S3O_PRIMTYPE_TRIANGLES) { 27 } 28 29 void UploadGeometryVBOs(); 30 void DrawForList() const; 31 SetVertexCountSS3OPiece32 void SetVertexCount(unsigned int n) { vertices.resize(n); } SetVertexDrawIndexCountSS3OPiece33 void SetVertexDrawIndexCount(unsigned int n) { vertexDrawIndices.resize(n); } 34 35 void SetMinMaxExtends(); 36 void SetVertexTangents(); 37 SetVertexSS3OPiece38 void SetVertex(int idx, const SS3OVertex& v) { vertices[idx] = v; } SetVertexDrawIndexSS3OPiece39 void SetVertexDrawIndex(int idx, const unsigned int drawIdx) { vertexDrawIndices[idx] = drawIdx; } 40 GetVertexCountSS3OPiece41 unsigned int GetVertexCount() const { return vertices.size(); } GetVertexDrawIndexCountSS3OPiece42 unsigned int GetVertexDrawIndexCount() const { return vertexDrawIndices.size(); } 43 GetVertexPosSS3OPiece44 const float3& GetVertexPos(const int idx) const { return vertices[idx].pos; } GetNormalSS3OPiece45 const float3& GetNormal(const int idx) const { return vertices[idx].normal; } 46 void Shatter(float pieceChance, int texType, int team, const float3& pos, const float3& speed) const; 47 48 int primType; 49 50 private: 51 std::vector<SS3OVertex> vertices; 52 std::vector<unsigned int> vertexDrawIndices; 53 }; 54 55 56 57 class CS3OParser: public IModelParser 58 { 59 public: 60 S3DModel* Load(const std::string& name); GetType()61 ModelType GetType() const { return MODELTYPE_S3O; } 62 63 private: 64 SS3OPiece* LoadPiece(S3DModel*, SS3OPiece*, unsigned char* buf, int offset); 65 }; 66 67 #endif /* S3O_PARSER_H */ 68