hiersave.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /* $Header: /Commando/Code/Tools/max2w3d/hiersave.h 29 10/26/00 5:59p Greg_h $ */
  19. /***********************************************************************************************
  20. *** Confidential - Westwood Studios ***
  21. ***********************************************************************************************
  22. * *
  23. * Project Name : Commando / G 3D Engine *
  24. * *
  25. * $Archive:: /Commando/Code/Tools/max2w3d/hiersave.h $*
  26. * *
  27. * $Author:: Greg_h $*
  28. * *
  29. * $Modtime:: 10/26/00 5:09p $*
  30. * *
  31. * $Revision:: 29 $*
  32. * *
  33. *---------------------------------------------------------------------------------------------*
  34. * Functions: *
  35. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  36. #ifndef HIERSAVE_H
  37. #define HIERSAVE_H
  38. #include "always.h"
  39. #include <Max.h>
  40. #include <stdio.h>
  41. #ifndef W3D_FILE_H
  42. #include "w3d_file.h"
  43. #endif
  44. #ifndef PROGRESS_H
  45. #include "progress.h"
  46. #endif
  47. #ifndef CHUNKIO_H
  48. #include "chunkio.h"
  49. #endif
  50. #ifndef NODELIST_H
  51. #include "nodelist.h"
  52. #endif
  53. #ifndef VECTOR_H
  54. #include "vector.h"
  55. #endif
  56. struct HierarchyNodeStruct
  57. {
  58. INode * MaxNode;
  59. W3dPivotStruct Pivot;
  60. W3dPivotFixupStruct Fixup;
  61. bool operator == (const HierarchyNodeStruct & that) { return false; }
  62. bool operator != (const HierarchyNodeStruct & that) { return !(*this == that); }
  63. };
  64. class HierarchySaveClass
  65. {
  66. public:
  67. enum {
  68. MATRIX_FIXUP_NONE = 0,
  69. MATRIX_FIXUP_TRANS = 1,
  70. MATRIX_FIXUP_TRANS_ROT = 2
  71. };
  72. HierarchySaveClass();
  73. HierarchySaveClass(
  74. INode * root,
  75. TimeValue time,
  76. Progress_Meter_Class & treemeter,
  77. char * hname,
  78. int fixup_type = MATRIX_FIXUP_NONE,
  79. HierarchySaveClass * fixuptree = NULL);
  80. HierarchySaveClass(
  81. INodeListClass * rootlist,
  82. TimeValue time,
  83. Progress_Meter_Class & treemeter,
  84. char * hname,
  85. int fixup_type = MATRIX_FIXUP_NONE,
  86. HierarchySaveClass * fixuptree = NULL,
  87. const Matrix3 & origin_offset = Matrix3(1));
  88. ~HierarchySaveClass();
  89. bool Save(ChunkSaveClass & csave);
  90. bool Load(ChunkLoadClass & cload);
  91. int Num_Nodes(void) const { return CurNode; }
  92. const char * Get_Name(void) const;
  93. const char * Get_Node_Name(int node) const;
  94. // get ahold of the max inode
  95. INode * Get_Node(int node) const;
  96. // Returns the node's transform from object to world space
  97. Matrix3 Get_Node_Transform(int node) const;
  98. // Returns the node's transform relative to its parent
  99. Matrix3 Get_Node_Relative_Transform(int node) const { return get_relative_transform(node); }
  100. // Get the fixup matrix for the given pivot (always applied to the *relative* transform)
  101. Matrix3 Get_Fixup_Transform(int node) const;
  102. // Finds a node by name
  103. int Find_Named_Node(const char * name) const;
  104. // Get the coordinate system to use when exporting the given INode. Note that this
  105. // function takes into account the multiple skeletons present when exporting LOD models.
  106. void Get_Export_Coordinate_System(INode * node,int * set_bone_index,INode ** set_bone_node,Matrix3 * set_transform);
  107. // Turning on terrian mode will cause all HTrees to force all normal meshes to be
  108. // attached to the RootTransform regardless of the status of their 'Export_Transform' flag
  109. static void Enable_Terrain_Optimization(bool onoff) { TerrainModeEnabled = onoff; }
  110. private:
  111. enum { MAX_PIVOTS = 4096, DEFAULT_NODE_ARRAY_SIZE = 512, NODE_ARRAY_GROWTH_SIZE = 32 };
  112. TimeValue CurTime;
  113. W3dHierarchyStruct HierarchyHeader;
  114. DynamicVectorClass<HierarchyNodeStruct> Node;
  115. int CurNode;
  116. int FixupType;
  117. Matrix3 OriginOffsetTransform; // this transform makes a node relative to the origin
  118. HierarchySaveClass * FixupTree;
  119. static bool TerrainModeEnabled;
  120. void add_tree(INode * node,int pidx);
  121. int add_node(INode * node,int pidx);
  122. bool save_header(ChunkSaveClass & csave);
  123. bool save_pivots(ChunkSaveClass & csave);
  124. bool save_fixups(ChunkSaveClass & csave);
  125. bool load_header(ChunkLoadClass & cload);
  126. bool load_pivots(ChunkLoadClass & cload);
  127. bool load_fixups(ChunkLoadClass & cload);
  128. Matrix3 get_relative_transform(int nodeidx) const;
  129. Matrix3 fixup_matrix(const Matrix3 & src) const;
  130. void Free(void);
  131. };
  132. #endif /*HIERSAVE_H*/