w3dutil.cpp 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047
  1. /*
  2. ** Command & Conquer Generals(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/w3dutil.cpp 45 8/21/01 10:28a Greg_h $ */
  19. /***********************************************************************************************
  20. *** Confidential - Westwood Studios ***
  21. ***********************************************************************************************
  22. * *
  23. * Project Name : Commando Tools - W3D export *
  24. * *
  25. * $Archive:: /Commando/Code/Tools/max2w3d/w3dutil.cpp $*
  26. * *
  27. * $Author:: Greg_h $*
  28. * *
  29. * $Modtime:: 8/21/01 9:41a $*
  30. * *
  31. * $Revision:: 45 $*
  32. * *
  33. *---------------------------------------------------------------------------------------------*
  34. * Functions: *
  35. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  36. #include "w3dutil.h"
  37. #include "w3ddesc.h"
  38. #include "rcmenu.h"
  39. #include "util.h"
  40. #include "nodelist.h"
  41. #include "tchar.h"
  42. #include "gamemtl.h"
  43. #include "notify.h"
  44. #include "gennamesdialog.h"
  45. #include "genmtlnamesdialog.h"
  46. #include "genlodextensiondialog.h"
  47. #include "floaterdialog.h"
  48. #include <StdMat.h>
  49. #define DAZZLE_SETTINGS_FILENAME "dazzle.ini"
  50. #define DAZZLE_TYPES_SECTION "Dazzles_List"
  51. #define DAZZLE_SECTION_BUFFERSIZE 32767
  52. static BOOL CALLBACK _settings_form_dlg_proc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
  53. static BOOL CALLBACK _w3d_utility_tools_dlg_proc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
  54. static VisibleSelectedINodeFilter _INodeFilter;
  55. /**********************************************************************************************
  56. **
  57. ** MaterialReferenceMaker - Class to support Export Utilities in the W3D Tools panel.
  58. **
  59. **********************************************************************************************/
  60. class MaterialReferenceMaker : public ReferenceMaker
  61. {
  62. public:
  63. ~MaterialReferenceMaker() {DeleteAllRefs();}
  64. virtual int NumRefs();
  65. virtual RefTargetHandle GetReference (int i);
  66. virtual void SetReference (int i, RefTargetHandle rtarg);
  67. RefResult NotifyRefChanged (Interval changeInt,RefTargetHandle hTarget,PartID& partID, RefMessage message);
  68. Mtl *MaterialPtr;
  69. static int ReferenceCount;
  70. };
  71. int MaterialReferenceMaker::NumRefs()
  72. {
  73. return (ReferenceCount);
  74. }
  75. RefTargetHandle MaterialReferenceMaker::GetReference (int i)
  76. {
  77. assert (i < ReferenceCount);
  78. return (MaterialPtr);
  79. }
  80. void MaterialReferenceMaker::SetReference (int i, RefTargetHandle rtarg)
  81. {
  82. assert (i < ReferenceCount);
  83. MaterialPtr = (Mtl*) rtarg;
  84. }
  85. RefResult MaterialReferenceMaker::NotifyRefChanged(Interval changeInt,RefTargetHandle hTarget,PartID& partID, RefMessage message)
  86. {
  87. return (REF_SUCCEED);
  88. }
  89. int MaterialReferenceMaker::ReferenceCount;
  90. /**********************************************************************************************
  91. **
  92. ** SettingsFormClass - code for the W3DUTILITY_SETTINGS_DIALOG. Used in the command panel
  93. ** and in the floating settings dialog.
  94. **
  95. **********************************************************************************************/
  96. class SettingsFormClass
  97. {
  98. public:
  99. SettingsFormClass(HWND hwnd);
  100. ~SettingsFormClass(void);
  101. bool Dialog_Proc(HWND hWnd,UINT message,WPARAM wParam,LPARAM);
  102. void Selection_Changed(void);
  103. static void Update_All_Instances(void);
  104. private:
  105. void Init(void);
  106. void Destroy(void);
  107. void Disable_Controls(void);
  108. void Update_Controls(INodeListClass * nodelist = NULL);
  109. HWND Hwnd;
  110. ISpinnerControl * RegionSpin;
  111. SettingsFormClass * Next;
  112. static SettingsFormClass * ActiveList;
  113. };
  114. /**********************************************************************************************
  115. **
  116. ** W3DUtilityClass - Utility plugin which presents windows controls for setting all of
  117. ** the W3D export options for the currently selected nodes
  118. **
  119. **********************************************************************************************/
  120. class W3DUtilityClass : public UtilityObj
  121. {
  122. public:
  123. W3DUtilityClass();
  124. ~W3DUtilityClass();
  125. void BeginEditParams(Interface *ip,IUtil *iu);
  126. void EndEditParams(Interface *ip,IUtil *iu);
  127. void SelectionSetChanged(Interface *ip,IUtil *iu);
  128. void DeleteThis() {}
  129. void Select_Hierarchy(void);
  130. void Select_Geometry(void);
  131. void Select_Alpha(void);
  132. void Select_Physical(void);
  133. void Select_Projectile(void);
  134. void Select_Vis(void);
  135. public:
  136. Interface * InterfacePtr;
  137. FloaterDialogClass SettingsFloater;
  138. HWND SettingsPanelHWND;
  139. HWND ToolsPanelHWND;
  140. bool UpdateSpinnerValue;
  141. GenNamesDialogClass::OptionsStruct NameOptions;
  142. GenMtlNamesDialogClass::OptionsStruct MtlNameOptions;
  143. GenLodExtensionDialogClass::OptionsStruct LodExtensionOptions;
  144. int WorkingNameIndex;
  145. enum {
  146. NONE = 0,
  147. HIDE,
  148. SELECT_GEOM,
  149. SELECT_HIER,
  150. SELECT_ALPHA,
  151. SELECT_PHYSICAL,
  152. SELECT_PROJECTILE,
  153. SELECT_VIS,
  154. GENERATE_NAME,
  155. GENERATE_MATERIAL_NAME,
  156. GENERATE_LOD_EXTENSION
  157. };
  158. enum MaterialConversionEnum {
  159. GAME_REFERENCE_COUNT,
  160. GAME_TO_STANDARD,
  161. STANDARD_TO_GAME
  162. };
  163. struct NodeStatesStruct
  164. {
  165. int ExportHierarchy;
  166. int ExportGeometry;
  167. int GeometryTwoSided;
  168. int GeometryHidden;
  169. int GeometryZNormals;
  170. int GeometryVertexAlpha;
  171. int GeometryCastShadow;
  172. int GeometryShatterable;
  173. int GeometryNPatch;
  174. int CollisionPhysical;
  175. int CollisionProjectile;
  176. int CollisionVis;
  177. int CollisionCamera;
  178. int CollisionVehicle;
  179. bool GeometryCameraAligned;
  180. bool GeometryCameraOriented;
  181. bool GeometryNormal;
  182. bool GeometryAABox;
  183. bool GeometryOBBox;
  184. bool GeometryNull;
  185. bool GeometryDazzle;
  186. bool GeometryAggregate;
  187. int DamageRegion;
  188. int DazzleCount;
  189. char DazzleType[128];
  190. };
  191. /*
  192. ** Evaluate the status of nodes in the given list
  193. */
  194. static int eval_tri_state(int totalcount,int oncount);
  195. static void eval_node_states(INodeListClass * node_list,NodeStatesStruct * ns);
  196. /*
  197. ** Update the controls in any active settings panels
  198. */
  199. static void update_settings_controls(INodeListClass * node_list = NULL);
  200. /*
  201. ** Modify the state of all selected nodes
  202. */
  203. static void set_hierarchy_in_all_selected(INodeListClass * list,bool onoff);
  204. static void set_geometry_in_all_selected(INodeListClass * list,bool onoff);
  205. static void enable_hidden_in_all_selected(INodeListClass * list,bool onoff);
  206. static void enable_two_sided_in_all_selected(INodeListClass * list,bool onoff);
  207. static void enable_znormals_in_all_selected(INodeListClass * list,bool onoff);
  208. static void enable_vertex_alpha_in_all_selected(INodeListClass * list,bool onoff);
  209. static void enable_shadow_in_all_selected(INodeListClass * list,bool onoff);
  210. static void enable_shatterable_in_all_selected(INodeListClass * list,bool onoff);
  211. static void enable_npatches_in_all_selected(INodeListClass * list,bool onoff);
  212. static void enable_physical_collision_in_all_selected(INodeListClass * list,bool onoff);
  213. static void enable_projectile_collision_in_all_selected(INodeListClass * list,bool onoff);
  214. static void enable_vis_collision_in_all_selected(INodeListClass * list,bool onoff);
  215. static void enable_camera_collision_in_all_selected(INodeListClass * list,bool onoff);
  216. static void enable_vehicle_collision_in_all_selected(INodeListClass * list,bool onoff);
  217. static void set_geometry_type_in_all_selected(INodeListClass * list,int geotype);
  218. static void set_dazzle_type_in_all_selected(INodeListClass * list,char * dazzletype);
  219. static void set_region_in_all_selected(INodeListClass * list,char region);
  220. /*
  221. ** Functions used by the tools rollup in the command panel
  222. */
  223. void descend_tree(INode * node,int action);
  224. void hide_node(INode * node);
  225. void select_geometry_node(INode * node);
  226. void select_hierarchy_node(INode * node);
  227. void select_alpha_node(INode * node);
  228. void select_physical_node(INode * node);
  229. void select_projectile_node(INode * node);
  230. void select_vis_node(INode * node);
  231. bool is_alpha_material(Mtl * nodemtl);
  232. bool is_alpha_mesh(INode * node,Mtl * nodemtl);
  233. void generate_names(void);
  234. void generate_node_name(INode * node);
  235. void generate_material_names(void);
  236. void generate_material_names_for_node(INode * node);
  237. void generate_material_names(Mtl * mtl);
  238. void generate_lod_extensions(void);
  239. void generate_lod_ext(INode * node);
  240. void create_floater(void);
  241. void export_with_standard_materials();
  242. int convert_materials (MaterialConversionEnum conversion, MaterialReferenceMaker *gamenodematerials);
  243. StdMat * new_standard_material (GameMtl *gamemtl);
  244. static W3DAppData0Struct * get_app_data_0(INode * node);
  245. static W3DAppData1Struct * get_app_data_1(INode * node);
  246. static W3DAppData2Struct * get_app_data_2(INode * node);
  247. static W3DDazzleAppDataStruct * get_dazzle_app_data(INode * node);
  248. };
  249. static W3DUtilityClass TheW3DUtility;
  250. /**********************************************************************************************
  251. **
  252. ** W3DUtilityClassDesc - Class Descriptor for the W3D Utility
  253. **
  254. **********************************************************************************************/
  255. class W3DUtilityClassDesc:public ClassDesc
  256. {
  257. public:
  258. int IsPublic() { return 1; }
  259. void * Create(BOOL loading = FALSE) { return &TheW3DUtility; }
  260. const TCHAR * ClassName() { return Get_String(IDS_W3D_UTILITY_CLASS_NAME); }
  261. SClass_ID SuperClassID() { return UTILITY_CLASS_ID; }
  262. Class_ID ClassID() { return W3DUtilityClassID; }
  263. const TCHAR* Category() { return Get_String(IDS_W3DMENU_CATEGORY); }
  264. };
  265. static W3DUtilityClassDesc W3DUtilityDesc;
  266. ClassDesc * Get_W3D_Utility_Desc(void)
  267. {
  268. return &W3DUtilityDesc;
  269. }
  270. /**********************************************************************************************
  271. **
  272. ** W3DUtilityClass Implementation
  273. **
  274. **********************************************************************************************/
  275. W3DUtilityClass::W3DUtilityClass(void)
  276. {
  277. InterfacePtr = NULL;
  278. SettingsPanelHWND = NULL;
  279. ToolsPanelHWND = NULL;
  280. UpdateSpinnerValue = true;
  281. }
  282. W3DUtilityClass::~W3DUtilityClass(void)
  283. {
  284. }
  285. void W3DUtilityClass::BeginEditParams(Interface *ip,IUtil *iu)
  286. {
  287. InterfacePtr = ip;
  288. SettingsPanelHWND = InterfacePtr->AddRollupPage(
  289. AppInstance,
  290. MAKEINTRESOURCE(IDD_W3DUTILITY_SETTINGS_DIALOG),
  291. _settings_form_dlg_proc,
  292. Get_String(IDS_W3DUTILITY_SETTINGS),
  293. 0);
  294. ToolsPanelHWND = InterfacePtr->AddRollupPage(
  295. AppInstance,
  296. MAKEINTRESOURCE(IDD_W3DUTILITY_TOOLS_DIALOG),
  297. _w3d_utility_tools_dlg_proc,
  298. Get_String(IDS_W3DUTILITY_TOOLS),
  299. 0);
  300. // TheRCMenu.Bind(TheW3DUtility.InterfacePtr,&TheW3DUtility);
  301. // RightClickMenuManager *rcm = ip->GetRightClickMenuManager();
  302. // if (TheRCMenu.Installed!=TRUE) {
  303. // rcm->Register(&TheRCMenu);
  304. // }
  305. SettingsFormClass::Update_All_Instances();
  306. }
  307. void W3DUtilityClass::EndEditParams(Interface *ip,IUtil *iu)
  308. {
  309. InterfacePtr = NULL;
  310. ip->DeleteRollupPage(SettingsPanelHWND);
  311. ip->DeleteRollupPage(ToolsPanelHWND);
  312. SettingsPanelHWND = NULL;
  313. ToolsPanelHWND = NULL;
  314. }
  315. void W3DUtilityClass::SelectionSetChanged(Interface *ip,IUtil *iu)
  316. {
  317. // (gth) the settings panels which need to respond to the selection set changing
  318. // are now registered directly with MAX and don't need to be updated here
  319. // update_dialog();
  320. }
  321. int W3DUtilityClass::eval_tri_state(int totalcount,int oncount)
  322. {
  323. if (oncount == 0) {
  324. return 0;
  325. }
  326. if (oncount == totalcount) {
  327. return 1;
  328. }
  329. return 2;
  330. }
  331. void W3DUtilityClass::eval_node_states(INodeListClass * list,NodeStatesStruct * ns)
  332. {
  333. // initialize the counters and booleans
  334. ns->ExportHierarchy = 0;
  335. ns->ExportGeometry = 0;
  336. ns->GeometryHidden = 0;
  337. ns->GeometryTwoSided = 0;
  338. ns->GeometryZNormals = 0;
  339. ns->GeometryVertexAlpha = 0;
  340. ns->GeometryCastShadow = 0;
  341. ns->GeometryShatterable = 0;
  342. ns->GeometryNPatch = 0;
  343. ns->CollisionPhysical = 0;
  344. ns->CollisionProjectile = 0;
  345. ns->CollisionVis = 0;
  346. ns->CollisionCamera = 0;
  347. ns->CollisionVehicle = 0;
  348. ns->GeometryCameraAligned = false;
  349. ns->GeometryCameraOriented = false;
  350. ns->GeometryNormal = false;
  351. ns->GeometryAABox = false;
  352. ns->GeometryOBBox = false;
  353. ns->GeometryNull = false;
  354. ns->GeometryDazzle = false;
  355. ns->GeometryAggregate = false;
  356. /*
  357. ** ns->DamageRegion will be MAX_DAMAGE_REGIONS if not all
  358. ** of the selected nodes are in the same damage region. If
  359. ** they are, then ns->DamageRegion will be the region they
  360. ** share.
  361. */
  362. if (list->Num_Nodes() > 0)
  363. {
  364. // Use the first damage region for comparing to the others.
  365. W3DAppData1Struct *wdata = get_app_data_1((*list)[0]);
  366. ns->DamageRegion = wdata->DamageRegion;
  367. }
  368. else
  369. ns->DamageRegion = MAX_DAMAGE_REGIONS;
  370. /*
  371. ** ns->DazzleType will be DEFAULT if not all of the selected
  372. ** nodes are the same. If they are the same, it will be the
  373. ** dazzle type that they all share
  374. */
  375. ns->DazzleCount = 0;
  376. if (list->Num_Nodes() > 0) {
  377. W3DDazzleAppDataStruct * dazzledata = get_dazzle_app_data((*list)[0]);
  378. strncpy(ns->DazzleType,dazzledata->DazzleType,sizeof(ns->DazzleType));
  379. } else {
  380. strcpy(ns->DazzleType,"DEFAULT");
  381. }
  382. /*
  383. ** evaluate each node
  384. */
  385. for (unsigned int ni=0; ni<list->Num_Nodes(); ni++) {
  386. W3DAppData2Struct * wdata = get_app_data_2((*list)[ni]);
  387. assert(wdata);
  388. ns->ExportHierarchy += (wdata->Is_Bone() ? 1 : 0);
  389. ns->ExportGeometry += (wdata->Is_Geometry() ? 1 : 0);
  390. ns->GeometryHidden += (wdata->Is_Hidden_Enabled() ? 1 : 0);
  391. ns->GeometryTwoSided += (wdata->Is_Two_Sided_Enabled() ? 1 : 0);
  392. ns->GeometryZNormals += (wdata->Is_ZNormals_Enabled() ? 1 : 0);
  393. ns->GeometryVertexAlpha += (wdata->Is_Vertex_Alpha_Enabled() ? 1 : 0);
  394. ns->GeometryCastShadow += (wdata->Is_Shadow_Enabled() ? 1 : 0);
  395. ns->GeometryShatterable += (wdata->Is_Shatterable_Enabled() ? 1 : 0);
  396. ns->GeometryNPatch += (wdata->Is_NPatchable_Enabled() ? 1 : 0);
  397. ns->CollisionPhysical += (wdata->Is_Physical_Collision_Enabled() ? 1 : 0);
  398. ns->CollisionProjectile += (wdata->Is_Projectile_Collision_Enabled() ? 1 : 0);
  399. ns->CollisionVis += (wdata->Is_Vis_Collision_Enabled() ? 1 : 0);
  400. ns->CollisionCamera += (wdata->Is_Camera_Collision_Enabled() ? 1 : 0);
  401. ns->CollisionVehicle += (wdata->Is_Vehicle_Collision_Enabled() ? 1 : 0);
  402. switch (wdata->Get_Geometry_Type()) {
  403. case W3DAppData2Struct::GEO_TYPE_CAMERA_ALIGNED: ns->GeometryCameraAligned = true; break;
  404. case W3DAppData2Struct::GEO_TYPE_CAMERA_ORIENTED: ns->GeometryCameraOriented = true; break;
  405. case W3DAppData2Struct::GEO_TYPE_NORMAL_MESH: ns->GeometryNormal = true; break;
  406. case W3DAppData2Struct::GEO_TYPE_AABOX: ns->GeometryAABox = true; break;
  407. case W3DAppData2Struct::GEO_TYPE_OBBOX: ns->GeometryOBBox = true; break;
  408. case W3DAppData2Struct::GEO_TYPE_NULL: ns->GeometryNull = true; break;
  409. case W3DAppData2Struct::GEO_TYPE_DAZZLE: ns->GeometryDazzle = true; ns->DazzleCount++; break;
  410. case W3DAppData2Struct::GEO_TYPE_AGGREGATE: ns->GeometryAggregate = true; break;
  411. }
  412. // Compare this damage region to our existing one. If it's not the same,
  413. // use MAX_DAMAGE_REGION (an invalid value) as a sentinel value.
  414. if (ns->DamageRegion != MAX_DAMAGE_REGIONS)
  415. {
  416. W3DAppData1Struct *wdata1 = get_app_data_1((*list)[ni]);
  417. assert(wdata1);
  418. if (wdata1->DamageRegion != ns->DamageRegion)
  419. ns->DamageRegion = MAX_DAMAGE_REGIONS;
  420. }
  421. // compare this objects dazzle type to our existing one. If its not
  422. // the same, use 'DEFAULT'.
  423. W3DDazzleAppDataStruct * dazzledata = get_dazzle_app_data((*list)[ni]);
  424. if (strcmp(ns->DazzleType,dazzledata->DazzleType) != 0) {
  425. strcpy(ns->DazzleType,"DEFAULT");
  426. }
  427. }
  428. // If any of the counters are zero, that means none of the objects had that
  429. // bit set. If any of them are equal to the number of objects, then they
  430. // all had that bit set. Otherwise, there was a mix and we should use the
  431. // third state for the checkbox (greyed out check).
  432. int count = list->Num_Nodes();
  433. ns->ExportHierarchy = eval_tri_state(count, ns->ExportHierarchy);
  434. ns->ExportGeometry = eval_tri_state(count, ns->ExportGeometry);
  435. ns->GeometryHidden = eval_tri_state(count, ns->GeometryHidden);
  436. ns->GeometryTwoSided = eval_tri_state(count, ns->GeometryTwoSided);
  437. ns->GeometryZNormals = eval_tri_state(count, ns->GeometryZNormals);
  438. ns->GeometryVertexAlpha = eval_tri_state(count, ns->GeometryVertexAlpha);
  439. ns->GeometryCastShadow = eval_tri_state(count, ns->GeometryCastShadow);
  440. ns->GeometryShatterable = eval_tri_state(count, ns->GeometryShatterable);
  441. ns->GeometryNPatch = eval_tri_state(count, ns->GeometryNPatch);
  442. ns->CollisionPhysical = eval_tri_state(count, ns->CollisionPhysical);
  443. ns->CollisionProjectile = eval_tri_state(count, ns->CollisionProjectile);
  444. ns->CollisionVis = eval_tri_state(count, ns->CollisionVis);
  445. ns->CollisionCamera = eval_tri_state(count, ns->CollisionCamera);
  446. ns->CollisionVehicle = eval_tri_state(count, ns->CollisionVehicle);
  447. }
  448. void W3DUtilityClass::update_settings_controls(INodeListClass * node_list)
  449. {
  450. SettingsFormClass::Update_All_Instances();
  451. }
  452. void W3DUtilityClass::set_hierarchy_in_all_selected(INodeListClass * node_list,bool onoff)
  453. {
  454. for (unsigned int ni=0; ni<node_list->Num_Nodes(); ni++) {
  455. W3DAppData2Struct * wdata = get_app_data_2((*node_list)[ni]);
  456. wdata->Enable_Export_Transform(onoff);
  457. }
  458. update_settings_controls(node_list);
  459. }
  460. void W3DUtilityClass::set_geometry_in_all_selected(INodeListClass * node_list,bool onoff)
  461. {
  462. for (unsigned int ni=0; ni<node_list->Num_Nodes(); ni++) {
  463. W3DAppData2Struct * wdata = get_app_data_2((*node_list)[ni]);
  464. wdata->Enable_Export_Geometry(onoff);
  465. }
  466. update_settings_controls(node_list);
  467. }
  468. void W3DUtilityClass::enable_hidden_in_all_selected(INodeListClass * node_list,bool onoff)
  469. {
  470. for (unsigned int ni=0; ni<node_list->Num_Nodes(); ni++) {
  471. W3DAppData2Struct * wdata = get_app_data_2((*node_list)[ni]);
  472. wdata->Enable_Hidden(onoff);
  473. }
  474. update_settings_controls(node_list);
  475. }
  476. void W3DUtilityClass::enable_two_sided_in_all_selected(INodeListClass * node_list,bool onoff)
  477. {
  478. for (unsigned int ni=0; ni<node_list->Num_Nodes(); ni++) {
  479. W3DAppData2Struct * wdata = get_app_data_2((*node_list)[ni]);
  480. wdata->Enable_Two_Sided(onoff);
  481. }
  482. update_settings_controls(node_list);
  483. }
  484. void W3DUtilityClass::enable_znormals_in_all_selected(INodeListClass * node_list,bool onoff)
  485. {
  486. for (unsigned int ni=0; ni<node_list->Num_Nodes(); ni++) {
  487. W3DAppData2Struct * wdata = get_app_data_2((*node_list)[ni]);
  488. wdata->Enable_ZNormals(onoff);
  489. }
  490. update_settings_controls(node_list);
  491. }
  492. void W3DUtilityClass::enable_vertex_alpha_in_all_selected(INodeListClass * node_list,bool onoff)
  493. {
  494. for (unsigned int ni=0; ni<node_list->Num_Nodes(); ni++) {
  495. W3DAppData2Struct * wdata = get_app_data_2((*node_list)[ni]);
  496. wdata->Enable_Vertex_Alpha(onoff);
  497. }
  498. update_settings_controls(node_list);
  499. }
  500. void W3DUtilityClass::enable_shadow_in_all_selected(INodeListClass * node_list,bool onoff)
  501. {
  502. for (unsigned int ni=0; ni<node_list->Num_Nodes(); ni++) {
  503. W3DAppData2Struct * wdata = get_app_data_2((*node_list)[ni]);
  504. wdata->Enable_Shadow(onoff);
  505. }
  506. update_settings_controls(node_list);
  507. }
  508. void W3DUtilityClass::enable_shatterable_in_all_selected(INodeListClass * node_list,bool onoff)
  509. {
  510. for (unsigned int ni=0; ni<node_list->Num_Nodes(); ni++) {
  511. W3DAppData2Struct * wdata = get_app_data_2((*node_list)[ni]);
  512. wdata->Enable_Shatterable(onoff);
  513. }
  514. update_settings_controls(node_list);
  515. }
  516. void W3DUtilityClass::enable_npatches_in_all_selected(INodeListClass * node_list,bool onoff)
  517. {
  518. for (unsigned int ni=0; ni<node_list->Num_Nodes(); ni++) {
  519. W3DAppData2Struct * wdata = get_app_data_2((*node_list)[ni]);
  520. wdata->Enable_NPatchable(onoff);
  521. }
  522. update_settings_controls(node_list);
  523. }
  524. void W3DUtilityClass::enable_physical_collision_in_all_selected(INodeListClass * node_list,bool onoff)
  525. {
  526. for (unsigned int ni=0; ni<node_list->Num_Nodes(); ni++) {
  527. W3DAppData2Struct * wdata = get_app_data_2((*node_list)[ni]);
  528. wdata->Enable_Physical_Collision(onoff);
  529. }
  530. update_settings_controls(node_list);
  531. }
  532. void W3DUtilityClass::enable_projectile_collision_in_all_selected(INodeListClass * node_list,bool onoff)
  533. {
  534. for (unsigned int ni=0; ni<node_list->Num_Nodes(); ni++) {
  535. W3DAppData2Struct * wdata = get_app_data_2((*node_list)[ni]);
  536. wdata->Enable_Projectile_Collision(onoff);
  537. }
  538. update_settings_controls(node_list);
  539. }
  540. void W3DUtilityClass::enable_vis_collision_in_all_selected(INodeListClass * node_list,bool onoff)
  541. {
  542. for (unsigned int ni=0; ni<node_list->Num_Nodes(); ni++) {
  543. W3DAppData2Struct * wdata = get_app_data_2((*node_list)[ni]);
  544. wdata->Enable_Vis_Collision(onoff);
  545. }
  546. update_settings_controls(node_list);
  547. }
  548. void W3DUtilityClass::enable_camera_collision_in_all_selected(INodeListClass * node_list,bool onoff)
  549. {
  550. for (unsigned int ni=0; ni<node_list->Num_Nodes(); ni++) {
  551. W3DAppData2Struct * wdata = get_app_data_2((*node_list)[ni]);
  552. wdata->Enable_Camera_Collision(onoff);
  553. }
  554. update_settings_controls(node_list);
  555. }
  556. void W3DUtilityClass::enable_vehicle_collision_in_all_selected(INodeListClass * node_list,bool onoff)
  557. {
  558. for (unsigned int ni=0; ni<node_list->Num_Nodes(); ni++) {
  559. W3DAppData2Struct * wdata = get_app_data_2((*node_list)[ni]);
  560. wdata->Enable_Vehicle_Collision(onoff);
  561. }
  562. update_settings_controls(node_list);
  563. }
  564. void W3DUtilityClass::set_geometry_type_in_all_selected(INodeListClass * node_list,int geotype)
  565. {
  566. for (unsigned int ni=0; ni<node_list->Num_Nodes(); ni++) {
  567. W3DAppData2Struct * wdata = get_app_data_2((*node_list)[ni]);
  568. wdata->Set_Geometry_Type((W3DAppData2Struct::GeometryTypeEnum)geotype);
  569. }
  570. update_settings_controls(node_list);
  571. }
  572. void W3DUtilityClass::set_dazzle_type_in_all_selected(INodeListClass * node_list,char * dazzle_type)
  573. {
  574. for (unsigned int ni=0; ni<node_list->Num_Nodes(); ni++) {
  575. W3DDazzleAppDataStruct * dazzledata = get_dazzle_app_data((*node_list)[ni]);
  576. strncpy(dazzledata->DazzleType,dazzle_type,sizeof(dazzledata->DazzleType) - 1);
  577. }
  578. update_settings_controls(node_list);
  579. }
  580. void W3DUtilityClass::set_region_in_all_selected(INodeListClass * list,char region)
  581. {
  582. if (list->Num_Nodes() == 0) return;
  583. // Damage regions are stored in each node's AppData1.
  584. for (int i = 0; i < list->Num_Nodes(); i++)
  585. {
  586. W3DAppData1Struct *wdata = get_app_data_1((*list)[i]);
  587. wdata->DamageRegion = region;
  588. }
  589. update_settings_controls(list);
  590. }
  591. void W3DUtilityClass::generate_names(void)
  592. {
  593. GenNamesDialogClass dialog(InterfacePtr);
  594. bool retval = dialog.Get_Options(&NameOptions);
  595. WorkingNameIndex = NameOptions.NameIndex;
  596. if (retval) {
  597. descend_tree(InterfacePtr->GetRootNode(),GENERATE_NAME);
  598. }
  599. }
  600. void W3DUtilityClass::generate_material_names(void)
  601. {
  602. GenMtlNamesDialogClass dialog(InterfacePtr);
  603. bool retval = dialog.Get_Options(&MtlNameOptions);
  604. WorkingNameIndex = MtlNameOptions.NameIndex;
  605. if (retval) {
  606. descend_tree(InterfacePtr->GetRootNode(),GENERATE_MATERIAL_NAME);
  607. }
  608. }
  609. void W3DUtilityClass::generate_lod_extensions(void)
  610. {
  611. GenLodExtensionDialogClass dialog(InterfacePtr);
  612. bool retval = dialog.Get_Options(&LodExtensionOptions);
  613. if (retval) {
  614. descend_tree(InterfacePtr->GetRootNode(),GENERATE_LOD_EXTENSION);
  615. }
  616. }
  617. void W3DUtilityClass::generate_lod_ext(INode * node)
  618. {
  619. /*
  620. ** Only works on selected nodes.
  621. */
  622. if (!node->Selected())
  623. return;
  624. /*
  625. ** If this node already has an LOD extension, we'll replace it
  626. ** with the new LOD index. Otherwise we'll tack it on the end.
  627. ** Display a error message if the name is too long to append
  628. ** the extension, and skip the node without changing the name.
  629. */
  630. char msg[256];
  631. char newname[W3D_NAME_LEN];
  632. char *oldname = node->GetName();
  633. char *ext = strrchr(oldname, '.');
  634. int old_lod;
  635. if ( (ext != NULL) && (sscanf(ext, ".%d", &old_lod) == 1) )
  636. {
  637. /*
  638. ** An existing LOD index. If it's different than the new
  639. ** one, replace it.
  640. */
  641. if (old_lod == LodExtensionOptions.LodIndex)
  642. return; // same lod index
  643. /*
  644. ** Room for the new extension? (2 because when we export, the extension will,
  645. ** be replaced by a single character [A..Z] to indicate the LOD level.
  646. ** ie. 2==strlen("A")+1)
  647. */
  648. if (ext - oldname + 2 <= W3D_NAME_LEN)
  649. {
  650. *ext = '\0';
  651. sprintf(newname, "%s.%02d", oldname, LodExtensionOptions.LodIndex);
  652. *ext = '.';
  653. node->SetName(newname);
  654. }
  655. else
  656. {
  657. *ext = '\0';
  658. sprintf(msg, "The maximum W3D object name is %d characters. Adding the LOD "
  659. "extension to \"%s\" will pass this limit! Please shorten its name.",
  660. W3D_NAME_LEN - 1, oldname);
  661. *ext = '.';
  662. MessageBox(NULL, msg, "Error", MB_OK);
  663. }
  664. }
  665. else
  666. {
  667. /*
  668. ** Room for the new extension? (2 because when we export, the extension will,
  669. ** be replaced by a single character [A..Z] to indicate the LOD level.
  670. ** ie. 2==strlen("A")+1)
  671. */
  672. if (strlen(oldname) + 2 <= W3D_NAME_LEN)
  673. {
  674. sprintf(newname, "%s.%02d", oldname, LodExtensionOptions.LodIndex);
  675. node->SetName(newname);
  676. }
  677. else
  678. {
  679. sprintf(msg, "The maximum W3D object name is %d characters. Adding the LOD "
  680. "extension to \"%s\" will pass this limit! Please shorten its name.",
  681. W3D_NAME_LEN - 1, oldname);
  682. MessageBox(NULL, msg, "Error", MB_OK);
  683. }
  684. }
  685. }
  686. void W3DUtilityClass::create_floater(void)
  687. {
  688. SettingsFloater.Create(InterfacePtr,IDD_W3DUTILITY_SETTINGS_DIALOG,_settings_form_dlg_proc);
  689. SettingsFormClass::Update_All_Instances();
  690. }
  691. void W3DUtilityClass::export_with_standard_materials()
  692. {
  693. char *convertingmessage = "Converting materials...";
  694. // Count the no. of references to game materials.
  695. MaterialReferenceMaker::ReferenceCount = convert_materials (GAME_REFERENCE_COUNT, NULL);
  696. MaterialReferenceMaker *gamenodematerials = NULL;
  697. if (MaterialReferenceMaker::ReferenceCount > 0) {
  698. gamenodematerials = new MaterialReferenceMaker [MaterialReferenceMaker::ReferenceCount];
  699. assert (gamenodematerials != NULL);
  700. }
  701. InterfacePtr->PushPrompt (convertingmessage);
  702. SetCursor (LoadCursor (NULL, IDC_WAIT));
  703. convert_materials (GAME_TO_STANDARD, gamenodematerials);
  704. InterfacePtr->PopPrompt();
  705. InterfacePtr->FileExport();
  706. UpdateWindow (InterfacePtr->GetMAXHWnd());
  707. InterfacePtr->PushPrompt (convertingmessage);
  708. SetCursor (LoadCursor (NULL, IDC_WAIT));
  709. convert_materials (STANDARD_TO_GAME, gamenodematerials);
  710. InterfacePtr->PopPrompt();
  711. // Clean-up.
  712. if (gamenodematerials != NULL) delete [] gamenodematerials;
  713. }
  714. int W3DUtilityClass::convert_materials (MaterialConversionEnum conversion, MaterialReferenceMaker *gamenodematerials)
  715. {
  716. int gamenodematerialindex = 0;
  717. INode *rootnode = InterfacePtr->GetRootNode();
  718. if (rootnode != NULL) {
  719. INodeListClass *meshlist = new INodeListClass (rootnode, 0);
  720. if (meshlist != NULL) {
  721. for (unsigned nodeindex = 0; nodeindex < meshlist->Num_Nodes(); nodeindex++) {
  722. Mtl *nodemtl = ((*meshlist) [nodeindex])->GetMtl();
  723. // Is this a non-null material?
  724. if (nodemtl != NULL) {
  725. // Is this not a multi-material?
  726. if (!nodemtl->IsMultiMtl()) {
  727. switch (conversion) {
  728. case GAME_REFERENCE_COUNT:
  729. if (nodemtl->ClassID() == GameMaterialClassID) {
  730. assert (((GameMtl*) nodemtl)->Substitute_Material() == NULL);
  731. }
  732. break;
  733. case GAME_TO_STANDARD:
  734. if (nodemtl->ClassID() == GameMaterialClassID) {
  735. // Make a reference to the game material to ensure that it is not deleted by the system.
  736. gamenodematerials [gamenodematerialindex].MakeRefByID (FOREVER, gamenodematerialindex, nodemtl);
  737. // Does this material already have an equivalent standard material?
  738. if (((GameMtl*) nodemtl)->Substitute_Material() == NULL) {
  739. ((GameMtl*) nodemtl)->Set_Substitute_Material (new_standard_material ((GameMtl*) nodemtl));
  740. }
  741. ((*meshlist) [nodeindex])->SetMtl (((GameMtl*) nodemtl)->Substitute_Material());
  742. } else {
  743. gamenodematerials [gamenodematerialindex].MaterialPtr = NULL;
  744. }
  745. break;
  746. case STANDARD_TO_GAME:
  747. // Change materials to game materials if they were previously game materials before being
  748. // converted to standard materials.
  749. if (gamenodematerials [gamenodematerialindex].MaterialPtr != NULL) {
  750. ((*meshlist) [nodeindex])->SetMtl (gamenodematerials [gamenodematerialindex].MaterialPtr);
  751. ((GameMtl*) gamenodematerials [gamenodematerialindex].MaterialPtr)->Set_Substitute_Material (NULL);
  752. }
  753. break;
  754. }
  755. gamenodematerialindex++;
  756. } else {
  757. // For each sub-material...
  758. for (int materialindex = 0; materialindex < nodemtl->NumSubMtls(); materialindex++) {
  759. Mtl *submaterial = nodemtl->GetSubMtl (materialindex);
  760. // Is this a non-null submaterial?
  761. if (submaterial != NULL) {
  762. switch (conversion) {
  763. case GAME_REFERENCE_COUNT:
  764. if (submaterial->ClassID() == GameMaterialClassID) {
  765. assert (((GameMtl*) submaterial)->Substitute_Material() == NULL);
  766. }
  767. break;
  768. case GAME_TO_STANDARD:
  769. if (submaterial->ClassID() == GameMaterialClassID) {
  770. // Make a reference to the game material to ensure that it is not deleted by the system.
  771. gamenodematerials [gamenodematerialindex].MakeRefByID (FOREVER, gamenodematerialindex, submaterial);
  772. // Does this material already have an equivalent standard material?
  773. if (((GameMtl*) submaterial)->Substitute_Material() == NULL) {
  774. ((GameMtl*) submaterial)->Set_Substitute_Material (new_standard_material ((GameMtl*) submaterial));
  775. }
  776. nodemtl->SetSubMtl (materialindex, ((GameMtl*) submaterial)->Substitute_Material());
  777. } else {
  778. gamenodematerials [gamenodematerialindex].MaterialPtr = NULL;
  779. }
  780. break;
  781. case STANDARD_TO_GAME:
  782. // Change materials to game materials if they were previously game materials before being
  783. // converted to standard materials.
  784. if (gamenodematerials [gamenodematerialindex].MaterialPtr != NULL) {
  785. nodemtl->SetSubMtl (materialindex, gamenodematerials [gamenodematerialindex].MaterialPtr);
  786. ((GameMtl*) gamenodematerials [gamenodematerialindex].MaterialPtr)->Set_Substitute_Material (NULL);
  787. }
  788. break;
  789. }
  790. gamenodematerialindex++;
  791. }
  792. }
  793. }
  794. }
  795. }
  796. // Clean-up.
  797. delete meshlist;
  798. }
  799. }
  800. return (gamenodematerialindex);
  801. }
  802. StdMat *W3DUtilityClass::new_standard_material (GameMtl *gamemtl)
  803. {
  804. Color emissive;
  805. // Create a new standard material.
  806. StdMat *stdmtl = NewDefaultStdMat();
  807. // Set its properties by translating the supplied game material.
  808. // NOTE 0: Only consider pass 0 in the game material - ignore all other passes.
  809. // NOTE 1: Use defaults for all standard material attributes that cannot be
  810. // converted from the game material in a meaningful way.
  811. stdmtl->SetName (gamemtl->GetName());
  812. stdmtl->SetAmbient (gamemtl->GetAmbient(), 0);
  813. stdmtl->SetDiffuse (gamemtl->GetDiffuse(), 0);
  814. stdmtl->SetSpecular (gamemtl->GetSpecular(), 0);
  815. stdmtl->SetOpacity (gamemtl->Get_Opacity (0, 0), 0);
  816. stdmtl->SetShininess (gamemtl->Get_Shininess (0, 0), 0);
  817. stdmtl->SetShinStr (gamemtl->GetShinStr(), 0);
  818. stdmtl->SetSubTexmap (ID_DI, gamemtl->Get_Texture (0, 0));
  819. emissive = gamemtl->Get_Emissive (0, 0);
  820. stdmtl->SetSelfIllum ((emissive.r + emissive.g + emissive.b) / 3.0f, 0);
  821. return (stdmtl);
  822. }
  823. void W3DUtilityClass::Select_Hierarchy(void)
  824. {
  825. InterfacePtr->SelectNode(NULL);
  826. INode * root = InterfacePtr->GetRootNode();
  827. descend_tree(root,SELECT_HIER);
  828. InterfacePtr->ForceCompleteRedraw();
  829. }
  830. void W3DUtilityClass::Select_Geometry(void)
  831. {
  832. InterfacePtr->SelectNode(NULL);
  833. INode * root = InterfacePtr->GetRootNode();
  834. descend_tree(root,SELECT_GEOM);
  835. InterfacePtr->ForceCompleteRedraw();
  836. }
  837. void W3DUtilityClass::Select_Alpha(void)
  838. {
  839. InterfacePtr->SelectNode(NULL);
  840. INode * root = InterfacePtr->GetRootNode();
  841. descend_tree(root,SELECT_ALPHA);
  842. InterfacePtr->ForceCompleteRedraw();
  843. }
  844. void W3DUtilityClass::Select_Physical(void)
  845. {
  846. InterfacePtr->SelectNode(NULL);
  847. INode * root = InterfacePtr->GetRootNode();
  848. descend_tree(root,SELECT_PHYSICAL);
  849. InterfacePtr->ForceCompleteRedraw();
  850. }
  851. void W3DUtilityClass::Select_Projectile(void)
  852. {
  853. InterfacePtr->SelectNode(NULL);
  854. INode * root = InterfacePtr->GetRootNode();
  855. descend_tree(root,SELECT_PROJECTILE);
  856. InterfacePtr->ForceCompleteRedraw();
  857. }
  858. void W3DUtilityClass::Select_Vis(void)
  859. {
  860. InterfacePtr->SelectNode(NULL);
  861. INode * root = InterfacePtr->GetRootNode();
  862. descend_tree(root,SELECT_VIS);
  863. InterfacePtr->ForceCompleteRedraw();
  864. }
  865. void W3DUtilityClass::descend_tree(INode * node,int func)
  866. {
  867. if (!node) return;
  868. switch (func)
  869. {
  870. case HIDE:
  871. hide_node(node);
  872. break;
  873. case SELECT_GEOM:
  874. select_geometry_node(node);
  875. break;
  876. case SELECT_HIER:
  877. select_hierarchy_node(node);
  878. break;
  879. case SELECT_ALPHA:
  880. select_alpha_node(node);
  881. break;
  882. case SELECT_PHYSICAL:
  883. select_physical_node(node);
  884. break;
  885. case SELECT_PROJECTILE:
  886. select_projectile_node(node);
  887. break;
  888. case SELECT_VIS:
  889. select_vis_node(node);
  890. break;
  891. case GENERATE_NAME:
  892. generate_node_name(node);
  893. break;
  894. case GENERATE_MATERIAL_NAME:
  895. generate_material_names_for_node(node);
  896. break;
  897. case GENERATE_LOD_EXTENSION:
  898. generate_lod_ext(node);
  899. break;
  900. default:
  901. break;
  902. };
  903. for (int i=0; i<node->NumberOfChildren(); i++) {
  904. INode * child = node->GetChildNode(i);
  905. descend_tree(child,func);
  906. }
  907. }
  908. void W3DUtilityClass::hide_node(INode * node)
  909. {
  910. if (!node->IsHidden()) node->Hide(TRUE);
  911. InterfacePtr->NodeInvalidateRect(node);
  912. }
  913. void W3DUtilityClass::select_geometry_node(INode * node)
  914. {
  915. if (Is_Geometry(node) && !node->IsHidden()) {
  916. InterfacePtr->SelectNode(node,0);
  917. }
  918. }
  919. void W3DUtilityClass::select_hierarchy_node(INode * node)
  920. {
  921. if (Is_Bone(node) && !node->IsHidden()) {
  922. InterfacePtr->SelectNode(node,0);
  923. }
  924. }
  925. void W3DUtilityClass::select_alpha_node(INode * node)
  926. {
  927. if (node->IsHidden() || !Is_Geometry(node)) {
  928. return;
  929. }
  930. Mtl * nodemtl = node->GetMtl();
  931. if (is_alpha_material(nodemtl)) {
  932. if (is_alpha_mesh(node,nodemtl)) {
  933. InterfacePtr->SelectNode(node,0);
  934. }
  935. }
  936. }
  937. void W3DUtilityClass::select_physical_node(INode * node)
  938. {
  939. if (!node->IsHidden() && Is_Geometry(node) && Is_Physical_Collision(node)) {
  940. InterfacePtr->SelectNode(node,0);
  941. }
  942. }
  943. void W3DUtilityClass::select_projectile_node(INode * node)
  944. {
  945. if (!node->IsHidden() && Is_Geometry(node) && Is_Projectile_Collision(node)) {
  946. InterfacePtr->SelectNode(node,0);
  947. }
  948. }
  949. void W3DUtilityClass::select_vis_node(INode * node)
  950. {
  951. if (!node->IsHidden() && Is_Geometry(node) && Is_Vis_Collision(node)) {
  952. InterfacePtr->SelectNode(node,0);
  953. }
  954. }
  955. bool W3DUtilityClass::is_alpha_material(Mtl * nodemtl)
  956. {
  957. if (nodemtl == NULL) {
  958. return false;
  959. }
  960. bool is_alpha = false;
  961. if (nodemtl->IsMultiMtl()) {
  962. for (int mi=0; mi<nodemtl->NumSubMtls(); mi++) {
  963. is_alpha |= is_alpha_material(nodemtl->GetSubMtl(mi));
  964. }
  965. } else {
  966. if (nodemtl->ClassID() == GameMaterialClassID) {
  967. GameMtl * gamemtl = (GameMtl *)nodemtl;
  968. if ( (gamemtl->Get_Dest_Blend(0) == W3DSHADER_DESTBLENDFUNC_SRC_ALPHA) ||
  969. (gamemtl->Get_Dest_Blend(0) == W3DSHADER_DESTBLENDFUNC_ONE_MINUS_SRC_ALPHA) ||
  970. (gamemtl->Get_Src_Blend(0) == W3DSHADER_SRCBLENDFUNC_SRC_ALPHA) ||
  971. (gamemtl->Get_Src_Blend(0) == W3DSHADER_SRCBLENDFUNC_ONE_MINUS_SRC_ALPHA) ||
  972. (gamemtl->Get_Alpha_Test(0) == W3DSHADER_ALPHATEST_ENABLE) )
  973. {
  974. is_alpha = true;
  975. }
  976. }
  977. }
  978. return is_alpha;
  979. }
  980. bool W3DUtilityClass::is_alpha_mesh(INode * node,Mtl * nodemtl)
  981. {
  982. Object * obj = node->EvalWorldState(0).obj;
  983. TriObject * tri = (TriObject *)obj->ConvertToType(0, triObjectClassID);
  984. if (tri != NULL) {
  985. Mesh & mesh = tri->mesh;
  986. int face_index;
  987. int mat_index;
  988. if (nodemtl == NULL) {
  989. return false;
  990. } else if (nodemtl->NumSubMtls() <= 1) {
  991. return is_alpha_material(nodemtl);
  992. } else {
  993. int sub_mtl_count = nodemtl->NumSubMtls();
  994. bool * sub_mtl_flags = new bool[sub_mtl_count];
  995. // Initialize each sub-material flag to false (indicates that the material is un-used)
  996. for (mat_index=0; mat_index<sub_mtl_count; mat_index++) {
  997. sub_mtl_flags[mat_index] = false;
  998. }
  999. // Set a true for each material actually referenced by the mesh
  1000. for (face_index=0; face_index<mesh.getNumFaces(); face_index++) {
  1001. int max_mat_index = mesh.faces[face_index].getMatID();
  1002. int mat_index = (max_mat_index % sub_mtl_count);
  1003. sub_mtl_flags[mat_index] = true;
  1004. }
  1005. // Loop over the used materials and return true if any are alpha materials
  1006. for (mat_index=0; mat_index<sub_mtl_count; mat_index++) {
  1007. if (sub_mtl_flags[mat_index]) {
  1008. if (is_alpha_material(nodemtl->GetSubMtl(mat_index))) {
  1009. return true;
  1010. }
  1011. }
  1012. }
  1013. }
  1014. }
  1015. return false;
  1016. }
  1017. void W3DUtilityClass::generate_node_name(INode * node)
  1018. {
  1019. TCHAR temp_string[256];
  1020. if (NameOptions.OnlyAffectSelected && !node->Selected()) {
  1021. return;
  1022. }
  1023. if (!Is_Bone(node) && !Is_Geometry(node)) {
  1024. return;
  1025. }
  1026. if (NameOptions.AssignNames) {
  1027. _stprintf(temp_string,"%s%03d",NameOptions.RootName,WorkingNameIndex);
  1028. node->SetName(temp_string);
  1029. WorkingNameIndex++;
  1030. }
  1031. if (NameOptions.AssignPrefix) {
  1032. _stprintf(temp_string,"%s%s",NameOptions.PrefixName,node->GetName());
  1033. node->SetName(temp_string);
  1034. }
  1035. if (NameOptions.AssignSuffix) {
  1036. _stprintf(temp_string,"%s%s",node->GetName(),NameOptions.SuffixName);
  1037. node->SetName(temp_string);
  1038. }
  1039. if (NameOptions.AssignCollisionBits) {
  1040. W3DAppData2Struct * wdata = W3DAppData2Struct::Get_App_Data(node);
  1041. assert(wdata);
  1042. wdata->Enable_Physical_Collision(NameOptions.PhysicalCollision);
  1043. wdata->Enable_Projectile_Collision(NameOptions.ProjectileCollision);
  1044. wdata->Enable_Vis_Collision(NameOptions.VisCollision);
  1045. wdata->Enable_Camera_Collision(NameOptions.CameraCollision);
  1046. wdata->Enable_Vehicle_Collision(NameOptions.VehicleCollision);
  1047. }
  1048. }
  1049. void W3DUtilityClass::generate_material_names_for_node(INode * node)
  1050. {
  1051. if (MtlNameOptions.OnlyAffectSelected && !node->Selected()) {
  1052. return;
  1053. }
  1054. generate_material_names(node->GetMtl());
  1055. }
  1056. void W3DUtilityClass::generate_material_names(Mtl * mtl)
  1057. {
  1058. if (mtl == NULL) {
  1059. return;
  1060. }
  1061. // set the name of this material and increment the index
  1062. TCHAR newname[GenMtlNamesDialogClass::MAX_MATERIAL_NAME_LEN];
  1063. _stprintf(newname,"%s%03d",MtlNameOptions.RootName,WorkingNameIndex);
  1064. mtl->SetName(newname);
  1065. WorkingNameIndex++;
  1066. // recurse into children
  1067. if (mtl->IsMultiMtl()) {
  1068. for (int mi=0; mi<mtl->NumSubMtls(); mi++) {
  1069. generate_material_names(mtl->GetSubMtl(mi));
  1070. }
  1071. }
  1072. }
  1073. W3DAppData0Struct * W3DUtilityClass::get_app_data_0(INode * node)
  1074. {
  1075. /*
  1076. ** Try to get our AppData which has the export flags
  1077. */
  1078. W3DAppData0Struct * wdata = NULL;
  1079. AppDataChunk * appdata = node->GetAppDataChunk(W3DUtilityClassID,UTILITY_CLASS_ID,0);
  1080. /*
  1081. ** If there wasn't one, return NULL since this app data chunk is obsolete now.
  1082. ** If there was one, get the data from it
  1083. */
  1084. if (appdata) {
  1085. wdata = (W3DAppData0Struct *)(appdata->data);
  1086. }
  1087. return wdata;
  1088. }
  1089. W3DAppData1Struct * W3DUtilityClass::get_app_data_1(INode * node)
  1090. {
  1091. // Try to get our AppData which has the damage region
  1092. W3DAppData1Struct * wdata = NULL;
  1093. AppDataChunk * appdata = node->GetAppDataChunk(W3DUtilityClassID,UTILITY_CLASS_ID,1);
  1094. // If there wasn't one, add one. If there was one, get the data from it
  1095. if (appdata) {
  1096. wdata = (W3DAppData1Struct *)(appdata->data);
  1097. } else {
  1098. wdata = new W3DAppData1Struct;
  1099. node->AddAppDataChunk(W3DUtilityClassID,UTILITY_CLASS_ID,1,sizeof(W3DAppData1Struct),wdata);
  1100. appdata = node->GetAppDataChunk(W3DUtilityClassID,UTILITY_CLASS_ID,1);
  1101. assert(appdata);
  1102. }
  1103. return wdata;
  1104. }
  1105. W3DAppData2Struct * W3DUtilityClass::get_app_data_2(INode * node)
  1106. {
  1107. return W3DAppData2Struct::Get_App_Data(node);
  1108. }
  1109. W3DDazzleAppDataStruct * W3DUtilityClass::get_dazzle_app_data(INode * node)
  1110. {
  1111. return W3DDazzleAppDataStruct::Get_App_Data(node);
  1112. }
  1113. /**********************************************************************************************
  1114. **
  1115. ** Dialog procs for the W3DUtilityClass
  1116. **
  1117. **********************************************************************************************/
  1118. static BOOL CALLBACK _w3d_utility_tools_dlg_proc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
  1119. {
  1120. switch (msg) {
  1121. case WM_LBUTTONDOWN:
  1122. case WM_LBUTTONUP:
  1123. case WM_MOUSEMOVE:
  1124. TheW3DUtility.InterfacePtr->RollupMouseMessage(hWnd,msg,wParam,lParam);
  1125. break;
  1126. case WM_COMMAND:
  1127. {
  1128. switch (LOWORD(wParam))
  1129. {
  1130. /*
  1131. ** Buttons
  1132. */
  1133. case IDC_SELECT_GEOMETRY:
  1134. TheW3DUtility.Select_Geometry();
  1135. break;
  1136. case IDC_SELECT_HIERARCHY:
  1137. TheW3DUtility.Select_Hierarchy();
  1138. break;
  1139. case IDC_SELECT_ALPHA_MESHES:
  1140. TheW3DUtility.Select_Alpha();
  1141. break;
  1142. case IDC_SELECT_PHYSICAL:
  1143. TheW3DUtility.Select_Physical();
  1144. break;
  1145. case IDC_SELECT_PROJECTILE:
  1146. TheW3DUtility.Select_Projectile();
  1147. break;
  1148. case IDC_SELECT_VIS:
  1149. TheW3DUtility.Select_Vis();
  1150. break;
  1151. case IDC_COLLECTION_NAMES_GENERATE:
  1152. TheW3DUtility.generate_names();
  1153. TheW3DUtility.update_settings_controls();
  1154. break;
  1155. case IDC_MATERIAL_NAMES_GENERATE:
  1156. TheW3DUtility.generate_material_names();
  1157. TheW3DUtility.update_settings_controls();
  1158. break;
  1159. case IDC_LOD_EXTENSION_GENERATE:
  1160. TheW3DUtility.generate_lod_extensions();
  1161. TheW3DUtility.update_settings_controls();
  1162. break;
  1163. case IDC_EXPORT_STANDARD_MATERIALS:
  1164. TheW3DUtility.export_with_standard_materials();
  1165. break;
  1166. case IDC_CREATE_SETTINGS_FLOATER:
  1167. TheW3DUtility.create_floater();
  1168. break;
  1169. }
  1170. return TRUE;
  1171. }
  1172. default:
  1173. return FALSE;
  1174. }
  1175. return TRUE;
  1176. }
  1177. /**********************************************************************************************
  1178. **
  1179. ** SettingsFormClass Implementation
  1180. ** NOTE: When you use the _settings_form_dlg_proc, a SettingsFormClass will automatically
  1181. ** be allocated and attached to the dialog. You can cause all of the active forms to
  1182. ** refresh their status by calling Update_All_Instances. The forms will be destroyed when
  1183. ** the window is destroyed.
  1184. **
  1185. **********************************************************************************************/
  1186. SettingsFormClass * SettingsFormClass::ActiveList = NULL;
  1187. BOOL CALLBACK _settings_form_dlg_proc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
  1188. {
  1189. if (msg == WM_INITDIALOG) {
  1190. SettingsFormClass * form = new SettingsFormClass(hWnd);
  1191. ::SetProp(hWnd,"SettingsFormClass",(HANDLE)form);
  1192. }
  1193. SettingsFormClass * form = (SettingsFormClass *)::GetProp(hWnd,"SettingsFormClass");
  1194. if (form) {
  1195. return form->Dialog_Proc(hWnd,msg,wParam,lParam);
  1196. } else {
  1197. return FALSE;
  1198. }
  1199. }
  1200. static void _settings_form_selection_changed_callback(void * param,NotifyInfo * info)
  1201. {
  1202. ((SettingsFormClass*)param)->Selection_Changed();
  1203. }
  1204. SettingsFormClass::SettingsFormClass(HWND hwnd) :
  1205. Hwnd(hwnd),
  1206. RegionSpin(NULL)
  1207. {
  1208. /*
  1209. ** Link into the active list
  1210. */
  1211. Next = ActiveList;
  1212. ActiveList = this;
  1213. /*
  1214. ** Register with MAX
  1215. */
  1216. ::RegisterNotification(_settings_form_selection_changed_callback, this, NOTIFY_SELECTIONSET_CHANGED);
  1217. }
  1218. SettingsFormClass::~SettingsFormClass(void)
  1219. {
  1220. /*
  1221. ** Unregister from MAX
  1222. */
  1223. ::UnRegisterNotification(_settings_form_selection_changed_callback, this, NOTIFY_SELECTIONSET_CHANGED);
  1224. /*
  1225. ** Unlink from the active list
  1226. */
  1227. if (ActiveList == this) {
  1228. ActiveList = Next;
  1229. } else {
  1230. SettingsFormClass * prev = ActiveList;
  1231. SettingsFormClass * cur = ActiveList->Next;
  1232. while ((cur != this) && (cur != NULL)) {
  1233. cur = cur->Next;
  1234. prev = prev->Next;
  1235. }
  1236. assert(cur == this);
  1237. if (cur == this) {
  1238. prev->Next = cur->Next;
  1239. }
  1240. }
  1241. Hwnd = NULL;
  1242. }
  1243. void SettingsFormClass::Update_All_Instances(void)
  1244. {
  1245. if (ActiveList == NULL) {
  1246. return;
  1247. }
  1248. /*
  1249. ** Build a list of the selected nodes
  1250. */
  1251. INodeListClass node_list( ::GetCOREInterface()->GetRootNode(),
  1252. ::GetCOREInterface()->GetTime(),
  1253. &_INodeFilter );
  1254. /*
  1255. ** Update all settings forms
  1256. */
  1257. SettingsFormClass * form = ActiveList;
  1258. while (form != NULL) {
  1259. form->Update_Controls(&node_list);
  1260. form = form->Next;
  1261. }
  1262. }
  1263. void SettingsFormClass::Init(void)
  1264. {
  1265. // Initialize the contents of the dazzle combo
  1266. // Reset the dazzle combo
  1267. HWND dazzle_combo = GetDlgItem(Hwnd,IDC_DAZZLE_COMBO);
  1268. assert(dazzle_combo != NULL);
  1269. SendMessage(dazzle_combo,CB_RESETCONTENT,0,0);
  1270. // Load the section of Dazzle.INI that defines all of the types. The windows function
  1271. // that I'm using here, reads in a NULL-terminated string for each entry in the section. Each
  1272. // string is of the form 'key=value'. Based on my testing, it appears that windows removes any white
  1273. // space before or after the equal sign as well.
  1274. char dllpath[_MAX_PATH];
  1275. ::GetModuleFileName(AppInstance,dllpath,sizeof(dllpath));
  1276. char * last_slash = strrchr(dllpath,'\\');
  1277. last_slash++;
  1278. strcpy(last_slash,DAZZLE_SETTINGS_FILENAME);
  1279. char * dazzle_types_buffer = new char[DAZZLE_SECTION_BUFFERSIZE]; // max size of a section for Win95
  1280. ::GetPrivateProfileSection( DAZZLE_TYPES_SECTION, dazzle_types_buffer, DAZZLE_SECTION_BUFFERSIZE, dllpath);
  1281. // Now we need to handle each string in the section buffer; skipping the 'key=' and adding
  1282. // the dazzle type name into the combo box.
  1283. char * entry = dazzle_types_buffer;
  1284. if (entry != NULL) {
  1285. while (*entry != NULL) {
  1286. entry = strchr(entry,'=');
  1287. if (entry != NULL) {
  1288. entry++;
  1289. ::SendMessage(dazzle_combo,CB_ADDSTRING,0,(LPARAM)entry);
  1290. entry += strlen(entry) + 1;
  1291. }
  1292. }
  1293. } else {
  1294. ::SendMessage(dazzle_combo,CB_ADDSTRING,0,(LPARAM)"Default");
  1295. }
  1296. ::SendMessage(dazzle_combo,CB_SETCURSEL,(WPARAM)0,0);
  1297. delete dazzle_types_buffer;
  1298. /*
  1299. ** Setup the damage region spinner control.
  1300. */
  1301. RegionSpin = SetupIntSpinner
  1302. (
  1303. Hwnd,
  1304. IDC_DAMREG_INDEX_SPIN,
  1305. IDC_DAMREG_INDEX_EDIT,
  1306. NO_DAMAGE_REGION, MAX_DAMAGE_REGIONS-1, NO_DAMAGE_REGION
  1307. );
  1308. }
  1309. void SettingsFormClass::Destroy(void)
  1310. {
  1311. ReleaseISpinner(RegionSpin);
  1312. RegionSpin = NULL;
  1313. }
  1314. bool SettingsFormClass::Dialog_Proc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
  1315. {
  1316. int check;
  1317. switch (message) {
  1318. case WM_INITDIALOG:
  1319. Init();
  1320. break;
  1321. case WM_DESTROY:
  1322. Destroy();
  1323. delete this;
  1324. break;
  1325. case WM_COMMAND:
  1326. {
  1327. /*
  1328. ** handle the tri-state checkboxes.
  1329. ** MAKE SURE YOU PUT ANY NEW CHECKBOX ID's IN HERE!!!
  1330. */
  1331. int control_id = LOWORD(wParam);
  1332. if ( (control_id == IDC_HIERARCHY_CHECK) ||
  1333. (control_id == IDC_GEOMETRY_CHECK) ||
  1334. (control_id == IDC_GEOMETRY_HIDE) ||
  1335. (control_id == IDC_GEOMETRY_TWO_SIDED) ||
  1336. (control_id == IDC_GEOMETRY_ZNORMALS) ||
  1337. (control_id == IDC_GEOMETRY_VERTEX_ALPHA) ||
  1338. (control_id == IDC_GEOMETRY_CAST_SHADOW) ||
  1339. (control_id == IDC_GEOMETRY_SHATTERABLE) ||
  1340. (control_id == IDC_GEOMETRY_NPATCH) ||
  1341. (control_id == IDC_COLLISION_PHYSICAL) ||
  1342. (control_id == IDC_COLLISION_PROJECTILE) ||
  1343. (control_id == IDC_COLLISION_VIS) ||
  1344. (control_id == IDC_COLLISION_CAMERA) ||
  1345. (control_id == IDC_COLLISION_VEHICLE))
  1346. {
  1347. check = !SendDlgItemMessage(hWnd,LOWORD(wParam),BM_GETCHECK,0,0L);
  1348. SendDlgItemMessage(hWnd,LOWORD(wParam),BM_SETCHECK,check,0L);
  1349. }
  1350. INodeListClass node_list( ::GetCOREInterface()->GetRootNode(),
  1351. ::GetCOREInterface()->GetTime(),
  1352. &_INodeFilter );
  1353. switch (LOWORD(wParam))
  1354. {
  1355. /*
  1356. ** Tri-State Checkboxes, make sure that the ID of all checkboxes is present
  1357. ** in the 'if' statement above!
  1358. */
  1359. case IDC_HIERARCHY_CHECK:
  1360. W3DUtilityClass::set_hierarchy_in_all_selected(&node_list,check == BST_CHECKED);
  1361. break;
  1362. case IDC_GEOMETRY_CHECK:
  1363. W3DUtilityClass::set_geometry_in_all_selected(&node_list,check == BST_CHECKED);
  1364. break;
  1365. case IDC_GEOMETRY_HIDE:
  1366. W3DUtilityClass::enable_hidden_in_all_selected(&node_list,check == BST_CHECKED);
  1367. break;
  1368. case IDC_GEOMETRY_TWO_SIDED:
  1369. W3DUtilityClass::enable_two_sided_in_all_selected(&node_list,check == BST_CHECKED);
  1370. break;
  1371. case IDC_GEOMETRY_ZNORMALS:
  1372. W3DUtilityClass::enable_znormals_in_all_selected(&node_list,check == BST_CHECKED);
  1373. break;
  1374. case IDC_GEOMETRY_VERTEX_ALPHA:
  1375. W3DUtilityClass::enable_vertex_alpha_in_all_selected(&node_list,check == BST_CHECKED);
  1376. break;
  1377. case IDC_GEOMETRY_CAST_SHADOW:
  1378. W3DUtilityClass::enable_shadow_in_all_selected(&node_list,check == BST_CHECKED);
  1379. break;
  1380. case IDC_GEOMETRY_SHATTERABLE:
  1381. W3DUtilityClass::enable_shatterable_in_all_selected(&node_list,check == BST_CHECKED);
  1382. break;
  1383. case IDC_GEOMETRY_NPATCH:
  1384. W3DUtilityClass::enable_npatches_in_all_selected(&node_list,check == BST_CHECKED);
  1385. break;
  1386. case IDC_COLLISION_PHYSICAL:
  1387. W3DUtilityClass::enable_physical_collision_in_all_selected(&node_list,check == BST_CHECKED);
  1388. break;
  1389. case IDC_COLLISION_PROJECTILE:
  1390. W3DUtilityClass::enable_projectile_collision_in_all_selected(&node_list,check == BST_CHECKED);
  1391. break;
  1392. case IDC_COLLISION_VIS:
  1393. W3DUtilityClass::enable_vis_collision_in_all_selected(&node_list,check == BST_CHECKED);
  1394. break;
  1395. case IDC_COLLISION_CAMERA:
  1396. W3DUtilityClass::enable_camera_collision_in_all_selected(&node_list,check == BST_CHECKED);
  1397. break;
  1398. case IDC_COLLISION_VEHICLE:
  1399. W3DUtilityClass::enable_vehicle_collision_in_all_selected(&node_list,check == BST_CHECKED);
  1400. break;
  1401. /*
  1402. ** Radio buttons for the Geometry type
  1403. */
  1404. case IDC_GEOMETRY_NORMAL:
  1405. W3DUtilityClass::set_geometry_type_in_all_selected(&node_list,W3DAppData2Struct::GEO_TYPE_NORMAL_MESH);
  1406. break;
  1407. case IDC_GEOMETRY_CAMERA_ALIGNED:
  1408. W3DUtilityClass::set_geometry_type_in_all_selected(&node_list,W3DAppData2Struct::GEO_TYPE_CAMERA_ALIGNED);
  1409. break;
  1410. case IDC_GEOMETRY_CAMERA_ORIENTED:
  1411. W3DUtilityClass::set_geometry_type_in_all_selected(&node_list,W3DAppData2Struct::GEO_TYPE_CAMERA_ORIENTED);
  1412. break;
  1413. case IDC_GEOMETRY_NULL:
  1414. W3DUtilityClass::set_geometry_type_in_all_selected(&node_list,W3DAppData2Struct::GEO_TYPE_NULL);
  1415. break;
  1416. case IDC_GEOMETRY_AABOX:
  1417. W3DUtilityClass::set_geometry_type_in_all_selected(&node_list,W3DAppData2Struct::GEO_TYPE_AABOX);
  1418. break;
  1419. case IDC_GEOMETRY_OBBOX:
  1420. W3DUtilityClass::set_geometry_type_in_all_selected(&node_list,W3DAppData2Struct::GEO_TYPE_OBBOX);
  1421. break;
  1422. case IDC_GEOMETRY_AGGREGATE:
  1423. W3DUtilityClass::set_geometry_type_in_all_selected(&node_list,W3DAppData2Struct::GEO_TYPE_AGGREGATE);
  1424. break;
  1425. case IDC_GEOMETRY_DAZZLE:
  1426. W3DUtilityClass::set_geometry_type_in_all_selected(&node_list,W3DAppData2Struct::GEO_TYPE_DAZZLE);
  1427. break;
  1428. /*
  1429. ** Dazzle type setting. Whenever the user changes the selected dazzle type, apply
  1430. ** the new setting to all selected nodes.
  1431. */
  1432. case IDC_DAZZLE_COMBO:
  1433. if (HIWORD(wParam) == CBN_SELCHANGE) {
  1434. HWND dazzle_combo = GetDlgItem(hWnd,IDC_DAZZLE_COMBO);
  1435. if (dazzle_combo != NULL) {
  1436. char dazzle_type[128];
  1437. int cursel = ::SendMessage(dazzle_combo,CB_GETCURSEL,0,0);
  1438. int len = ::SendMessage(dazzle_combo,CB_GETLBTEXTLEN,cursel,0);
  1439. if (len < 128) {
  1440. ::SendMessage(dazzle_combo,CB_GETLBTEXT,(WPARAM)cursel,(LPARAM)dazzle_type);
  1441. W3DUtilityClass::set_dazzle_type_in_all_selected(&node_list,dazzle_type);
  1442. }
  1443. }
  1444. }
  1445. break;
  1446. }
  1447. return TRUE;
  1448. }
  1449. /*
  1450. ** Spinners
  1451. */
  1452. case CC_SPINNER_CHANGE:
  1453. {
  1454. INodeListClass node_list( ::GetCOREInterface()->GetRootNode(),
  1455. ::GetCOREInterface()->GetTime(),
  1456. &_INodeFilter );
  1457. W3DUtilityClass::set_region_in_all_selected(&node_list,RegionSpin->GetIVal());
  1458. break;
  1459. }
  1460. /*
  1461. ** Max Custom Edit boxes
  1462. */
  1463. case WM_CUSTEDIT_ENTER:
  1464. {
  1465. INodeListClass node_list( ::GetCOREInterface()->GetRootNode(),
  1466. ::GetCOREInterface()->GetTime(),
  1467. &_INodeFilter );
  1468. ICustEdit * edit_ctrl = GetICustEdit(GetDlgItem(hWnd,wParam));
  1469. if (wParam == IDC_OBJ_NAME) {
  1470. if (edit_ctrl && node_list.Num_Nodes() == 1) {
  1471. char buffer[64];
  1472. edit_ctrl->GetText(buffer,sizeof(buffer));
  1473. node_list[0]->SetName(buffer);
  1474. Update_All_Instances();
  1475. }
  1476. }
  1477. ReleaseICustEdit(edit_ctrl);
  1478. break;
  1479. }
  1480. default:
  1481. return FALSE;
  1482. }
  1483. return TRUE;
  1484. }
  1485. void SettingsFormClass::Selection_Changed(void)
  1486. {
  1487. INodeListClass node_list( ::GetCOREInterface()->GetRootNode(),
  1488. ::GetCOREInterface()->GetTime(),
  1489. &_INodeFilter );
  1490. Update_Controls(&node_list);
  1491. }
  1492. void SettingsFormClass::Update_Controls(INodeListClass * node_list)
  1493. {
  1494. /*
  1495. ** Update name of currently selected object
  1496. ** "Multiple" if more than one, "None" if no selected objs...
  1497. */
  1498. ICustEdit * edit_ctrl = GetICustEdit(GetDlgItem(Hwnd,IDC_OBJ_NAME));
  1499. if (edit_ctrl != NULL) {
  1500. if (node_list->Num_Nodes() == 0) {
  1501. edit_ctrl->Enable(FALSE);
  1502. edit_ctrl->SetText(Get_String(IDS_NO_OBJECT));
  1503. } else if (node_list->Num_Nodes() == 1) {
  1504. edit_ctrl->Enable(TRUE);
  1505. edit_ctrl->SetText((*node_list)[0]->GetName());
  1506. } else {
  1507. edit_ctrl->Enable(FALSE);
  1508. edit_ctrl->SetText(Get_String(IDS_MULTIPLE_OBJECTS));
  1509. }
  1510. ReleaseICustEdit(edit_ctrl);
  1511. }
  1512. if (node_list->Num_Nodes() == 0) {
  1513. Disable_Controls();
  1514. return;
  1515. }
  1516. W3DUtilityClass::NodeStatesStruct ns;
  1517. W3DUtilityClass::eval_node_states(node_list,&ns);
  1518. /*
  1519. ** Enable hierarchy and geometry checks since they are always available
  1520. */
  1521. EnableWindow(GetDlgItem(Hwnd,IDC_HIERARCHY_CHECK),TRUE);
  1522. EnableWindow(GetDlgItem(Hwnd,IDC_GEOMETRY_CHECK),TRUE);
  1523. /*
  1524. ** Enable/Disable the geometry controls
  1525. */
  1526. if (ns.ExportGeometry == 1) {
  1527. EnableWindow(GetDlgItem(Hwnd,IDC_GEOMETRY_CAMERA_ALIGNED),TRUE);
  1528. EnableWindow(GetDlgItem(Hwnd,IDC_GEOMETRY_CAMERA_ORIENTED),TRUE);
  1529. EnableWindow(GetDlgItem(Hwnd,IDC_GEOMETRY_NORMAL),TRUE);
  1530. EnableWindow(GetDlgItem(Hwnd,IDC_GEOMETRY_NULL),TRUE);
  1531. EnableWindow(GetDlgItem(Hwnd,IDC_GEOMETRY_AABOX),TRUE);
  1532. EnableWindow(GetDlgItem(Hwnd,IDC_GEOMETRY_OBBOX),TRUE);
  1533. EnableWindow(GetDlgItem(Hwnd,IDC_GEOMETRY_AGGREGATE),TRUE);
  1534. EnableWindow(GetDlgItem(Hwnd,IDC_GEOMETRY_DAZZLE),TRUE);
  1535. EnableWindow(GetDlgItem(Hwnd,IDC_GEOMETRY_HIDE),TRUE);
  1536. EnableWindow(GetDlgItem(Hwnd,IDC_GEOMETRY_TWO_SIDED),TRUE);
  1537. EnableWindow(GetDlgItem(Hwnd,IDC_GEOMETRY_ZNORMALS),TRUE);
  1538. EnableWindow(GetDlgItem(Hwnd,IDC_GEOMETRY_VERTEX_ALPHA),TRUE);
  1539. EnableWindow(GetDlgItem(Hwnd,IDC_GEOMETRY_CAST_SHADOW),TRUE);
  1540. EnableWindow(GetDlgItem(Hwnd,IDC_GEOMETRY_SHATTERABLE),TRUE);
  1541. EnableWindow(GetDlgItem(Hwnd,IDC_GEOMETRY_NPATCH),TRUE);
  1542. EnableWindow(GetDlgItem(Hwnd,IDC_COLLISION_PHYSICAL),TRUE);
  1543. EnableWindow(GetDlgItem(Hwnd,IDC_COLLISION_PROJECTILE),TRUE);
  1544. EnableWindow(GetDlgItem(Hwnd,IDC_COLLISION_VIS),TRUE);
  1545. EnableWindow(GetDlgItem(Hwnd,IDC_COLLISION_CAMERA),TRUE);
  1546. EnableWindow(GetDlgItem(Hwnd,IDC_COLLISION_VEHICLE),TRUE);
  1547. } else {
  1548. EnableWindow(GetDlgItem(Hwnd,IDC_GEOMETRY_CAMERA_ALIGNED),FALSE);
  1549. EnableWindow(GetDlgItem(Hwnd,IDC_GEOMETRY_CAMERA_ORIENTED),FALSE);
  1550. EnableWindow(GetDlgItem(Hwnd,IDC_GEOMETRY_NORMAL),FALSE);
  1551. EnableWindow(GetDlgItem(Hwnd,IDC_GEOMETRY_NULL),FALSE);
  1552. EnableWindow(GetDlgItem(Hwnd,IDC_GEOMETRY_AABOX),FALSE);
  1553. EnableWindow(GetDlgItem(Hwnd,IDC_GEOMETRY_OBBOX),FALSE);
  1554. EnableWindow(GetDlgItem(Hwnd,IDC_GEOMETRY_AGGREGATE),FALSE);
  1555. EnableWindow(GetDlgItem(Hwnd,IDC_GEOMETRY_DAZZLE),FALSE);
  1556. EnableWindow(GetDlgItem(Hwnd,IDC_GEOMETRY_HIDE),FALSE);
  1557. EnableWindow(GetDlgItem(Hwnd,IDC_GEOMETRY_TWO_SIDED),FALSE);
  1558. EnableWindow(GetDlgItem(Hwnd,IDC_GEOMETRY_ZNORMALS),FALSE);
  1559. EnableWindow(GetDlgItem(Hwnd,IDC_GEOMETRY_VERTEX_ALPHA),FALSE);
  1560. EnableWindow(GetDlgItem(Hwnd,IDC_GEOMETRY_CAST_SHADOW),FALSE);
  1561. EnableWindow(GetDlgItem(Hwnd,IDC_GEOMETRY_SHATTERABLE),FALSE);
  1562. EnableWindow(GetDlgItem(Hwnd,IDC_GEOMETRY_NPATCH),FALSE);
  1563. EnableWindow(GetDlgItem(Hwnd,IDC_COLLISION_PHYSICAL),FALSE);
  1564. EnableWindow(GetDlgItem(Hwnd,IDC_COLLISION_PROJECTILE),FALSE);
  1565. EnableWindow(GetDlgItem(Hwnd,IDC_COLLISION_VIS),FALSE);
  1566. EnableWindow(GetDlgItem(Hwnd,IDC_COLLISION_CAMERA),FALSE);
  1567. EnableWindow(GetDlgItem(Hwnd,IDC_COLLISION_VEHICLE),FALSE);
  1568. }
  1569. /*
  1570. ** Set the checks based on the nodes states:
  1571. ** no check - none of the selected nodes had this setting
  1572. ** check - all of the selected nodes had this setting
  1573. ** grey check - some of the selected nodes had this setting
  1574. */
  1575. SendDlgItemMessage(Hwnd,IDC_HIERARCHY_CHECK,BM_SETCHECK,ns.ExportHierarchy,0L);
  1576. SendDlgItemMessage(Hwnd,IDC_GEOMETRY_CHECK,BM_SETCHECK,ns.ExportGeometry,0L);
  1577. SendDlgItemMessage(Hwnd,IDC_GEOMETRY_HIDE,BM_SETCHECK,ns.GeometryHidden,0L);
  1578. SendDlgItemMessage(Hwnd,IDC_GEOMETRY_TWO_SIDED,BM_SETCHECK,ns.GeometryTwoSided,0L);
  1579. SendDlgItemMessage(Hwnd,IDC_GEOMETRY_ZNORMALS,BM_SETCHECK,ns.GeometryZNormals,0L);
  1580. SendDlgItemMessage(Hwnd,IDC_GEOMETRY_VERTEX_ALPHA,BM_SETCHECK,ns.GeometryVertexAlpha,0L);
  1581. SendDlgItemMessage(Hwnd,IDC_GEOMETRY_CAST_SHADOW,BM_SETCHECK,ns.GeometryCastShadow,0L);
  1582. SendDlgItemMessage(Hwnd,IDC_GEOMETRY_SHATTERABLE,BM_SETCHECK,ns.GeometryShatterable,0L);
  1583. SendDlgItemMessage(Hwnd,IDC_GEOMETRY_NPATCH,BM_SETCHECK,ns.GeometryNPatch,0L);
  1584. SendDlgItemMessage(Hwnd,IDC_COLLISION_PHYSICAL,BM_SETCHECK,ns.CollisionPhysical,0L);
  1585. SendDlgItemMessage(Hwnd,IDC_COLLISION_PROJECTILE,BM_SETCHECK,ns.CollisionProjectile,0L);
  1586. SendDlgItemMessage(Hwnd,IDC_COLLISION_VIS,BM_SETCHECK,ns.CollisionVis,0L);
  1587. SendDlgItemMessage(Hwnd,IDC_COLLISION_CAMERA,BM_SETCHECK,ns.CollisionCamera,0L);
  1588. SendDlgItemMessage(Hwnd,IDC_COLLISION_VEHICLE,BM_SETCHECK,ns.CollisionVehicle,0L);
  1589. /*
  1590. ** The damage region spinner should only be enabled if
  1591. ** Export Hierarchy is checked for all selected nodes.
  1592. */
  1593. BOOL spinner_enable = false;
  1594. if (ns.ExportHierarchy == 1)
  1595. {
  1596. if (ns.DamageRegion != MAX_DAMAGE_REGIONS)
  1597. {
  1598. // Show the damage region in the spinner.
  1599. RegionSpin->SetIndeterminate(FALSE);
  1600. RegionSpin->SetValue(ns.DamageRegion, FALSE);
  1601. }
  1602. else
  1603. {
  1604. // The selected objects aren't all in the same region.
  1605. RegionSpin->SetIndeterminate(TRUE);
  1606. }
  1607. spinner_enable = true;
  1608. }
  1609. EnableWindow(GetDlgItem(Hwnd,IDC_DAMREG_INDEX_EDIT),spinner_enable);
  1610. EnableWindow(GetDlgItem(Hwnd,IDC_DAMREG_INDEX_SPIN),spinner_enable);
  1611. /*
  1612. ** The dazzle combo box should only be enabled if
  1613. ** Export Geometry, and geometry type dazzle is set for all
  1614. ** selected nodes.
  1615. */
  1616. bool dazzle_combo_enable = false;
  1617. if (ns.ExportGeometry == 1) {
  1618. if (ns.DazzleCount == node_list->Num_Nodes()) {
  1619. dazzle_combo_enable = true;
  1620. }
  1621. }
  1622. HWND dazzle_combo = GetDlgItem(Hwnd,IDC_DAZZLE_COMBO);
  1623. EnableWindow(dazzle_combo,dazzle_combo_enable);
  1624. int selindex = ::SendMessage(dazzle_combo,CB_FINDSTRING,(WPARAM)0,(LPARAM)ns.DazzleType);
  1625. if (selindex != CB_ERR) {
  1626. ::SendMessage(dazzle_combo,CB_SETCURSEL,(WPARAM)selindex,(LPARAM)0);
  1627. } else {
  1628. ::SendMessage(dazzle_combo,CB_SETCURSEL,(WPARAM)0,(LPARAM)0);
  1629. }
  1630. /*
  1631. ** Set any radio buttons present
  1632. */
  1633. CheckDlgButton(Hwnd,IDC_GEOMETRY_CAMERA_ALIGNED,(ns.GeometryCameraAligned ? BST_CHECKED : BST_UNCHECKED));
  1634. CheckDlgButton(Hwnd,IDC_GEOMETRY_CAMERA_ORIENTED,(ns.GeometryCameraOriented ? BST_CHECKED : BST_UNCHECKED));
  1635. CheckDlgButton(Hwnd,IDC_GEOMETRY_NORMAL,(ns.GeometryNormal ? BST_CHECKED : BST_UNCHECKED));
  1636. CheckDlgButton(Hwnd,IDC_GEOMETRY_NULL,(ns.GeometryNull ? BST_CHECKED : BST_UNCHECKED));
  1637. CheckDlgButton(Hwnd,IDC_GEOMETRY_AABOX,(ns.GeometryAABox ? BST_CHECKED : BST_UNCHECKED));
  1638. CheckDlgButton(Hwnd,IDC_GEOMETRY_OBBOX,(ns.GeometryOBBox ? BST_CHECKED : BST_UNCHECKED));
  1639. CheckDlgButton(Hwnd,IDC_GEOMETRY_AGGREGATE,(ns.GeometryAggregate ? BST_CHECKED : BST_UNCHECKED));
  1640. CheckDlgButton(Hwnd,IDC_GEOMETRY_DAZZLE,(ns.GeometryDazzle ? BST_CHECKED : BST_UNCHECKED));
  1641. }
  1642. void SettingsFormClass::Disable_Controls(void)
  1643. {
  1644. EnableWindow(GetDlgItem(Hwnd,IDC_OBJ_NAME),FALSE);
  1645. EnableWindow(GetDlgItem(Hwnd,IDC_HIERARCHY_CHECK),FALSE);
  1646. EnableWindow(GetDlgItem(Hwnd,IDC_GEOMETRY_CHECK),FALSE);
  1647. EnableWindow(GetDlgItem(Hwnd,IDC_DAMREG_INDEX_EDIT),FALSE);
  1648. EnableWindow(GetDlgItem(Hwnd,IDC_DAMREG_INDEX_SPIN),FALSE);
  1649. EnableWindow(GetDlgItem(Hwnd,IDC_GEOMETRY_NORMAL),FALSE);
  1650. EnableWindow(GetDlgItem(Hwnd,IDC_GEOMETRY_CAMERA_ALIGNED),FALSE);
  1651. EnableWindow(GetDlgItem(Hwnd,IDC_GEOMETRY_CAMERA_ORIENTED),FALSE);
  1652. EnableWindow(GetDlgItem(Hwnd,IDC_GEOMETRY_AABOX),FALSE);
  1653. EnableWindow(GetDlgItem(Hwnd,IDC_GEOMETRY_OBBOX),FALSE);
  1654. EnableWindow(GetDlgItem(Hwnd,IDC_GEOMETRY_NULL),FALSE);
  1655. EnableWindow(GetDlgItem(Hwnd,IDC_GEOMETRY_AGGREGATE),FALSE);
  1656. EnableWindow(GetDlgItem(Hwnd,IDC_GEOMETRY_DAZZLE),FALSE);
  1657. EnableWindow(GetDlgItem(Hwnd,IDC_GEOMETRY_HIDE),FALSE);
  1658. EnableWindow(GetDlgItem(Hwnd,IDC_GEOMETRY_TWO_SIDED),FALSE);
  1659. EnableWindow(GetDlgItem(Hwnd,IDC_GEOMETRY_ZNORMALS),FALSE);
  1660. EnableWindow(GetDlgItem(Hwnd,IDC_GEOMETRY_VERTEX_ALPHA),FALSE);
  1661. EnableWindow(GetDlgItem(Hwnd,IDC_GEOMETRY_CAST_SHADOW),FALSE);
  1662. EnableWindow(GetDlgItem(Hwnd,IDC_GEOMETRY_SHATTERABLE),FALSE);
  1663. EnableWindow(GetDlgItem(Hwnd,IDC_GEOMETRY_NPATCH),FALSE);
  1664. EnableWindow(GetDlgItem(Hwnd,IDC_COLLISION_PHYSICAL),FALSE);
  1665. EnableWindow(GetDlgItem(Hwnd,IDC_COLLISION_PROJECTILE),FALSE);
  1666. EnableWindow(GetDlgItem(Hwnd,IDC_COLLISION_VIS),FALSE);
  1667. EnableWindow(GetDlgItem(Hwnd,IDC_COLLISION_CAMERA),FALSE);
  1668. EnableWindow(GetDlgItem(Hwnd,IDC_COLLISION_VEHICLE),FALSE);
  1669. EnableWindow(GetDlgItem(Hwnd,IDC_DAZZLE_COMBO),FALSE);
  1670. CheckDlgButton(Hwnd,IDC_HIERARCHY_CHECK,BST_UNCHECKED);
  1671. CheckDlgButton(Hwnd,IDC_GEOMETRY_CHECK,BST_UNCHECKED);
  1672. CheckDlgButton(Hwnd,IDC_GEOMETRY_CAMERA_ALIGNED,BST_UNCHECKED);
  1673. CheckDlgButton(Hwnd,IDC_GEOMETRY_CAMERA_ORIENTED,BST_UNCHECKED);
  1674. CheckDlgButton(Hwnd,IDC_GEOMETRY_NORMAL,BST_UNCHECKED);
  1675. CheckDlgButton(Hwnd,IDC_GEOMETRY_AABOX,BST_UNCHECKED);
  1676. CheckDlgButton(Hwnd,IDC_GEOMETRY_OBBOX,BST_UNCHECKED);
  1677. CheckDlgButton(Hwnd,IDC_GEOMETRY_NULL,BST_UNCHECKED);
  1678. CheckDlgButton(Hwnd,IDC_GEOMETRY_AGGREGATE,BST_UNCHECKED);
  1679. CheckDlgButton(Hwnd,IDC_GEOMETRY_DAZZLE,BST_UNCHECKED);
  1680. CheckDlgButton(Hwnd,IDC_GEOMETRY_HIDE,BST_UNCHECKED);
  1681. CheckDlgButton(Hwnd,IDC_GEOMETRY_TWO_SIDED,BST_UNCHECKED);
  1682. CheckDlgButton(Hwnd,IDC_GEOMETRY_ZNORMALS,BST_UNCHECKED);
  1683. CheckDlgButton(Hwnd,IDC_GEOMETRY_VERTEX_ALPHA,BST_UNCHECKED);
  1684. CheckDlgButton(Hwnd,IDC_GEOMETRY_CAST_SHADOW,BST_UNCHECKED);
  1685. CheckDlgButton(Hwnd,IDC_GEOMETRY_SHATTERABLE,BST_UNCHECKED);
  1686. CheckDlgButton(Hwnd,IDC_GEOMETRY_NPATCH,BST_UNCHECKED);
  1687. CheckDlgButton(Hwnd,IDC_COLLISION_PHYSICAL,BST_UNCHECKED);
  1688. CheckDlgButton(Hwnd,IDC_COLLISION_PROJECTILE,BST_UNCHECKED);
  1689. CheckDlgButton(Hwnd,IDC_COLLISION_VIS,BST_UNCHECKED);
  1690. CheckDlgButton(Hwnd,IDC_COLLISION_CAMERA,BST_UNCHECKED);
  1691. CheckDlgButton(Hwnd,IDC_COLLISION_VEHICLE,BST_UNCHECKED);
  1692. }
  1693. /*
  1694. ** Functions to access the W3D AppData of any INode.
  1695. */
  1696. W3DAppData0Struct * GetW3DAppData0 (INode *node)
  1697. {
  1698. return TheW3DUtility.get_app_data_0(node);
  1699. }
  1700. W3DAppData1Struct * GetW3DAppData1 (INode *node)
  1701. {
  1702. return TheW3DUtility.get_app_data_1(node);
  1703. }
  1704. W3DAppData2Struct * GetW3DAppData2 (INode *node)
  1705. {
  1706. return TheW3DUtility.get_app_data_2(node);
  1707. }
  1708. W3DDazzleAppDataStruct * GetW3DDazzleAppData(INode *node)
  1709. {
  1710. return TheW3DUtility.get_dazzle_app_data(node);
  1711. }