modeler.cpp 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560
  1. #include "pch.h"
  2. //////////////////////////////////////////////////////////////////////////////
  3. //
  4. // Function defined in xfile.cpp
  5. //
  6. //////////////////////////////////////////////////////////////////////////////
  7. TRef<Geo> ImportXFile(Modeler* pmodeler, ZFile* pfile, Number* pnumberFrame, bool& bAnimation);
  8. //////////////////////////////////////////////////////////////////////////////
  9. //
  10. // ModelerSite
  11. //
  12. //////////////////////////////////////////////////////////////////////////////
  13. class ModelerSiteImpl : public ModelerSite {
  14. public:
  15. //
  16. // ModelerSite members
  17. //
  18. void Error(const ZString& str)
  19. {
  20. ZError(str);
  21. }
  22. };
  23. //////////////////////////////////////////////////////////////////////////////
  24. //
  25. // Factories
  26. //
  27. //////////////////////////////////////////////////////////////////////////////
  28. class AnimatedImagePaneRectFactory : public IFunction {
  29. private:
  30. public:
  31. TRef<IObject> Apply(ObjectStack& stack)
  32. {
  33. TRef<Image> pimage = Image::Cast((Value*)(IObject*)stack.Pop());
  34. TRef<RectValue> prect = RectValue::Cast( (IObject*)stack.Pop());
  35. return (Pane*)
  36. new AnimatedImagePane(
  37. pimage,
  38. prect->GetValue()
  39. );
  40. }
  41. };
  42. //////////////////////////////////////////////////////////////////////////////
  43. //
  44. //
  45. //
  46. //////////////////////////////////////////////////////////////////////////////
  47. class AnimatedImagePaneFactory : public IFunction {
  48. private:
  49. public:
  50. TRef<IObject> Apply(ObjectStack& stack)
  51. {
  52. TRef<Image> pimage = Image::Cast((Value*)(IObject*)stack.Pop());
  53. return (Pane*)new AnimatedImagePane(pimage);
  54. }
  55. };
  56. //////////////////////////////////////////////////////////////////////////////
  57. //
  58. //
  59. //
  60. //////////////////////////////////////////////////////////////////////////////
  61. class PaneImageFactory : public IFunction {
  62. private:
  63. TRef<Engine> m_pengine;
  64. public:
  65. PaneImageFactory(
  66. Modeler* pmodeler
  67. ) :
  68. m_pengine(pmodeler->GetEngine())
  69. {
  70. }
  71. TRef<IObject> Apply(ObjectStack& stack)
  72. {
  73. TRef<Pane> ppane; CastTo(ppane, (IObject*)stack.Pop());
  74. TRef<Boolean> pbooleanZBuffer = Boolean::Cast((IObject*)stack.Pop());
  75. TRef<Boolean> pbooleanColorKey = Boolean::Cast((IObject*)stack.Pop());
  76. SurfaceType stype = SurfaceType2D() | SurfaceType3D();
  77. if (pbooleanZBuffer->GetValue()) {
  78. stype.Set(SurfaceTypeZBuffer());
  79. }
  80. return (Value*)
  81. CreatePaneImage(
  82. m_pengine,
  83. stype,
  84. pbooleanColorKey->GetValue(),
  85. ppane
  86. );
  87. }
  88. };
  89. //////////////////////////////////////////////////////////////////////////////
  90. //
  91. //
  92. //
  93. //////////////////////////////////////////////////////////////////////////////
  94. class FrameImageButtonPaneFactory : public IFunction {
  95. private:
  96. TRef<Modeler> m_pmodeler;
  97. TRef<Number> m_ptime;
  98. public:
  99. FrameImageButtonPaneFactory(
  100. Modeler* pmodeler,
  101. Number* ptime
  102. ) :
  103. m_pmodeler(pmodeler),
  104. m_ptime(ptime)
  105. {
  106. }
  107. TRef<IObject> Apply(ObjectStack& stack)
  108. {
  109. StringValue* pstring = StringValue::Cast((IObject*)stack.Pop());
  110. Number* pnumber = Number::Cast((IObject*)stack.Pop());
  111. bool bLoop = GetBoolean((IObject*)stack.Pop());
  112. bool bFinish = GetBoolean((IObject*)stack.Pop());
  113. TRef<INameSpace> pns = m_pmodeler->GetNameSpace(pstring->GetValue());
  114. TRef<ModifiableNumber> pnumberFrame; CastTo(pnumberFrame, pns->FindMember("frame"));
  115. TRef<Image> pimage = pns->FindImage("image");
  116. return
  117. CreateFrameImageButtonPane(
  118. m_ptime,
  119. pimage,
  120. pnumberFrame,
  121. pnumber->GetValue(),
  122. bLoop,
  123. bFinish
  124. );
  125. }
  126. };
  127. //////////////////////////////////////////////////////////////////////////////
  128. //
  129. //
  130. //
  131. //////////////////////////////////////////////////////////////////////////////
  132. class PointX : public Number {
  133. private:
  134. PointValue* GetPoint() { return PointValue::Cast(GetChild(0)); }
  135. public:
  136. PointX(PointValue* ppoint) :
  137. Number(ppoint)
  138. {
  139. }
  140. void Evaluate()
  141. {
  142. GetValueInternal() = GetPoint()->GetValue().X();
  143. }
  144. };
  145. class PointXFactory : public IFunction {
  146. private:
  147. public:
  148. TRef<IObject> Apply(ObjectStack& stack)
  149. {
  150. TRef<PointValue> ppoint = PointValue::Cast((IObject*)stack.Pop());
  151. return new PointX(ppoint);
  152. }
  153. };
  154. //////////////////////////////////////////////////////////////////////////////
  155. //
  156. //
  157. //
  158. //////////////////////////////////////////////////////////////////////////////
  159. class PointY : public Number {
  160. private:
  161. PointValue* GetPoint() { return PointValue::Cast(GetChild(0)); }
  162. public:
  163. PointY(PointValue* ppoint) :
  164. Number(ppoint)
  165. {
  166. }
  167. void Evaluate()
  168. {
  169. GetValueInternal() = GetPoint()->GetValue().Y();
  170. }
  171. };
  172. class PointYFactory : public IFunction {
  173. private:
  174. public:
  175. TRef<IObject> Apply(ObjectStack& stack)
  176. {
  177. TRef<PointValue> ppoint = PointValue::Cast((IObject*)stack.Pop());
  178. return new PointY(ppoint);
  179. }
  180. };
  181. //////////////////////////////////////////////////////////////////////////////
  182. //
  183. //
  184. //
  185. //////////////////////////////////////////////////////////////////////////////
  186. class ImageSize : public PointValue {
  187. private:
  188. Image* GetImage() { return Image::Cast(GetChild(0)); }
  189. public:
  190. ImageSize(Image* pimage) :
  191. PointValue(pimage)
  192. {
  193. }
  194. void Evaluate()
  195. {
  196. GetValueInternal() = Point::Cast(GetImage()->GetBounds().GetRect().Size());
  197. }
  198. };
  199. class ImageSizeFactory : public IFunction {
  200. private:
  201. public:
  202. TRef<IObject> Apply(ObjectStack& stack)
  203. {
  204. TRef<Image> pimage = Image::Cast((Value*)(IObject*)stack.Pop());
  205. return new ImageSize(pimage);
  206. }
  207. };
  208. //////////////////////////////////////////////////////////////////////////////
  209. //
  210. //
  211. //
  212. //////////////////////////////////////////////////////////////////////////////
  213. class MDLFileImageFactory : public IFunction {
  214. private:
  215. TRef<Modeler> m_pmodeler;
  216. public:
  217. MDLFileImageFactory(Modeler* pmodeler) :
  218. m_pmodeler(pmodeler)
  219. {
  220. }
  221. TRef<IObject> Apply(ObjectStack& stack)
  222. {
  223. TRef<StringValue> pstring = StringValue::Cast((IObject*)stack.Pop());
  224. return (Value*)
  225. CreateMDLFileImage(
  226. m_pmodeler,
  227. pstring->GetValue()
  228. );
  229. }
  230. };
  231. //////////////////////////////////////////////////////////////////////////////
  232. //
  233. //
  234. //
  235. //////////////////////////////////////////////////////////////////////////////
  236. class StringImageFactory : public IFunction {
  237. private:
  238. public:
  239. TRef<IObject> Apply(ObjectStack& stack)
  240. {
  241. TRef<Number> pjustify = Number::Cast((IObject*)stack.Pop());
  242. TRef<Number> pwidth = Number::Cast((IObject*)stack.Pop());
  243. TRef<FontValue> pfont = FontValue::Cast((IObject*)stack.Pop());
  244. TRef<ColorValue> pcolor = ColorValue::Cast((IObject*)stack.Pop());
  245. TRef<StringValue> pstring = StringValue::Cast((IObject*)stack.Pop());
  246. Justification justification;
  247. justification.SetWord((DWORD)pjustify->GetValue());
  248. return (Value*)
  249. CreateStringImage(
  250. justification,
  251. pfont->GetValue(),
  252. pcolor,
  253. (int)pwidth->GetValue(),
  254. pstring
  255. );
  256. }
  257. };
  258. //////////////////////////////////////////////////////////////////////////////
  259. //
  260. //
  261. //
  262. //////////////////////////////////////////////////////////////////////////////
  263. class TextFileImageFactory : public IFunction {
  264. private:
  265. public:
  266. TRef<IObject> Apply(ObjectStack& stack)
  267. {
  268. TRef<Number> pjustify = Number::Cast((IObject*)stack.Pop());
  269. TRef<Number> pwidth = Number::Cast((IObject*)stack.Pop());
  270. TRef<FontValue> pfont = FontValue::Cast((IObject*)stack.Pop());
  271. TRef<ColorValue> pcolor = ColorValue::Cast((IObject*)stack.Pop());
  272. TRef<StringValue> pstring = StringValue::Cast((IObject*)stack.Pop());
  273. Justification justification;
  274. justification.SetWord((DWORD)pjustify->GetValue());
  275. TRef<ZFile> pfile = new ZFile(pstring->GetValue());
  276. ZString str;
  277. if (pfile->IsValid()) {
  278. str = ZString((PCC)pfile->GetPointer(), pfile->GetLength());
  279. } else {
  280. str = "Unable to open file " + pstring->GetValue();
  281. }
  282. //
  283. // remove all of the 0xd characters from the string
  284. //
  285. int index = 0;
  286. while (index < str.GetLength()) {
  287. if (str[index] == 0xd) {
  288. str = str.Left(index) + str.Right(str.GetLength() - index - 1);
  289. } else {
  290. index++;
  291. }
  292. }
  293. //
  294. //
  295. //
  296. return (Value*)
  297. CreateStringImage(
  298. justification,
  299. pfont->GetValue(),
  300. pcolor,
  301. (int)pwidth->GetValue(),
  302. new StringValue(str)
  303. );
  304. }
  305. };
  306. //////////////////////////////////////////////////////////////////////////////
  307. //
  308. //
  309. //
  310. //////////////////////////////////////////////////////////////////////////////
  311. class JustifyImageFactory : public IFunction {
  312. private:
  313. public:
  314. TRef<IObject> Apply(ObjectStack& stack)
  315. {
  316. TRef<Image> pimage = Image::Cast((Value*)(IObject*)stack.Pop());
  317. TRef<Number> pjustify = Number::Cast( (IObject*)stack.Pop());
  318. Justification justification;
  319. justification.SetWord((DWORD)pjustify->GetValue());
  320. return (Value*)
  321. CreateJustifyImage(
  322. pimage,
  323. justification
  324. );
  325. }
  326. };
  327. //////////////////////////////////////////////////////////////////////////////
  328. //
  329. //
  330. //
  331. //////////////////////////////////////////////////////////////////////////////
  332. class GaugeImageFactory : public IFunction {
  333. private:
  334. public:
  335. TRef<IObject> Apply(ObjectStack& stack)
  336. {
  337. TRef<Number> pjustify = Number::Cast((IObject*)stack.Pop());
  338. TRef<Image> pimage = Image::Cast((Value*)(IObject*)stack.Pop());
  339. TRef<Number> pnumber = Number::Cast((IObject*)stack.Pop());
  340. Justification justification;
  341. justification.SetWord((DWORD)pjustify->GetValue());
  342. return
  343. (Value*)CreateGaugeImage(
  344. justification,
  345. pimage,
  346. false,
  347. pnumber
  348. );
  349. }
  350. };
  351. //////////////////////////////////////////////////////////////////////////////
  352. //
  353. //
  354. //
  355. //////////////////////////////////////////////////////////////////////////////
  356. class GaugeImageRectFactory : public IFunction {
  357. private:
  358. public:
  359. TRef<IObject> Apply(ObjectStack& stack)
  360. {
  361. TRef<Number> pjustify = Number::Cast( (IObject*)stack.Pop());
  362. TRef<Image> pimage = Image::Cast((Value*)(IObject*)stack.Pop());
  363. TRef<RectValue> prect = RectValue::Cast( (IObject*)stack.Pop());
  364. TRef<Boolean> pbool = Boolean::Cast( (IObject*)stack.Pop());
  365. TRef<Number> pnumber = Number::Cast( (IObject*)stack.Pop());
  366. Justification justification;
  367. justification.SetWord((DWORD)pjustify->GetValue());
  368. return
  369. (Value*)CreateGaugeImage(
  370. justification,
  371. pimage,
  372. prect->GetValue(),
  373. pbool->GetValue(),
  374. pnumber
  375. );
  376. }
  377. };
  378. //////////////////////////////////////////////////////////////////////////////
  379. //
  380. //
  381. //
  382. //////////////////////////////////////////////////////////////////////////////
  383. class UndetectableImageFactory : public IFunction {
  384. private:
  385. public:
  386. TRef<IObject> Apply(ObjectStack& stack)
  387. {
  388. TRef<Image> pimage = Image::Cast((Value*)(IObject*)stack.Pop());
  389. return (Value*)CreateUndetectableImage(pimage);
  390. }
  391. };
  392. //////////////////////////////////////////////////////////////////////////////
  393. //
  394. //
  395. //
  396. //////////////////////////////////////////////////////////////////////////////
  397. class ClipImageFactory : public IFunction {
  398. private:
  399. public:
  400. TRef<IObject> Apply(ObjectStack& stack)
  401. {
  402. TRef<Image> pimage = Image::Cast((Value*)(IObject*)stack.Pop());
  403. TRef<RectValue> prect = RectValue::Cast( (IObject*)stack.Pop());
  404. return (Value*)CreateClipImage(pimage, prect);
  405. }
  406. };
  407. //////////////////////////////////////////////////////////////////////////////
  408. //
  409. //
  410. //
  411. //////////////////////////////////////////////////////////////////////////////
  412. class PickImageFactory : public IFunction {
  413. private:
  414. public:
  415. TRef<IObject> Apply(ObjectStack& stack)
  416. {
  417. TRef<Image> pimage = Image::Cast((Value*)(IObject*)stack.Pop());
  418. return (Value*)CreatePickImage(pimage);
  419. }
  420. };
  421. //////////////////////////////////////////////////////////////////////////////
  422. //
  423. //
  424. //
  425. //////////////////////////////////////////////////////////////////////////////
  426. class ColorImageFactory : public IFunction {
  427. private:
  428. public:
  429. TRef<IObject> Apply(ObjectStack& stack)
  430. {
  431. TRef<ColorValue> pcolor = ColorValue::Cast((IObject*)stack.Pop());
  432. return (Value*)CreateColorImage(pcolor);
  433. }
  434. };
  435. //////////////////////////////////////////////////////////////////////////////
  436. //
  437. //
  438. //
  439. //////////////////////////////////////////////////////////////////////////////
  440. class ExtentImageFactory : public IFunction {
  441. private:
  442. public:
  443. TRef<IObject> Apply(ObjectStack& stack)
  444. {
  445. TRef<RectValue> prect = RectValue::Cast((IObject*)stack.Pop());
  446. TRef<ColorValue> pcolor = ColorValue::Cast((IObject*)stack.Pop());
  447. return (Value*)CreateExtentImage(prect, pcolor);
  448. }
  449. };
  450. //////////////////////////////////////////////////////////////////////////////
  451. //
  452. //
  453. //
  454. //////////////////////////////////////////////////////////////////////////////
  455. /* !!! remove
  456. class EmptyImageFactory : public IFunction {
  457. private:
  458. public:
  459. TRef<IObject> Apply(ObjectStack& stack)
  460. {
  461. return (Value*)Image::GetEmpty();
  462. }
  463. };
  464. */
  465. //////////////////////////////////////////////////////////////////////////////
  466. //
  467. //
  468. //
  469. //////////////////////////////////////////////////////////////////////////////
  470. class ImportXFileFactory : public IFunction {
  471. private:
  472. TRef<Modeler> m_pmodeler;
  473. public:
  474. ImportXFileFactory(Modeler* pmodeler) :
  475. m_pmodeler(pmodeler)
  476. {
  477. }
  478. TRef<IObject> Apply(ObjectStack& stack)
  479. {
  480. ZString str = GetString((IObject*)stack.Pop());
  481. TRef<Number> pnumber = Number::Cast((IObject*)stack.Pop());
  482. bool bAnimation;
  483. TRef<IObject> pobject = m_pmodeler->LoadXFile(str, pnumber, bAnimation);
  484. ZAssert(pobject != NULL);
  485. return pobject;
  486. }
  487. };
  488. //////////////////////////////////////////////////////////////////////////////
  489. //
  490. //
  491. //
  492. //////////////////////////////////////////////////////////////////////////////
  493. class ImportMDLFactory : public IFunction {
  494. private:
  495. TRef<Modeler> m_pmodeler;
  496. public:
  497. ImportMDLFactory(Modeler* pmodeler) :
  498. m_pmodeler(pmodeler)
  499. {
  500. }
  501. TRef<IObject> Apply(ObjectStack& stack)
  502. {
  503. ZString str = GetString((IObject*)stack.Pop());
  504. TRef<INameSpace> pns = m_pmodeler->GetNameSpace(str);
  505. if (pns) {
  506. return pns->FindMember("object");
  507. }
  508. return NULL;
  509. }
  510. };
  511. //////////////////////////////////////////////////////////////////////////////
  512. //
  513. //
  514. //
  515. //////////////////////////////////////////////////////////////////////////////
  516. class ImportImageFactory : public IFunction {
  517. private:
  518. TRef<Modeler> m_pmodeler;
  519. TRef<PrivateEngine> m_pengine;
  520. public:
  521. ImportImageFactory(Modeler* pmodeler) :
  522. m_pmodeler(pmodeler)
  523. {
  524. CastTo(m_pengine, m_pmodeler->GetEngine());
  525. }
  526. TRef<IObject> Apply(ObjectStack& stack)
  527. {
  528. ZString str = GetString((IObject*)stack.Pop());
  529. bool b = GetBoolean((IObject*)stack.Pop());
  530. TRef<Image> pimage = m_pmodeler->LoadImage(str, b);
  531. ZAssert(pimage != NULL);
  532. return (Value*)pimage;
  533. }
  534. TRef<IObject> Read(IBinaryReaderSite* psite, ObjectStack& stack)
  535. {
  536. #ifdef DREAMCAST
  537. BinarySurfaceInfo bsi;
  538. BinarySurfaceInfo* pbsi = &bsi; psite->CopyStructure(pbsi);
  539. #else
  540. BinarySurfaceInfo* pbsi; psite->GetStructure(pbsi);
  541. #endif
  542. PixelFormat* ppf =
  543. m_pengine->GetPixelFormat(
  544. pbsi->m_bitCount,
  545. pbsi->m_redMask,
  546. pbsi->m_greenMask,
  547. pbsi->m_blueMask,
  548. pbsi->m_alphaMask
  549. );
  550. BYTE* pdata = psite->GetPointer();
  551. psite->MovePointer(pbsi->m_pitch * pbsi->m_size.Y());
  552. TRef<Surface> psurface =
  553. m_pengine->CreateSurface(
  554. pbsi->m_size,
  555. ppf,
  556. NULL,
  557. pbsi->m_pitch,
  558. pdata,
  559. psite->GetMemoryObject()
  560. );
  561. if (pbsi->m_bColorKey) {
  562. psurface->SetColorKey(Color(0, 0, 0));
  563. }
  564. return (Value*)new ConstantImage(psurface, ZString());
  565. }
  566. };
  567. //////////////////////////////////////////////////////////////////////////////
  568. //
  569. //
  570. //
  571. //////////////////////////////////////////////////////////////////////////////
  572. class ImportFontFactory : public IFunction {
  573. private:
  574. TRef<Modeler> m_pmodeler;
  575. TRef<PrivateEngine> m_pengine;
  576. public:
  577. ImportFontFactory(Modeler* pmodeler) :
  578. m_pmodeler(pmodeler)
  579. {
  580. CastTo(m_pengine, m_pmodeler->GetEngine());
  581. }
  582. TRef<IObject> Apply(ObjectStack& stack)
  583. {
  584. ZUnimplemented();
  585. return NULL;
  586. }
  587. TRef<IObject> Read(IBinaryReaderSite* psite, ObjectStack& stack)
  588. {
  589. return
  590. new FontValue(
  591. CreateEngineFont(psite)
  592. );
  593. }
  594. };
  595. //////////////////////////////////////////////////////////////////////////////
  596. //
  597. //
  598. //
  599. //////////////////////////////////////////////////////////////////////////////
  600. class ImportImageLRFactory : public IFunction {
  601. private:
  602. TRef<Modeler> m_pmodeler;
  603. TRef<PrivateEngine> m_pengine;
  604. public:
  605. ImportImageLRFactory(Modeler* pmodeler) :
  606. m_pmodeler(pmodeler)
  607. {
  608. CastTo(m_pengine, m_pmodeler->GetEngine());
  609. }
  610. TRef<IObject> Apply(ObjectStack& stack)
  611. {
  612. ZString str = GetString((IObject*)stack.Pop());
  613. bool b = GetBoolean((IObject*)stack.Pop());
  614. TRef<Image> pimage = m_pmodeler->LoadImage(str, b);
  615. const Bounds2& bounds = pimage->GetBounds();
  616. return
  617. (Value*)new TranslateImage(
  618. pimage,
  619. Point(
  620. 0,
  621. -bounds.GetRect().YSize()
  622. )
  623. );
  624. }
  625. };
  626. //////////////////////////////////////////////////////////////////////////////
  627. //
  628. //
  629. //
  630. //////////////////////////////////////////////////////////////////////////////
  631. class ImportImage3DFactory : public IFunction {
  632. private:
  633. TRef<Modeler> m_pmodeler;
  634. TRef<PrivateEngine> m_pengine;
  635. public:
  636. ImportImage3DFactory(Modeler* pmodeler) :
  637. m_pmodeler(pmodeler)
  638. {
  639. CastTo(m_pengine, m_pmodeler->GetEngine());
  640. }
  641. TRef<IObject> Apply(ObjectStack& stack)
  642. {
  643. ZString str = GetString((IObject*)stack.Pop());
  644. TRef<ColorValue> pcolor = ColorValue::Cast( (IObject*)stack.Pop());
  645. bool b = GetBoolean((IObject*)stack.Pop());
  646. TRef<Surface> psurface = m_pmodeler->LoadSurface(str, b);
  647. return (Value*)CreateConstantImage3D(psurface, pcolor);
  648. }
  649. };
  650. //////////////////////////////////////////////////////////////////////////////
  651. //
  652. //
  653. //
  654. //////////////////////////////////////////////////////////////////////////////
  655. class BlendImageFactory : public IFunction {
  656. private:
  657. public:
  658. TRef<IObject> Apply(ObjectStack& stack)
  659. {
  660. TRef<Image> pimage = Image::Cast((Value*)(IObject*)stack.Pop());
  661. TRef<Number> pnumberBlend = Number::Cast( (IObject*)stack.Pop());
  662. return
  663. (Value*)CreateBlendImage(
  664. pimage,
  665. (BlendMode)(int)pnumberBlend->GetValue()
  666. );
  667. }
  668. };
  669. //////////////////////////////////////////////////////////////////////////////
  670. //
  671. //
  672. //
  673. //////////////////////////////////////////////////////////////////////////////
  674. class TranslateImageFactory : public IFunction {
  675. public:
  676. TRef<IObject> Apply(ObjectStack& stack)
  677. {
  678. TRef<Image> pimage = Image::Cast((Value*)(IObject*)stack.Pop());
  679. TRef<PointValue> ppoint = PointValue::Cast( (IObject*)stack.Pop());
  680. return
  681. (Value*)new TransformImage(
  682. pimage,
  683. new TranslateTransform2(ppoint)
  684. );
  685. }
  686. };
  687. //////////////////////////////////////////////////////////////////////////////
  688. //
  689. //
  690. //
  691. //////////////////////////////////////////////////////////////////////////////
  692. class VisibleImageFactory : public IFunction {
  693. public:
  694. TRef<IObject> Apply(ObjectStack& stack)
  695. {
  696. TRef<Image> pimage = Image::Cast((Value*)(IObject*)stack.Pop());
  697. TRef<Boolean> pbool; CastTo(pbool, (Value*)(IObject*)stack.Pop());
  698. return (Value*)CreateVisibleImage(pimage, pbool);
  699. }
  700. };
  701. //////////////////////////////////////////////////////////////////////////////
  702. //
  703. //
  704. //
  705. //////////////////////////////////////////////////////////////////////////////
  706. class ScaleImageFactory : public IFunction {
  707. public:
  708. TRef<IObject> Apply(ObjectStack& stack)
  709. {
  710. TRef<Image> pimage = Image::Cast((Value*)(IObject*)stack.Pop());
  711. TRef<PointValue> ppoint = PointValue::Cast( (IObject*)stack.Pop());
  712. return
  713. (Value*)new TransformImage(
  714. pimage,
  715. new ScaleTransform2(ppoint)
  716. );
  717. }
  718. };
  719. //////////////////////////////////////////////////////////////////////////////
  720. //
  721. //
  722. //
  723. //////////////////////////////////////////////////////////////////////////////
  724. class RotateImageFactory : public IFunction {
  725. public:
  726. TRef<IObject> Apply(ObjectStack& stack)
  727. {
  728. TRef<Image> pimage = Image::Cast((Value*)(IObject*)stack.Pop());
  729. TRef<Number> pangle = Number::Cast( (IObject*)stack.Pop());
  730. return
  731. (Value*)new TransformImage(
  732. pimage,
  733. new RotateTransform2(pangle)
  734. );
  735. }
  736. };
  737. //////////////////////////////////////////////////////////////////////////////
  738. //
  739. //
  740. //
  741. //////////////////////////////////////////////////////////////////////////////
  742. class GeoImageFactory : public IFunction {
  743. public:
  744. TRef<IObject> Apply(ObjectStack& stack)
  745. {
  746. TRef<Geo> pgeo = Geo::Cast((Value*)(IObject*)stack.Pop());
  747. TRef<RectValue> prect = RectValue::Cast( (IObject*)stack.Pop());
  748. TRef<Camera> pcamera = Camera::Cast( (IObject*)stack.Pop());
  749. TRef<Boolean> pbooleanZBuffer = Boolean::Cast( (IObject*)stack.Pop());
  750. TRef<Viewport> pviewport = new Viewport(pcamera, prect);
  751. return
  752. (Value*)new GeoImage(
  753. pgeo,
  754. pviewport,
  755. pbooleanZBuffer->GetValue()
  756. );
  757. }
  758. };
  759. //////////////////////////////////////////////////////////////////////////////
  760. //
  761. //
  762. //
  763. //////////////////////////////////////////////////////////////////////////////
  764. class GeoImage2DFactory : public IFunction {
  765. public:
  766. TRef<IObject> Apply(ObjectStack& stack)
  767. {
  768. TRef<Geo> pgeo =Geo::Cast((Value*)(IObject*)stack.Pop());
  769. return (Value*)CreateGeoImage2D(pgeo);
  770. }
  771. };
  772. //////////////////////////////////////////////////////////////////////////////
  773. //
  774. //
  775. //
  776. //////////////////////////////////////////////////////////////////////////////
  777. class ModifiableNumberFactory : public IFunction {
  778. private:
  779. public:
  780. TRef<IObject> Apply(ObjectStack& stack)
  781. {
  782. float value = GetNumber((IObject*)stack.Pop());
  783. return new ModifiableNumber(value);
  784. }
  785. };
  786. //////////////////////////////////////////////////////////////////////////////
  787. //
  788. //
  789. //
  790. //////////////////////////////////////////////////////////////////////////////
  791. class WrapNumberFactory : public IFunction {
  792. private:
  793. public:
  794. TRef<IObject> Apply(ObjectStack& stack)
  795. {
  796. TRef<Number> pnumber = Number::Cast((IObject*)stack.Pop());
  797. return new WrapNumber(pnumber);
  798. }
  799. };
  800. //////////////////////////////////////////////////////////////////////////////
  801. //
  802. //
  803. //
  804. //////////////////////////////////////////////////////////////////////////////
  805. typedef TRef<IObject> TRefIObject; //hack for VC5
  806. template<class StaticType, class ValueType>
  807. class TIFunctionBinary : public IFunction {
  808. public:
  809. TRefIObject Read(IBinaryReaderSite* psite, ObjectStack& stack)
  810. {
  811. #ifdef DREAMCAST
  812. StaticType value;
  813. StaticType* pvalue = &value; psite->CopyStructure(pvalue);
  814. #else
  815. StaticType* pvalue = (StaticType*)psite->GetPointer();
  816. psite->MovePointer(sizeof(StaticType));
  817. #endif
  818. return new ValueType(*pvalue);
  819. }
  820. };
  821. //////////////////////////////////////////////////////////////////////////////
  822. //
  823. //
  824. //
  825. //////////////////////////////////////////////////////////////////////////////
  826. class RGBColorFactory : public TIFunctionBinary<Color, ColorValue > {
  827. private:
  828. public:
  829. TRef<IObject> Apply(ObjectStack& stack)
  830. {
  831. float r = GetNumber((IObject*)stack.Pop());
  832. float g = GetNumber((IObject*)stack.Pop());
  833. float b = GetNumber((IObject*)stack.Pop());
  834. return new ColorValue(Color(r, g, b));
  835. }
  836. };
  837. //////////////////////////////////////////////////////////////////////////////
  838. //
  839. //
  840. //
  841. //////////////////////////////////////////////////////////////////////////////
  842. class RGBAColorFactory : public TIFunctionBinary<Color, ColorValue > {
  843. private:
  844. public:
  845. TRef<IObject> Apply(ObjectStack& stack)
  846. {
  847. float r = GetNumber((IObject*)stack.Pop());
  848. float g = GetNumber((IObject*)stack.Pop());
  849. float b = GetNumber((IObject*)stack.Pop());
  850. float a = GetNumber((IObject*)stack.Pop());
  851. return new ColorValue(Color(r, g, b, a));
  852. }
  853. };
  854. //////////////////////////////////////////////////////////////////////////////
  855. //
  856. //
  857. //
  858. //////////////////////////////////////////////////////////////////////////////
  859. class VectorFactory : public TIFunctionBinary<Vector, VectorValue > {
  860. private:
  861. public:
  862. TRef<IObject> Apply(ObjectStack& stack)
  863. {
  864. float x = GetNumber((IObject*)stack.Pop());
  865. float y = GetNumber((IObject*)stack.Pop());
  866. float z = GetNumber((IObject*)stack.Pop());
  867. return new VectorValue(Vector(x, y, z));
  868. }
  869. };
  870. //////////////////////////////////////////////////////////////////////////////
  871. //
  872. //
  873. //
  874. //////////////////////////////////////////////////////////////////////////////
  875. class PointFactory : public TIFunctionBinary<Point, PointValue > {
  876. private:
  877. public:
  878. TRef<IObject> Apply(ObjectStack& stack)
  879. {
  880. float x = GetNumber((IObject*)stack.Pop());
  881. float y = GetNumber((IObject*)stack.Pop());
  882. return new PointValue(Point(x, y));
  883. }
  884. };
  885. class PointV : public PointValue {
  886. public:
  887. PointV(Number* px, Number* py) :
  888. PointValue(px, py)
  889. {
  890. }
  891. Number* Get0() { return Number::Cast(GetChild(0)); }
  892. Number* Get1() { return Number::Cast(GetChild(1)); }
  893. void Evaluate()
  894. {
  895. GetValueInternal() =
  896. Point(
  897. Get0()->GetValue(),
  898. Get1()->GetValue()
  899. );
  900. }
  901. };
  902. class PointVFactory : public TIFunctionBinary<Point, PointValue > {
  903. public:
  904. TRef<IObject> Apply(ObjectStack& stack)
  905. {
  906. Number* px; CastTo(px, (IObject*)stack.Pop());
  907. Number* py; CastTo(py, (IObject*)stack.Pop());
  908. return new PointV(px, py);
  909. }
  910. };
  911. //////////////////////////////////////////////////////////////////////////////
  912. //
  913. //
  914. //
  915. //////////////////////////////////////////////////////////////////////////////
  916. class RectFactory : public TIFunctionBinary<Rect, RectValue > {
  917. private:
  918. public:
  919. TRef<IObject> Apply(ObjectStack& stack)
  920. {
  921. float xmin = GetNumber((IObject*)stack.Pop());
  922. float ymin = GetNumber((IObject*)stack.Pop());
  923. float xmax = GetNumber((IObject*)stack.Pop());
  924. float ymax = GetNumber((IObject*)stack.Pop());
  925. return new RectValue(Rect(xmin, ymin, xmax, ymax));
  926. }
  927. };
  928. //////////////////////////////////////////////////////////////////////////////
  929. //
  930. //
  931. //
  932. //////////////////////////////////////////////////////////////////////////////
  933. class MatrixTransformFactory : public TIFunctionBinary<Matrix, Transform> {
  934. private:
  935. public:
  936. TRef<IObject> Apply(ObjectStack& stack)
  937. {
  938. float m00 = GetNumber((IObject*)stack.Pop());
  939. float m01 = GetNumber((IObject*)stack.Pop());
  940. float m02 = GetNumber((IObject*)stack.Pop());
  941. float m03 = GetNumber((IObject*)stack.Pop());
  942. float m10 = GetNumber((IObject*)stack.Pop());
  943. float m11 = GetNumber((IObject*)stack.Pop());
  944. float m12 = GetNumber((IObject*)stack.Pop());
  945. float m13 = GetNumber((IObject*)stack.Pop());
  946. float m20 = GetNumber((IObject*)stack.Pop());
  947. float m21 = GetNumber((IObject*)stack.Pop());
  948. float m22 = GetNumber((IObject*)stack.Pop());
  949. float m23 = GetNumber((IObject*)stack.Pop());
  950. float m30 = GetNumber((IObject*)stack.Pop());
  951. float m31 = GetNumber((IObject*)stack.Pop());
  952. float m32 = GetNumber((IObject*)stack.Pop());
  953. float m33 = GetNumber((IObject*)stack.Pop());
  954. return
  955. new Transform(
  956. Matrix(
  957. m00, m01, m02, m03,
  958. m10, m11, m12, m13,
  959. m20, m21, m22, m23,
  960. m30, m31, m32, m33
  961. )
  962. );
  963. }
  964. };
  965. //////////////////////////////////////////////////////////////////////////////
  966. //
  967. //
  968. //
  969. //////////////////////////////////////////////////////////////////////////////
  970. class MaterialFactory : public IFunction {
  971. public:
  972. TRef<IObject> Apply(ObjectStack& stack)
  973. {
  974. TRef<ColorValue> pcolorDiffuse = ColorValue::Cast((IObject*)stack.Pop());
  975. TRef<ColorValue> pcolorSpecular = ColorValue::Cast((IObject*)stack.Pop());
  976. TRef<ColorValue> pcolorEmissive = ColorValue::Cast((IObject*)stack.Pop());
  977. TRef<Number> ppower = Number::Cast((IObject*)stack.Pop());
  978. return
  979. CreateMaterial(
  980. pcolorDiffuse,
  981. pcolorSpecular,
  982. pcolorEmissive,
  983. ppower
  984. );
  985. }
  986. };
  987. //////////////////////////////////////////////////////////////////////////////
  988. //
  989. //
  990. //
  991. //////////////////////////////////////////////////////////////////////////////
  992. class TransformGeoFactory : public IFunction {
  993. private:
  994. public:
  995. TRef<IObject> Apply(ObjectStack& stack)
  996. {
  997. TRef<Geo> pgeo = Geo::Cast((IObject*)stack.Pop());
  998. TRef<Transform> ptrans = Transform::Cast((IObject*)stack.Pop());
  999. return new TransformGeo(pgeo, ptrans);
  1000. }
  1001. };
  1002. //////////////////////////////////////////////////////////////////////////////
  1003. //
  1004. //
  1005. //
  1006. //////////////////////////////////////////////////////////////////////////////
  1007. class TextureGeoFactory : public IFunction {
  1008. private:
  1009. public:
  1010. TRef<IObject> Apply(ObjectStack& stack)
  1011. {
  1012. TRef<Geo> pgeo = Geo::Cast((IObject*)stack.Pop());
  1013. TRef<Image> pimage = Image::Cast((Value*)(IObject*)stack.Pop());
  1014. return new TextureGeo(pgeo, pimage);
  1015. }
  1016. };
  1017. //////////////////////////////////////////////////////////////////////////////
  1018. //
  1019. //
  1020. //
  1021. //////////////////////////////////////////////////////////////////////////////
  1022. class BlendGeoFactory : public IFunction {
  1023. private:
  1024. public:
  1025. TRef<IObject> Apply(ObjectStack& stack)
  1026. {
  1027. TRef<Geo> pgeo = Geo::Cast((IObject*)stack.Pop());
  1028. TRef<Number> pnumberBlend = Number::Cast((IObject*)stack.Pop());
  1029. return
  1030. CreateBlendGeo(
  1031. pgeo,
  1032. (BlendMode)(int)pnumberBlend->GetValue()
  1033. );
  1034. }
  1035. };
  1036. //////////////////////////////////////////////////////////////////////////////
  1037. //
  1038. //
  1039. //
  1040. //////////////////////////////////////////////////////////////////////////////
  1041. class MaterialGeoFactory : public IFunction {
  1042. private:
  1043. public:
  1044. TRef<IObject> Apply(ObjectStack& stack)
  1045. {
  1046. TRef<Geo> pgeo = Geo::Cast((IObject*)stack.Pop());
  1047. TRef<Material> pmaterial = Material::Cast((IObject*)stack.Pop());
  1048. return new MaterialGeo(pgeo, pmaterial);
  1049. }
  1050. };
  1051. //////////////////////////////////////////////////////////////////////////////
  1052. //
  1053. // Switch Value
  1054. //
  1055. //////////////////////////////////////////////////////////////////////////////
  1056. template<class StaticType>
  1057. class TSwitchValue : public TStaticValue<StaticType> {
  1058. protected:
  1059. //////////////////////////////////////////////////////////////////////////////
  1060. //
  1061. // Types
  1062. //
  1063. //////////////////////////////////////////////////////////////////////////////
  1064. typedef TStaticValue<StaticType> ValueType;
  1065. class Data {
  1066. public:
  1067. float m_number;
  1068. TRef<ValueType> m_pvalue;
  1069. };
  1070. typedef TList<Data, DefaultNoEquals> DataList;
  1071. //////////////////////////////////////////////////////////////////////////////
  1072. //
  1073. // Members
  1074. //
  1075. //////////////////////////////////////////////////////////////////////////////
  1076. DataList m_list;
  1077. TRef<ValueType> m_pdefault;
  1078. float m_number;
  1079. TStaticValue<StaticType>* GetWrappedValue() { return TStaticValue<StaticType>::Cast(GetChild(0)); }
  1080. public:
  1081. //////////////////////////////////////////////////////////////////////////////
  1082. //
  1083. // Methods
  1084. //
  1085. //////////////////////////////////////////////////////////////////////////////
  1086. TSwitchValue(ValueType* pdefault, Number* pnumber) :
  1087. TStaticValue<StaticType>(pdefault, pnumber),
  1088. m_pdefault(pdefault),
  1089. m_number(pnumber->GetValue())
  1090. {
  1091. }
  1092. Number* GetNumber() { return Number::Cast(GetChild(1)); }
  1093. //////////////////////////////////////////////////////////////////////////////
  1094. //
  1095. // SwitchImage Methods
  1096. //
  1097. //////////////////////////////////////////////////////////////////////////////
  1098. void AddValue(float number, ValueType* pvalue)
  1099. {
  1100. m_list.PushFront();
  1101. m_list.GetFront().m_number = number;
  1102. m_list.GetFront().m_pvalue = pvalue;
  1103. if (m_number == number) {
  1104. pvalue->Update();
  1105. SetChild(0, pvalue);
  1106. }
  1107. }
  1108. //////////////////////////////////////////////////////////////////////////////
  1109. //
  1110. // Value Methods
  1111. //
  1112. //////////////////////////////////////////////////////////////////////////////
  1113. void Evaluate()
  1114. {
  1115. float number = GetNumber()->GetValue();
  1116. if (m_number != number) {
  1117. m_number = number;
  1118. DataList::Iterator iter(m_list);
  1119. while (true) {
  1120. if (iter.End()) {
  1121. m_pdefault->Update();
  1122. SetChild(0, m_pdefault);
  1123. break;
  1124. }
  1125. const Data& data = iter.Value();
  1126. if (data.m_number == number) {
  1127. data.m_pvalue->Update();
  1128. SetChild(0, data.m_pvalue);
  1129. break;
  1130. }
  1131. iter.Next();
  1132. }
  1133. }
  1134. GetValueInternal() = GetWrappedValue()->GetValue();
  1135. }
  1136. };
  1137. //////////////////////////////////////////////////////////////////////////////
  1138. //
  1139. // Switch Value Factory
  1140. //
  1141. //////////////////////////////////////////////////////////////////////////////
  1142. template<class StaticType>
  1143. class TSwitchFactory : public IFunction {
  1144. private:
  1145. typedef TStaticValue<StaticType> ValueType;
  1146. typedef TSwitchValue<StaticType> SwitchType;
  1147. public:
  1148. TRef<IObject> Apply(ObjectStack& stack)
  1149. {
  1150. TRef<Number> pnumber; CastTo(pnumber, (IObject*)stack.Pop());
  1151. TRef<ValueType> pvalue; CastTo(pvalue, (Value*)(IObject*)stack.Pop());
  1152. TRef<IObjectList> plist; CastTo(plist, (IObject*)stack.Pop());
  1153. TRef<SwitchType> pswitch = new SwitchType(pvalue, pnumber);
  1154. IObjectPair* ppair; CastTo(ppair, plist->GetFirst());
  1155. while (ppair) {
  1156. TRef<Number> pnumber; CastTo(pnumber, ppair->GetFirst() );
  1157. TRef<ValueType> pimage; CastTo(pvalue, ppair->GetSecond());
  1158. pswitch->AddValue(
  1159. pnumber->GetValue(),
  1160. pvalue
  1161. );
  1162. CastTo(ppair, plist->GetNext());
  1163. }
  1164. return (Value*)pswitch;
  1165. }
  1166. };
  1167. //////////////////////////////////////////////////////////////////////////////
  1168. //
  1169. //
  1170. //
  1171. //////////////////////////////////////////////////////////////////////////////
  1172. class SwitchImageFactory : public IFunction {
  1173. private:
  1174. public:
  1175. TRef<IObject> Apply(ObjectStack& stack)
  1176. {
  1177. TRef<Number> pnumber; CastTo(pnumber, (IObject*)stack.Pop());
  1178. TRef<Image> pimage; CastTo(pimage, (Value*)(IObject*)stack.Pop());
  1179. TRef<IObjectList> plist; CastTo(plist, (IObject*)stack.Pop());
  1180. TRef<SwitchImage> pswitch = CreateSwitchImage(pnumber, pimage);
  1181. IObjectPair* ppair; CastTo(ppair, plist->GetFirst());
  1182. while (ppair) {
  1183. float number = GetNumber( ppair->GetFirst());
  1184. TRef<Image> pimage = Image::Cast((Value*)ppair->GetSecond());
  1185. pswitch->AddImage(number, pimage);
  1186. CastTo(ppair, plist->GetNext());
  1187. }
  1188. return (Value*)pswitch;
  1189. }
  1190. };
  1191. //////////////////////////////////////////////////////////////////////////////
  1192. //
  1193. //
  1194. //
  1195. //////////////////////////////////////////////////////////////////////////////
  1196. class GroupImageFactory : public IFunction {
  1197. private:
  1198. public:
  1199. TRef<IObject> Apply(ObjectStack& stack)
  1200. {
  1201. TRef<GroupImage> pgroup = new GroupImage();
  1202. TRef<IObjectList> plist; CastTo(plist, (IObject*)stack.Pop());
  1203. plist->GetFirst();
  1204. while (plist->GetCurrent() != NULL) {
  1205. pgroup->AddImage(Image::Cast((Value*)plist->GetCurrent()));
  1206. plist->GetNext();
  1207. }
  1208. return (Value*)pgroup;
  1209. }
  1210. };
  1211. //////////////////////////////////////////////////////////////////////////////
  1212. //
  1213. //
  1214. //
  1215. //////////////////////////////////////////////////////////////////////////////
  1216. class GroupGeoFactory : public IFunction {
  1217. private:
  1218. public:
  1219. TRef<IObject> Apply(ObjectStack& stack)
  1220. {
  1221. TRef<GroupGeo> pgroup = GroupGeo::Create();
  1222. TRef<IObjectList> plist; CastTo(plist, (IObject*)stack.Pop());
  1223. plist->GetFirst();
  1224. while (plist->GetCurrent() != NULL) {
  1225. pgroup->AddGeo(Geo::Cast(plist->GetCurrent()));
  1226. plist->GetNext();
  1227. }
  1228. return pgroup;
  1229. }
  1230. };
  1231. //////////////////////////////////////////////////////////////////////////////
  1232. //
  1233. //
  1234. //
  1235. //////////////////////////////////////////////////////////////////////////////
  1236. class MeshGeoFactory : public IFunction {
  1237. private:
  1238. public:
  1239. TRef<IObject> Apply(ObjectStack& stack)
  1240. {
  1241. TRef<IObjectList> plistVertices; CastTo(plistVertices, (IObject*)stack.Pop());
  1242. TRef<IObjectList> plistIndices; CastTo(plistIndices, (IObject*)stack.Pop() );
  1243. TVector<Vertex> vertices;
  1244. TVector<WORD> indices;
  1245. plistVertices->GetFirst();
  1246. while (plistVertices->GetCurrent() != NULL) {
  1247. float x = GetNumber(plistVertices->GetCurrent());
  1248. float y = GetNumber(plistVertices->GetNext());
  1249. float z = GetNumber(plistVertices->GetNext());
  1250. float nx = GetNumber(plistVertices->GetNext());
  1251. float ny = GetNumber(plistVertices->GetNext());
  1252. float nz = GetNumber(plistVertices->GetNext());
  1253. float tx = GetNumber(plistVertices->GetNext());
  1254. float ty = GetNumber(plistVertices->GetNext());
  1255. vertices.PushEnd(Vertex(x, y, z, nx, ny, nz, tx,ty));
  1256. plistVertices->GetNext();
  1257. }
  1258. plistIndices->GetFirst();
  1259. while (plistIndices->GetCurrent() != NULL) {
  1260. indices.PushEnd((WORD)GetNumber(plistIndices->GetCurrent()));
  1261. plistIndices->GetNext();
  1262. }
  1263. return Geo::CreateMesh(vertices, indices);
  1264. }
  1265. #ifdef DREAMCAST
  1266. #if 0
  1267. class MeshDataCopy : public IObject
  1268. {
  1269. public:
  1270. MeshDataCopy(Vertex* pvertex, DWORD countVertices, WORD* pindex, DWORD countIndices)
  1271. {
  1272. Vertex* pvertexCopy = (Vertex*)malloc(countVertices * sizeof(Vertex));
  1273. memcpy(pvertexCopy, pvertex, countVertices * sizeof(Vertex));
  1274. m_pvertex = new D3DVertex[countVertices];
  1275. for (int i = 0; i < countVertices; i++)
  1276. {
  1277. m_pvertex[i].SetPosition(pvertexCopy[i].GetPosition());
  1278. m_pvertex[i].SetTextureCoordinate(pvertexCopy[i].GetTextureCoordinate());
  1279. m_pvertex[i].SetNormal(pvertexCopy[i].GetNormal());
  1280. }
  1281. free(pvertexCopy);
  1282. m_pindex = (WORD*)malloc(countIndices * sizeof(WORD));
  1283. memcpy(m_pindex, pindex, countIndices * sizeof(WORD));
  1284. }
  1285. ~MeshDataCopy()
  1286. {
  1287. delete m_pvertex;
  1288. free(m_pindex);
  1289. }
  1290. D3DVertex* m_pvertex;
  1291. WORD* m_pindex;
  1292. };
  1293. TRef<IObject> Read(IBinaryReaderSite* psite, ObjectStack& stack)
  1294. {
  1295. DWORD countVertices = psite->GetDWORD();
  1296. DWORD countIndices = psite->GetDWORD();
  1297. Vertex* pvertex = (Vertex*)psite->GetPointer();
  1298. psite->MovePointer(countVertices * sizeof(Vertex));
  1299. WORD* pindex = (WORD*)psite->GetPointer();
  1300. psite->MovePointer(countIndices * sizeof(WORD));
  1301. TRef<MeshDataCopy> pdata = new MeshDataCopy(pvertex, countVertices, pindex, countIndices);
  1302. return
  1303. Geo::CreateMesh(
  1304. pdata->m_pvertex,
  1305. countVertices,
  1306. pdata->m_pindex,
  1307. countIndices,
  1308. pdata
  1309. );
  1310. }
  1311. #endif
  1312. #if 1
  1313. class MeshDataCopy : public IObject
  1314. {
  1315. public:
  1316. MeshDataCopy(Vertex* pvertex, DWORD countVertices, WORD* pindex,
  1317. DWORD countIndices)
  1318. {
  1319. m_pvertex = (Vertex*)malloc(countVertices * sizeof(Vertex));
  1320. memcpy(m_pvertex, pvertex, countVertices * sizeof(Vertex));
  1321. m_pindex = (WORD*)malloc(countIndices * sizeof(WORD));
  1322. memcpy(m_pindex, pindex, countIndices * sizeof(WORD));
  1323. }
  1324. ~MeshDataCopy()
  1325. {
  1326. free(m_pvertex);
  1327. free(m_pindex);
  1328. }
  1329. Vertex* m_pvertex;
  1330. WORD* m_pindex;
  1331. };
  1332. TRef<IObject> Read(IBinaryReaderSite* psite, ObjectStack& stack)
  1333. {
  1334. DWORD countVertices = psite->GetDWORD();
  1335. DWORD countIndices = psite->GetDWORD();
  1336. Vertex* pvertex = (Vertex*)psite->GetPointer();
  1337. psite->MovePointer(countVertices * sizeof(Vertex));
  1338. WORD* pindex = (WORD*)psite->GetPointer();
  1339. psite->MovePointer(countIndices * sizeof(WORD));
  1340. TRef<MeshDataCopy> pdata = new MeshDataCopy(pvertex, countVertices,
  1341. pindex, countIndices);
  1342. return
  1343. Geo::CreateMesh(
  1344. pdata->m_pvertex,
  1345. countVertices,
  1346. pdata->m_pindex,
  1347. countIndices,
  1348. pdata
  1349. );
  1350. }
  1351. #endif
  1352. #else
  1353. TRef<IObject> Read(IBinaryReaderSite* psite, ObjectStack& stack)
  1354. {
  1355. DWORD countVertices = psite->GetDWORD();
  1356. DWORD countIndices = psite->GetDWORD();
  1357. Vertex* pvertex = (Vertex*)psite->GetPointer();
  1358. psite->MovePointer(countVertices * sizeof(Vertex));
  1359. WORD* pindex = (WORD*)psite->GetPointer();
  1360. psite->MovePointer(countIndices * sizeof(WORD));
  1361. return
  1362. Geo::CreateMesh(
  1363. pvertex,
  1364. countVertices,
  1365. pindex,
  1366. countIndices,
  1367. psite->GetMemoryObject()
  1368. );
  1369. }
  1370. #endif
  1371. };
  1372. //////////////////////////////////////////////////////////////////////////////
  1373. //
  1374. //
  1375. //
  1376. //////////////////////////////////////////////////////////////////////////////
  1377. class LODGeoFactory : public IFunction {
  1378. private:
  1379. public:
  1380. TRef<IObject> Apply(ObjectStack& stack)
  1381. {
  1382. TRef<Geo> pgeo; CastTo(pgeo, (IObject*)stack.Pop());
  1383. TRef<IObjectList> plistLOD; CastTo(plistLOD, (IObject*)stack.Pop());
  1384. TRef<LODGeo> plodGeo = LODGeo::Create(pgeo);
  1385. IObjectPair* ppair; CastTo(ppair, plistLOD->GetFirst());
  1386. while (ppair) {
  1387. float pixels = GetNumber(ppair->GetFirst());
  1388. TRef<Geo> pgeoLOD = Geo::Cast(ppair->GetSecond());
  1389. plodGeo->AddGeo(pgeoLOD, pixels);
  1390. CastTo(ppair, plistLOD->GetNext());
  1391. }
  1392. return plodGeo;
  1393. }
  1394. };
  1395. //////////////////////////////////////////////////////////////////////////////
  1396. //
  1397. //
  1398. //
  1399. //////////////////////////////////////////////////////////////////////////////
  1400. class KeyFramedTranslateFactory : public IFunction {
  1401. private:
  1402. public:
  1403. TRef<IObject> Apply(ObjectStack& stack)
  1404. {
  1405. TRef<IObjectList> plist; CastTo(plist, (IObject*)stack.Pop());
  1406. TRef<Number> pframe; CastTo(pframe, (IObject*)stack.Pop());
  1407. TRef<KeyFramedTranslateTransform> ptrans = CreateKeyFramedTranslateTransform(pframe);
  1408. plist->GetFirst();
  1409. while (plist->GetCurrent() != NULL) {
  1410. float time = GetNumber(plist->GetCurrent());
  1411. float x = GetNumber(plist->GetNext());
  1412. float y = GetNumber(plist->GetNext());
  1413. float z = GetNumber(plist->GetNext());
  1414. ptrans->AddKey(time, Vector(x, y, z));
  1415. plist->GetNext();
  1416. }
  1417. return ptrans;
  1418. }
  1419. };
  1420. //////////////////////////////////////////////////////////////////////////////
  1421. //
  1422. //
  1423. //
  1424. //////////////////////////////////////////////////////////////////////////////
  1425. class ScaleFactory : public IFunction {
  1426. private:
  1427. public:
  1428. TRef<IObject> Apply(ObjectStack& stack)
  1429. {
  1430. TRef<Number> pscale = Number::Cast((IObject*)stack.Pop());
  1431. return new ScaleTransform(pscale->GetValue());
  1432. }
  1433. };
  1434. //////////////////////////////////////////////////////////////////////////////
  1435. //
  1436. //
  1437. //
  1438. //////////////////////////////////////////////////////////////////////////////
  1439. class TranslateFactory : public IFunction {
  1440. private:
  1441. public:
  1442. TRef<IObject> Apply(ObjectStack& stack)
  1443. {
  1444. TRef<VectorValue> pvector = VectorValue::Cast((IObject*)stack.Pop());
  1445. return new TranslateTransform(pvector->GetValue());
  1446. }
  1447. };
  1448. //////////////////////////////////////////////////////////////////////////////
  1449. //
  1450. //
  1451. //
  1452. //////////////////////////////////////////////////////////////////////////////
  1453. class RotateFactory : public IFunction {
  1454. private:
  1455. public:
  1456. TRef<IObject> Apply(ObjectStack& stack)
  1457. {
  1458. TRef<VectorValue> pvector = VectorValue::Cast((IObject*)stack.Pop());
  1459. TRef<Number> pangle = Number::Cast((IObject*)stack.Pop());
  1460. return
  1461. new RotateTransform(
  1462. pvector->GetValue(),
  1463. pangle->GetValue()
  1464. );
  1465. }
  1466. };
  1467. //////////////////////////////////////////////////////////////////////////////
  1468. //
  1469. //
  1470. //
  1471. //////////////////////////////////////////////////////////////////////////////
  1472. class KeyFramedScaleFactory : public IFunction {
  1473. private:
  1474. public:
  1475. TRef<IObject> Apply(ObjectStack& stack)
  1476. {
  1477. TRef<IObjectList> plist; CastTo(plist, (IObject*)stack.Pop());
  1478. TRef<Number> pframe; CastTo(pframe, (IObject*)stack.Pop());
  1479. TRef<KeyFramedScaleTransform> ptrans = CreateKeyFramedScaleTransform(pframe);
  1480. plist->GetFirst();
  1481. while (plist->GetCurrent() != NULL) {
  1482. float time = GetNumber(plist->GetCurrent());
  1483. float x = GetNumber(plist->GetNext());
  1484. float y = GetNumber(plist->GetNext());
  1485. float z = GetNumber(plist->GetNext());
  1486. ptrans->AddKey(time, Vector(x, y, z));
  1487. plist->GetNext();
  1488. }
  1489. return ptrans;
  1490. }
  1491. };
  1492. //////////////////////////////////////////////////////////////////////////////
  1493. //
  1494. //
  1495. //
  1496. //////////////////////////////////////////////////////////////////////////////
  1497. class KeyFramedRotateFactory : public IFunction {
  1498. private:
  1499. public:
  1500. TRef<IObject> Apply(ObjectStack& stack)
  1501. {
  1502. TRef<IObjectList> plist; CastTo(plist, (IObject*)stack.Pop());
  1503. TRef<Number> pframe; CastTo(pframe, (IObject*)stack.Pop());
  1504. TRef<KeyFramedRotateTransform> ptrans = CreateKeyFramedRotateTransform(pframe);
  1505. plist->GetFirst();
  1506. while (plist->GetCurrent() != NULL) {
  1507. float time = GetNumber(plist->GetCurrent());
  1508. float s = GetNumber(plist->GetNext());
  1509. float x = GetNumber(plist->GetNext());
  1510. float y = GetNumber(plist->GetNext());
  1511. float z = GetNumber(plist->GetNext());
  1512. ptrans->AddKey(time, Quaternion(s, x, y, z));
  1513. plist->GetNext();
  1514. }
  1515. return ptrans;
  1516. }
  1517. };
  1518. //////////////////////////////////////////////////////////////////////////////
  1519. //
  1520. //
  1521. //
  1522. //////////////////////////////////////////////////////////////////////////////
  1523. class Win32FontFactory : public IFunction {
  1524. private:
  1525. Engine* m_pengine;
  1526. public:
  1527. Win32FontFactory(Engine* pengine) :
  1528. m_pengine(pengine)
  1529. {
  1530. }
  1531. TRef<IObject> Apply(ObjectStack& stack)
  1532. {
  1533. TRef<StringValue> pstringName; CastTo(pstringName, (IObject*)stack.Pop());
  1534. TRef<Number> pnumberSize; CastTo(pnumberSize, (IObject*)stack.Pop());
  1535. TRef<Boolean> pboolBold; CastTo(pboolBold, (IObject*)stack.Pop());
  1536. TRef<Number> pnumberStretch; CastTo(pnumberStretch, (IObject*)stack.Pop());
  1537. return
  1538. new FontValue(
  1539. CreateEngineFont(
  1540. CreateFont(
  1541. (int)pnumberSize->GetValue(),
  1542. (int)pnumberStretch->GetValue(),0, 0,
  1543. pboolBold->GetValue() ? FW_BOLD : FW_DONTCARE,
  1544. FALSE, FALSE, FALSE, ANSI_CHARSET,
  1545. OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
  1546. DEFAULT_QUALITY, DEFAULT_PITCH | FF_MODERN,
  1547. pstringName->GetValue()
  1548. )
  1549. )
  1550. );
  1551. }
  1552. };
  1553. //////////////////////////////////////////////////////////////////////////////
  1554. //
  1555. // Numbers
  1556. //
  1557. //////////////////////////////////////////////////////////////////////////////
  1558. class ModFactory : public IFunction {
  1559. public:
  1560. TRef<IObject> Apply(ObjectStack& stack)
  1561. {
  1562. TRef<Number> pnumber1; CastTo(pnumber1, (IObject*)stack.Pop());
  1563. TRef<Number> pnumber2; CastTo(pnumber2, (IObject*)stack.Pop());
  1564. return Mod(pnumber1, pnumber2);
  1565. }
  1566. };
  1567. class MinFactory : public IFunction {
  1568. public:
  1569. TRef<IObject> Apply(ObjectStack& stack)
  1570. {
  1571. TRef<Number> pnumber1; CastTo(pnumber1, (IObject*)stack.Pop());
  1572. TRef<Number> pnumber2; CastTo(pnumber2, (IObject*)stack.Pop());
  1573. return Min(pnumber1, pnumber2);
  1574. }
  1575. };
  1576. class MaxFactory : public IFunction {
  1577. public:
  1578. TRef<IObject> Apply(ObjectStack& stack)
  1579. {
  1580. TRef<Number> pnumber1; CastTo(pnumber1, (IObject*)stack.Pop());
  1581. TRef<Number> pnumber2; CastTo(pnumber2, (IObject*)stack.Pop());
  1582. return Max(pnumber1, pnumber2);
  1583. }
  1584. };
  1585. class AddFactory : public IFunction {
  1586. public:
  1587. TRef<IObject> Apply(ObjectStack& stack)
  1588. {
  1589. TRef<Number> pnumber1; CastTo(pnumber1, (IObject*)stack.Pop());
  1590. TRef<Number> pnumber2; CastTo(pnumber2, (IObject*)stack.Pop());
  1591. return Add(pnumber1, pnumber2);
  1592. }
  1593. };
  1594. class SubtractFactory : public IFunction {
  1595. public:
  1596. TRef<IObject> Apply(ObjectStack& stack)
  1597. {
  1598. TRef<Number> pnumber1; CastTo(pnumber1, (IObject*)stack.Pop());
  1599. TRef<Number> pnumber2; CastTo(pnumber2, (IObject*)stack.Pop());
  1600. return Subtract(pnumber1, pnumber2);
  1601. }
  1602. };
  1603. class MultiplyFactory : public IFunction {
  1604. public:
  1605. TRef<IObject> Apply(ObjectStack& stack)
  1606. {
  1607. TRef<Number> pnumber1; CastTo(pnumber1, (IObject*)stack.Pop());
  1608. TRef<Number> pnumber2; CastTo(pnumber2, (IObject*)stack.Pop());
  1609. return Multiply(pnumber1, pnumber2);
  1610. }
  1611. };
  1612. class DivideFactory : public IFunction {
  1613. public:
  1614. TRef<IObject> Apply(ObjectStack& stack)
  1615. {
  1616. TRef<Number> pnumber1; CastTo(pnumber1, (IObject*)stack.Pop());
  1617. TRef<Number> pnumber2; CastTo(pnumber2, (IObject*)stack.Pop());
  1618. return Divide(pnumber1, pnumber2);
  1619. }
  1620. };
  1621. //////////////////////////////////////////////////////////////////////////////
  1622. //
  1623. // NumberString
  1624. //
  1625. //////////////////////////////////////////////////////////////////////////////
  1626. class NumberString : public StringValue {
  1627. public:
  1628. NumberString(Number* pvalue) :
  1629. StringValue(pvalue)
  1630. {
  1631. }
  1632. Number* GetNumber() { return Number::Cast(GetChild(0)); }
  1633. void Evaluate()
  1634. {
  1635. GetValueInternal() = (int)(GetNumber()->GetValue() + 0.5);
  1636. }
  1637. ZString GetFunctionName() { return "NumberString"; }
  1638. };
  1639. class NumberStringFactory : public IFunction {
  1640. public:
  1641. TRef<IObject> Apply(ObjectStack& stack)
  1642. {
  1643. TRef<Number> pnumber; CastTo(pnumber, (IObject*)stack.Pop());
  1644. return new NumberString(pnumber);
  1645. }
  1646. };
  1647. //////////////////////////////////////////////////////////////////////////////
  1648. //
  1649. // RealNumberString
  1650. //
  1651. //////////////////////////////////////////////////////////////////////////////
  1652. class RealNumberString : public StringValue {
  1653. public:
  1654. RealNumberString(Number* pvalue) :
  1655. StringValue(pvalue)
  1656. {
  1657. }
  1658. Number* GetNumber() { return Number::Cast(GetChild(0)); }
  1659. void Evaluate()
  1660. {
  1661. char cbTemp[80];
  1662. sprintf(cbTemp, "%.2g", (double)GetNumber()->GetValue());
  1663. GetValueInternal() = cbTemp;
  1664. }
  1665. ZString GetFunctionName() { return "RealNumberString"; }
  1666. };
  1667. class RealNumberStringFactory : public IFunction {
  1668. public:
  1669. TRef<IObject> Apply(ObjectStack& stack)
  1670. {
  1671. TRef<Number> pnumber; CastTo(pnumber, (IObject*)stack.Pop());
  1672. return new RealNumberString(pnumber);
  1673. }
  1674. };
  1675. //////////////////////////////////////////////////////////////////////////////
  1676. //
  1677. // ConcatinatedString
  1678. //
  1679. //////////////////////////////////////////////////////////////////////////////
  1680. class ConcatinatedString : public StringValue {
  1681. public:
  1682. ConcatinatedString(StringValue* pvalue1, StringValue* pvalue2) :
  1683. StringValue(pvalue1, pvalue2)
  1684. {
  1685. }
  1686. void Evaluate()
  1687. {
  1688. GetValueInternal() = ((StringValue*)GetChild(0))->GetValue()
  1689. + ((StringValue*)GetChild(1))->GetValue();
  1690. }
  1691. ZString GetFunctionName() { return "ConcatinatedString"; }
  1692. };
  1693. class ConcatinatedStringFactory : public IFunction {
  1694. public:
  1695. TRef<IObject> Apply(ObjectStack& stack)
  1696. {
  1697. TRef<StringValue> pstring1; CastTo(pstring1, (IObject*)stack.Pop());
  1698. TRef<StringValue> pstring2; CastTo(pstring2, (IObject*)stack.Pop());
  1699. return new ConcatinatedString(pstring1, pstring2);
  1700. }
  1701. };
  1702. //////////////////////////////////////////////////////////////////////////////
  1703. //
  1704. // Modeler
  1705. //
  1706. //////////////////////////////////////////////////////////////////////////////
  1707. class ModelerImpl : public Modeler {
  1708. private:
  1709. TRef<Engine> m_pengine;
  1710. TRef<ModelerSite> m_psite;
  1711. PathString m_pathStr;
  1712. TMap<ZString, TRef<INameSpace> > m_mapNameSpace;
  1713. public:
  1714. ModelerImpl(Engine* pengine) :
  1715. m_pengine(pengine),
  1716. m_pathStr(".")
  1717. {
  1718. m_psite = new ModelerSiteImpl();
  1719. InitializeNameSpace();
  1720. }
  1721. void SetSite(ModelerSite* psite)
  1722. {
  1723. m_psite = psite;
  1724. }
  1725. void SetArtPath(const PathString& pathStr)
  1726. {
  1727. m_pathStr = pathStr;
  1728. }
  1729. ZString GetArtPath()
  1730. {
  1731. return m_pathStr;
  1732. }
  1733. void Terminate()
  1734. {
  1735. m_mapNameSpace.SetEmpty();
  1736. m_pengine = NULL;
  1737. m_psite = NULL;
  1738. }
  1739. void InitializeNameSpace()
  1740. {
  1741. INameSpace* pns = CreateNameSpace("model");
  1742. //
  1743. // Types
  1744. //
  1745. pns->AddType("Number" , new TBaseMDLType<float >("float" , ZString()));
  1746. pns->AddType("Boolean" , new TBaseMDLType<bool >("bool" , "b" ));
  1747. pns->AddType("Color" , new TBaseMDLType<Color >("Color" , "color" ));
  1748. pns->AddType("Point" , new TBaseMDLType<Point >("Point" , "point" ));
  1749. pns->AddType("Vector" , new TBaseMDLType<Vector >("Vector" , "vec" ));
  1750. pns->AddType("Rect" , new TBaseMDLType<Rect >("Rect" , "rect" ));
  1751. pns->AddType("Orientation", new TBaseMDLType<Orientation>("Orientation", "orient" ));
  1752. pns->AddType("String" , CreateStringMDLType() );
  1753. pns->AddType("Image" , CreateIObjectMDLType("Image", "image") );
  1754. pns->AddType("Geo" , CreateIObjectMDLType("Geo" , "Geo" ) );
  1755. //
  1756. // built in values
  1757. //
  1758. TRef<Number> ptime = new ModifiableNumber(0);
  1759. pns->AddMember("emptyGeo", Geo::GetEmpty() );
  1760. pns->AddMember("emptyImage", (Value*)Image::GetEmpty() );
  1761. pns->AddMember("transparentImage", (Value*)CreateTransparentImage());
  1762. pns->AddMember("emptyString", new StringValue(ZString()) );
  1763. pns->AddMember("identityTransform", GetIdentityTransform() );
  1764. pns->AddMember("time", ptime );
  1765. pns->AddMember("white", new ColorValue(Color::White() ) );
  1766. pns->AddMember("black", new ColorValue(Color::Black() ) );
  1767. pns->AddMember("red", new ColorValue(Color::Red() ) );
  1768. pns->AddMember("green", new ColorValue(Color::Green() ) );
  1769. pns->AddMember("blue", new ColorValue(Color::Blue() ) );
  1770. pns->AddMember("yellow", new ColorValue(Color::Yellow()) );
  1771. pns->AddMember("pi", new Number(pi) );
  1772. pns->AddMember("defaultFont",
  1773. new FontValue(
  1774. CreateEngineFont(
  1775. CreateFont(
  1776. 11,
  1777. 0, 0, 0,
  1778. FW_DONTCARE, FALSE, FALSE, FALSE, ANSI_CHARSET,
  1779. OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
  1780. DEFAULT_QUALITY, DEFAULT_PITCH | FF_MODERN,
  1781. "tahoma"
  1782. )
  1783. )
  1784. )
  1785. );
  1786. //
  1787. // Switches
  1788. //
  1789. pns->AddMember("SwitchString", new TSwitchFactory<ZString>());
  1790. //
  1791. // Data type constructors
  1792. //
  1793. pns->AddMember("ModifiableNumber", new ModifiableNumberFactory());
  1794. pns->AddMember("WrapNumber", new WrapNumberFactory());
  1795. pns->AddMember("Color", new RGBColorFactory());
  1796. pns->AddMember("ColorA", new RGBAColorFactory());
  1797. pns->AddMember("Vector", new VectorFactory());
  1798. pns->AddMember("Point", new PointFactory());
  1799. pns->AddMember("Rect", new RectFactory());
  1800. pns->AddMember("Material", new MaterialFactory());
  1801. pns->AddMember("PointV", new PointVFactory());
  1802. //
  1803. // Numbers
  1804. //
  1805. pns->AddMember("Min", new MinFactory());
  1806. pns->AddMember("Max", new MaxFactory());
  1807. pns->AddMember("Mod", new ModFactory());
  1808. pns->AddMember("Add", new AddFactory());
  1809. pns->AddMember("Subtract", new SubtractFactory());
  1810. pns->AddMember("Multiply", new MultiplyFactory());
  1811. pns->AddMember("Divide", new DivideFactory());
  1812. //
  1813. // Strings
  1814. //
  1815. pns->AddMember("NumberString", new NumberStringFactory());
  1816. pns->AddMember("RealNumberString", new RealNumberStringFactory());
  1817. pns->AddMember("ConcatinatedString", new ConcatinatedStringFactory());
  1818. //
  1819. // Images
  1820. //
  1821. pns->AddMember("ImportImage", new ImportImageFactory(this));
  1822. pns->AddMember("ImportImage3D", new ImportImage3DFactory(this));
  1823. pns->AddMember("ImportImageLR", new ImportImageLRFactory(this));
  1824. pns->AddMember("FrameImage", CreateFrameImageFactory());
  1825. pns->AddMember("GaugeImage", new GaugeImageFactory());
  1826. pns->AddMember("GaugeImageRect", new GaugeImageRectFactory());
  1827. pns->AddMember("GroupImage", new GroupImageFactory());
  1828. pns->AddMember("SwitchImage", new SwitchImageFactory());
  1829. pns->AddMember("GeoImage", new GeoImageFactory());
  1830. pns->AddMember("GeoImage2D", new GeoImage2DFactory());
  1831. pns->AddMember("ClipImage", new ClipImageFactory());
  1832. pns->AddMember("PickImage", new PickImageFactory());
  1833. pns->AddMember("UndetectableImage", new UndetectableImageFactory());
  1834. pns->AddMember("ColorImage", new ColorImageFactory());
  1835. pns->AddMember("ExtentImage", new ExtentImageFactory());
  1836. // !!! pns->AddMember("EmptyImage", new EmptyImageFactory());
  1837. pns->AddMember("StringImage", new StringImageFactory());
  1838. pns->AddMember("MDLFileImage", new MDLFileImageFactory(this));
  1839. pns->AddMember("TextFileImage", new TextFileImageFactory());
  1840. pns->AddMember("JustifyLeft", new Number((float)JustifyLeft().GetWord() ));
  1841. pns->AddMember("JustifyRight", new Number((float)JustifyRight().GetWord() ));
  1842. pns->AddMember("JustifyTop", new Number((float)JustifyTop().GetWord() ));
  1843. pns->AddMember("JustifyBottom", new Number((float)JustifyBottom().GetWord() ));
  1844. pns->AddMember("JustifyXCenter", new Number((float)JustifyXCenter().GetWord()));
  1845. pns->AddMember("JustifyYCenter", new Number((float)JustifyYCenter().GetWord()));
  1846. pns->AddMember("JustifyCenter", new Number((float)JustifyCenter().GetWord() ));
  1847. pns->AddMember("JustifyImage", new JustifyImageFactory());
  1848. pns->AddMember("VisibleImage", new VisibleImageFactory());
  1849. pns->AddMember("TranslateImage", new TranslateImageFactory());
  1850. pns->AddMember("ScaleImage", new ScaleImageFactory());
  1851. pns->AddMember("RotateImage", new RotateImageFactory());
  1852. pns->AddMember("BlendImage", new BlendImageFactory());
  1853. //
  1854. // Image Attributes
  1855. //
  1856. pns->AddMember("ImageSize", new ImageSizeFactory());
  1857. //
  1858. // Point Attributes
  1859. //
  1860. pns->AddMember("PointY", new PointYFactory());
  1861. pns->AddMember("PointX", new PointXFactory());
  1862. //
  1863. // Geos
  1864. //
  1865. pns->AddMember("ImportXFile", new ImportXFileFactory(this));
  1866. pns->AddMember("ImportMDL", new ImportMDLFactory(this));
  1867. pns->AddMember("MeshGeo", new MeshGeoFactory());
  1868. pns->AddMember("LODGeo", new LODGeoFactory());
  1869. pns->AddMember("GroupGeo", new GroupGeoFactory());
  1870. pns->AddMember("TransformGeo", new TransformGeoFactory());
  1871. pns->AddMember("MaterialGeo", new MaterialGeoFactory());
  1872. pns->AddMember("TextureGeo", new TextureGeoFactory());
  1873. pns->AddMember("Matrix", new MatrixTransformFactory());
  1874. pns->AddMember("BlendGeo", new BlendGeoFactory());
  1875. pns->AddMember("BlendModeSource", new Number(BlendModeSource ));
  1876. pns->AddMember("BlendModeAdd", new Number(BlendModeAdd ));
  1877. pns->AddMember("BlendModeSourceAlpha", new Number(BlendModeSourceAlpha));
  1878. //
  1879. // Transforms
  1880. //
  1881. pns->AddMember("KeyFramedTranslate", new KeyFramedTranslateFactory());
  1882. pns->AddMember("KeyFramedScale", new KeyFramedScaleFactory());
  1883. pns->AddMember("KeyFramedRotate", new KeyFramedRotateFactory());
  1884. pns->AddMember("Scale", new ScaleFactory());
  1885. pns->AddMember("Translate", new TranslateFactory());
  1886. pns->AddMember("Rotate", new RotateFactory());
  1887. //
  1888. // Fonts
  1889. //
  1890. pns->AddMember("Win32Font", new Win32FontFactory(m_pengine));
  1891. pns->AddMember("ImportFont", new ImportFontFactory(this));
  1892. //
  1893. // Panes
  1894. //
  1895. pns->AddMember("AnimatedImagePane", new AnimatedImagePaneFactory());
  1896. pns->AddMember("AnimatedImagePaneRect", new AnimatedImagePaneRectFactory());
  1897. pns->AddMember("FrameImageButtonPane", new FrameImageButtonPaneFactory(this, ptime));
  1898. pns->AddMember("PaneImage", new PaneImageFactory(this));
  1899. }
  1900. Engine* GetEngine()
  1901. {
  1902. return m_pengine;
  1903. }
  1904. TRef<ZFile> GetFile(const PathString& pathStr, const ZString& strExtensionArg, bool bError)
  1905. {
  1906. ZString strExtension = pathStr.GetExtension();
  1907. ZString strToOpen;
  1908. if (!strExtension.IsEmpty()) {
  1909. if (strExtension != strExtensionArg) {
  1910. return NULL;
  1911. }
  1912. strToOpen = m_pathStr + pathStr;
  1913. } else {
  1914. strToOpen = ZString(m_pathStr + pathStr) + ("." + strExtensionArg);
  1915. }
  1916. TRef<ZFile> pfile= new ZFile(strToOpen, OF_READ | OF_SHARE_DENY_WRITE);
  1917. ZRetailAssert(!(bError && !pfile->IsValid() && m_psite));
  1918. /*
  1919. if (
  1920. bError
  1921. && !pfile->IsValid()
  1922. && m_psite
  1923. ) {
  1924. m_psite->Error(
  1925. "Could not open the artwork file '"
  1926. + strToOpen + "'"
  1927. );
  1928. }
  1929. */
  1930. return pfile->IsValid() ? pfile : NULL;
  1931. }
  1932. TRef<ZFile> LoadFile(const PathString& pathStr, const ZString& strExtensionArg, bool bError)
  1933. {
  1934. return GetFile(pathStr, strExtensionArg, bError);
  1935. }
  1936. TRef<Surface> LoadSurface(const ZString& str, bool bColorKey, bool bError)
  1937. {
  1938. TRef<ConstantImage> pimage; CastTo(pimage, LoadImage(str, bColorKey, bError));
  1939. if (pimage) {
  1940. return pimage->GetSurface();
  1941. }
  1942. return NULL;
  1943. }
  1944. TRef<Image> LoadImage(const ZString& str, bool bColorKey, bool bError)
  1945. {
  1946. ZAssert(str.ToLower() == str);
  1947. ZAssert(str.Right(3) == "bmp");
  1948. //
  1949. // Is the image already loaded?
  1950. //
  1951. TRef<INameSpace> pns = GetCachedNameSpace(str);
  1952. if (pns) {
  1953. TRef<ConstantImage> pimage; CastTo(pimage, (Value*)pns->FindMember(str));
  1954. if (pimage) {
  1955. TRef<Surface> psurface = pimage->GetSurface();
  1956. // HACK: Need to uncomment and track down the bug that's
  1957. // triggering this when a weapon fires, but this hack should
  1958. // keep the debug client testable.
  1959. //ZAssert(bColorKey == psurface->HasColorKey());
  1960. return pimage;
  1961. }
  1962. return NULL;
  1963. }
  1964. //
  1965. // Try to load it
  1966. //
  1967. pns = GetNameSpace(str, bError);
  1968. if (pns) {
  1969. TRef<ConstantImage> pimage; CastTo(pimage, (Value*)pns->FindMember(str));
  1970. if (pimage) {
  1971. TRef<Surface> psurface = pimage->GetSurface();
  1972. psurface->SetName(str);
  1973. if (bColorKey) {
  1974. psurface->SetColorKey(Color(0, 0, 0));
  1975. }
  1976. return pimage;
  1977. }
  1978. }
  1979. return NULL;
  1980. }
  1981. HBITMAP LoadBitmap(const PathString& pathStrArg, bool bError)
  1982. {
  1983. PathString pathStr = m_pathStr + pathStrArg;
  1984. ZString strExtension = pathStr.GetExtension();
  1985. if (strExtension == "bmp" || strExtension.IsEmpty()) {
  1986. if (strExtension.IsEmpty()) {
  1987. pathStr += ".bmp";
  1988. }
  1989. return
  1990. (HBITMAP)::LoadImageA(
  1991. NULL,
  1992. pathStr,
  1993. IMAGE_BITMAP,
  1994. 0,
  1995. 0,
  1996. LR_LOADFROMFILE | LR_CREATEDIBSECTION
  1997. );
  1998. }
  1999. return NULL;
  2000. }
  2001. TRef<Geo> LoadGeo(const ZString& str, bool bError)
  2002. {
  2003. ZAssert(str.ToLower() == str);
  2004. TRef<INameSpace> pns = GetNameSpace(str, bError);
  2005. if (pns) {
  2006. TRef<Geo> pgeo; CastTo(pgeo, (Value*)pns->FindMember("object"));
  2007. return pgeo;
  2008. }
  2009. return NULL;
  2010. }
  2011. TRef<Geo> LoadXFile(
  2012. const PathString& pathStr,
  2013. Number* pnumberFrame,
  2014. bool& bAnimation,
  2015. bool bError
  2016. ) {
  2017. TRef<ZFile> pfile = GetFile(pathStr, "x", bError);
  2018. if (pfile) {
  2019. return ::ImportXFile(this, pfile, pnumberFrame, bAnimation);
  2020. }
  2021. return NULL;
  2022. }
  2023. INameSpace* CreateNameSpace(const ZString& str)
  2024. {
  2025. TRef<INameSpace> pns = ::CreateNameSpace(str);
  2026. m_mapNameSpace.Set(str, pns);
  2027. return pns;
  2028. }
  2029. INameSpace* CreateNameSpace(const ZString& str, INameSpace* pnsParent)
  2030. {
  2031. TRef<INameSpace> pns = ::CreateNameSpace(str, pnsParent);
  2032. m_mapNameSpace.Set(str, pns);
  2033. return pns;
  2034. }
  2035. INameSpace* GetCachedNameSpace(const ZString& str)
  2036. {
  2037. TRef<INameSpace> pns;
  2038. if (m_mapNameSpace.Find(str, pns)) {
  2039. return pns;
  2040. }
  2041. return NULL;
  2042. }
  2043. INameSpace* GetNameSpace(const ZString& str, bool bError)
  2044. {
  2045. TRef<INameSpace> pns = GetCachedNameSpace(str);
  2046. if (pns) {
  2047. return pns;
  2048. }
  2049. TRef<ZFile> pfile = GetFile(str, "mdl", bError);
  2050. if (pfile != NULL) {
  2051. if (*(DWORD*)pfile->GetPointer(false, false) == MDLMagic) {
  2052. if (g_bMDLLog) {
  2053. ZDebugOutput("Reading Binary MDL file '" + str + "'\n");
  2054. }
  2055. pns = CreateBinaryNameSpace(str, this, pfile);
  2056. } else {
  2057. if (g_bMDLLog) {
  2058. ZDebugOutput("Reading Text MDL file '" + str + "'\n");
  2059. }
  2060. pns = ::CreateNameSpace(str, this, pfile);
  2061. }
  2062. m_mapNameSpace.Set(str, pns);
  2063. return pns;
  2064. }
  2065. return NULL;
  2066. }
  2067. void UnloadNameSpace(const ZString& str)
  2068. {
  2069. m_mapNameSpace.Remove(str);
  2070. }
  2071. void UnloadNameSpace(INameSpace* pns)
  2072. {
  2073. m_mapNameSpace.Remove(TRef<INameSpace>(pns));
  2074. }
  2075. };
  2076. //////////////////////////////////////////////////////////////////////////////
  2077. //
  2078. // Constructor
  2079. //
  2080. //////////////////////////////////////////////////////////////////////////////
  2081. TRef<Modeler> Modeler::Create(Engine* pengine)
  2082. {
  2083. return new ModelerImpl(pengine);
  2084. }