PolyMesh.h 2.6 KB

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