part_ldr.cpp 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888
  1. /*
  2. ** Command & Conquer Generals Zero Hour(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : WW3D *
  23. * *
  24. * $Archive:: /VSS_Sync/ww3d2/part_ldr.cpp $*
  25. * *
  26. * Author:: Patrick Smith
  27. * *
  28. * $Modtime:: 10/26/01 2:57p $*
  29. * *
  30. * $Revision:: 11 $*
  31. * *
  32. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  33. #include "part_ldr.h"
  34. #include "part_emt.h"
  35. #include "w3derr.h"
  36. #include "chunkio.h"
  37. #include "win.h" // for lstrcpy, can this be improved?
  38. #include "assetmgr.h"
  39. #include "texture.h"
  40. #ifndef SAFE_DELETE
  41. #define SAFE_DELETE(pointer) \
  42. { \
  43. if (pointer) { \
  44. delete pointer; \
  45. pointer = 0; \
  46. } \
  47. }
  48. #endif //SAFE_DELETE
  49. #ifndef SAFE_DELETE_ARRAY
  50. #define SAFE_DELETE_ARRAY(pointer) \
  51. if (pointer) { \
  52. delete [] pointer; \
  53. pointer = 0; \
  54. } \
  55. #endif //SAFE_DELETE
  56. ///////////////////////////////////////////////////////////////////////////////////
  57. //
  58. // Global variable initialization
  59. //
  60. ParticleEmitterLoaderClass _ParticleEmitterLoader;
  61. // This array is declared in "W3D_File.H"
  62. const char *EMITTER_TYPE_NAMES[EMITTER_TYPEID_COUNT] =
  63. {
  64. "Default"
  65. };
  66. ///////////////////////////////////////////////////////////////////////////////////
  67. //
  68. // ParticleEmitterDefClass
  69. //
  70. ParticleEmitterDefClass::ParticleEmitterDefClass (void)
  71. : m_pName (NULL),
  72. m_Version (0L),
  73. m_pUserString (NULL),
  74. m_iUserType (EMITTER_TYPEID_DEFAULT),
  75. m_InitialOrientationRandom (0),
  76. m_pCreationVolume (NULL),
  77. m_pVelocityRandomizer (NULL)
  78. {
  79. ::memset (&m_Info, 0, sizeof (m_Info));
  80. ::memset (&m_InfoV2, 0, sizeof (m_InfoV2));
  81. ::memset (&m_ExtraInfo, 0, sizeof (m_ExtraInfo));
  82. ::memset (&m_ColorKeyframes, 0, sizeof (m_ColorKeyframes));
  83. ::memset (&m_OpacityKeyframes, 0, sizeof (m_OpacityKeyframes));
  84. ::memset (&m_SizeKeyframes, 0, sizeof (m_SizeKeyframes));
  85. ::memset (&m_RotationKeyframes, 0, sizeof (m_RotationKeyframes));
  86. ::memset (&m_FrameKeyframes, 0, sizeof (m_FrameKeyframes));
  87. ::memset (&m_BlurTimeKeyframes, 0, sizeof (m_BlurTimeKeyframes));
  88. ::memset (&m_LineProperties, 0, sizeof (m_LineProperties));
  89. return ;
  90. }
  91. ///////////////////////////////////////////////////////////////////////////////////
  92. //
  93. // ParticleEmitterDefClass
  94. //
  95. ParticleEmitterDefClass::ParticleEmitterDefClass (const ParticleEmitterDefClass &src)
  96. : m_pName (NULL),
  97. m_Version (0L),
  98. m_pUserString (NULL),
  99. m_iUserType (EMITTER_TYPEID_DEFAULT),
  100. m_InitialOrientationRandom (src.m_InitialOrientationRandom),
  101. m_pCreationVolume (NULL),
  102. m_pVelocityRandomizer (NULL)
  103. {
  104. ::memset (&m_Info, 0, sizeof (m_Info));
  105. ::memset (&m_InfoV2, 0, sizeof (m_InfoV2));
  106. ::memset (&m_ExtraInfo, 0, sizeof (m_ExtraInfo));
  107. ::memset (&m_ColorKeyframes, 0, sizeof (m_ColorKeyframes));
  108. ::memset (&m_OpacityKeyframes, 0, sizeof (m_OpacityKeyframes));
  109. ::memset (&m_SizeKeyframes, 0, sizeof (m_SizeKeyframes));
  110. ::memset (&m_RotationKeyframes, 0, sizeof (m_RotationKeyframes));
  111. ::memset (&m_FrameKeyframes, 0, sizeof (m_FrameKeyframes));
  112. ::memset (&m_BlurTimeKeyframes, 0, sizeof (m_BlurTimeKeyframes));
  113. ::memset (&m_LineProperties, 0, sizeof (m_LineProperties));
  114. (*this) = src;
  115. return ;
  116. }
  117. ///////////////////////////////////////////////////////////////////////////////////
  118. //
  119. // ~ParticleEmitterDefClass
  120. //
  121. ParticleEmitterDefClass::~ParticleEmitterDefClass (void)
  122. {
  123. // Free the name buffer if necessary
  124. if (m_pName != NULL) {
  125. // free() is used because the buffer was allocated with ::_strdup().
  126. ::free (m_pName);
  127. m_pName = NULL;
  128. }
  129. // Free the user-string buffer if necessary
  130. if (m_pUserString != NULL) {
  131. // free() is used because the buffer was allocated with ::malloc() or ::_strdup().
  132. ::free (m_pUserString);
  133. m_pUserString = NULL;
  134. }
  135. Free_Props ();
  136. SAFE_DELETE (m_pCreationVolume);
  137. SAFE_DELETE (m_pVelocityRandomizer);
  138. return ;
  139. }
  140. ///////////////////////////////////////////////////////////////////////////////////
  141. //
  142. // ParticleEmitterDefClass
  143. //
  144. const ParticleEmitterDefClass &
  145. ParticleEmitterDefClass::operator= (const ParticleEmitterDefClass &src)
  146. {
  147. //
  148. // Copy the user structures
  149. //
  150. Set_Name (src.Get_Name ());
  151. Set_User_String (src.Get_User_String ());
  152. Set_User_Type (src.Get_User_Type ());
  153. m_Version = src.m_Version;
  154. //
  155. // Copy the information structures
  156. //
  157. ::memcpy (&m_Info, &src.m_Info, sizeof (m_Info));
  158. ::memcpy (&m_InfoV2, &src.m_InfoV2, sizeof (m_InfoV2));
  159. ::memcpy (&m_ExtraInfo, &src.m_ExtraInfo, sizeof (m_ExtraInfo));
  160. ::memcpy (&m_LineProperties, &src.m_LineProperties, sizeof(m_LineProperties));
  161. //
  162. // Copy the keyframes
  163. //
  164. Free_Props ();
  165. ::Copy_Emitter_Property_Struct (m_ColorKeyframes, src.m_ColorKeyframes);
  166. ::Copy_Emitter_Property_Struct (m_OpacityKeyframes, src.m_OpacityKeyframes);
  167. ::Copy_Emitter_Property_Struct (m_SizeKeyframes, src.m_SizeKeyframes);
  168. ::Copy_Emitter_Property_Struct (m_RotationKeyframes, src.m_RotationKeyframes);
  169. ::Copy_Emitter_Property_Struct (m_FrameKeyframes, src.m_FrameKeyframes);
  170. ::Copy_Emitter_Property_Struct (m_BlurTimeKeyframes, src.m_BlurTimeKeyframes);
  171. m_InitialOrientationRandom = src.m_InitialOrientationRandom;
  172. //
  173. // Create the randomizers
  174. //
  175. SAFE_DELETE (m_pCreationVolume);
  176. SAFE_DELETE (m_pVelocityRandomizer);
  177. m_pCreationVolume = Create_Randomizer (m_InfoV2.CreationVolume);
  178. m_pVelocityRandomizer = Create_Randomizer (m_InfoV2.VelRandom);
  179. return (*this);
  180. }
  181. ///////////////////////////////////////////////////////////////////////////////////
  182. //
  183. // Free_Props
  184. //
  185. void
  186. ParticleEmitterDefClass::Free_Props (void)
  187. {
  188. m_ColorKeyframes.NumKeyFrames = 0;
  189. m_OpacityKeyframes.NumKeyFrames = 0;
  190. m_SizeKeyframes.NumKeyFrames = 0;
  191. m_RotationKeyframes.NumKeyFrames = 0;
  192. m_FrameKeyframes.NumKeyFrames = 0;
  193. m_BlurTimeKeyframes.NumKeyFrames = 0;
  194. SAFE_DELETE_ARRAY (m_ColorKeyframes.KeyTimes);
  195. SAFE_DELETE_ARRAY (m_ColorKeyframes.Values);
  196. SAFE_DELETE_ARRAY (m_OpacityKeyframes.KeyTimes);
  197. SAFE_DELETE_ARRAY (m_OpacityKeyframes.Values);
  198. SAFE_DELETE_ARRAY (m_SizeKeyframes.KeyTimes);
  199. SAFE_DELETE_ARRAY (m_SizeKeyframes.Values);
  200. SAFE_DELETE_ARRAY (m_RotationKeyframes.KeyTimes);
  201. SAFE_DELETE_ARRAY (m_RotationKeyframes.Values);
  202. SAFE_DELETE_ARRAY (m_FrameKeyframes.KeyTimes);
  203. SAFE_DELETE_ARRAY (m_FrameKeyframes.Values);
  204. SAFE_DELETE_ARRAY (m_BlurTimeKeyframes.KeyTimes);
  205. SAFE_DELETE_ARRAY (m_BlurTimeKeyframes.Values);
  206. return ;
  207. }
  208. ///////////////////////////////////////////////////////////////////////////////////
  209. //
  210. // Set_Velocity_Random
  211. //
  212. void
  213. ParticleEmitterDefClass::Set_Velocity_Random (Vector3Randomizer *randomizer)
  214. {
  215. SAFE_DELETE (m_pVelocityRandomizer);
  216. m_pVelocityRandomizer = randomizer;
  217. //
  218. // Ensure our persistent structure is up-to-date so it will save correctly
  219. //
  220. if (m_pVelocityRandomizer != NULL) {
  221. Initialize_Randomizer_Struct (*m_pVelocityRandomizer, m_InfoV2.VelRandom);
  222. }
  223. return ;
  224. }
  225. ///////////////////////////////////////////////////////////////////////////////////
  226. //
  227. // Set_Creation_Volume
  228. //
  229. void
  230. ParticleEmitterDefClass::Set_Creation_Volume (Vector3Randomizer *randomizer)
  231. {
  232. SAFE_DELETE (m_pCreationVolume);
  233. m_pCreationVolume = randomizer;
  234. //
  235. // Ensure our persistent structure is up-to-date so it will save correctly
  236. //
  237. if (m_pCreationVolume != NULL) {
  238. Initialize_Randomizer_Struct (*m_pCreationVolume, m_InfoV2.CreationVolume);
  239. }
  240. return ;
  241. }
  242. ///////////////////////////////////////////////////////////////////////////////////
  243. //
  244. // Set_User_String
  245. //
  246. void
  247. ParticleEmitterDefClass::Set_User_String (const char *pstring)
  248. {
  249. SAFE_FREE (m_pUserString);
  250. m_pUserString = ::_strdup (pstring);
  251. return ;
  252. }
  253. ///////////////////////////////////////////////////////////////////////////////////
  254. //
  255. // Set_Name
  256. //
  257. void
  258. ParticleEmitterDefClass::Set_Name (const char *pname)
  259. {
  260. SAFE_FREE (m_pName);
  261. m_pName = ::_strdup (pname);
  262. return ;
  263. }
  264. ///////////////////////////////////////////////////////////////////////////////////
  265. //
  266. // Set_Texture_Filename
  267. //
  268. void
  269. ParticleEmitterDefClass::Set_Texture_Filename (const char *pname)
  270. {
  271. ::lstrcpy (m_Info.TextureFilename, pname);
  272. Normalize_Filename ();
  273. return ;
  274. }
  275. ///////////////////////////////////////////////////////////////////////////////////
  276. //
  277. // Normalize_Filename
  278. //
  279. void
  280. ParticleEmitterDefClass::Normalize_Filename (void)
  281. {
  282. TCHAR path[MAX_PATH];
  283. ::lstrcpy (path, m_Info.TextureFilename);
  284. // Find the last occurance of the directory deliminator
  285. LPCTSTR filename = ::strrchr (path, '\\');
  286. if (filename != NULL) {
  287. // Increment past the directory deliminator
  288. filename ++;
  289. // Now copy the filename protion of the path to the structure
  290. ::lstrcpy (m_Info.TextureFilename, filename);
  291. }
  292. return ;
  293. }
  294. ///////////////////////////////////////////////////////////////////////////////////
  295. //
  296. // Load
  297. //
  298. WW3DErrorType
  299. ParticleEmitterDefClass::Load_W3D (ChunkLoadClass &chunk_load)
  300. {
  301. // Assume error
  302. WW3DErrorType ret_val = WW3D_ERROR_LOAD_FAILED;
  303. Initialize_To_Ver2 ();
  304. // Attempt to read the different sections of the emitter definition
  305. if ((Read_Header (chunk_load) == WW3D_ERROR_OK) &&
  306. (Read_User_Data (chunk_load) == WW3D_ERROR_OK) &&
  307. (Read_Info (chunk_load) == WW3D_ERROR_OK)) {
  308. if (m_Version > 0x00010000) {
  309. //
  310. // Read the version 2.0 structures from the chunk
  311. //
  312. if ((Read_InfoV2 (chunk_load) == WW3D_ERROR_OK) &&
  313. (Read_Props (chunk_load) == WW3D_ERROR_OK)) {
  314. // Success!
  315. ret_val = WW3D_ERROR_OK;
  316. }
  317. } else {
  318. // Make sure the data fits version 2
  319. Convert_To_Ver2 ();
  320. ret_val = WW3D_ERROR_OK;
  321. }
  322. }
  323. // (gth) Handle all future additions to the particle emitter file format
  324. // in the typical chunk fashion.
  325. while (chunk_load.Open_Chunk() && ret_val == WW3D_ERROR_OK) {
  326. switch (chunk_load.Cur_Chunk_ID())
  327. {
  328. case W3D_CHUNK_EMITTER_LINE_PROPERTIES:
  329. ret_val = Read_Line_Properties(chunk_load);
  330. break;
  331. case W3D_CHUNK_EMITTER_ROTATION_KEYFRAMES:
  332. ret_val = Read_Rotation_Keyframes(chunk_load);
  333. break;
  334. case W3D_CHUNK_EMITTER_FRAME_KEYFRAMES:
  335. ret_val = Read_Frame_Keyframes(chunk_load);
  336. break;
  337. case W3D_CHUNK_EMITTER_BLUR_TIME_KEYFRAMES:
  338. ret_val = Read_Blur_Time_Keyframes(chunk_load);
  339. break;
  340. case W3D_CHUNK_EMITTER_EXTRA_INFO:
  341. ret_val = Read_Extra_Info(chunk_load);
  342. break;
  343. default:
  344. WWDEBUG_SAY(("Unhandled Chunk! File: %s Line: %d\r\n",__FILE__,__LINE__));
  345. break;
  346. }
  347. chunk_load.Close_Chunk();
  348. }
  349. // Return the WW3DErrorType return code
  350. return ret_val;
  351. }
  352. ///////////////////////////////////////////////////////////////////////////////////
  353. //
  354. // Initialize_To_Ver2
  355. //
  356. void
  357. ParticleEmitterDefClass::Initialize_To_Ver2 (void)
  358. {
  359. ::memset (&m_Info, 0, sizeof (m_Info));
  360. ::memset (&m_InfoV2, 0, sizeof (m_InfoV2));
  361. ::memset (&m_ExtraInfo, 0, sizeof (m_ExtraInfo));
  362. //
  363. // Set the version 2 values using defaults from version 1
  364. //
  365. m_InfoV2.BurstSize = 1;
  366. m_InfoV2.OutwardVel = 0;
  367. m_InfoV2.VelInherit = 0;
  368. W3dUtilityClass::Convert_Shader (ShaderClass::_PresetAdditiveSpriteShader, &m_InfoV2.Shader);
  369. m_InfoV2.CreationVolume.ClassID = Vector3Randomizer::CLASSID_SOLIDBOX;
  370. m_InfoV2.CreationVolume.Value1 = 0;
  371. m_InfoV2.CreationVolume.Value2 = 0;
  372. m_InfoV2.CreationVolume.Value3 = 0;
  373. m_InfoV2.VelRandom.ClassID = Vector3Randomizer::CLASSID_SOLIDBOX;
  374. m_InfoV2.VelRandom.Value1 = 0;
  375. m_InfoV2.VelRandom.Value2 = 0;
  376. m_InfoV2.VelRandom.Value3 = 0;
  377. Free_Props ();
  378. return ;
  379. }
  380. ///////////////////////////////////////////////////////////////////////////////////
  381. //
  382. // Convert_To_Ver2
  383. //
  384. void
  385. ParticleEmitterDefClass::Convert_To_Ver2 (void)
  386. {
  387. if (m_Version < 0x00020000) {
  388. m_InfoV2.BurstSize = 1;
  389. m_InfoV2.OutwardVel = 0;
  390. m_InfoV2.VelInherit = 0;
  391. //
  392. // Determine which shader to use...
  393. //
  394. ShaderClass shader = ShaderClass::_PresetAdditiveSpriteShader;
  395. TextureClass *ptexture = WW3DAssetManager::Get_Instance ()->Get_Texture (m_Info.TextureFilename);
  396. if (ptexture != NULL) {
  397. // If texture has an alpha channel do alpha blending instead of additive
  398. // (which is the default for point groups):
  399. // SurfaceClass::SurfaceDescription surf_desc;
  400. // ::ZeroMemory(&surf_desc, sizeof(SurfaceClass::SurfaceDescription));
  401. // ptexture->Get_Level_Description(surf_desc);
  402. // if (Has_Alpha(surf_desc.Format)) {
  403. if (Has_Alpha(ptexture->Get_Texture_Format())) {
  404. shader = ShaderClass::_PresetAlphaSpriteShader;
  405. }
  406. ptexture->Release_Ref();
  407. }
  408. W3dUtilityClass::Convert_Shader (shader, &m_InfoV2.Shader);
  409. //
  410. // Convert the randomziers
  411. //
  412. m_InfoV2.CreationVolume.ClassID = Vector3Randomizer::CLASSID_SOLIDBOX;
  413. m_InfoV2.CreationVolume.Value1 = m_Info.PositionRandom / 1000.0f;
  414. m_InfoV2.CreationVolume.Value2 = m_Info.PositionRandom / 1000.0f;
  415. m_InfoV2.CreationVolume.Value3 = m_Info.PositionRandom / 1000.0f;
  416. m_InfoV2.VelRandom.ClassID = Vector3Randomizer::CLASSID_SOLIDBOX;
  417. m_InfoV2.VelRandom.Value1 = m_Info.VelocityRandom;
  418. m_InfoV2.VelRandom.Value2 = m_Info.VelocityRandom;
  419. m_InfoV2.VelRandom.Value3 = m_Info.VelocityRandom;
  420. //
  421. // Recreate the randomizers
  422. //
  423. SAFE_DELETE (m_pCreationVolume);
  424. SAFE_DELETE (m_pVelocityRandomizer);
  425. m_pCreationVolume = Create_Randomizer (m_InfoV2.CreationVolume);
  426. m_pVelocityRandomizer = Create_Randomizer (m_InfoV2.VelRandom);
  427. //
  428. // Convert the colors, opacities, and sizes
  429. //
  430. Free_Props ();
  431. m_ColorKeyframes.Start = RGBA_TO_VECTOR3 (m_Info.StartColor);
  432. m_ColorKeyframes.Rand = Vector3 (0, 0, 0);
  433. m_ColorKeyframes.NumKeyFrames = 1;
  434. m_ColorKeyframes.KeyTimes = W3DNEW float(m_Info.FadeTime);
  435. m_ColorKeyframes.Values = W3DNEW Vector3(RGBA_TO_VECTOR3 (m_Info.EndColor));
  436. m_OpacityKeyframes.Start = ((float)(m_Info.StartColor.A)) / 255;
  437. m_OpacityKeyframes.Rand = 0;
  438. m_OpacityKeyframes.NumKeyFrames = 1;
  439. m_OpacityKeyframes.KeyTimes = W3DNEW float(m_Info.FadeTime);
  440. m_OpacityKeyframes.Values = W3DNEW float(((float)(m_Info.EndColor.A)) / 255);
  441. m_SizeKeyframes.Start = m_Info.StartSize;
  442. m_SizeKeyframes.Rand = 0;
  443. m_SizeKeyframes.NumKeyFrames = 0;
  444. }
  445. return ;
  446. }
  447. ///////////////////////////////////////////////////////////////////////////////////
  448. //
  449. // Read_Header
  450. //
  451. WW3DErrorType
  452. ParticleEmitterDefClass::Read_Header (ChunkLoadClass &chunk_load)
  453. {
  454. // Assume error
  455. WW3DErrorType ret_val = WW3D_ERROR_LOAD_FAILED;
  456. // Is this the header chunk?
  457. if (chunk_load.Open_Chunk () &&
  458. (chunk_load.Cur_Chunk_ID () == W3D_CHUNK_EMITTER_HEADER)) {
  459. W3dEmitterHeaderStruct header = { 0 };
  460. if (chunk_load.Read (&header, sizeof (header)) == sizeof (header)) {
  461. // Copy the name from the header structure
  462. m_pName = ::_strdup (header.Name);
  463. m_Version = header.Version;
  464. // Success!
  465. ret_val = WW3D_ERROR_OK;
  466. }
  467. // Close the chunk, so the next read will be successful.
  468. chunk_load.Close_Chunk ();
  469. }
  470. // Return the WW3DErrorType return code
  471. return ret_val;
  472. }
  473. ///////////////////////////////////////////////////////////////////////////////////
  474. //
  475. // Read_User_Data
  476. //
  477. WW3DErrorType
  478. ParticleEmitterDefClass::Read_User_Data (ChunkLoadClass &chunk_load)
  479. {
  480. // Assume error
  481. WW3DErrorType ret_val = WW3D_ERROR_LOAD_FAILED;
  482. // Is this the user chunk?
  483. if (chunk_load.Open_Chunk () &&
  484. (chunk_load.Cur_Chunk_ID () == W3D_CHUNK_EMITTER_USER_DATA)) {
  485. W3dEmitterUserInfoStruct user_info = { 0 };
  486. if (chunk_load.Read (&user_info, sizeof (user_info)) == sizeof (user_info)) {
  487. // Assume success from here on out
  488. ret_val = WW3D_ERROR_OK;
  489. // Record the user information into our member data
  490. m_iUserType = user_info.Type;
  491. // Should we read the user string from the file?
  492. if (user_info.SizeofStringParam > 0) {
  493. m_pUserString = (char *)::malloc (sizeof (char) * (user_info.SizeofStringParam+1));
  494. m_pUserString[0] = 0;
  495. // Attempt to read the user-string from the chunk
  496. if (chunk_load.Read (m_pUserString, user_info.SizeofStringParam) != user_info.SizeofStringParam) {
  497. ret_val = WW3D_ERROR_LOAD_FAILED;
  498. }
  499. }
  500. }
  501. // Close the chunk, so the next read will be successful.
  502. chunk_load.Close_Chunk ();
  503. }
  504. // Return the WW3DErrorType return code
  505. return ret_val;
  506. }
  507. ///////////////////////////////////////////////////////////////////////////////////
  508. //
  509. // Read_Info
  510. //
  511. WW3DErrorType
  512. ParticleEmitterDefClass::Read_Info (ChunkLoadClass &chunk_load)
  513. {
  514. // Assume error
  515. WW3DErrorType ret_val = WW3D_ERROR_LOAD_FAILED;
  516. // Is this the user chunk?
  517. if (chunk_load.Open_Chunk () &&
  518. (chunk_load.Cur_Chunk_ID () == W3D_CHUNK_EMITTER_INFO)) {
  519. // Read the chunk straight into our member structure
  520. ::memset (&m_Info, 0, sizeof (m_Info));
  521. if (chunk_load.Read (&m_Info, sizeof (m_Info)) == sizeof (m_Info)) {
  522. // Success!
  523. ret_val = WW3D_ERROR_OK;
  524. }
  525. // Close the chunk, so the next read will be successful.
  526. chunk_load.Close_Chunk ();
  527. }
  528. // Return the WW3DErrorType return code
  529. return ret_val;
  530. }
  531. ///////////////////////////////////////////////////////////////////////////////////
  532. //
  533. // Create_Randomizer
  534. //
  535. Vector3Randomizer *
  536. ParticleEmitterDefClass::Create_Randomizer (W3dVolumeRandomizerStruct &info)
  537. {
  538. Vector3Randomizer *randomizer = NULL;
  539. switch (info.ClassID)
  540. {
  541. case Vector3Randomizer::CLASSID_SOLIDBOX:
  542. randomizer = W3DNEW Vector3SolidBoxRandomizer (Vector3 (info.Value1, info.Value2, info.Value3));
  543. break;
  544. case Vector3Randomizer::CLASSID_SOLIDSPHERE:
  545. randomizer = W3DNEW Vector3SolidSphereRandomizer (info.Value1);
  546. break;
  547. case Vector3Randomizer::CLASSID_HOLLOWSPHERE:
  548. randomizer = W3DNEW Vector3HollowSphereRandomizer (info.Value1);
  549. break;
  550. case Vector3Randomizer::CLASSID_SOLIDCYLINDER:
  551. randomizer = W3DNEW Vector3SolidCylinderRandomizer (info.Value1, info.Value2);
  552. break;
  553. }
  554. return randomizer;
  555. }
  556. ///////////////////////////////////////////////////////////////////////////////////
  557. //
  558. // Initialize_Randomizer_Struct
  559. //
  560. void
  561. ParticleEmitterDefClass::Initialize_Randomizer_Struct
  562. (
  563. const Vector3Randomizer & randomizer,
  564. W3dVolumeRandomizerStruct & info
  565. )
  566. {
  567. info.ClassID = randomizer.Class_ID ();
  568. switch (randomizer.Class_ID ())
  569. {
  570. case Vector3Randomizer::CLASSID_SOLIDBOX:
  571. {
  572. Vector3 extents = ((Vector3SolidBoxRandomizer &)randomizer).Get_Extents ();
  573. info.Value1 = extents.X;
  574. info.Value2 = extents.Y;
  575. info.Value3 = extents.Z;
  576. }
  577. break;
  578. case Vector3Randomizer::CLASSID_SOLIDSPHERE:
  579. info.Value1 = ((Vector3SolidSphereRandomizer &)randomizer).Get_Radius ();
  580. break;
  581. case Vector3Randomizer::CLASSID_HOLLOWSPHERE:
  582. info.Value1 = ((Vector3HollowSphereRandomizer &)randomizer).Get_Radius ();
  583. break;
  584. case Vector3Randomizer::CLASSID_SOLIDCYLINDER:
  585. info.Value1 = ((Vector3SolidCylinderRandomizer &)randomizer).Get_Height ();
  586. info.Value2 = ((Vector3SolidCylinderRandomizer &)randomizer).Get_Radius ();
  587. break;
  588. }
  589. return ;
  590. }
  591. ///////////////////////////////////////////////////////////////////////////////////
  592. //
  593. // Read_InfoV2
  594. //
  595. WW3DErrorType
  596. ParticleEmitterDefClass::Read_InfoV2 (ChunkLoadClass &chunk_load)
  597. {
  598. // Assume error
  599. WW3DErrorType ret_val = WW3D_ERROR_LOAD_FAILED;
  600. // Is this the user chunk?
  601. if (chunk_load.Open_Chunk () &&
  602. (chunk_load.Cur_Chunk_ID () == W3D_CHUNK_EMITTER_INFOV2)) {
  603. // Read the chunk straight into our member structure
  604. ::memset (&m_InfoV2, 0, sizeof (m_InfoV2));
  605. if (chunk_load.Read (&m_InfoV2, sizeof (m_InfoV2)) == sizeof (m_InfoV2)) {
  606. //
  607. // Recreate the randomizers
  608. //
  609. SAFE_DELETE (m_pCreationVolume);
  610. SAFE_DELETE (m_pVelocityRandomizer);
  611. m_pCreationVolume = Create_Randomizer (m_InfoV2.CreationVolume);
  612. m_pVelocityRandomizer = Create_Randomizer (m_InfoV2.VelRandom);
  613. // Success!
  614. ret_val = WW3D_ERROR_OK;
  615. }
  616. // Close the chunk, so the next read will be successful.
  617. chunk_load.Close_Chunk ();
  618. }
  619. // Return the WW3DErrorClass::ErrorType return code
  620. return ret_val;
  621. }
  622. ///////////////////////////////////////////////////////////////////////////////////
  623. //
  624. // Read_Props
  625. //
  626. WW3DErrorType
  627. ParticleEmitterDefClass::Read_Props (ChunkLoadClass &chunk_load)
  628. {
  629. // Assume error
  630. WW3DErrorType ret_val = WW3D_ERROR_LOAD_FAILED;
  631. Free_Props ();
  632. // Is this the user chunk?
  633. if (chunk_load.Open_Chunk () &&
  634. (chunk_load.Cur_Chunk_ID () == W3D_CHUNK_EMITTER_PROPS)) {
  635. W3dEmitterPropertyStruct info = { 0 };
  636. if (chunk_load.Read (&info, sizeof (info)) == sizeof (info)) {
  637. unsigned int index=0;
  638. //ParticlePropertyStruct<Vector3>
  639. m_ColorKeyframes.NumKeyFrames = info.ColorKeyframes - 1;
  640. m_OpacityKeyframes.NumKeyFrames = info.OpacityKeyframes - 1;
  641. m_SizeKeyframes.NumKeyFrames = info.SizeKeyframes - 1;
  642. m_ColorKeyframes.Rand = RGBA_TO_VECTOR3 (info.ColorRandom);
  643. m_OpacityKeyframes.Rand = info.OpacityRandom;
  644. m_SizeKeyframes.Rand = info.SizeRandom;
  645. //
  646. // Allocate the array of color keyframes
  647. //
  648. if (m_ColorKeyframes.NumKeyFrames > 0) {
  649. m_ColorKeyframes.KeyTimes = W3DNEWARRAY float[m_ColorKeyframes.NumKeyFrames];
  650. m_ColorKeyframes.Values = W3DNEWARRAY Vector3[m_ColorKeyframes.NumKeyFrames];
  651. }
  652. //
  653. // Allocate the array of opacity keyframes
  654. //
  655. if (m_OpacityKeyframes.NumKeyFrames > 0) {
  656. m_OpacityKeyframes.KeyTimes = W3DNEWARRAY float[m_OpacityKeyframes.NumKeyFrames];
  657. m_OpacityKeyframes.Values = W3DNEWARRAY float[m_OpacityKeyframes.NumKeyFrames];
  658. }
  659. //
  660. // Allocate the array of size keyframes
  661. //
  662. if (m_SizeKeyframes.NumKeyFrames > 0) {
  663. m_SizeKeyframes.KeyTimes = W3DNEWARRAY float[m_SizeKeyframes.NumKeyFrames];
  664. m_SizeKeyframes.Values = W3DNEWARRAY float[m_SizeKeyframes.NumKeyFrames];
  665. }
  666. //
  667. // Read the color keyframes from the chunk
  668. //
  669. Read_Color_Keyframe (chunk_load, NULL, &m_ColorKeyframes.Start);
  670. for (index = 0; index < m_ColorKeyframes.NumKeyFrames; index ++) {
  671. Read_Color_Keyframe (chunk_load,
  672. &m_ColorKeyframes.KeyTimes[index],
  673. &m_ColorKeyframes.Values[index]);
  674. }
  675. //
  676. // If the last keyframe is 'black' and we are using a color randomizer,
  677. // then make sure the last color is less then 0 so any randomized color
  678. // will end up as black
  679. //
  680. int last_keyframe = (m_ColorKeyframes.NumKeyFrames - 1);
  681. if ( last_keyframe > 0 &&
  682. m_ColorKeyframes.Values[last_keyframe].X == 0 &&
  683. m_ColorKeyframes.Values[last_keyframe].Y == 0 &&
  684. m_ColorKeyframes.Values[last_keyframe].Z == 0 &&
  685. (m_ColorKeyframes.Rand.X > 0 || m_ColorKeyframes.Rand.Y > 0 || m_ColorKeyframes.Rand.Z > 0))
  686. {
  687. m_ColorKeyframes.Values[last_keyframe].X = -m_ColorKeyframes.Rand.X;
  688. m_ColorKeyframes.Values[last_keyframe].Y = -m_ColorKeyframes.Rand.Y;
  689. m_ColorKeyframes.Values[last_keyframe].Z = -m_ColorKeyframes.Rand.Z;
  690. }
  691. //
  692. // Read the opacity keyframes from the chunk
  693. //
  694. Read_Opacity_Keyframe (chunk_load, NULL, &m_OpacityKeyframes.Start);
  695. for (index = 0; index < m_OpacityKeyframes.NumKeyFrames; index ++) {
  696. Read_Opacity_Keyframe (chunk_load,
  697. &m_OpacityKeyframes.KeyTimes[index],
  698. &m_OpacityKeyframes.Values[index]);
  699. }
  700. //
  701. // Read the size keyframes from the chunk
  702. //
  703. Read_Size_Keyframe (chunk_load, NULL, &m_SizeKeyframes.Start);
  704. for (index = 0; index < m_SizeKeyframes.NumKeyFrames; index ++) {
  705. Read_Size_Keyframe (chunk_load,
  706. &m_SizeKeyframes.KeyTimes[index],
  707. &m_SizeKeyframes.Values[index]);
  708. }
  709. // Success!
  710. ret_val = WW3D_ERROR_OK;
  711. }
  712. // Close the chunk, so the next read will be successful.
  713. chunk_load.Close_Chunk ();
  714. }
  715. // Return the WW3DErrorClass::ErrorType return code
  716. return ret_val;
  717. }
  718. //////////////////////////////////////////////////////////////////////////////////
  719. //
  720. // Read_Color_Keyframe
  721. //
  722. bool
  723. ParticleEmitterDefClass::Read_Color_Keyframe
  724. (
  725. ChunkLoadClass & chunk_load,
  726. float * key_time,
  727. Vector3 * value
  728. )
  729. {
  730. bool retval = false;
  731. //
  732. // Read the color key frame from the chunk
  733. //
  734. W3dEmitterColorKeyframeStruct key_frame = { 0 };
  735. if (chunk_load.Read (&key_frame, sizeof (key_frame)) == sizeof (key_frame)) {
  736. // Pass the key time to the caller
  737. if (key_time != NULL) {
  738. (*key_time) = key_frame.Time;
  739. }
  740. // Pass the oclor back to the caller
  741. if (value != NULL) {
  742. (*value) = RGBA_TO_VECTOR3 (key_frame.Color);
  743. }
  744. // Success!
  745. retval = true;
  746. }
  747. return retval;
  748. }
  749. //////////////////////////////////////////////////////////////////////////////////
  750. //
  751. // Read_Opacity_Keyframe
  752. //
  753. bool
  754. ParticleEmitterDefClass::Read_Opacity_Keyframe
  755. (
  756. ChunkLoadClass & chunk_load,
  757. float * key_time,
  758. float * value
  759. )
  760. {
  761. bool retval = false;
  762. //
  763. // Read the key frame from the chunk
  764. //
  765. W3dEmitterOpacityKeyframeStruct key_frame = { 0 };
  766. if (chunk_load.Read (&key_frame, sizeof (key_frame)) == sizeof (key_frame)) {
  767. // Pass the key time to the caller
  768. if (key_time != NULL) {
  769. (*key_time) = key_frame.Time;
  770. }
  771. // Pass the value back to the caller
  772. if (value != NULL) {
  773. (*value) = key_frame.Opacity;
  774. }
  775. // Success!
  776. retval = true;
  777. }
  778. return retval;
  779. }
  780. //////////////////////////////////////////////////////////////////////////////////
  781. //
  782. // Read_Size_Keyframe
  783. //
  784. bool
  785. ParticleEmitterDefClass::Read_Size_Keyframe
  786. (
  787. ChunkLoadClass & chunk_load,
  788. float * key_time,
  789. float * value
  790. )
  791. {
  792. bool retval = false;
  793. //
  794. // Read the key frame from the chunk
  795. //
  796. W3dEmitterSizeKeyframeStruct key_frame = { 0 };
  797. if (chunk_load.Read (&key_frame, sizeof (key_frame)) == sizeof (key_frame)) {
  798. // Pass the key time to the caller
  799. if (key_time != NULL) {
  800. (*key_time) = key_frame.Time;
  801. }
  802. // Pass the value back to the caller
  803. if (value != NULL) {
  804. (*value) = key_frame.Size;
  805. }
  806. // Success!
  807. retval = true;
  808. }
  809. return retval;
  810. }
  811. //////////////////////////////////////////////////////////////////////////////////
  812. //
  813. // Read_Line_Properties
  814. //
  815. WW3DErrorType
  816. ParticleEmitterDefClass::Read_Line_Properties(ChunkLoadClass & chunk_load)
  817. {
  818. // Assume error
  819. WW3DErrorType ret_val = WW3D_ERROR_LOAD_FAILED;
  820. // Is this the user chunk?
  821. if (chunk_load.Cur_Chunk_ID () == W3D_CHUNK_EMITTER_LINE_PROPERTIES) {
  822. // Read the chunk straight into our member structure
  823. if (chunk_load.Read (&m_LineProperties, sizeof (m_LineProperties)) == sizeof (m_LineProperties)) {
  824. // Success!
  825. ret_val = WW3D_ERROR_OK;
  826. }
  827. }
  828. // Return the WW3DErrorType return code
  829. return ret_val;
  830. }
  831. //////////////////////////////////////////////////////////////////////////////////
  832. //
  833. // Read_Rotation_Keyframes
  834. //
  835. WW3DErrorType
  836. ParticleEmitterDefClass::Read_Rotation_Keyframes (ChunkLoadClass &chunk_load)
  837. {
  838. // Assume success
  839. WW3DErrorType ret_val = WW3D_ERROR_OK;
  840. // Read the header
  841. W3dEmitterRotationHeaderStruct header;
  842. if (chunk_load.Read(&header,sizeof(header)) != sizeof(header)) {
  843. ret_val = WW3D_ERROR_LOAD_FAILED;
  844. }
  845. m_RotationKeyframes.NumKeyFrames = header.KeyframeCount;
  846. m_RotationKeyframes.Rand = header.Random;
  847. m_InitialOrientationRandom = header.OrientationRandom;
  848. // Read in the first key
  849. W3dEmitterRotationKeyframeStruct key;
  850. if (chunk_load.Read(&key,sizeof(key)) == sizeof(key)) {
  851. m_RotationKeyframes.Start = key.Rotation;
  852. }
  853. // Allocate the rotation keys
  854. if (m_RotationKeyframes.NumKeyFrames > 0) {
  855. m_RotationKeyframes.KeyTimes = W3DNEWARRAY float[m_RotationKeyframes.NumKeyFrames];
  856. m_RotationKeyframes.Values = W3DNEWARRAY float[m_RotationKeyframes.NumKeyFrames];
  857. }
  858. // Read in the keys
  859. for (unsigned int i=0; (i<header.KeyframeCount) && (ret_val == WW3D_ERROR_OK); i++) {
  860. W3dEmitterRotationKeyframeStruct key;
  861. if (chunk_load.Read(&key,sizeof(key)) == sizeof(key)) {
  862. m_RotationKeyframes.KeyTimes[i] = key.Time;
  863. m_RotationKeyframes.Values[i] = key.Rotation;
  864. } else {
  865. m_RotationKeyframes.KeyTimes[i] = 0.0f;
  866. m_RotationKeyframes.Values[i] = 0.0f;
  867. ret_val = WW3D_ERROR_LOAD_FAILED;
  868. }
  869. }
  870. return ret_val;
  871. }
  872. //////////////////////////////////////////////////////////////////////////////////
  873. //
  874. // Read_Frame_Keyframes
  875. //
  876. WW3DErrorType
  877. ParticleEmitterDefClass::Read_Frame_Keyframes (ChunkLoadClass &chunk_load)
  878. {
  879. // Assume success
  880. WW3DErrorType ret_val = WW3D_ERROR_OK;
  881. // Read the header
  882. W3dEmitterFrameHeaderStruct header;
  883. if (chunk_load.Read(&header,sizeof(header)) != sizeof(header)) {
  884. ret_val = WW3D_ERROR_LOAD_FAILED;
  885. }
  886. // Read in the first key
  887. W3dEmitterFrameKeyframeStruct key;
  888. if (chunk_load.Read(&key,sizeof(key)) == sizeof(key)) {
  889. m_FrameKeyframes.Start = key.Frame;
  890. }
  891. // Allocate the keys
  892. m_FrameKeyframes.NumKeyFrames = header.KeyframeCount;
  893. m_FrameKeyframes.Rand = header.Random;
  894. if (m_FrameKeyframes.NumKeyFrames > 0) {
  895. m_FrameKeyframes.KeyTimes = W3DNEWARRAY float[m_FrameKeyframes.NumKeyFrames];
  896. m_FrameKeyframes.Values = W3DNEWARRAY float[m_FrameKeyframes.NumKeyFrames];
  897. }
  898. // Read in the keys
  899. for (unsigned int i=0; (i<header.KeyframeCount) && (ret_val == WW3D_ERROR_OK); i++) {
  900. W3dEmitterFrameKeyframeStruct key;
  901. if (chunk_load.Read(&key,sizeof(key)) != sizeof(key)) {
  902. ret_val = WW3D_ERROR_LOAD_FAILED;
  903. }
  904. m_FrameKeyframes.KeyTimes[i] = key.Time;
  905. m_FrameKeyframes.Values[i] = key.Frame;
  906. }
  907. return ret_val;
  908. }
  909. //////////////////////////////////////////////////////////////////////////////////
  910. //
  911. // Read_Blur_Time_Keyframes
  912. //
  913. WW3DErrorType
  914. ParticleEmitterDefClass::Read_Blur_Time_Keyframes (ChunkLoadClass &chunk_load)
  915. {
  916. // Assume success
  917. WW3DErrorType ret_val = WW3D_ERROR_OK;
  918. // Read the header
  919. W3dEmitterBlurTimeHeaderStruct header;
  920. if (chunk_load.Read(&header,sizeof(header)) != sizeof(header)) {
  921. ret_val = WW3D_ERROR_LOAD_FAILED;
  922. }
  923. // Read in the first key
  924. W3dEmitterBlurTimeKeyframeStruct key;
  925. if (chunk_load.Read(&key,sizeof(key)) == sizeof(key)) {
  926. m_BlurTimeKeyframes.Start = key.BlurTime;
  927. }
  928. // Allocate the keys
  929. m_BlurTimeKeyframes.NumKeyFrames = header.KeyframeCount;
  930. m_BlurTimeKeyframes.Rand = header.Random;
  931. if (m_BlurTimeKeyframes.NumKeyFrames > 0) {
  932. m_BlurTimeKeyframes.KeyTimes = new float[m_BlurTimeKeyframes.NumKeyFrames];
  933. m_BlurTimeKeyframes.Values = new float[m_BlurTimeKeyframes.NumKeyFrames];
  934. }
  935. // Read in the keys
  936. for (unsigned int i=0; (i<header.KeyframeCount) && (ret_val == WW3D_ERROR_OK); i++) {
  937. W3dEmitterBlurTimeKeyframeStruct key;
  938. if (chunk_load.Read(&key,sizeof(key)) != sizeof(key)) {
  939. ret_val = WW3D_ERROR_LOAD_FAILED;
  940. }
  941. m_BlurTimeKeyframes.KeyTimes[i] = key.Time;
  942. m_BlurTimeKeyframes.Values[i] = key.BlurTime;
  943. }
  944. return ret_val;
  945. }
  946. //////////////////////////////////////////////////////////////////////////////////
  947. //
  948. // Read_Extra_Info
  949. //
  950. WW3DErrorType
  951. ParticleEmitterDefClass::Read_Extra_Info (ChunkLoadClass &chunk_load)
  952. {
  953. // Assume error
  954. WW3DErrorType ret_val = WW3D_ERROR_LOAD_FAILED;
  955. // Read the chunk straight into our member structure
  956. ::memset (&m_ExtraInfo, 0, sizeof (m_ExtraInfo));
  957. if (chunk_load.Read (&m_ExtraInfo, sizeof (m_ExtraInfo)) == sizeof (m_ExtraInfo)) {
  958. // Success!
  959. ret_val = WW3D_ERROR_OK;
  960. }
  961. // Return the WW3DErrorType return code
  962. return ret_val;
  963. }
  964. //////////////////////////////////////////////////////////////////////////////////
  965. //
  966. // Save
  967. //
  968. WW3DErrorType
  969. ParticleEmitterDefClass::Save_W3D (ChunkSaveClass &chunk_save)
  970. {
  971. // Assume error
  972. WW3DErrorType ret_val = WW3D_ERROR_SAVE_FAILED;
  973. // Begin a chunk that identifies an emitter
  974. if (chunk_save.Begin_Chunk (W3D_CHUNK_EMITTER) == TRUE) {
  975. // Attempt to save the different sections of the emitter definition
  976. if ((Save_Header (chunk_save) == WW3D_ERROR_OK) &&
  977. (Save_User_Data (chunk_save) == WW3D_ERROR_OK) &&
  978. (Save_Info (chunk_save) == WW3D_ERROR_OK) &&
  979. (Save_InfoV2 (chunk_save) == WW3D_ERROR_OK) &&
  980. (Save_Props (chunk_save) == WW3D_ERROR_OK) &&
  981. (Save_Line_Properties (chunk_save) == WW3D_ERROR_OK) &&
  982. (Save_Rotation_Keyframes (chunk_save) == WW3D_ERROR_OK) &&
  983. (Save_Frame_Keyframes (chunk_save) == WW3D_ERROR_OK) &&
  984. (Save_Blur_Time_Keyframes (chunk_save) == WW3D_ERROR_OK) &&
  985. (Save_Extra_Info (chunk_save) == WW3D_ERROR_OK)
  986. )
  987. {
  988. // Success!
  989. ret_val = WW3D_ERROR_OK;
  990. }
  991. // Close the emitter chunk
  992. chunk_save.End_Chunk ();
  993. }
  994. // Return the WW3DErrorType return code
  995. return ret_val;
  996. }
  997. ///////////////////////////////////////////////////////////////////////////////////
  998. //
  999. // Save_Header
  1000. //
  1001. WW3DErrorType
  1002. ParticleEmitterDefClass::Save_Header (ChunkSaveClass &chunk_save)
  1003. {
  1004. // Assume error
  1005. WW3DErrorType ret_val = WW3D_ERROR_SAVE_FAILED;
  1006. // Begin a chunk that identifies the emitter
  1007. if (chunk_save.Begin_Chunk (W3D_CHUNK_EMITTER_HEADER) == TRUE) {
  1008. // Fill the header structure
  1009. W3dEmitterHeaderStruct header = { 0 };
  1010. header.Version = W3D_CURRENT_EMITTER_VERSION;
  1011. ::lstrcpyn (header.Name, m_pName, sizeof (header.Name));
  1012. header.Name[sizeof (header.Name) - 1] = 0;
  1013. // Write the header out to the chunk
  1014. if (chunk_save.Write (&header, sizeof (header)) == sizeof (header))
  1015. {
  1016. // Success!
  1017. ret_val = WW3D_ERROR_OK;
  1018. }
  1019. // End the header chunk
  1020. chunk_save.End_Chunk ();
  1021. }
  1022. // Return the WW3DErrorType return code
  1023. return ret_val;
  1024. }
  1025. ///////////////////////////////////////////////////////////////////////////////////
  1026. //
  1027. // Save_User_Data
  1028. //
  1029. WW3DErrorType
  1030. ParticleEmitterDefClass::Save_User_Data (ChunkSaveClass &chunk_save)
  1031. {
  1032. // Assume error
  1033. WW3DErrorType ret_val = WW3D_ERROR_SAVE_FAILED;
  1034. // Begin a chunk that contains user information
  1035. if (chunk_save.Begin_Chunk (W3D_CHUNK_EMITTER_USER_DATA) == TRUE) {
  1036. DWORD string_len = m_pUserString ? (::lstrlen (m_pUserString) + 1) : 0;
  1037. // Fill the header structure
  1038. W3dEmitterUserInfoStruct user_info = { 0 };
  1039. user_info.Type = m_iUserType;
  1040. user_info.SizeofStringParam = string_len;
  1041. // Write the user information structure out to the chunk
  1042. if (chunk_save.Write (&user_info, sizeof (user_info)) == sizeof (user_info))
  1043. {
  1044. // Assume success
  1045. ret_val = WW3D_ERROR_OK;
  1046. // Do we need to write the user string to the file?
  1047. if (m_pUserString != NULL) {
  1048. // Now write the user string param to the file
  1049. if (chunk_save.Write (m_pUserString, string_len) != string_len) {
  1050. // Something went wrong
  1051. ret_val = WW3D_ERROR_SAVE_FAILED;
  1052. }
  1053. }
  1054. }
  1055. // End the user information chunk
  1056. chunk_save.End_Chunk ();
  1057. }
  1058. // Return the WW3DErrorType return code
  1059. return ret_val;
  1060. }
  1061. ///////////////////////////////////////////////////////////////////////////////////
  1062. //
  1063. // Save_Info
  1064. //
  1065. WW3DErrorType
  1066. ParticleEmitterDefClass::Save_Info (ChunkSaveClass &chunk_save)
  1067. {
  1068. // Assume error
  1069. WW3DErrorType ret_val = WW3D_ERROR_SAVE_FAILED;
  1070. // Begin a chunk that identifies the generic emitter settings
  1071. if (chunk_save.Begin_Chunk (W3D_CHUNK_EMITTER_INFO) == TRUE) {
  1072. // Write the settings structure out to the chunk
  1073. if (chunk_save.Write (&m_Info, sizeof (m_Info)) == sizeof (m_Info))
  1074. {
  1075. // Success!
  1076. ret_val = WW3D_ERROR_OK;
  1077. }
  1078. // End the settings chunk
  1079. chunk_save.End_Chunk ();
  1080. }
  1081. // Return the WW3DErrorType return code
  1082. return ret_val;
  1083. }
  1084. ///////////////////////////////////////////////////////////////////////////////////
  1085. //
  1086. // Save_InfoV2
  1087. //
  1088. WW3DErrorType
  1089. ParticleEmitterDefClass::Save_InfoV2 (ChunkSaveClass &chunk_save)
  1090. {
  1091. // Assume error
  1092. WW3DErrorType ret_val = WW3D_ERROR_SAVE_FAILED;
  1093. // Begin a chunk that identifies the generic emitter settings
  1094. if (chunk_save.Begin_Chunk (W3D_CHUNK_EMITTER_INFOV2) == TRUE) {
  1095. // Write the settings structure out to the chunk
  1096. if (chunk_save.Write (&m_InfoV2, sizeof (m_InfoV2)) == sizeof (m_InfoV2))
  1097. {
  1098. // Success!
  1099. ret_val = WW3D_ERROR_OK;
  1100. }
  1101. // End the settings chunk
  1102. chunk_save.End_Chunk ();
  1103. }
  1104. // Return the WW3DErrorType return code
  1105. return ret_val;
  1106. }
  1107. ///////////////////////////////////////////////////////////////////////////////////
  1108. //
  1109. // Save_Props
  1110. //
  1111. WW3DErrorType
  1112. ParticleEmitterDefClass::Save_Props (ChunkSaveClass &chunk_save)
  1113. {
  1114. // Assume error
  1115. WW3DErrorType ret_val = WW3D_ERROR_SAVE_FAILED;
  1116. // Begin a chunk that identifies the generic emitter settings
  1117. if (chunk_save.Begin_Chunk (W3D_CHUNK_EMITTER_PROPS) == TRUE) {
  1118. //
  1119. // Fill in the property struct
  1120. //
  1121. W3dEmitterPropertyStruct info = { 0 };
  1122. info.ColorKeyframes = m_ColorKeyframes.NumKeyFrames + 1;
  1123. info.OpacityKeyframes = m_OpacityKeyframes.NumKeyFrames + 1;
  1124. info.SizeKeyframes = m_SizeKeyframes.NumKeyFrames + 1;
  1125. info.OpacityRandom = m_OpacityKeyframes.Rand;
  1126. info.SizeRandom = m_SizeKeyframes.Rand;
  1127. VECTOR3_TO_RGBA (m_ColorKeyframes.Rand, info.ColorRandom);
  1128. //
  1129. // Write the property structure out to the chunk
  1130. //
  1131. if (chunk_save.Write (&info, sizeof (info)) == sizeof (info)) {
  1132. //
  1133. // Save the keyframes
  1134. //
  1135. if ((Save_Color_Keyframes (chunk_save) == WW3D_ERROR_OK) &&
  1136. (Save_Opacity_Keyframes (chunk_save) == WW3D_ERROR_OK) &&
  1137. (Save_Size_Keyframes (chunk_save) == WW3D_ERROR_OK)) {
  1138. // Success!
  1139. ret_val = WW3D_ERROR_OK;
  1140. }
  1141. }
  1142. // End the settings chunk
  1143. chunk_save.End_Chunk ();
  1144. }
  1145. // Return the WW3DErrorType return code
  1146. return ret_val;
  1147. }
  1148. ///////////////////////////////////////////////////////////////////////////////////
  1149. //
  1150. // Save_Color_Keyframes
  1151. //
  1152. WW3DErrorType
  1153. ParticleEmitterDefClass::Save_Color_Keyframes (ChunkSaveClass &chunk_save)
  1154. {
  1155. // Assume error
  1156. WW3DErrorType ret_val = WW3D_ERROR_SAVE_FAILED;
  1157. W3dEmitterColorKeyframeStruct info = { 0 };
  1158. info.Time = 0;
  1159. VECTOR3_TO_RGBA (m_ColorKeyframes.Start, info.Color);
  1160. //
  1161. // Write the starting color keyframe to the chunk
  1162. //
  1163. if (chunk_save.Write (&info, sizeof (info)) == sizeof (info)) {
  1164. //
  1165. // Write each of the remaining color keyframes to the chunk
  1166. //
  1167. int count = m_ColorKeyframes.NumKeyFrames;
  1168. bool success = true;
  1169. for (int index = 0; (index < count) && success; index ++) {
  1170. info.Time = m_ColorKeyframes.KeyTimes[index];
  1171. VECTOR3_TO_RGBA (m_ColorKeyframes.Values[index], info.Color);
  1172. success = (chunk_save.Write (&info, sizeof (info)) == sizeof (info));
  1173. }
  1174. ret_val = success ? WW3D_ERROR_OK : WW3D_ERROR_SAVE_FAILED;
  1175. }
  1176. // Return the WW3DErrorType return code
  1177. return ret_val;
  1178. }
  1179. ///////////////////////////////////////////////////////////////////////////////////
  1180. //
  1181. // Save_Opacity_Keyframes
  1182. //
  1183. WW3DErrorType
  1184. ParticleEmitterDefClass::Save_Opacity_Keyframes (ChunkSaveClass &chunk_save)
  1185. {
  1186. // Assume error
  1187. WW3DErrorType ret_val = WW3D_ERROR_SAVE_FAILED;
  1188. W3dEmitterOpacityKeyframeStruct info = { 0 };
  1189. info.Time = 0;
  1190. info.Opacity = m_OpacityKeyframes.Start;
  1191. //
  1192. // Write the starting keyframe to the chunk
  1193. //
  1194. if (chunk_save.Write (&info, sizeof (info)) == sizeof (info)) {
  1195. //
  1196. // Write each of the remaining keyframes to the chunk
  1197. //
  1198. int count = m_OpacityKeyframes.NumKeyFrames;
  1199. bool success = true;
  1200. for (int index = 0; (index < count) && success; index ++) {
  1201. info.Time = m_OpacityKeyframes.KeyTimes[index];
  1202. info.Opacity = m_OpacityKeyframes.Values[index];
  1203. success = (chunk_save.Write (&info, sizeof (info)) == sizeof (info));
  1204. }
  1205. ret_val = success ? WW3D_ERROR_OK : WW3D_ERROR_SAVE_FAILED;
  1206. }
  1207. // Return the WW3DErrorType return code
  1208. return ret_val;
  1209. }
  1210. ///////////////////////////////////////////////////////////////////////////////////
  1211. //
  1212. // Save_Size_Keyframes
  1213. //
  1214. WW3DErrorType
  1215. ParticleEmitterDefClass::Save_Size_Keyframes (ChunkSaveClass &chunk_save)
  1216. {
  1217. // Assume error
  1218. WW3DErrorType ret_val = WW3D_ERROR_SAVE_FAILED;
  1219. W3dEmitterSizeKeyframeStruct info = { 0 };
  1220. info.Time = 0;
  1221. info.Size = m_SizeKeyframes.Start;
  1222. //
  1223. // Write the starting keyframe to the chunk
  1224. //
  1225. if (chunk_save.Write (&info, sizeof (info)) == sizeof (info)) {
  1226. //
  1227. // Write each of the remaining keyframes to the chunk
  1228. //
  1229. int count = m_SizeKeyframes.NumKeyFrames;
  1230. bool success = true;
  1231. for (int index = 0; (index < count) && success; index ++) {
  1232. info.Time = m_SizeKeyframes.KeyTimes[index];
  1233. info.Size = m_SizeKeyframes.Values[index];
  1234. success = (chunk_save.Write (&info, sizeof (info)) == sizeof (info));
  1235. }
  1236. ret_val = success ? WW3D_ERROR_OK : WW3D_ERROR_SAVE_FAILED;
  1237. }
  1238. // Return the WW3DErrorType return code
  1239. return ret_val;
  1240. }
  1241. WW3DErrorType
  1242. ParticleEmitterDefClass::Save_Line_Properties (ChunkSaveClass &chunk_save)
  1243. {
  1244. // Assume error
  1245. WW3DErrorType ret_val = WW3D_ERROR_SAVE_FAILED;
  1246. // Begin a chunk that identifies the line properties
  1247. if (chunk_save.Begin_Chunk (W3D_CHUNK_EMITTER_LINE_PROPERTIES) == TRUE) {
  1248. // Write the line properties structure out to the chunk
  1249. if (chunk_save.Write (&m_LineProperties, sizeof (m_LineProperties)) == sizeof (m_LineProperties))
  1250. {
  1251. // Success!
  1252. ret_val = WW3D_ERROR_OK;
  1253. }
  1254. // End the chunk
  1255. chunk_save.End_Chunk ();
  1256. }
  1257. // Return the WW3DErrorType return code
  1258. return ret_val;
  1259. }
  1260. ///////////////////////////////////////////////////////////////////////////////////
  1261. //
  1262. // Save_Rotation_Keyframes
  1263. // NOTE: Rotation keyframes are saved in a separate chunk unlike color,size,and
  1264. // opacity which are embedded inside the PROPS chunk.
  1265. //
  1266. WW3DErrorType
  1267. ParticleEmitterDefClass::Save_Rotation_Keyframes (ChunkSaveClass & chunk_save)
  1268. {
  1269. // Assume error
  1270. WW3DErrorType ret_val = WW3D_ERROR_SAVE_FAILED;
  1271. // Begin a chunk that identifies the rotation keyframes
  1272. if (chunk_save.Begin_Chunk (W3D_CHUNK_EMITTER_ROTATION_KEYFRAMES) == TRUE) {
  1273. // Write the header
  1274. W3dEmitterRotationHeaderStruct header;
  1275. header.KeyframeCount = m_RotationKeyframes.NumKeyFrames;
  1276. header.Random = m_RotationKeyframes.Rand;
  1277. header.OrientationRandom = m_InitialOrientationRandom;
  1278. chunk_save.Write (&header, sizeof (W3dEmitterRotationHeaderStruct));
  1279. // Write the keyframes
  1280. bool success = true;
  1281. W3dEmitterRotationKeyframeStruct key;
  1282. // Write the start keyframe
  1283. key.Time = 0;
  1284. key.Rotation = m_RotationKeyframes.Start;
  1285. chunk_save.Write (&key, sizeof (key));
  1286. // Write the remaining keyframes
  1287. for (unsigned int index = 0; (index < header.KeyframeCount) && success; index ++) {
  1288. key.Time = m_RotationKeyframes.KeyTimes[index];
  1289. key.Rotation = m_RotationKeyframes.Values[index];
  1290. success = (chunk_save.Write (&key, sizeof (key)) == sizeof (key));
  1291. }
  1292. ret_val = success ? WW3D_ERROR_OK : WW3D_ERROR_SAVE_FAILED;
  1293. // End the chunk
  1294. chunk_save.End_Chunk ();
  1295. }
  1296. // Return the WW3DErrorType return code
  1297. return ret_val;
  1298. }
  1299. ///////////////////////////////////////////////////////////////////////////////////
  1300. //
  1301. // Save_Frame_Keyframes
  1302. // NOTE: Frame keyframes are saved in a separate chunk unlike color,size,and
  1303. // opacity which are embedded inside the PROPS chunk.
  1304. //
  1305. WW3DErrorType
  1306. ParticleEmitterDefClass::Save_Frame_Keyframes (ChunkSaveClass & chunk_save)
  1307. {
  1308. // Assume error
  1309. WW3DErrorType ret_val = WW3D_ERROR_SAVE_FAILED;
  1310. // Begin a chunk that identifies the rotation keyframes
  1311. if (chunk_save.Begin_Chunk (W3D_CHUNK_EMITTER_FRAME_KEYFRAMES) == TRUE) {
  1312. // Write the header
  1313. W3dEmitterFrameHeaderStruct header;
  1314. header.KeyframeCount = m_FrameKeyframes.NumKeyFrames;
  1315. header.Random = m_FrameKeyframes.Rand;
  1316. chunk_save.Write (&header, sizeof (W3dEmitterFrameHeaderStruct));
  1317. // Write the keyframes
  1318. bool success = true;
  1319. W3dEmitterFrameKeyframeStruct key;
  1320. // Write the start keyframe
  1321. key.Time = 0;
  1322. key.Frame = m_FrameKeyframes.Start;
  1323. chunk_save.Write (&key, sizeof (key));
  1324. // Write the remaining keyframes
  1325. for (unsigned int index = 0; (index < header.KeyframeCount) && success; index ++) {
  1326. key.Time = m_FrameKeyframes.KeyTimes[index];
  1327. key.Frame = m_FrameKeyframes.Values[index];
  1328. success = (chunk_save.Write (&key, sizeof (key)) == sizeof (key));
  1329. }
  1330. ret_val = success ? WW3D_ERROR_OK : WW3D_ERROR_SAVE_FAILED;
  1331. // End the chunk
  1332. chunk_save.End_Chunk ();
  1333. }
  1334. // Return the WW3DErrorType return code
  1335. return ret_val;
  1336. }
  1337. ///////////////////////////////////////////////////////////////////////////////////
  1338. //
  1339. // Save_Blur_Time_Keyframes
  1340. // NOTE: Blur Time keyframes are saved in a separate chunk unlike color,size,and
  1341. // opacity which are embedded inside the PROPS chunk.
  1342. //
  1343. WW3DErrorType
  1344. ParticleEmitterDefClass::Save_Blur_Time_Keyframes (ChunkSaveClass & chunk_save)
  1345. {
  1346. // Assume error
  1347. WW3DErrorType ret_val = WW3D_ERROR_SAVE_FAILED;
  1348. // Begin a chunk that identifies the rotation keyframes
  1349. if (chunk_save.Begin_Chunk (W3D_CHUNK_EMITTER_BLUR_TIME_KEYFRAMES) == TRUE) {
  1350. // Write the header
  1351. W3dEmitterBlurTimeHeaderStruct header;
  1352. header.KeyframeCount = m_BlurTimeKeyframes.NumKeyFrames;
  1353. header.Random = m_BlurTimeKeyframes.Rand;
  1354. chunk_save.Write (&header, sizeof (W3dEmitterBlurTimeHeaderStruct));
  1355. // Write the keyframes
  1356. bool success = true;
  1357. W3dEmitterBlurTimeKeyframeStruct key;
  1358. // Write the start keyframe
  1359. key.Time = 0;
  1360. key.BlurTime = m_BlurTimeKeyframes.Start;
  1361. chunk_save.Write (&key, sizeof (key));
  1362. // Write the remaining keyframes
  1363. for (unsigned int index = 0; (index < header.KeyframeCount) && success; index ++) {
  1364. key.Time = m_BlurTimeKeyframes.KeyTimes[index];
  1365. key.BlurTime = m_BlurTimeKeyframes.Values[index];
  1366. success = (chunk_save.Write (&key, sizeof (key)) == sizeof (key));
  1367. }
  1368. ret_val = success ? WW3D_ERROR_OK : WW3D_ERROR_SAVE_FAILED;
  1369. // End the chunk
  1370. chunk_save.End_Chunk ();
  1371. }
  1372. // Return the WW3DErrorType return code
  1373. return ret_val;
  1374. }
  1375. WW3DErrorType
  1376. ParticleEmitterDefClass::Save_Extra_Info (ChunkSaveClass & chunk_save)
  1377. {
  1378. // Assume error
  1379. WW3DErrorType ret_val = WW3D_ERROR_SAVE_FAILED;
  1380. // Begin a chunk that identifies the extra info
  1381. if (chunk_save.Begin_Chunk (W3D_CHUNK_EMITTER_EXTRA_INFO) == TRUE) {
  1382. W3dEmitterExtraInfoStruct data;
  1383. memset(&data, 0, sizeof(data));
  1384. data.FutureStartTime = Get_Future_Start_Time();
  1385. bool success = (chunk_save.Write (&data, sizeof (data)) == sizeof (data));
  1386. ret_val = success ? WW3D_ERROR_OK : WW3D_ERROR_SAVE_FAILED;
  1387. chunk_save.End_Chunk ();
  1388. }
  1389. return ret_val;
  1390. }
  1391. ///////////////////////////////////////////////////////////////////////////////////
  1392. //
  1393. // Set_Color_Keyframes
  1394. //
  1395. void
  1396. ParticleEmitterDefClass::Set_Color_Keyframes (ParticlePropertyStruct<Vector3> &keyframes)
  1397. {
  1398. SAFE_DELETE_ARRAY (m_ColorKeyframes.KeyTimes);
  1399. SAFE_DELETE_ARRAY (m_ColorKeyframes.Values);
  1400. ::Copy_Emitter_Property_Struct (m_ColorKeyframes, keyframes);
  1401. return ;
  1402. }
  1403. ///////////////////////////////////////////////////////////////////////////////////
  1404. //
  1405. // Set_Opacity_Keyframes
  1406. //
  1407. void
  1408. ParticleEmitterDefClass::Set_Opacity_Keyframes (ParticlePropertyStruct<float> &keyframes)
  1409. {
  1410. SAFE_DELETE_ARRAY (m_OpacityKeyframes.KeyTimes);
  1411. SAFE_DELETE_ARRAY (m_OpacityKeyframes.Values);
  1412. ::Copy_Emitter_Property_Struct (m_OpacityKeyframes, keyframes);
  1413. return ;
  1414. }
  1415. ///////////////////////////////////////////////////////////////////////////////////
  1416. //
  1417. // Set_Size_Keyframes
  1418. //
  1419. void
  1420. ParticleEmitterDefClass::Set_Size_Keyframes (ParticlePropertyStruct<float> &keyframes)
  1421. {
  1422. SAFE_DELETE_ARRAY (m_SizeKeyframes.KeyTimes);
  1423. SAFE_DELETE_ARRAY (m_SizeKeyframes.Values);
  1424. ::Copy_Emitter_Property_Struct (m_SizeKeyframes, keyframes);
  1425. return ;
  1426. }
  1427. ///////////////////////////////////////////////////////////////////////////////////
  1428. //
  1429. // Set_Rotation_Keyframes
  1430. //
  1431. void
  1432. ParticleEmitterDefClass::Set_Rotation_Keyframes (ParticlePropertyStruct<float> &keyframes, float orient_rnd)
  1433. {
  1434. SAFE_DELETE_ARRAY (m_RotationKeyframes.KeyTimes);
  1435. SAFE_DELETE_ARRAY (m_RotationKeyframes.Values);
  1436. ::Copy_Emitter_Property_Struct (m_RotationKeyframes, keyframes);
  1437. m_InitialOrientationRandom = orient_rnd;
  1438. return ;
  1439. }
  1440. ///////////////////////////////////////////////////////////////////////////////////
  1441. //
  1442. // Set_Frame_Keyframes
  1443. //
  1444. void
  1445. ParticleEmitterDefClass::Set_Frame_Keyframes (ParticlePropertyStruct<float> &keyframes)
  1446. {
  1447. SAFE_DELETE_ARRAY (m_FrameKeyframes.KeyTimes);
  1448. SAFE_DELETE_ARRAY (m_FrameKeyframes.Values);
  1449. ::Copy_Emitter_Property_Struct (m_FrameKeyframes, keyframes);
  1450. return ;
  1451. }
  1452. ///////////////////////////////////////////////////////////////////////////////////
  1453. //
  1454. // Set_Blur_Time_Keyframes
  1455. //
  1456. void
  1457. ParticleEmitterDefClass::Set_Blur_Time_Keyframes (ParticlePropertyStruct<float> &keyframes)
  1458. {
  1459. SAFE_DELETE_ARRAY (m_BlurTimeKeyframes.KeyTimes);
  1460. SAFE_DELETE_ARRAY (m_BlurTimeKeyframes.Values);
  1461. ::Copy_Emitter_Property_Struct (m_BlurTimeKeyframes, keyframes);
  1462. return ;
  1463. }
  1464. ///////////////////////////////////////////////////////////////////////////////////
  1465. //
  1466. // Get_Color_Keyframes
  1467. //
  1468. void
  1469. ParticleEmitterDefClass::Get_Color_Keyframes (ParticlePropertyStruct<Vector3> &keyframes) const
  1470. {
  1471. ::Copy_Emitter_Property_Struct (keyframes, m_ColorKeyframes);
  1472. return ;
  1473. }
  1474. ///////////////////////////////////////////////////////////////////////////////////
  1475. //
  1476. // Get_Opacity_Keyframes
  1477. //
  1478. void
  1479. ParticleEmitterDefClass::Get_Opacity_Keyframes (ParticlePropertyStruct<float> &keyframes) const
  1480. {
  1481. ::Copy_Emitter_Property_Struct (keyframes, m_OpacityKeyframes);
  1482. return ;
  1483. }
  1484. ///////////////////////////////////////////////////////////////////////////////////
  1485. //
  1486. // Get_Size_Keyframes
  1487. //
  1488. void
  1489. ParticleEmitterDefClass::Get_Size_Keyframes (ParticlePropertyStruct<float> &keyframes) const
  1490. {
  1491. ::Copy_Emitter_Property_Struct (keyframes, m_SizeKeyframes);
  1492. return ;
  1493. }
  1494. ///////////////////////////////////////////////////////////////////////////////////
  1495. //
  1496. // Get_Rotation_Keyframes
  1497. //
  1498. void
  1499. ParticleEmitterDefClass::Get_Rotation_Keyframes (ParticlePropertyStruct<float> &keyframes) const
  1500. {
  1501. ::Copy_Emitter_Property_Struct (keyframes, m_RotationKeyframes);
  1502. return ;
  1503. }
  1504. ///////////////////////////////////////////////////////////////////////////////////
  1505. //
  1506. // Get_Frame_Keyframes
  1507. //
  1508. void
  1509. ParticleEmitterDefClass::Get_Frame_Keyframes (ParticlePropertyStruct<float> &keyframes) const
  1510. {
  1511. ::Copy_Emitter_Property_Struct (keyframes, m_FrameKeyframes);
  1512. return ;
  1513. }
  1514. ///////////////////////////////////////////////////////////////////////////////////
  1515. //
  1516. // Get_Blur_Time_Keyframes
  1517. //
  1518. void
  1519. ParticleEmitterDefClass::Get_Blur_Time_Keyframes (ParticlePropertyStruct<float> &blurtimeframes) const
  1520. {
  1521. ::Copy_Emitter_Property_Struct (blurtimeframes, m_BlurTimeKeyframes);
  1522. return ;
  1523. }
  1524. ///////////////////////////////////////////////////////////////////////////////////
  1525. //
  1526. // Create
  1527. //
  1528. RenderObjClass *
  1529. ParticleEmitterPrototypeClass::Create (void)
  1530. {
  1531. return ParticleEmitterClass::Create_From_Definition (*m_pDefinition);
  1532. }
  1533. ///////////////////////////////////////////////////////////////////////////////////
  1534. //
  1535. // Load
  1536. //
  1537. PrototypeClass *
  1538. ParticleEmitterLoaderClass::Load_W3D (ChunkLoadClass &chunk_load)
  1539. {
  1540. // Assume failure
  1541. ParticleEmitterPrototypeClass *pprototype = NULL;
  1542. // Create a definition object
  1543. ParticleEmitterDefClass *pdefinition = W3DNEW ParticleEmitterDefClass;
  1544. if (pdefinition != NULL) {
  1545. // Ask the definition object to load the emitter data
  1546. if (pdefinition->Load_W3D (chunk_load) != WW3D_ERROR_OK) {
  1547. // Error! Free the definition
  1548. delete pdefinition;
  1549. pdefinition = NULL;
  1550. } else {
  1551. // Success! Create a prototype from the definition
  1552. pprototype = W3DNEW ParticleEmitterPrototypeClass (pdefinition);
  1553. }
  1554. }
  1555. // Return a pointer to the prototype
  1556. return pprototype;
  1557. }