part_ldr.cpp 50 KB

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