home *** CD-ROM | disk | FTP | other *** search
/ Xentax forum attachments archive / xentax.7z / 5257 / source.7z / x_lwo.h < prev    next >
Encoding:
C/C++ Source or Header  |  2012-03-20  |  10.7 KB  |  441 lines

  1. #ifndef __XENTAX_LWO_H
  2. #define __XENTAX_LWO_H
  3.  
  4. // CLIP chunk (list of images)
  5. // TAGS chunk (list of surface names + skeleton surface name + bone part names)
  6. // for each layer
  7. //     LAYR chunk
  8. //     PNTS chunk (list of points)
  9. //     VMAP chunk #1 (UV #1)
  10. //     VMAP chunk #2 (UV #2)
  11. //     VMAP chunk #3 (Weight)
  12. //     VMAP chunk #4 (Weight)
  13. //     VMAP chunk #5 (Morphological)
  14. //     VMAP chunk #6 (Morphological)
  15. //     VMAP chunk #7 (Color)
  16. //     VMAP chunk #8 (Color)
  17. //     VMAP chunk #N
  18. //     POLS chunk (list of polygons)
  19. //     PTAG chunk (list of surface-polygon associations)
  20. //     for each skeleton
  21. //         PNTS chunk (skeleton list of points)
  22. //         POLS chunk (skeleton list of polygons)
  23. //         PTAG chunk (skeleton list of bone-surface associations)
  24. //         PTAG chunk (skeleton list of bone-name associations)
  25. //         PTAG chunk (skeleton list of bone-part associations)
  26. //         PTAG chunk (skeleton list of bone-uphandle associations)
  27. //         PTAG chunk (skeleton list of bone-weightmap associations)
  28. // for each surface
  29. //     SURF chunk
  30.  
  31. //
  32. // CHUNKTYPES
  33. //
  34.  
  35. inline uint32 LWO_TAG(uint32 a, uint32 b, uint32 c, uint32 d)
  36. {
  37.  return ((a << 24) | (b << 16) | (c << 8) | (d));
  38. }
  39.  
  40. #define LWO_FORM LWO_TAG('F', 'O', 'R', 'M')
  41. #define LWO_LWO2 LWO_TAG('L', 'W', 'O', '2')
  42. #define LWO_TAGS LWO_TAG('T', 'A', 'G', 'S')
  43. #define LWO_LAYR LWO_TAG('L', 'A', 'Y', 'R')
  44. #define LWO_PNTS LWO_TAG('P', 'N', 'T', 'S')
  45. #define LWO_VMAP LWO_TAG('V', 'M', 'A', 'P')
  46. #define LWO_WGHT LWO_TAG('W', 'G', 'H', 'T')
  47. #define LWO_TXUV LWO_TAG('T', 'X', 'U', 'V')
  48. #define LWO_MORF LWO_TAG('M', 'O', 'R', 'F')
  49. #define LWO_POLS LWO_TAG('P', 'O', 'L', 'S')
  50. #define LWO_FACE LWO_TAG('F', 'A', 'C', 'E')
  51. #define LWO_BONE LWO_TAG('B', 'O', 'N', 'E')
  52. #define LWO_PART LWO_TAG('P', 'A', 'R', 'T')
  53. #define LWO_ENVL LWO_TAG('E', 'N', 'V', 'L')
  54. #define LWO_CLIP LWO_TAG('C', 'L', 'I', 'P')
  55. #define LWO_SURF LWO_TAG('S', 'U', 'R', 'F')
  56. #define LWO_PTAG LWO_TAG('P', 'T', 'A', 'G')
  57. #define LWO_COLR LWO_TAG('C', 'O', 'L', 'R')
  58. #define LWO_DIFF LWO_TAG('D', 'I', 'F', 'F')
  59. #define LWO_SPEC LWO_TAG('S', 'P', 'E', 'C')
  60. #define LWO_TRAN LWO_TAG('T', 'R', 'A', 'N')
  61. #define LWO_CLIP LWO_TAG('C', 'L', 'I', 'P')
  62. #define LWO_STIL LWO_TAG('S', 'T', 'I', 'L')
  63. #define LWO_FLAG LWO_TAG('F', 'L', 'A', 'G')
  64. #define LWO_BLOK LWO_TAG('B', 'L', 'O', 'K')
  65. #define LWO_IMAP LWO_TAG('I', 'M', 'A', 'P')
  66. #define LWO_TMAP LWO_TAG('T', 'M', 'A', 'P')
  67. #define LWO_CHAN LWO_TAG('C', 'H', 'A', 'N')
  68. #define LWO_OPAC LWO_TAG('O', 'P', 'A', 'C')
  69. #define LWO_ENAB LWO_TAG('E', 'N', 'A', 'B')
  70. #define LWO_NEGA LWO_TAG('N', 'E', 'G', 'A')
  71. #define LWO_CNTR LWO_TAG('C', 'N', 'T', 'R')
  72. #define LWO_SIZE LWO_TAG('S', 'I', 'Z', 'E')
  73. #define LWO_ROTA LWO_TAG('R', 'O', 'T', 'A')
  74. #define LWO_FALL LWO_TAG('F', 'A', 'L', 'L')
  75. #define LWO_OMAP LWO_TAG('O', 'M', 'A', 'P')
  76. #define LWO_CSYS LWO_TAG('C', 'S', 'Y', 'S')
  77. #define LWO_PROJ LWO_TAG('P', 'R', 'O', 'J')
  78. #define LWO_AXIS LWO_TAG('A', 'X', 'I', 'S')
  79. #define LWO_IMAG LWO_TAG('I', 'M', 'A', 'G')
  80. #define LWO_WRAP LWO_TAG('W', 'R', 'A', 'P')
  81. #define LWO_WRPW LWO_TAG('W', 'R', 'P', 'W')
  82. #define LWO_WRPH LWO_TAG('W', 'R', 'P', 'H')
  83. #define LWO_VMAP LWO_TAG('V', 'M', 'A', 'P')
  84. #define LWO_AAST LWO_TAG('A', 'A', 'S', 'T')
  85. #define LWO_PIXB LWO_TAG('P', 'I', 'X', 'B')
  86.  
  87. //
  88. // LAYER MACROS
  89. //
  90.  
  91. #define LWO_MAX_LAYERS 128
  92.  
  93. //
  94. // SURFACE MACROS
  95. //
  96.  
  97. #define LWO_SURF_FLAGS_COLR      0x0001
  98. #define LWO_SURF_FLAGS_DIFF      0x0002
  99. #define LWO_SURF_FLAGS_SPEC      0x0004
  100. #define LWO_SURF_FLAGS_TRAN      0x0008
  101. #define LWO_SURF_FLAGS_COLR_BLOK 0x0010
  102. #define LWO_SURF_FLAGS_DIFF_BLOK 0x0020
  103. #define LWO_SURF_FLAGS_SPEC_BLOK 0x0040
  104. #define LWO_SURF_FLAGS_TRAN_BLOK 0x0080
  105.  
  106. //
  107. // GENERAL STRUCTURES
  108. //
  109.  
  110. struct lwVertex1D { real32 x; };
  111. struct lwVertex2D { real32 x; real32 y; };
  112. struct lwVertex3D { real32 x; real32 y; real32 z; };
  113. struct lwTriangle { uint32 a; uint32 b; uint32 c; };
  114. struct lwSkelegon { uint32 a; uint32 b; std::string name; };
  115.  
  116. struct lwRefVertex1D { uint32 reference; real32 x; };
  117. struct lwRefVertex2D { uint32 reference; real32 x; real32 y; };
  118. struct lwRefVertex3D { uint32 reference; real32 x; real32 y; real32 z; };
  119.  
  120. //
  121. // CHUNK STRUCTURES (TAGS)
  122. //
  123.  
  124. struct lwTAGS {
  125.  uint32 chunksize;
  126.  uint32 currindex;
  127.  boost::bimap<uint16, std::string> surftags;
  128.  boost::bimap<uint16, std::string> bonetags;
  129.  boost::bimap<uint16, std::string> parttags;
  130.  boost::bimap<uint16, std::string> bnuptags;
  131. };
  132.  
  133. struct lwPTAG {
  134.  uint32 chunksize;
  135.  uint32 type;
  136.  std::map<uint32, uint16> tags;
  137. };
  138.  
  139. //
  140. // CHUNK STRUCTURES (CLIPS)
  141. //
  142.  
  143. struct lwCLIP {
  144.  uint32 chunksize;
  145.  std::string filename;
  146. };
  147.  
  148. //
  149. // CHUNK STRUCTURES (VERTEX MAPS)
  150. //
  151.  
  152. struct lwTXUV {
  153.  uint32 chunksize;
  154.  boost::shared_array<lwRefVertex2D> data;
  155.  uint32 elem;
  156. };
  157.  
  158. struct lwWGHT {
  159.  uint32 chunksize;
  160.  boost::shared_array<lwRefVertex1D> data;
  161.  uint32 elem;
  162. };
  163.  
  164. struct lwMORF {
  165.  uint32 chunksize;
  166.  boost::shared_array<lwRefVertex3D> data;
  167.  uint32 elem;
  168. };
  169.  
  170. //
  171. // CHUNK STRUCTURES (POLYGON TYPES)
  172. //
  173.  
  174. struct lwPOLS {
  175.  uint32 chunksize;
  176.  boost::shared_array<lwTriangle> data;
  177.  uint32 elem;
  178.  std::string name; // TODO: remove
  179.  lwPTAG surf;
  180. };
  181.  
  182. // lwSKEL
  183. struct lwSKEL {
  184.  uint32 chunksize;
  185.  boost::shared_array<lwSkelegon> data;
  186.  uint32 elem;
  187.  std::string name;
  188.  lwPTAG stag;
  189.  lwPTAG btag;
  190.  lwPTAG ptag;
  191.  lwPTAG utag;
  192. };
  193.  
  194. //
  195. // CHUNK STRUCTURES (POINT TYPES)
  196. //
  197.  
  198. struct lwPNTS {
  199.  uint32 chunksize;
  200.  boost::shared_array<lwVertex3D> data;
  201.  uint32 elem;
  202.  std::map<std::string, lwTXUV> txuv;
  203.  std::map<std::string, lwWGHT> wght;
  204.  std::map<std::string, lwMORF> morf;
  205.  std::deque<lwPOLS> face;
  206. };
  207.  
  208. struct lwJNTS {
  209.  uint32 chunksize;
  210.  boost::shared_array<lwVertex3D> data;
  211.  uint32 elem;
  212.  std::deque<lwSKEL> skel;
  213. };
  214.  
  215. //
  216. // CHUNK STRUCTURES (LAYERS)
  217. //
  218.  
  219. struct lwLAYR {
  220.  uint32 chunksize;
  221.  uint16 flags;
  222.  real32 pivot_x;
  223.  real32 pivot_y;
  224.  real32 pivot_z;
  225.  std::string name;
  226.  std::map<uint16, lwPNTS> pntss;
  227.  std::map<uint16, lwJNTS> jntss;
  228. };
  229.  
  230. //
  231. // CHUNK STRUCTURES (SURFACE SUBCHUNKS)
  232. //
  233.  
  234. struct lwCHAN {
  235.  uint16 chunksize;
  236.  uint32 channel;
  237. };
  238.  
  239. struct lwENAB {
  240.  uint16 chunksize;
  241.  uint16 enable;
  242. };
  243.  
  244. struct lwOPAC {
  245.  uint16 chunksize;
  246.  uint16 type;
  247.  real32 opacity;
  248. };
  249.  
  250. struct lwAXIS {
  251.  uint16 chunksize;
  252.  uint16 axis;
  253. };
  254.  
  255. struct lwNEGA {
  256.  uint16 chunksize;
  257.  uint16 enable;
  258. };
  259.  
  260. struct lwCNTR {
  261.  uint16 chunksize;
  262.  real32 x;
  263.  real32 y;
  264.  real32 z;
  265. };
  266.  
  267. struct lwSIZE {
  268.  uint16 chunksize;
  269.  real32 x;
  270.  real32 y;
  271.  real32 z;
  272. };
  273.  
  274. struct lwROTA {
  275.  uint16 chunksize;
  276.  real32 x;
  277.  real32 y;
  278.  real32 z;
  279. };
  280.  
  281. struct lwFALL {
  282.  uint16 chunksize;
  283.  uint16 type;
  284.  real32 x;
  285.  real32 y;
  286.  real32 z;
  287. };
  288.  
  289. struct lwCSYS {
  290.  uint16 chunksize;
  291.  uint16 type;
  292. };
  293.  
  294. struct lwPROJ {
  295.  uint16 chunksize;
  296.  uint16 mode;
  297. };
  298.  
  299. struct lwIMAG {
  300.  uint16 chunksize;
  301.  uint32 clipindex;
  302. };
  303.  
  304. struct lwWRAP {
  305.  uint16 chunksize;
  306.  uint16 wrap_w;
  307.  uint16 wrap_h;
  308. };
  309.  
  310. struct lwVMAP {
  311.  uint16 chunksize;
  312.  std::string name;
  313. };
  314.  
  315. struct lwAAST {
  316.  uint16 chunksize;
  317.  uint16 flags;
  318.  real32 strength;
  319. };
  320.  
  321. struct lwPIXB {
  322.  uint16 chunksize;
  323.  uint16 flags;
  324. };
  325.  
  326. //
  327. // CHUNK STRUCTURES (SURFACES)
  328. //
  329.  
  330. struct lwIMAP {
  331.  uint16 chunksize;
  332.  lwCHAN chan;
  333.  lwENAB enab;
  334.  lwNEGA nega;
  335.  lwOPAC opac;
  336.  lwAXIS axis;
  337. };
  338.  
  339. struct lwTMAP {
  340.  uint16 chunksize;
  341.  lwCNTR cntr;
  342.  lwSIZE size;
  343.  lwROTA rota;
  344.  lwFALL fall;
  345.  lwCSYS csys;
  346. };
  347.  
  348. struct lwBLOK {
  349.  uint16 chunksize;
  350.  lwIMAP imap;
  351.  lwTMAP tmap;
  352.  lwPROJ proj;
  353.  lwAXIS axis;
  354.  lwIMAG imag;
  355.  lwWRAP wrap;
  356.  lwVMAP vmap;
  357.  lwAAST aast;
  358.  lwPIXB pixb;
  359. };
  360.  
  361. struct lwSURF {
  362.  uint32 chunksize;
  363.  uint32 flags;
  364.  real32 colr[3];
  365.  real32 diff;
  366.  real32 spec;
  367.  real32 tran;
  368.  lwBLOK colr_map;
  369.  lwBLOK diff_map;
  370.  lwBLOK spec_map;
  371.  lwBLOK tran_map;
  372. };
  373.  
  374. //
  375. // LWO2 CLASS
  376. //
  377.  
  378. class lwFileSaver {
  379.  private :
  380.   lwTAGS tags;
  381.   std::map<uint32, lwCLIP> clips;
  382.   std::map<uint16, lwLAYR> layrs;
  383.   std::map<std::string, lwSURF> surfs;
  384.  private :
  385.   bool hasTxuv(const char* name)const;
  386.  public :
  387.   bool insertClip(uint32 clipindex, const char* filename);
  388.   bool insertLayr(uint16 layer, const char* name);
  389.   bool insertPnts(uint16 layer, uint16 pointset, const boost::shared_array<lwVertex3D>& data, uint32 elem);
  390.   bool insertTxuv(uint16 layer, uint16 pointset, const char* name, const boost::shared_array<lwRefVertex2D>& data, uint32 elem);
  391.   bool insertWght(uint16 layer, uint16 pointset, const char* name, const boost::shared_array<lwRefVertex1D>& data, uint32 elem);
  392.   bool insertMorf(uint16 layer, uint16 pointset, const char* name, const boost::shared_array<lwRefVertex3D>& data, uint32 elem);
  393.   bool insertPols(uint16 layer, uint16 pointset, const char* name, const boost::shared_array<lwTriangle>& data, uint32 elem);
  394.   bool insertJnts(uint16 layer, uint16 jointset, const boost::shared_array<lwVertex3D>& data, uint32 elem);
  395.   bool insertSkel(uint16 layer, uint16 jointset, const char* name, const boost::shared_array<lwSkelegon>& data, uint32 elem);
  396.  public :
  397.   bool insertBone(const char* name);
  398.   bool insertPart(const char* name);
  399.   bool insertSurf(const char* name);
  400.   bool setSurfColr(const char* name, real32 r, real32 g, real32 b);
  401.   bool setSurfDiff(const char* name, real32 intensity);
  402.   bool setSurfSpec(const char* name, real32 intensity);
  403.   bool setSurfTran(const char* name, real32 intensity);
  404.  public :
  405.   bool enableSurfColrImag(const char* name);
  406.   bool enableSurfDiffImag(const char* name);
  407.   bool enableSurfSpecImag(const char* name);
  408.   bool enableSurfTranImag(const char* name);
  409.  public :
  410.   bool setSurfVmap(const char* surface, const char* mapname, uint32 type);
  411.   bool setSurfColrVmap(const char* surface, const char* mapname);
  412.   bool setSurfDiffVmap(const char* surface, const char* mapname);
  413.   bool setSurfSpecVmap(const char* surface, const char* mapname);
  414.   bool setSurfTranVmap(const char* surface, const char* mapname);
  415.  public :
  416.   bool setSurfImag(const char* surface, uint32 clipindex, uint32 type);
  417.   bool setSurfColrImag(const char* surface, uint32 clipindex);
  418.   bool setSurfDiffImag(const char* surface, uint32 clipindex);
  419.   bool setSurfSpecImag(const char* surface, uint32 clipindex);
  420.   bool setSurfTranImag(const char* surface, uint32 clipindex);
  421.  public :
  422.   bool setSurfNega(const char* surface, uint16 state, uint32 type);
  423.   bool setSurfColrNega(const char* surface, uint16 state);
  424.   bool setSurfDiffNega(const char* surface, uint16 state);
  425.   bool setSurfSpecNega(const char* surface, uint16 state);
  426.   bool setSurfTranNega(const char* surface, uint16 state);
  427.  public :
  428.   bool save(const char* filename)const;
  429.  public :
  430.   lwFileSaver();
  431.  ~lwFileSaver();
  432. };
  433.  
  434. //
  435. // LWO2 CLASS EXAMPLE
  436. //
  437.  
  438. void lwFileSaverExample(void);
  439.  
  440. #endif
  441.