AppData.cpp 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. /*
  2. ** Command & Conquer Generals Zero Hour(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. /***********************************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : G *
  23. * *
  24. * $Archive:: /Commando/Code/Tools/max2w3d/AppData.cpp $*
  25. * *
  26. * $Author:: Greg_h $*
  27. * *
  28. * $Modtime:: 9/26/00 4:24p $*
  29. * *
  30. * $Revision:: 4 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. /*
  36. ** AppData.cpp - Implementation of some Westwood
  37. ** extensions to the MAXScript language.
  38. */
  39. #include <MaxScrpt.h> // Main MAXScript header
  40. #include <MaxObj.h> // MAX* Wrapper objects
  41. #include <Strings.h> // MAX String class
  42. #include <definsfn.h> // def_* functions to create static function headers
  43. #include "w3dutil.h" // W3DAppData*Struct accessor functions!
  44. #include "w3ddesc.h"
  45. /*
  46. ** Let MAXScript know we're implementing new built-in functions.
  47. */
  48. def_visible_primitive(copy_app_data, "wwCopyAppData");
  49. def_visible_primitive(set_origin_app_data, "wwSetOriginAppData");
  50. def_visible_primitive(get_hierarchy_file, "wwGetHierarchyFile");
  51. /*
  52. **
  53. ** MAXScript Function:
  54. ** wwCopyAppData - Usage: wwCopyAppData to_node from_node
  55. **
  56. ** Copies all AppData associated with from_node to to_node.
  57. ** This is needed for W3D flags such as Export Geometry
  58. ** and Export Transform to get passed on to their
  59. ** instances/copies/references.
  60. */
  61. Value * copy_app_data_cf (Value **arg_list, int count)
  62. {
  63. // Verify the number and type of the arguments.
  64. check_arg_count("wwCopyAppData", 2, count);
  65. type_check(arg_list[0], MAXNode, "Target INode");
  66. type_check(arg_list[1], MAXNode, "Source INode");
  67. // Get the INode pointers that were passed in.
  68. INode *dest_node = arg_list[0]->to_node();
  69. INode *src_node = arg_list[1]->to_node();
  70. /*
  71. ** Copy W3DAppData0Struct
  72. */
  73. W3DAppData0Struct *app_data_0 = GetW3DAppData0(src_node);
  74. if (app_data_0 != NULL) {
  75. // App Data 0 is now obsolete, not fatal if we don't find one
  76. W3DAppData0Struct *copy_data_0 = new W3DAppData0Struct;
  77. if (copy_data_0 == NULL)
  78. throw RuntimeError("Out of memory.");
  79. // Copy the app data and give it to the target node.
  80. *copy_data_0 = *app_data_0;
  81. dest_node->AddAppDataChunk(W3DUtilityClassID, UTILITY_CLASS_ID, W3D_APPDATA_0,
  82. sizeof(W3DAppData0Struct), copy_data_0);
  83. }
  84. /*
  85. ** Copy W3DAppData1Struct
  86. */
  87. W3DAppData1Struct *app_data_1 = GetW3DAppData1(src_node);
  88. if (app_data_1 == NULL)
  89. throw RuntimeError("Unable to retrieve W3DAppData1Struct from object: ", arg_list[1]);
  90. W3DAppData1Struct *copy_data_1 = new W3DAppData1Struct;
  91. if (copy_data_1 == NULL)
  92. throw RuntimeError("Out of memory.");
  93. // Copy the app data and give it to the target node.
  94. *copy_data_1 = *app_data_1;
  95. dest_node->AddAppDataChunk(W3DUtilityClassID, UTILITY_CLASS_ID, W3D_APPDATA_1,
  96. sizeof(W3DAppData1Struct), copy_data_1);
  97. /*
  98. ** Copy W3DAppData2Struct
  99. */
  100. W3DAppData2Struct *app_data_2 = GetW3DAppData2(src_node);
  101. if (app_data_2 == NULL)
  102. throw RuntimeError("Unable to retrieve W3DAppData1Struct from object: ", arg_list[1]);
  103. W3DAppData2Struct *copy_data_2 = new W3DAppData2Struct;
  104. if (copy_data_2 == NULL)
  105. throw RuntimeError("Out of memory.");
  106. // Copy the app data and give it to the target node.
  107. *copy_data_2 = *app_data_2;
  108. dest_node->AddAppDataChunk(W3DUtilityClassID, UTILITY_CLASS_ID, W3D_APPDATA_2,
  109. sizeof(W3DAppData2Struct), copy_data_2);
  110. /*
  111. ** Copy W3DDazzleAppDataStruct if one is present.
  112. */
  113. W3DDazzleAppDataStruct *dazzle_app_data = GetW3DDazzleAppData(src_node);
  114. if (dazzle_app_data != NULL) {
  115. W3DDazzleAppDataStruct *copy_dazzle_data = new W3DDazzleAppDataStruct;
  116. if (copy_dazzle_data == NULL)
  117. throw RuntimeError("Out of memory.");
  118. // Copy the app data and give it to the target node.
  119. *copy_dazzle_data = *dazzle_app_data;
  120. dest_node->AddAppDataChunk(W3DUtilityClassID, UTILITY_CLASS_ID, W3D_DAZZLE_APPDATA,
  121. sizeof(W3DDazzleAppDataStruct), copy_dazzle_data);
  122. }
  123. return &ok;
  124. }
  125. /*
  126. **
  127. ** MAXScript Function:
  128. ** wwSetOriginAppData - Usage: wwSetOriginAppData origin_node
  129. **
  130. ** Sets the AppData associated with the given node to values
  131. ** appropriate to an origin. (ie. turn off Export Geometry and
  132. ** Export Transform)
  133. */
  134. Value * set_origin_app_data_cf (Value **arg_list, int count)
  135. {
  136. // Check the arguments that were passed to this function.
  137. check_arg_count("wwSetOriginAppData", 1, count);
  138. type_check(arg_list[0], MAXNode, "Origin INode");
  139. // Get the INode that we were given.
  140. INode *origin = arg_list[0]->to_node();
  141. // Get the node's W3DAppData2Struct, and modify it accordingly.
  142. W3DAppData2Struct *data = GetW3DAppData2(origin);
  143. if (data == NULL)
  144. throw RuntimeError("Unable to retrieve W3DAppData0Struct from object: ", arg_list[0]);
  145. // Turn off Export Geometry and Export Hierarchy.
  146. data->Enable_Export_Geometry(false);
  147. data->Enable_Export_Transform(false);
  148. return &ok;
  149. }
  150. /*
  151. **
  152. ** MAXScript Function:
  153. ** wwGetHierarchyFile - Usage: wwGetHierarchyFile()
  154. **
  155. ** Returns the relative pathname of the file that will be loaded
  156. ** during W3D export to get the hierarchy tree. If no such file
  157. ** will be loaded, the return value is the MAXScript undefined.
  158. **
  159. */
  160. Value * get_hierarchy_file_cf (Value **arg_list, int count)
  161. {
  162. // Check that we weren't passed any arguments.
  163. check_arg_count("wwGetHierarchyFile", 0, count);
  164. // Retrieve the export options from the scene.
  165. W3dExportOptionsStruct *options = NULL;
  166. AppDataChunk * appdata = MAXScript_interface->GetScenePointer()->GetAppDataChunk(W3D_EXPORTER_CLASS_ID,SCENE_EXPORT_CLASS_ID,0);
  167. if (appdata)
  168. options = (W3dExportOptionsStruct*)(appdata->data);
  169. // If we didn't get any options, return undefined.
  170. if (!options)
  171. return &undefined;
  172. // Return the relative path to the htree file if it's available.
  173. // Otherwise, return the absolute path.
  174. one_typed_value_local(String* htree_file);
  175. if (options->RelativeHierarchyFilename[0] != 0)
  176. vl.htree_file = new String(options->RelativeHierarchyFilename);
  177. else if (options->HierarchyFilename[0] != 0)
  178. vl.htree_file = new String(options->HierarchyFilename);
  179. else
  180. {
  181. // Neither filename is available, return undefined.
  182. pop_value_locals();
  183. return &undefined;
  184. }
  185. return_value(vl.htree_file);
  186. }