meshgen.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #ifndef __meshgen_h__
  2. #define __meshgen_h__
  3. #include "c3dlas.h"
  4. typedef struct {
  5. Vector3* vertices;
  6. Vector3* normals;
  7. short* indices;
  8. int nElements;
  9. int nVertices;
  10. int nNormals;
  11. int nIndices;
  12. short width; // should be plenty. 8 billion triangles it too much to render anyway.
  13. short height;
  14. } IndexedPatch;
  15. typedef struct TriangleMesh {
  16. Vector3* vertices;
  17. Vector3* normals;
  18. unsigned int* indices;
  19. // used quantity
  20. int vertexCnt; // also used for normals.
  21. int indexCnt;
  22. // always GL_TRIANGLES
  23. // allocated sizes, in elements
  24. int szVertices;
  25. int szIndices;
  26. char windingDir; // c = clockwise, w = widdershins (counter-clockwise)
  27. } TriangleMesh;
  28. typedef struct MeshSlice {
  29. // MeshVertex* vertices;
  30. short* indices;
  31. // always line strips; -1 resets
  32. int vertexCnt;
  33. int indexCnt;
  34. // allocated sizes, in elements
  35. int szVertices;
  36. int szIndices;
  37. Vector2 texDxDy;
  38. } MeshSlice;
  39. // TODO: winding and strips. currently it outputs a triangle list and the winding is probably fucked.
  40. // in the x-y plane, 0,0 at the lower left
  41. void mgGenFlatPatch(short width, short height, IndexedPatch* out);
  42. float* genNoisef(short width, short height, float min, float max);
  43. TriangleMesh* makeCube(Matrix* mat, int flat);
  44. TriangleMesh* makeQuad(float width, float height);
  45. TriangleMesh* makeCylinder(int sides, float height, float baseRadius, float topRadius);
  46. TriangleMesh* makeIcosahedron(float radius);
  47. TriangleMesh* makeSubbedIcosahedron(float radius, int subdivisions);
  48. // uncapped cylinders
  49. // discs
  50. // free triangles
  51. // tetrahedrons / cones
  52. // shapes with planar but subdivided faces
  53. // mesh smoothing fn
  54. // tex coord projection
  55. TriangleMesh* makeParallelpiped();
  56. #endif // __meshgen_h__