PolyMesh.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * PolyMesh.h
  3. * TAU
  4. *
  5. * Created by Ivan Safrin on 3/18/08.
  6. * Copyright 2008 __MyCompanyName__. All rights reserved.
  7. *
  8. */
  9. // @package BasicTypes
  10. #pragma once
  11. #include <math.h>
  12. #include "PolyGlobals.h"
  13. #include "PolyPolygon.h"
  14. #include "PolyVertex.h"
  15. #include <string>
  16. #include <vector>
  17. #include "OSBasics.h"
  18. using namespace std;
  19. namespace Polycode {
  20. class _PolyExport VertexBuffer {
  21. public:
  22. int getVertexCount() { return vertexCount;}
  23. protected:
  24. int vertexCount;
  25. };
  26. class _PolyExport RenderDataArray {
  27. public:
  28. int arrayType;
  29. int stride;
  30. int size;
  31. void *arrayPtr;
  32. void *rendererData;
  33. int count;
  34. static const int VERTEX_DATA_ARRAY = 0;
  35. static const int COLOR_DATA_ARRAY = 1;
  36. static const int NORMAL_DATA_ARRAY = 2;
  37. static const int TEXCOORD_DATA_ARRAY = 3;
  38. };
  39. typedef struct {
  40. float x;
  41. float y;
  42. float z;
  43. } Vector3_struct;
  44. typedef struct {
  45. float x;
  46. float y;
  47. } Vector2_struct;
  48. typedef struct {
  49. unsigned int v1;
  50. unsigned int v2;
  51. unsigned int v3;
  52. float nx;
  53. float ny;
  54. float nz;
  55. Vector2_struct uvs[3];
  56. } Face_struct;
  57. class _PolyExport Mesh {
  58. public:
  59. Mesh(string fileName);
  60. Mesh(int meshType);
  61. ~Mesh();
  62. void addPolygon(Polygon *newPolygon);
  63. void loadMesh(string fileName);
  64. void loadFromFile(OSFILE *inFile);
  65. void saveToFile(OSFILE *outFile);
  66. unsigned int getPolygonCount();
  67. Polygon *getPolygon(unsigned int index);
  68. void createPlane(float w, float h);
  69. void createBox(float w, float d, float h);
  70. void createSphere(float radius, float numRings, float numSegments);
  71. void addVertex(Vertex* vertex);
  72. Vertex *getVertex(unsigned int index);
  73. unsigned int getNumVertices();
  74. void useVertexNormals(bool val);
  75. int getVertexIndex(Vertex *vertex);
  76. void setVertexBuffer(VertexBuffer *buffer);
  77. VertexBuffer *getVertexBuffer();
  78. bool usesFaceUV() { return useFaceUV; }
  79. float getRadius();
  80. void calculateNormals();
  81. int getMeshType();
  82. void setMeshType(int newType);
  83. Vector3 calculateBBox();
  84. bool hasVertexBuffer() { return meshHasVertexBuffer; }
  85. static const int QUAD_MESH = 0;
  86. static const int TRI_MESH = 1;
  87. static const int TRIFAN_MESH = 2;
  88. static const int TRISTRIP_MESH = 3;
  89. static const int LINE_MESH = 4;
  90. unsigned int numUVs;
  91. bool arrayDirtyMap[16];
  92. RenderDataArray *renderDataArrays[16];
  93. private:
  94. VertexBuffer *vertexBuffer;
  95. bool meshHasVertexBuffer;
  96. int meshType;
  97. bool useFaceUV;
  98. vector <Polygon*> polygons;
  99. vector <Vertex*> vertices;
  100. };
  101. }