SceneEditor.cpp 74 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148
  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. /***********************************************************************************************
  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 : LevelEdit *
  23. * *
  24. * $Archive:: /Commando/Code/Tools/LevelEdit/SceneEditor.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 3/12/02 3:31p $*
  29. * *
  30. * $Revision:: 116 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "stdafx.h"
  36. #include "sceneeditor.h"
  37. #include "nodemgr.h"
  38. #include "groupmgr.h"
  39. #include "utils.h"
  40. #include "matrix3d.h"
  41. #include "vector.h"
  42. #include "leveleditdoc.h"
  43. #include "filemgr.h"
  44. #include "cameramgr.h"
  45. #include "leveleditview.h"
  46. #include "hittestinfo.h"
  47. #include "collisiongroups.h"
  48. #include "mainfrm.h"
  49. #include "wwaudio.h"
  50. #include "audiblesound.h"
  51. #include "mesh.h"
  52. #include "staticphys.h"
  53. #include "phys3.h"
  54. #include "_assetmgr.h"
  55. #include "editorassetmgr.h"
  56. #include "humanphys.h"
  57. #include "pathfindsectorbuilder.h"
  58. #include "pathfind.h"
  59. #include "node.h"
  60. #include "mover.h"
  61. #include "nodefunction.h"
  62. #include "chunkio.h"
  63. #include "decophys.h"
  64. #include "VisPointNode.h"
  65. #include "editorchunkids.h"
  66. #include "presetmgr.h"
  67. #include "combat.h"
  68. #include "ccamera.h"
  69. #include "visenum.h"
  70. #include "staticaabtreecull.h"
  71. #include "dynamicaabtreecull.h"
  72. #include "soundscene.h"
  73. #include "backgroundmgr.h"
  74. #include "texture.h"
  75. #include "smartgameobj.h"
  76. #include "objectnode.h"
  77. #include "mousemgr.h"
  78. #include "lightnode.h"
  79. #include "light.h"
  80. #include "euler.h"
  81. #include "w3d_file.h"
  82. #include "part_emt.h"
  83. #include "gameobjmanager.h"
  84. #include "selectpresetdialog.h"
  85. #include "actionparams.h"
  86. #include "generatingvisdialog.h"
  87. #include "generatingedgesampledvisdialog.h"
  88. #include "generatinglightvisdialog.h"
  89. #include "visgenprogress.h"
  90. #include "vissectorsampler.h"
  91. #include "vismgr.h"
  92. #include "generatingmanualvisdialog.h"
  93. #include "heightdb.h"
  94. #include "staticanimphys.h"
  95. #include "conversationmgr.h"
  96. #include "building.h"
  97. #include "buildingnode.h"
  98. #include "vistable.h"
  99. #include "rendobj.h"
  100. #include "pscene.h"
  101. #include "leveledit.h"
  102. #include "visrendercontext.h"
  103. #include "mapmgr.h"
  104. #include "editableheightfield.h"
  105. #include "heightfieldeditor.h"
  106. #include "heightfieldmgr.h"
  107. #include "pathmgr.h"
  108. //////////////////////////////////////////////////////////////////////
  109. //
  110. // SceneEditorClass
  111. //
  112. //////////////////////////////////////////////////////////////////////
  113. SceneEditorClass::SceneEditorClass (void)
  114. : m_SelectionMgr (NULL),
  115. m_bLightsOn (true),
  116. m_bAggregateChildrenVisible (true),
  117. m_bVisPointsDisplayed (0),
  118. m_TotalVisPoints (0),
  119. m_ManualVisPointsVisible (true),
  120. m_MovingObject (NULL),
  121. m_DisplaySoundSpheres (false),
  122. m_DisplayLightSpheres (false),
  123. m_ShowStaticAnimPhys (true),
  124. m_ShowEditorObjects (true),
  125. m_BuildingPowerEnabled (true),
  126. m_CreateProxies (true),
  127. PhysicsSceneClass ()
  128. {
  129. //
  130. // Ensure that we are initialized
  131. //
  132. Initialize ();
  133. //
  134. // Set some default light settings
  135. //
  136. Enable_Sun_Light (true);
  137. Set_Ambient_Light (Vector3 (0.3F, 0.3F, 0.3F));
  138. Set_Sun_Light_Orientation (0.0F, DEG_TO_RADF (50.0F));
  139. Update_Lighting ();
  140. return ;
  141. }
  142. //////////////////////////////////////////////////////////////////////
  143. //
  144. // ~SceneEditorClass
  145. //
  146. //////////////////////////////////////////////////////////////////////
  147. SceneEditorClass::~SceneEditorClass (void)
  148. {
  149. Empty_Local_Clipboard ();
  150. Cleanup_Resources ();
  151. Remove_All_Vis_Points ();
  152. return ;
  153. }
  154. //////////////////////////////////////////////////////////////////////
  155. //
  156. // Initialize
  157. //
  158. //////////////////////////////////////////////////////////////////////
  159. void
  160. SceneEditorClass::Initialize (void)
  161. {
  162. //
  163. // Load the lighting mode from the registry
  164. //
  165. int prelit_mode = theApp.GetProfileInt ("Config", "PrelitMode", WW3D::PRELIT_MODE_LIGHTMAP_MULTI_PASS);
  166. WW3D::Set_Prelit_Mode ((WW3D::PrelitModeEnum)prelit_mode);
  167. //
  168. // Initialize some misc variables
  169. //
  170. ParticleEmitterClass::Set_Default_Remove_On_Complete (false);
  171. Cleanup_Resources ();
  172. m_ManualVisPointsVisible = true;
  173. m_BuildingPowerEnabled = true;
  174. PathfindClass::Get_Instance ()->Reset_Sectors ();
  175. //
  176. // Create the node and selection managers
  177. //
  178. m_SelectionMgr = new SelectionMgrClass;
  179. //
  180. // Reset our undo stack
  181. //
  182. m_UndoMgr.Purge_Buffers ();
  183. //
  184. // Set-up our collision groups
  185. //
  186. Disable_All_Collision_Detections (EDITOR_COLLISION_GROUP);
  187. Disable_All_Collision_Detections (DEF_COLLISION_GROUP);
  188. Enable_Collision_Detection (DEF_COLLISION_GROUP, DEF_COLLISION_GROUP);
  189. Enable_All_Collision_Detections (MOUSE_CLICK_COLLISION_GROUP);
  190. Enable_All_Collision_Detections (15);
  191. Disable_All_Collision_Detections (STATIC_OBJ_COLLISION_GROUP);
  192. Enable_Collision_Detection (STATIC_OBJ_COLLISION_GROUP, 15);
  193. Disable_Collision_Detection (MOUSE_CLICK_COLLISION_GROUP, 15);
  194. Enable_All_Collision_Detections (GAME_COLLISION_GROUP);
  195. Disable_Collision_Detection (GAME_COLLISION_GROUP, EDITOR_COLLISION_GROUP);
  196. //
  197. // Refresh the per-level include file list
  198. //
  199. STRING_LIST &level_includes =::Get_File_Mgr ()->Get_Include_File_List ();
  200. level_includes.Delete_All ();
  201. //
  202. // Reset the pathfind data
  203. //
  204. PathfindClass::Get_Instance ()->Reset_Sectors ();
  205. PathfindClass::Get_Instance ()->Reset_Portals ();
  206. //
  207. // Reset the list of conversations
  208. //
  209. ConversationMgrClass::Reset_Conversations (ConversationMgrClass::CATEGORY_LEVEL, true);
  210. //
  211. // Reset the map
  212. //
  213. MapMgrClass::Set_Map_Title (0);
  214. MapMgrClass::Set_Map_Texture ("");
  215. MapMgrClass::Set_Map_Center (Vector2 (0.0F, 0.0F));
  216. MapMgrClass::Set_Map_Scale (Vector2 (0.0F, 0.0F));
  217. MapMgrClass::Cloud_All_Cells ();
  218. //
  219. // Initialize the heightfield system
  220. //
  221. HeightfieldMgrClass::Initialize ();
  222. HeightfieldEditorClass::Initialize ();
  223. return ;
  224. }
  225. //////////////////////////////////////////////////////////////////////
  226. //
  227. // Cleanup_Resources
  228. //
  229. //////////////////////////////////////////////////////////////////////
  230. void
  231. SceneEditorClass::Cleanup_Resources (void)
  232. {
  233. //
  234. // Free the background sound
  235. //
  236. if (WWAudioClass::Get_Instance () != NULL) {
  237. WWAudioClass::Get_Instance ()->Set_Background_Music (NULL);
  238. }
  239. //
  240. // Cleanup the different managers
  241. //
  242. m_UndoMgr.Purge_Buffers ();
  243. SAFE_DELETE (m_SelectionMgr);
  244. NodeMgrClass::Free_Nodes ();
  245. NetworkObjectMgrClass::Delete_Pending ();
  246. // Remove all entries from the group list
  247. Reset_Global_Groups_List ();
  248. m_MovingObject = NULL;
  249. //
  250. // Shutdown the heightfield system
  251. //
  252. HeightfieldEditorClass::Shutdown ();
  253. HeightfieldMgrClass::Shutdown ();
  254. return ;
  255. }
  256. //////////////////////////////////////////////////////////////////////
  257. //
  258. // Create_Node
  259. //
  260. //////////////////////////////////////////////////////////////////////
  261. NodeClass *
  262. SceneEditorClass::Create_Node
  263. (
  264. PresetClass * preset,
  265. Matrix3D * transform,
  266. DWORD node_id,
  267. bool add_to_scene
  268. )
  269. {
  270. ::Get_Main_View ()->Allow_Repaint (false);
  271. CWaitCursor wait_cursor;
  272. //
  273. // Create the new node
  274. //
  275. NodeClass *node = NodeMgrClass::Create_Node (preset, node_id);
  276. ASSERT (node != NULL);
  277. if (node != NULL) {
  278. //
  279. // Find a good starting position for this node in the scene
  280. //
  281. if (transform != NULL) {
  282. node->Set_Transform (*transform);
  283. } else {
  284. MoverClass::Position_Node (node);
  285. }
  286. //
  287. // Add the new node to the scene
  288. //
  289. if (add_to_scene) {
  290. node->Add_To_Scene ();
  291. }
  292. //
  293. // Update the file manager's database
  294. //
  295. Update_File_Mgr (node);
  296. //
  297. // Repartition the static culling systems if we are dropping
  298. // in a terrain.
  299. //
  300. if (node->Get_Type () == NODE_TYPE_TERRAIN) {
  301. Re_Partition_Static_Lights ();
  302. Re_Partition_Audio_System ();
  303. } else if (node->Get_Type () == NODE_TYPE_WAYPATH) {
  304. ::Get_Mouse_Mgr ()->Set_Mouse_Mode (MouseMgrClass::MODE_WAYPATH_EDIT);
  305. MMWaypathEditClass *mode = (MMWaypathEditClass *)::Get_Mouse_Mgr ()->Get_Mode_Mgr ();
  306. if (mode != NULL) {
  307. mode->Set_Waypath ((WaypathNodeClass *)node);
  308. }
  309. }
  310. //
  311. // Create any linked nodes and put them into the scene
  312. //
  313. if (preset != NULL) {
  314. preset->Create_Linked_Nodes (node);
  315. }
  316. //
  317. // Release our hold on the node
  318. //
  319. node->Release_Ref ();
  320. }
  321. Set_Modified (true);
  322. ::Get_Main_View ()->Allow_Repaint (true);
  323. return node;
  324. }
  325. //////////////////////////////////////////////////////////////////////
  326. //
  327. // Clone_Node
  328. //
  329. //////////////////////////////////////////////////////////////////////
  330. NodeClass *
  331. SceneEditorClass::Clone_Node (NodeClass *node)
  332. {
  333. NodeClass *new_node = node->Clone ();
  334. if (new_node != NULL) {
  335. //
  336. // Make sure the new node has a name and ID
  337. //
  338. NodeMgrClass::Setup_Node_Identity (*new_node);
  339. NodeMgrClass::Add_Node (new_node);
  340. //
  341. // Add the new node to the scene
  342. //
  343. new_node->Add_To_Scene ();
  344. //
  345. // Update the file manager's database
  346. //
  347. Update_File_Mgr (new_node);
  348. }
  349. return new_node;
  350. }
  351. //////////////////////////////////////////////////////////////////////
  352. //
  353. // Reload_Lightmap_Models
  354. //
  355. //////////////////////////////////////////////////////////////////////
  356. void
  357. SceneEditorClass::Reload_Lightmap_Models (void)
  358. {
  359. //
  360. // Save the setting in the registry
  361. //
  362. theApp.WriteProfileInt ("Config", "PrelitMode", WW3D::Get_Prelit_Mode ());
  363. //
  364. // Force free the assets...
  365. //
  366. WW3DAssetManager::Get_Instance ()->Free_Assets ();
  367. //
  368. // Reload the necessary "tool" assets
  369. //
  370. CLevelEditDoc *doc = ::Get_Current_Document ();
  371. if (doc != NULL) {
  372. doc->Preload_Human_Data ();
  373. doc->Preload_Tool_Assets ();
  374. }
  375. //
  376. // Reload all the nodes
  377. //
  378. NodeMgrClass::Reload_Nodes ();
  379. //
  380. // Make sure we don't toss vis
  381. //
  382. Validate_Vis ();
  383. return ;
  384. }
  385. //////////////////////////////////////////////////////////////////////
  386. //
  387. // Add_Node
  388. //
  389. //////////////////////////////////////////////////////////////////////
  390. void
  391. SceneEditorClass::Add_Node (NodeClass *node)
  392. {
  393. NodeMgrClass::Add_Node (node);
  394. node->Add_To_Scene ();
  395. Update_File_Mgr (node);
  396. return ;
  397. }
  398. //////////////////////////////////////////////////////////////////////
  399. //
  400. // Delete_Node
  401. //
  402. //////////////////////////////////////////////////////////////////////
  403. bool
  404. SceneEditorClass::Delete_Node (NodeClass *node, bool allow_undo)
  405. {
  406. // Add this operation to our undo manager
  407. if (allow_undo) {
  408. Begin_Operation (OPERATION_DELETE, node);
  409. }
  410. //
  411. // Remove all files that this node was dependent on from the file manager's list
  412. //
  413. Update_File_Mgr (node, false);
  414. //
  415. // Remove the node from the level
  416. //
  417. node->Remove_From_Scene ();
  418. node->Show_Selection_Box (false);
  419. node->On_Delete ();
  420. NodeMgrClass::Remove_Node (node);
  421. // Notify the undo manager that this operation is over
  422. if (allow_undo) {
  423. End_Operation ();
  424. }
  425. Set_Modified (true);
  426. return true;
  427. }
  428. //////////////////////////////////////////////////////////////////////
  429. //
  430. // Delete_Nodes
  431. //
  432. //////////////////////////////////////////////////////////////////////
  433. bool
  434. SceneEditorClass::Delete_Nodes (PresetClass *preset)
  435. {
  436. bool retval = true;
  437. //
  438. // Build a list of nodes to that are dependent on this preset
  439. //
  440. DynamicVectorClass<NodeClass *> node_removal_list;
  441. for ( NodeClass *node = NodeMgrClass::Get_First ();
  442. node != NULL;
  443. node = NodeMgrClass::Get_Next (node))
  444. {
  445. if (node->Get_Preset () == preset) {
  446. node_removal_list.Add (node);
  447. }
  448. }
  449. //
  450. // Remove these nodes from the level
  451. //
  452. for (int index = 0; index < node_removal_list.Count (); index ++) {
  453. retval &= Delete_Node (node_removal_list[index], false);
  454. }
  455. return retval;
  456. }
  457. //////////////////////////////////////////////////////////////////////
  458. //
  459. // Update_File_Mgr
  460. //
  461. //////////////////////////////////////////////////////////////////////
  462. void
  463. SceneEditorClass::Update_File_Mgr
  464. (
  465. NodeClass * node,
  466. bool add_node
  467. )
  468. {
  469. ::Get_File_Mgr ()->Update (node, add_node);
  470. return ;
  471. }
  472. //////////////////////////////////////////////////////////////////////
  473. //
  474. // Clone_Objects
  475. //
  476. //////////////////////////////////////////////////////////////////////
  477. bool
  478. SceneEditorClass::Clone_Objects (void)
  479. {
  480. m_SelectionMgr->Clone_Group ();
  481. //
  482. // Loop through all the objects in the current selection
  483. // and update the file manager's information based on them
  484. //
  485. int count = m_SelectionMgr->Get_Count ();
  486. for (int index = 0; index < count; index ++) {
  487. NodeClass *node = m_SelectionMgr->Get_At (index);
  488. Update_File_Mgr (node);
  489. }
  490. Set_Modified ();
  491. return true;
  492. }
  493. //////////////////////////////////////////////////////////////////////
  494. //
  495. // Add_Groups_To_List
  496. //
  497. //////////////////////////////////////////////////////////////////////
  498. void
  499. SceneEditorClass::Add_Groups_To_List
  500. (
  501. NodeClass & node,
  502. GROUP_LIST &group_list
  503. )
  504. {
  505. /*group_list += node.Get_Groups ();
  506. // Loop through all the children of this node and
  507. // add their groups to the list as well
  508. for (NodeInstanceClass *child = node.Get_Child ();
  509. child != NULL;
  510. child = child->Get_Sibling ()) {
  511. Add_Groups_To_List (*child, group_list);
  512. }*/
  513. return ;
  514. }
  515. //////////////////////////////////////////////////////////////////////
  516. //
  517. // Build_Group_List
  518. //
  519. //////////////////////////////////////////////////////////////////////
  520. void
  521. SceneEditorClass::Build_Group_List
  522. (
  523. GROUP_LIST & group_list,
  524. NodeClass * node
  525. )
  526. {
  527. if (node != NULL) {
  528. Add_Groups_To_List (*node, group_list);
  529. } else {
  530. //
  531. // Loop through all the objects in the current selection
  532. // and add thier groups to this list
  533. //
  534. for (int index = 0; index < m_SelectionMgr->Get_Count (); index ++) {
  535. NodeClass *node = m_SelectionMgr->Get_At (index);
  536. if (node != NULL) {
  537. Add_Groups_To_List (*node, group_list);
  538. }
  539. }
  540. }
  541. return ;
  542. }
  543. //////////////////////////////////////////////////////////////////////
  544. //
  545. // Add_Nodes_To_List
  546. //
  547. //////////////////////////////////////////////////////////////////////
  548. void
  549. SceneEditorClass::Add_Nodes_To_List
  550. (
  551. NodeClass &node,
  552. NODE_LIST &node_list
  553. )
  554. {
  555. //
  556. // Loop through all the children of this node and
  557. // add them and their children to the list as well
  558. //
  559. /*for (NodeInstanceClass *child = node.Get_Child ();
  560. child != NULL;
  561. child = child->Get_Sibling ()) {
  562. if (child->Is_Owner_Only () == false) {
  563. node_list.Add_Unique (child);
  564. }
  565. Add_Nodes_To_List (*child, node_list);
  566. }*/
  567. return ;
  568. }
  569. //////////////////////////////////////////////////////////////////////
  570. //
  571. // Build_Node_List
  572. //
  573. //////////////////////////////////////////////////////////////////////
  574. Vector3
  575. SceneEditorClass::Build_Node_List (NODE_LIST &node_list)
  576. {
  577. //
  578. // Add all the nodes from the selection set to the list
  579. //
  580. for (int index = 0; index < m_SelectionMgr->Get_Count (); index ++) {
  581. NodeClass *node = m_SelectionMgr->Get_At (index);
  582. if (node != NULL) {
  583. node_list.Add_Unique (node);
  584. }
  585. }
  586. m_SelectionMgr->Set_Dirty ();
  587. return m_SelectionMgr->Get_Center ();
  588. }
  589. //////////////////////////////////////////////////////////////////////
  590. //
  591. // Build_Node_List
  592. //
  593. //////////////////////////////////////////////////////////////////////
  594. void
  595. SceneEditorClass::Build_Node_List
  596. (
  597. NODE_LIST & node_list,
  598. NodeClass * parent_node
  599. )
  600. {
  601. //
  602. // Build a complete list of all the groups in the selection set
  603. //
  604. GROUP_LIST group_list;
  605. Build_Group_List (group_list, parent_node);
  606. // Loop through all the objects of all the groups in the selection
  607. // set and add them to the list
  608. for (int group = 0; group < group_list.Count (); group ++) {
  609. GroupMgrClass *group_mgr = group_list[group];
  610. group_mgr->Set_Dirty ();
  611. for (int index = 0; index < group_mgr->Get_Count (); index ++) {
  612. NodeClass *node = group_mgr->Get_At (index);
  613. if (node != NULL) {
  614. node_list.Add_Unique (node);
  615. Add_Nodes_To_List (*node, node_list);
  616. }
  617. }
  618. }
  619. //
  620. // Don't forget to add the nodes from the selection group as well!
  621. //
  622. if (parent_node == NULL) {
  623. for (int index = 0; index < m_SelectionMgr->Get_Count (); index ++) {
  624. NodeClass *node = m_SelectionMgr->Get_At (index);
  625. if (node != NULL) {
  626. node_list.Add_Unique (node);
  627. Add_Nodes_To_List (*node, node_list);
  628. }
  629. }
  630. } else {
  631. /*if (parent_node->Is_Owner_Only () == false) {
  632. node_list.Add_Unique (pparent_node);
  633. }
  634. Add_Nodes_To_List (*pparent_node, node_list);*/
  635. }
  636. return ;
  637. }
  638. ///////////////////////////////////////////////////////////////
  639. //
  640. // Delete_Nodes
  641. //
  642. ///////////////////////////////////////////////////////////////
  643. void
  644. SceneEditorClass::Delete_Nodes (void)
  645. {
  646. NODE_LIST affected_list;
  647. //
  648. // Build a list of all the nodes that are affected by this operation
  649. //
  650. for (int index = 0; index < m_SelectionMgr->Get_Count (); index ++) {
  651. NodeClass *node = m_SelectionMgr->Get_At (index);
  652. if (node != NULL) {
  653. // Add this node to our list of affected nodes
  654. affected_list.Add_Unique (node);
  655. }
  656. }
  657. // Add this operation to our undo manager
  658. Begin_Operation (OPERATION_DELETE, &affected_list);
  659. //
  660. // Perfrom the actual delete operation
  661. //
  662. for (index = 0; index < affected_list.Count (); index ++) {
  663. Delete_Node (affected_list[index], false);
  664. }
  665. // Notify the undo manager that this operation is over
  666. End_Operation ();
  667. // Reset the contents of the selection.
  668. // Note: We create a temporary group here to keep a refcount
  669. // locked on the selected nodes while we delete the selection group.
  670. // Remember, freeing the selection group decrements the node's refcounts.
  671. //GroupMgrClass temp_group = *m_SelectionMgr;
  672. m_SelectionMgr->Free_List ();
  673. return ;
  674. }
  675. ///////////////////////////////////////////////////////////////
  676. //
  677. // Set_Selection
  678. //
  679. ///////////////////////////////////////////////////////////////
  680. void
  681. SceneEditorClass::Set_Selection (NodeClass *node)
  682. {
  683. // Is this item already in the list?
  684. if (m_SelectionMgr->Is_Item_In_Group (node) == false) {
  685. //
  686. // Make this node the only selected node
  687. //
  688. m_SelectionMgr->Reset ();
  689. m_SelectionMgr->Add_Node (node);
  690. Update_Toolbars ();
  691. }
  692. return ;
  693. }
  694. ///////////////////////////////////////////////////////////////
  695. //
  696. // Toggle_Selection
  697. //
  698. ///////////////////////////////////////////////////////////////
  699. void
  700. SceneEditorClass::Toggle_Selection (NodeClass *node)
  701. {
  702. //
  703. // If this node isn't already in the selection set, then
  704. // add it. However, if its in the selection set, remove it.
  705. //
  706. if (m_SelectionMgr->Is_Item_In_Group (node)) {
  707. m_SelectionMgr->Remove_Node (node);
  708. } else {
  709. m_SelectionMgr->Add_Node (node);
  710. }
  711. Update_Toolbars ();
  712. return ;
  713. }
  714. ///////////////////////////////////////////////////////////////
  715. //
  716. // Update_Toolbars
  717. //
  718. ///////////////////////////////////////////////////////////////
  719. void
  720. SceneEditorClass::Update_Toolbars (void)
  721. {
  722. bool show_ani_toolbar = false;
  723. int frame = 0;
  724. int max_frames = 0;
  725. if (m_SelectionMgr->Get_Count () > 0) {
  726. //
  727. // Loop through all the objects in the current selection
  728. // and output their names to the debug window...
  729. //
  730. CString selection_set = "Selection set: ";
  731. int sel_count = min (m_SelectionMgr->Get_Count (), 4);
  732. for (int index = 0; index < sel_count; index ++) {
  733. NodeClass *node = m_SelectionMgr->Get_At (index);
  734. selection_set += node->Get_Name ();
  735. //
  736. // Print vis-id and occluder status if we're only printing one object
  737. //
  738. PhysClass *phys_obj = node->Peek_Physics_Obj ();
  739. if (m_SelectionMgr->Get_Count () == 1 && phys_obj != NULL) {
  740. StaticPhysClass *static_phys_obj = phys_obj->As_StaticPhysClass();
  741. if (static_phys_obj != NULL) {
  742. selection_set += (" (");
  743. CString visid_string;
  744. visid_string.Format(" VisObjectId = %d, ",static_phys_obj->Get_Vis_Object_ID());
  745. selection_set += visid_string;
  746. visid_string.Format(" VisSectorId = %d, ",static_phys_obj->Get_Vis_Sector_ID());
  747. selection_set += visid_string;
  748. AABTreeLinkClass *link = (AABTreeLinkClass *)static_phys_obj->Get_Cull_Link ();
  749. if (link != NULL) {
  750. visid_string.Format(" CullLink = %d, ",link->Node->Index);
  751. selection_set += visid_string;
  752. }
  753. if (!static_phys_obj->Is_Occluder()) {
  754. selection_set += CString(" Non-Occluder ");
  755. }
  756. selection_set += (")");
  757. } else if (node->Get_Type () == NODE_TYPE_LIGHT) {
  758. selection_set += (" (");
  759. CString visid_string;
  760. visid_string.Format(" VisSectorId = %d, ",((LightNodeClass *)node)->Get_Vis_Sector_ID());
  761. selection_set += visid_string;
  762. selection_set += (")");
  763. } else {
  764. selection_set += (" (");
  765. CString visid_string;
  766. visid_string.Format(" VisObjectId = %d, ",phys_obj->Get_Vis_Object_ID());
  767. selection_set += visid_string;
  768. selection_set += (")");
  769. }
  770. }
  771. selection_set += ", ";
  772. }
  773. if (sel_count < m_SelectionMgr->Get_Count ()) {
  774. selection_set += "and many more....";
  775. }
  776. //
  777. // Now output this string to the debug window
  778. //
  779. selection_set += "\r\n";
  780. ::Output_Message (selection_set);
  781. }
  782. // Show/hide the animation toolbar depending on the current state
  783. CMainFrame *pmainwnd = (CMainFrame *)::AfxGetMainWnd ();
  784. if (pmainwnd != NULL) {
  785. pmainwnd->Show_Ani_Toolbar (show_ani_toolbar);
  786. pmainwnd->Update_Ani_Frame (frame, max_frames);
  787. }
  788. return ;
  789. }
  790. ///////////////////////////////////////////////////////////////
  791. //
  792. // Find_Node_At_Point
  793. //
  794. ///////////////////////////////////////////////////////////////
  795. NodeClass *
  796. SceneEditorClass::Find_Node_At_Point (CPoint point, Vector3 *intersect_pt)
  797. {
  798. //
  799. // Calculate the ray from the current camera pos through
  800. // the mouse cursor.
  801. //
  802. Vector3 ray_start;
  803. Vector3 ray_end;
  804. MoverClass::Get_Mouse_Ray (point, 250.0F, ray_start, ray_end);
  805. //
  806. // Cast the ray into the world
  807. //
  808. CastResultStruct res;
  809. if (intersect_pt != NULL) {
  810. res.ComputeContactPoint = true;
  811. }
  812. PhysClass *physobj = MoverClass::Cast_Ray (res, ray_start, ray_end, MOUSE_CLICK_COLLISION_GROUP);
  813. if ((physobj != NULL) && (physobj->Peek_Model() != NULL)) {
  814. WWDEBUG_SAY(("Picked model: %s\r\n",physobj->Peek_Model()->Get_Name()));
  815. }
  816. //
  817. // Get the node's pointer that was hit from the raycast
  818. //
  819. NodeClass *node = NULL;
  820. if (physobj != NULL) {
  821. HITTESTINFO *hit_info = (HITTESTINFO *)physobj->Peek_Model ()->Get_User_Data ();
  822. if (hit_info != NULL && hit_info->Type == HITTESTINFO::Node) {
  823. node = hit_info->node;
  824. //
  825. // Return the intersection point (if requested)
  826. //
  827. if (intersect_pt != NULL) {
  828. (*intersect_pt) = res.ContactPoint;
  829. }
  830. }
  831. }
  832. // Return a pointer to the node
  833. return node;
  834. }
  835. ///////////////////////////////////////////////////////////////
  836. //
  837. // Execute_Function_At_Point
  838. //
  839. ///////////////////////////////////////////////////////////////
  840. bool
  841. SceneEditorClass::Execute_Function_At_Point (CPoint point)
  842. {
  843. bool processed = false;
  844. //
  845. // Calculate the ray from the current camera pos through
  846. // the mouse cursor.
  847. //
  848. Vector3 ray_start;
  849. Vector3 ray_end;
  850. MoverClass::Get_Mouse_Ray (point, 250.0F, ray_start, ray_end);
  851. //
  852. // Cast the ray into the world
  853. //
  854. CastResultStruct res;
  855. PhysClass *physobj = MoverClass::Cast_Ray (res, ray_start, ray_end, MOUSE_CLICK_COLLISION_GROUP);
  856. //
  857. // Determine if the user clicked on a 'function'
  858. //
  859. NodeClass *node = NULL;
  860. if (physobj != NULL) {
  861. HITTESTINFO *hit_info = (HITTESTINFO *)physobj->Peek_Model ()->Get_User_Data ();
  862. if ((hit_info != NULL) && hit_info->Type == HITTESTINFO::Function) {
  863. hit_info->function->On_Click ();
  864. processed = true;
  865. }
  866. }
  867. // Return the true/false result code
  868. return processed;
  869. }
  870. ///////////////////////////////////////////////////////////////
  871. //
  872. // Move_Selected_Nodes
  873. //
  874. ///////////////////////////////////////////////////////////////
  875. void
  876. SceneEditorClass::Move_Selected_Nodes (void)
  877. {
  878. float speed_modifier = ::Get_Camera_Mgr ()->Get_Speed_Modifier ();
  879. float modifier = (::GetAsyncKeyState (VK_CONTROL) < 0) ? speed_modifier : 1.0F;
  880. Matrix3D coord_system = ::Get_Camera_Mgr ()->Get_Camera ()->Get_Transform ();
  881. bool move_object = false;
  882. Vector3 delta (0, 0, 0);
  883. if (::GetAsyncKeyState (VK_LEFT) < 0) {
  884. //
  885. // Move the objects along the x-axis of the current view
  886. //
  887. Vector3 movement (-0.05F * modifier, 0, 0);
  888. delta += coord_system.Rotate_Vector (movement);
  889. move_object = true;
  890. } else if (::GetAsyncKeyState (VK_RIGHT) < 0) {
  891. //
  892. // Move the objects along the x-axis of the current view
  893. //
  894. Vector3 movement (0.05F * modifier, 0, 0);
  895. delta += coord_system.Rotate_Vector (movement);
  896. move_object = true;
  897. }
  898. if (::GetAsyncKeyState (VK_UP) < 0) {
  899. //
  900. // Should we move the object 'up'?
  901. //
  902. if (::GetAsyncKeyState (VK_SHIFT) < 0) {
  903. delta += Vector3 (0, 0, 0.05F * modifier);
  904. } else {
  905. //
  906. // Move the object along the 'ground-plane' at an axis orthogonal to the view's x-axis.
  907. //
  908. Vector3 y_vector = Vector3::Cross_Product (coord_system.Get_X_Vector (), Vector3 (0, 0, 1));
  909. y_vector.Normalize ();
  910. delta += y_vector * (-0.05F * modifier);
  911. }
  912. move_object = true;
  913. } else if (::GetAsyncKeyState (VK_DOWN) < 0) {
  914. //
  915. // Should we move the object 'up'?
  916. //
  917. if (::GetAsyncKeyState (VK_SHIFT) < 0) {
  918. delta += Vector3 (0, 0, -0.05F * modifier);
  919. } else {
  920. //
  921. // Move the object along the 'ground-plane' at an axis orthogonal to the view's x-axis.
  922. //
  923. Vector3 y_vector = Vector3::Cross_Product (coord_system.Get_X_Vector (), Vector3 (0, 0, 1));
  924. y_vector.Normalize ();
  925. delta += y_vector * (0.05F * modifier);
  926. }
  927. move_object = true;
  928. }
  929. //
  930. // Move the selected nodes if necessary
  931. //
  932. if (move_object) {
  933. MoverClass::Move_Nodes (delta);
  934. }
  935. return ;
  936. }
  937. ///////////////////////////////////////////////////////////////
  938. //
  939. // On_Frame
  940. //
  941. ///////////////////////////////////////////////////////////////
  942. void
  943. SceneEditorClass::On_Frame (void)
  944. {
  945. //
  946. // Let the heightfield editor think
  947. //
  948. HeightfieldEditorClass::On_Frame_Update ();
  949. //
  950. // Get the currently 'focussed' process
  951. //
  952. HWND current_focus_wnd = ::GetFocus ();
  953. DWORD process_id = 0;
  954. if (current_focus_wnd != NULL) {
  955. ::GetWindowThreadProcessId (current_focus_wnd, &process_id);
  956. }
  957. //
  958. // If we are the current process, then move the nodes
  959. //
  960. if (process_id == ::GetCurrentProcessId ()) {
  961. Move_Selected_Nodes ();
  962. }
  963. if (m_MovingObject != NULL) {
  964. PathMgrClass::Resolve_Paths (Vector3 (0, 0, 0));
  965. PhysicalGameObj *game_obj = ((ObjectNodeClass *)m_MovingObject)->Peek_Game_Obj ();
  966. ((SmartGameObj *)game_obj)->Generate_Control ();
  967. game_obj->Think ();
  968. PhysClass *phys_obj = game_obj->Peek_Physical_Object ();
  969. if (phys_obj != NULL) {
  970. phys_obj->Timestep (TimeManager::Get_Frame_Seconds ());
  971. }
  972. game_obj->Post_Think ();
  973. #if 0
  974. ActionClass *action = ((SmartGameObj *)game_obj)->Get_Action ();
  975. if (action != NULL && action->Get_Movement () == NULL) {
  976. //m_MovingObject = NULL;
  977. }
  978. #endif
  979. }
  980. return ;
  981. }
  982. ///////////////////////////////////////////////////////////////
  983. //
  984. // Record_Vis_Info
  985. //
  986. ///////////////////////////////////////////////////////////////
  987. void
  988. SceneEditorClass::Record_Vis_Info (const Matrix3D &view_transform, const Vector3 &sample_location)
  989. {
  990. // Put up an hour glass
  991. CWaitCursor wait_cursor;
  992. PresetClass *preset = PresetMgrClass::Get_First (CLASSID_VIS_POINT_DEF, PresetMgrClass::ID_CLASS);
  993. if (preset == NULL) {
  994. CString message = "Missing 'Manual Vis Point' preset. Please create a default preset under the 'Manual Vis Point' folder in the preset library.";
  995. ::MessageBox (::AfxGetMainWnd ()->m_hWnd, message, "Missing Preset", MB_OK | MB_ICONEXCLAMATION);
  996. } else {
  997. //
  998. // When doing a manual vis, use the FOV and clip settings of the in-game camera
  999. //
  1000. CameraClass *scene_cam = CombatManager::Get_Camera ();
  1001. WWASSERT (scene_cam != NULL);
  1002. float scene_znear = 0;
  1003. float scene_zfar = 0;
  1004. scene_cam->Get_Clip_Planes (scene_znear, scene_zfar);
  1005. scene_cam->Set_Clip_Planes (scene_znear, VIS_FAR_CLIP);
  1006. //
  1007. // Generate the 'vis' information
  1008. //
  1009. VisSampleClass vis_sample = Update_Vis (view_transform * Vector3 (0, 0, -scene_znear), view_transform, (VisDirBitsType)(VIS_FORWARD_BIT | VIS_DONT_RECENTER), scene_cam);
  1010. if (vis_sample.Get_Bits_Changed () > 0 && vis_sample.Sample_Rejected () == false) {
  1011. //
  1012. // Convert the matrix to an obj-space transform
  1013. //
  1014. Matrix3D cam_to_world (Vector3 (0, 0, -1), Vector3 (-1, 0, 0), Vector3 (0, 1, 0), Vector3 (0, 0, 0));
  1015. Matrix3D obj_tm = view_transform * cam_to_world;
  1016. //
  1017. // Create the UI
  1018. //
  1019. Create_Vis_Point (view_transform);
  1020. VisPointNodeClass *vis_point = new VisPointNodeClass (preset);
  1021. vis_point->Set_ID (::Get_Node_Mgr ().Get_Node_ID (vis_point->Get_Type ()));
  1022. vis_point->Initialize ();
  1023. vis_point->Add_To_Scene ();
  1024. vis_point->Set_Transform (obj_tm);
  1025. vis_point->Set_Vis_Tile_Location (sample_location);
  1026. vis_point->Save_Camera_Settings (*scene_cam);
  1027. vis_point->Hide (!m_ManualVisPointsVisible);
  1028. ::Get_Node_Mgr ().Add_Node (vis_point);
  1029. vis_point->Release_Ref ();
  1030. Set_Modified (true);
  1031. }
  1032. //
  1033. // Put the normal settings back into the scene camera
  1034. //
  1035. scene_cam->Set_Clip_Planes (scene_znear, scene_zfar);
  1036. }
  1037. return ;
  1038. }
  1039. ///////////////////////////////////////////////////////////////
  1040. //
  1041. // Begin_Operation
  1042. //
  1043. ///////////////////////////////////////////////////////////////
  1044. void
  1045. SceneEditorClass::Begin_Operation
  1046. (
  1047. OPERATION_TYPE type,
  1048. NodeClass * node
  1049. )
  1050. {
  1051. if (node != NULL) {
  1052. // Build a list containing the node
  1053. NODE_LIST node_list;
  1054. node_list.Add_Unique (node);
  1055. // Pass this list onto the undo manager
  1056. Begin_Operation (type, &node_list);
  1057. }
  1058. return ;
  1059. }
  1060. ///////////////////////////////////////////////////////////////
  1061. //
  1062. // Begin_Operation
  1063. //
  1064. ///////////////////////////////////////////////////////////////
  1065. void
  1066. SceneEditorClass::Begin_Operation
  1067. (
  1068. OPERATION_TYPE type,
  1069. NODE_LIST * affected_list
  1070. )
  1071. {
  1072. NODE_LIST node_list;
  1073. //
  1074. // If necessary, build a complete list of all the nodes that will be
  1075. // affected by this operation
  1076. //
  1077. if (affected_list == NULL) {
  1078. Build_Node_List (node_list, NULL);
  1079. affected_list = &node_list;
  1080. }
  1081. m_UndoMgr.Begin_Operation (type, *affected_list);
  1082. return ;
  1083. }
  1084. ///////////////////////////////////////////////////////////////
  1085. //
  1086. // End_Operation
  1087. //
  1088. ///////////////////////////////////////////////////////////////
  1089. void
  1090. SceneEditorClass::End_Operation (void)
  1091. {
  1092. m_UndoMgr.End_Operation ();
  1093. return ;
  1094. }
  1095. ///////////////////////////////////////////////////////////////
  1096. //
  1097. // Undo
  1098. //
  1099. ///////////////////////////////////////////////////////////////
  1100. bool
  1101. SceneEditorClass::Undo (void)
  1102. {
  1103. m_UndoMgr.Perform_Undo ();
  1104. return true;
  1105. }
  1106. ///////////////////////////////////////////////////////////////
  1107. //
  1108. // Cut_Objects
  1109. //
  1110. ///////////////////////////////////////////////////////////////
  1111. bool
  1112. SceneEditorClass::Cut_Objects (void)
  1113. {
  1114. bool retval = false;
  1115. // Turn painting off
  1116. CLevelEditView::Allow_Repaint (false);
  1117. // Copy the objects to the clipboard, then delete them
  1118. if (Copy_Objects ()) {
  1119. Delete_Nodes ();
  1120. }
  1121. // Turn painting back on
  1122. CLevelEditView::Allow_Repaint (true);
  1123. // Return the true/false result code
  1124. return retval;
  1125. }
  1126. ///////////////////////////////////////////////////////////////
  1127. //
  1128. // Copy_Objects
  1129. //
  1130. ///////////////////////////////////////////////////////////////
  1131. bool
  1132. SceneEditorClass::Copy_Objects (void)
  1133. {
  1134. Empty_Local_Clipboard ();
  1135. // Loop through all the nodes in the current selection
  1136. // and 'copy' them.
  1137. int count = m_SelectionMgr->Get_Count ();
  1138. for (int index = 0; index < count; index ++) {
  1139. NodeClass *node = m_SelectionMgr->Get_At (index);
  1140. //
  1141. // Copy the node and add it to our 'clipboard'
  1142. //
  1143. NodeClass *node_copy = node->Clone ();
  1144. ASSERT (node_copy != NULL);
  1145. if (node_copy != NULL) {
  1146. node_copy->Remove_From_Scene ();
  1147. m_LocalClipboard.Add (node_copy);
  1148. }
  1149. }
  1150. return true;
  1151. }
  1152. ///////////////////////////////////////////////////////////////
  1153. //
  1154. // Paste_Objects
  1155. //
  1156. ///////////////////////////////////////////////////////////////
  1157. bool
  1158. SceneEditorClass::Paste_Objects (void)
  1159. {
  1160. bool retval = (m_LocalClipboard.Count () > 0);
  1161. // Turn painting off
  1162. CLevelEditView::Allow_Repaint (false);
  1163. // Reset the selection group
  1164. m_SelectionMgr->Reset ();
  1165. for (int index = 0; index < m_LocalClipboard.Count (); index ++) {
  1166. //
  1167. // Copy the node on the clipboard and add it to the scene
  1168. //
  1169. NodeClass *node = m_LocalClipboard[index];
  1170. NodeClass *node_copy = Clone_Node (node);
  1171. if (node_copy != NULL) {
  1172. m_SelectionMgr->Add_Node (node_copy);
  1173. MEMBER_RELEASE (node_copy);
  1174. }
  1175. }
  1176. //
  1177. // Cast the nodes along the line-of-sight ray for 500 meters
  1178. //
  1179. Vector3 ray_start;
  1180. Vector3 ray_end;
  1181. MoverClass::Get_LOS_Ray (500.0F, ray_start, ray_end);
  1182. MoverClass::Position_Nodes_Along_Ray (ray_start, ray_end);
  1183. // Turn painting back on
  1184. CLevelEditView::Allow_Repaint (true);
  1185. Update_Toolbars ();
  1186. // Return the true/false result code
  1187. return retval;
  1188. }
  1189. ///////////////////////////////////////////////////////////////
  1190. //
  1191. // Can_Paste
  1192. //
  1193. ///////////////////////////////////////////////////////////////
  1194. bool
  1195. SceneEditorClass::Can_Paste (void)
  1196. {
  1197. // Return the true/false result code
  1198. return bool(m_LocalClipboard.Count () > 0);
  1199. }
  1200. ///////////////////////////////////////////////////////////////
  1201. //
  1202. // Empty_Local_Clipboard
  1203. //
  1204. ///////////////////////////////////////////////////////////////
  1205. void
  1206. SceneEditorClass::Empty_Local_Clipboard (void)
  1207. {
  1208. // Loop through all the entries in the clipboard and delete them
  1209. for (int index = 0; index < m_LocalClipboard.Count (); index ++) {
  1210. MEMBER_RELEASE (m_LocalClipboard[index]);
  1211. }
  1212. // Reset the list
  1213. m_LocalClipboard.Delete_All ();
  1214. return ;
  1215. }
  1216. ///////////////////////////////////////////////////////////////
  1217. //
  1218. // Add_Global_Group
  1219. //
  1220. ///////////////////////////////////////////////////////////////
  1221. GroupMgrClass *
  1222. SceneEditorClass::Add_Global_Group
  1223. (
  1224. const CString & name,
  1225. NODE_LIST * initial_list
  1226. )
  1227. {
  1228. // Create a new group with the speicfied name
  1229. UserGroupMgrClass *group = new UserGroupMgrClass;
  1230. group->Set_Name (name);
  1231. // If we have a list of nodes to add to this group,
  1232. // then do so now.
  1233. if (initial_list != NULL) {
  1234. for (int index = 0; index < initial_list->Count (); index ++) {
  1235. group->Add_Node ((*initial_list)[index]);
  1236. }
  1237. }
  1238. // Add this new group manager to our global list
  1239. m_GroupsList.Add_Unique (group);
  1240. // Return a pointer to the new group
  1241. return group;
  1242. }
  1243. ///////////////////////////////////////////////////////////////
  1244. //
  1245. // Remove_Global_Group
  1246. //
  1247. ///////////////////////////////////////////////////////////////
  1248. void
  1249. SceneEditorClass::Remove_Global_Group (GroupMgrClass *group)
  1250. {
  1251. // If this group is in our global list, then remove
  1252. // it from the list, remove it from any UI, and free its memory.
  1253. if (m_GroupsList.Is_Item_In_List (group)) {
  1254. m_GroupsList.Remove (group);
  1255. Remove_Group_From_Toolbar (group);
  1256. SAFE_DELETE (group);
  1257. }
  1258. return ;
  1259. }
  1260. ///////////////////////////////////////////////////////////////
  1261. //
  1262. // Reset_Global_Groups_List
  1263. //
  1264. ///////////////////////////////////////////////////////////////
  1265. void
  1266. SceneEditorClass::Reset_Global_Groups_List (void)
  1267. {
  1268. // Loop through all the groups in our list and
  1269. // free their associated memory.
  1270. for (int index = 0; index < m_GroupsList.Count (); index ++) {
  1271. GroupMgrClass *group = m_GroupsList[index];
  1272. if (group != NULL) {
  1273. Remove_Group_From_Toolbar (group);
  1274. SAFE_DELETE (group);
  1275. }
  1276. }
  1277. // Remove all the entries from the list
  1278. m_GroupsList.Delete_All ();
  1279. return ;
  1280. }
  1281. ////////////////////////////////////////////////////////////////
  1282. //
  1283. // Add_Group_To_Toolbar
  1284. //
  1285. ////////////////////////////////////////////////////////////////
  1286. void
  1287. SceneEditorClass::Add_Group_To_Toolbar (GroupMgrClass *group)
  1288. {
  1289. ASSERT (group != NULL);
  1290. // Get the form representing the groups list, and add this group to it
  1291. /*GroupsPageClass *group_page = ::Get_Groups_Form ();
  1292. if (group_page != NULL) {
  1293. group_page->Add_Group (group);
  1294. }*/
  1295. return ;
  1296. }
  1297. ////////////////////////////////////////////////////////////////
  1298. //
  1299. // Remove_Group_From_Toolbar
  1300. //
  1301. ////////////////////////////////////////////////////////////////
  1302. void
  1303. SceneEditorClass::Remove_Group_From_Toolbar (GroupMgrClass *group)
  1304. {
  1305. ASSERT (group != NULL);
  1306. // Get the form representing the groups list, and remove this group from it
  1307. /*GroupsPageClass *group_page = ::Get_Groups_Form ();
  1308. if (group_page != NULL) {
  1309. group_page->Remove_Group (group);
  1310. }*/
  1311. return ;
  1312. }
  1313. ////////////////////////////////////////////////////////////////
  1314. //
  1315. // Turn_Lights_On
  1316. //
  1317. ////////////////////////////////////////////////////////////////
  1318. void
  1319. SceneEditorClass::Turn_Lights_On (bool onoff)
  1320. {
  1321. m_bLightsOn = onoff;
  1322. //
  1323. // Loop through all the lights in the world
  1324. //
  1325. /*LightInstanceClass *plight = NULL;
  1326. for (plight = (LightInstanceClass *)::Get_Node_Mgr ().Get_First (NODE_TYPE_LIGHT);
  1327. plight != NULL;
  1328. plight = (LightInstanceClass *)::Get_Node_Mgr ().Get_Next (NODE_TYPE_LIGHT)) {
  1329. plight->Turn_Light_On (onoff);
  1330. }*/
  1331. ::Refresh_Main_View ();
  1332. return ;
  1333. }
  1334. ////////////////////////////////////////////////////////////////
  1335. //
  1336. // Lock_Nodes
  1337. //
  1338. ////////////////////////////////////////////////////////////////
  1339. void
  1340. SceneEditorClass::Lock_Nodes (bool lock)
  1341. {
  1342. //
  1343. // Loop through all the nodes in the current selection
  1344. //
  1345. for (int index = 0; index < m_SelectionMgr->Get_Count (); index ++) {
  1346. NodeClass *node = m_SelectionMgr->Get_At (index);
  1347. if (node != NULL) {
  1348. //
  1349. // Lock the node, this keep the node from moving during
  1350. // drag operations.
  1351. //
  1352. node->Lock (lock);
  1353. }
  1354. }
  1355. return ;
  1356. }
  1357. ////////////////////////////////////////////////////////////////
  1358. //
  1359. // Set_Background_Music
  1360. //
  1361. ////////////////////////////////////////////////////////////////
  1362. void
  1363. SceneEditorClass::Set_Background_Music (LPCTSTR filename)
  1364. {
  1365. //
  1366. // Stop the old sound
  1367. //
  1368. WWAudioClass::Get_Instance ()->Set_Background_Music (NULL);
  1369. //
  1370. // Remove the sound file from the file manager
  1371. //
  1372. if (m_BackgroundSoundFilename.GetLength () > 0) {
  1373. CString old_path = ::Get_File_Mgr ()->Make_Full_Path (m_BackgroundSoundFilename);
  1374. ::Get_File_Mgr ()->Remove_File (::Get_File_Mgr ()->Find_File (old_path));
  1375. m_BackgroundSoundFilename.Empty ();
  1376. }
  1377. //
  1378. // Set the new background music
  1379. //
  1380. if ((filename != NULL) && (filename[0] != 0)) {
  1381. CString path = ::Get_File_Mgr ()->Make_Full_Path (filename);
  1382. if (::Get_File_Mgr ()->Does_File_Exist (path, true)) {
  1383. //
  1384. // Set the background music
  1385. //
  1386. ::Set_Current_Directory (::Strip_Filename_From_Path (path));
  1387. WWAudioClass::Get_Instance ()->Set_Background_Music (::Get_Filename_From_Path (path));
  1388. //
  1389. // Add this sound to the file manager
  1390. //
  1391. ::Get_File_Mgr ()->Add_File (path);
  1392. m_BackgroundSoundFilename = path;
  1393. }
  1394. }
  1395. return ;
  1396. }
  1397. ////////////////////////////////////////////////////////////////
  1398. //
  1399. // View_Aggregate_Children
  1400. //
  1401. ////////////////////////////////////////////////////////////////
  1402. void
  1403. SceneEditorClass::View_Aggregate_Children (bool view)
  1404. {
  1405. // Did the state change?
  1406. /*if (view != m_bAggregateChildrenVisible) {
  1407. m_bAggregateChildrenVisible = view;
  1408. // Make sure to reset the selection for this to work
  1409. m_SelectionMgr->Reset ();
  1410. // Update all the aggregates in the level
  1411. ::Get_Node_Mgr ().Update_Aggregate_Instances ();
  1412. }*/
  1413. return ;
  1414. }
  1415. ////////////////////////////////////////////////////////////////
  1416. //
  1417. // Display_Vis_Points
  1418. //
  1419. ////////////////////////////////////////////////////////////////
  1420. void
  1421. SceneEditorClass::Display_Vis_Points (bool onoff)
  1422. {
  1423. // Did the state change?
  1424. if (onoff != m_bVisPointsDisplayed) {
  1425. m_bVisPointsDisplayed = onoff;
  1426. //
  1427. // Show/hide all the vis points
  1428. //
  1429. for (int index = 0; index < m_VisPoints.Count (); index ++) {
  1430. DecorationPhysClass *vis_point = m_VisPoints[index];
  1431. if (vis_point != NULL) {
  1432. if (onoff) {
  1433. Add_Dynamic_Object (vis_point);
  1434. } else {
  1435. Remove_Object (vis_point);
  1436. }
  1437. }
  1438. }
  1439. }
  1440. return ;
  1441. }
  1442. ////////////////////////////////////////////////////////////////
  1443. //
  1444. // Create_Vis_Point
  1445. //
  1446. ////////////////////////////////////////////////////////////////
  1447. void
  1448. SceneEditorClass::Create_Vis_Point (const Matrix3D &transform)
  1449. {
  1450. //
  1451. // Create a new vis-point marker at the location
  1452. //
  1453. DecorationPhysClass *new_point = new DecorationPhysClass;
  1454. new_point->Set_Model_By_Name ("WAYSTART");
  1455. new_point->Set_Transform (transform);
  1456. new_point->Set_Collision_Group (0);
  1457. //
  1458. // Add this new point to our list
  1459. //
  1460. m_VisPoints.Add (new_point);
  1461. if (m_bVisPointsDisplayed) {
  1462. Add_Dynamic_Object (new_point);
  1463. }
  1464. return ;
  1465. }
  1466. ////////////////////////////////////////////////////////////////
  1467. //
  1468. // Remove_All_Vis_Points
  1469. //
  1470. ////////////////////////////////////////////////////////////////
  1471. void
  1472. SceneEditorClass::Remove_All_Vis_Points (void)
  1473. {
  1474. ::Get_Main_View ()->Allow_Repaint (false);
  1475. CWaitCursor wait_cursor;
  1476. //
  1477. // Build a list of all the vis points in the world
  1478. //
  1479. for (int index = 0; index < m_VisPoints.Count (); index ++) {
  1480. DecorationPhysClass *vis_point = m_VisPoints[index];
  1481. if (vis_point != NULL) {
  1482. Remove_Object (vis_point);
  1483. vis_point->Release_Ref ();
  1484. }
  1485. }
  1486. m_VisPoints.Delete_All ();
  1487. ::Get_Main_View ()->Allow_Repaint (true);
  1488. return ;
  1489. }
  1490. ////////////////////////////////////////////////////////////////
  1491. //
  1492. // Discard_Vis
  1493. //
  1494. ////////////////////////////////////////////////////////////////
  1495. void
  1496. SceneEditorClass::Discard_Vis (void)
  1497. {
  1498. m_VisLog.Reset_Log ();
  1499. Remove_All_Vis_Points ();
  1500. PhysicsSceneClass::Internal_Vis_Reset ();
  1501. return ;
  1502. }
  1503. ////////////////////////////////////////////////////////////////
  1504. //
  1505. // Reset_Vis
  1506. //
  1507. ////////////////////////////////////////////////////////////////
  1508. void
  1509. SceneEditorClass::Reset_Vis (bool doitnow)
  1510. {
  1511. m_VisLog.Reset_Log ();
  1512. Remove_All_Vis_Points ();
  1513. PhysicsSceneClass::Reset_Vis (doitnow);
  1514. return ;
  1515. }
  1516. ////////////////////////////////////////////////////////////////
  1517. //
  1518. // Internal_Vis_Reset
  1519. //
  1520. ////////////////////////////////////////////////////////////////
  1521. void
  1522. SceneEditorClass::Internal_Vis_Reset (void)
  1523. {
  1524. if (VisResetNeeded) {
  1525. PhysicsSceneClass::Internal_Vis_Reset ();
  1526. //
  1527. // Ask all the nodes
  1528. //
  1529. NodeClass *node = NULL;
  1530. for ( node = NodeMgrClass::Get_First ();
  1531. node != NULL;
  1532. node = NodeMgrClass::Get_Next (node))
  1533. {
  1534. node->Update_Cached_Vis_IDs ();
  1535. }
  1536. }
  1537. return ;
  1538. }
  1539. ////////////////////////////////////////////////////////////////
  1540. //
  1541. // Get_Vis_Camera_FOV
  1542. //
  1543. ////////////////////////////////////////////////////////////////
  1544. void
  1545. SceneEditorClass::Get_Vis_Camera_FOV (double &hfov, double &vfov)
  1546. {
  1547. CameraClass *vis_camera = Get_Vis_Camera ();
  1548. WWASSERT (vis_camera != NULL);
  1549. if (vis_camera != NULL) {
  1550. hfov = vis_camera->Get_Horizontal_FOV ();
  1551. vfov = vis_camera->Get_Vertical_FOV ();
  1552. MEMBER_RELEASE (vis_camera);
  1553. } else {
  1554. hfov = 0;
  1555. vfov = 0;
  1556. }
  1557. return ;
  1558. }
  1559. ////////////////////////////////////////////////////////////////
  1560. //
  1561. // Get_Vis_Camera_Clip_Planes
  1562. //
  1563. ////////////////////////////////////////////////////////////////
  1564. void
  1565. SceneEditorClass::Get_Vis_Camera_Clip_Planes (float &znear, float &zfar)
  1566. {
  1567. CameraClass *vis_camera = Get_Vis_Camera ();
  1568. WWASSERT (vis_camera != NULL);
  1569. if (vis_camera != NULL) {
  1570. vis_camera->Get_Clip_Planes (znear, zfar);
  1571. MEMBER_RELEASE (vis_camera);
  1572. } else {
  1573. znear = 0;
  1574. zfar = 0;
  1575. }
  1576. return ;
  1577. }
  1578. ////////////////////////////////////////////////////////////////
  1579. //
  1580. // Get_Render_Camera
  1581. //
  1582. ////////////////////////////////////////////////////////////////
  1583. CameraClass *
  1584. SceneEditorClass::Get_Render_Camera (void)
  1585. {
  1586. CameraClass *camera = NULL;
  1587. if (::Get_Camera_Mgr ()->Get_Camera_Mode () == CameraMgr::MODE_WALK_THROUGH) {
  1588. camera = CombatManager::Get_Camera ();
  1589. } else {
  1590. camera = ::Get_Camera_Mgr ()->Get_Camera ();
  1591. }
  1592. return camera;
  1593. }
  1594. ////////////////////////////////////////////////////////////////
  1595. //
  1596. // Generate_Pathfind_Portals
  1597. //
  1598. ////////////////////////////////////////////////////////////////
  1599. void
  1600. SceneEditorClass::Generate_Pathfind_Portals (void)
  1601. {
  1602. CWaitCursor wait_cursor;
  1603. //
  1604. // Create a pathfind floodfiller object
  1605. //
  1606. PathfindSectorBuilderClass builder;
  1607. builder.Allow_Water_Floodfill (true);
  1608. builder.Initialize ();
  1609. //
  1610. // Find all the pathfind start-points in the level and add
  1611. // them to the floodfiller
  1612. //
  1613. NodeClass *node = NULL;
  1614. for ( node = NodeMgrClass::Get_First ();
  1615. node != NULL;
  1616. node = NodeMgrClass::Get_Next (node))
  1617. {
  1618. if (node->Get_Type () == NODE_TYPE_PATHFIND_START) {
  1619. builder.Add_Start_Point (node->Get_Transform ().Get_Translation ());
  1620. }
  1621. }
  1622. //
  1623. // Perform the floodfill from each of the start locations
  1624. //
  1625. builder.Generate_Sectors ();
  1626. builder.Compress_Sectors_For_Pathfind ();
  1627. //
  1628. // Build height data for flying vehicles
  1629. //
  1630. HeightDBClass::Generate ();
  1631. //
  1632. // Cleanup
  1633. //
  1634. builder.Shutdown ();
  1635. return ;
  1636. }
  1637. ////////////////////////////////////////////////////////////////
  1638. //
  1639. // Export_VIS
  1640. //
  1641. ////////////////////////////////////////////////////////////////
  1642. void
  1643. SceneEditorClass::Export_VIS (LPCTSTR filename)
  1644. {
  1645. //
  1646. // Create the file
  1647. //
  1648. HANDLE hfile = ::CreateFile (filename,
  1649. GENERIC_WRITE,
  1650. 0,
  1651. NULL,
  1652. CREATE_ALWAYS,
  1653. 0L,
  1654. NULL);
  1655. ASSERT (hfile != INVALID_HANDLE_VALUE);
  1656. if (hfile != INVALID_HANDLE_VALUE) {
  1657. RawFileClass file_obj;
  1658. file_obj.Attach (hfile);
  1659. ChunkSaveClass chunk_save (&file_obj);
  1660. //
  1661. // Export the data to this file
  1662. //
  1663. Export_Vis_Data (chunk_save);
  1664. }
  1665. return ;
  1666. }
  1667. ////////////////////////////////////////////////////////////////
  1668. //
  1669. // Update_Selection_Boxes
  1670. //
  1671. ////////////////////////////////////////////////////////////////
  1672. void
  1673. SceneEditorClass::Update_Selection_Boxes (void)
  1674. {
  1675. //
  1676. // Loop through all the nodes in the current selection
  1677. //
  1678. for (int index = 0; index < m_SelectionMgr->Get_Count (); index ++) {
  1679. NodeClass *node = m_SelectionMgr->Get_At (index);
  1680. if (node != NULL) {
  1681. //
  1682. // Ask the node to update its selection box (color and pos)
  1683. //
  1684. node->Update_Selection_Box ();
  1685. }
  1686. }
  1687. return ;
  1688. }
  1689. ////////////////////////////////////////////////////////////////
  1690. //
  1691. // Re_Partition_Audio_System
  1692. //
  1693. ////////////////////////////////////////////////////////////////
  1694. void
  1695. SceneEditorClass::Re_Partition_Audio_System (void)
  1696. {
  1697. const AABoxClass & level_bounds = StaticCullingSystem->Get_Bounding_Box();
  1698. Vector3 min,max;
  1699. min = level_bounds.Center - level_bounds.Extent;
  1700. max = level_bounds.Center + level_bounds.Extent;
  1701. SoundSceneClass *sound_scene = WWAudioClass::Get_Instance ()->Get_Sound_Scene ();
  1702. if (sound_scene != NULL) {
  1703. sound_scene->Re_Partition (min, max);
  1704. }
  1705. return ;
  1706. }
  1707. ////////////////////////////////////////////////////////////////
  1708. //
  1709. // Are_Manual_Vis_Points_Visible
  1710. //
  1711. ////////////////////////////////////////////////////////////////
  1712. bool
  1713. SceneEditorClass::Are_Manual_Vis_Points_Visible (void)
  1714. {
  1715. return m_ManualVisPointsVisible;
  1716. }
  1717. ////////////////////////////////////////////////////////////////
  1718. //
  1719. // Show_Manual_Vis_Points
  1720. //
  1721. ////////////////////////////////////////////////////////////////
  1722. void
  1723. SceneEditorClass::Show_Manual_Vis_Points (bool show_points)
  1724. {
  1725. if (m_ManualVisPointsVisible != show_points) {
  1726. m_ManualVisPointsVisible = show_points;
  1727. NodeClass *node = NULL;
  1728. for ( node = NodeMgrClass::Get_First ();
  1729. node != NULL;
  1730. node = NodeMgrClass::Get_Next (node))
  1731. {
  1732. if (node->Get_Type () == NODE_TYPE_VIS_POINT) {
  1733. node->Hide (!m_ManualVisPointsVisible);
  1734. }
  1735. }
  1736. }
  1737. return ;
  1738. }
  1739. ////////////////////////////////////////////////////////////////
  1740. //
  1741. // DoObjectGoto
  1742. //
  1743. ////////////////////////////////////////////////////////////////
  1744. void
  1745. SceneEditorClass::DoObjectGoto (NodeClass *node1, NodeClass *node2)
  1746. {
  1747. SANITY_CHECK(node1 != NULL && node2 != NULL && node1->Get_Type () == NODE_TYPE_OBJECT) {
  1748. return ;
  1749. }
  1750. //
  1751. // Register all the waypaths with the pathfinding system
  1752. //
  1753. for ( NodeClass *node = NodeMgrClass::Get_First (NODE_TYPE_WAYPATH);
  1754. node != NULL;
  1755. node = NodeMgrClass::Get_Next (node, NODE_TYPE_WAYPATH))
  1756. {
  1757. node->Pre_Export ();
  1758. }
  1759. //
  1760. // Force the pathfind system to use any available waypath data
  1761. // in its evaluation
  1762. //
  1763. PathfindClass::Get_Instance ()->Generate_Waypath_Sectors_And_Portals ();
  1764. m_MovingObject = node1;
  1765. PhysicalGameObj *game_obj = ((ObjectNodeClass *)m_MovingObject)->Peek_Game_Obj ();
  1766. if (game_obj != NULL && game_obj->As_SmartGameObj () != NULL) {
  1767. ActionClass *action = ((SmartGameObj *)game_obj)->Get_Action ();
  1768. ActionParamsStruct parameters;
  1769. parameters.MoveLocation = node2->Get_Transform ().Get_Translation ();
  1770. parameters.MoveArrivedDistance = 3.0F;
  1771. action->Goto( parameters );
  1772. }
  1773. //
  1774. // Unregister all the waypaths with the pathfinding system
  1775. //
  1776. for ( node = NodeMgrClass::Get_First (NODE_TYPE_WAYPATH);
  1777. node != NULL;
  1778. node = NodeMgrClass::Get_Next (node, NODE_TYPE_WAYPATH))
  1779. {
  1780. node->Post_Export ();
  1781. }
  1782. return ;
  1783. }
  1784. ////////////////////////////////////////////////////////////////
  1785. //
  1786. // Export_Lights
  1787. //
  1788. ////////////////////////////////////////////////////////////////
  1789. void
  1790. SceneEditorClass::Export_Lights (LPCTSTR filename)
  1791. {
  1792. FileClass *file = _TheFileFactory->Get_File (filename);
  1793. if (file != NULL && file->Create () && file->Open (FileClass::WRITE)) {
  1794. //
  1795. // Write the first chunk header
  1796. //
  1797. ChunkSaveClass csave (file);
  1798. csave.Begin_Chunk (W3D_CHUNK_LIGHTSCAPE);
  1799. //
  1800. // Loop over all the lights in the scene
  1801. //
  1802. for ( NodeClass *node = NodeMgrClass::Get_First (NODE_TYPE_LIGHT);
  1803. node != NULL;
  1804. node = NodeMgrClass::Get_Next (node, NODE_TYPE_LIGHT))
  1805. {
  1806. LightNodeClass *light_node = (LightNodeClass *)node;
  1807. //
  1808. // Get the actual light from the editor object
  1809. //
  1810. LightClass *light = light_node->Peek_Light ();
  1811. if (light != NULL) {
  1812. //
  1813. // Save this light
  1814. //
  1815. csave.Begin_Chunk (W3D_CHUNK_LIGHTSCAPE_LIGHT);
  1816. light->Save_W3D (csave);
  1817. //
  1818. // Save the light's transform as well
  1819. //
  1820. csave.Begin_Chunk (W3D_CHUNK_LIGHT_TRANSFORM);
  1821. Matrix3D tm = light->Get_Transform ();
  1822. W3dLightTransformStruct w3d_tm ={ tm[0][0], tm[0][1], tm[0][2], tm[0][3],
  1823. tm[1][0], tm[1][1], tm[1][2], tm[1][3],
  1824. tm[2][0], tm[2][1], tm[2][2], tm[2][3] };
  1825. csave.Write (&w3d_tm, sizeof (w3d_tm));
  1826. csave.End_Chunk ();
  1827. csave.End_Chunk ();
  1828. }
  1829. }
  1830. csave.End_Chunk ();
  1831. //
  1832. // Close the file
  1833. //
  1834. file->Close ();
  1835. }
  1836. _TheFileFactory->Return_File (file);
  1837. return ;
  1838. }
  1839. ////////////////////////////////////////////////////////////////
  1840. //
  1841. // Import_Lights
  1842. //
  1843. ////////////////////////////////////////////////////////////////
  1844. void
  1845. SceneEditorClass::Import_Lights
  1846. (
  1847. DynamicVectorClass<StringClass> & filename_list,
  1848. DynamicVectorClass<LightNodeClass *> * node_list
  1849. )
  1850. {
  1851. DynamicVectorClass<LightClass *> light_list;
  1852. ::Get_Main_View ()->Allow_Repaint (false);
  1853. //
  1854. // Build a list of light objects from the LIG files
  1855. //
  1856. for (int index = 0; index < filename_list.Count (); index ++) {
  1857. FileClass *file = _TheFileFactory->Get_File (filename_list[index]);
  1858. if (file != NULL && file->Open ()) {
  1859. //
  1860. // Read the lights from this file
  1861. //
  1862. ChunkLoadClass cload (file);
  1863. int group_id = 0;
  1864. while (cload.Open_Chunk ()) {
  1865. switch (cload.Cur_Chunk_ID ()) {
  1866. case W3D_CHUNK_LIGHTSCAPE:
  1867. Build_Light_List (cload, light_list, group_id ++);
  1868. break;
  1869. default:
  1870. ASSERT (0);
  1871. TRACE ("Unrecognized chunk id found while importing lights!\n");
  1872. break;
  1873. }
  1874. cload.Close_Chunk ();
  1875. }
  1876. file->Close ();
  1877. }
  1878. //
  1879. // Delete the file object
  1880. //
  1881. if (file != NULL) {
  1882. _TheFileFactory->Return_File (file);
  1883. }
  1884. }
  1885. //
  1886. // Make sure we don't get duplicate lights
  1887. //
  1888. Filter_Lights (light_list);
  1889. //
  1890. // Get the preset we will use to derive each imported light-node from
  1891. //
  1892. PresetClass *preset = PresetMgrClass::Find_Preset ("Lightscape Imported");
  1893. ASSERT (preset != NULL);
  1894. CString base_name = ::Asset_Name_From_Filename (filename_list[0]);
  1895. //
  1896. // Add the lights to the level
  1897. //
  1898. for (index = 0; index < light_list.Count (); index ++) {
  1899. LightClass *light = light_list[index];
  1900. if (light != NULL) {
  1901. //
  1902. // Create an editor 'node' for this light and configure it from the
  1903. // light render-object.
  1904. //
  1905. if (light->Get_Type () != LightClass::DIRECTIONAL) {
  1906. Matrix3D tm = light->Get_Transform ();
  1907. LightNodeClass *light_node = (LightNodeClass *)Create_Node (preset, &tm);
  1908. light_node->Initialize_From_Light (light);
  1909. light_node->Set_Group_ID ((int)light->Get_User_Data ());
  1910. CString light_name;
  1911. light_name.Format ("%s%04d", (LPCTSTR)base_name, index + 1);
  1912. light_node->Peek_Light_Phys ()->Set_Name (light_name);
  1913. //
  1914. // Add this light to the list the caller supplied us with (if necessary)
  1915. //
  1916. if (node_list != NULL) {
  1917. node_list->Add (light_node);
  1918. light_node->Add_Ref ();
  1919. }
  1920. }
  1921. //
  1922. // Free our hold on the light
  1923. //
  1924. MEMBER_RELEASE (light);
  1925. }
  1926. }
  1927. ::Get_Main_View ()->Allow_Repaint (true);
  1928. return ;
  1929. }
  1930. ////////////////////////////////////////////////////////////////
  1931. //
  1932. // Build_Light_List
  1933. //
  1934. ////////////////////////////////////////////////////////////////
  1935. void
  1936. SceneEditorClass::Build_Light_List
  1937. (
  1938. ChunkLoadClass & cload,
  1939. DynamicVectorClass<LightClass *> & light_list,
  1940. int group_id
  1941. )
  1942. {
  1943. while (cload.Open_Chunk ()) {
  1944. switch (cload.Cur_Chunk_ID ()) {
  1945. case W3D_CHUNK_LIGHTSCAPE_LIGHT:
  1946. {
  1947. //
  1948. // Load the light and add it to the list
  1949. //
  1950. cload.Open_Chunk ();
  1951. LightClass *light = new LightClass;
  1952. light->Load_W3D (cload);
  1953. light->Set_User_Data ((void *)group_id);
  1954. light_list.Add (light);
  1955. cload.Close_Chunk ();
  1956. //
  1957. // Read the light's transform from the file
  1958. //
  1959. cload.Open_Chunk ();
  1960. ASSERT (cload.Cur_Chunk_ID () == W3D_CHUNK_LIGHT_TRANSFORM);
  1961. if (cload.Cur_Chunk_ID () == W3D_CHUNK_LIGHT_TRANSFORM) {
  1962. //
  1963. // Read the transform
  1964. //
  1965. W3dLightTransformStruct w3d_tm = { 0 };
  1966. cload.Read (&w3d_tm, sizeof (w3d_tm));
  1967. //
  1968. // Convert the persistent-safe transform to a
  1969. // render-obj friendly transform;
  1970. //
  1971. Matrix3D tm ( w3d_tm.Transform [0][0], w3d_tm.Transform [0][1], w3d_tm.Transform [0][2], w3d_tm.Transform [0][3],
  1972. w3d_tm.Transform [1][0], w3d_tm.Transform [1][1], w3d_tm.Transform [1][2], w3d_tm.Transform [1][3],
  1973. w3d_tm.Transform [2][0], w3d_tm.Transform [2][1], w3d_tm.Transform [2][2], w3d_tm.Transform [2][3]);
  1974. light->Set_Transform (tm);
  1975. }
  1976. cload.Close_Chunk ();
  1977. }
  1978. break;
  1979. default:
  1980. ::Output_Message ("Found invalid chunk in light importer.\r\n");
  1981. break;
  1982. }
  1983. cload.Close_Chunk ();
  1984. }
  1985. return ;
  1986. }
  1987. ////////////////////////////////////////////////////////////////
  1988. //
  1989. // Filter_Lights
  1990. //
  1991. ////////////////////////////////////////////////////////////////
  1992. void
  1993. SceneEditorClass::Filter_Lights (DynamicVectorClass<LightClass *> &light_list)
  1994. {
  1995. //
  1996. // Loop over every light
  1997. //
  1998. for (int index1 = 0; index1 < light_list.Count (); index1 ++) {
  1999. LightClass *light1 = light_list[index1];
  2000. bool is_unique = true;
  2001. //
  2002. // Compare this light against every other light
  2003. //
  2004. for (int index2 = 0; index2 < light_list.Count () && is_unique; index2 ++) {
  2005. //
  2006. // Don't check against itself
  2007. //
  2008. if (index2 != index1) {
  2009. LightClass *light2 = light_list[index2];
  2010. is_unique = (Compare_Lights (light1, light2) == false);
  2011. }
  2012. }
  2013. //
  2014. // Remove this light from the list if it is not unique
  2015. //
  2016. if (is_unique == false) {
  2017. MEMBER_RELEASE (light1);
  2018. light_list.Delete (index1);
  2019. index1 --;
  2020. }
  2021. }
  2022. return ;
  2023. }
  2024. ////////////////////////////////////////////////////////////////
  2025. //
  2026. // Display_Sound_Spheres
  2027. //
  2028. ////////////////////////////////////////////////////////////////
  2029. void
  2030. SceneEditorClass::Display_Sound_Spheres (bool onoff)
  2031. {
  2032. if (m_DisplaySoundSpheres != onoff) {
  2033. m_DisplaySoundSpheres = onoff;
  2034. //
  2035. // Loop over all the sounds and tell them to turn the spheres
  2036. // on or off.
  2037. //
  2038. for ( NodeClass *node = NodeMgrClass::Get_First (NODE_TYPE_SOUND);
  2039. node != NULL;
  2040. node = NodeMgrClass::Get_Next (node, NODE_TYPE_SOUND))
  2041. {
  2042. node->Show_Attenuation_Spheres (m_DisplaySoundSpheres);
  2043. }
  2044. }
  2045. return ;
  2046. }
  2047. ////////////////////////////////////////////////////////////////
  2048. //
  2049. // Display_Light_Spheres
  2050. //
  2051. ////////////////////////////////////////////////////////////////
  2052. void
  2053. SceneEditorClass::Display_Light_Spheres (bool onoff)
  2054. {
  2055. if (m_DisplayLightSpheres != onoff) {
  2056. m_DisplayLightSpheres = onoff;
  2057. //
  2058. // Loop over all the lights and tell them to turn the spheres
  2059. // on or off.
  2060. //
  2061. for ( NodeClass *node = NodeMgrClass::Get_First (NODE_TYPE_LIGHT);
  2062. node != NULL;
  2063. node = NodeMgrClass::Get_Next (node, NODE_TYPE_LIGHT))
  2064. {
  2065. node->Show_Attenuation_Spheres (m_DisplayLightSpheres);
  2066. }
  2067. }
  2068. return ;
  2069. }
  2070. ////////////////////////////////////////////////////////////////
  2071. //
  2072. // Import_Sunlight
  2073. //
  2074. ////////////////////////////////////////////////////////////////
  2075. void
  2076. SceneEditorClass::Import_Sunlight (LPCTSTR filename)
  2077. {
  2078. DynamicVectorClass<LightClass *> light_list;
  2079. //
  2080. // Open the file
  2081. //
  2082. FileClass *file = _TheFileFactory->Get_File (filename);
  2083. if (file != NULL && file->Open ()) {
  2084. //
  2085. // Read the lights from this file
  2086. //
  2087. ChunkLoadClass cload (file);
  2088. cload.Open_Chunk ();
  2089. ASSERT (cload.Cur_Chunk_ID () == W3D_CHUNK_LIGHTSCAPE);
  2090. Build_Light_List (cload, light_list);
  2091. cload.Close_Chunk ();
  2092. file->Close ();
  2093. _TheFileFactory->Return_File (file);
  2094. }
  2095. //
  2096. // Try to find all the directional lights
  2097. //
  2098. LightClass *sunlight = NULL;
  2099. bool more_than_one = false;
  2100. for (int index = 0; index < light_list.Count () && !more_than_one; index ++) {
  2101. LightClass *light = light_list[index];
  2102. if (light != NULL) {
  2103. //
  2104. // We assume that every directional light is the 'sunlight'.
  2105. //
  2106. if (light->Get_Type () == LightClass::DIRECTIONAL) {
  2107. if (sunlight == NULL) {
  2108. sunlight = light;
  2109. } else {
  2110. //
  2111. // Check to make sure all directional lights are the same
  2112. //
  2113. if (Compare_Lights (sunlight, light) == false) {
  2114. more_than_one = true;
  2115. }
  2116. MEMBER_RELEASE (light);
  2117. }
  2118. }
  2119. }
  2120. }
  2121. bool apply_changes = (sunlight != NULL);
  2122. if (more_than_one) {
  2123. //
  2124. // Ask the user if they wish to make these changes
  2125. //
  2126. if (::MessageBox ( ::AfxGetMainWnd ()->m_hWnd,
  2127. "There are multiple sunlight definitions in this file which have different settings. Do you wish to continue?",
  2128. "Ambiguous Lights",
  2129. MB_ICONQUESTION | MB_YESNO) == IDNO)
  2130. {
  2131. apply_changes = false;
  2132. }
  2133. }
  2134. //
  2135. // Reconfigure the sunlight (if necessary)
  2136. //
  2137. if (apply_changes) {
  2138. LightClass *global_sunlight_obj = Get_Sun_Light ();
  2139. Vector3 diffuse;
  2140. sunlight->Get_Diffuse (&diffuse);
  2141. global_sunlight_obj->Set_Diffuse (diffuse);
  2142. global_sunlight_obj->Set_Intensity (sunlight->Get_Intensity ());
  2143. global_sunlight_obj->Set_Transform (sunlight->Get_Transform ());
  2144. MEMBER_RELEASE (global_sunlight_obj);
  2145. //
  2146. // Convert the sun's 3x3 roational matrix to a
  2147. // 'rotation' and 'elevation'.
  2148. //
  2149. Matrix3D tm = sunlight->Get_Transform ();
  2150. Vector3 test_vector (0, 0, -1);
  2151. test_vector = tm.Rotate_Vector (test_vector);
  2152. test_vector.Normalize ();
  2153. float rotation = ::atan2 (test_vector.Y, test_vector.X);
  2154. float elevation = ::asin (test_vector.Z);
  2155. Set_Sun_Light_Orientation (rotation, elevation);
  2156. Update_Lighting ();
  2157. }
  2158. MEMBER_RELEASE (sunlight);
  2159. return ;
  2160. }
  2161. ////////////////////////////////////////////////////////////////
  2162. //
  2163. // Compare_Lights
  2164. //
  2165. ////////////////////////////////////////////////////////////////
  2166. bool
  2167. SceneEditorClass::Compare_Lights (LightClass *light1, LightClass *light2)
  2168. {
  2169. bool retval = false;
  2170. //
  2171. // Are the positions and orientations approximately the same?
  2172. // Are they both the same type of light?
  2173. //
  2174. const Matrix3D &tm1 = light1->Get_Transform ();
  2175. const Matrix3D &tm2 = light2->Get_Transform ();
  2176. if ( tm1 == tm2 &&
  2177. light1->Get_Type () == light2->Get_Type ())
  2178. {
  2179. //
  2180. // Are their color's and intensities approx the same?
  2181. //
  2182. Vector3 ambient1;
  2183. Vector3 ambient2;
  2184. Vector3 specular1;
  2185. Vector3 specular2;
  2186. Vector3 diffuse1;
  2187. Vector3 diffuse2;
  2188. light1->Get_Ambient (&ambient1);
  2189. light2->Get_Ambient (&ambient2);
  2190. light1->Get_Specular (&specular1);
  2191. light2->Get_Specular (&specular2);
  2192. light1->Get_Diffuse (&diffuse1);
  2193. light2->Get_Diffuse (&diffuse2);
  2194. float intensity1 = light1->Get_Intensity ();
  2195. float intensity2 = light2->Get_Intensity ();
  2196. if ( ambient1 == ambient2 &&
  2197. specular1 == specular2 &&
  2198. diffuse1 == diffuse2 &&
  2199. intensity1 == intensity2)
  2200. {
  2201. //
  2202. // Are their attenuation ranges the same?
  2203. //
  2204. double inner1 = 0;
  2205. double inner2 = 0;
  2206. double outer1 = 0;
  2207. double outer2 = 0;
  2208. light1->Get_Far_Attenuation_Range (inner1, outer1);
  2209. light2->Get_Far_Attenuation_Range (inner2, outer2);
  2210. if (inner1 == inner2 && outer1 == outer2) {
  2211. retval = true;
  2212. }
  2213. }
  2214. }
  2215. return retval;
  2216. }
  2217. ////////////////////////////////////////////////////////////////
  2218. //
  2219. // Replace_Selection
  2220. //
  2221. ////////////////////////////////////////////////////////////////
  2222. void
  2223. SceneEditorClass::Replace_Selection (void)
  2224. {
  2225. //
  2226. // Is there a selection set to replace?
  2227. //
  2228. int count = m_SelectionMgr->Get_Count ();
  2229. if (count > 0) {
  2230. //
  2231. // Configure a dialog that will allow the user to select a preset
  2232. //
  2233. SelectPresetDialogClass dialog (::AfxGetMainWnd ());
  2234. dialog.Set_Title ("Object Replace");
  2235. dialog.Set_Message ("Select the new preset you want to replace the selected objects with.");
  2236. dialog.Allow_None_Selection (false);
  2237. //
  2238. // Let the user pick a preset
  2239. //
  2240. if (dialog.DoModal () == IDOK) {
  2241. PresetClass *preset = dialog.Get_Selection ();
  2242. DynamicVectorClass<NodeClass *> new_nodes;
  2243. CWaitCursor wait_cursor;
  2244. //
  2245. // Loop over all the selected nodes
  2246. //
  2247. for (int index = 0; index < count; index ++) {
  2248. //
  2249. // Get the transform of this selected node
  2250. //
  2251. NodeClass *node = m_SelectionMgr->Get_At (index);
  2252. Matrix3D tm = node->Get_Transform ();
  2253. //
  2254. // Create a new node with this same transform
  2255. //
  2256. NodeClass *new_node = Create_Node (preset, &tm, 0, true);
  2257. new_node->Set_ID (node->Get_ID ());
  2258. new_nodes.Add (new_node);
  2259. //
  2260. // Test to see if both node's are game objects of some sort.
  2261. // If they are, then we need to copy the scripts.
  2262. //
  2263. ObjectNodeClass *old_obj_node = node->As_ObjectNodeClass ();
  2264. ObjectNodeClass *new_obj_node = new_node->As_ObjectNodeClass ();
  2265. if (old_obj_node != NULL && new_obj_node != NULL) {
  2266. new_obj_node->Copy_Scripts (*old_obj_node);
  2267. }
  2268. //
  2269. // Delete the old node
  2270. //
  2271. Delete_Node (node, false);
  2272. }
  2273. //
  2274. // Clear the selection
  2275. //
  2276. m_SelectionMgr->Reset ();
  2277. //
  2278. // Add the new nodes to the selection set
  2279. //
  2280. for (index = 0; index < new_nodes.Count (); index ++) {
  2281. NodeClass *new_node = new_nodes[index];
  2282. m_SelectionMgr->Add_Node (new_node);
  2283. }
  2284. }
  2285. }
  2286. return ;
  2287. }
  2288. ////////////////////////////////////////////////////////////////
  2289. //
  2290. // Generate_Uniform_Sampled_Vis
  2291. //
  2292. ////////////////////////////////////////////////////////////////
  2293. void
  2294. SceneEditorClass::Generate_Uniform_Sampled_Vis
  2295. (
  2296. float granularity,
  2297. float sample_height,
  2298. bool ignore_bias,
  2299. bool selection_only,
  2300. bool farm_mode,
  2301. int farm_cpu_index,
  2302. int farm_cpu_total
  2303. )
  2304. {
  2305. GeneratingVisDialogClass dialog (granularity, ::AfxGetMainWnd ());
  2306. dialog.Set_Sample_Height (sample_height);
  2307. dialog.Set_Ignore_Bias (ignore_bias);
  2308. dialog.Do_Selection_Only (selection_only);
  2309. if (farm_mode) {
  2310. dialog.Set_Farm_Mode (farm_cpu_index,farm_cpu_total);
  2311. }
  2312. dialog.DoModal ();
  2313. return ;
  2314. }
  2315. ////////////////////////////////////////////////////////////////
  2316. //
  2317. // Generate_Edge_Sampled_Vis
  2318. //
  2319. ////////////////////////////////////////////////////////////////
  2320. void
  2321. SceneEditorClass::Generate_Edge_Sampled_Vis
  2322. (
  2323. float granularity,
  2324. bool ignore_bias,
  2325. bool farm_mode,
  2326. int farm_cpu_index,
  2327. int farm_cpu_total
  2328. )
  2329. {
  2330. //
  2331. // Build a list of nodes that should be vis-sampled
  2332. //
  2333. DynamicVectorClass<NodeClass *> node_list;
  2334. VisMgrClass::Build_Node_List (node_list);
  2335. //
  2336. // Determine the first and last node that this cpu is to process. In farm
  2337. // mode, the processing is split up amongst several computers...
  2338. //
  2339. int first_node = 0;
  2340. int last_node = node_list.Count();
  2341. if (farm_mode) {
  2342. int node_count = node_list.Count();
  2343. float nodes_per_processor = (float)node_count / (float)farm_cpu_total;
  2344. first_node = (int)::floor (nodes_per_processor * (float)farm_cpu_index);
  2345. last_node = (int)::ceil (nodes_per_processor * (float)(farm_cpu_index+1));
  2346. }
  2347. VisGenProgressClass progress_obj;
  2348. progress_obj.Set_Node_Count (last_node - first_node);
  2349. GeneratingEdgeSampledVisDialogClass *dialog = GeneratingEdgeSampledVisDialogClass::Display ();
  2350. dialog->Set_Progress_Obj (&progress_obj);
  2351. dialog->Enable_Farm_Mode (farm_mode);
  2352. //
  2353. // Perform the per-node vis sampling
  2354. //
  2355. VisSectorSamplerClass sampler (this, &progress_obj, granularity, MOUSE_CLICK_COLLISION_GROUP);
  2356. for ( int index = first_node;
  2357. index < last_node && !progress_obj.Is_Cancel_Requested ();
  2358. index ++)
  2359. {
  2360. NodeClass *node = node_list[index];
  2361. if (node != NULL) {
  2362. //
  2363. // Simply pass off the render object onto the sampler class
  2364. // for point generation
  2365. //
  2366. RenderObjClass *render_obj = node->Peek_Render_Obj ();
  2367. if (render_obj != NULL) {
  2368. sampler.Process (render_obj);
  2369. }
  2370. }
  2371. ::General_Pump_Messages ();
  2372. }
  2373. //
  2374. // Now render any manual vis points
  2375. //
  2376. VisMgrClass::Render_Manual_Vis_Points ();
  2377. dialog->Set_Progress_Obj (NULL);
  2378. dialog->Set_Finished (true);
  2379. return ;
  2380. }
  2381. ////////////////////////////////////////////////////////////////
  2382. //
  2383. // Generate_Light_Vis
  2384. //
  2385. ////////////////////////////////////////////////////////////////
  2386. void
  2387. SceneEditorClass::Generate_Light_Vis
  2388. (
  2389. bool farm_mode,
  2390. int farm_cpu_index,
  2391. int farm_cpu_total
  2392. )
  2393. {
  2394. GeneratingLightVisDialogClass dialog (::AfxGetMainWnd ());
  2395. if (farm_mode) {
  2396. dialog.Set_Farm_Mode (farm_cpu_index,farm_cpu_total);
  2397. }
  2398. dialog.DoModal ();
  2399. return ;
  2400. }
  2401. ////////////////////////////////////////////////////////////////
  2402. //
  2403. // Generate_Manual_Vis
  2404. //
  2405. ////////////////////////////////////////////////////////////////
  2406. void
  2407. SceneEditorClass::Generate_Manual_Vis
  2408. (
  2409. bool farm_mode,
  2410. int farm_cpu_index,
  2411. int farm_cpu_total
  2412. )
  2413. {
  2414. GeneratingManualVisDialogClass dialog (::AfxGetMainWnd ());
  2415. if (farm_mode) {
  2416. dialog.Set_Farm_Mode (farm_cpu_index, farm_cpu_total);
  2417. }
  2418. dialog.DoModal ();
  2419. return ;
  2420. }
  2421. ////////////////////////////////////////////////////////////////
  2422. //
  2423. // Display_Editor_Objects
  2424. //
  2425. ////////////////////////////////////////////////////////////////
  2426. void
  2427. SceneEditorClass::Display_Editor_Objects (bool onoff)
  2428. {
  2429. m_ShowEditorObjects = onoff;
  2430. //
  2431. // Loop over all the nodes, picking out the editor-only
  2432. // nodes to show or hide.
  2433. //
  2434. DynamicVectorClass<NodeClass *> node_list;
  2435. NodeMgrClass::Build_Full_Node_List (node_list);
  2436. for (int index = 0; index < node_list.Count (); index ++) {
  2437. NodeClass *node = node_list[index];
  2438. if (node != NULL) {
  2439. int type = node->Get_Type ();
  2440. //
  2441. // Does this node have an editor-only display object?
  2442. //
  2443. if ( type == NODE_TYPE_ZONE ||
  2444. type == NODE_TYPE_WAYPATH ||
  2445. type == NODE_TYPE_WAYPOINT ||
  2446. type == NODE_TYPE_LIGHT ||
  2447. type == NODE_TYPE_TRANSITION ||
  2448. type == NODE_TYPE_TRANSITION_CHARACTER ||
  2449. type == NODE_TYPE_SOUND ||
  2450. type == NODE_TYPE_VIS ||
  2451. type == NODE_TYPE_VIS_POINT ||
  2452. type == NODE_TYPE_PATHFIND_START ||
  2453. type == NODE_TYPE_DUMMY_OBJECT ||
  2454. type == NODE_TYPE_COVER_SPOT ||
  2455. type == NODE_TYPE_COVER_ATTACK_POINT ||
  2456. type == NODE_TYPE_DAMAGE_ZONE ||
  2457. type == NODE_TYPE_BUILDING ||
  2458. type == NODE_TYPE_EDITOR_ONLY_OBJ)
  2459. {
  2460. node->Hide (!onoff);
  2461. }
  2462. }
  2463. }
  2464. return ;
  2465. }
  2466. ////////////////////////////////////////////////////////////////
  2467. //
  2468. // Display_Static_Anim_Phys
  2469. //
  2470. ////////////////////////////////////////////////////////////////
  2471. void
  2472. SceneEditorClass::Display_Static_Anim_Phys (bool onoff)
  2473. {
  2474. m_ShowStaticAnimPhys = onoff;
  2475. //
  2476. // Get the list of all static objects from the physics scene
  2477. //
  2478. RefPhysListIterator iterator = ::Get_Scene_Editor ()->Get_Static_Object_Iterator ();
  2479. for (iterator.First (); !iterator.Is_Done (); iterator.Next ()) {
  2480. //
  2481. // Is this object a static anim phys?
  2482. //
  2483. PhysClass *phys_obj = iterator.Peek_Obj ();
  2484. StaticAnimPhysClass *static_phys_obj = phys_obj->As_StaticAnimPhysClass ();
  2485. if (static_phys_obj != NULL && static_phys_obj->Peek_Model () != NULL) {
  2486. //
  2487. // Hide the static anim phys object and turn off its collision
  2488. //
  2489. static_phys_obj->Peek_Model ()->Set_Hidden (!onoff);
  2490. if (onoff == false) {
  2491. phys_obj->Inc_Ignore_Counter ();
  2492. } else if (phys_obj->Is_Ignore_Me ()) {
  2493. phys_obj->Dec_Ignore_Counter ();
  2494. }
  2495. }
  2496. }
  2497. /*for ( NodeClass *node = NodeMgrClass::Get_First ();
  2498. node != NULL;
  2499. node = NodeMgrClass::Get_Next (node))
  2500. {
  2501. PhysClass *phys_obj = node->Peek_Physics_Obj ();
  2502. if (phys_obj != NULL && phys_obj->As_StaticAnimPhysClass () != NULL) {
  2503. node->Hide (!onoff);
  2504. }
  2505. }*/
  2506. return ;
  2507. }
  2508. ////////////////////////////////////////////////////////////////
  2509. //
  2510. // Enable_Building_Power
  2511. //
  2512. ////////////////////////////////////////////////////////////////
  2513. void
  2514. SceneEditorClass::Enable_Building_Power (bool onoff)
  2515. {
  2516. //
  2517. // Make sure the buildings are in a good state
  2518. //
  2519. GameObjManager::Update_Building_Collection_Spheres ();
  2520. GameObjManager::Init_Buildings ();
  2521. //
  2522. // Loop over all the lights and tell them to turn the spheres
  2523. // on or off.
  2524. //
  2525. for ( NodeClass *node = NodeMgrClass::Get_First (NODE_TYPE_BUILDING);
  2526. node != NULL;
  2527. node = NodeMgrClass::Get_Next (node, NODE_TYPE_BUILDING))
  2528. {
  2529. ((BuildingNodeClass *)node)->Enable_Power (onoff);
  2530. ((BuildingNodeClass *)node)->Set_Normalized_Health (onoff * 1.0F);
  2531. }
  2532. m_BuildingPowerEnabled = onoff;
  2533. return ;
  2534. }
  2535. ////////////////////////////////////////////////////////////////
  2536. //
  2537. // Reset_Dynamic_Object_Visibility_Status
  2538. //
  2539. ////////////////////////////////////////////////////////////////
  2540. void
  2541. SceneEditorClass::Reset_Dynamic_Object_Visibility_Status (void)
  2542. {
  2543. //
  2544. // Get the list of all dynamic objects from the physics scene
  2545. //
  2546. RefPhysListIterator iterator = ::Get_Scene_Editor ()->Get_Dynamic_Object_Iterator ();
  2547. for (iterator.First (); !iterator.Is_Done (); iterator.Next ()) {
  2548. //
  2549. // Make sure this phys obj is a dynamic object
  2550. //
  2551. PhysClass *phys_obj = iterator.Peek_Obj ();
  2552. DynamicPhysClass *dyn_phys_obj = phys_obj->As_DynamicPhysClass ();
  2553. if (dyn_phys_obj != NULL) {
  2554. //
  2555. // Reset this dynamic object's visibility
  2556. //
  2557. dyn_phys_obj->Update_Visibility_Status ();
  2558. }
  2559. }
  2560. return ;
  2561. }
  2562. ////////////////////////////////////////////////////////////////
  2563. //
  2564. // Reset_Vis_For_Node
  2565. //
  2566. ////////////////////////////////////////////////////////////////
  2567. void
  2568. SceneEditorClass::Reset_Vis_For_Node (NodeClass *node)
  2569. {
  2570. if (node == NULL || node->Is_Static () == false) {
  2571. return ;
  2572. }
  2573. //
  2574. // Make sure this is a static phys object
  2575. //
  2576. PhysClass *phys = node->Peek_Physics_Obj ();
  2577. if (phys != NULL && phys->As_StaticPhysClass () != NULL) {
  2578. StaticPhysClass *static_phys = phys->As_StaticPhysClass ();
  2579. //
  2580. // Get this sector's id
  2581. //
  2582. int vis_id = static_phys->Get_Vis_Sector_ID ();
  2583. if (vis_id > 0) {
  2584. //
  2585. // Get the vis table for this sector
  2586. //
  2587. VisTableClass *vis_table = VisTableManager.Get_Vis_Table(vis_id, false);
  2588. if (vis_table != NULL) {
  2589. //
  2590. // Reset the visibility data for this sector
  2591. //
  2592. vis_table->Reset_All ();
  2593. VisTableManager.Update_Vis_Table(vis_id,vis_table);
  2594. REF_PTR_RELEASE(vis_table);
  2595. }
  2596. }
  2597. }
  2598. return ;
  2599. }
  2600. ////////////////////////////////////////////////////////////////
  2601. //
  2602. // Update_Lighting
  2603. //
  2604. ////////////////////////////////////////////////////////////////
  2605. void
  2606. SceneEditorClass::Update_Lighting (void)
  2607. {
  2608. Vector3 lev_min;
  2609. Vector3 lev_max;
  2610. Vector3 sundirection;
  2611. Get_Level_Extents (lev_min, lev_max);
  2612. AABoxClass box;
  2613. box.Center = lev_min + ((lev_max - lev_min) * 0.5F);
  2614. box.Extent = ((lev_max - lev_min) * 0.5F);
  2615. Invalidate_Lighting_Caches (box);
  2616. return ;
  2617. }
  2618. ////////////////////////////////////////////////////////////////
  2619. //
  2620. // Set_Sun_Light_Orientation
  2621. //
  2622. ////////////////////////////////////////////////////////////////
  2623. void
  2624. SceneEditorClass::Set_Sun_Light_Orientation (float yaw, float pitch)
  2625. {
  2626. PhysicsSceneClass::Set_Sun_Light_Orientation (yaw, pitch);
  2627. }
  2628. ////////////////////////////////////////////////////////////////
  2629. //
  2630. // Show_Vis_Window
  2631. //
  2632. ////////////////////////////////////////////////////////////////
  2633. void
  2634. SceneEditorClass::Show_Vis_Window (bool onoff)
  2635. {
  2636. if (m_VisWindow.m_hWnd == NULL) {
  2637. m_VisWindow.Create ();
  2638. }
  2639. m_VisWindow.ShowWindow (onoff ? SW_SHOW : SW_HIDE);
  2640. return ;
  2641. }
  2642. ////////////////////////////////////////////////////////////////
  2643. //
  2644. // Is_Vis_Window_Visible
  2645. //
  2646. ////////////////////////////////////////////////////////////////
  2647. bool
  2648. SceneEditorClass::Is_Vis_Window_Visible (void)
  2649. {
  2650. bool retval = true;
  2651. if ( m_VisWindow.m_hWnd == NULL ||
  2652. m_VisWindow.IsWindowVisible () == false)
  2653. {
  2654. retval = false;
  2655. }
  2656. return retval;
  2657. }
  2658. ////////////////////////////////////////////////////////////////
  2659. //
  2660. // On_Vis_Occluders_Rendered
  2661. //
  2662. ////////////////////////////////////////////////////////////////
  2663. void
  2664. SceneEditorClass::On_Vis_Occluders_Rendered
  2665. (
  2666. VisRenderContextClass & context,
  2667. VisSampleClass & sample
  2668. )
  2669. {
  2670. m_VisWindow.Update_Display (*context.VisRasterizer);
  2671. return ;
  2672. }