PARSTXTR.C 80 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281
  1. /****************************************************************************
  2. * parstxtr.c
  3. *
  4. * This module parses textures and atmosphere effects.
  5. *
  6. * from Persistence of Vision(tm) Ray Tracer
  7. * Copyright 1996,1999 Persistence of Vision Team
  8. *---------------------------------------------------------------------------
  9. * NOTICE: This source code file is provided so that users may experiment
  10. * with enhancements to POV-Ray and to port the software to platforms other
  11. * than those supported by the POV-Ray Team. There are strict rules under
  12. * which you are permitted to use this file. The rules are in the file
  13. * named POVLEGAL.DOC which should be distributed with this file.
  14. * If POVLEGAL.DOC is not available or for more info please contact the POV-Ray
  15. * Team Coordinator by email to team-coord@povray.org or visit us on the web at
  16. * http://www.povray.org. The latest version of POV-Ray may be found at this site.
  17. *
  18. * This program is based on the popular DKB raytracer version 2.12.
  19. * DKBTrace was originally written by David K. Buck.
  20. * DKBTrace Ver 2.0-2.12 were written by David K. Buck & Aaron A. Collins.
  21. *
  22. * Modifications by Thomas Willhalm, March 1999, used with permission.
  23. *
  24. *****************************************************************************/
  25. #include "frame.h"
  26. #include "vector.h"
  27. #include "povproto.h"
  28. #include "parse.h"
  29. #include "parstxtr.h"
  30. #include "colour.h"
  31. #include "express.h"
  32. #include "gif.h"
  33. #include "iff.h"
  34. #include "image.h"
  35. #include "matrices.h"
  36. #include "media.h"
  37. #include "normal.h"
  38. #include "pigment.h"
  39. #include "povray.h"
  40. #include "pgm.h"
  41. #include "ppm.h"
  42. #include "targa.h"
  43. #include "png_pov.h"
  44. #include "texture.h"
  45. #include "tokenize.h"
  46. /*****************************************************************************
  47. * Local preprocessor defines
  48. ******************************************************************************/
  49. #define ADD_TNORMAL if (Tnormal == NULL) {if ((Default_Texture->Tnormal) != NULL) \
  50. Tnormal = Copy_Tnormal ((Default_Texture->Tnormal)); else Tnormal = Create_Tnormal ();\
  51. Texture->Tnormal=Tnormal;};
  52. /*****************************************************************************
  53. * Local typedefs
  54. ******************************************************************************/
  55. /*****************************************************************************
  56. * Local variables
  57. ******************************************************************************/
  58. TEXTURE *Default_Texture;
  59. /*****************************************************************************
  60. * Static functions
  61. ******************************************************************************/
  62. static void Parse_Bump_Map (TNORMAL *Tnormal);
  63. static void Parse_Image_Map (PIGMENT *Pigment);
  64. static void Parse_Pattern (TPATTERN *New, int TPat_Type);
  65. static TEXTURE *Parse_Vers1_Texture (void);
  66. static TEXTURE *Parse_Tiles (void);
  67. static TEXTURE *Parse_Material_Map (void);
  68. static void Parse_Texture_Transform (TEXTURE *Texture);
  69. static TURB *Check_Turb (WARP **Warps_Ptr);
  70. static void Parse_Warp (WARP **Warp_Ptr);
  71. static void Check_BH_Parameters (BLACK_HOLE *bh);
  72. static void Warn_Interior (char *s);
  73. /*****************************************************************************
  74. *
  75. * FUNCTION
  76. *
  77. * INPUT
  78. *
  79. * OUTPUT
  80. *
  81. * RETURNS
  82. *
  83. * AUTHOR
  84. *
  85. * POV-Ray Team
  86. *
  87. * DESCRIPTION
  88. *
  89. * CHANGES
  90. *
  91. ******************************************************************************/
  92. IMAGE *Parse_Image (int Legal)
  93. {
  94. IMAGE *Image;
  95. VECTOR Local_Vector;
  96. char *Name;
  97. Image = Create_Image ();
  98. Image->Image_Type = Legal;
  99. if (Legal & GRAD_FILE)
  100. {
  101. EXPECT
  102. CASE_VECTOR
  103. Warn(1.5, "Old style orientation vector or map type not supported. Ignoring value.");
  104. Parse_Vector (Local_Vector);
  105. END_CASE
  106. OTHERWISE
  107. UNGET
  108. EXIT
  109. END_CASE
  110. END_EXPECT
  111. }
  112. EXPECT
  113. CASE (IFF_TOKEN)
  114. Image->File_Type = IFF_FILE;
  115. Name=Parse_String();
  116. Read_Iff_Image (Image, Name);
  117. POV_FREE(Name);
  118. EXIT
  119. END_CASE
  120. CASE (GIF_TOKEN)
  121. Image->File_Type = GIF_FILE;
  122. Name=Parse_String();
  123. Read_Gif_Image(Image, Name);
  124. POV_FREE(Name);
  125. EXIT
  126. END_CASE
  127. CASE (POT_TOKEN)
  128. Image->File_Type = POT_FILE;
  129. Name=Parse_String();
  130. Read_Gif_Image(Image, Name);
  131. POV_FREE(Name);
  132. EXIT
  133. END_CASE
  134. CASE (SYS_TOKEN)
  135. Image->File_Type = SYS_FILE;
  136. Name=Parse_String();
  137. READ_SYS_IMAGE(Image, Name);
  138. POV_FREE(Name);
  139. EXIT
  140. END_CASE
  141. CASE (TGA_TOKEN)
  142. Image->File_Type = TGA_FILE;
  143. Name=Parse_String();
  144. Read_Targa_Image(Image, Name);
  145. POV_FREE(Name);
  146. EXIT
  147. END_CASE
  148. CASE (PNG_TOKEN)
  149. Image->File_Type = PNG_FILE;
  150. Name=Parse_String();
  151. Read_Png_Image(Image, Name);
  152. POV_FREE(Name);
  153. EXIT
  154. END_CASE
  155. CASE (PGM_TOKEN)
  156. Image->File_Type = PGM_FILE;
  157. Name=Parse_String();
  158. Read_PGM_Image(Image, Name);
  159. POV_FREE(Name);
  160. EXIT
  161. END_CASE
  162. CASE (PPM_TOKEN)
  163. Image->File_Type = PPM_FILE;
  164. Name=Parse_String();
  165. Read_PPM_Image(Image, Name);
  166. POV_FREE(Name);
  167. EXIT
  168. END_CASE
  169. OTHERWISE
  170. Parse_Error_Str ("map file spec");
  171. END_CASE
  172. END_EXPECT
  173. if (!(Image->File_Type & Legal))
  174. Error ("File type not supported here.");
  175. return (Image);
  176. }
  177. /*****************************************************************************
  178. *
  179. * FUNCTION
  180. *
  181. * INPUT
  182. *
  183. * OUTPUT
  184. *
  185. * RETURNS
  186. *
  187. * AUTHOR
  188. *
  189. * POV-Ray Team
  190. *
  191. * DESCRIPTION
  192. *
  193. * CHANGES
  194. *
  195. ******************************************************************************/
  196. static void Parse_Image_Map (PIGMENT *Pigment)
  197. {
  198. int reg;
  199. IMAGE *Image;
  200. Parse_Begin();
  201. Image = Parse_Image (IMAGE_FILE);
  202. Image->Use_Colour_Flag = TRUE;
  203. EXPECT /* Look for image_attribs */
  204. CASE (ONCE_TOKEN)
  205. Image->Once_Flag=TRUE;
  206. END_CASE
  207. CASE (INTERPOLATE_TOKEN)
  208. Image->Interpolation_Type = (int)Parse_Float();
  209. END_CASE
  210. CASE (MAP_TYPE_TOKEN)
  211. Image->Map_Type = (int) Parse_Float ();
  212. END_CASE
  213. CASE (USE_COLOUR_TOKEN)
  214. Image->Use_Colour_Flag = TRUE;
  215. END_CASE
  216. CASE (USE_INDEX_TOKEN)
  217. Image->Use_Colour_Flag = FALSE;
  218. END_CASE
  219. CASE (ALPHA_TOKEN)
  220. Warn(1.55, "Keyword ALPHA discontinued. Use FILTER instead.");
  221. CASE (COLOUR_KEY_TOKEN)
  222. switch(Token.Function_Id)
  223. {
  224. case FILTER_TOKEN:
  225. EXPECT
  226. CASE (ALL_TOKEN)
  227. {
  228. DBL filter;
  229. filter = Parse_Float();
  230. for (reg = 0 ; reg < Image->Colour_Map_Size ; reg++)
  231. Image->Colour_Map[reg].Filter
  232. = (unsigned short) (filter *255.0);
  233. }
  234. EXIT
  235. END_CASE
  236. OTHERWISE
  237. UNGET
  238. reg = (int)(Parse_Float() + 0.01);
  239. if (Image->Colour_Map == NULL)
  240. Not_With ("filter","non color-mapped image");
  241. if ((reg < 0) || (reg >= Image->Colour_Map_Size))
  242. Error ("FILTER color register value out of range.");
  243. Parse_Comma();
  244. Image->Colour_Map[reg].Filter
  245. = (unsigned short) (255.0 * Parse_Float());
  246. EXIT
  247. END_CASE
  248. END_EXPECT
  249. Pigment->Flags |= HAS_FILTER;
  250. break;
  251. case TRANSMIT_TOKEN:
  252. EXPECT
  253. CASE (ALL_TOKEN)
  254. {
  255. DBL transmit;
  256. transmit = Parse_Float();
  257. for (reg = 0 ; reg < Image->Colour_Map_Size ; reg++)
  258. Image->Colour_Map[reg].Transmit
  259. = (unsigned short) (transmit *255.0);
  260. }
  261. EXIT
  262. END_CASE
  263. OTHERWISE
  264. UNGET
  265. reg = (int)(Parse_Float() + 0.01);
  266. if (Image->Colour_Map == NULL)
  267. Not_With ("transmit","non color-mapped image");
  268. if ((reg < 0) || (reg >= Image->Colour_Map_Size))
  269. Error ("TRANSMIT color register value out of range.");
  270. Parse_Comma();
  271. Image->Colour_Map[reg].Transmit
  272. = (unsigned short) (255.0 * Parse_Float());
  273. EXIT
  274. END_CASE
  275. END_EXPECT
  276. Pigment->Flags |= HAS_FILTER;
  277. break;
  278. default:
  279. UNGET
  280. Parse_Error_Str ("filter or transmit");
  281. break;
  282. }
  283. END_CASE
  284. OTHERWISE
  285. UNGET
  286. EXIT
  287. END_CASE
  288. END_EXPECT
  289. Pigment->Vals.Image=Image;
  290. Parse_End();
  291. }
  292. /*****************************************************************************
  293. *
  294. * FUNCTION
  295. *
  296. * INPUT
  297. *
  298. * OUTPUT
  299. *
  300. * RETURNS
  301. *
  302. * AUTHOR
  303. *
  304. * POV-Ray Team
  305. *
  306. * DESCRIPTION
  307. *
  308. * CHANGES
  309. *
  310. ******************************************************************************/
  311. static void Parse_Bump_Map (TNORMAL *Tnormal)
  312. {
  313. IMAGE *Image;
  314. Parse_Begin();
  315. Image = Parse_Image(IMAGE_FILE);
  316. Image->Use_Colour_Flag = TRUE;
  317. EXPECT
  318. CASE (ONCE_TOKEN)
  319. Image->Once_Flag=TRUE;
  320. END_CASE
  321. CASE (MAP_TYPE_TOKEN)
  322. Image->Map_Type = (int) Parse_Float ();
  323. END_CASE
  324. CASE (INTERPOLATE_TOKEN)
  325. Image->Interpolation_Type = (int)Parse_Float();
  326. END_CASE
  327. CASE (BUMP_SIZE_TOKEN)
  328. Tnormal->Amount = Parse_Float ();
  329. END_CASE
  330. CASE (USE_COLOUR_TOKEN)
  331. Image->Use_Colour_Flag = TRUE;
  332. END_CASE
  333. CASE (USE_INDEX_TOKEN)
  334. Image->Use_Colour_Flag = FALSE;
  335. END_CASE
  336. OTHERWISE
  337. UNGET
  338. EXIT
  339. END_CASE
  340. END_EXPECT
  341. Tnormal->Vals.Image=Image;
  342. Parse_End();
  343. }
  344. /*****************************************************************************
  345. *
  346. * FUNCTION
  347. *
  348. * INPUT
  349. *
  350. * OUTPUT
  351. *
  352. * RETURNS
  353. *
  354. * AUTHOR
  355. *
  356. * POV-Ray Team
  357. *
  358. * DESCRIPTION
  359. *
  360. * CHANGES
  361. *
  362. ******************************************************************************/
  363. void Parse_Pigment (PIGMENT **Pigment_Ptr)
  364. {
  365. EXPECT /* Look for [pigment_id] */
  366. CASE (PIGMENT_ID_TOKEN)
  367. Destroy_Pigment(*Pigment_Ptr);
  368. *Pigment_Ptr = Copy_Pigment ((PIGMENT *) Token.Data);
  369. EXIT
  370. END_CASE
  371. OTHERWISE
  372. UNGET
  373. EXIT
  374. END_CASE
  375. END_EXPECT /* End pigment_id */
  376. Parse_Pattern((TPATTERN *)(*Pigment_Ptr),PIGMENT_TYPE);
  377. if (Not_In_Default && ((*Pigment_Ptr)->Type == NO_PATTERN))
  378. {
  379. Warn(1.7, "Pigment type unspecified or not 1st item.");
  380. }
  381. }
  382. /*****************************************************************************
  383. *
  384. * FUNCTION
  385. *
  386. * INPUT
  387. *
  388. * OUTPUT
  389. *
  390. * RETURNS
  391. *
  392. * AUTHOR
  393. *
  394. * POV-Ray Team
  395. *
  396. * DESCRIPTION
  397. *
  398. * CHANGES
  399. *
  400. ******************************************************************************/
  401. static void Parse_Pattern (TPATTERN *New, int TPat_Type)
  402. {
  403. VECTOR Local_Vector;
  404. COLOUR Local_Colour;
  405. MATRIX Local_Matrix;
  406. TRANSFORM Local_Trans;
  407. TURB *Local_Turb;
  408. unsigned short Old_Type=New->Type;
  409. IMAGE *Old_Image = NULL;
  410. DENSITY_FILE *Old_Density_File = NULL;
  411. if (Old_Type==BITMAP_PATTERN)
  412. {
  413. Old_Image=New->Vals.Image;
  414. }
  415. if (Old_Type==DENSITY_FILE_PATTERN)
  416. {
  417. Old_Density_File=New->Vals.Density_File;
  418. }
  419. EXPECT
  420. CASE (AGATE_TOKEN)
  421. New->Type = AGATE_PATTERN;
  422. Check_Turb(&(New->Warps));
  423. New->Vals.Agate_Turb_Scale = 1.0;
  424. EXIT
  425. END_CASE
  426. CASE (BOZO_TOKEN)
  427. New->Type = BOZO_PATTERN;
  428. EXIT
  429. END_CASE
  430. CASE (GRANITE_TOKEN)
  431. New->Type = GRANITE_PATTERN;
  432. EXIT
  433. END_CASE
  434. CASE (LEOPARD_TOKEN)
  435. New->Type = LEOPARD_PATTERN;
  436. EXIT
  437. END_CASE
  438. CASE (MARBLE_TOKEN)
  439. New->Type = MARBLE_PATTERN;
  440. New->Wave_Type = TRIANGLE_WAVE;
  441. EXIT
  442. END_CASE
  443. CASE (MANDEL_TOKEN)
  444. New->Type = MANDEL_PATTERN;
  445. New->Vals.Iterations = (int)Parse_Float();
  446. EXIT
  447. END_CASE
  448. CASE (ONION_TOKEN)
  449. New->Type = ONION_PATTERN;
  450. EXIT
  451. END_CASE
  452. CASE (SPIRAL1_TOKEN)
  453. New->Type = SPIRAL1_PATTERN;
  454. New->Vals.Arms = (short)Parse_Float ();
  455. New->Wave_Type = TRIANGLE_WAVE;
  456. EXIT
  457. END_CASE
  458. CASE (SPIRAL2_TOKEN)
  459. New->Type = SPIRAL2_PATTERN;
  460. New->Vals.Arms = (short)Parse_Float ();
  461. New->Wave_Type = TRIANGLE_WAVE;
  462. EXIT
  463. END_CASE
  464. CASE (SPOTTED_TOKEN)
  465. New->Type = SPOTTED_PATTERN;
  466. EXIT
  467. END_CASE
  468. CASE (WOOD_TOKEN)
  469. New->Type = WOOD_PATTERN;
  470. New->Wave_Type = TRIANGLE_WAVE;
  471. EXIT
  472. END_CASE
  473. CASE (GRADIENT_TOKEN)
  474. New->Type = GRADIENT_PATTERN;
  475. Parse_Vector (New->Vals.Gradient);
  476. EXIT
  477. END_CASE
  478. CASE (RADIAL_TOKEN)
  479. New->Type = RADIAL_PATTERN;
  480. EXIT
  481. END_CASE
  482. CASE (CRACKLE_TOKEN)
  483. New->Type = CRACKLE_PATTERN;
  484. EXIT
  485. END_CASE
  486. CASE_COLOUR
  487. if ((TPat_Type != PIGMENT_TYPE) && (TPat_Type != DENSITY_TYPE))
  488. {
  489. Only_In("color","pigment or density");
  490. }
  491. New->Type = PLAIN_PATTERN;
  492. Parse_Colour (((PIGMENT *)New)->Colour);
  493. EXIT
  494. END_CASE
  495. CASE (CHECKER_TOKEN)
  496. New->Type = CHECKER_PATTERN;
  497. New->Frequency = 0.0;
  498. Destroy_Blend_Map(New->Blend_Map);
  499. New->Blend_Map = Parse_Blend_List(2,&Check_Default_Map,TPat_Type);
  500. EXIT
  501. END_CASE
  502. CASE (BRICK_TOKEN)
  503. if (New->Type!=BRICK_PATTERN)
  504. {
  505. Make_Vector(New->Vals.Brick.Size,8.0,3.0,4.5);
  506. New->Vals.Brick.Mortar=0.5-Small_Tolerance*2.0;
  507. New->Type = BRICK_PATTERN;
  508. }
  509. New->Frequency = 0.0;
  510. Destroy_Blend_Map(New->Blend_Map);
  511. New->Blend_Map = Parse_Blend_List(2,&Brick_Default_Map,TPat_Type);
  512. EXIT
  513. END_CASE
  514. CASE (HEXAGON_TOKEN)
  515. New->Type = HEXAGON_PATTERN;
  516. New->Frequency = 0.0;
  517. Destroy_Blend_Map(New->Blend_Map);
  518. New->Blend_Map = Parse_Blend_List(3,&Hex_Default_Map,TPat_Type);
  519. EXIT
  520. END_CASE
  521. CASE (IMAGE_MAP_TOKEN)
  522. if (TPat_Type != PIGMENT_TYPE)
  523. {
  524. Only_In("image_map","pigment");
  525. }
  526. if (Old_Type==BITMAP_PATTERN)
  527. {
  528. Destroy_Image(Old_Image);
  529. }
  530. New->Type = BITMAP_PATTERN;
  531. New->Frequency = 0.0;
  532. Parse_Image_Map ((PIGMENT *)New);
  533. EXIT
  534. END_CASE
  535. CASE (BUMP_MAP_TOKEN)
  536. if (TPat_Type != NORMAL_TYPE)
  537. {
  538. Only_In("bump_map","normal");
  539. }
  540. if (Old_Type==BITMAP_PATTERN)
  541. {
  542. Destroy_Image(Old_Image);
  543. }
  544. New->Type = BITMAP_PATTERN;
  545. New->Frequency = 0.0;
  546. Parse_Bump_Map ((TNORMAL *)New);
  547. EXIT
  548. END_CASE
  549. CASE (WAVES_TOKEN)
  550. New->Type = WAVES_PATTERN;
  551. EXIT
  552. END_CASE
  553. CASE (RIPPLES_TOKEN)
  554. New->Type = RIPPLES_PATTERN;
  555. EXIT
  556. END_CASE
  557. CASE (WRINKLES_TOKEN)
  558. New->Type = WRINKLES_PATTERN;
  559. EXIT
  560. END_CASE
  561. CASE (BUMPS_TOKEN)
  562. New->Type = BUMPS_PATTERN;
  563. EXIT
  564. END_CASE
  565. CASE (DENTS_TOKEN)
  566. New->Type = DENTS_PATTERN;
  567. EXIT
  568. END_CASE
  569. CASE (QUILTED_TOKEN)
  570. New->Type = QUILTED_PATTERN;
  571. New->Vals.Quilted.Control0 = 1.0;
  572. New->Vals.Quilted.Control1 = 1.0;
  573. New->Frequency = 0.0;
  574. EXIT
  575. END_CASE
  576. CASE (AVERAGE_TOKEN)
  577. New->Type = AVERAGE_PATTERN;
  578. EXIT
  579. END_CASE
  580. CASE (PLANAR_TOKEN)
  581. New->Type = PLANAR_PATTERN;
  582. EXIT
  583. END_CASE
  584. CASE (BOXED_TOKEN)
  585. New->Type = BOXED_PATTERN;
  586. EXIT
  587. END_CASE
  588. CASE (SPHERICAL_TOKEN)
  589. New->Type = SPHERICAL_PATTERN;
  590. EXIT
  591. END_CASE
  592. CASE (CYLINDRICAL_TOKEN)
  593. New->Type = CYLINDRICAL_PATTERN;
  594. EXIT
  595. END_CASE
  596. CASE (DENSITY_FILE_TOKEN)
  597. if (Old_Type==DENSITY_FILE_PATTERN)
  598. {
  599. Destroy_Density_File(Old_Density_File);
  600. }
  601. New->Type = DENSITY_FILE_PATTERN;
  602. New->Vals.Density_File = Create_Density_File();
  603. GET(DF3_TOKEN);
  604. New->Vals.Density_File->Data->Name = Parse_String();
  605. Read_Density_File(New->Vals.Density_File);
  606. EXIT
  607. END_CASE
  608. OTHERWISE
  609. UNGET
  610. EXIT
  611. END_CASE
  612. END_EXPECT /* Concludes pattern_body */
  613. if ((Old_Type==BITMAP_PATTERN) && (New->Type!=BITMAP_PATTERN))
  614. {
  615. Destroy_Image(Old_Image);
  616. }
  617. if ((Old_Type==DENSITY_FILE_PATTERN) && (New->Type!=DENSITY_FILE_PATTERN))
  618. {
  619. Destroy_Density_File(Old_Density_File);
  620. }
  621. if (TPat_Type == NORMAL_TYPE)
  622. {
  623. Parse_Comma();
  624. ((TNORMAL *)New)->Amount = Allow_Float (((TNORMAL *)New)->Amount );
  625. }
  626. EXPECT /* Look for pattern_modifier */
  627. CASE (TURBULENCE_TOKEN)
  628. Local_Turb=Check_Turb(&(New->Warps));
  629. Parse_Vector(Local_Turb->Turbulence);
  630. END_CASE
  631. CASE (COLOUR_MAP_TOKEN)
  632. if ((TPat_Type != PIGMENT_TYPE) && (TPat_Type != DENSITY_TYPE))
  633. {
  634. Only_In("color_map","pigment");
  635. }
  636. if (New->Type == CHECKER_PATTERN ||
  637. New->Type == BRICK_PATTERN ||
  638. New->Type == HEXAGON_PATTERN ||
  639. New->Type == PLAIN_PATTERN ||
  640. New->Type == AVERAGE_PATTERN ||
  641. New->Type == BITMAP_PATTERN)
  642. {
  643. Error("Cannot use color_map with this pattern type.");
  644. }
  645. Destroy_Blend_Map(New->Blend_Map);
  646. New->Blend_Map = Parse_Colour_Map ();
  647. END_CASE
  648. CASE (PIGMENT_MAP_TOKEN)
  649. if (TPat_Type != PIGMENT_TYPE)
  650. {
  651. Only_In("pigment_map","pigment");
  652. }
  653. if (New->Type == CHECKER_PATTERN ||
  654. New->Type == BRICK_PATTERN ||
  655. New->Type == HEXAGON_PATTERN ||
  656. New->Type == PLAIN_PATTERN ||
  657. New->Type == BITMAP_PATTERN)
  658. Not_With ("pigment_map","this pigment type");
  659. Destroy_Blend_Map(New->Blend_Map);
  660. New->Blend_Map = Parse_Blend_Map (PIGMENT_TYPE,New->Type);
  661. END_CASE
  662. CASE (DENSITY_MAP_TOKEN)
  663. if (TPat_Type != DENSITY_TYPE)
  664. {
  665. Only_In("density_map","density");
  666. }
  667. if (New->Type == CHECKER_PATTERN ||
  668. New->Type == BRICK_PATTERN ||
  669. New->Type == HEXAGON_PATTERN ||
  670. New->Type == PLAIN_PATTERN ||
  671. New->Type == BITMAP_PATTERN)
  672. Not_With ("density_map","this density type");
  673. Destroy_Blend_Map(New->Blend_Map);
  674. New->Blend_Map = Parse_Blend_Map (DENSITY_TYPE,New->Type);
  675. END_CASE
  676. CASE (SLOPE_MAP_TOKEN)
  677. if (TPat_Type != NORMAL_TYPE)
  678. {
  679. Only_In("slope_map","normal");
  680. }
  681. if (New->Type == CHECKER_PATTERN ||
  682. New->Type == BRICK_PATTERN ||
  683. New->Type == HEXAGON_PATTERN ||
  684. New->Type == PLAIN_PATTERN ||
  685. New->Type == AVERAGE_PATTERN ||
  686. New->Type == BITMAP_PATTERN)
  687. Not_With ("slope_map","this normal type");
  688. Destroy_Blend_Map(New->Blend_Map);
  689. New->Blend_Map = Parse_Blend_Map (SLOPE_TYPE,New->Type);
  690. END_CASE
  691. CASE (NORMAL_MAP_TOKEN)
  692. if (TPat_Type != NORMAL_TYPE)
  693. {
  694. Only_In("normal_map","normal");
  695. }
  696. if (New->Type == CHECKER_PATTERN ||
  697. New->Type == BRICK_PATTERN ||
  698. New->Type == HEXAGON_PATTERN ||
  699. New->Type == PLAIN_PATTERN ||
  700. New->Type == BITMAP_PATTERN)
  701. Not_With ("normal_map","this normal type");
  702. Destroy_Blend_Map(New->Blend_Map);
  703. New->Blend_Map = Parse_Blend_Map (NORMAL_TYPE,New->Type);
  704. END_CASE
  705. CASE (TEXTURE_MAP_TOKEN)
  706. if (TPat_Type != TEXTURE_TYPE)
  707. {
  708. Only_In("texture_map","texture");
  709. }
  710. if (New->Type == CHECKER_PATTERN ||
  711. New->Type == BRICK_PATTERN ||
  712. New->Type == HEXAGON_PATTERN ||
  713. New->Type == PLAIN_PATTERN ||
  714. New->Type == BITMAP_PATTERN)
  715. Not_With ("texture_map","this pattern type");
  716. Destroy_Blend_Map(New->Blend_Map);
  717. New->Blend_Map = Parse_Blend_Map (TEXTURE_TYPE,New->Type);
  718. END_CASE
  719. CASE (QUICK_COLOUR_TOKEN)
  720. if (TPat_Type != PIGMENT_TYPE)
  721. {
  722. Only_In("quick_color","pigment");
  723. }
  724. Parse_Colour (Local_Colour);
  725. if (opts.Quality_Flags & Q_QUICKC)
  726. {
  727. New->Type = PLAIN_PATTERN;
  728. Assign_Colour(((PIGMENT *)New)->Colour,Local_Colour);
  729. }
  730. END_CASE
  731. CASE (CONTROL0_TOKEN)
  732. if (New->Type == QUILTED_PATTERN)
  733. {
  734. New->Vals.Quilted.Control0 = Parse_Float ();
  735. }
  736. else
  737. {
  738. Not_With ("control0","this normal");
  739. }
  740. END_CASE
  741. CASE (CONTROL1_TOKEN)
  742. if (New->Type == QUILTED_PATTERN)
  743. {
  744. New->Vals.Quilted.Control1 = Parse_Float ();
  745. }
  746. else
  747. {
  748. Not_With ("control1","this normal");
  749. }
  750. END_CASE
  751. CASE (OCTAVES_TOKEN)
  752. Local_Turb=Check_Turb(&(New->Warps));
  753. Local_Turb->Octaves = (int)Parse_Float();
  754. if(Local_Turb->Octaves < 1)
  755. Local_Turb->Octaves = 1;
  756. if(Local_Turb->Octaves > 10) /* Avoid DOMAIN errors */
  757. Local_Turb->Octaves = 10;
  758. END_CASE
  759. CASE (OMEGA_TOKEN)
  760. Local_Turb=Check_Turb(&(New->Warps));
  761. Local_Turb->Omega = Parse_Float();
  762. END_CASE
  763. CASE (LAMBDA_TOKEN)
  764. Local_Turb=Check_Turb(&(New->Warps));
  765. Local_Turb->Lambda = Parse_Float();
  766. END_CASE
  767. CASE (FREQUENCY_TOKEN)
  768. New->Frequency = Parse_Float();
  769. END_CASE
  770. CASE (RAMP_WAVE_TOKEN)
  771. New->Wave_Type = RAMP_WAVE;
  772. END_CASE
  773. CASE (TRIANGLE_WAVE_TOKEN)
  774. New->Wave_Type = TRIANGLE_WAVE;
  775. END_CASE
  776. CASE (SINE_WAVE_TOKEN)
  777. New->Wave_Type = SINE_WAVE;
  778. END_CASE
  779. CASE (SCALLOP_WAVE_TOKEN)
  780. New->Wave_Type = SCALLOP_WAVE;
  781. END_CASE
  782. CASE (CUBIC_WAVE_TOKEN)
  783. New->Wave_Type = CUBIC_WAVE;
  784. END_CASE
  785. CASE (POLY_WAVE_TOKEN)
  786. New->Wave_Type = POLY_WAVE;
  787. New->Exponent = Allow_Float(New->Exponent);
  788. END_CASE
  789. CASE (PHASE_TOKEN)
  790. New->Phase = Parse_Float();
  791. END_CASE
  792. CASE (BUMP_SIZE_TOKEN)
  793. if (TPat_Type != NORMAL_TYPE)
  794. Only_In ("bump_size","normal");
  795. ((TNORMAL *)New)->Amount = Parse_Float ();
  796. END_CASE
  797. CASE (AGATE_TURB_TOKEN)
  798. if (New->Type != AGATE_PATTERN)
  799. Not_With ("agate_turb","non-agate");
  800. New->Vals.Agate_Turb_Scale = Parse_Float();
  801. Check_Turb(&(New->Warps)); /* agate needs Octaves, Lambda etc. */
  802. END_CASE
  803. CASE (BRICK_SIZE_TOKEN)
  804. if (New->Type != BRICK_PATTERN)
  805. Not_With ("brick_size","non-brick");
  806. Parse_Vector(New->Vals.Brick.Size);
  807. END_CASE
  808. CASE (MORTAR_TOKEN)
  809. if (New->Type != BRICK_PATTERN)
  810. Not_With ("mortar","non-brick");
  811. New->Vals.Brick.Mortar = Parse_Float()-Small_Tolerance*2.0;
  812. END_CASE
  813. CASE (INTERPOLATE_TOKEN)
  814. if (New->Type != DENSITY_FILE_PATTERN)
  815. Not_With ("interpolate","non-density_file");
  816. New->Vals.Density_File->Interpolation = (int)Parse_Float();
  817. END_CASE
  818. CASE (WARP_TOKEN)
  819. Parse_Warp(&(New->Warps));
  820. END_CASE
  821. CASE (TRANSLATE_TOKEN)
  822. Parse_Vector (Local_Vector);
  823. Translate_Tpattern (New, Local_Vector);
  824. END_CASE
  825. CASE (ROTATE_TOKEN)
  826. Parse_Vector (Local_Vector);
  827. Rotate_Tpattern (New, Local_Vector);
  828. END_CASE
  829. CASE (SCALE_TOKEN)
  830. Parse_Scale_Vector (Local_Vector);
  831. Scale_Tpattern (New, Local_Vector);
  832. END_CASE
  833. CASE (MATRIX_TOKEN)
  834. Parse_Matrix(Local_Matrix);
  835. Compute_Matrix_Transform(&Local_Trans, Local_Matrix);
  836. Transform_Tpattern (New, &Local_Trans);
  837. END_CASE
  838. CASE (TRANSFORM_TOKEN)
  839. GET(TRANSFORM_ID_TOKEN)
  840. Transform_Tpattern (New, (TRANSFORM *)Token.Data);
  841. END_CASE
  842. OTHERWISE
  843. UNGET
  844. EXIT
  845. END_CASE
  846. END_EXPECT
  847. if ((New->Type==AVERAGE_PATTERN) && (New->Blend_Map==NULL))
  848. {
  849. Error("Average must have map.");
  850. }
  851. if ((TPat_Type==TEXTURE_TYPE) && (New->Type!=PLAIN_PATTERN) &&
  852. (New->Blend_Map==NULL))
  853. {
  854. Error("Patterned texture must have texture_map.");
  855. }
  856. }
  857. /*****************************************************************************
  858. *
  859. * FUNCTION
  860. *
  861. * INPUT
  862. *
  863. * OUTPUT
  864. *
  865. * RETURNS
  866. *
  867. * AUTHOR
  868. *
  869. * POV-Ray Team
  870. *
  871. * DESCRIPTION
  872. *
  873. * CHANGES
  874. *
  875. ******************************************************************************/
  876. void Parse_Tnormal (TNORMAL **Tnormal_Ptr)
  877. {
  878. EXPECT /* Look for [tnormal_id] */
  879. CASE (TNORMAL_ID_TOKEN)
  880. Destroy_Tnormal(*Tnormal_Ptr);
  881. *Tnormal_Ptr = Copy_Tnormal ((TNORMAL *) Token.Data);
  882. EXIT
  883. END_CASE
  884. OTHERWISE
  885. UNGET
  886. EXIT
  887. END_CASE
  888. END_EXPECT /* End [tnormal_id] */
  889. if (*Tnormal_Ptr == NULL)
  890. { /* tw */
  891. if ((Default_Texture->Tnormal) != NULL)
  892. *Tnormal_Ptr = Copy_Tnormal ((Default_Texture->Tnormal));
  893. else
  894. *Tnormal_Ptr = Create_Tnormal ();
  895. } /* tw */
  896. Parse_Pattern((TPATTERN *)*Tnormal_Ptr,NORMAL_TYPE);
  897. }
  898. /*****************************************************************************
  899. *
  900. * FUNCTION
  901. *
  902. * INPUT
  903. *
  904. * OUTPUT
  905. *
  906. * RETURNS
  907. *
  908. * AUTHOR
  909. *
  910. * POV-Ray Team
  911. *
  912. * DESCRIPTION
  913. *
  914. * CHANGES
  915. *
  916. ******************************************************************************/
  917. void Parse_Finish (FINISH **Finish_Ptr)
  918. {
  919. COLOUR Temp_Colour;
  920. FINISH *New;
  921. VECTOR Local_Vector;
  922. Parse_Begin ();
  923. EXPECT /* Look for zero or one finish_id */
  924. CASE (FINISH_ID_TOKEN)
  925. Destroy_Finish(*Finish_Ptr);
  926. *Finish_Ptr = Copy_Finish ((FINISH *) Token.Data);
  927. EXIT
  928. END_CASE
  929. OTHERWISE
  930. UNGET
  931. EXIT
  932. END_CASE
  933. END_EXPECT /* End finish_id */
  934. New = *Finish_Ptr;
  935. EXPECT /* Look for zero or more finish_body */
  936. CASE (AMBIENT_TOKEN)
  937. Parse_Colour(Temp_Colour);
  938. New->Ambient[RED] = Temp_Colour[RED];
  939. New->Ambient[GREEN] = Temp_Colour[GREEN];
  940. New->Ambient[BLUE] = Temp_Colour[BLUE];
  941. END_CASE
  942. CASE (BRILLIANCE_TOKEN)
  943. New->Brilliance = Parse_Float ();
  944. END_CASE
  945. CASE (DIFFUSE_TOKEN)
  946. New->Diffuse = Parse_Float ();
  947. END_CASE
  948. CASE (REFLECTION_TOKEN)
  949. Parse_Colour(Temp_Colour);
  950. New->Reflection[RED] = Temp_Colour[RED];
  951. New->Reflection[GREEN] = Temp_Colour[GREEN];
  952. New->Reflection[BLUE] = Temp_Colour[BLUE];
  953. END_CASE
  954. CASE (REFLECTION_EXPONENT_TOKEN)
  955. New->Reflect_Exp = 1.0 / Parse_Float ();
  956. END_CASE
  957. CASE (PHONG_TOKEN)
  958. New->Phong = Parse_Float ();
  959. END_CASE
  960. CASE (PHONG_SIZE_TOKEN)
  961. New->Phong_Size = Parse_Float ();
  962. END_CASE
  963. CASE (SPECULAR_TOKEN)
  964. New->Specular = Parse_Float ();
  965. END_CASE
  966. CASE (ROUGHNESS_TOKEN)
  967. New->Roughness = Parse_Float ();
  968. if (New->Roughness != 0.0)
  969. New->Roughness = 1.0/New->Roughness; /* CEY 12/92 */
  970. else
  971. Warn(0.0, "Zero roughness used.");
  972. END_CASE
  973. CASE (METALLIC_TOKEN)
  974. New->Metallic = 1.0;
  975. EXPECT
  976. CASE_FLOAT
  977. New->Metallic = Parse_Float();
  978. EXIT
  979. END_CASE
  980. OTHERWISE
  981. UNGET
  982. EXIT
  983. END_CASE
  984. END_EXPECT
  985. END_CASE
  986. CASE (CRAND_TOKEN)
  987. New->Crand = Parse_Float();
  988. END_CASE
  989. CASE (IRID_TOKEN) /* DMF */
  990. Parse_Begin();
  991. New->Irid = Parse_Float();
  992. EXPECT
  993. CASE (THICKNESS_TOKEN) /* DMF */
  994. New->Irid_Film_Thickness = Parse_Float();
  995. END_CASE
  996. CASE (TURBULENCE_TOKEN) /* DMF */
  997. Parse_Vector(Local_Vector);
  998. New->Irid_Turb = Local_Vector[X];
  999. END_CASE
  1000. OTHERWISE
  1001. UNGET
  1002. EXIT
  1003. END_CASE
  1004. END_EXPECT
  1005. Parse_End();
  1006. END_CASE
  1007. CASE (IOR_TOKEN)
  1008. New->Temp_IOR = Parse_Float();
  1009. Warn_Interior("Index of refraction value");
  1010. END_CASE
  1011. CASE (CAUSTICS_TOKEN)
  1012. New->Temp_Caustics = Parse_Float();
  1013. Warn_Interior("Caustics value");
  1014. END_CASE
  1015. CASE (REFRACTION_TOKEN)
  1016. New->Temp_Refract = Parse_Float();
  1017. Warn_Interior("Refraction value unnecessary to turn on refraction.\nTo attenuate, the fade_power and fade_distance keywords ");
  1018. END_CASE
  1019. OTHERWISE
  1020. UNGET
  1021. EXIT
  1022. END_CASE
  1023. END_EXPECT /* End of finish_body */
  1024. EXPECT /* Look for finish_mods */
  1025. /* CASE none implemented
  1026. END_CASE */
  1027. OTHERWISE
  1028. UNGET
  1029. EXIT
  1030. END_CASE
  1031. END_EXPECT /* End of finish_mods */
  1032. Parse_End ();
  1033. }
  1034. /*****************************************************************************
  1035. *
  1036. * FUNCTION
  1037. *
  1038. * INPUT
  1039. *
  1040. * OUTPUT
  1041. *
  1042. * RETURNS
  1043. *
  1044. * AUTHOR
  1045. *
  1046. * POV-Ray Team
  1047. *
  1048. * DESCRIPTION
  1049. *
  1050. * CHANGES
  1051. *
  1052. ******************************************************************************/
  1053. TEXTURE *Parse_Texture ()
  1054. {
  1055. VECTOR Local_Vector;
  1056. MATRIX Local_Matrix;
  1057. TRANSFORM Local_Trans;
  1058. TEXTURE *Texture;
  1059. int Modified_Pnf;
  1060. if (opts.Language_Version < 3.0)
  1061. {
  1062. return(Parse_Vers1_Texture());
  1063. }
  1064. Modified_Pnf = FALSE;
  1065. EXPECT /* First allow a texture identifier */
  1066. CASE (TEXTURE_ID_TOKEN)
  1067. Texture = Copy_Textures((TEXTURE *) Token.Data);
  1068. Modified_Pnf = TRUE;
  1069. EXIT
  1070. END_CASE
  1071. OTHERWISE
  1072. UNGET
  1073. Texture = Copy_Textures (Default_Texture);
  1074. EXIT
  1075. END_CASE
  1076. END_EXPECT
  1077. /* If the texture identifer or the default texture was a PLAIN_PATTERN
  1078. then allow its pigment, normal or finish to be overridden by
  1079. pigment identifier, normal identifier and finish identifiers.
  1080. This is a consession to backwards compatibility so that
  1081. "texture{PIGMENT_IDENTIFIER}" etc. is legal even though it should
  1082. be "texture{pigment{PIGMENT_IDENTIFIER}}"
  1083. */
  1084. /* Look for [pnf_texture] */
  1085. if (Texture->Type == PLAIN_PATTERN)
  1086. {
  1087. EXPECT /* Look for [pnf_ids] */
  1088. CASE (PIGMENT_ID_TOKEN)
  1089. Warn_State(Token.Token_Id, PIGMENT_TOKEN);
  1090. Destroy_Pigment(Texture->Pigment);
  1091. Texture->Pigment = Copy_Pigment ((PIGMENT *) Token.Data);
  1092. Modified_Pnf = TRUE;
  1093. END_CASE
  1094. CASE (TNORMAL_ID_TOKEN)
  1095. Warn_State(Token.Token_Id, TNORMAL_TOKEN);
  1096. Destroy_Tnormal(Texture->Tnormal);
  1097. Texture->Tnormal = Copy_Tnormal ((TNORMAL *) Token.Data);
  1098. Modified_Pnf = TRUE;
  1099. END_CASE
  1100. CASE (FINISH_ID_TOKEN)
  1101. Warn_State(Token.Token_Id, FINISH_TOKEN);
  1102. Destroy_Finish(Texture->Finish);
  1103. Texture->Finish = Copy_Finish ((FINISH *) Token.Data);
  1104. Modified_Pnf = TRUE;
  1105. END_CASE
  1106. OTHERWISE
  1107. UNGET
  1108. EXIT
  1109. END_CASE
  1110. END_EXPECT
  1111. /* If the texture identifer or the default texture was a PLAIN_PATTERN
  1112. then allow its pigment, normal or finish to be overridden by
  1113. pigment, normal or finish statement. Also allow transformations.
  1114. */
  1115. EXPECT /* Modify previous pnf */
  1116. CASE (PIGMENT_TOKEN)
  1117. Parse_Begin ();
  1118. Parse_Pigment ( &(Texture->Pigment) );
  1119. Parse_End ();
  1120. Modified_Pnf = TRUE;
  1121. END_CASE
  1122. CASE (TNORMAL_TOKEN)
  1123. Parse_Begin ();
  1124. Parse_Tnormal ( &(Texture->Tnormal) );
  1125. Parse_End ();
  1126. Modified_Pnf = TRUE;
  1127. END_CASE
  1128. CASE (FINISH_TOKEN)
  1129. Parse_Finish ( &(Texture->Finish) );
  1130. Modified_Pnf = TRUE;
  1131. END_CASE
  1132. CASE (TRANSLATE_TOKEN)
  1133. Parse_Vector (Local_Vector);
  1134. Compute_Translation_Transform(&Local_Trans, Local_Vector);
  1135. Transform_Textures (Texture, &Local_Trans);
  1136. Modified_Pnf = TRUE;
  1137. END_CASE
  1138. CASE (ROTATE_TOKEN)
  1139. Parse_Vector (Local_Vector);
  1140. Compute_Rotation_Transform(&Local_Trans, Local_Vector);
  1141. Transform_Textures (Texture, &Local_Trans);
  1142. Modified_Pnf = TRUE;
  1143. END_CASE
  1144. CASE (SCALE_TOKEN)
  1145. Parse_Scale_Vector (Local_Vector);
  1146. Compute_Scaling_Transform(&Local_Trans, Local_Vector);
  1147. Transform_Textures (Texture, &Local_Trans);
  1148. Modified_Pnf = TRUE;
  1149. END_CASE
  1150. CASE (MATRIX_TOKEN)
  1151. Parse_Matrix(Local_Matrix);
  1152. Compute_Matrix_Transform(&Local_Trans, Local_Matrix);
  1153. Transform_Textures (Texture, &Local_Trans);
  1154. Modified_Pnf = TRUE;
  1155. END_CASE
  1156. CASE (TRANSFORM_TOKEN)
  1157. GET(TRANSFORM_ID_TOKEN)
  1158. Transform_Textures (Texture, (TRANSFORM *)Token.Data);
  1159. Modified_Pnf = TRUE;
  1160. END_CASE
  1161. OTHERWISE
  1162. UNGET
  1163. EXIT
  1164. END_CASE
  1165. END_EXPECT
  1166. }
  1167. else
  1168. {
  1169. /* Here it is not a PLAIN_PATTERN texture and since default textures
  1170. must be plain then this was a texture identifier that was a special
  1171. texture. Allow transforms. The "if(!Modified_Pnf)..." below
  1172. will always fail if we came here. So we return after the
  1173. transforms. */
  1174. Parse_Texture_Transform(Texture);
  1175. }
  1176. /* If we've modified the default texture with a p,n, or f then this
  1177. has to stay a PLAIN_PATTERN pnf texture. We won't allow
  1178. a texture_map or pattern. Therefore quit now.
  1179. */
  1180. if (!Modified_Pnf)
  1181. {
  1182. /* At this point we've either got a texture statement that had
  1183. no p, n or f. Nor any texture identifier. Its probably
  1184. a patterned texture_map texture. It could be an empty
  1185. statement such as "texture{}" */
  1186. EXPECT
  1187. CASE (TILES_TOKEN)
  1188. Destroy_Textures (Texture);
  1189. Texture = Parse_Tiles();
  1190. Parse_Texture_Transform(Texture);
  1191. EXIT
  1192. END_CASE
  1193. CASE (MATERIAL_MAP_TOKEN)
  1194. Destroy_Textures (Texture);
  1195. Texture = Parse_Material_Map ();
  1196. Parse_Texture_Transform(Texture);
  1197. EXIT
  1198. END_CASE
  1199. OTHERWISE
  1200. UNGET;
  1201. Destroy_Pigment(Texture->Pigment);
  1202. Destroy_Tnormal(Texture->Tnormal);
  1203. Destroy_Finish(Texture->Finish);
  1204. Texture->Pigment = NULL;
  1205. Texture->Tnormal = NULL;
  1206. Texture->Finish = NULL;
  1207. Parse_Pattern((TPATTERN *)Texture,TEXTURE_TYPE);
  1208. /* if following is true, parsed "texture{}" so restore
  1209. default texture.
  1210. */
  1211. if (Texture->Type <= PLAIN_PATTERN)
  1212. {
  1213. Destroy_Textures(Texture);
  1214. Texture = Copy_Textures (Default_Texture);
  1215. }
  1216. EXIT
  1217. END_CASE
  1218. END_EXPECT
  1219. }
  1220. return (Texture);
  1221. }
  1222. /*****************************************************************************
  1223. *
  1224. * FUNCTION
  1225. *
  1226. * INPUT
  1227. *
  1228. * OUTPUT
  1229. *
  1230. * RETURNS
  1231. *
  1232. * AUTHOR
  1233. *
  1234. * POV-Ray Team
  1235. *
  1236. * DESCRIPTION
  1237. *
  1238. * CHANGES
  1239. *
  1240. ******************************************************************************/
  1241. static TEXTURE *Parse_Tiles()
  1242. {
  1243. TEXTURE *Texture, *Local_Texture;
  1244. BLEND_MAP_ENTRY *Entry;
  1245. Parse_Begin ();
  1246. Texture = Create_Texture ();
  1247. Destroy_Pigment(Texture->Pigment);
  1248. Destroy_Tnormal(Texture->Tnormal);
  1249. Destroy_Finish(Texture->Finish);
  1250. Texture->Pigment = NULL;
  1251. Texture->Tnormal = NULL;
  1252. Texture->Finish = NULL;
  1253. Texture->Type = CHECKER_PATTERN;
  1254. Texture->Blend_Map = Create_Blend_Map();
  1255. Texture->Blend_Map->Number_Of_Entries = 2;
  1256. Texture->Blend_Map->Blend_Map_Entries = Entry = Create_BMap_Entries (2);
  1257. Texture->Blend_Map->Type = TEXTURE_TYPE;
  1258. Entry[0].Vals.Texture=NULL;
  1259. Entry[0].value=0.0;
  1260. Entry[0].Same=FALSE;
  1261. Entry[1].Vals.Texture=NULL;
  1262. Entry[1].value=1.0;
  1263. Entry[1].Same=FALSE;
  1264. /* Note first tile is 1, 2nd tile is 0 to keep compatible with old tiles */
  1265. EXPECT
  1266. CASE (TEXTURE_TOKEN)
  1267. Parse_Begin ();
  1268. Local_Texture = Parse_Texture ();
  1269. Link_Textures(&(Entry[1].Vals.Texture),Local_Texture);
  1270. Parse_End ();
  1271. END_CASE
  1272. OTHERWISE
  1273. UNGET
  1274. EXIT
  1275. END_CASE
  1276. END_EXPECT
  1277. GET (TILE2_TOKEN);
  1278. EXPECT
  1279. CASE (TEXTURE_TOKEN)
  1280. Parse_Begin ();
  1281. Local_Texture = Parse_Texture ();
  1282. Link_Textures(&(Entry[0].Vals.Texture),Local_Texture);
  1283. Parse_End ();
  1284. END_CASE
  1285. OTHERWISE
  1286. UNGET
  1287. EXIT
  1288. END_CASE
  1289. END_EXPECT
  1290. Parse_End ();
  1291. return (Texture);
  1292. }
  1293. /*****************************************************************************
  1294. *
  1295. * FUNCTION
  1296. *
  1297. * INPUT
  1298. *
  1299. * OUTPUT
  1300. *
  1301. * RETURNS
  1302. *
  1303. * AUTHOR
  1304. *
  1305. * POV-Ray Team
  1306. *
  1307. * DESCRIPTION
  1308. *
  1309. * CHANGES
  1310. *
  1311. ******************************************************************************/
  1312. static TEXTURE *Parse_Material_Map()
  1313. {
  1314. TEXTURE *Texture, *Local_Texture;
  1315. Parse_Begin ();
  1316. Texture = Create_Texture ();
  1317. Destroy_Pigment(Texture->Pigment);
  1318. Destroy_Tnormal(Texture->Tnormal);
  1319. Destroy_Finish(Texture->Finish);
  1320. Texture->Pigment = NULL;
  1321. Texture->Tnormal = NULL;
  1322. Texture->Finish = NULL;
  1323. Texture->Type = BITMAP_PATTERN;
  1324. Texture->Vals.Image = Parse_Image(MATERIAL_FILE);
  1325. Texture->Vals.Image->Use_Colour_Flag = FALSE;
  1326. EXPECT
  1327. CASE (ONCE_TOKEN)
  1328. Texture->Vals.Image->Once_Flag=TRUE;
  1329. END_CASE
  1330. CASE (INTERPOLATE_TOKEN)
  1331. Texture->Vals.Image->Interpolation_Type=(int)Parse_Float();
  1332. END_CASE
  1333. CASE (MAP_TYPE_TOKEN)
  1334. Texture->Vals.Image->Map_Type = (int) Parse_Float ();
  1335. END_CASE
  1336. OTHERWISE
  1337. UNGET
  1338. EXIT
  1339. END_CASE
  1340. END_EXPECT
  1341. GET (TEXTURE_TOKEN) /* First material */
  1342. Parse_Begin();
  1343. Texture->Materials = Local_Texture = Parse_Texture ();
  1344. Parse_End();
  1345. Texture->Num_Of_Mats++;
  1346. EXPECT /* Subsequent materials */
  1347. CASE (TEXTURE_TOKEN)
  1348. Parse_Begin();
  1349. Local_Texture->Next_Material = Parse_Texture ();
  1350. Parse_End();
  1351. Local_Texture = Local_Texture->Next_Material;
  1352. Texture->Num_Of_Mats++;
  1353. END_CASE
  1354. OTHERWISE
  1355. UNGET
  1356. EXIT
  1357. END_CASE
  1358. END_EXPECT
  1359. Parse_End ();
  1360. return(Texture);
  1361. }
  1362. /*****************************************************************************
  1363. *
  1364. * FUNCTION
  1365. *
  1366. * INPUT
  1367. *
  1368. * OUTPUT
  1369. *
  1370. * RETURNS
  1371. *
  1372. * AUTHOR
  1373. *
  1374. * POV-Ray Team
  1375. *
  1376. * DESCRIPTION
  1377. *
  1378. * CHANGES
  1379. *
  1380. ******************************************************************************/
  1381. static TEXTURE *Parse_Vers1_Texture ()
  1382. {
  1383. VECTOR Local_Vector;
  1384. COLOUR Local_Colour;
  1385. MATRIX Local_Matrix;
  1386. TRANSFORM Local_Trans;
  1387. TURB *Local_Turb;
  1388. TEXTURE *Texture;
  1389. PIGMENT *Pigment;
  1390. TNORMAL *Tnormal;
  1391. FINISH *Finish;
  1392. EXPECT /* Look for texture_body */
  1393. CASE (TILES_TOKEN)
  1394. Texture = Parse_Tiles();
  1395. EXIT
  1396. END_CASE
  1397. CASE (MATERIAL_MAP_TOKEN)
  1398. Texture = Parse_Material_Map ();
  1399. EXIT
  1400. END_CASE
  1401. CASE (TEXTURE_ID_TOKEN)
  1402. Texture = Copy_Textures((TEXTURE *) Token.Data);
  1403. EXIT
  1404. END_CASE
  1405. OTHERWISE
  1406. UNGET
  1407. Texture = Copy_Textures (Default_Texture);
  1408. EXIT
  1409. END_CASE
  1410. END_EXPECT
  1411. /* Look for [pnf_texture] */
  1412. if (Texture->Type == PLAIN_PATTERN)
  1413. {
  1414. EXPECT /* Look for [pnf_ids] */
  1415. CASE (PIGMENT_ID_TOKEN)
  1416. Destroy_Pigment(Texture->Pigment);
  1417. Texture->Pigment = Copy_Pigment ((PIGMENT *) Token.Data);
  1418. END_CASE
  1419. CASE (TNORMAL_ID_TOKEN)
  1420. Destroy_Tnormal(Texture->Tnormal);
  1421. Texture->Tnormal = Copy_Tnormal ((TNORMAL *) Token.Data);
  1422. END_CASE
  1423. CASE (FINISH_ID_TOKEN)
  1424. Destroy_Finish(Texture->Finish);
  1425. Texture->Finish = Copy_Finish ((FINISH *) Token.Data);
  1426. END_CASE
  1427. OTHERWISE
  1428. UNGET
  1429. EXIT
  1430. END_CASE
  1431. END_EXPECT
  1432. Pigment = Texture->Pigment;
  1433. Tnormal = Texture->Tnormal;
  1434. Finish = Texture->Finish;
  1435. EXPECT
  1436. CASE (PIGMENT_TOKEN)
  1437. Parse_Begin ();
  1438. Parse_Pigment ( &(Texture->Pigment) );
  1439. Parse_End ();
  1440. END_CASE
  1441. CASE (TNORMAL_TOKEN)
  1442. Parse_Begin ();
  1443. Parse_Tnormal ( &(Texture->Tnormal) );
  1444. Parse_End ();
  1445. END_CASE
  1446. CASE (FINISH_TOKEN)
  1447. Parse_Finish ( &(Texture->Finish) );
  1448. END_CASE
  1449. /***********************************************************************
  1450. PIGMENT STUFF OUTSIDE PIGMENT{}
  1451. NOTE: Do not add new keywords to this section. Use 1.0 syntax only.
  1452. ***********************************************************************/
  1453. CASE (AGATE_TOKEN)
  1454. Warn_State(Token.Token_Id, PIGMENT_TOKEN);
  1455. Pigment->Type = AGATE_PATTERN;
  1456. Pigment->Vals.Agate_Turb_Scale = 1.0;
  1457. Check_Turb(&(Pigment->Warps)); /* agate needs Octaves, Lambda etc. */
  1458. END_CASE
  1459. CASE (BOZO_TOKEN)
  1460. Warn_State(Token.Token_Id, PIGMENT_TOKEN);
  1461. Pigment->Type = BOZO_PATTERN;
  1462. END_CASE
  1463. CASE (GRANITE_TOKEN)
  1464. Warn_State(Token.Token_Id, PIGMENT_TOKEN);
  1465. Pigment->Type = GRANITE_PATTERN;
  1466. END_CASE
  1467. CASE (LEOPARD_TOKEN)
  1468. Warn_State(Token.Token_Id, PIGMENT_TOKEN);
  1469. Pigment->Type = LEOPARD_PATTERN;
  1470. END_CASE
  1471. CASE (MARBLE_TOKEN)
  1472. Warn_State(Token.Token_Id, PIGMENT_TOKEN);
  1473. Pigment->Type = MARBLE_PATTERN;
  1474. END_CASE
  1475. CASE (MANDEL_TOKEN)
  1476. Warn_State(Token.Token_Id, PIGMENT_TOKEN);
  1477. Pigment->Type = MANDEL_PATTERN;
  1478. Pigment->Vals.Iterations = (int)Parse_Float();
  1479. END_CASE
  1480. CASE (ONION_TOKEN)
  1481. Warn_State(Token.Token_Id, PIGMENT_TOKEN);
  1482. Pigment->Type = ONION_PATTERN;
  1483. END_CASE
  1484. CASE (SPOTTED_TOKEN)
  1485. Warn_State(Token.Token_Id, PIGMENT_TOKEN);
  1486. Pigment->Type = SPOTTED_PATTERN;
  1487. END_CASE
  1488. CASE (WOOD_TOKEN)
  1489. Warn_State(Token.Token_Id, PIGMENT_TOKEN);
  1490. Pigment->Type = WOOD_PATTERN;
  1491. END_CASE
  1492. CASE (GRADIENT_TOKEN)
  1493. Warn_State(Token.Token_Id, PIGMENT_TOKEN);
  1494. Pigment->Type = GRADIENT_PATTERN;
  1495. Parse_Vector (Pigment->Vals.Gradient);
  1496. END_CASE
  1497. CASE_COLOUR
  1498. Warn_State(Token.Token_Id, PIGMENT_TOKEN);
  1499. Pigment->Type = PLAIN_PATTERN;
  1500. Parse_Colour (Pigment->Colour);
  1501. END_CASE
  1502. CASE (CHECKER_TOKEN)
  1503. Warn_State(Token.Token_Id, PIGMENT_TOKEN);
  1504. Pigment->Type = CHECKER_PATTERN;
  1505. Pigment->Frequency = 0.0;
  1506. Destroy_Blend_Map(Pigment->Blend_Map);
  1507. Pigment->Blend_Map = Parse_Blend_List(2,&Check_Default_Map,COLOUR_TYPE);
  1508. END_CASE
  1509. CASE (HEXAGON_TOKEN)
  1510. Warn_State(Token.Token_Id, PIGMENT_TOKEN);
  1511. Pigment->Type = HEXAGON_PATTERN;
  1512. Pigment->Frequency = 0.0;
  1513. Destroy_Blend_Map(Pigment->Blend_Map);
  1514. Pigment->Blend_Map = Parse_Blend_List(3,&Hex_Default_Map,COLOUR_TYPE);
  1515. END_CASE
  1516. CASE (IMAGE_MAP_TOKEN)
  1517. Warn_State(Token.Token_Id, PIGMENT_TOKEN);
  1518. Pigment->Type = BITMAP_PATTERN;
  1519. Pigment->Frequency = 0.0;
  1520. Parse_Image_Map (Pigment);
  1521. END_CASE
  1522. CASE (TURBULENCE_TOKEN)
  1523. Local_Turb=Check_Turb(&(Pigment->Warps));
  1524. Parse_Vector(Local_Turb->Turbulence);
  1525. END_CASE
  1526. CASE (COLOUR_MAP_TOKEN)
  1527. Warn_State(Token.Token_Id, PIGMENT_TOKEN);
  1528. if (Pigment->Type == CHECKER_PATTERN ||
  1529. Pigment->Type == HEXAGON_PATTERN ||
  1530. Pigment->Type == PLAIN_PATTERN ||
  1531. Pigment->Type == BITMAP_PATTERN)
  1532. Warn(1.5, "Cannot use color map with this pigment type.");
  1533. Destroy_Blend_Map(Pigment->Blend_Map);
  1534. Pigment->Blend_Map = Parse_Colour_Map ();
  1535. END_CASE
  1536. CASE (QUICK_COLOUR_TOKEN)
  1537. Warn_State(Token.Token_Id, PIGMENT_TOKEN);
  1538. Parse_Colour (Local_Colour);
  1539. if (opts.Quality_Flags & Q_QUICKC)
  1540. {
  1541. Assign_Colour(Pigment->Colour,Local_Colour);
  1542. }
  1543. END_CASE
  1544. CASE (OCTAVES_TOKEN)
  1545. Local_Turb=Check_Turb(&(Pigment->Warps));
  1546. Local_Turb->Octaves = (int)Parse_Float();
  1547. if(Local_Turb->Octaves < 1)
  1548. Local_Turb->Octaves = 1;
  1549. if(Local_Turb->Octaves > 10) /* Avoid DOMAIN errors */
  1550. Local_Turb->Octaves = 10;
  1551. END_CASE
  1552. CASE (OMEGA_TOKEN)
  1553. Local_Turb=Check_Turb(&(Pigment->Warps));
  1554. Local_Turb->Omega = Parse_Float();
  1555. END_CASE
  1556. CASE (LAMBDA_TOKEN)
  1557. Local_Turb=Check_Turb(&(Pigment->Warps));
  1558. Local_Turb->Lambda = Parse_Float();
  1559. END_CASE
  1560. /***********************************************************************
  1561. TNORMAL STUFF OUTSIDE NORMAL{}
  1562. NOTE: Do not add new keywords to this section. Use 1.0 syntax only.
  1563. ***********************************************************************/
  1564. CASE (BUMPS_TOKEN)
  1565. Warn_State(Token.Token_Id, TNORMAL_TOKEN);
  1566. ADD_TNORMAL
  1567. Tnormal->Type = BUMPS_PATTERN;
  1568. Tnormal->Amount = Parse_Float ();
  1569. END_CASE
  1570. CASE (DENTS_TOKEN)
  1571. Warn_State(Token.Token_Id, TNORMAL_TOKEN);
  1572. ADD_TNORMAL
  1573. Tnormal->Type = DENTS_PATTERN;
  1574. Tnormal->Amount = Parse_Float ();
  1575. END_CASE
  1576. CASE (RIPPLES_TOKEN)
  1577. Warn_State(Token.Token_Id, TNORMAL_TOKEN);
  1578. ADD_TNORMAL
  1579. Tnormal->Type = RIPPLES_PATTERN;
  1580. Tnormal->Amount = Parse_Float ();
  1581. END_CASE
  1582. CASE (WAVES_TOKEN)
  1583. Warn_State(Token.Token_Id, TNORMAL_TOKEN);
  1584. ADD_TNORMAL
  1585. Tnormal->Type = WAVES_PATTERN;
  1586. Tnormal->Amount = Parse_Float ();
  1587. END_CASE
  1588. CASE (WRINKLES_TOKEN)
  1589. Warn_State(Token.Token_Id, TNORMAL_TOKEN);
  1590. ADD_TNORMAL
  1591. Tnormal->Type = WRINKLES_PATTERN;
  1592. Tnormal->Amount = Parse_Float ();
  1593. END_CASE
  1594. CASE (BUMP_MAP_TOKEN)
  1595. Warn_State(Token.Token_Id, TNORMAL_TOKEN);
  1596. ADD_TNORMAL
  1597. Tnormal->Type = BITMAP_PATTERN;
  1598. Tnormal->Frequency = 0.0;
  1599. Parse_Bump_Map (Tnormal);
  1600. END_CASE
  1601. CASE (FREQUENCY_TOKEN)
  1602. Warn_State(Token.Token_Id, TNORMAL_TOKEN);
  1603. ADD_TNORMAL
  1604. if (!(Tnormal->Type == RIPPLES_PATTERN || Tnormal->Type == WAVES_PATTERN))
  1605. if (opts.Language_Version >= 1.5)
  1606. Warn(1.5, "Cannot use frequency with this normal.");
  1607. Tnormal->Frequency = Parse_Float();
  1608. END_CASE
  1609. CASE (PHASE_TOKEN)
  1610. Warn_State(Token.Token_Id, TNORMAL_TOKEN);
  1611. ADD_TNORMAL
  1612. if (!(Tnormal->Type == RIPPLES_PATTERN || Tnormal->Type == WAVES_PATTERN))
  1613. if (opts.Language_Version >= 1.5)
  1614. Warn(1.5, "Cannot use phase with this normal.");
  1615. Tnormal->Phase = Parse_Float();
  1616. END_CASE
  1617. /***********************************************************************
  1618. FINISH STUFF OUTSIDE FINISH{}
  1619. NOTE: Do not add new keywords to this section. Use 1.0 syntax only.
  1620. ***********************************************************************/
  1621. CASE (AMBIENT_TOKEN)
  1622. Warn_State(Token.Token_Id, FINISH_TOKEN);
  1623. Finish->Ambient[RED] =
  1624. Finish->Ambient[GREEN] =
  1625. Finish->Ambient[BLUE] = Parse_Float ();
  1626. END_CASE
  1627. CASE (BRILLIANCE_TOKEN)
  1628. Warn_State(Token.Token_Id, FINISH_TOKEN);
  1629. Finish->Brilliance = Parse_Float ();
  1630. END_CASE
  1631. CASE (DIFFUSE_TOKEN)
  1632. Warn_State(Token.Token_Id, FINISH_TOKEN);
  1633. Finish->Diffuse = Parse_Float ();
  1634. END_CASE
  1635. CASE (REFLECTION_TOKEN)
  1636. Warn_State(Token.Token_Id, FINISH_TOKEN);
  1637. Finish->Reflection[RED] =
  1638. Finish->Reflection[GREEN] =
  1639. Finish->Reflection[BLUE] = Parse_Float ();
  1640. END_CASE
  1641. CASE (PHONG_TOKEN)
  1642. Warn_State(Token.Token_Id, FINISH_TOKEN);
  1643. Finish->Phong = Parse_Float ();
  1644. END_CASE
  1645. CASE (PHONG_SIZE_TOKEN)
  1646. Warn_State(Token.Token_Id, FINISH_TOKEN);
  1647. Finish->Phong_Size = Parse_Float ();
  1648. END_CASE
  1649. CASE (SPECULAR_TOKEN)
  1650. Warn_State(Token.Token_Id, FINISH_TOKEN);
  1651. Finish->Specular = Parse_Float ();
  1652. END_CASE
  1653. CASE (ROUGHNESS_TOKEN)
  1654. Warn_State(Token.Token_Id, FINISH_TOKEN);
  1655. Finish->Roughness = Parse_Float ();
  1656. if (Finish->Roughness != 0.0)
  1657. Finish->Roughness = 1.0/Finish->Roughness; /* CEY 12/92 */
  1658. else
  1659. Warn(0.0, "Zero roughness used.");
  1660. END_CASE
  1661. CASE (METALLIC_TOKEN)
  1662. Warn_State(Token.Token_Id, FINISH_TOKEN);
  1663. Finish->Metallic = 1.0;
  1664. END_CASE
  1665. CASE (CRAND_TOKEN)
  1666. Warn_State(Token.Token_Id, FINISH_TOKEN);
  1667. Finish->Crand = Parse_Float();
  1668. END_CASE
  1669. CASE_FLOAT
  1670. Finish->Crand = Parse_Float();
  1671. Warn(1.5, "Should use crand keyword in finish statement.");
  1672. END_CASE
  1673. CASE (IOR_TOKEN)
  1674. Warn_State(Token.Token_Id, INTERIOR_TOKEN);
  1675. Finish->Temp_IOR = Parse_Float();
  1676. Warn_Interior("Index of refraction value");
  1677. END_CASE
  1678. CASE (REFRACTION_TOKEN)
  1679. Warn_State(Token.Token_Id, INTERIOR_TOKEN);
  1680. Finish->Temp_Refract = Parse_Float();
  1681. Warn_Interior("Refraction value unnecessary to turn on refraction.\nTo attenuate, the fade_power and fade_distance keywords ");
  1682. END_CASE
  1683. CASE (TRANSLATE_TOKEN)
  1684. Parse_Vector (Local_Vector);
  1685. Compute_Translation_Transform(&Local_Trans, Local_Vector);
  1686. Transform_Textures (Texture, &Local_Trans);
  1687. END_CASE
  1688. CASE (ROTATE_TOKEN)
  1689. Parse_Vector (Local_Vector);
  1690. Compute_Rotation_Transform(&Local_Trans, Local_Vector);
  1691. Transform_Textures (Texture, &Local_Trans);
  1692. END_CASE
  1693. CASE (SCALE_TOKEN)
  1694. Parse_Scale_Vector (Local_Vector);
  1695. Compute_Scaling_Transform(&Local_Trans, Local_Vector);
  1696. Transform_Textures (Texture, &Local_Trans);
  1697. END_CASE
  1698. CASE (MATRIX_TOKEN)
  1699. Parse_Matrix(Local_Matrix);
  1700. Compute_Matrix_Transform(&Local_Trans, Local_Matrix);
  1701. Transform_Textures (Texture, &Local_Trans);
  1702. END_CASE
  1703. CASE (TRANSFORM_TOKEN)
  1704. GET(TRANSFORM_ID_TOKEN)
  1705. Transform_Textures (Texture, (TRANSFORM *)Token.Data);
  1706. END_CASE
  1707. CASE (TEXTURE_ID_TOKEN)
  1708. Warn(0.0, "Texture identifier overwriting previous values.");
  1709. Destroy_Textures(Texture);
  1710. Texture = Copy_Textures((TEXTURE *) Token.Data);
  1711. Pigment = Texture->Pigment;
  1712. Tnormal = Texture->Tnormal;
  1713. Finish = Texture->Finish;
  1714. END_CASE
  1715. OTHERWISE
  1716. UNGET
  1717. EXIT
  1718. END_CASE
  1719. /***********************************************************************/
  1720. END_EXPECT
  1721. if (Not_In_Default && (Texture->Pigment->Type == NO_PATTERN) &&
  1722. !(opts.Language_Version < 1.5))
  1723. Parse_Error(PIGMENT_ID_TOKEN);
  1724. }
  1725. Parse_Texture_Transform(Texture);
  1726. return (Texture);
  1727. }
  1728. /*****************************************************************************
  1729. *
  1730. * FUNCTION
  1731. *
  1732. * INPUT
  1733. *
  1734. * OUTPUT
  1735. *
  1736. * RETURNS
  1737. *
  1738. * AUTHOR
  1739. *
  1740. * POV-Ray Team
  1741. *
  1742. * DESCRIPTION
  1743. *
  1744. * CHANGES
  1745. *
  1746. ******************************************************************************/
  1747. static void Parse_Texture_Transform (TEXTURE *Texture)
  1748. {
  1749. VECTOR Local_Vector;
  1750. MATRIX Local_Matrix;
  1751. TRANSFORM Local_Trans;
  1752. EXPECT
  1753. CASE (TRANSLATE_TOKEN)
  1754. Parse_Vector (Local_Vector);
  1755. Compute_Translation_Transform(&Local_Trans, Local_Vector);
  1756. Transform_Textures (Texture, &Local_Trans);
  1757. END_CASE
  1758. CASE (ROTATE_TOKEN)
  1759. Parse_Vector (Local_Vector);
  1760. Compute_Rotation_Transform(&Local_Trans, Local_Vector);
  1761. Transform_Textures (Texture, &Local_Trans);
  1762. END_CASE
  1763. CASE (SCALE_TOKEN)
  1764. Parse_Scale_Vector (Local_Vector);
  1765. Compute_Scaling_Transform(&Local_Trans, Local_Vector);
  1766. Transform_Textures (Texture, &Local_Trans);
  1767. END_CASE
  1768. CASE (MATRIX_TOKEN)
  1769. Parse_Matrix(Local_Matrix);
  1770. Compute_Matrix_Transform(&Local_Trans, Local_Matrix);
  1771. Transform_Textures (Texture, &Local_Trans);
  1772. END_CASE
  1773. CASE (TRANSFORM_TOKEN)
  1774. GET(TRANSFORM_ID_TOKEN)
  1775. Transform_Textures (Texture, (TRANSFORM *)Token.Data);
  1776. END_CASE
  1777. OTHERWISE
  1778. UNGET
  1779. EXIT
  1780. END_CASE
  1781. END_EXPECT
  1782. }
  1783. /*****************************************************************************
  1784. *
  1785. * FUNCTION
  1786. *
  1787. * Parse_Media
  1788. *
  1789. * INPUT
  1790. *
  1791. * OUTPUT
  1792. *
  1793. * RETURNS
  1794. *
  1795. * AUTHOR
  1796. *
  1797. * Dieter Bayer
  1798. *
  1799. * DESCRIPTION
  1800. *
  1801. * -
  1802. *
  1803. * CHANGES
  1804. *
  1805. * Dec 1996 : Creation.
  1806. *
  1807. ******************************************************************************/
  1808. void Parse_Media(IMEDIA **Media_Ptr)
  1809. {
  1810. IMEDIA *IMedia, *Next_Media;
  1811. TRANSFORM Local_Trans;
  1812. VECTOR Local_Vector;
  1813. MATRIX Local_Matrix;
  1814. Next_Media = *Media_Ptr;
  1815. Parse_Begin();
  1816. EXPECT
  1817. CASE(MEDIA_ID_TOKEN)
  1818. IMedia = Copy_Media((IMEDIA *)Token.Data);
  1819. EXIT
  1820. END_CASE
  1821. OTHERWISE
  1822. UNGET
  1823. IMedia = Create_Media();
  1824. EXIT
  1825. END_CASE
  1826. END_EXPECT
  1827. EXPECT
  1828. CASE (INTERVALS_TOKEN)
  1829. if ((IMedia->Intervals = (int)Parse_Float()) < 1)
  1830. {
  1831. Error("At least one interval is needed in media.\n");
  1832. }
  1833. END_CASE
  1834. CASE (SAMPLES_TOKEN)
  1835. IMedia->Min_Samples = (int)Parse_Float();
  1836. Parse_Comma();
  1837. IMedia->Max_Samples = (int)Parse_Float();
  1838. if (IMedia->Min_Samples < 1)
  1839. {
  1840. Error("At least one sample per interval is needed in media.\n");
  1841. }
  1842. if (IMedia->Max_Samples < IMedia->Min_Samples)
  1843. {
  1844. Error("Maximum number of samples per interval smaller than minimum number.\n");
  1845. }
  1846. END_CASE
  1847. CASE (ABSORPTION_TOKEN)
  1848. Parse_Colour(IMedia->Absorption);
  1849. END_CASE
  1850. CASE (EMISSION_TOKEN)
  1851. Parse_Colour(IMedia->Emission);
  1852. END_CASE
  1853. CASE (SCATTERING_TOKEN)
  1854. Parse_Begin();
  1855. IMedia->Type = (int)Parse_Float();
  1856. if ((IMedia->Type < 1) || (IMedia->Type > SCATTERING_TYPES))
  1857. {
  1858. Warn(0.0, "Unknown atmospheric scattering type.");
  1859. }
  1860. Parse_Comma();
  1861. Parse_Colour(IMedia->Scattering);
  1862. EXPECT
  1863. CASE (ECCENTRICITY_TOKEN)
  1864. if (IMedia->Type != HENYEY_GREENSTEIN_SCATTERING)
  1865. {
  1866. Error("Eccentricity cannot be used with this scattering type.");
  1867. }
  1868. IMedia->Eccentricity = Parse_Float();
  1869. END_CASE
  1870. CASE (EXTINCTION_TOKEN)
  1871. IMedia->sc_ext = Parse_Float();
  1872. END_CASE
  1873. OTHERWISE
  1874. UNGET
  1875. EXIT
  1876. END_CASE
  1877. END_EXPECT
  1878. Parse_End();
  1879. END_CASE
  1880. CASE (CONFIDENCE_TOKEN)
  1881. IMedia->Confidence = Parse_Float();
  1882. if ((IMedia->Confidence <= 0.0) || (IMedia->Confidence >= 1.0))
  1883. {
  1884. Error("Illegal confidence value in media.\n");
  1885. }
  1886. END_CASE
  1887. CASE (VARIANCE_TOKEN)
  1888. IMedia->Variance = Parse_Float();
  1889. END_CASE
  1890. CASE (RATIO_TOKEN)
  1891. IMedia->Ratio = Parse_Float();
  1892. END_CASE
  1893. CASE (DENSITY_TOKEN)
  1894. Parse_Begin();
  1895. Parse_Media_Density_Pattern(&(IMedia->Density));
  1896. Parse_End();
  1897. END_CASE
  1898. CASE (TRANSLATE_TOKEN)
  1899. Parse_Vector (Local_Vector);
  1900. Compute_Translation_Transform(&Local_Trans, Local_Vector);
  1901. Transform_Density (IMedia->Density, &Local_Trans);
  1902. END_CASE
  1903. CASE (ROTATE_TOKEN)
  1904. Parse_Vector (Local_Vector);
  1905. Compute_Rotation_Transform(&Local_Trans, Local_Vector);
  1906. Transform_Density (IMedia->Density, &Local_Trans);
  1907. END_CASE
  1908. CASE (SCALE_TOKEN)
  1909. Parse_Scale_Vector (Local_Vector);
  1910. Compute_Scaling_Transform(&Local_Trans, Local_Vector);
  1911. Transform_Density (IMedia->Density, &Local_Trans);
  1912. END_CASE
  1913. CASE (MATRIX_TOKEN)
  1914. Parse_Matrix(Local_Matrix);
  1915. Compute_Matrix_Transform(&Local_Trans, Local_Matrix);
  1916. Transform_Density (IMedia->Density, &Local_Trans);
  1917. END_CASE
  1918. CASE (TRANSFORM_TOKEN)
  1919. GET(TRANSFORM_ID_TOKEN)
  1920. Transform_Density (IMedia->Density, &Local_Trans);
  1921. END_CASE
  1922. OTHERWISE
  1923. UNGET
  1924. EXIT
  1925. END_CASE
  1926. END_EXPECT
  1927. Parse_End();
  1928. IMedia->Next_Media = Next_Media;
  1929. *Media_Ptr = IMedia;
  1930. }
  1931. /*****************************************************************************
  1932. *
  1933. * FUNCTION
  1934. *
  1935. * Parse_Interior
  1936. *
  1937. * INPUT
  1938. *
  1939. * OUTPUT
  1940. *
  1941. * RETURNS
  1942. *
  1943. * AUTHOR
  1944. *
  1945. * Dieter Bayer
  1946. *
  1947. * DESCRIPTION
  1948. *
  1949. * -
  1950. *
  1951. * CHANGES
  1952. *
  1953. * Jan 1997 : Creation.
  1954. *
  1955. ******************************************************************************/
  1956. void Parse_Interior(INTERIOR **Interior_Ptr)
  1957. {
  1958. INTERIOR *Interior;
  1959. Parse_Begin();
  1960. EXPECT
  1961. CASE(INTERIOR_ID_TOKEN)
  1962. Destroy_Interior(*Interior_Ptr);
  1963. *Interior_Ptr = Copy_Interior((INTERIOR *)Token.Data);
  1964. EXIT
  1965. END_CASE
  1966. OTHERWISE
  1967. UNGET
  1968. EXIT
  1969. END_CASE
  1970. END_EXPECT
  1971. if(*Interior_Ptr == NULL)
  1972. {
  1973. *Interior_Ptr = Create_Interior();
  1974. }
  1975. Interior = *Interior_Ptr;
  1976. EXPECT
  1977. CASE (IOR_TOKEN)
  1978. Interior->IOR = Parse_Float();
  1979. END_CASE
  1980. CASE (CAUSTICS_TOKEN)
  1981. Interior->Caustics = Parse_Float() * 45.0;
  1982. END_CASE
  1983. CASE (FADE_DISTANCE_TOKEN)
  1984. Interior->Fade_Distance = Parse_Float();
  1985. END_CASE
  1986. CASE (FADE_POWER_TOKEN)
  1987. Interior->Fade_Power = Parse_Float();
  1988. END_CASE
  1989. CASE (MEDIA_TOKEN)
  1990. Parse_Media((IMEDIA **)(&Interior->IMedia));
  1991. END_CASE
  1992. CASE (REFRACTION_TOKEN)
  1993. Interior->Old_Refract = Parse_Float();
  1994. Warn_Interior("Refraction value unnecessary to turn on refraction.\nTo attenuate, the fade_power and fade_distance keywords ");
  1995. END_CASE
  1996. OTHERWISE
  1997. UNGET
  1998. EXIT
  1999. END_CASE
  2000. END_EXPECT
  2001. Parse_End();
  2002. Init_Interior(Interior);
  2003. }
  2004. /*****************************************************************************
  2005. *
  2006. * FUNCTION
  2007. *
  2008. * Parse_Media_Density_Pattern
  2009. *
  2010. * INPUT
  2011. *
  2012. * OUTPUT
  2013. *
  2014. * RETURNS
  2015. *
  2016. * AUTHOR
  2017. *
  2018. * Dieter Bayer
  2019. *
  2020. * DESCRIPTION
  2021. *
  2022. * -
  2023. *
  2024. * CHANGES
  2025. *
  2026. * Dez 1996 : Creation.
  2027. *
  2028. ******************************************************************************/
  2029. void Parse_Media_Density_Pattern(PIGMENT **Density_Ptr)
  2030. {
  2031. PIGMENT *New;
  2032. EXPECT
  2033. CASE (DENSITY_ID_TOKEN)
  2034. New = Copy_Pigment ((PIGMENT *) Token.Data);
  2035. EXIT
  2036. END_CASE
  2037. OTHERWISE
  2038. New = Create_Pigment();
  2039. UNGET
  2040. EXIT
  2041. END_CASE
  2042. END_EXPECT
  2043. Parse_Pattern((TPATTERN *)New,DENSITY_TYPE);
  2044. New->Next = (TPATTERN *)(*Density_Ptr);
  2045. *Density_Ptr = New;
  2046. }
  2047. /*****************************************************************************
  2048. *
  2049. * FUNCTION
  2050. *
  2051. * INPUT
  2052. *
  2053. * OUTPUT
  2054. *
  2055. * RETURNS
  2056. *
  2057. * AUTHOR
  2058. *
  2059. * POV-Ray Team
  2060. *
  2061. * DESCRIPTION
  2062. *
  2063. * CHANGES
  2064. *
  2065. ******************************************************************************/
  2066. FOG *Parse_Fog()
  2067. {
  2068. VECTOR Vector;
  2069. MATRIX Matrix;
  2070. TRANSFORM Trans;
  2071. FOG *Fog;
  2072. Parse_Begin();
  2073. EXPECT
  2074. CASE(FOG_ID_TOKEN)
  2075. Fog = Copy_Fog ((FOG *) Token.Data);
  2076. EXIT
  2077. END_CASE
  2078. OTHERWISE
  2079. UNGET
  2080. Fog = Create_Fog();
  2081. EXIT
  2082. END_CASE
  2083. END_EXPECT
  2084. EXPECT
  2085. CASE_COLOUR
  2086. Parse_Colour(Fog->Colour);
  2087. END_CASE
  2088. CASE (DISTANCE_TOKEN)
  2089. Fog->Distance = Parse_Float();
  2090. END_CASE
  2091. CASE_FLOAT
  2092. Warn(1.5, "Should use distance keyword.");
  2093. Fog->Distance = Parse_Float();
  2094. END_CASE
  2095. CASE (FOG_TYPE_TOKEN)
  2096. Fog->Type = (int)Parse_Float();
  2097. if ((Fog->Type < ORIG_FOG) || (Fog->Type > FOG_TYPES))
  2098. {
  2099. Warn(0.0, "Unknown fog type.");
  2100. }
  2101. END_CASE
  2102. CASE (FOG_ALT_TOKEN)
  2103. Fog->Alt = Parse_Float();
  2104. END_CASE
  2105. CASE (FOG_OFFSET_TOKEN)
  2106. Fog->Offset = Parse_Float();
  2107. END_CASE
  2108. CASE (TURB_DEPTH_TOKEN)
  2109. Fog->Turb_Depth = Parse_Float();
  2110. END_CASE
  2111. CASE (UP_TOKEN)
  2112. Parse_Vector(Fog->Up);
  2113. END_CASE
  2114. CASE (TURBULENCE_TOKEN)
  2115. if (Fog->Turb == NULL)
  2116. {
  2117. Fog->Turb=(TURB *)Create_Warp(CLASSIC_TURB_WARP);
  2118. }
  2119. Parse_Vector(Fog->Turb->Turbulence);
  2120. END_CASE
  2121. CASE (OCTAVES_TOKEN)
  2122. if (Fog->Turb == NULL)
  2123. {
  2124. Fog->Turb=(TURB *)Create_Warp(CLASSIC_TURB_WARP);
  2125. }
  2126. Fog->Turb->Octaves = (int)Parse_Float();
  2127. if(Fog->Turb->Octaves < 1)
  2128. Fog->Turb->Octaves = 1;
  2129. if(Fog->Turb->Octaves > 10)
  2130. Fog->Turb->Octaves = 10;
  2131. END_CASE
  2132. CASE (OMEGA_TOKEN)
  2133. if (Fog->Turb == NULL)
  2134. {
  2135. Fog->Turb=(TURB *)Create_Warp(CLASSIC_TURB_WARP);
  2136. }
  2137. Fog->Turb->Omega = Parse_Float();
  2138. END_CASE
  2139. CASE (LAMBDA_TOKEN)
  2140. if (Fog->Turb == NULL)
  2141. {
  2142. Fog->Turb=(TURB *)Create_Warp(CLASSIC_TURB_WARP);
  2143. }
  2144. Fog->Turb->Lambda = Parse_Float();
  2145. END_CASE
  2146. CASE (ROTATE_TOKEN)
  2147. Parse_Vector(Vector);
  2148. Compute_Rotation_Transform(&Trans, Vector);
  2149. MTransDirection(Fog->Up, Fog->Up, &Trans);
  2150. END_CASE
  2151. CASE (SCALE_TOKEN)
  2152. Parse_Vector(Vector);
  2153. Compute_Scaling_Transform(&Trans, Vector);
  2154. MTransDirection(Fog->Up, Fog->Up, &Trans);
  2155. END_CASE
  2156. CASE (TRANSLATE_TOKEN)
  2157. Parse_Vector(Vector);
  2158. Warn(0.0, "A fog's up vector can't be translated.");
  2159. /*
  2160. Compute_Translation_Transform(&Trans, Vector);
  2161. MTransDirection(Fog->Up, Fog->Up, &Trans);
  2162. */
  2163. END_CASE
  2164. CASE (MATRIX_TOKEN)
  2165. Parse_Matrix(Matrix);
  2166. Compute_Matrix_Transform(&Trans, Matrix);
  2167. MTransDirection(Fog->Up, Fog->Up, &Trans);
  2168. END_CASE
  2169. CASE (TRANSFORM_TOKEN)
  2170. GET(TRANSFORM_ID_TOKEN)
  2171. MTransDirection(Fog->Up, Fog->Up, (TRANSFORM *)Token.Data);
  2172. END_CASE
  2173. OTHERWISE
  2174. UNGET
  2175. EXIT
  2176. END_CASE
  2177. END_EXPECT
  2178. Parse_End ();
  2179. /* Make sure the up vector is normalized. */
  2180. VNormalize(Fog->Up, Fog->Up);
  2181. return(Fog);
  2182. }
  2183. /*****************************************************************************
  2184. *
  2185. * FUNCTION
  2186. *
  2187. * Parse_Rainbow
  2188. *
  2189. * INPUT
  2190. *
  2191. * OUTPUT
  2192. *
  2193. * RETURNS
  2194. *
  2195. * AUTHOR
  2196. *
  2197. * Dieter Bayer
  2198. *
  2199. * DESCRIPTION
  2200. *
  2201. * -
  2202. *
  2203. * CHANGES
  2204. *
  2205. * Jul 1994 : Creation.
  2206. *
  2207. * Dec 1994 : Modified to work with multiple rainbows. [DB]
  2208. *
  2209. * Apr 1995 : Added code for rainbow arcs. [DB]
  2210. *
  2211. ******************************************************************************/
  2212. RAINBOW *Parse_Rainbow()
  2213. {
  2214. int Angle1, Angle2;
  2215. DBL dot;
  2216. RAINBOW *Rainbow;
  2217. Angle1 = Angle2 = FALSE;
  2218. Parse_Begin();
  2219. EXPECT
  2220. CASE(RAINBOW_ID_TOKEN)
  2221. Rainbow = Copy_Rainbow ((RAINBOW *) Token.Data);
  2222. EXIT
  2223. END_CASE
  2224. OTHERWISE
  2225. UNGET
  2226. Rainbow = Create_Rainbow();
  2227. EXIT
  2228. END_CASE
  2229. END_EXPECT
  2230. EXPECT
  2231. CASE (ANGLE_TOKEN)
  2232. Rainbow->Angle = Parse_Float();
  2233. END_CASE
  2234. CASE (DIRECTION_TOKEN)
  2235. Parse_Vector(Rainbow->Antisolar_Vector);
  2236. END_CASE
  2237. CASE (COLOUR_MAP_TOKEN)
  2238. Rainbow->Pigment = Create_Pigment();
  2239. Rainbow->Pigment->Blend_Map = Parse_Colour_Map();
  2240. Rainbow->Pigment->Type = GRADIENT_PATTERN;
  2241. Make_Vector (Rainbow->Pigment->Vals.Gradient,1.0,0.0,0.0);
  2242. END_CASE
  2243. CASE (DISTANCE_TOKEN)
  2244. Rainbow->Distance = Parse_Float();
  2245. END_CASE
  2246. CASE (JITTER_TOKEN)
  2247. Rainbow->Jitter = Parse_Float();
  2248. END_CASE
  2249. CASE (WIDTH_TOKEN)
  2250. Rainbow->Width = Parse_Float();
  2251. END_CASE
  2252. CASE (UP_TOKEN)
  2253. Parse_Vector(Rainbow->Up_Vector);
  2254. END_CASE
  2255. CASE (FALLOFF_ANGLE_TOKEN)
  2256. Angle1 = TRUE;
  2257. Rainbow->Falloff_Angle = Parse_Float();
  2258. if ((Rainbow->Falloff_Angle < 0.0) || (Rainbow->Falloff_Angle > 360.0))
  2259. {
  2260. Error("Illegal falloff angle in rainbow (Use value from 0 to 360 degrees).\n");
  2261. }
  2262. Rainbow->Falloff_Angle *= M_PI_360;
  2263. END_CASE
  2264. CASE (ARC_ANGLE_TOKEN)
  2265. Angle2 = TRUE;
  2266. Rainbow->Arc_Angle = Parse_Float();
  2267. if ((Rainbow->Arc_Angle < 0.0) || (Rainbow->Arc_Angle > 360.0))
  2268. {
  2269. Error("Illegal arc angle in rainbow (Use value from 0 to 360 degrees).\n");
  2270. }
  2271. Rainbow->Arc_Angle *= M_PI_360;
  2272. END_CASE
  2273. OTHERWISE
  2274. UNGET
  2275. EXIT
  2276. END_CASE
  2277. END_EXPECT
  2278. Parse_End();
  2279. /* Setup falloff angle. */
  2280. if (Angle2 && !Angle1)
  2281. {
  2282. Rainbow->Falloff_Angle = Rainbow->Arc_Angle;
  2283. }
  2284. /* Test if arc angle is greater or equal to falloff angle. */
  2285. if (Rainbow->Arc_Angle < Rainbow->Falloff_Angle)
  2286. {
  2287. Error("Arc angle is smaller than falloff angle in rainbow.\n");
  2288. }
  2289. /* Get falloff region width.*/
  2290. Rainbow->Falloff_Width = Rainbow->Arc_Angle - Rainbow->Falloff_Angle;
  2291. /* Check for illegal vectors. */
  2292. VDot(dot, Rainbow->Antisolar_Vector, Rainbow->Antisolar_Vector);
  2293. if (fabs(dot) < EPSILON)
  2294. {
  2295. Error("Rainbow's direction vector is zero.\n");
  2296. }
  2297. VDot(dot, Rainbow->Up_Vector, Rainbow->Up_Vector);
  2298. if (fabs(dot) < EPSILON)
  2299. {
  2300. Error("Rainbow's up vector is zero.\n");
  2301. }
  2302. VNormalizeEq(Rainbow->Antisolar_Vector);
  2303. VNormalizeEq(Rainbow->Up_Vector);
  2304. VDot(dot, Rainbow->Up_Vector, Rainbow->Antisolar_Vector);
  2305. if (fabs(1.0 - fabs(dot)) < EPSILON)
  2306. {
  2307. Error("Rainbow's up and direction vector are co-linear.\n");
  2308. }
  2309. /* Make sure that up and antisolar vector are perpendicular. */
  2310. VCross(Rainbow->Right_Vector, Rainbow->Up_Vector, Rainbow->Antisolar_Vector);
  2311. VCross(Rainbow->Up_Vector, Rainbow->Antisolar_Vector, Rainbow->Right_Vector);
  2312. VNormalizeEq(Rainbow->Up_Vector);
  2313. VNormalizeEq(Rainbow->Right_Vector);
  2314. /* Adjust rainbow angle and width. */
  2315. Rainbow->Angle -= 0.5 * Rainbow->Width;
  2316. Rainbow->Angle *= M_PI_180;
  2317. Rainbow->Width *= M_PI_180;
  2318. return(Rainbow);
  2319. }
  2320. /*****************************************************************************
  2321. *
  2322. * FUNCTION
  2323. *
  2324. * Parse_Skysphere
  2325. *
  2326. * INPUT
  2327. *
  2328. * OUTPUT
  2329. *
  2330. * RETURNS
  2331. *
  2332. * AUTHOR
  2333. *
  2334. * Dieter Bayer
  2335. *
  2336. * DESCRIPTION
  2337. *
  2338. * -
  2339. *
  2340. * CHANGES
  2341. *
  2342. * Jul 1994 : Creation.
  2343. *
  2344. * Dec 1994 : Modified to work with multiple skyspheres. [DB]
  2345. *
  2346. ******************************************************************************/
  2347. SKYSPHERE *Parse_Skysphere()
  2348. {
  2349. VECTOR Local_Vector;
  2350. MATRIX Local_Matrix;
  2351. TRANSFORM Local_Trans;
  2352. SKYSPHERE *Skysphere;
  2353. Parse_Begin();
  2354. EXPECT
  2355. CASE(SKYSPHERE_ID_TOKEN)
  2356. Skysphere = Copy_Skysphere((SKYSPHERE *)Token.Data);
  2357. EXIT
  2358. END_CASE
  2359. OTHERWISE
  2360. UNGET
  2361. Skysphere = Create_Skysphere();
  2362. EXIT
  2363. END_CASE
  2364. END_EXPECT
  2365. EXPECT
  2366. CASE (PIGMENT_TOKEN)
  2367. Skysphere->Count++;
  2368. Skysphere->Pigments = (PIGMENT **)POV_REALLOC(Skysphere->Pigments, Skysphere->Count*sizeof(SKYSPHERE *), "sky-sphere pigment");
  2369. Skysphere->Pigments[Skysphere->Count-1] = Create_Pigment();
  2370. Parse_Begin();
  2371. Parse_Pigment(&(Skysphere->Pigments[Skysphere->Count-1]));
  2372. Parse_End();
  2373. END_CASE
  2374. CASE (TRANSLATE_TOKEN)
  2375. Parse_Vector (Local_Vector);
  2376. Translate_Skysphere(Skysphere, Local_Vector);
  2377. END_CASE
  2378. CASE (ROTATE_TOKEN)
  2379. Parse_Vector (Local_Vector);
  2380. Rotate_Skysphere(Skysphere, Local_Vector);
  2381. END_CASE
  2382. CASE (SCALE_TOKEN)
  2383. Parse_Scale_Vector (Local_Vector);
  2384. Scale_Skysphere(Skysphere, Local_Vector);
  2385. END_CASE
  2386. CASE (MATRIX_TOKEN)
  2387. Parse_Matrix(Local_Matrix);
  2388. Compute_Matrix_Transform(&Local_Trans, Local_Matrix);
  2389. Transform_Skysphere(Skysphere, &Local_Trans);
  2390. END_CASE
  2391. CASE (TRANSFORM_TOKEN)
  2392. GET(TRANSFORM_ID_TOKEN)
  2393. Transform_Skysphere(Skysphere, (TRANSFORM *)Token.Data);
  2394. END_CASE
  2395. OTHERWISE
  2396. UNGET
  2397. EXIT
  2398. END_CASE
  2399. END_EXPECT
  2400. Parse_End();
  2401. if (Skysphere->Count==0)
  2402. {
  2403. Error("Empty sky_sphere statement.");
  2404. }
  2405. return(Skysphere);
  2406. }
  2407. /*****************************************************************************
  2408. *
  2409. * FUNCTION : Check_BH_Parameters
  2410. *
  2411. * ARGUMENTS : bh - pointer to Black_Hole
  2412. *
  2413. * AUTHOR : CJC [7/95]
  2414. *
  2415. * DESCRIPTION : Applies sanity checks to the parameters of a black hole.
  2416. *
  2417. * CHANGES
  2418. *
  2419. ******************************************************************************/
  2420. static void Check_BH_Parameters (BLACK_HOLE *bh)
  2421. {
  2422. if (bh->Repeat == FALSE) return ;
  2423. if (bh->Repeat_Vector [X] > 0.0)
  2424. {
  2425. if (bh->Center [X] < bh->Radius)
  2426. bh->Center [X] = bh->Radius ;
  2427. if (bh->Repeat_Vector [X] < bh->Center [X] + bh->Radius + bh->Uncertainty_Vector [X])
  2428. {
  2429. bh->Repeat_Vector [X] = bh->Center [X] + bh->Radius + bh->Uncertainty_Vector [X] ;
  2430. Warning (0.0, "Black Hole repeat vector X too small ; increased to %g\n", bh->Repeat_Vector [X]) ;
  2431. }
  2432. if (bh->Repeat_Vector [X] < Small_Tolerance)
  2433. {
  2434. Warning (0.0,"Black Hole repeat vector X is less than %f ; ignored\n", (float) Small_Tolerance) ;
  2435. bh->Repeat_Vector [X] = 0.0 ;
  2436. }
  2437. }
  2438. if (bh->Repeat_Vector [Y] > 0.0)
  2439. {
  2440. if (bh->Center [Y] < bh->Radius)
  2441. bh->Center [Y] = bh->Radius ;
  2442. if (bh->Repeat_Vector [Y] < bh->Center [Y] + bh->Radius + bh->Uncertainty_Vector [Y])
  2443. {
  2444. bh->Repeat_Vector [Y] = bh->Center [Y] + bh->Radius + bh->Uncertainty_Vector [Y] ;
  2445. Warning (0.0, "Black Hole repeat vector Y too small ; increased to %g\n", bh->Repeat_Vector [Y]) ;
  2446. }
  2447. if (bh->Repeat_Vector [Y] < Small_Tolerance)
  2448. {
  2449. Warning (0.0, "Black Hole repeat vector Y is less than %f ; ignored\n", (float) Small_Tolerance) ;
  2450. bh->Repeat_Vector [Y] = 0.0 ;
  2451. }
  2452. }
  2453. if (bh->Repeat_Vector [Z] > 0.0)
  2454. {
  2455. if (bh->Center [Z] < bh->Radius)
  2456. bh->Center [Z] = bh->Radius ;
  2457. if (bh->Repeat_Vector [Z] < bh->Center [Z] + bh->Radius + bh->Uncertainty_Vector [Z])
  2458. {
  2459. bh->Repeat_Vector [Z] = bh->Center [Z] + bh->Radius + bh->Uncertainty_Vector [Z] ;
  2460. Warning (0.0, "Black Hole repeat vector Z too small ; increased to %g\n", bh->Repeat_Vector [Z]) ;
  2461. }
  2462. if (bh->Repeat_Vector [Z] < Small_Tolerance)
  2463. {
  2464. Warning (0.0, "Black Hole repeat vector Z is less than %f ; ignored\n", (float) Small_Tolerance) ;
  2465. bh->Repeat_Vector [Z] = 0.0 ;
  2466. }
  2467. }
  2468. }
  2469. /*****************************************************************************
  2470. *
  2471. * FUNCTION
  2472. *
  2473. * Check_Turb
  2474. *
  2475. * INPUT
  2476. *
  2477. * Warps_Ptr : Address where the root warp of a warp list
  2478. * is stored.
  2479. *
  2480. * OUTPUT
  2481. *
  2482. * Warps_Ptr : If *Warps_Ptr is NULL, a classic turb warp
  2483. * is created and a pointer to it is stored
  2484. *
  2485. * RETURNS
  2486. *
  2487. * A pointer to the last warp in the chain which is guarenteed
  2488. * to be a classic turb.
  2489. *
  2490. * AUTHOR
  2491. *
  2492. * CEY [2/95]
  2493. *
  2494. * DESCRIPTION : This routine is called when a classic outside-the-warp
  2495. * turbulence parameter is parsed. One and only one classic turb may exist
  2496. * in a warp chain. If there is one, it must be the last. This routine
  2497. * traverses the warp chain and looks at the last link. If it is not a
  2498. * classic turb then it adds one to the end and returns a pointer to it.
  2499. * If the chain is empty, it creates a single link chain consisting of a
  2500. * classic turb link. Future warp links get added ahead of the chain so
  2501. * that any classic turb link is always last.
  2502. *
  2503. * CHANGES
  2504. *
  2505. ******************************************************************************/
  2506. static TURB *Check_Turb (WARP **Warps_Ptr)
  2507. {
  2508. WARP *Temp=*Warps_Ptr;
  2509. if (Temp == NULL)
  2510. {
  2511. *Warps_Ptr = Temp = Create_Warp(CLASSIC_TURB_WARP);
  2512. }
  2513. else
  2514. {
  2515. while (Temp->Next_Warp != NULL)
  2516. {
  2517. Temp=Temp->Next_Warp;
  2518. }
  2519. if (Temp->Warp_Type != CLASSIC_TURB_WARP)
  2520. {
  2521. Temp->Next_Warp=Create_Warp(CLASSIC_TURB_WARP);
  2522. Temp=Temp->Next_Warp;
  2523. }
  2524. }
  2525. return((TURB *)Temp);
  2526. }
  2527. /*****************************************************************************
  2528. *
  2529. * FUNCTION
  2530. *
  2531. * INPUT
  2532. *
  2533. * OUTPUT
  2534. *
  2535. * RETURNS
  2536. *
  2537. * AUTHOR
  2538. *
  2539. * POV-Ray Team
  2540. *
  2541. * DESCRIPTION
  2542. *
  2543. * CHANGES
  2544. *
  2545. ******************************************************************************/
  2546. static void Parse_Warp (WARP **Warp_Ptr)
  2547. {
  2548. WARP *New = NULL;
  2549. TURB *Turb;
  2550. REPEAT *Repeat;
  2551. BLACK_HOLE *Black_Hole;
  2552. VECTOR Local_Vector;
  2553. Parse_Begin();
  2554. EXPECT
  2555. CASE(TURBULENCE_TOKEN)
  2556. New=Create_Warp(EXTRA_TURB_WARP);
  2557. Turb=(TURB *)New;
  2558. Parse_Vector(Turb->Turbulence);
  2559. EXPECT
  2560. CASE(OCTAVES_TOKEN)
  2561. Turb->Octaves = (int)Parse_Float();
  2562. if(Turb->Octaves < 1)
  2563. Turb->Octaves = 1;
  2564. if(Turb->Octaves > 10) /* Avoid DOMAIN errors */
  2565. Turb->Octaves = 10;
  2566. END_CASE
  2567. CASE (OMEGA_TOKEN)
  2568. Turb->Omega = Parse_Float();
  2569. END_CASE
  2570. CASE (LAMBDA_TOKEN)
  2571. Turb->Lambda = Parse_Float();
  2572. END_CASE
  2573. OTHERWISE
  2574. UNGET
  2575. EXIT
  2576. END_CASE
  2577. END_EXPECT
  2578. EXIT
  2579. END_CASE
  2580. CASE(REPEAT_TOKEN)
  2581. New=Create_Warp(REPEAT_WARP);
  2582. Repeat=(REPEAT *)New;
  2583. Parse_Vector(Local_Vector);
  2584. Repeat->Axis=-1;
  2585. if (Local_Vector[X]!=0.0)
  2586. Repeat->Axis=X;
  2587. if (Local_Vector[Y]!=0.0)
  2588. { /* tw */
  2589. if (Repeat->Axis < X)
  2590. Repeat->Axis=Y;
  2591. else
  2592. Error("Can only repeat along 1 axis.");
  2593. } /* tw */
  2594. if (Local_Vector[Z]!=0.0)
  2595. { /* tw */
  2596. if (Repeat->Axis < X)
  2597. Repeat->Axis=Z;
  2598. else
  2599. Error("Can only repeat along 1 axis.");
  2600. } /* tw */
  2601. if (Repeat->Axis < X)
  2602. Error("No axis specified in repeat.");
  2603. Repeat->Width=Local_Vector[Repeat->Axis];
  2604. EXPECT
  2605. CASE(OFFSET_TOKEN)
  2606. Parse_Vector(Repeat->Offset);
  2607. END_CASE
  2608. CASE(FLIP_TOKEN)
  2609. Parse_Vector(Repeat->Flip);
  2610. if (Repeat->Flip[X]!=0.0) Repeat->Flip[X]=-1.0; else Repeat->Flip[X]=1.0;
  2611. if (Repeat->Flip[Y]!=0.0) Repeat->Flip[Y]=-1.0; else Repeat->Flip[Y]=1.0;
  2612. if (Repeat->Flip[Z]!=0.0) Repeat->Flip[Z]=-1.0; else Repeat->Flip[Z]=1.0;
  2613. END_CASE
  2614. OTHERWISE
  2615. UNGET
  2616. EXIT
  2617. END_CASE
  2618. END_EXPECT
  2619. EXIT
  2620. END_CASE
  2621. CASE(BLACK_HOLE_TOKEN)
  2622. New = Create_Warp(BLACK_HOLE_WARP) ;
  2623. Black_Hole = (BLACK_HOLE *) New ;
  2624. Parse_Vector (Local_Vector) ;
  2625. Assign_Vector (Black_Hole->Center, Local_Vector) ;
  2626. Parse_Comma () ;
  2627. Black_Hole->Radius = Parse_Float () ;
  2628. Black_Hole->Radius_Squared = Black_Hole->Radius * Black_Hole->Radius ;
  2629. Black_Hole->Inverse_Radius = 1.0 / Black_Hole->Radius;
  2630. Black_Hole->Strength = 1.0 ;
  2631. Black_Hole->Power = 2.0 ;
  2632. Black_Hole->Inverted = FALSE ;
  2633. Black_Hole->Type = 0 ;
  2634. EXPECT
  2635. CASE(STRENGTH_TOKEN)
  2636. Black_Hole->Strength = Parse_Float () ;
  2637. END_CASE
  2638. CASE(FALLOFF_TOKEN)
  2639. Black_Hole->Power = Parse_Float () ;
  2640. END_CASE
  2641. CASE(INVERSE_TOKEN)
  2642. Black_Hole->Inverted = TRUE ;
  2643. END_CASE
  2644. CASE(TYPE_TOKEN)
  2645. Black_Hole->Type = (int) Parse_Float () ;
  2646. END_CASE
  2647. CASE(REPEAT_TOKEN)
  2648. Parse_Vector (Black_Hole->Repeat_Vector) ;
  2649. Black_Hole->Repeat = TRUE ;
  2650. Check_BH_Parameters (Black_Hole) ;
  2651. END_CASE
  2652. CASE(TURBULENCE_TOKEN)
  2653. Parse_Vector (Black_Hole->Uncertainty_Vector) ;
  2654. Black_Hole->Uncertain = TRUE ;
  2655. Check_BH_Parameters (Black_Hole) ;
  2656. END_CASE
  2657. OTHERWISE
  2658. UNGET
  2659. EXIT
  2660. END_CASE
  2661. END_EXPECT
  2662. EXIT
  2663. END_CASE
  2664. OTHERWISE
  2665. Parse_Error_Str ("warp type");
  2666. END_CASE
  2667. END_EXPECT
  2668. if (New==NULL)
  2669. {
  2670. Error("Empty warp statement.");
  2671. }
  2672. New->Next_Warp=*Warp_Ptr;
  2673. *Warp_Ptr=New;
  2674. Parse_End();
  2675. }
  2676. static void Warn_Interior(char *s)
  2677. {
  2678. Warn(0.0,s);
  2679. Warning(0.0,"should be specified in 'interior{...}' statement.\n");
  2680. Warn_Compat(0);
  2681. }
  2682. void Parse_Material(MATERIAL *Material)
  2683. {
  2684. MATERIAL *Temp;
  2685. TEXTURE *Texture;
  2686. VECTOR Local_Vector;
  2687. MATRIX Local_Matrix;
  2688. TRANSFORM Local_Trans;
  2689. Parse_Begin();
  2690. EXPECT
  2691. CASE(MATERIAL_ID_TOKEN)
  2692. Temp = (MATERIAL *)Token.Data;
  2693. Texture = Copy_Textures(Temp->Texture);
  2694. Link_Textures(&(Material->Texture),Texture);
  2695. Destroy_Interior(Material->Interior);
  2696. Material->Interior = Copy_Interior(Temp->Interior);
  2697. EXIT
  2698. END_CASE
  2699. OTHERWISE
  2700. UNGET
  2701. EXIT
  2702. END_CASE
  2703. END_EXPECT
  2704. EXPECT
  2705. CASE (TEXTURE_TOKEN)
  2706. Parse_Begin ();
  2707. Texture = Parse_Texture ();
  2708. Parse_End ();
  2709. Link_Textures(&(Material->Texture),Texture);
  2710. END_CASE
  2711. CASE (INTERIOR_TOKEN)
  2712. Parse_Interior((INTERIOR **)(&(Material->Interior)));
  2713. END_CASE
  2714. CASE (TRANSLATE_TOKEN)
  2715. Parse_Vector (Local_Vector);
  2716. Compute_Translation_Transform(&Local_Trans, Local_Vector);
  2717. Transform_Textures (Material->Texture, &Local_Trans);
  2718. Transform_Interior (Material->Interior,&Local_Trans);
  2719. END_CASE
  2720. CASE (ROTATE_TOKEN)
  2721. Parse_Vector (Local_Vector);
  2722. Compute_Rotation_Transform(&Local_Trans, Local_Vector);
  2723. Transform_Textures (Material->Texture, &Local_Trans);
  2724. Transform_Interior (Material->Interior,&Local_Trans);
  2725. END_CASE
  2726. CASE (SCALE_TOKEN)
  2727. Parse_Scale_Vector (Local_Vector);
  2728. Compute_Scaling_Transform(&Local_Trans, Local_Vector);
  2729. Transform_Textures (Material->Texture, &Local_Trans);
  2730. Transform_Interior (Material->Interior,&Local_Trans);
  2731. END_CASE
  2732. CASE (MATRIX_TOKEN)
  2733. Parse_Matrix(Local_Matrix);
  2734. Compute_Matrix_Transform(&Local_Trans, Local_Matrix);
  2735. Transform_Textures (Material->Texture, &Local_Trans);
  2736. Transform_Interior (Material->Interior,&Local_Trans);
  2737. END_CASE
  2738. CASE (TRANSFORM_TOKEN)
  2739. GET(TRANSFORM_ID_TOKEN)
  2740. Transform_Textures (Material->Texture, (TRANSFORM *)Token.Data);
  2741. Transform_Interior (Material->Interior,(TRANSFORM *)Token.Data);
  2742. END_CASE
  2743. OTHERWISE
  2744. UNGET
  2745. EXIT
  2746. END_CASE
  2747. END_EXPECT
  2748. Parse_End();
  2749. }