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