PARSE.C 137 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256
  1. /****************************************************************************
  2. * parse.c
  3. *
  4. * This module implements a parser for the scene description files.
  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 "atmosph.h"
  31. #include "bezier.h"
  32. #include "blob.h"
  33. #include "boxes.h"
  34. #include "bsphere.h"
  35. #include "colour.h"
  36. #include "cones.h"
  37. #include "csg.h"
  38. #include "discs.h"
  39. #include "express.h"
  40. #include "fractal.h"
  41. #include "gif.h"
  42. #include "hfield.h"
  43. #include "iff.h"
  44. #include "image.h"
  45. #include "interior.h"
  46. #include "lathe.h"
  47. #include "polysolv.h"
  48. #include "matrices.h"
  49. #include "mesh.h"
  50. #include "normal.h"
  51. #include "objects.h"
  52. #include "octree.h"
  53. #include "pigment.h"
  54. #include "planes.h"
  55. #include "poly.h"
  56. #include "polygon.h"
  57. #include "povray.h"
  58. #include "pgm.h"
  59. #include "ppm.h"
  60. #include "prism.h"
  61. #include "quadrics.h"
  62. #include "radiosit.h"
  63. #include "render.h"
  64. #include "sor.h"
  65. #include "spheres.h"
  66. #include "super.h"
  67. #include "targa.h"
  68. #include "texture.h"
  69. #include "tokenize.h"
  70. #include "torus.h"
  71. #include "triangle.h"
  72. #include "truetype.h"
  73. /*****************************************************************************
  74. * Local preprocessor defines
  75. ******************************************************************************/
  76. /* Volume that is considered to be infinite. [DB 9/94] */
  77. #define INFINITE_VOLUME BOUND_HUGE
  78. /*****************************************************************************
  79. * Local typedefs
  80. ******************************************************************************/
  81. /*****************************************************************************
  82. * Local variables
  83. ******************************************************************************/
  84. short Not_In_Default;
  85. short Ok_To_Declare;
  86. short LValue_Ok;
  87. static TOKEN *Brace_Stack;
  88. static int Brace_Index;
  89. static CAMERA *Default_Camera;
  90. /*****************************************************************************
  91. * Static functions
  92. ******************************************************************************/
  93. static TRANSFORM *Parse_Transform (void);
  94. static void Frame_Init (void);
  95. static void Parse_Coeffs (int order, DBL *Coeffs);
  96. static OBJECT *Parse_Bicubic_Patch (void);
  97. static OBJECT *Parse_Blob (void);
  98. static OBJECT *Parse_Bound_Clip (void);
  99. static OBJECT *Parse_Box (void);
  100. static OBJECT *Parse_Cone (void);
  101. static OBJECT *Parse_CSG (int CSG_Type);
  102. static OBJECT *Parse_Cylinder (void);
  103. static OBJECT *Parse_Disc (void);
  104. static OBJECT *Parse_Julia_Fractal (void);
  105. static OBJECT *Parse_HField (void);
  106. static OBJECT *Parse_Lathe (void);
  107. static OBJECT *Parse_Light_Source (void);
  108. static OBJECT *Parse_Object_Id (void);
  109. static OBJECT *Parse_Plane (void);
  110. static OBJECT *Parse_Poly (int order);
  111. static OBJECT *Parse_Polygon (void);
  112. static OBJECT *Parse_Prism (void);
  113. static OBJECT *Parse_Quadric (void);
  114. static OBJECT *Parse_Smooth_Triangle (void);
  115. static OBJECT *Parse_Sor (void);
  116. static OBJECT *Parse_Sphere (void);
  117. static OBJECT *Parse_Superellipsoid (void);
  118. static OBJECT *Parse_Torus (void);
  119. static OBJECT *Parse_Triangle (void);
  120. static OBJECT *Parse_Mesh (void);
  121. static TEXTURE *Parse_Mesh_Texture (void);
  122. static OBJECT *Parse_TrueType (void);
  123. static void Parse_Blob_Element_Mods (BLOB_ELEMENT *Element);
  124. static void Parse_Camera (CAMERA **Camera_Ptr);
  125. static void Parse_Frame (void);
  126. static void Found_Instead (void);
  127. static void Link (OBJECT *New_Object,OBJECT **Field,OBJECT **Old_Object_List);
  128. static void Link_To_Frame (OBJECT *Object);
  129. static void Post_Process (OBJECT *Object, OBJECT *Parent);
  130. static void Parse_Global_Settings (void);
  131. static void Global_Setting_Warn (void);
  132. static void Set_CSG_Children_Flag (OBJECT*, unsigned long, unsigned long, unsigned long);
  133. static void *Copy_Identifier (void *Data, int Type);
  134. /*****************************************************************************
  135. *
  136. * FUNCTION
  137. *
  138. * INPUT
  139. *
  140. * OUTPUT
  141. *
  142. * RETURNS
  143. *
  144. * AUTHOR
  145. *
  146. * DESCRIPTION
  147. *
  148. * CHANGES
  149. *
  150. ******************************************************************************/
  151. /* Parse the file. */
  152. void Parse ()
  153. {
  154. Initialize_Tokenizer();
  155. Brace_Stack = (TOKEN *)POV_MALLOC(MAX_BRACES*sizeof (TOKEN), "brace stack");
  156. Brace_Index = 0;
  157. Default_Camera = Create_Camera();
  158. Default_Texture = Create_Texture();
  159. Default_Texture->Pigment = Create_Pigment();
  160. Default_Texture->Tnormal = NULL;
  161. Default_Texture->Finish = Create_Finish();
  162. Not_In_Default = TRUE;
  163. Ok_To_Declare = TRUE;
  164. LValue_Ok = FALSE;
  165. Frame_Init ();
  166. Stage = STAGE_PARSING;
  167. Parse_Frame ();
  168. Post_Media(Frame.Atmosphere);
  169. if (Frame.Objects == NULL)
  170. {
  171. Error ("No objects in scene.");
  172. }
  173. Stage = STAGE_CLEANUP_PARSE;
  174. Terminate_Tokenizer();
  175. Destroy_Textures(Default_Texture);
  176. Destroy_Camera(Default_Camera);
  177. POV_FREE (Brace_Stack);
  178. Default_Texture = NULL;
  179. Default_Camera = NULL;
  180. Brace_Stack = NULL;
  181. }
  182. /*****************************************************************************
  183. *
  184. * FUNCTION
  185. *
  186. * INPUT
  187. *
  188. * OUTPUT
  189. *
  190. * RETURNS
  191. *
  192. * AUTHOR
  193. *
  194. * DESCRIPTION
  195. *
  196. * CHANGES
  197. *
  198. ******************************************************************************/
  199. /* Set up the fields in the frame to default values. */
  200. static
  201. void Frame_Init ()
  202. {
  203. Frame.Camera = Copy_Camera(Default_Camera);
  204. Frame.Number_Of_Light_Sources = 0;
  205. Frame.Light_Sources = NULL;
  206. Frame.Objects = NULL;
  207. Frame.Atmosphere_IOR = 1.0;
  208. Frame.Antialias_Threshold = opts.Antialias_Threshold;
  209. /* dmf -- the first is physically "more correct". The second works better */
  210. /* Make_Colour (Frame.Irid_Wavelengths, 0.70, 0.52, 0.48); */
  211. Make_Colour (Frame.Irid_Wavelengths, 0.25, 0.18, 0.14);
  212. Make_Colour (Frame.Background_Colour, 0.0, 0.0, 0.0);
  213. Make_Colour (Frame.Ambient_Light, 1.0, 1.0, 1.0);
  214. /* Init atmospheric stuff. [DB 12/94] */
  215. Frame.Atmosphere = NULL;
  216. Frame.Fog = NULL;
  217. Frame.Rainbow = NULL;
  218. Frame.Skysphere = NULL;
  219. }
  220. /*****************************************************************************
  221. *
  222. * FUNCTION
  223. *
  224. * INPUT
  225. *
  226. * OUTPUT
  227. *
  228. * RETURNS
  229. *
  230. * AUTHOR
  231. *
  232. * DESCRIPTION
  233. *
  234. * CHANGES
  235. *
  236. ******************************************************************************/
  237. void Parse_Begin ()
  238. {
  239. char *front;
  240. if (++Brace_Index >= MAX_BRACES)
  241. {
  242. Warn(0.0,"Too many nested '{' braces.\n");
  243. Brace_Index--;
  244. }
  245. Brace_Stack[Brace_Index]=Token.Token_Id;
  246. Get_Token ();
  247. if (Token.Token_Id == LEFT_CURLY_TOKEN)
  248. {
  249. return;
  250. }
  251. front = Get_Token_String (Brace_Stack[Brace_Index]);
  252. Where_Error ();
  253. Error_Line ("Missing { after %s, ", front);
  254. Found_Instead ();
  255. }
  256. /*****************************************************************************
  257. *
  258. * FUNCTION
  259. *
  260. * INPUT
  261. *
  262. * OUTPUT
  263. *
  264. * RETURNS
  265. *
  266. * AUTHOR
  267. *
  268. * DESCRIPTION
  269. *
  270. * CHANGES
  271. *
  272. ******************************************************************************/
  273. void Parse_End ()
  274. {
  275. char *front;
  276. Get_Token ();
  277. if (Token.Token_Id == RIGHT_CURLY_TOKEN)
  278. {
  279. if(--Brace_Index < 0)
  280. {
  281. Warn(0.0,"Possible '}' brace missmatch.");
  282. Brace_Index = 0;
  283. }
  284. return;
  285. }
  286. front = Get_Token_String (Brace_Stack[Brace_Index]);
  287. Where_Error ();
  288. Error_Line("No matching } in %s,", front);
  289. Found_Instead ();
  290. }
  291. /*****************************************************************************
  292. *
  293. * FUNCTION
  294. *
  295. * INPUT
  296. *
  297. * OUTPUT
  298. *
  299. * RETURNS
  300. *
  301. * AUTHOR
  302. *
  303. * DESCRIPTION
  304. *
  305. * CHANGES
  306. *
  307. ******************************************************************************/
  308. static OBJECT *Parse_Object_Id ()
  309. {
  310. OBJECT *Object;
  311. EXPECT
  312. CASE (OBJECT_ID_TOKEN)
  313. Warn_State(OBJECT_ID_TOKEN, OBJECT_TOKEN);
  314. Object = Copy_Object((OBJECT *) Token.Data);
  315. Parse_Object_Mods (Object);
  316. EXIT
  317. END_CASE
  318. OTHERWISE
  319. Object = NULL;
  320. UNGET
  321. EXIT
  322. END_CASE
  323. END_EXPECT
  324. return (Object);
  325. }
  326. /*****************************************************************************
  327. *
  328. * FUNCTION
  329. *
  330. * INPUT
  331. *
  332. * OUTPUT
  333. *
  334. * RETURNS
  335. *
  336. * AUTHOR
  337. *
  338. * DESCRIPTION
  339. *
  340. * CHANGES
  341. *
  342. ******************************************************************************/
  343. void Parse_Comma (void)
  344. {
  345. Get_Token();
  346. if (Token.Token_Id != COMMA_TOKEN)
  347. {
  348. UNGET;
  349. }
  350. }
  351. void Parse_Semi_Colon (void)
  352. {
  353. Get_Token();
  354. if (Token.Token_Id != SEMI_COLON_TOKEN)
  355. {
  356. UNGET;
  357. if (opts.Language_Version >= 3.1)
  358. {
  359. Warn(0.0,"All #version and #declares of float, vector, and color require semi-colon ';' at end.\n");
  360. }
  361. }
  362. }
  363. /*****************************************************************************
  364. *
  365. * FUNCTION
  366. *
  367. * INPUT
  368. *
  369. * OUTPUT
  370. *
  371. * RETURNS
  372. *
  373. * AUTHOR
  374. *
  375. * DESCRIPTION
  376. *
  377. * CHANGES
  378. *
  379. ******************************************************************************/
  380. static void Parse_Coeffs(int order, DBL *Coeffs)
  381. {
  382. int i;
  383. EXPECT
  384. CASE (LEFT_ANGLE_TOKEN)
  385. Coeffs[0] = Parse_Float();
  386. for (i = 1; i < term_counts(order); i++)
  387. {
  388. Parse_Comma();
  389. Coeffs[i] = Parse_Float();
  390. }
  391. GET (RIGHT_ANGLE_TOKEN);
  392. EXIT
  393. END_CASE
  394. OTHERWISE
  395. Parse_Error (LEFT_ANGLE_TOKEN);
  396. END_CASE
  397. END_EXPECT
  398. }
  399. /*****************************************************************************
  400. *
  401. * FUNCTION
  402. *
  403. * INPUT
  404. *
  405. * OUTPUT
  406. *
  407. * RETURNS
  408. *
  409. * AUTHOR
  410. *
  411. * DESCRIPTION
  412. *
  413. * CHANGES
  414. *
  415. ******************************************************************************/
  416. static
  417. OBJECT *Parse_Bound_Clip ()
  418. {
  419. VECTOR Local_Vector;
  420. MATRIX Local_Matrix;
  421. TRANSFORM Local_Trans;
  422. OBJECT *First, *Current, *Prev;
  423. First = Prev = NULL;
  424. while ((Current = Parse_Object ()) != NULL)
  425. {
  426. if (Current->Type & (TEXTURED_OBJECT+PATCH_OBJECT))
  427. Error ("Illegal texture or patch in clip or bound.");
  428. if (First == NULL)
  429. First = Current;
  430. if (Prev != NULL)
  431. Prev->Sibling = Current;
  432. Prev = Current;
  433. }
  434. EXPECT
  435. CASE (TRANSLATE_TOKEN)
  436. Parse_Vector (Local_Vector);
  437. Compute_Translation_Transform(&Local_Trans, Local_Vector);
  438. for (Current = First; Current != NULL; Current = Current->Sibling)
  439. {
  440. Translate_Object (Current, Local_Vector, &Local_Trans);
  441. }
  442. END_CASE
  443. CASE (ROTATE_TOKEN)
  444. Parse_Vector (Local_Vector);
  445. Compute_Rotation_Transform(&Local_Trans, Local_Vector);
  446. for (Current = First; Current != NULL; Current = Current->Sibling)
  447. {
  448. Rotate_Object (Current, Local_Vector, &Local_Trans);
  449. }
  450. END_CASE
  451. CASE (SCALE_TOKEN)
  452. Parse_Scale_Vector (Local_Vector);
  453. Compute_Scaling_Transform(&Local_Trans, Local_Vector);
  454. for (Current = First; Current != NULL; Current = Current->Sibling)
  455. {
  456. Scale_Object (Current, Local_Vector, &Local_Trans);
  457. }
  458. END_CASE
  459. CASE (TRANSFORM_TOKEN)
  460. GET(TRANSFORM_ID_TOKEN)
  461. for (Current = First; Current != NULL; Current = Current->Sibling)
  462. {
  463. Transform_Object (Current, (TRANSFORM *)Token.Data);
  464. }
  465. END_CASE
  466. CASE (MATRIX_TOKEN)
  467. Parse_Matrix (Local_Matrix);
  468. Compute_Matrix_Transform(&Local_Trans, Local_Matrix);
  469. for (Current = First; Current != NULL; Current = Current->Sibling)
  470. {
  471. Transform_Object (Current, &Local_Trans);
  472. }
  473. END_CASE
  474. OTHERWISE
  475. UNGET
  476. EXIT
  477. END_CASE
  478. END_EXPECT
  479. if (First==NULL)
  480. {
  481. Parse_Error_Str("object");
  482. }
  483. return (First);
  484. }
  485. /*****************************************************************************
  486. *
  487. * FUNCTION
  488. *
  489. * INPUT
  490. *
  491. * OUTPUT
  492. *
  493. * RETURNS
  494. *
  495. * AUTHOR
  496. *
  497. * DESCRIPTION
  498. *
  499. * CHANGES
  500. *
  501. ******************************************************************************/
  502. void Parse_Object_Mods (OBJECT *Object)
  503. {
  504. DBL Temp_Water_Level;
  505. DBL V1, V2;
  506. VECTOR Min, Max;
  507. VECTOR Local_Vector;
  508. MATRIX Local_Matrix;
  509. TRANSFORM Local_Trans;
  510. BBOX BBox;
  511. OBJECT *Sib;
  512. TEXTURE *Local_Texture;
  513. MATERIAL Local_Material;
  514. OBJECT *Temp1_Object;
  515. OBJECT *Temp2_Object;
  516. COLOUR Local_Colour;
  517. EXPECT
  518. CASE_COLOUR
  519. Parse_Colour (Local_Colour);
  520. if (opts.Language_Version < 1.5)
  521. if (Object->Texture != NULL)
  522. if (Object->Texture->Type == PLAIN_PATTERN)
  523. if (opts.Quality_Flags & Q_QUICKC)
  524. {
  525. Assign_Colour(Object->Texture->Pigment->Colour,Local_Colour);
  526. break; /* acts like END_CASE */
  527. }
  528. Warn(0.0, "Quick color belongs in texture. Color ignored.");
  529. END_CASE
  530. CASE (TRANSLATE_TOKEN)
  531. Parse_Vector (Local_Vector);
  532. Compute_Translation_Transform(&Local_Trans, Local_Vector);
  533. Translate_Object (Object, Local_Vector, &Local_Trans);
  534. END_CASE
  535. CASE (ROTATE_TOKEN)
  536. Parse_Vector (Local_Vector);
  537. Compute_Rotation_Transform(&Local_Trans, Local_Vector);
  538. Rotate_Object (Object, Local_Vector, &Local_Trans);
  539. END_CASE
  540. CASE (SCALE_TOKEN)
  541. Parse_Scale_Vector (Local_Vector);
  542. Compute_Scaling_Transform(&Local_Trans, Local_Vector);
  543. Scale_Object (Object, Local_Vector, &Local_Trans);
  544. END_CASE
  545. CASE (TRANSFORM_TOKEN)
  546. GET(TRANSFORM_ID_TOKEN)
  547. Transform_Object (Object, (TRANSFORM *)Token.Data);
  548. END_CASE
  549. CASE (MATRIX_TOKEN)
  550. Parse_Matrix (Local_Matrix);
  551. Compute_Matrix_Transform(&Local_Trans, Local_Matrix);
  552. Transform_Object (Object, &Local_Trans);
  553. END_CASE
  554. CASE (BOUNDED_BY_TOKEN)
  555. Parse_Begin ();
  556. if (Object->Bound != NULL)
  557. if (Object->Clip == Object->Bound)
  558. Error ("Cannot add bounds after linking bounds and clips.");
  559. EXPECT
  560. CASE (CLIPPED_BY_TOKEN)
  561. if (Object->Bound != NULL)
  562. Error ("Cannot link clips with previous bounds.");
  563. Object->Bound = Object->Clip;
  564. EXIT
  565. END_CASE
  566. OTHERWISE
  567. UNGET
  568. Temp1_Object = Temp2_Object = Parse_Bound_Clip ();
  569. while (Temp2_Object->Sibling != NULL)
  570. Temp2_Object = Temp2_Object->Sibling;
  571. Temp2_Object->Sibling = Object->Bound;
  572. Object->Bound = Temp1_Object;
  573. EXIT
  574. END_CASE
  575. END_EXPECT
  576. Parse_End ();
  577. END_CASE
  578. CASE (CLIPPED_BY_TOKEN)
  579. Parse_Begin ();
  580. if (Object->Clip != NULL)
  581. if (Object->Clip == Object->Bound)
  582. Error ("Cannot add clips after linking bounds and clips.");
  583. EXPECT
  584. CASE (BOUNDED_BY_TOKEN)
  585. if (Object->Clip != NULL)
  586. Error ("Cannot link bounds with previous clips.");
  587. Object->Clip = Object->Bound;
  588. EXIT
  589. END_CASE
  590. OTHERWISE
  591. UNGET
  592. Temp1_Object = Temp2_Object = Parse_Bound_Clip ();
  593. while (Temp2_Object->Sibling != NULL)
  594. Temp2_Object = Temp2_Object->Sibling;
  595. Temp2_Object->Sibling = Object->Clip;
  596. Object->Clip = Temp1_Object;
  597. /* Compute quadric bounding box before transformations. [DB 8/94] */
  598. if (Object->Methods == &Quadric_Methods)
  599. {
  600. Make_Vector(Min, -BOUND_HUGE, -BOUND_HUGE, -BOUND_HUGE);
  601. Make_Vector(Max, BOUND_HUGE, BOUND_HUGE, BOUND_HUGE);
  602. Compute_Quadric_BBox((QUADRIC *)Object, Min, Max);
  603. }
  604. EXIT
  605. END_CASE
  606. END_EXPECT
  607. Parse_End ();
  608. END_CASE
  609. CASE (TEXTURE_TOKEN)
  610. Object->Type |= TEXTURED_OBJECT;
  611. Parse_Begin ();
  612. Local_Texture = Parse_Texture ();
  613. Parse_End ();
  614. Link_Textures(&(Object->Texture), Local_Texture);
  615. END_CASE
  616. CASE (INTERIOR_TOKEN)
  617. Parse_Interior((INTERIOR **)(&Object->Interior));
  618. END_CASE
  619. CASE (MATERIAL_TOKEN)
  620. Local_Material.Texture = Object->Texture;
  621. Local_Material.Interior = Object->Interior;
  622. Parse_Material(&Local_Material);
  623. Object->Texture = Local_Material.Texture;
  624. Object->Interior = Local_Material.Interior;
  625. END_CASE
  626. CASE3 (PIGMENT_TOKEN, TNORMAL_TOKEN, FINISH_TOKEN)
  627. Object->Type |= TEXTURED_OBJECT;
  628. if (Object->Texture == NULL)
  629. Object->Texture = Copy_Textures(Default_Texture);
  630. else
  631. if (Object->Texture->Type != PLAIN_PATTERN)
  632. Link_Textures(&(Object->Texture), Copy_Textures(Default_Texture));
  633. UNGET
  634. EXPECT
  635. CASE (PIGMENT_TOKEN)
  636. Parse_Begin ();
  637. Parse_Pigment ( &(Object->Texture->Pigment) );
  638. Parse_End ();
  639. END_CASE
  640. CASE (TNORMAL_TOKEN)
  641. Parse_Begin ();
  642. Parse_Tnormal ( &(Object->Texture->Tnormal) );
  643. Parse_End ();
  644. END_CASE
  645. CASE (FINISH_TOKEN)
  646. Parse_Finish ( &(Object->Texture->Finish) );
  647. END_CASE
  648. OTHERWISE
  649. UNGET
  650. EXIT
  651. END_CASE
  652. END_EXPECT
  653. END_CASE
  654. CASE (INVERSE_TOKEN)
  655. if (Object->Type & PATCH_OBJECT)
  656. Warn (0.0, "Cannot invert a patch object.");
  657. Invert_Object (Object);
  658. END_CASE
  659. CASE (STURM_TOKEN)
  660. if (!(Object->Type & STURM_OK_OBJECT))
  661. Not_With ("sturm","this object");
  662. Bool_Flag (Object, STURM_FLAG, (Allow_Float(1.0) > 0.0));
  663. END_CASE
  664. CASE (WATER_LEVEL_TOKEN)
  665. if (!(Object->Type & WATER_LEVEL_OK_OBJECT))
  666. Not_With ("water_level","this object");
  667. Temp_Water_Level = Parse_Float();
  668. if (opts.Language_Version < 2.0)
  669. Temp_Water_Level /=256.0;
  670. ((HFIELD *) Object)->bounding_box->bounds[0][Y] = 65536.0 * Temp_Water_Level;
  671. END_CASE
  672. CASE (SMOOTH_TOKEN)
  673. if (!(Object->Type & SMOOTH_OK_OBJECT))
  674. Not_With ("smooth","this object");
  675. Set_Flag(Object, SMOOTHED_FLAG);
  676. Object->Type |= DOUBLE_ILLUMINATE;
  677. END_CASE
  678. CASE (NO_SHADOW_TOKEN)
  679. Set_Flag(Object, NO_SHADOW_FLAG);
  680. END_CASE
  681. CASE (LIGHT_SOURCE_TOKEN)
  682. Error("Light source must be defined using new syntax.");
  683. END_CASE
  684. CASE(HIERARCHY_TOKEN)
  685. if (!(Object->Type & HIERARCHY_OK_OBJECT))
  686. Not_With ("hierarchy", "this object");
  687. Bool_Flag (Object, HIERARCHY_FLAG, (Allow_Float(1.0) > 0.0));
  688. END_CASE
  689. CASE(HOLLOW_TOKEN)
  690. Bool_Flag (Object, HOLLOW_FLAG, (Allow_Float(1.0) > 0.0));
  691. Set_Flag (Object, HOLLOW_SET_FLAG);
  692. if ((Object->Methods == &CSG_Intersection_Methods) ||
  693. (Object->Methods == &CSG_Merge_Methods) ||
  694. (Object->Methods == &CSG_Union_Methods))
  695. {
  696. Set_CSG_Children_Flag(Object, Test_Flag(Object, HOLLOW_FLAG), HOLLOW_FLAG, HOLLOW_SET_FLAG);
  697. }
  698. END_CASE
  699. OTHERWISE
  700. UNGET
  701. EXIT
  702. END_CASE
  703. END_EXPECT
  704. /*
  705. * Assign bounding objects' bounding box to object
  706. * if object's bounding box is larger. [DB 9/94]
  707. */
  708. if (Object->Bound != NULL)
  709. {
  710. /* Get bounding objects bounding box. */
  711. Make_Vector(Min, -BOUND_HUGE, -BOUND_HUGE, -BOUND_HUGE);
  712. Make_Vector(Max, BOUND_HUGE, BOUND_HUGE, BOUND_HUGE);
  713. for (Sib = Object->Bound; Sib != NULL; Sib = Sib->Sibling)
  714. {
  715. if (!Test_Flag(Sib, INVERTED_FLAG))
  716. {
  717. Min[X] = max(Min[X], Sib->BBox.Lower_Left[X]);
  718. Min[Y] = max(Min[Y], Sib->BBox.Lower_Left[Y]);
  719. Min[Z] = max(Min[Z], Sib->BBox.Lower_Left[Z]);
  720. Max[X] = min(Max[X], Sib->BBox.Lower_Left[X] + Sib->BBox.Lengths[X]);
  721. Max[Y] = min(Max[Y], Sib->BBox.Lower_Left[Y] + Sib->BBox.Lengths[Y]);
  722. Max[Z] = min(Max[Z], Sib->BBox.Lower_Left[Z] + Sib->BBox.Lengths[Z]);
  723. }
  724. }
  725. Make_BBox_from_min_max(BBox, Min, Max);
  726. /* Get bounding boxes' volumes. */
  727. BOUNDS_VOLUME(V1, BBox);
  728. BOUNDS_VOLUME(V2, Object->BBox);
  729. if (V1 < V2)
  730. {
  731. Object->BBox = BBox;
  732. }
  733. }
  734. /*
  735. * Assign clipping objects' bounding box to object
  736. * if object's bounding box is larger. [DB 9/94]
  737. */
  738. if (Object->Clip != NULL)
  739. {
  740. /* Get clipping objects bounding box. */
  741. Make_Vector(Min, -BOUND_HUGE, -BOUND_HUGE, -BOUND_HUGE);
  742. Make_Vector(Max, BOUND_HUGE, BOUND_HUGE, BOUND_HUGE);
  743. for (Sib = Object->Clip; Sib != NULL; Sib = Sib->Sibling)
  744. {
  745. if (!Test_Flag(Sib, INVERTED_FLAG))
  746. {
  747. Min[X] = max(Min[X], Sib->BBox.Lower_Left[X]);
  748. Min[Y] = max(Min[Y], Sib->BBox.Lower_Left[Y]);
  749. Min[Z] = max(Min[Z], Sib->BBox.Lower_Left[Z]);
  750. Max[X] = min(Max[X], Sib->BBox.Lower_Left[X] + Sib->BBox.Lengths[X]);
  751. Max[Y] = min(Max[Y], Sib->BBox.Lower_Left[Y] + Sib->BBox.Lengths[Y]);
  752. Max[Z] = min(Max[Z], Sib->BBox.Lower_Left[Z] + Sib->BBox.Lengths[Z]);
  753. }
  754. }
  755. Make_BBox_from_min_max(BBox, Min, Max);
  756. /* Get bounding boxes' volumes. */
  757. BOUNDS_VOLUME(V1, BBox);
  758. BOUNDS_VOLUME(V2, Object->BBox);
  759. if (V1 < V2)
  760. {
  761. Object->BBox = BBox;
  762. }
  763. }
  764. Parse_End ();
  765. }
  766. /*****************************************************************************
  767. *
  768. * FUNCTION
  769. *
  770. * INPUT
  771. *
  772. * OUTPUT
  773. *
  774. * RETURNS
  775. *
  776. * AUTHOR
  777. *
  778. * DESCRIPTION
  779. *
  780. * CHANGES
  781. *
  782. ******************************************************************************/
  783. static OBJECT *Parse_Sphere()
  784. {
  785. SPHERE *Object;
  786. Parse_Begin();
  787. if ((Object = (SPHERE *)Parse_Object_Id()) != NULL)
  788. {
  789. return ((OBJECT *) Object);
  790. }
  791. Object = Create_Sphere();
  792. Parse_Vector(Object->Center);
  793. Parse_Comma();
  794. Object->Radius = Parse_Float();
  795. Compute_Sphere_BBox(Object);
  796. Parse_Object_Mods((OBJECT *)Object);
  797. return((OBJECT *)Object);
  798. }
  799. /*****************************************************************************
  800. *
  801. * FUNCTION
  802. *
  803. * INPUT
  804. *
  805. * OUTPUT
  806. *
  807. * RETURNS
  808. *
  809. * AUTHOR
  810. *
  811. * DESCRIPTION
  812. *
  813. * CHANGES
  814. *
  815. ******************************************************************************/
  816. static
  817. OBJECT *Parse_Plane ()
  818. {
  819. DBL len;
  820. PLANE *Object;
  821. Parse_Begin ();
  822. if ( (Object = (PLANE *)Parse_Object_Id()) != NULL)
  823. return ((OBJECT *) Object);
  824. Object = Create_Plane();
  825. Parse_Vector(Object->Normal_Vector); Parse_Comma();
  826. VLength(len, Object->Normal_Vector);
  827. if (len < EPSILON)
  828. {
  829. Error("Degenerate plane normal.");
  830. }
  831. VInverseScaleEq(Object->Normal_Vector, len);
  832. Object->Distance = -Parse_Float();
  833. Compute_Plane_BBox(Object);
  834. Parse_Object_Mods ((OBJECT *)Object);
  835. return ((OBJECT *) Object);
  836. }
  837. /*****************************************************************************
  838. *
  839. * FUNCTION
  840. *
  841. * INPUT
  842. *
  843. * OUTPUT
  844. *
  845. * RETURNS
  846. *
  847. * AUTHOR
  848. *
  849. * DESCRIPTION
  850. *
  851. * CHANGES
  852. *
  853. ******************************************************************************/
  854. static
  855. OBJECT *Parse_HField ()
  856. {
  857. HFIELD *Object;
  858. VECTOR Local_Vector;
  859. IMAGE *Image;
  860. Parse_Begin ();
  861. if ( (Object = (HFIELD *)Parse_Object_Id()) != NULL)
  862. return ((OBJECT *) Object);
  863. Object = Create_HField();
  864. Image = Parse_Image (HF_FILE);
  865. Image->Use_Colour_Flag = FALSE;
  866. Make_Vector(Object->bounding_box->bounds[0], 0.0, 0.0, 0.0);
  867. if (Image->File_Type == POT_FILE)
  868. {
  869. Object->bounding_box->bounds[1][X] = Image->width/2.0 - 1.0;
  870. }
  871. else
  872. {
  873. Object->bounding_box->bounds[1][X] = Image->width - 1.0;
  874. }
  875. Object->bounding_box->bounds[1][Y] = 65536.0;
  876. Object->bounding_box->bounds[1][Z] = Image->height - 1.0;
  877. Make_Vector(Local_Vector,
  878. 1.0 / (Object->bounding_box->bounds[1][X]),
  879. 1.0 / (Object->bounding_box->bounds[1][Y]),
  880. 1.0 / (Object->bounding_box->bounds[1][Z]));
  881. Compute_Scaling_Transform(Object->Trans, Local_Vector);
  882. Parse_Object_Mods ((OBJECT *)Object);
  883. Compute_HField(Object, Image);
  884. Compute_HField_BBox(Object);
  885. Destroy_Image (Image);
  886. return ((OBJECT *) Object);
  887. }
  888. /*****************************************************************************
  889. *
  890. * FUNCTION
  891. *
  892. * INPUT
  893. *
  894. * OUTPUT
  895. *
  896. * RETURNS
  897. *
  898. * AUTHOR
  899. *
  900. * DESCRIPTION
  901. *
  902. * CHANGES
  903. *
  904. ******************************************************************************/
  905. static OBJECT *Parse_Triangle()
  906. {
  907. TRIANGLE *Object;
  908. Parse_Begin();
  909. if ((Object = (TRIANGLE *)Parse_Object_Id()) != NULL)
  910. {
  911. return((OBJECT *) Object);
  912. }
  913. Object = Create_Triangle();
  914. Parse_Vector(Object->P1); Parse_Comma();
  915. Parse_Vector(Object->P2); Parse_Comma();
  916. Parse_Vector(Object->P3);
  917. /* Note that Compute_Triangle also computes the bounding box. */
  918. if (!Compute_Triangle(Object, FALSE))
  919. {
  920. Warn(0.0, "Degenerate triangle. Please remove.");
  921. }
  922. Parse_Object_Mods((OBJECT *)Object);
  923. return((OBJECT *)Object);
  924. }
  925. /*****************************************************************************
  926. *
  927. * FUNCTION
  928. *
  929. * INPUT
  930. *
  931. * OUTPUT
  932. *
  933. * RETURNS
  934. *
  935. * AUTHOR
  936. *
  937. * DESCRIPTION
  938. *
  939. * CHANGES
  940. *
  941. ******************************************************************************/
  942. static
  943. OBJECT *Parse_Smooth_Triangle ()
  944. {
  945. SMOOTH_TRIANGLE *Object;
  946. short degen;
  947. DBL vlen;
  948. degen=FALSE;
  949. Parse_Begin ();
  950. if ( (Object = (SMOOTH_TRIANGLE *)Parse_Object_Id()) != NULL)
  951. return ((OBJECT *) Object);
  952. Object = Create_Smooth_Triangle();
  953. Parse_Vector (Object->P1); Parse_Comma();
  954. Parse_Vector (Object->N1); Parse_Comma();
  955. VLength(vlen,Object->N1);
  956. if (vlen == 0.0)
  957. degen=TRUE;
  958. else
  959. VNormalize (Object->N1, Object->N1);
  960. Parse_Vector (Object->P2); Parse_Comma();
  961. Parse_Vector (Object->N2); Parse_Comma();
  962. VLength(vlen,Object->N2);
  963. if (vlen == 0.0)
  964. degen=TRUE;
  965. else
  966. VNormalize (Object->N2, Object->N2);
  967. Parse_Vector (Object->P3); Parse_Comma();
  968. Parse_Vector (Object->N3);
  969. VLength(vlen,Object->N3);
  970. if (vlen == 0.0)
  971. degen=TRUE;
  972. else
  973. VNormalize (Object->N3, Object->N3);
  974. if (!degen)
  975. {
  976. degen=!Compute_Triangle ((TRIANGLE *) Object,TRUE);
  977. }
  978. if (degen)
  979. {
  980. Warn(0.0, "Degenerate triangle. Please remove.");
  981. }
  982. Compute_Triangle_BBox((TRIANGLE *)Object);
  983. Parse_Object_Mods ((OBJECT *)Object);
  984. return ((OBJECT *) Object);
  985. }
  986. /*****************************************************************************
  987. *
  988. * FUNCTION
  989. *
  990. * INPUT
  991. *
  992. * OUTPUT
  993. *
  994. * RETURNS
  995. *
  996. * AUTHOR
  997. *
  998. * DESCRIPTION
  999. *
  1000. * CHANGES
  1001. *
  1002. ******************************************************************************/
  1003. static
  1004. OBJECT *Parse_Quadric ()
  1005. {
  1006. VECTOR Min, Max;
  1007. QUADRIC *Object;
  1008. Parse_Begin ();
  1009. if ( (Object = (QUADRIC *)Parse_Object_Id()) != NULL)
  1010. return ((OBJECT *) Object);
  1011. Object = Create_Quadric();
  1012. Parse_Vector(Object->Square_Terms); Parse_Comma();
  1013. Parse_Vector(Object->Mixed_Terms); Parse_Comma();
  1014. Parse_Vector(Object->Terms); Parse_Comma();
  1015. Object->Constant = Parse_Float();
  1016. Make_Vector(Min, -BOUND_HUGE, -BOUND_HUGE, -BOUND_HUGE);
  1017. Make_Vector(Max, BOUND_HUGE, BOUND_HUGE, BOUND_HUGE);
  1018. Compute_Quadric_BBox(Object, Min, Max);
  1019. Parse_Object_Mods ((OBJECT *)Object);
  1020. return ((OBJECT *) Object);
  1021. }
  1022. /*****************************************************************************
  1023. *
  1024. * FUNCTION
  1025. *
  1026. * INPUT
  1027. *
  1028. * OUTPUT
  1029. *
  1030. * RETURNS
  1031. *
  1032. * AUTHOR
  1033. *
  1034. * DESCRIPTION
  1035. *
  1036. * CHANGES
  1037. *
  1038. ******************************************************************************/
  1039. static
  1040. OBJECT *Parse_Box ()
  1041. {
  1042. BOX *Object;
  1043. DBL temp;
  1044. Parse_Begin ();
  1045. if ( (Object = (BOX *)Parse_Object_Id()) != NULL)
  1046. return ((OBJECT *) Object);
  1047. Object = Create_Box();
  1048. Parse_Vector(Object->bounds[0]); Parse_Comma();
  1049. Parse_Vector(Object->bounds[1]);
  1050. if (Object->bounds[0][X] > Object->bounds[1][X]) {
  1051. temp = Object->bounds[0][X];
  1052. Object->bounds[0][X] = Object->bounds[1][X];
  1053. Object->bounds[1][X] = temp;
  1054. }
  1055. if (Object->bounds[0][Y] > Object->bounds[1][Y]) {
  1056. temp = Object->bounds[0][Y];
  1057. Object->bounds[0][Y] = Object->bounds[1][Y];
  1058. Object->bounds[1][Y] = temp;
  1059. }
  1060. if (Object->bounds[0][Z] > Object->bounds[1][Z]) {
  1061. temp = Object->bounds[0][Z];
  1062. Object->bounds[0][Z] = Object->bounds[1][Z];
  1063. Object->bounds[1][Z] = temp;
  1064. }
  1065. Compute_Box_BBox(Object);
  1066. Parse_Object_Mods ((OBJECT *)Object);
  1067. return ((OBJECT *) Object);
  1068. }
  1069. /*****************************************************************************
  1070. *
  1071. * FUNCTION
  1072. *
  1073. * INPUT
  1074. *
  1075. * OUTPUT
  1076. *
  1077. * RETURNS
  1078. *
  1079. * AUTHOR
  1080. *
  1081. * DESCRIPTION
  1082. *
  1083. * CHANGES
  1084. *
  1085. ******************************************************************************/
  1086. static
  1087. OBJECT *Parse_Disc ()
  1088. {
  1089. DISC *Object;
  1090. DBL tmpf;
  1091. Parse_Begin ();
  1092. if ( (Object = (DISC *)Parse_Object_Id()) != NULL)
  1093. return ((OBJECT *) Object);
  1094. Object = Create_Disc();
  1095. Parse_Vector(Object->center); Parse_Comma ();
  1096. Parse_Vector(Object->normal); Parse_Comma ();
  1097. VNormalize(Object->normal, Object->normal);
  1098. tmpf = Parse_Float(); Parse_Comma ();
  1099. Object->oradius2 = tmpf * tmpf;
  1100. EXPECT
  1101. CASE_FLOAT
  1102. tmpf = Parse_Float();
  1103. Object->iradius2 = tmpf * tmpf;
  1104. END_CASE
  1105. OTHERWISE
  1106. UNGET
  1107. EXIT
  1108. END_CASE
  1109. END_EXPECT
  1110. /* Calculate info needed for ray-disc intersections */
  1111. VDot(tmpf, Object->center, Object->normal);
  1112. Object->d = -tmpf;
  1113. Compute_Disc(Object);
  1114. Parse_Object_Mods ((OBJECT *)Object);
  1115. return ((OBJECT *) Object);
  1116. }
  1117. /*****************************************************************************
  1118. *
  1119. * FUNCTION
  1120. *
  1121. * INPUT
  1122. *
  1123. * OUTPUT
  1124. *
  1125. * RETURNS
  1126. *
  1127. * AUTHOR
  1128. *
  1129. * DESCRIPTION
  1130. *
  1131. * CHANGES
  1132. *
  1133. ******************************************************************************/
  1134. static
  1135. OBJECT *Parse_Cylinder ()
  1136. {
  1137. CONE *Object;
  1138. Parse_Begin ();
  1139. if ( (Object = (CONE *)Parse_Object_Id()) != NULL)
  1140. return ((OBJECT *) Object);
  1141. Object = Create_Cylinder();
  1142. Parse_Vector(Object->apex); Parse_Comma ();
  1143. Parse_Vector(Object->base); Parse_Comma ();
  1144. Object->apex_radius = Parse_Float();
  1145. Object->base_radius = Object->apex_radius;
  1146. EXPECT
  1147. CASE(OPEN_TOKEN)
  1148. Clear_Flag(Object, CLOSED_FLAG);
  1149. EXIT
  1150. END_CASE
  1151. OTHERWISE
  1152. UNGET
  1153. EXIT
  1154. END_CASE
  1155. END_EXPECT
  1156. Compute_Cylinder_Data((OBJECT *)Object);
  1157. Compute_Cone_BBox(Object);
  1158. Parse_Object_Mods ((OBJECT *)Object);
  1159. return ((OBJECT *) Object);
  1160. }
  1161. /*****************************************************************************
  1162. *
  1163. * FUNCTION
  1164. *
  1165. * INPUT
  1166. *
  1167. * OUTPUT
  1168. *
  1169. * RETURNS
  1170. *
  1171. * AUTHOR
  1172. *
  1173. * DESCRIPTION
  1174. *
  1175. * CHANGES
  1176. *
  1177. ******************************************************************************/
  1178. static
  1179. OBJECT *Parse_Cone ()
  1180. {
  1181. CONE *Object;
  1182. Parse_Begin ();
  1183. if ( (Object = (CONE *)Parse_Object_Id()) != NULL)
  1184. return ((OBJECT *) Object);
  1185. Object = Create_Cone();
  1186. Parse_Vector(Object->apex); Parse_Comma ();
  1187. Object->apex_radius = Parse_Float(); Parse_Comma ();
  1188. Parse_Vector(Object->base); Parse_Comma ();
  1189. Object->base_radius = Parse_Float();
  1190. EXPECT
  1191. CASE(OPEN_TOKEN)
  1192. Clear_Flag(Object, CLOSED_FLAG);
  1193. EXIT
  1194. END_CASE
  1195. OTHERWISE
  1196. UNGET
  1197. EXIT
  1198. END_CASE
  1199. END_EXPECT
  1200. /* Compute run-time values for the cone */
  1201. Compute_Cone_Data((OBJECT *)Object);
  1202. Compute_Cone_BBox(Object);
  1203. Parse_Object_Mods ((OBJECT *)Object);
  1204. return ((OBJECT *) Object);
  1205. }
  1206. /*****************************************************************************
  1207. *
  1208. * FUNCTION
  1209. *
  1210. * Parse_Blob_Element_Mods
  1211. *
  1212. * INPUT
  1213. *
  1214. * OUTPUT
  1215. *
  1216. * RETURNS
  1217. *
  1218. * AUTHOR
  1219. *
  1220. * Dieter Bayer
  1221. *
  1222. * DESCRIPTION
  1223. *
  1224. * -
  1225. *
  1226. * CHANGES
  1227. *
  1228. * Sep 1994 : Creation.
  1229. *
  1230. ******************************************************************************/
  1231. static void Parse_Blob_Element_Mods(BLOB_ELEMENT *Element)
  1232. {
  1233. VECTOR Local_Vector;
  1234. MATRIX Local_Matrix;
  1235. TRANSFORM Local_Trans;
  1236. TEXTURE *Local_Texture;
  1237. EXPECT
  1238. CASE (TRANSLATE_TOKEN)
  1239. Parse_Vector (Local_Vector);
  1240. Translate_Blob_Element (Element, Local_Vector);
  1241. END_CASE
  1242. CASE (ROTATE_TOKEN)
  1243. Parse_Vector (Local_Vector);
  1244. Rotate_Blob_Element (Element, Local_Vector);
  1245. END_CASE
  1246. CASE (SCALE_TOKEN)
  1247. Parse_Scale_Vector (Local_Vector);
  1248. Scale_Blob_Element (Element, Local_Vector);
  1249. END_CASE
  1250. CASE (TRANSFORM_TOKEN)
  1251. GET(TRANSFORM_ID_TOKEN)
  1252. Transform_Blob_Element (Element, (TRANSFORM *)Token.Data);
  1253. END_CASE
  1254. CASE (MATRIX_TOKEN)
  1255. Parse_Matrix (Local_Matrix);
  1256. Compute_Matrix_Transform(&Local_Trans, Local_Matrix);
  1257. Transform_Blob_Element (Element, &Local_Trans);
  1258. END_CASE
  1259. CASE (TEXTURE_TOKEN)
  1260. Parse_Begin ();
  1261. Local_Texture = Parse_Texture();
  1262. Parse_End ();
  1263. Link_Textures(&Element->Texture, Local_Texture);
  1264. END_CASE
  1265. CASE3 (PIGMENT_TOKEN, TNORMAL_TOKEN, FINISH_TOKEN)
  1266. if (Element->Texture == NULL)
  1267. {
  1268. Element->Texture = Copy_Textures(Default_Texture);
  1269. }
  1270. else
  1271. {
  1272. if (Element->Texture->Type != PLAIN_PATTERN)
  1273. {
  1274. Link_Textures(&Element->Texture, Copy_Textures(Default_Texture));
  1275. }
  1276. }
  1277. UNGET
  1278. EXPECT
  1279. CASE (PIGMENT_TOKEN)
  1280. Parse_Begin ();
  1281. Parse_Pigment(&Element->Texture->Pigment);
  1282. Parse_End ();
  1283. END_CASE
  1284. CASE (TNORMAL_TOKEN)
  1285. Parse_Begin ();
  1286. Parse_Tnormal(&Element->Texture->Tnormal);
  1287. Parse_End ();
  1288. END_CASE
  1289. CASE (FINISH_TOKEN)
  1290. Parse_Finish(&Element->Texture->Finish);
  1291. END_CASE
  1292. OTHERWISE
  1293. UNGET
  1294. EXIT
  1295. END_CASE
  1296. END_EXPECT
  1297. END_CASE
  1298. OTHERWISE
  1299. UNGET
  1300. EXIT
  1301. END_CASE
  1302. END_EXPECT
  1303. Parse_End();
  1304. /* Postprocess to make sure that HAS_FILTER will be set correctly. */
  1305. Post_Textures(Element->Texture);
  1306. }
  1307. /*****************************************************************************
  1308. *
  1309. * FUNCTION
  1310. *
  1311. * Parse_Blob
  1312. *
  1313. * INPUT
  1314. *
  1315. * OUTPUT
  1316. *
  1317. * RETURNS
  1318. *
  1319. * AUTHOR
  1320. *
  1321. * Dieter Bayer
  1322. *
  1323. * DESCRIPTION
  1324. *
  1325. * -
  1326. *
  1327. * CHANGES
  1328. *
  1329. * Jul 1994 : Creation.
  1330. *
  1331. ******************************************************************************/
  1332. static OBJECT *Parse_Blob()
  1333. {
  1334. int npoints;
  1335. DBL threshold;
  1336. VECTOR Axis, Base, Apex;
  1337. BLOB *Object;
  1338. BLOB_LIST *blob_components, *blob_component;
  1339. Parse_Begin();
  1340. if ((Object = (BLOB *)Parse_Object_Id()) != NULL)
  1341. {
  1342. return ((OBJECT *) Object);
  1343. }
  1344. Object = Create_Blob();
  1345. blob_components = NULL;
  1346. npoints = 0;
  1347. threshold = 1.0;
  1348. EXPECT
  1349. CASE (THRESHOLD_TOKEN)
  1350. threshold = Parse_Float();
  1351. END_CASE
  1352. /*************************************************************************
  1353. * Read sperical component (old syntax).
  1354. *************************************************************************/
  1355. CASE (COMPONENT_TOKEN)
  1356. blob_component = Create_Blob_List_Element();
  1357. blob_component->elem.Type = BLOB_SPHERE;
  1358. blob_component->elem.c[2] = Parse_Float();
  1359. Parse_Comma();
  1360. blob_component->elem.rad2 = Parse_Float();
  1361. Parse_Comma();
  1362. blob_component->elem.rad2 = Sqr(blob_component->elem.rad2);
  1363. Parse_Vector(blob_component->elem.O);
  1364. /* Next component. */
  1365. blob_component->next = blob_components;
  1366. blob_components = blob_component;
  1367. npoints++;
  1368. END_CASE
  1369. /*************************************************************************
  1370. * Read sperical component (new syntax).
  1371. *************************************************************************/
  1372. CASE (SPHERE_TOKEN)
  1373. blob_component = Create_Blob_List_Element();
  1374. blob_component->elem.Type = BLOB_SPHERE;
  1375. Parse_Begin();
  1376. Parse_Vector(blob_component->elem.O);
  1377. Parse_Comma();
  1378. blob_component->elem.rad2 = Parse_Float();
  1379. blob_component->elem.rad2 = Sqr(blob_component->elem.rad2);
  1380. Parse_Comma();
  1381. ALLOW(STRENGTH_TOKEN)
  1382. blob_component->elem.c[2] = Parse_Float();
  1383. Parse_Blob_Element_Mods(&blob_component->elem);
  1384. /* Next component. */
  1385. blob_component->next = blob_components;
  1386. blob_components = blob_component;
  1387. npoints++;
  1388. END_CASE
  1389. /*************************************************************************
  1390. * Read cylindrical component.
  1391. *************************************************************************/
  1392. CASE (CYLINDER_TOKEN)
  1393. blob_component = Create_Blob_List_Element();
  1394. blob_component->elem.Type = BLOB_CYLINDER;
  1395. blob_component->elem.Trans = Create_Transform();
  1396. Parse_Begin();
  1397. Parse_Vector(Base);
  1398. Parse_Comma();
  1399. Parse_Vector(Apex);
  1400. Parse_Comma();
  1401. blob_component->elem.rad2 = Parse_Float();
  1402. blob_component->elem.rad2 = Sqr(blob_component->elem.rad2);
  1403. Parse_Comma();
  1404. ALLOW(STRENGTH_TOKEN)
  1405. blob_component->elem.c[2] = Parse_Float();
  1406. /* Calculate cylinder's coordinate system. */
  1407. VSub(Axis, Apex, Base);
  1408. VLength(blob_component->elem.len, Axis);
  1409. if (blob_component->elem.len < EPSILON)
  1410. {
  1411. Error("Degenerate cylindrical component in blob.\n");
  1412. }
  1413. VInverseScaleEq(Axis, blob_component->elem.len);
  1414. Compute_Coordinate_Transform(blob_component->elem.Trans, Base, Axis, 1.0, 1.0);
  1415. Parse_Blob_Element_Mods(&blob_component->elem);
  1416. /* Next component. */
  1417. blob_component->next = blob_components;
  1418. blob_components = blob_component;
  1419. npoints++;
  1420. END_CASE
  1421. OTHERWISE
  1422. UNGET
  1423. EXIT
  1424. END_CASE
  1425. END_EXPECT
  1426. Create_Blob_Element_Texture_List(Object, blob_components, npoints);
  1427. Parse_Object_Mods((OBJECT *)Object);
  1428. /* The blob's texture has to be processed before Make_Blob() is called. */
  1429. Post_Textures(Object->Texture);
  1430. /* Finally, process the information */
  1431. Make_Blob(Object, threshold, blob_components, npoints);
  1432. return((OBJECT *)Object);
  1433. }
  1434. /*****************************************************************************
  1435. *
  1436. * FUNCTION
  1437. *
  1438. * Parse_Julia_Fractal
  1439. *
  1440. * INPUT None
  1441. *
  1442. * OUTPUT Fractal Objecstructure filledt
  1443. *
  1444. * RETURNS
  1445. *
  1446. * OBJECT * -
  1447. *
  1448. * AUTHOR
  1449. *
  1450. * Pascal Massimino
  1451. *
  1452. * DESCRIPTION
  1453. *
  1454. * -
  1455. *
  1456. * CHANGES
  1457. *
  1458. * Dec 1994 : Adopted to version 3.0. [DB]
  1459. * Sept 1995 : Total rewrite for new syntax [TW]
  1460. *
  1461. ******************************************************************************/
  1462. static OBJECT *Parse_Julia_Fractal ()
  1463. {
  1464. FRACTAL *Object;
  1465. DBL P;
  1466. Parse_Begin();
  1467. if ( (Object = (FRACTAL *)Parse_Object_Id()) != NULL)
  1468. return((OBJECT *)Object);
  1469. Object = Create_Fractal();
  1470. Parse_Vector4D(Object->Julia_Parm);
  1471. EXPECT
  1472. CASE(MAX_ITERATION_TOKEN)
  1473. Object->n = (int)floor(Parse_Float());
  1474. if (Object->n <= 0)
  1475. {
  1476. Object->n = 1;
  1477. }
  1478. END_CASE
  1479. CASE(SLICE_TOKEN)
  1480. Parse_Vector4D(Object->Slice);
  1481. Parse_Comma();
  1482. Object->SliceDist = Parse_Float();
  1483. /* normalize slice vector */
  1484. V4D_Dot(P,Object->Slice, Object->Slice);
  1485. if (fabs(P) < EPSILON)
  1486. {
  1487. Error("Slice vector is zero.\n");
  1488. }
  1489. if (fabs(Object->Slice[T]) < EPSILON)
  1490. {
  1491. Error("Slice t component is zero.\n");
  1492. }
  1493. P = sqrt(P);
  1494. V4D_InverseScaleEq(Object->Slice, P);
  1495. END_CASE
  1496. CASE(PRECISION_TOKEN)
  1497. P = Parse_Float();
  1498. if ( P < 1.0 )
  1499. {
  1500. P = 1.0;
  1501. }
  1502. Object->Precision = 1.0 / P;
  1503. END_CASE
  1504. CASE(FLOAT_FUNCT_TOKEN)
  1505. switch(Token.Function_Id)
  1506. {
  1507. case EXP_TOKEN:
  1508. Object->Sub_Type = EXP_STYPE;
  1509. break;
  1510. case LOG_TOKEN:
  1511. Object->Sub_Type = LOG_STYPE;
  1512. break;
  1513. case SIN_TOKEN:
  1514. Object->Sub_Type = SIN_STYPE;
  1515. break;
  1516. case ASIN_TOKEN:
  1517. Object->Sub_Type = ASIN_STYPE;
  1518. break;
  1519. case COS_TOKEN:
  1520. Object->Sub_Type = COS_STYPE;
  1521. break;
  1522. case ACOS_TOKEN:
  1523. Object->Sub_Type = ACOS_STYPE;
  1524. break;
  1525. default: Parse_Error_Str ("fractal keyword");
  1526. }
  1527. END_CASE
  1528. /* if any of the next become supported by the expression parser,
  1529. * then their handling would need to move above to the FUNC_TOKEN
  1530. * case above.
  1531. */
  1532. CASE(ATAN_TOKEN)
  1533. Object->Sub_Type = ATAN_STYPE;
  1534. END_CASE
  1535. CASE(COSH_TOKEN)
  1536. Object->Sub_Type = COSH_STYPE;
  1537. END_CASE
  1538. CASE(SINH_TOKEN)
  1539. Object->Sub_Type = SINH_STYPE;
  1540. END_CASE
  1541. CASE(TANH_TOKEN)
  1542. Object->Sub_Type = TANH_STYPE;
  1543. END_CASE
  1544. CASE(ATANH_TOKEN)
  1545. Object->Sub_Type = ATANH_STYPE;
  1546. END_CASE
  1547. CASE(ACOSH_TOKEN)
  1548. Object->Sub_Type = ACOSH_STYPE;
  1549. END_CASE
  1550. CASE(ASINH_TOKEN)
  1551. Object->Sub_Type = ASINH_STYPE;
  1552. END_CASE
  1553. CASE(SQR_TOKEN)
  1554. Object->Sub_Type = SQR_STYPE;
  1555. END_CASE
  1556. CASE(PWR_TOKEN)
  1557. Object->Sub_Type = PWR_STYPE;
  1558. Parse_Float_Param2(&Object->exponent.x,&Object->exponent.y);
  1559. END_CASE
  1560. CASE(CUBE_TOKEN)
  1561. Object->Sub_Type = CUBE_STYPE;
  1562. END_CASE
  1563. CASE(RECIPROCAL_TOKEN)
  1564. Object->Sub_Type = RECIPROCAL_STYPE;
  1565. END_CASE
  1566. CASE(HYPERCOMPLEX_TOKEN)
  1567. Object->Algebra = HYPERCOMPLEX_TYPE;
  1568. END_CASE
  1569. CASE(QUATERNION_TOKEN)
  1570. Object->Algebra = QUATERNION_TYPE;
  1571. END_CASE
  1572. OTHERWISE
  1573. UNGET
  1574. EXIT
  1575. END_CASE
  1576. END_EXPECT
  1577. Parse_Object_Mods((OBJECT *)Object);
  1578. SetUp_Fractal(Object);
  1579. return((OBJECT *)Object);
  1580. }
  1581. /*****************************************************************************
  1582. *
  1583. * FUNCTION
  1584. *
  1585. * Parse_Polygon
  1586. *
  1587. * INPUT
  1588. *
  1589. * OUTPUT
  1590. *
  1591. * RETURNS
  1592. *
  1593. * OBJECT * -
  1594. *
  1595. * AUTHOR
  1596. *
  1597. * Dieter Bayer
  1598. *
  1599. * DESCRIPTION
  1600. *
  1601. * -
  1602. *
  1603. * CHANGES
  1604. *
  1605. * May 1994 : Creation.
  1606. *
  1607. * Oct 1994 : Modified to use new polygon data structure. [DB]
  1608. *
  1609. ******************************************************************************/
  1610. static OBJECT *Parse_Polygon()
  1611. {
  1612. int i, closed = FALSE;
  1613. int Number;
  1614. POLYGON *Object;
  1615. VECTOR *Points, P;
  1616. Parse_Begin();
  1617. if ((Object = (POLYGON *)Parse_Object_Id()) != NULL)
  1618. {
  1619. return((OBJECT *) Object);
  1620. }
  1621. Object = Create_Polygon();
  1622. Number = (int)Parse_Float();
  1623. if (Number < 3)
  1624. {
  1625. Error("Polygon needs at least three points.");
  1626. }
  1627. Points = (VECTOR *)POV_MALLOC((Number+1)*sizeof(VECTOR), "temporary polygon points");
  1628. for (i = 0; i < Number; i++)
  1629. {
  1630. Parse_Comma();
  1631. Parse_Vector(Points[i]);
  1632. }
  1633. /* Check for closed polygons. */
  1634. Assign_Vector(P, Points[0]);
  1635. for (i = 1; i < Number; i++)
  1636. {
  1637. closed = FALSE;
  1638. if ((fabs(P[X] - Points[i][X]) < EPSILON) &&
  1639. (fabs(P[Y] - Points[i][Y]) < EPSILON) &&
  1640. (fabs(P[Z] - Points[i][Z]) < EPSILON))
  1641. {
  1642. i++;
  1643. if (i < Number)
  1644. {
  1645. Assign_Vector(P, Points[i]);
  1646. }
  1647. closed = TRUE;
  1648. }
  1649. }
  1650. if (!closed)
  1651. {
  1652. Warn(0.0, "Polygon not closed. Closing it.");
  1653. Assign_Vector(Points[Number], P);
  1654. Number++;
  1655. }
  1656. Compute_Polygon(Object, Number, Points);
  1657. POV_FREE (Points);
  1658. Parse_Object_Mods ((OBJECT *)Object);
  1659. return((OBJECT *) Object);
  1660. }
  1661. /*****************************************************************************
  1662. *
  1663. * FUNCTION
  1664. *
  1665. * Parse_Prism
  1666. *
  1667. * INPUT
  1668. *
  1669. * OUTPUT
  1670. *
  1671. * RETURNS
  1672. *
  1673. * OBJECT * -
  1674. *
  1675. * AUTHOR
  1676. *
  1677. * Dieter Bayer
  1678. *
  1679. * DESCRIPTION
  1680. *
  1681. * -
  1682. *
  1683. * CHANGES
  1684. *
  1685. * May 1994 : Creation.
  1686. *
  1687. ******************************************************************************/
  1688. static OBJECT *Parse_Prism()
  1689. {
  1690. int i, closed = FALSE;
  1691. DBL h;
  1692. PRISM *Object;
  1693. UV_VECT *Points, P;
  1694. Parse_Begin();
  1695. if ((Object = (PRISM *)Parse_Object_Id()) != NULL)
  1696. {
  1697. return((OBJECT *) Object);
  1698. }
  1699. Object = Create_Prism();
  1700. /*
  1701. * Determine kind of spline used (linear, quadratic, cubic)
  1702. * and type of sweeping (linear, conic).
  1703. */
  1704. EXPECT
  1705. CASE(LINEAR_SPLINE_TOKEN)
  1706. Object->Spline_Type = LINEAR_SPLINE;
  1707. END_CASE
  1708. CASE(QUADRATIC_SPLINE_TOKEN)
  1709. Object->Spline_Type = QUADRATIC_SPLINE;
  1710. END_CASE
  1711. CASE(CUBIC_SPLINE_TOKEN)
  1712. Object->Spline_Type = CUBIC_SPLINE;
  1713. END_CASE
  1714. CASE(BEZIER_SPLINE_TOKEN)
  1715. Object->Spline_Type = BEZIER_SPLINE;
  1716. END_CASE
  1717. CASE(LINEAR_SWEEP_TOKEN)
  1718. Object->Sweep_Type = LINEAR_SWEEP;
  1719. END_CASE
  1720. CASE(CONIC_SWEEP_TOKEN)
  1721. Object->Sweep_Type = CONIC_SWEEP;
  1722. END_CASE
  1723. OTHERWISE
  1724. UNGET
  1725. EXIT
  1726. END_CASE
  1727. END_EXPECT
  1728. /* Read prism heights. */
  1729. Object->Height1 = Parse_Float(); Parse_Comma();
  1730. Object->Height2 = Parse_Float(); Parse_Comma();
  1731. if (Object->Height1 > Object->Height2)
  1732. {
  1733. h = Object->Height1;
  1734. Object->Height1 = Object->Height2;
  1735. Object->Height2 = h;
  1736. }
  1737. /* Get number of points = number of segments. */
  1738. Object->Number = (int)Parse_Float();
  1739. switch (Object->Spline_Type)
  1740. {
  1741. case LINEAR_SPLINE :
  1742. if (Object->Number < 3)
  1743. {
  1744. Error("Prism with linear splines must have at least three points.");
  1745. }
  1746. break;
  1747. case QUADRATIC_SPLINE :
  1748. if (Object->Number < 5)
  1749. {
  1750. Error("Prism with quadratic splines must have at least five points.");
  1751. }
  1752. break;
  1753. case CUBIC_SPLINE :
  1754. if (Object->Number < 6)
  1755. {
  1756. Error("Prism with cubic splines must have at least six points.");
  1757. }
  1758. break;
  1759. case BEZIER_SPLINE :
  1760. if ((Object->Number & 3) != 0)
  1761. {
  1762. Error("Prism with Bezier splines must have four points per segment.");
  1763. }
  1764. break;
  1765. }
  1766. /* Allocate Object->Number points for the prism. */
  1767. Points = (UV_VECT *)POV_MALLOC((Object->Number+1) * sizeof(UV_VECT), "temporary prism points");
  1768. /* Read points (x, y : coordinate of 2d point; z : not used). */
  1769. for (i = 0; i < Object->Number; i++)
  1770. {
  1771. Parse_Comma();
  1772. Parse_UV_Vect(Points[i]);
  1773. }
  1774. /* Closed or not closed that's the question. */
  1775. EXPECT
  1776. CASE(OPEN_TOKEN)
  1777. Clear_Flag(Object, CLOSED_FLAG);
  1778. EXIT
  1779. END_CASE
  1780. OTHERWISE
  1781. UNGET
  1782. EXIT
  1783. END_CASE
  1784. END_EXPECT
  1785. /* Check for closed prism. */
  1786. if ((Object->Spline_Type == LINEAR_SPLINE) ||
  1787. (Object->Spline_Type == QUADRATIC_SPLINE) ||
  1788. (Object->Spline_Type == CUBIC_SPLINE))
  1789. {
  1790. switch (Object->Spline_Type)
  1791. {
  1792. case LINEAR_SPLINE :
  1793. i = 1;
  1794. Assign_UV_Vect(P, Points[0]);
  1795. break;
  1796. case QUADRATIC_SPLINE :
  1797. case CUBIC_SPLINE :
  1798. i = 2;
  1799. Assign_UV_Vect(P, Points[1]);
  1800. break;
  1801. }
  1802. for ( ; i < Object->Number; i++)
  1803. {
  1804. closed = FALSE;
  1805. if ((fabs(P[X] - Points[i][X]) < EPSILON) &&
  1806. (fabs(P[Y] - Points[i][Y]) < EPSILON))
  1807. {
  1808. switch (Object->Spline_Type)
  1809. {
  1810. case LINEAR_SPLINE :
  1811. i++;
  1812. if (i < Object->Number)
  1813. {
  1814. Assign_UV_Vect(P, Points[i]);
  1815. }
  1816. break;
  1817. case QUADRATIC_SPLINE :
  1818. i += 2;
  1819. if (i < Object->Number)
  1820. {
  1821. Assign_UV_Vect(P, Points[i]);
  1822. }
  1823. break;
  1824. case CUBIC_SPLINE :
  1825. i += 3;
  1826. if (i < Object->Number)
  1827. {
  1828. Assign_UV_Vect(P, Points[i]);
  1829. }
  1830. break;
  1831. }
  1832. closed = TRUE;
  1833. }
  1834. }
  1835. }
  1836. else
  1837. {
  1838. closed = TRUE;
  1839. for (i = 0; i < Object->Number; i += 4)
  1840. {
  1841. if ((fabs(Points[i][X] - Points[(i-1+Object->Number) % Object->Number][X]) > EPSILON) ||
  1842. (fabs(Points[i][Y] - Points[(i-1+Object->Number) % Object->Number][Y]) > EPSILON))
  1843. {
  1844. closed = FALSE;
  1845. break;
  1846. }
  1847. }
  1848. }
  1849. if (!closed)
  1850. {
  1851. if (Object->Spline_Type == LINEAR_SPLINE)
  1852. {
  1853. Assign_UV_Vect(Points[Object->Number], P);
  1854. Object->Number++;
  1855. Warn(0.0, "Linear prism not closed. Closing it.");
  1856. }
  1857. else
  1858. {
  1859. Set_Flag(Object, DEGENERATE_FLAG);
  1860. Warn(0.0, "Prism not closed. Ignoring it.");
  1861. }
  1862. }
  1863. /* Compute spline segments. */
  1864. Compute_Prism(Object, Points);
  1865. /* Compute bounding box. */
  1866. Compute_Prism_BBox(Object);
  1867. /* Parse object's modifiers. */
  1868. Parse_Object_Mods((OBJECT *)Object);
  1869. /* Destroy temporary points. */
  1870. POV_FREE (Points);
  1871. return((OBJECT *) Object);
  1872. }
  1873. /*****************************************************************************
  1874. *
  1875. * FUNCTION
  1876. *
  1877. * Parse_Sor
  1878. *
  1879. * INPUT
  1880. *
  1881. * OUTPUT
  1882. *
  1883. * RETURNS
  1884. *
  1885. * OBJECT * -
  1886. *
  1887. * AUTHOR
  1888. *
  1889. * Dieter Bayer
  1890. *
  1891. * DESCRIPTION
  1892. *
  1893. * Read a surface of revolution primitive.
  1894. *
  1895. * CHANGES
  1896. *
  1897. * May 1994 : Creation.
  1898. *
  1899. ******************************************************************************/
  1900. static OBJECT *Parse_Sor()
  1901. {
  1902. int i;
  1903. SOR *Object;
  1904. UV_VECT *Points;
  1905. Parse_Begin();
  1906. if ((Object = (SOR *)Parse_Object_Id()) != NULL)
  1907. {
  1908. return((OBJECT *)Object);
  1909. }
  1910. Object = Create_Sor();
  1911. /* Get number of points. */
  1912. Object->Number = (int)Parse_Float();
  1913. if (Object->Number <4)
  1914. {
  1915. Error("Surface of revolution must have at least four points.");
  1916. }
  1917. /* Get temporary points describing the rotated curve. */
  1918. Points = (UV_VECT *)POV_MALLOC(Object->Number*sizeof(UV_VECT), "temporary surface of revolution points");
  1919. /* Read points (x : radius; y : height; z : not used). */
  1920. for (i = 0; i < Object->Number; i++)
  1921. {
  1922. Parse_Comma();
  1923. Parse_UV_Vect(Points[i]);
  1924. if ((Points[i][X] < 0.0) ||
  1925. ((i > 1 ) && (i < Object->Number - 1) && (Points[i][Y] <= Points[i-1][Y])))
  1926. {
  1927. Error("Incorrect point in surface of revolution.");
  1928. }
  1929. }
  1930. /* Closed or not closed that's the question. */
  1931. EXPECT
  1932. CASE(OPEN_TOKEN)
  1933. Clear_Flag(Object, CLOSED_FLAG);
  1934. EXIT
  1935. END_CASE
  1936. OTHERWISE
  1937. UNGET
  1938. EXIT
  1939. END_CASE
  1940. END_EXPECT
  1941. /* There are Number-3 segments! */
  1942. Object->Number -= 3;
  1943. /* Compute spline segments. */
  1944. Compute_Sor(Object, Points);
  1945. /* Compute bounding box. */
  1946. Compute_Sor_BBox(Object);
  1947. /* Parse object's modifiers. */
  1948. Parse_Object_Mods((OBJECT *)Object);
  1949. /* Destroy temporary points. */
  1950. POV_FREE (Points);
  1951. return ((OBJECT *) Object);
  1952. }
  1953. /*****************************************************************************
  1954. *
  1955. * FUNCTION
  1956. *
  1957. * Parse_Lathe
  1958. *
  1959. * INPUT
  1960. *
  1961. * OUTPUT
  1962. *
  1963. * RETURNS
  1964. *
  1965. * OBJECT * -
  1966. *
  1967. * AUTHOR
  1968. *
  1969. * Dieter Bayer
  1970. *
  1971. * DESCRIPTION
  1972. *
  1973. * Read a lathe primitive.
  1974. *
  1975. * CHANGES
  1976. *
  1977. * Jun 1994 : Creation.
  1978. *
  1979. ******************************************************************************/
  1980. static OBJECT *Parse_Lathe()
  1981. {
  1982. int i;
  1983. LATHE *Object;
  1984. UV_VECT *Points;
  1985. Parse_Begin();
  1986. if ((Object = (LATHE *)Parse_Object_Id()) != NULL)
  1987. {
  1988. return((OBJECT *)Object);
  1989. }
  1990. Object = Create_Lathe();
  1991. /* Determine kind of spline used and aspect ratio. */
  1992. EXPECT
  1993. CASE(LINEAR_SPLINE_TOKEN)
  1994. Object->Spline_Type = LINEAR_SPLINE;
  1995. END_CASE
  1996. CASE(QUADRATIC_SPLINE_TOKEN)
  1997. Object->Spline_Type = QUADRATIC_SPLINE;
  1998. END_CASE
  1999. CASE(CUBIC_SPLINE_TOKEN)
  2000. Object->Spline_Type = CUBIC_SPLINE;
  2001. END_CASE
  2002. CASE(BEZIER_SPLINE_TOKEN)
  2003. Object->Spline_Type = BEZIER_SPLINE;
  2004. END_CASE
  2005. OTHERWISE
  2006. UNGET
  2007. EXIT
  2008. END_CASE
  2009. END_EXPECT
  2010. /* Get number of points. */
  2011. Object->Number = (int)Parse_Float();
  2012. switch (Object->Spline_Type)
  2013. {
  2014. case LINEAR_SPLINE :
  2015. if (Object->Number < 2)
  2016. {
  2017. Error("Lathe with linear splines must have at least two points.");
  2018. }
  2019. break;
  2020. case QUADRATIC_SPLINE :
  2021. if (Object->Number < 3)
  2022. {
  2023. Error("Lathe with quadratic splines must have at least three points.");
  2024. }
  2025. break;
  2026. case CUBIC_SPLINE :
  2027. if (Object->Number < 4)
  2028. {
  2029. Error("Prism with cubic splines must have at least four points.");
  2030. }
  2031. break;
  2032. case BEZIER_SPLINE :
  2033. if ((Object->Number & 3) != 0)
  2034. {
  2035. Error("Lathe with Bezier splines must have four points per segment.");
  2036. }
  2037. break;
  2038. }
  2039. /* Get temporary points describing the rotated curve. */
  2040. Points = (UV_VECT *)POV_MALLOC(Object->Number*sizeof(UV_VECT), "temporary lathe points");
  2041. /* Read points (x : radius; y : height; z : not used). */
  2042. for (i = 0; i < Object->Number; i++)
  2043. {
  2044. Parse_Comma();
  2045. Parse_UV_Vect(Points[i]);
  2046. if ((i > 0) && (i < Object->Number - 1) && (Points[i][X] < 0.0))
  2047. {
  2048. Error("Incorrect point in lathe.");
  2049. }
  2050. }
  2051. /* Compute spline segments. */
  2052. Compute_Lathe(Object, Points);
  2053. /* Compute bounding box. */
  2054. Compute_Lathe_BBox(Object);
  2055. /* Parse object's modifiers. */
  2056. Parse_Object_Mods((OBJECT *)Object);
  2057. /* Destroy temporary points. */
  2058. POV_FREE (Points);
  2059. return((OBJECT *) Object);
  2060. }
  2061. /*****************************************************************************
  2062. *
  2063. * FUNCTION
  2064. *
  2065. * Parse_Superellipsoid
  2066. *
  2067. * INPUT
  2068. *
  2069. * OUTPUT
  2070. *
  2071. * RETURNS
  2072. *
  2073. * OBJECT * -
  2074. *
  2075. * AUTHOR
  2076. *
  2077. * Dieter Bayer
  2078. *
  2079. * DESCRIPTION
  2080. *
  2081. * Read a superellipsoid primitive.
  2082. *
  2083. * CHANGES
  2084. *
  2085. * Oct 1994 : Creation.
  2086. *
  2087. ******************************************************************************/
  2088. static OBJECT *Parse_Superellipsoid()
  2089. {
  2090. UV_VECT V1;
  2091. SUPERELLIPSOID *Object;
  2092. Parse_Begin();
  2093. if ((Object = (SUPERELLIPSOID *)Parse_Object_Id()) != NULL)
  2094. {
  2095. return((OBJECT *)Object);
  2096. }
  2097. Object = Create_Superellipsoid();
  2098. Parse_UV_Vect(V1);
  2099. /* The x component is e, the y component is n. */
  2100. Object->Power[X] = 2.0 / V1[X];
  2101. Object->Power[Y] = V1[X] / V1[Y];
  2102. Object->Power[Z] = 2.0 / V1[Y];
  2103. /* Compute bounding box. */
  2104. Compute_Superellipsoid_BBox(Object);
  2105. /* Parse object's modifiers. */
  2106. Parse_Object_Mods((OBJECT *)Object);
  2107. return((OBJECT *) Object);
  2108. }
  2109. /*****************************************************************************
  2110. *
  2111. * FUNCTION
  2112. *
  2113. * Parse_Torus
  2114. *
  2115. * INPUT
  2116. *
  2117. * OUTPUT
  2118. *
  2119. * RETURNS
  2120. *
  2121. * OBJECT
  2122. *
  2123. * AUTHOR
  2124. *
  2125. * Dieter Bayer
  2126. *
  2127. * DESCRIPTION
  2128. *
  2129. * -
  2130. *
  2131. * CHANGES
  2132. *
  2133. * Jul 1994 : Creation.
  2134. *
  2135. ******************************************************************************/
  2136. static OBJECT *Parse_Torus()
  2137. {
  2138. TORUS *Object;
  2139. Parse_Begin();
  2140. if ((Object = (TORUS *)Parse_Object_Id()) != NULL)
  2141. {
  2142. return((OBJECT *)Object);
  2143. }
  2144. Object = Create_Torus();
  2145. /* Read in the two radii. */
  2146. Object->R = Parse_Float(); /* Big radius */
  2147. Parse_Comma();
  2148. Object->r = Parse_Float(); /* Little radius */
  2149. Compute_Torus_BBox(Object);
  2150. Parse_Object_Mods ((OBJECT *)Object);
  2151. return ((OBJECT *) Object);
  2152. }
  2153. /*****************************************************************************
  2154. *
  2155. * FUNCTION
  2156. *
  2157. * Parse_Mesh_Texture
  2158. *
  2159. * INPUT
  2160. *
  2161. * OUTPUT
  2162. *
  2163. * RETURNS
  2164. *
  2165. * OBJECT
  2166. *
  2167. * AUTHOR
  2168. *
  2169. * Dieter Bayer
  2170. *
  2171. * DESCRIPTION
  2172. *
  2173. * Read an individual triangle mesh texture.
  2174. *
  2175. * CHANGES
  2176. *
  2177. * Feb 1995 : Creation.
  2178. *
  2179. ******************************************************************************/
  2180. static TEXTURE *Parse_Mesh_Texture()
  2181. {
  2182. TEXTURE *Texture;
  2183. Texture = NULL;
  2184. EXPECT
  2185. CASE(TEXTURE_TOKEN)
  2186. Parse_Begin();
  2187. GET(TEXTURE_ID_TOKEN);
  2188. Texture = (TEXTURE *)Token.Data;
  2189. Parse_End();
  2190. END_CASE
  2191. OTHERWISE
  2192. UNGET
  2193. EXIT
  2194. END_CASE
  2195. END_EXPECT
  2196. return(Texture);
  2197. }
  2198. /*****************************************************************************
  2199. *
  2200. * FUNCTION
  2201. *
  2202. * Parse_Mesh
  2203. *
  2204. * INPUT
  2205. *
  2206. * OUTPUT
  2207. *
  2208. * RETURNS
  2209. *
  2210. * OBJECT
  2211. *
  2212. * AUTHOR
  2213. *
  2214. * Dieter Bayer
  2215. *
  2216. * DESCRIPTION
  2217. *
  2218. * Read a triangle mesh.
  2219. *
  2220. * CHANGES
  2221. *
  2222. * Feb 1995 : Creation.
  2223. *
  2224. ******************************************************************************/
  2225. static OBJECT *Parse_Mesh()
  2226. {
  2227. int i;
  2228. int number_of_normals, number_of_textures, number_of_triangles, number_of_vertices;
  2229. int max_normals, max_textures, max_triangles, max_vertices;
  2230. DBL l1, l2, l3;
  2231. VECTOR D1, D2, P1, P2, P3, N1, N2, N3, N;
  2232. SNGL_VECT *Normals, *Vertices;
  2233. TEXTURE **Textures;
  2234. MESH *Object;
  2235. MESH_TRIANGLE *Triangles;
  2236. int fully_textured=TRUE;
  2237. Parse_Begin();
  2238. if ((Object = (MESH *)Parse_Object_Id()) != NULL)
  2239. {
  2240. return((OBJECT *)Object);
  2241. }
  2242. /* Create object. */
  2243. Object = Create_Mesh();
  2244. /* Allocate temporary normals, textures, triangles and vertices. */
  2245. max_normals = 256;
  2246. max_vertices = 256;
  2247. max_textures = 16;
  2248. max_triangles = 256;
  2249. Normals = (SNGL_VECT *)POV_MALLOC(max_normals*sizeof(SNGL_VECT), "temporary triangle mesh data");
  2250. Textures = (TEXTURE **)POV_MALLOC(max_textures*sizeof(TEXTURE *), "temporary triangle mesh data");
  2251. Triangles = (MESH_TRIANGLE *)POV_MALLOC(max_triangles*sizeof(MESH_TRIANGLE), "temporary triangle mesh data");
  2252. Vertices = (SNGL_VECT *)POV_MALLOC(max_vertices*sizeof(SNGL_VECT), "temporary triangle mesh data");
  2253. /* Read raw triangle file. */
  2254. number_of_normals = 0;
  2255. number_of_textures = 0;
  2256. number_of_triangles = 0;
  2257. number_of_vertices = 0;
  2258. /* Create hash tables. */
  2259. Create_Mesh_Hash_Tables();
  2260. EXPECT
  2261. CASE(TRIANGLE_TOKEN)
  2262. Parse_Begin();
  2263. Parse_Vector(P1); Parse_Comma();
  2264. Parse_Vector(P2); Parse_Comma();
  2265. Parse_Vector(P3);
  2266. if (!Mesh_Degenerate(P1, P2, P3))
  2267. {
  2268. if (number_of_triangles >= max_triangles)
  2269. {
  2270. if (max_triangles >= INT_MAX/2)
  2271. {
  2272. Error("Too many triangles in triangle mesh.\n");
  2273. }
  2274. max_triangles *= 2;
  2275. Triangles = (MESH_TRIANGLE *)POV_REALLOC(Triangles, max_triangles*sizeof(MESH_TRIANGLE), "triangle triangle mesh data");
  2276. }
  2277. /* Init triangle. */
  2278. Init_Mesh_Triangle(&Triangles[number_of_triangles]);
  2279. Triangles[number_of_triangles].P1 = Mesh_Hash_Vertex(&number_of_vertices, &max_vertices, &Vertices, P1);
  2280. Triangles[number_of_triangles].P2 = Mesh_Hash_Vertex(&number_of_vertices, &max_vertices, &Vertices, P2);
  2281. Triangles[number_of_triangles].P3 = Mesh_Hash_Vertex(&number_of_vertices, &max_vertices, &Vertices, P3);
  2282. Compute_Mesh_Triangle(&Triangles[number_of_triangles], FALSE, P1, P2, P3, N);
  2283. Triangles[number_of_triangles].Normal_Ind = Mesh_Hash_Normal(&number_of_normals, &max_normals, &Normals, N);
  2284. Triangles[number_of_triangles].Texture = Mesh_Hash_Texture(&number_of_textures, &max_textures, &Textures, Parse_Mesh_Texture());
  2285. if (Triangles[number_of_triangles].Texture < 0)
  2286. {
  2287. fully_textured = FALSE;
  2288. }
  2289. number_of_triangles++;
  2290. }
  2291. Parse_End();
  2292. END_CASE
  2293. CASE(SMOOTH_TRIANGLE_TOKEN)
  2294. Parse_Begin();
  2295. Parse_Vector(P1); Parse_Comma();
  2296. Parse_Vector(N1); Parse_Comma();
  2297. Parse_Vector(P2); Parse_Comma();
  2298. Parse_Vector(N2); Parse_Comma();
  2299. Parse_Vector(P3); Parse_Comma();
  2300. Parse_Vector(N3);
  2301. VLength(l1, N1);
  2302. VLength(l2, N2);
  2303. VLength(l3, N3);
  2304. if ((l1 != 0.0) && (l2 != 0.0) && (l3 != 0.0) && (!Mesh_Degenerate(P1, P2, P3)))
  2305. {
  2306. if (number_of_triangles >= max_triangles)
  2307. {
  2308. if (max_triangles >= INT_MAX/2)
  2309. {
  2310. Error("Too many triangles in triangle mesh.\n");
  2311. }
  2312. max_triangles *= 2;
  2313. Triangles = (MESH_TRIANGLE *)POV_REALLOC(Triangles, max_triangles*sizeof(MESH_TRIANGLE), "triangle triangle mesh data");
  2314. }
  2315. VInverseScaleEq(N1, l1);
  2316. VInverseScaleEq(N2, l2);
  2317. VInverseScaleEq(N3, l3);
  2318. /* Init triangle. */
  2319. Init_Mesh_Triangle(&Triangles[number_of_triangles]);
  2320. Triangles[number_of_triangles].P1 = Mesh_Hash_Vertex(&number_of_vertices, &max_vertices, &Vertices, P1);
  2321. Triangles[number_of_triangles].P2 = Mesh_Hash_Vertex(&number_of_vertices, &max_vertices, &Vertices, P2);
  2322. Triangles[number_of_triangles].P3 = Mesh_Hash_Vertex(&number_of_vertices, &max_vertices, &Vertices, P3);
  2323. /* Check for equal normals. */
  2324. VSub(D1, N1, N2);
  2325. VSub(D2, N1, N3);
  2326. VDot(l1, D1, D1);
  2327. VDot(l2, D2, D2);
  2328. if ((fabs(l1) > EPSILON) || (fabs(l2) > EPSILON))
  2329. {
  2330. /* Smooth triangle. */
  2331. Triangles[number_of_triangles].N1 = Mesh_Hash_Normal(&number_of_normals, &max_normals, &Normals, N1);
  2332. Triangles[number_of_triangles].N2 = Mesh_Hash_Normal(&number_of_normals, &max_normals, &Normals, N2);
  2333. Triangles[number_of_triangles].N3 = Mesh_Hash_Normal(&number_of_normals, &max_normals, &Normals, N3);
  2334. Compute_Mesh_Triangle(&Triangles[number_of_triangles], TRUE, P1, P2, P3, N);
  2335. }
  2336. else
  2337. {
  2338. /* Flat triangle. */
  2339. Compute_Mesh_Triangle(&Triangles[number_of_triangles], FALSE, P1, P2, P3, N);
  2340. }
  2341. Triangles[number_of_triangles].Normal_Ind = Mesh_Hash_Normal(&number_of_normals, &max_normals, &Normals, N);
  2342. Triangles[number_of_triangles].Texture = Mesh_Hash_Texture(&number_of_textures, &max_textures, &Textures, Parse_Mesh_Texture());
  2343. if (Triangles[number_of_triangles].Texture < 0)
  2344. {
  2345. fully_textured = FALSE;
  2346. }
  2347. number_of_triangles++;
  2348. }
  2349. Parse_End();
  2350. END_CASE
  2351. OTHERWISE
  2352. UNGET
  2353. EXIT
  2354. END_CASE
  2355. END_EXPECT
  2356. /* Destroy hash tables. */
  2357. Destroy_Mesh_Hash_Tables();
  2358. /* If there are no triangles something went wrong. */
  2359. if (number_of_triangles == 0)
  2360. {
  2361. Error("No triangles in triangle mesh.\n");
  2362. }
  2363. /* Init triangle mesh data. */
  2364. Object->Data = (MESH_DATA *)POV_MALLOC(sizeof(MESH_DATA), "triangle mesh data");
  2365. Object->Data->References = 1;
  2366. Object->Data->Tree = NULL;
  2367. Object->Data->Normals = NULL;
  2368. Object->Data->Textures = NULL;
  2369. Object->Data->Triangles = NULL;
  2370. Object->Data->Vertices = NULL;
  2371. /* Allocate memory for normals, textures, triangles and vertices. */
  2372. Object->Data->Number_Of_Normals = number_of_normals;
  2373. Object->Data->Number_Of_Textures = number_of_textures;
  2374. Object->Data->Number_Of_Triangles = number_of_triangles;
  2375. Object->Data->Number_Of_Vertices = number_of_vertices;
  2376. Object->Data->Normals = (SNGL_VECT *)POV_MALLOC(number_of_normals*sizeof(SNGL_VECT), "triangle mesh data");
  2377. if (number_of_textures)
  2378. {
  2379. Set_Flag(Object, MULTITEXTURE_FLAG);
  2380. Object->Data->Textures = (TEXTURE **)POV_MALLOC(number_of_textures*sizeof(TEXTURE *), "triangle mesh data");
  2381. }
  2382. Object->Data->Triangles = (MESH_TRIANGLE *)POV_MALLOC(number_of_triangles*sizeof(MESH_TRIANGLE), "triangle mesh data");
  2383. Object->Data->Vertices = (SNGL_VECT *)POV_MALLOC(number_of_vertices*sizeof(SNGL_VECT), "triangle mesh data");
  2384. /* Copy normals, textures, triangles and vertices into mesh. */
  2385. for (i = 0; i < number_of_normals; i++)
  2386. {
  2387. Assign_SNGL_Vect(Object->Data->Normals[i], Normals[i]);
  2388. }
  2389. for (i = 0; i < number_of_textures; i++)
  2390. {
  2391. Object->Data->Textures[i] = Copy_Textures(Textures[i]);
  2392. /* now free the texture, in order to decrement the reference count */
  2393. Destroy_Textures(Textures[i]);
  2394. }
  2395. if (fully_textured)
  2396. {
  2397. Object->Type |= TEXTURED_OBJECT;
  2398. }
  2399. for (i = 0; i < number_of_triangles; i++)
  2400. {
  2401. Object->Data->Triangles[i] = Triangles[i];
  2402. }
  2403. for (i = 0; i < number_of_vertices; i++)
  2404. {
  2405. Assign_SNGL_Vect(Object->Data->Vertices[i], Vertices[i]);
  2406. }
  2407. /* Free temporary memory. */
  2408. POV_FREE(Normals);
  2409. POV_FREE(Textures);
  2410. POV_FREE(Triangles);
  2411. POV_FREE(Vertices);
  2412. /*
  2413. Render_Info("Mesh: %ld bytes: %ld vertices, %ld normals, %ld textures, %ld triangles\n",
  2414. Object->Data->Number_Of_Normals*sizeof(SNGL_VECT)+
  2415. Object->Data->Number_Of_Textures*sizeof(TEXTURE *)+
  2416. Object->Data->Number_Of_Triangles*sizeof(MESH_TRIANGLE)+
  2417. Object->Data->Number_Of_Vertices*sizeof(SNGL_VECT),
  2418. Object->Data->Number_Of_Vertices,
  2419. Object->Data->Number_Of_Normals,
  2420. Object->Data->Number_Of_Textures,
  2421. Object->Data->Number_Of_Triangles);
  2422. */
  2423. /* Create bounding box. */
  2424. Compute_Mesh_BBox(Object);
  2425. /* Parse object modifiers. */
  2426. Parse_Object_Mods((OBJECT *)Object);
  2427. /* Create bounding box tree. */
  2428. Build_Mesh_BBox_Tree(Object);
  2429. return((OBJECT *)Object);
  2430. }
  2431. /*****************************************************************************
  2432. *
  2433. * FUNCTION
  2434. *
  2435. * INPUT
  2436. *
  2437. * OUTPUT
  2438. *
  2439. * RETURNS
  2440. *
  2441. * AUTHOR
  2442. *
  2443. * DESCRIPTION
  2444. *
  2445. * CHANGES
  2446. *
  2447. ******************************************************************************/
  2448. static
  2449. OBJECT *Parse_Poly (int order)
  2450. {
  2451. POLY *Object;
  2452. Parse_Begin ();
  2453. if ( (Object = (POLY *)Parse_Object_Id()) != NULL)
  2454. return ((OBJECT *) Object);
  2455. if (order == 0)
  2456. {
  2457. order = (int)Parse_Float(); Parse_Comma();
  2458. if (order < 2 || order > MAX_ORDER)
  2459. Error("Order of poly is out of range.");
  2460. }
  2461. Object = Create_Poly(order);
  2462. Parse_Coeffs(Object->Order, &(Object->Coeffs[0]));
  2463. Compute_Poly_BBox(Object);
  2464. Parse_Object_Mods ((OBJECT *)Object);
  2465. return ((OBJECT *) Object);
  2466. }
  2467. /*****************************************************************************
  2468. *
  2469. * FUNCTION
  2470. *
  2471. * INPUT
  2472. *
  2473. * OUTPUT
  2474. *
  2475. * RETURNS
  2476. *
  2477. * AUTHOR
  2478. *
  2479. * DESCRIPTION
  2480. *
  2481. * CHANGES
  2482. *
  2483. ******************************************************************************/
  2484. static
  2485. OBJECT *Parse_Bicubic_Patch ()
  2486. {
  2487. BICUBIC_PATCH *Object;
  2488. int i, j;
  2489. Parse_Begin ();
  2490. if ( (Object = (BICUBIC_PATCH *)Parse_Object_Id()) != NULL)
  2491. return ((OBJECT *) Object);
  2492. Object = Create_Bicubic_Patch();
  2493. EXPECT
  2494. CASE_FLOAT
  2495. Warn(1.5, "Should use keywords for bicubic parameters.");
  2496. Object->Patch_Type = (int)Parse_Float();
  2497. if (Object->Patch_Type == 2 ||
  2498. Object->Patch_Type == 3)
  2499. Object->Flatness_Value = Parse_Float();
  2500. else
  2501. Object->Flatness_Value = 0.1;
  2502. Object->U_Steps = (int)Parse_Float();
  2503. Object->V_Steps = (int)Parse_Float();
  2504. EXIT
  2505. END_CASE
  2506. CASE (TYPE_TOKEN)
  2507. Object->Patch_Type = (int)Parse_Float();
  2508. END_CASE
  2509. CASE (FLATNESS_TOKEN)
  2510. Object->Flatness_Value = Parse_Float();
  2511. END_CASE
  2512. CASE (V_STEPS_TOKEN)
  2513. Object->V_Steps = (int)Parse_Float();
  2514. END_CASE
  2515. CASE (U_STEPS_TOKEN)
  2516. Object->U_Steps = (int)Parse_Float();
  2517. END_CASE
  2518. OTHERWISE
  2519. UNGET
  2520. EXIT
  2521. END_CASE
  2522. END_EXPECT
  2523. if (Object->Patch_Type > 1)
  2524. {
  2525. Object->Patch_Type = 1;
  2526. Warn(0.0, "Patch type no longer supported. Using type 1.");
  2527. }
  2528. if ((Object->Patch_Type < 0) || (Object->Patch_Type > MAX_PATCH_TYPE))
  2529. Error("Undefined bicubic patch type.");
  2530. Parse_Comma();
  2531. for (i=0;i<4;i++)
  2532. for (j=0;j<4;j++)
  2533. {
  2534. Parse_Vector(Object->Control_Points[i][j]);
  2535. if (!((i==3)&&(j==3)))
  2536. Parse_Comma();
  2537. };
  2538. Precompute_Patch_Values(Object); /* interpolated mesh coords */
  2539. Compute_Bicubic_Patch_BBox(Object);
  2540. Parse_Object_Mods ((OBJECT *)Object);
  2541. return ((OBJECT *) Object);
  2542. }
  2543. /*****************************************************************************
  2544. *
  2545. * FUNCTION
  2546. *
  2547. * INPUT
  2548. *
  2549. * OUTPUT
  2550. *
  2551. * RETURNS
  2552. *
  2553. * AUTHOR
  2554. *
  2555. * DESCRIPTION
  2556. *
  2557. * CHANGES
  2558. *
  2559. ******************************************************************************/
  2560. static
  2561. OBJECT *Parse_TrueType ()
  2562. {
  2563. OBJECT *Object;
  2564. char *filename, *text_string;
  2565. DBL depth;
  2566. VECTOR offset;
  2567. TRANSFORM Local_Trans;
  2568. Parse_Begin ();
  2569. GET(TTF_TOKEN);
  2570. if ( (Object = (OBJECT *)Parse_Object_Id()) != NULL)
  2571. return ((OBJECT *) Object);
  2572. Object = (OBJECT *)Create_CSG_Union ();
  2573. /*** Object = Create_TTF(); */
  2574. /* Parse the TrueType font file name */
  2575. filename = Parse_String();
  2576. Parse_Comma();
  2577. /* Parse the text string to be rendered */
  2578. text_string = Parse_String();
  2579. Parse_Comma();
  2580. /* Get the extrusion depth */
  2581. depth = Parse_Float(); Parse_Comma ();
  2582. /* Get the offset vector */
  2583. Parse_Vector(offset);
  2584. /* Process all this good info */
  2585. ProcessNewTTF((OBJECT *)Object, filename, text_string, depth, offset);
  2586. /* Free up the filename and text string memory */
  2587. POV_FREE (filename);
  2588. POV_FREE (text_string);
  2589. /**** Compute_TTF_BBox(Object); */
  2590. Compute_CSG_BBox((OBJECT *)Object);
  2591. /* This tiny rotation should fix cracks in text that lies along an axis */
  2592. Make_Vector(offset, 0.001, 0.001, 0.001);
  2593. Compute_Rotation_Transform(&Local_Trans, offset);
  2594. Rotate_Object ((OBJECT *)Object, offset, &Local_Trans);
  2595. /* Get any rotate/translate or texturing stuff */
  2596. Parse_Object_Mods ((OBJECT *)Object);
  2597. return ((OBJECT *) Object);
  2598. }
  2599. /*****************************************************************************
  2600. *
  2601. * FUNCTION
  2602. *
  2603. * INPUT
  2604. *
  2605. * OUTPUT
  2606. *
  2607. * RETURNS
  2608. *
  2609. * AUTHOR
  2610. *
  2611. * DESCRIPTION
  2612. *
  2613. * CHANGES
  2614. *
  2615. ******************************************************************************/
  2616. static
  2617. OBJECT *Parse_CSG (int CSG_Type)
  2618. {
  2619. CSG *Object;
  2620. OBJECT *Local;
  2621. int Object_Count = 0;
  2622. int Light_Source_Union = TRUE;
  2623. Parse_Begin ();
  2624. if ( (Object = (CSG *)Parse_Object_Id()) != NULL)
  2625. return ((OBJECT *) Object);
  2626. if (CSG_Type & CSG_UNION_TYPE)
  2627. Object = Create_CSG_Union ();
  2628. else
  2629. if (CSG_Type & CSG_MERGE_TYPE)
  2630. Object = Create_CSG_Merge ();
  2631. else
  2632. Object = Create_CSG_Intersection ();
  2633. Object->Children = NULL;
  2634. while ((Local = Parse_Object ()) != NULL)
  2635. {
  2636. if ((CSG_Type & CSG_INTERSECTION_TYPE) && (Local->Type & PATCH_OBJECT))
  2637. Warn(0.0, "Patch objects not allowed in intersection.");
  2638. Object_Count++;
  2639. if ((CSG_Type & CSG_DIFFERENCE_TYPE) && (Object_Count > 1))
  2640. Invert_Object (Local);
  2641. Object->Type |= (Local->Type & CHILDREN_FLAGS);
  2642. if (!(Local->Type & LIGHT_SOURCE_OBJECT))
  2643. {
  2644. Light_Source_Union = FALSE;
  2645. }
  2646. Local->Type |= IS_CHILD_OBJECT;
  2647. Link(Local, &Local->Sibling, &Object->Children);
  2648. };
  2649. if (Light_Source_Union)
  2650. {
  2651. Object->Type |= LT_SRC_UNION_OBJECT;
  2652. }
  2653. if ((Object_Count < 2) && (opts.Language_Version >= 1.5))
  2654. Warn(1.5, "Should have at least 2 objects in csg.");
  2655. Compute_CSG_BBox((OBJECT *)Object);
  2656. Parse_Object_Mods ((OBJECT *)Object);
  2657. return ((OBJECT *) Object);
  2658. }
  2659. /*****************************************************************************
  2660. *
  2661. * FUNCTION
  2662. *
  2663. * INPUT
  2664. *
  2665. * OUTPUT
  2666. *
  2667. * RETURNS
  2668. *
  2669. * AUTHOR
  2670. *
  2671. * DESCRIPTION
  2672. *
  2673. * CHANGES
  2674. *
  2675. ******************************************************************************/
  2676. static
  2677. OBJECT *Parse_Light_Source ()
  2678. {
  2679. DBL Len;
  2680. VECTOR Local_Vector;
  2681. MATRIX Local_Matrix;
  2682. TRANSFORM Local_Trans;
  2683. LIGHT_SOURCE *Object;
  2684. Parse_Begin ();
  2685. if ( (Object = (LIGHT_SOURCE *)Parse_Object_Id()) != NULL)
  2686. return ((OBJECT *) Object);
  2687. Object = Create_Light_Source ();
  2688. Parse_Vector(Object->Center);
  2689. Parse_Comma();
  2690. Parse_Colour (Object->Colour);
  2691. EXPECT
  2692. CASE (LOOKS_LIKE_TOKEN)
  2693. if (Object->Children != NULL)
  2694. Error("Only one looks_like allowed per light_source.");
  2695. Parse_Begin ();
  2696. Object->Type &= ~(int)PATCH_OBJECT;
  2697. if ((Object->Children = Parse_Object ()) == NULL)
  2698. Parse_Error_Str ("object");
  2699. Compute_Translation_Transform(&Local_Trans, Object->Center);
  2700. Translate_Object (Object->Children, Object->Center, &Local_Trans);
  2701. Parse_Object_Mods (Object->Children);
  2702. Set_Flag(Object->Children, NO_SHADOW_FLAG);
  2703. Set_Flag(Object, NO_SHADOW_FLAG);
  2704. Object->Type |= (Object->Children->Type & CHILDREN_FLAGS);
  2705. END_CASE
  2706. CASE (FILL_LIGHT_TOKEN)
  2707. Object->Light_Type = FILL_LIGHT_SOURCE;
  2708. END_CASE
  2709. CASE (SPOTLIGHT_TOKEN)
  2710. Object->Light_Type = SPOT_SOURCE;
  2711. END_CASE
  2712. CASE (CYLINDER_TOKEN)
  2713. Object->Light_Type = CYLINDER_SOURCE;
  2714. END_CASE
  2715. CASE (POINT_AT_TOKEN)
  2716. if ((Object->Light_Type == SPOT_SOURCE) || (Object->Light_Type == CYLINDER_SOURCE))
  2717. Parse_Vector(Object->Points_At);
  2718. else
  2719. Not_With ("point_at","standard light source");
  2720. END_CASE
  2721. CASE (TIGHTNESS_TOKEN)
  2722. if ((Object->Light_Type == SPOT_SOURCE) || (Object->Light_Type == CYLINDER_SOURCE))
  2723. Object->Coeff = Parse_Float();
  2724. else
  2725. Not_With ("tightness","standard light source");
  2726. END_CASE
  2727. CASE (RADIUS_TOKEN)
  2728. if ((Object->Light_Type == SPOT_SOURCE) || (Object->Light_Type == CYLINDER_SOURCE))
  2729. Object->Radius = Parse_Float();
  2730. else
  2731. Not_With ("radius","standard light source");
  2732. END_CASE
  2733. CASE (FALLOFF_TOKEN)
  2734. if ((Object->Light_Type == SPOT_SOURCE) || (Object->Light_Type == CYLINDER_SOURCE))
  2735. Object->Falloff = Parse_Float();
  2736. else
  2737. Not_With ("falloff","standard light source");
  2738. END_CASE
  2739. CASE (FADE_DISTANCE_TOKEN)
  2740. Object->Fade_Distance = Parse_Float();
  2741. END_CASE
  2742. CASE (FADE_POWER_TOKEN)
  2743. Object->Fade_Power = Parse_Float();
  2744. END_CASE
  2745. CASE (AREA_LIGHT_TOKEN)
  2746. Object->Area_Light = TRUE;
  2747. Parse_Vector (Object->Axis1); Parse_Comma ();
  2748. Parse_Vector (Object->Axis2); Parse_Comma ();
  2749. Object->Area_Size1 = (int)Parse_Float(); Parse_Comma ();
  2750. Object->Area_Size2 = (int)Parse_Float();
  2751. Object->Light_Grid = Create_Light_Grid (Object->Area_Size1, Object->Area_Size2);
  2752. END_CASE
  2753. CASE (JITTER_TOKEN)
  2754. Object->Jitter = TRUE;
  2755. END_CASE
  2756. CASE (TRACK_TOKEN)
  2757. Object->Track = TRUE;
  2758. END_CASE
  2759. CASE (ADAPTIVE_TOKEN)
  2760. Object->Adaptive_Level = (int)Parse_Float();
  2761. END_CASE
  2762. CASE (MEDIA_ATTENUATION_TOKEN)
  2763. Object->Media_Attenuation = Allow_Float(1.0) > 0.0;
  2764. END_CASE
  2765. CASE (MEDIA_INTERACTION_TOKEN)
  2766. Object->Media_Interaction = Allow_Float(1.0) > 0.0;
  2767. END_CASE
  2768. CASE (TRANSLATE_TOKEN)
  2769. Parse_Vector (Local_Vector);
  2770. Compute_Translation_Transform(&Local_Trans, Local_Vector);
  2771. Translate_Object ((OBJECT *)Object, Local_Vector, &Local_Trans);
  2772. END_CASE
  2773. CASE (ROTATE_TOKEN)
  2774. Parse_Vector (Local_Vector);
  2775. Compute_Rotation_Transform(&Local_Trans, Local_Vector);
  2776. Rotate_Object ((OBJECT *)Object, Local_Vector, &Local_Trans);
  2777. END_CASE
  2778. CASE (SCALE_TOKEN)
  2779. Parse_Scale_Vector (Local_Vector);
  2780. Compute_Scaling_Transform(&Local_Trans, Local_Vector);
  2781. Scale_Object ((OBJECT *)Object, Local_Vector, &Local_Trans);
  2782. END_CASE
  2783. CASE (TRANSFORM_TOKEN)
  2784. GET(TRANSFORM_ID_TOKEN)
  2785. Transform_Object ((OBJECT *)Object, (TRANSFORM *)Token.Data);
  2786. END_CASE
  2787. CASE (MATRIX_TOKEN)
  2788. Parse_Matrix (Local_Matrix);
  2789. Compute_Matrix_Transform(&Local_Trans, Local_Matrix);
  2790. Transform_Object ((OBJECT *)Object, &Local_Trans);
  2791. END_CASE
  2792. OTHERWISE
  2793. UNGET
  2794. EXIT
  2795. END_CASE
  2796. END_EXPECT
  2797. Parse_End ();
  2798. if (Object->Light_Type == SPOT_SOURCE)
  2799. {
  2800. Object->Radius = cos(Object->Radius * M_PI_180);
  2801. Object->Falloff = cos(Object->Falloff * M_PI_180);
  2802. }
  2803. VSub(Object->Direction, Object->Points_At, Object->Center);
  2804. VLength(Len, Object->Direction);
  2805. if (Len > EPSILON)
  2806. {
  2807. VInverseScaleEq(Object->Direction, Len);
  2808. }
  2809. return ((OBJECT *)Object);
  2810. }
  2811. /*****************************************************************************
  2812. *
  2813. * FUNCTION
  2814. *
  2815. * INPUT
  2816. *
  2817. * OUTPUT
  2818. *
  2819. * RETURNS
  2820. *
  2821. * AUTHOR
  2822. *
  2823. * DESCRIPTION
  2824. *
  2825. * CHANGES
  2826. *
  2827. ******************************************************************************/
  2828. OBJECT *Parse_Object ()
  2829. {
  2830. OBJECT *Object = NULL;
  2831. EXPECT
  2832. CASE (JULIA_FRACTAL_TOKEN)
  2833. Object = Parse_Julia_Fractal ();
  2834. EXIT
  2835. END_CASE
  2836. CASE (SPHERE_TOKEN)
  2837. Object = Parse_Sphere ();
  2838. EXIT
  2839. END_CASE
  2840. CASE (PLANE_TOKEN)
  2841. Object = Parse_Plane ();
  2842. EXIT
  2843. END_CASE
  2844. CASE (CONE_TOKEN)
  2845. Object = Parse_Cone ();
  2846. EXIT
  2847. END_CASE
  2848. CASE (CYLINDER_TOKEN)
  2849. Object = Parse_Cylinder ();
  2850. EXIT
  2851. END_CASE
  2852. CASE (DISC_TOKEN)
  2853. Object = Parse_Disc ();
  2854. EXIT
  2855. END_CASE
  2856. CASE (QUADRIC_TOKEN)
  2857. Object = Parse_Quadric ();
  2858. EXIT
  2859. END_CASE
  2860. CASE (CUBIC_TOKEN)
  2861. Object = Parse_Poly (3);
  2862. EXIT
  2863. END_CASE
  2864. CASE (QUARTIC_TOKEN)
  2865. Object = Parse_Poly (4);
  2866. EXIT
  2867. END_CASE
  2868. CASE (POLY_TOKEN)
  2869. Object = Parse_Poly (0);
  2870. EXIT
  2871. END_CASE
  2872. CASE (TORUS_TOKEN)
  2873. Object = Parse_Torus ();
  2874. EXIT
  2875. END_CASE
  2876. /* Parse lathe primitive. [DB 8/94] */
  2877. CASE (LATHE_TOKEN)
  2878. Object = Parse_Lathe();
  2879. EXIT
  2880. END_CASE
  2881. /* Parse polygon primitive. [DB 8/94] */
  2882. CASE (POLYGON_TOKEN)
  2883. Object = Parse_Polygon();
  2884. EXIT
  2885. END_CASE
  2886. /* Parse prism primitive. [DB 8/94] */
  2887. CASE (PRISM_TOKEN)
  2888. Object = Parse_Prism();
  2889. EXIT
  2890. END_CASE
  2891. /* Parse surface of revolution primitive. [DB 8/94] */
  2892. CASE (SOR_TOKEN)
  2893. Object = Parse_Sor();
  2894. EXIT
  2895. END_CASE
  2896. /* Parse superellipsoid primitive. [DB 11/94] */
  2897. CASE (SUPERELLIPSOID_TOKEN)
  2898. Object = Parse_Superellipsoid();
  2899. EXIT
  2900. END_CASE
  2901. /* Parse triangle mesh primitive. [DB 2/95] */
  2902. CASE (MESH_TOKEN)
  2903. Object = Parse_Mesh();
  2904. EXIT
  2905. END_CASE
  2906. CASE (TEXT_TOKEN)
  2907. Object = Parse_TrueType ();
  2908. EXIT
  2909. END_CASE
  2910. CASE (OBJECT_ID_TOKEN)
  2911. Object = Copy_Object((OBJECT *) Token.Data);
  2912. EXIT
  2913. END_CASE
  2914. CASE (UNION_TOKEN)
  2915. Object = Parse_CSG (CSG_UNION_TYPE);
  2916. EXIT
  2917. END_CASE
  2918. CASE (COMPOSITE_TOKEN)
  2919. Warn(1.5, "Use union instead of composite.");
  2920. Object = Parse_CSG (CSG_UNION_TYPE);
  2921. EXIT
  2922. END_CASE
  2923. CASE (MERGE_TOKEN)
  2924. Object = Parse_CSG (CSG_MERGE_TYPE);
  2925. EXIT
  2926. END_CASE
  2927. CASE (INTERSECTION_TOKEN)
  2928. Object = Parse_CSG (CSG_INTERSECTION_TYPE);
  2929. EXIT
  2930. END_CASE
  2931. CASE (DIFFERENCE_TOKEN)
  2932. Object = Parse_CSG (CSG_DIFFERENCE_TYPE+CSG_INTERSECTION_TYPE);
  2933. EXIT
  2934. END_CASE
  2935. CASE (BICUBIC_PATCH_TOKEN)
  2936. Object = Parse_Bicubic_Patch ();
  2937. EXIT
  2938. END_CASE
  2939. CASE (TRIANGLE_TOKEN)
  2940. Object = Parse_Triangle ();
  2941. EXIT
  2942. END_CASE
  2943. CASE (SMOOTH_TRIANGLE_TOKEN)
  2944. Object = Parse_Smooth_Triangle ();
  2945. EXIT
  2946. END_CASE
  2947. CASE (HEIGHT_FIELD_TOKEN)
  2948. Object = Parse_HField ();
  2949. EXIT
  2950. END_CASE
  2951. CASE (BOX_TOKEN)
  2952. Object = Parse_Box ();
  2953. EXIT
  2954. END_CASE
  2955. CASE (BLOB_TOKEN)
  2956. Object = Parse_Blob ();
  2957. EXIT
  2958. END_CASE
  2959. CASE (LIGHT_SOURCE_TOKEN)
  2960. Object = Parse_Light_Source ();
  2961. EXIT
  2962. END_CASE
  2963. CASE (OBJECT_TOKEN)
  2964. Parse_Begin ();
  2965. Object = Parse_Object ();
  2966. if (!Object)
  2967. Parse_Error_Str ("object");
  2968. Parse_Object_Mods ((OBJECT *)Object);
  2969. EXIT
  2970. END_CASE
  2971. OTHERWISE
  2972. UNGET
  2973. EXIT
  2974. END_CASE
  2975. END_EXPECT
  2976. return ((OBJECT *) Object);
  2977. }
  2978. /*****************************************************************************
  2979. *
  2980. * FUNCTION
  2981. *
  2982. * INPUT
  2983. *
  2984. * OUTPUT
  2985. *
  2986. * RETURNS
  2987. *
  2988. * AUTHOR
  2989. *
  2990. * DESCRIPTION
  2991. *
  2992. * CHANGES
  2993. *
  2994. ******************************************************************************/
  2995. void Parse_Default ()
  2996. {
  2997. TEXTURE *Local_Texture;
  2998. PIGMENT *Local_Pigment;
  2999. TNORMAL *Local_Tnormal;
  3000. FINISH *Local_Finish;
  3001. Not_In_Default = FALSE;
  3002. Parse_Begin();
  3003. EXPECT
  3004. CASE (TEXTURE_TOKEN)
  3005. Local_Texture = Default_Texture;
  3006. Parse_Begin ();
  3007. Default_Texture = Parse_Texture();
  3008. Parse_End ();
  3009. if (Default_Texture->Type != PLAIN_PATTERN)
  3010. Error("Default texture cannot be material map or tiles.");
  3011. if (Default_Texture->Next != NULL)
  3012. Error("Default texture cannot be layered.");
  3013. Destroy_Textures(Local_Texture);
  3014. END_CASE
  3015. CASE (PIGMENT_TOKEN)
  3016. Local_Pigment = Copy_Pigment((Default_Texture->Pigment));
  3017. Parse_Begin ();
  3018. Parse_Pigment (&Local_Pigment);
  3019. Parse_End ();
  3020. Destroy_Pigment(Default_Texture->Pigment);
  3021. Default_Texture->Pigment = Local_Pigment;
  3022. END_CASE
  3023. CASE (TNORMAL_TOKEN)
  3024. Local_Tnormal = Copy_Tnormal((Default_Texture->Tnormal));
  3025. Parse_Begin ();
  3026. Parse_Tnormal (&Local_Tnormal);
  3027. Parse_End ();
  3028. Destroy_Tnormal(Default_Texture->Tnormal);
  3029. Default_Texture->Tnormal = Local_Tnormal;
  3030. END_CASE
  3031. CASE (FINISH_TOKEN)
  3032. Local_Finish = Copy_Finish((Default_Texture->Finish));
  3033. Parse_Finish (&Local_Finish);
  3034. Destroy_Finish(Default_Texture->Finish);
  3035. Default_Texture->Finish = Local_Finish;
  3036. END_CASE
  3037. CASE (CAMERA_TOKEN)
  3038. Parse_Camera (&Default_Camera);
  3039. END_CASE
  3040. OTHERWISE
  3041. UNGET
  3042. EXIT
  3043. END_CASE
  3044. END_EXPECT
  3045. Parse_End();
  3046. Not_In_Default = TRUE;
  3047. }
  3048. /*****************************************************************************
  3049. *
  3050. * FUNCTION
  3051. *
  3052. * INPUT
  3053. *
  3054. * OUTPUT
  3055. *
  3056. * RETURNS
  3057. *
  3058. * AUTHOR
  3059. *
  3060. * DESCRIPTION
  3061. *
  3062. * CHANGES
  3063. *
  3064. ******************************************************************************/
  3065. static void Parse_Frame ()
  3066. {
  3067. OBJECT *Object;
  3068. RAINBOW *Local_Rainbow;
  3069. FOG *Local_Fog;
  3070. SKYSPHERE *Local_Skysphere;
  3071. int i;
  3072. EXPECT
  3073. CASE (RAINBOW_TOKEN)
  3074. Local_Rainbow = Parse_Rainbow();
  3075. Local_Rainbow->Next = Frame.Rainbow;
  3076. Frame.Rainbow = Local_Rainbow;
  3077. END_CASE
  3078. CASE (SKYSPHERE_TOKEN)
  3079. Local_Skysphere = Parse_Skysphere();
  3080. if (Frame.Skysphere != NULL)
  3081. {
  3082. Warn(0.0, "Only one sky-sphere allowed (last one will be used).");
  3083. Destroy_Skysphere(Frame.Skysphere);
  3084. }
  3085. Frame.Skysphere = Local_Skysphere;
  3086. for (i=0; i<Local_Skysphere->Count; i++)
  3087. {
  3088. Post_Pigment(Local_Skysphere->Pigments[i]);
  3089. }
  3090. END_CASE
  3091. CASE (FOG_TOKEN)
  3092. Local_Fog = Parse_Fog();
  3093. Local_Fog->Next = Frame.Fog;
  3094. Frame.Fog = Local_Fog;
  3095. END_CASE
  3096. CASE (MEDIA_TOKEN)
  3097. Parse_Media(&Frame.Atmosphere);
  3098. END_CASE
  3099. CASE (BACKGROUND_TOKEN)
  3100. Parse_Begin();
  3101. Parse_Colour (Frame.Background_Colour);
  3102. Parse_End();
  3103. END_CASE
  3104. CASE (CAMERA_TOKEN)
  3105. Parse_Camera (&Frame.Camera);
  3106. END_CASE
  3107. CASE (DECLARE_TOKEN)
  3108. UNGET
  3109. Warn(2.99,"Should have '#' before 'declare'.");
  3110. Parse_Directive (FALSE);
  3111. END_CASE
  3112. CASE (INCLUDE_TOKEN)
  3113. UNGET
  3114. Warn(2.99,"Should have '#' before 'include'.");
  3115. Parse_Directive (FALSE);
  3116. END_CASE
  3117. CASE (FLOAT_FUNCT_TOKEN)
  3118. switch(Token.Function_Id)
  3119. {
  3120. case VERSION_TOKEN:
  3121. UNGET
  3122. Parse_Directive (FALSE);
  3123. UNGET
  3124. break;
  3125. default:
  3126. UNGET
  3127. Parse_Error_Str ("object or directive");
  3128. break;
  3129. }
  3130. END_CASE
  3131. CASE (MAX_TRACE_LEVEL_TOKEN)
  3132. Global_Setting_Warn();
  3133. Max_Trace_Level = (int) Parse_Float ();
  3134. END_CASE
  3135. CASE (MAX_INTERSECTIONS)
  3136. Global_Setting_Warn();
  3137. Max_Intersections = (int)Parse_Float ();
  3138. END_CASE
  3139. CASE (DEFAULT_TOKEN)
  3140. Parse_Default();
  3141. END_CASE
  3142. CASE (END_OF_FILE_TOKEN)
  3143. EXIT
  3144. END_CASE
  3145. CASE (GLOBAL_SETTINGS_TOKEN)
  3146. Parse_Global_Settings();
  3147. END_CASE
  3148. OTHERWISE
  3149. UNGET
  3150. Object = Parse_Object();
  3151. if (Object == NULL)
  3152. Parse_Error_Str ("object or directive");
  3153. Post_Process (Object, NULL);
  3154. Link_To_Frame (Object);
  3155. END_CASE
  3156. END_EXPECT
  3157. }
  3158. /*****************************************************************************
  3159. *
  3160. * FUNCTION
  3161. *
  3162. * INPUT
  3163. *
  3164. * OUTPUT
  3165. *
  3166. * RETURNS
  3167. *
  3168. * AUTHOR
  3169. *
  3170. * DESCRIPTION
  3171. *
  3172. * CHANGES
  3173. *
  3174. * Mar 1996 : Add line number info to warning message [AED]
  3175. *
  3176. ******************************************************************************/
  3177. static void Global_Setting_Warn()
  3178. {
  3179. if (opts.Language_Version >= 3.0)
  3180. {
  3181. Warning(0.0, "%s:%d: warning: '%s' should be in 'global_settings{...}' statement.\n",
  3182. Token.Filename, Token.Token_Line_No+1, Token.Token_String);
  3183. }
  3184. }
  3185. /*****************************************************************************
  3186. *
  3187. * FUNCTION
  3188. *
  3189. * INPUT
  3190. *
  3191. * OUTPUT
  3192. *
  3193. * RETURNS
  3194. *
  3195. * AUTHOR
  3196. *
  3197. * DESCRIPTION
  3198. *
  3199. * CHANGES
  3200. *
  3201. ******************************************************************************/
  3202. static void Parse_Global_Settings()
  3203. {
  3204. Parse_Begin();
  3205. EXPECT
  3206. CASE (IRID_WAVELENGTH_TOKEN)
  3207. Parse_Colour (Frame.Irid_Wavelengths);
  3208. END_CASE
  3209. CASE (ASSUMED_GAMMA_TOKEN)
  3210. {
  3211. DBL AssumedGamma;
  3212. AssumedGamma = Parse_Float ();
  3213. if (fabs(AssumedGamma - opts.DisplayGamma) < 0.1)
  3214. {
  3215. opts.GammaFactor = 1.0;
  3216. opts.Options &= ~GAMMA_CORRECT; /* turn off gamma correction */
  3217. }
  3218. else
  3219. {
  3220. opts.GammaFactor = AssumedGamma/opts.DisplayGamma;
  3221. opts.Options |= GAMMA_CORRECT; /* turn on gamma correction */
  3222. }
  3223. }
  3224. END_CASE
  3225. CASE (MAX_TRACE_LEVEL_TOKEN)
  3226. Max_Trace_Level = (int) Parse_Float ();
  3227. END_CASE
  3228. CASE (ADC_BAILOUT_TOKEN)
  3229. ADC_Bailout = Parse_Float ();
  3230. END_CASE
  3231. CASE (NUMBER_OF_WAVES_TOKEN)
  3232. Number_Of_Waves = (int) Parse_Float ();
  3233. if(Number_Of_Waves <=0)
  3234. {
  3235. Warn(0.0, "Illegal Value: Number_Of_Waves = 0. Changed to 1.");
  3236. Number_Of_Waves = 1;
  3237. }
  3238. END_CASE
  3239. CASE (MAX_INTERSECTIONS)
  3240. Max_Intersections = (int)Parse_Float ();
  3241. END_CASE
  3242. CASE (AMBIENT_LIGHT_TOKEN)
  3243. Parse_Colour (Frame.Ambient_Light);
  3244. END_CASE
  3245. CASE (RADIOSITY_TOKEN)
  3246. Experimental_Flag |= EF_RADIOS;
  3247. Parse_Begin();
  3248. EXPECT
  3249. CASE (BRIGHTNESS_TOKEN)
  3250. if ((opts.Radiosity_Brightness = Parse_Float()) <= 0.0)
  3251. {
  3252. Error("Radiosity brightness must be a positive number.");
  3253. }
  3254. END_CASE
  3255. CASE (COUNT_TOKEN)
  3256. if (( opts.Radiosity_Count = (int)Parse_Float()) <= 0)
  3257. {
  3258. Error("Radiosity count must be a positive number.");
  3259. }
  3260. if ( opts.Radiosity_Count > 1600)
  3261. {
  3262. Error("Radiosity count can not be more than 1600.");
  3263. opts.Radiosity_Count = 1600;
  3264. }
  3265. END_CASE
  3266. CASE (DISTANCE_MAXIMUM_TOKEN)
  3267. if (( opts.Radiosity_Dist_Max = Parse_Float()) < 0.0)
  3268. {
  3269. Error("Radiosity distance maximum must be a positive number.");
  3270. }
  3271. END_CASE
  3272. CASE (ERROR_BOUND_TOKEN)
  3273. if (( opts.Radiosity_Error_Bound = Parse_Float()) <= 0.0)
  3274. {
  3275. Error("Radiosity error bound must be a positive number.");
  3276. }
  3277. END_CASE
  3278. CASE (GRAY_THRESHOLD_TOKEN)
  3279. opts.Radiosity_Gray = Parse_Float();
  3280. if (( opts.Radiosity_Gray < 0.0) || ( opts.Radiosity_Gray > 1.0))
  3281. {
  3282. Error("Radiosity gray threshold must be from 0.0 to 1.0.");
  3283. }
  3284. END_CASE
  3285. CASE (LOW_ERROR_FACTOR_TOKEN)
  3286. if (( opts.Radiosity_Low_Error_Factor = Parse_Float()) <= 0.0)
  3287. {
  3288. Error("Radiosity low error factor must be a positive number.");
  3289. }
  3290. END_CASE
  3291. CASE (MINIMUM_REUSE_TOKEN)
  3292. if (( opts.Radiosity_Min_Reuse = Parse_Float()) < 0.0)
  3293. {
  3294. Error("Radiosity min reuse can not be a negative number.");
  3295. }
  3296. END_CASE
  3297. CASE (NEAREST_COUNT_TOKEN)
  3298. opts.Radiosity_Nearest_Count = (int)Parse_Float();
  3299. if (( opts.Radiosity_Nearest_Count < 1) ||
  3300. ( opts.Radiosity_Nearest_Count > MAX_NEAREST_COUNT))
  3301. {
  3302. Error("Radiosity nearest count must be a value from 1 to %ld.", (long)MAX_NEAREST_COUNT);
  3303. }
  3304. END_CASE
  3305. CASE (RECURSION_LIMIT_TOKEN)
  3306. if (( opts.Radiosity_Recursion_Limit = (int)Parse_Float()) <= 0)
  3307. {
  3308. Error("Radiosity recursion limit must be a positive number.");
  3309. }
  3310. END_CASE
  3311. OTHERWISE
  3312. UNGET
  3313. EXIT
  3314. END_CASE
  3315. END_EXPECT
  3316. Parse_End();
  3317. END_CASE
  3318. CASE (HF_GRAY_16_TOKEN)
  3319. if (Allow_Float(1.0)>EPSILON)
  3320. {
  3321. opts.Options |= HF_GRAY_16;
  3322. opts.PaletteOption = GREY; /* Force gray scale preview */
  3323. Output_File_Handle->file_type = HF_FTYPE;
  3324. }
  3325. END_CASE
  3326. OTHERWISE
  3327. UNGET
  3328. EXIT
  3329. END_CASE
  3330. END_EXPECT
  3331. Parse_End();
  3332. }
  3333. /*****************************************************************************
  3334. *
  3335. * FUNCTION
  3336. *
  3337. * INPUT
  3338. *
  3339. * OUTPUT
  3340. *
  3341. * RETURNS
  3342. *
  3343. * AUTHOR
  3344. *
  3345. * DESCRIPTION
  3346. *
  3347. * CHANGES
  3348. *
  3349. ******************************************************************************/
  3350. void Destroy_Frame()
  3351. {
  3352. FOG *Fog, *Next_Fog;
  3353. RAINBOW *Rainbow, *Next_Rainbow;
  3354. Destroy_Camera (Frame.Camera); Frame.Camera=NULL;
  3355. /* Destroy fogs. [DB 12/94] */
  3356. for (Fog = Frame.Fog; Fog != NULL;)
  3357. {
  3358. Next_Fog = Fog->Next;
  3359. Destroy_Fog(Fog);
  3360. Fog = Next_Fog;
  3361. }
  3362. Frame.Fog = NULL;
  3363. /* Destroy rainbows. [DB 12/94] */
  3364. for (Rainbow = Frame.Rainbow; Rainbow != NULL;)
  3365. {
  3366. Next_Rainbow = Rainbow->Next;
  3367. Destroy_Rainbow(Rainbow);
  3368. Rainbow = Next_Rainbow;
  3369. }
  3370. Frame.Rainbow = NULL;
  3371. /* Destroy skysphere. [DB 12/94] */
  3372. Destroy_Skysphere(Frame.Skysphere);
  3373. Frame.Skysphere = NULL;
  3374. /* Destroy atmosphere. [DB 1/95] */
  3375. Destroy_Media(Frame.Atmosphere);
  3376. Frame.Atmosphere = NULL;
  3377. if (Frame.Objects != NULL) {
  3378. Destroy_Object (Frame.Objects);
  3379. Frame.Objects = NULL;
  3380. Frame.Light_Sources = NULL;
  3381. }
  3382. }
  3383. /*****************************************************************************
  3384. *
  3385. * FUNCTION
  3386. *
  3387. * INPUT
  3388. *
  3389. * OUTPUT
  3390. *
  3391. * RETURNS
  3392. *
  3393. * AUTHOR
  3394. *
  3395. * DESCRIPTION
  3396. *
  3397. * CHANGES
  3398. *
  3399. ******************************************************************************/
  3400. static void Parse_Camera (CAMERA **Camera_Ptr)
  3401. {
  3402. int i;
  3403. DBL Direction_Length = 1.0, Up_Length, Right_Length, Handedness;
  3404. DBL k1, k2, k3;
  3405. VECTOR Local_Vector;
  3406. MATRIX Local_Matrix;
  3407. TRANSFORM Local_Trans;
  3408. CAMERA *New;
  3409. Parse_Begin ();
  3410. EXPECT
  3411. CASE (CAMERA_ID_TOKEN)
  3412. Destroy_Camera(*Camera_Ptr);
  3413. *Camera_Ptr = Copy_Camera ((CAMERA *) Token.Data);
  3414. EXIT
  3415. END_CASE
  3416. OTHERWISE
  3417. UNGET
  3418. EXIT
  3419. END_CASE
  3420. END_EXPECT
  3421. New = *Camera_Ptr;
  3422. EXPECT
  3423. /* Get camera type. [DB 7/94] */
  3424. CASE (PERSPECTIVE_TOKEN)
  3425. New->Type = PERSPECTIVE_CAMERA;
  3426. END_CASE
  3427. CASE (ORTHOGRAPHIC_TOKEN)
  3428. New->Type = ORTHOGRAPHIC_CAMERA;
  3429. /*
  3430. * Resize right and up vector to get the same image
  3431. * area as we get with the perspective camera.
  3432. */
  3433. VSub(Local_Vector, New->Look_At, New->Location);
  3434. VLength(k1, Local_Vector);
  3435. VLength(k2, New->Direction);
  3436. if ((k1 > EPSILON) && (k2 > EPSILON))
  3437. {
  3438. VScaleEq(New->Right, k1 / k2);
  3439. VScaleEq(New->Up, k1 / k2);
  3440. }
  3441. END_CASE
  3442. CASE (FISHEYE_TOKEN)
  3443. New->Type = FISHEYE_CAMERA;
  3444. END_CASE
  3445. CASE (ULTRA_WIDE_ANGLE_TOKEN)
  3446. New->Type = ULTRA_WIDE_ANGLE_CAMERA;
  3447. END_CASE
  3448. CASE (OMNIMAX_TOKEN)
  3449. New->Type = OMNIMAX_CAMERA;
  3450. END_CASE
  3451. CASE (PANORAMIC_TOKEN)
  3452. New->Type = PANORAMIC_CAMERA;
  3453. END_CASE
  3454. CASE (CYLINDER_TOKEN)
  3455. i = (int)Parse_Float();
  3456. switch (i)
  3457. {
  3458. case 1: New->Type = CYL_1_CAMERA; break;
  3459. case 2: New->Type = CYL_2_CAMERA; break;
  3460. case 3: New->Type = CYL_3_CAMERA; break;
  3461. case 4: New->Type = CYL_4_CAMERA; break;
  3462. }
  3463. END_CASE
  3464. /* Read viewing angle. Scale direction vector if necessary. [DB 7/94] */
  3465. CASE (ANGLE_TOKEN)
  3466. New->Angle = Parse_Float();
  3467. if (New->Angle < 0.0)
  3468. {
  3469. Error("Negative viewing angle.");
  3470. }
  3471. if (New->Type == PERSPECTIVE_CAMERA)
  3472. {
  3473. if (New->Angle >= 180.0)
  3474. {
  3475. Error("Viewing angle has to be smaller than 180 degrees.");
  3476. }
  3477. VNormalize(New->Direction, New->Direction);
  3478. VLength (Right_Length, New->Right);
  3479. Direction_Length = Right_Length / tan(New->Angle * M_PI_360)/2.0;
  3480. VScaleEq(New->Direction, Direction_Length);
  3481. }
  3482. END_CASE
  3483. /* Read primary ray pertubation. [DB 7/94] */
  3484. CASE (TNORMAL_TOKEN)
  3485. Parse_Begin ();
  3486. Parse_Tnormal(&(New->Tnormal));
  3487. Parse_End ();
  3488. END_CASE
  3489. CASE (LOCATION_TOKEN)
  3490. Parse_Vector(New->Location);
  3491. END_CASE
  3492. CASE (DIRECTION_TOKEN)
  3493. Parse_Vector(New->Direction);
  3494. END_CASE
  3495. CASE (UP_TOKEN)
  3496. Parse_Vector(New->Up);
  3497. END_CASE
  3498. CASE (RIGHT_TOKEN)
  3499. Parse_Vector(New->Right);
  3500. END_CASE
  3501. CASE (SKY_TOKEN)
  3502. Parse_Vector(New->Sky);
  3503. END_CASE
  3504. CASE (LOOK_AT_TOKEN)
  3505. VLength (Direction_Length, New->Direction);
  3506. VLength (Up_Length, New->Up);
  3507. VLength (Right_Length, New->Right);
  3508. VCross (Local_Vector, New->Up, New->Direction);
  3509. VDot (Handedness, Local_Vector, New->Right);
  3510. Parse_Vector (New->Direction);
  3511. Assign_Vector(New->Look_At, New->Direction);
  3512. VSub (New->Direction, New->Direction, New->Location);
  3513. /* Check for zero length direction vector. */
  3514. if (VSumSqr(New->Direction) < EPSILON)
  3515. {
  3516. Error("Camera location and look_at point must be different.\n");
  3517. }
  3518. VNormalize (New->Direction, New->Direction);
  3519. /* Save Right vector */
  3520. Assign_Vector (Local_Vector, New->Right);
  3521. VCross (New->Right, New->Sky, New->Direction);
  3522. /* Avoid DOMAIN error (from Terry Kanakis) */
  3523. if((fabs(New->Right[X]) < EPSILON) &&
  3524. (fabs(New->Right[Y]) < EPSILON) &&
  3525. (fabs(New->Right[Z]) < EPSILON))
  3526. {
  3527. /* Restore Right vector*/
  3528. Assign_Vector (New->Right, Local_Vector);
  3529. }
  3530. VNormalize (New->Right, New->Right);
  3531. VCross (New->Up, New->Direction, New->Right);
  3532. VScale (New->Direction, New->Direction, Direction_Length);
  3533. if (Handedness > 0.0)
  3534. VScaleEq (New->Right, Right_Length)
  3535. else
  3536. VScaleEq (New->Right, -Right_Length);
  3537. VScaleEq(New->Up, Up_Length);
  3538. END_CASE
  3539. CASE (TRANSLATE_TOKEN)
  3540. Parse_Vector (Local_Vector);
  3541. Translate_Camera (New, Local_Vector);
  3542. END_CASE
  3543. CASE (ROTATE_TOKEN)
  3544. Parse_Vector (Local_Vector);
  3545. Rotate_Camera (New, Local_Vector);
  3546. END_CASE
  3547. CASE (SCALE_TOKEN)
  3548. Parse_Scale_Vector (Local_Vector);
  3549. Scale_Camera (New, Local_Vector);
  3550. END_CASE
  3551. CASE (TRANSFORM_TOKEN)
  3552. GET(TRANSFORM_ID_TOKEN)
  3553. Transform_Camera (New, (TRANSFORM *)Token.Data);
  3554. END_CASE
  3555. CASE (MATRIX_TOKEN)
  3556. Parse_Matrix (Local_Matrix);
  3557. Compute_Matrix_Transform(&Local_Trans, Local_Matrix);
  3558. Transform_Camera (New, &Local_Trans);
  3559. END_CASE
  3560. /* Parse focal blur stuff. */
  3561. CASE (BLUR_SAMPLES_TOKEN)
  3562. New->Blur_Samples = Parse_Float();
  3563. if (New->Blur_Samples <= 0)
  3564. {
  3565. Error("Illegal number of focal blur samples.\n");
  3566. }
  3567. END_CASE
  3568. CASE (CONFIDENCE_TOKEN)
  3569. k1 = Parse_Float();
  3570. if ((k1 > 0.0) && (k1 < 1.0))
  3571. {
  3572. New->Confidence = k1;
  3573. }
  3574. else
  3575. {
  3576. Warn(0.0, "Illegal confidence value. Default is used.");
  3577. }
  3578. END_CASE
  3579. CASE (VARIANCE_TOKEN)
  3580. k1 = Parse_Float();
  3581. if ((k1 >= 0.0) && (k1 <= 1.0))
  3582. {
  3583. New->Variance = k1;
  3584. }
  3585. else
  3586. {
  3587. Warn(0.0, "Illegal variance value. Default is used.");
  3588. }
  3589. END_CASE
  3590. CASE (APERTURE_TOKEN)
  3591. New->Aperture = Parse_Float();
  3592. END_CASE
  3593. CASE (FOCAL_POINT_TOKEN)
  3594. Parse_Vector(Local_Vector);
  3595. VSubEq(Local_Vector, New->Location);
  3596. VLength (New->Focal_Distance, Local_Vector);
  3597. END_CASE
  3598. OTHERWISE
  3599. UNGET
  3600. EXIT
  3601. END_CASE
  3602. END_EXPECT
  3603. Parse_End ();
  3604. /* Make sure the focal distance hasn't been explicitly given */
  3605. if ( New->Focal_Distance < 0.0 )
  3606. New->Focal_Distance = Direction_Length;
  3607. if ( New->Focal_Distance == 0.0 )
  3608. New->Focal_Distance = 1.0;
  3609. /* Print a warning message if vectors are not perpendicular. [DB 10/94] */
  3610. VDot(k1, New->Right, New->Up);
  3611. VDot(k2, New->Right, New->Direction);
  3612. VDot(k3, New->Up, New->Direction);
  3613. if ((fabs(k1) > EPSILON) || (fabs(k2) > EPSILON) || (fabs(k3) > EPSILON))
  3614. {
  3615. Warn(0.0, "Camera vectors are not perpendicular. "
  3616. "Making look_at the last statement may help.");
  3617. }
  3618. }
  3619. /*****************************************************************************
  3620. *
  3621. * FUNCTION
  3622. *
  3623. * INPUT
  3624. *
  3625. * OUTPUT
  3626. *
  3627. * RETURNS
  3628. *
  3629. * AUTHOR
  3630. *
  3631. * DESCRIPTION
  3632. *
  3633. * CHANGES
  3634. *
  3635. ******************************************************************************/
  3636. void Parse_Matrix(MATRIX Matrix)
  3637. {
  3638. int i, j;
  3639. EXPECT
  3640. CASE (LEFT_ANGLE_TOKEN)
  3641. Matrix[0][0] = Parse_Float();
  3642. for (i = 0; i < 4; i++)
  3643. {
  3644. for (j = !i ? 1 : 0; j < 3; j++)
  3645. {
  3646. Parse_Comma();
  3647. Matrix[i][j] = Parse_Float();
  3648. }
  3649. Matrix[i][3] = (i != 3 ? 0.0 : 1.0);
  3650. }
  3651. GET (RIGHT_ANGLE_TOKEN);
  3652. /* Check to see that we aren't scaling any dimension by zero */
  3653. for (i = 0; i < 3; i++)
  3654. {
  3655. if (fabs(Matrix[0][i]) < EPSILON && fabs(Matrix[1][i]) < EPSILON &&
  3656. fabs(Matrix[2][i]) < EPSILON)
  3657. {
  3658. Warn(0.0,"Illegal matrix column: Scale by 0.0. Changed to 1.0.");
  3659. Matrix[i][i] = 1.0;
  3660. }
  3661. }
  3662. EXIT
  3663. END_CASE
  3664. OTHERWISE
  3665. Parse_Error (LEFT_ANGLE_TOKEN);
  3666. END_CASE
  3667. END_EXPECT
  3668. }
  3669. /*****************************************************************************
  3670. *
  3671. * FUNCTION
  3672. *
  3673. * INPUT
  3674. *
  3675. * OUTPUT
  3676. *
  3677. * RETURNS
  3678. *
  3679. * AUTHOR
  3680. *
  3681. * DESCRIPTION
  3682. *
  3683. * CHANGES
  3684. *
  3685. ******************************************************************************/
  3686. static
  3687. TRANSFORM *Parse_Transform ()
  3688. {
  3689. MATRIX Local_Matrix;
  3690. TRANSFORM *New, Local_Trans;
  3691. VECTOR Local_Vector;
  3692. Parse_Begin ();
  3693. New = Create_Transform ();
  3694. EXPECT
  3695. CASE(TRANSFORM_ID_TOKEN)
  3696. Compose_Transforms (New, (TRANSFORM *)Token.Data);
  3697. END_CASE
  3698. CASE (TRANSFORM_TOKEN)
  3699. GET(TRANSFORM_ID_TOKEN)
  3700. Compose_Transforms(New, (TRANSFORM *)Token.Data);
  3701. END_CASE
  3702. CASE (TRANSLATE_TOKEN)
  3703. Parse_Vector (Local_Vector);
  3704. Compute_Translation_Transform(&Local_Trans, Local_Vector);
  3705. Compose_Transforms (New, &Local_Trans);
  3706. END_CASE
  3707. CASE (ROTATE_TOKEN)
  3708. Parse_Vector (Local_Vector);
  3709. Compute_Rotation_Transform(&Local_Trans, Local_Vector);
  3710. Compose_Transforms (New, &Local_Trans);
  3711. END_CASE
  3712. CASE (SCALE_TOKEN)
  3713. Parse_Scale_Vector (Local_Vector);
  3714. Compute_Scaling_Transform(&Local_Trans, Local_Vector);
  3715. Compose_Transforms (New, &Local_Trans);
  3716. END_CASE
  3717. CASE (MATRIX_TOKEN)
  3718. Parse_Matrix(Local_Matrix);
  3719. Compute_Matrix_Transform(&Local_Trans, Local_Matrix);
  3720. Compose_Transforms (New, &Local_Trans);
  3721. END_CASE
  3722. OTHERWISE
  3723. UNGET
  3724. EXIT
  3725. END_CASE
  3726. END_EXPECT
  3727. Parse_End ();
  3728. return (New);
  3729. }
  3730. /*****************************************************************************
  3731. *
  3732. * FUNCTION
  3733. *
  3734. * INPUT
  3735. *
  3736. * OUTPUT
  3737. *
  3738. * RETURNS
  3739. *
  3740. * AUTHOR
  3741. *
  3742. * DESCRIPTION
  3743. *
  3744. * CHANGES
  3745. *
  3746. ******************************************************************************/
  3747. void Parse_Declare ()
  3748. {
  3749. int Previous=-1; /* tw */
  3750. int Local_Index,Local_Flag;
  3751. SYM_ENTRY *Temp_Entry;
  3752. if ((Local_Flag=(Token.Token_Id==LOCAL_TOKEN))) /* tw */
  3753. {
  3754. Local_Index=Table_Index;
  3755. }
  3756. else
  3757. {
  3758. Local_Index=1;
  3759. }
  3760. LValue_Ok = TRUE;
  3761. EXPECT
  3762. CASE (IDENTIFIER_TOKEN)
  3763. Temp_Entry = Add_Symbol (Local_Index,Token.Token_String,IDENTIFIER_TOKEN);
  3764. Token.NumberPtr = &(Temp_Entry->Token_Number);
  3765. Token.DataPtr = &(Temp_Entry->Data);
  3766. Previous = Token.Token_Id;
  3767. EXIT
  3768. END_CASE
  3769. CASE4 (TNORMAL_ID_TOKEN, FINISH_ID_TOKEN, TEXTURE_ID_TOKEN, OBJECT_ID_TOKEN)
  3770. CASE4 (COLOUR_MAP_ID_TOKEN, TRANSFORM_ID_TOKEN, CAMERA_ID_TOKEN, PIGMENT_ID_TOKEN)
  3771. CASE4 (SLOPE_MAP_ID_TOKEN,NORMAL_MAP_ID_TOKEN,TEXTURE_MAP_ID_TOKEN,COLOUR_ID_TOKEN)
  3772. CASE4 (PIGMENT_MAP_ID_TOKEN, MEDIA_ID_TOKEN,STRING_ID_TOKEN,INTERIOR_ID_TOKEN)
  3773. CASE5 (DENSITY_MAP_ID_TOKEN, ARRAY_ID_TOKEN, DENSITY_ID_TOKEN,UV_ID_TOKEN,VECTOR_4D_ID_TOKEN)
  3774. CASE4 (RAINBOW_ID_TOKEN, FOG_ID_TOKEN, SKYSPHERE_ID_TOKEN,MATERIAL_ID_TOKEN)
  3775. if (Local_Flag && (Token.Table_Index != Table_Index))
  3776. {
  3777. Temp_Entry = Add_Symbol (Local_Index,Token.Token_String,IDENTIFIER_TOKEN);
  3778. Token.NumberPtr = &(Temp_Entry->Token_Number);
  3779. Token.DataPtr = &(Temp_Entry->Data);
  3780. Previous = IDENTIFIER_TOKEN;
  3781. }
  3782. else
  3783. {
  3784. Previous = Token.Token_Id;
  3785. }
  3786. EXIT
  3787. END_CASE
  3788. CASE (EMPTY_ARRAY_TOKEN)
  3789. Previous = Token.Token_Id;
  3790. EXIT
  3791. END_CASE
  3792. CASE2 (VECTOR_FUNCT_TOKEN, FLOAT_FUNCT_TOKEN)
  3793. switch(Token.Function_Id)
  3794. {
  3795. case VECTOR_ID_TOKEN:
  3796. case FLOAT_ID_TOKEN:
  3797. if (Local_Flag && (Token.Table_Index != Table_Index))
  3798. {
  3799. Temp_Entry = Add_Symbol (Local_Index,Token.Token_String,IDENTIFIER_TOKEN);
  3800. Token.NumberPtr = &(Temp_Entry->Token_Number);
  3801. Token.DataPtr = &(Temp_Entry->Data);
  3802. }
  3803. Previous = Token.Function_Id;
  3804. break;
  3805. default:
  3806. Parse_Error(IDENTIFIER_TOKEN);
  3807. break;
  3808. }
  3809. EXIT
  3810. END_CASE
  3811. OTHERWISE
  3812. Parse_Error(IDENTIFIER_TOKEN);
  3813. END_CASE
  3814. END_EXPECT
  3815. LValue_Ok = FALSE;
  3816. GET (EQUALS_TOKEN);
  3817. if (!Parse_RValue (Previous,Token.NumberPtr,Token.DataPtr, FALSE,TRUE))
  3818. {
  3819. Parse_Error_Str("RValue to declare");
  3820. }
  3821. }
  3822. int Parse_RValue (int Previous, int *NumberPtr, void **DataPtr, int ParFlag, int SemiFlag)
  3823. {
  3824. EXPRESS Local_Express;
  3825. COLOUR *Local_Colour;
  3826. PIGMENT *Local_Pigment;
  3827. TNORMAL *Local_Tnormal;
  3828. FINISH *Local_Finish;
  3829. TEXTURE *Local_Texture, *Temp_Texture;
  3830. TRANSFORM *Local_Trans;
  3831. OBJECT *Local_Object;
  3832. CAMERA *Local_Camera;
  3833. IMEDIA *Local_Media;
  3834. PIGMENT *Local_Density;
  3835. INTERIOR *Local_Interior;
  3836. MATERIAL *Local_Material;
  3837. void *Temp_Data;
  3838. POV_PARAM *New_Par;
  3839. int Found=TRUE;
  3840. int Temp_Count=30000;
  3841. int Old_Ok=Ok_To_Declare;
  3842. int Terms;
  3843. EXPECT
  3844. CASE4 (TNORMAL_ID_TOKEN, FINISH_ID_TOKEN, TEXTURE_ID_TOKEN, OBJECT_ID_TOKEN)
  3845. CASE4 (COLOUR_MAP_ID_TOKEN, TRANSFORM_ID_TOKEN, CAMERA_ID_TOKEN, PIGMENT_ID_TOKEN)
  3846. CASE4 (SLOPE_MAP_ID_TOKEN,NORMAL_MAP_ID_TOKEN,TEXTURE_MAP_ID_TOKEN,ARRAY_ID_TOKEN)
  3847. CASE4 (PIGMENT_MAP_ID_TOKEN, MEDIA_ID_TOKEN,INTERIOR_ID_TOKEN,DENSITY_ID_TOKEN)
  3848. CASE4 (DENSITY_MAP_ID_TOKEN, RAINBOW_ID_TOKEN, FOG_ID_TOKEN, SKYSPHERE_ID_TOKEN)
  3849. CASE (MATERIAL_ID_TOKEN)
  3850. if (ParFlag)
  3851. {
  3852. New_Par = (POV_PARAM *)POV_MALLOC(sizeof(POV_PARAM),"parameter");
  3853. New_Par->NumberPtr = Token.NumberPtr;
  3854. New_Par->DataPtr = Token.DataPtr;
  3855. *NumberPtr = PARAMETER_ID_TOKEN;
  3856. *DataPtr = (void *)New_Par;
  3857. }
  3858. else
  3859. {
  3860. Temp_Data = (void *) Copy_Identifier((void *)*Token.DataPtr,*Token.NumberPtr);
  3861. *NumberPtr = *Token.NumberPtr;
  3862. Test_Redefine(Previous,NumberPtr,*DataPtr);
  3863. *DataPtr = Temp_Data;
  3864. }
  3865. EXIT
  3866. END_CASE
  3867. CASE (IDENTIFIER_TOKEN)
  3868. if (ParFlag)
  3869. {
  3870. Error("Cannot pass uninitialized identifier as macro parameter.\nInitialize first.\n");
  3871. }
  3872. else
  3873. {
  3874. Error("Cannot assign uninitialized identifier.\n");
  3875. }
  3876. EXIT
  3877. END_CASE
  3878. CASE_COLOUR
  3879. Local_Colour = Create_Colour();
  3880. Ok_To_Declare = FALSE;
  3881. Parse_Colour (*Local_Colour);
  3882. if (SemiFlag)
  3883. {
  3884. Parse_Semi_Colon();
  3885. }
  3886. Ok_To_Declare = TRUE;
  3887. *NumberPtr = COLOUR_ID_TOKEN;
  3888. Test_Redefine(Previous,NumberPtr,*DataPtr);
  3889. *DataPtr = (void *) Local_Colour;
  3890. EXIT
  3891. END_CASE
  3892. CASE_VECTOR
  3893. Ok_To_Declare = FALSE;
  3894. if (ParFlag &&
  3895. ( ( (Token.Token_Id==FLOAT_FUNCT_TOKEN) &&
  3896. (Token.Function_Id==FLOAT_ID_TOKEN)
  3897. ) ||
  3898. ( (Token.Token_Id==VECTOR_FUNCT_TOKEN) &&
  3899. (Token.Function_Id==VECTOR_ID_TOKEN)
  3900. ) ||
  3901. (Token.Token_Id==VECTOR_4D_ID_TOKEN)
  3902. ||
  3903. (Token.Token_Id==UV_ID_TOKEN)
  3904. )
  3905. )
  3906. {
  3907. Temp_Count=token_count;
  3908. }
  3909. Terms = Parse_Unknown_Vector (Local_Express);
  3910. if (SemiFlag)
  3911. {
  3912. Parse_Semi_Colon();
  3913. }
  3914. Temp_Count -= token_count;
  3915. if ((Temp_Count==-1) || (Temp_Count==1000))
  3916. {
  3917. New_Par = (POV_PARAM *)POV_MALLOC(sizeof(POV_PARAM),"parameter");
  3918. New_Par->NumberPtr = Token.NumberPtr;
  3919. New_Par->DataPtr = Token.DataPtr;
  3920. *NumberPtr = PARAMETER_ID_TOKEN;
  3921. *DataPtr = (void *)New_Par;
  3922. }
  3923. else
  3924. {
  3925. switch(Terms)
  3926. {
  3927. case 1:
  3928. *NumberPtr = FLOAT_ID_TOKEN;
  3929. Test_Redefine(Previous,NumberPtr,*DataPtr);
  3930. *DataPtr = (void *) Create_Float();
  3931. *((DBL *)*DataPtr) = Local_Express[X];
  3932. break;
  3933. case 2:
  3934. *NumberPtr = UV_ID_TOKEN;
  3935. Test_Redefine(Previous,NumberPtr,*DataPtr);
  3936. *DataPtr = (void *) Create_UV_Vect();
  3937. Assign_UV_Vect(*DataPtr, Local_Express);
  3938. break;
  3939. case 3:
  3940. *NumberPtr = VECTOR_ID_TOKEN;
  3941. Test_Redefine(Previous,NumberPtr,*DataPtr);
  3942. *DataPtr = (void *) Create_Vector();
  3943. Assign_Vector(*DataPtr, Local_Express);
  3944. break;
  3945. case 4:
  3946. *NumberPtr = VECTOR_4D_ID_TOKEN;
  3947. Test_Redefine(Previous,NumberPtr,*DataPtr);
  3948. *DataPtr = (void *) Create_Vector_4D();
  3949. Assign_Vector_4D(*DataPtr, Local_Express);
  3950. break;
  3951. case 5:
  3952. *NumberPtr = COLOUR_ID_TOKEN;
  3953. Test_Redefine(Previous,NumberPtr,*DataPtr);
  3954. *DataPtr = (void *) Create_Colour();
  3955. Assign_Colour(*DataPtr, Local_Express);
  3956. break;
  3957. }
  3958. }
  3959. Ok_To_Declare = TRUE;
  3960. EXIT
  3961. END_CASE
  3962. CASE (PIGMENT_TOKEN)
  3963. Local_Pigment = Copy_Pigment((Default_Texture->Pigment));
  3964. Parse_Begin ();
  3965. Parse_Pigment (&Local_Pigment);
  3966. Parse_End ();
  3967. *NumberPtr = PIGMENT_ID_TOKEN;
  3968. Test_Redefine(Previous,NumberPtr,*DataPtr);
  3969. *DataPtr = (void *)Local_Pigment;
  3970. EXIT
  3971. END_CASE
  3972. CASE (TNORMAL_TOKEN)
  3973. Local_Tnormal = Copy_Tnormal((Default_Texture->Tnormal));
  3974. Parse_Begin ();
  3975. Parse_Tnormal (&Local_Tnormal);
  3976. Parse_End ();
  3977. *NumberPtr = TNORMAL_ID_TOKEN;
  3978. Test_Redefine(Previous,NumberPtr,*DataPtr);
  3979. *DataPtr = (void *) Local_Tnormal;
  3980. EXIT
  3981. END_CASE
  3982. CASE (FINISH_TOKEN)
  3983. Local_Finish = Copy_Finish((Default_Texture->Finish));
  3984. Parse_Finish (&Local_Finish);
  3985. *NumberPtr = FINISH_ID_TOKEN;
  3986. Test_Redefine(Previous,NumberPtr,*DataPtr);
  3987. *DataPtr = (void *) Local_Finish;
  3988. EXIT
  3989. END_CASE
  3990. CASE (CAMERA_TOKEN)
  3991. Local_Camera = Copy_Camera(Default_Camera);
  3992. Parse_Camera (&Local_Camera);
  3993. *NumberPtr = CAMERA_ID_TOKEN;
  3994. Test_Redefine(Previous,NumberPtr,*DataPtr);
  3995. *DataPtr = (void *) Local_Camera;
  3996. EXIT
  3997. END_CASE
  3998. CASE (TEXTURE_TOKEN)
  3999. Parse_Begin ();
  4000. Local_Texture = Parse_Texture ();
  4001. Parse_End ();
  4002. Temp_Texture=NULL;
  4003. Link_Textures(&Temp_Texture, Local_Texture);
  4004. Ok_To_Declare = FALSE;
  4005. EXPECT
  4006. CASE (TEXTURE_TOKEN)
  4007. Parse_Begin ();
  4008. Local_Texture = Parse_Texture ();
  4009. Parse_End ();
  4010. Link_Textures(&Temp_Texture, Local_Texture);
  4011. END_CASE
  4012. OTHERWISE
  4013. UNGET
  4014. EXIT
  4015. END_CASE
  4016. END_EXPECT
  4017. *NumberPtr = TEXTURE_ID_TOKEN;
  4018. Test_Redefine(Previous,NumberPtr,*DataPtr);
  4019. *DataPtr = (void *)Temp_Texture;
  4020. Ok_To_Declare = TRUE;
  4021. EXIT
  4022. END_CASE
  4023. CASE (COLOUR_MAP_TOKEN)
  4024. Temp_Data=(void *) Parse_Colour_Map ();
  4025. *NumberPtr = COLOUR_MAP_ID_TOKEN;
  4026. Test_Redefine(Previous,NumberPtr,*DataPtr);
  4027. *DataPtr = Temp_Data;
  4028. EXIT
  4029. END_CASE
  4030. CASE (PIGMENT_MAP_TOKEN)
  4031. Temp_Data = (void *) Parse_Blend_Map (PIGMENT_TYPE,NO_PATTERN);
  4032. *NumberPtr = PIGMENT_MAP_ID_TOKEN;
  4033. Test_Redefine(Previous,NumberPtr,*DataPtr);
  4034. *DataPtr = Temp_Data;
  4035. EXIT
  4036. END_CASE
  4037. CASE (DENSITY_MAP_TOKEN)
  4038. Temp_Data = (void *) Parse_Blend_Map (DENSITY_TYPE,NO_PATTERN);
  4039. *NumberPtr = DENSITY_MAP_ID_TOKEN;
  4040. Test_Redefine(Previous,NumberPtr,*DataPtr);
  4041. *DataPtr = Temp_Data;
  4042. EXIT
  4043. END_CASE
  4044. CASE (SLOPE_MAP_TOKEN)
  4045. Temp_Data = (void *) Parse_Blend_Map (SLOPE_TYPE,NO_PATTERN);
  4046. *NumberPtr = SLOPE_MAP_ID_TOKEN;
  4047. Test_Redefine(Previous,NumberPtr,*DataPtr);
  4048. *DataPtr = Temp_Data;
  4049. EXIT
  4050. END_CASE
  4051. CASE (TEXTURE_MAP_TOKEN)
  4052. Temp_Data = (void *) Parse_Blend_Map (TEXTURE_TYPE,NO_PATTERN);
  4053. *NumberPtr = TEXTURE_MAP_ID_TOKEN;
  4054. Test_Redefine(Previous,NumberPtr,*DataPtr);
  4055. *DataPtr = Temp_Data;
  4056. EXIT
  4057. END_CASE
  4058. CASE (NORMAL_MAP_TOKEN)
  4059. Temp_Data = (void *) Parse_Blend_Map (NORMAL_TYPE,NO_PATTERN);
  4060. *NumberPtr = NORMAL_MAP_ID_TOKEN;
  4061. Test_Redefine(Previous,NumberPtr,*DataPtr);
  4062. *DataPtr = Temp_Data;
  4063. EXIT
  4064. END_CASE
  4065. CASE (RAINBOW_TOKEN)
  4066. Temp_Data = (void *) Parse_Rainbow();
  4067. *NumberPtr = RAINBOW_ID_TOKEN;
  4068. Test_Redefine(Previous,NumberPtr,*DataPtr);
  4069. *DataPtr = Temp_Data;
  4070. EXIT
  4071. END_CASE
  4072. CASE (FOG_TOKEN)
  4073. Temp_Data = (void *) Parse_Fog();
  4074. *NumberPtr = FOG_ID_TOKEN;
  4075. Test_Redefine(Previous,NumberPtr,*DataPtr);
  4076. *DataPtr = Temp_Data;
  4077. EXIT
  4078. END_CASE
  4079. CASE (MEDIA_TOKEN)
  4080. Local_Media = NULL;
  4081. Parse_Media(&Local_Media);
  4082. Temp_Data = (void *)Local_Media;
  4083. *NumberPtr = MEDIA_ID_TOKEN;
  4084. Test_Redefine(Previous,NumberPtr,*DataPtr);
  4085. *DataPtr = Temp_Data;
  4086. EXIT
  4087. END_CASE
  4088. CASE (DENSITY_TOKEN)
  4089. Local_Density = NULL;
  4090. Parse_Begin ();
  4091. Parse_Media_Density_Pattern (&Local_Density);
  4092. Parse_End ();
  4093. *NumberPtr = DENSITY_ID_TOKEN;
  4094. Test_Redefine(Previous,NumberPtr,*DataPtr);
  4095. *DataPtr = (void *)Local_Density;
  4096. EXIT
  4097. END_CASE
  4098. CASE (INTERIOR_TOKEN)
  4099. Local_Interior = NULL;
  4100. Parse_Interior(&Local_Interior);
  4101. Temp_Data = (void *)Local_Interior;
  4102. *NumberPtr = INTERIOR_ID_TOKEN;
  4103. Test_Redefine(Previous,NumberPtr,*DataPtr);
  4104. *DataPtr = Temp_Data;
  4105. EXIT
  4106. END_CASE
  4107. CASE (MATERIAL_TOKEN)
  4108. Local_Material = Create_Material();
  4109. Parse_Material(Local_Material);
  4110. Temp_Data = (void *)Local_Material;
  4111. *NumberPtr = MATERIAL_ID_TOKEN;
  4112. Test_Redefine(Previous,NumberPtr,*DataPtr);
  4113. *DataPtr = Temp_Data;
  4114. EXIT
  4115. END_CASE
  4116. CASE (SKYSPHERE_TOKEN)
  4117. Temp_Data = (void *) Parse_Skysphere();
  4118. *NumberPtr = SKYSPHERE_ID_TOKEN;
  4119. Test_Redefine(Previous,NumberPtr,*DataPtr);
  4120. *DataPtr = Temp_Data;
  4121. EXIT
  4122. END_CASE
  4123. CASE (TRANSFORM_TOKEN)
  4124. Local_Trans = Parse_Transform ();
  4125. *NumberPtr = TRANSFORM_ID_TOKEN;
  4126. Test_Redefine(Previous,NumberPtr,*DataPtr);
  4127. *DataPtr = (void *) Local_Trans;
  4128. EXIT
  4129. END_CASE
  4130. CASE4 (STRING_LITERAL_TOKEN,CHR_TOKEN,SUBSTR_TOKEN,STR_TOKEN)
  4131. CASE4 (CONCAT_TOKEN,STRUPR_TOKEN,STRLWR_TOKEN,STRING_ID_TOKEN)
  4132. UNGET
  4133. Temp_Data = Parse_String();
  4134. *NumberPtr = STRING_ID_TOKEN;
  4135. Test_Redefine(Previous,NumberPtr,*DataPtr);
  4136. *DataPtr = Temp_Data;
  4137. EXIT
  4138. END_CASE
  4139. CASE (ARRAY_TOKEN)
  4140. Temp_Data = (void *) Parse_Array_Declare();
  4141. *NumberPtr = ARRAY_ID_TOKEN;
  4142. Test_Redefine(Previous,NumberPtr,*DataPtr);
  4143. *DataPtr = Temp_Data;
  4144. EXIT
  4145. END_CASE
  4146. OTHERWISE
  4147. UNGET
  4148. Local_Object = Parse_Object ();
  4149. Found=(Local_Object!=NULL);
  4150. *NumberPtr = OBJECT_ID_TOKEN;
  4151. Test_Redefine(Previous,NumberPtr,*DataPtr);
  4152. *DataPtr = (void *) Local_Object;
  4153. EXIT
  4154. END_CASE
  4155. END_EXPECT
  4156. Ok_To_Declare=Old_Ok;
  4157. return(Found);
  4158. }
  4159. void Destroy_Ident_Data (void *Data, int Type)
  4160. {
  4161. int i;
  4162. POV_ARRAY *a;
  4163. DATA_FILE *Temp_File;
  4164. if (Data==NULL)
  4165. {
  4166. return;
  4167. }
  4168. switch (Type)
  4169. {
  4170. case COLOUR_ID_TOKEN:
  4171. Destroy_Colour((COLOUR *)Data);
  4172. break;
  4173. case VECTOR_ID_TOKEN:
  4174. Destroy_Vector((VECTOR *)Data);
  4175. break;
  4176. case UV_ID_TOKEN:
  4177. Destroy_UV_Vect((UV_VECT *)Data);
  4178. break;
  4179. case VECTOR_4D_ID_TOKEN:
  4180. Destroy_Vector((VECTOR_4D *)Data);
  4181. break;
  4182. case FLOAT_ID_TOKEN:
  4183. Destroy_Float((DBL *)Data);
  4184. break;
  4185. case PIGMENT_ID_TOKEN:
  4186. case DENSITY_ID_TOKEN:
  4187. Destroy_Pigment((PIGMENT *)Data);
  4188. break;
  4189. case TNORMAL_ID_TOKEN:
  4190. Destroy_Tnormal((TNORMAL *)Data);
  4191. break;
  4192. case FINISH_ID_TOKEN:
  4193. Destroy_Finish((FINISH *)Data);
  4194. break;
  4195. case MEDIA_ID_TOKEN:
  4196. Destroy_Media((IMEDIA *)Data);
  4197. break;
  4198. case INTERIOR_ID_TOKEN:
  4199. Destroy_Interior((INTERIOR *)Data);
  4200. break;
  4201. case MATERIAL_ID_TOKEN:
  4202. Destroy_Material((MATERIAL *)Data);
  4203. break;
  4204. case TEXTURE_ID_TOKEN:
  4205. Destroy_Textures((TEXTURE *)Data);
  4206. break;
  4207. case OBJECT_ID_TOKEN:
  4208. Destroy_Object((OBJECT *)Data);
  4209. break;
  4210. case COLOUR_MAP_ID_TOKEN:
  4211. case PIGMENT_MAP_ID_TOKEN:
  4212. case SLOPE_MAP_ID_TOKEN:
  4213. case TEXTURE_MAP_ID_TOKEN:
  4214. case NORMAL_MAP_ID_TOKEN:
  4215. case DENSITY_MAP_ID_TOKEN:
  4216. Destroy_Blend_Map((BLEND_MAP *)Data);
  4217. break;
  4218. case TRANSFORM_ID_TOKEN:
  4219. Destroy_Transform((TRANSFORM *)Data);
  4220. break;
  4221. case CAMERA_ID_TOKEN:
  4222. Destroy_Camera((CAMERA *)Data);
  4223. break;
  4224. case RAINBOW_ID_TOKEN:
  4225. Destroy_Rainbow((RAINBOW *)Data);
  4226. break;
  4227. case FOG_ID_TOKEN:
  4228. Destroy_Fog((FOG *)Data);
  4229. break;
  4230. case SKYSPHERE_ID_TOKEN:
  4231. Destroy_Skysphere((SKYSPHERE *)Data);
  4232. break;
  4233. case MACRO_ID_TOKEN:
  4234. Destroy_Macro((POV_MACRO *)Data);
  4235. break;
  4236. case STRING_ID_TOKEN:
  4237. POV_FREE((char *)Data);
  4238. break;
  4239. case ARRAY_ID_TOKEN:
  4240. a=(POV_ARRAY *)Data;
  4241. for (i=0; i<a->Total; i++)
  4242. {
  4243. Destroy_Ident_Data (a->DataPtrs[i],a->Type);
  4244. }
  4245. POV_FREE(a->DataPtrs);
  4246. POV_FREE(a);
  4247. break;
  4248. case PARAMETER_ID_TOKEN:
  4249. POV_FREE(Data);
  4250. break;
  4251. case FILE_ID_TOKEN:
  4252. Temp_File=(DATA_FILE *)Data;
  4253. if (Temp_File->File!=NULL)
  4254. {
  4255. fflush(Temp_File->File);
  4256. fclose(Temp_File->File);
  4257. }
  4258. if (Temp_File->Filename!=NULL)
  4259. {
  4260. POV_FREE(Temp_File->Filename);
  4261. }
  4262. POV_FREE(Data);
  4263. break;
  4264. }
  4265. }
  4266. /*****************************************************************************
  4267. *
  4268. * FUNCTION
  4269. *
  4270. * INPUT
  4271. *
  4272. * OUTPUT
  4273. *
  4274. * RETURNS
  4275. *
  4276. * AUTHOR
  4277. *
  4278. * DESCRIPTION
  4279. *
  4280. * CHANGES
  4281. *
  4282. ******************************************************************************/
  4283. static void Link (OBJECT *New_Object, OBJECT **Field, OBJECT **Old_Object_List)
  4284. {
  4285. *Field = *Old_Object_List;
  4286. *Old_Object_List = New_Object;
  4287. }
  4288. /*****************************************************************************
  4289. *
  4290. * FUNCTION
  4291. *
  4292. * INPUT
  4293. *
  4294. * OUTPUT
  4295. *
  4296. * RETURNS
  4297. *
  4298. * AUTHOR
  4299. *
  4300. * DESCRIPTION
  4301. *
  4302. * CHANGES
  4303. *
  4304. ******************************************************************************/
  4305. void Link_Textures (TEXTURE **Old_Textures, TEXTURE *New_Textures)
  4306. {
  4307. TEXTURE *Layer;
  4308. if (New_Textures == NULL)
  4309. return;
  4310. if ((*Old_Textures) != NULL)
  4311. {
  4312. if ((*Old_Textures)->Type != PLAIN_PATTERN)
  4313. {
  4314. Error("Cannot layer over a patterned texture.\n");
  4315. }
  4316. }
  4317. for (Layer = New_Textures ;
  4318. Layer->Next != NULL ;
  4319. Layer = (TEXTURE *)Layer->Next)
  4320. {}
  4321. Layer->Next = (TPATTERN *)*Old_Textures;
  4322. *Old_Textures = New_Textures;
  4323. if ((New_Textures->Type != PLAIN_PATTERN) && (New_Textures->Next != NULL))
  4324. {
  4325. Error("Cannot layer a patterned texture over another.\n");
  4326. }
  4327. }
  4328. /*****************************************************************************
  4329. *
  4330. * FUNCTION
  4331. *
  4332. * INPUT
  4333. *
  4334. * OUTPUT
  4335. *
  4336. * RETURNS
  4337. *
  4338. * AUTHOR
  4339. *
  4340. * DESCRIPTION
  4341. *
  4342. * CHANGES
  4343. *
  4344. ******************************************************************************/
  4345. char *Get_Token_String (TOKEN Token_Id)
  4346. {
  4347. register int i;
  4348. for (i = 0 ; i < LAST_TOKEN ; i++)
  4349. if (Reserved_Words[i].Token_Number == Token_Id)
  4350. return (Reserved_Words[i].Token_Name);
  4351. return ("");
  4352. }
  4353. /*****************************************************************************
  4354. *
  4355. * FUNCTION
  4356. *
  4357. * INPUT
  4358. *
  4359. * OUTPUT
  4360. *
  4361. * RETURNS
  4362. *
  4363. * AUTHOR
  4364. *
  4365. * DESCRIPTION
  4366. *
  4367. * CHANGES
  4368. *
  4369. ******************************************************************************/
  4370. void Test_Redefine(TOKEN Previous, TOKEN *NumberPtr, void *Data)
  4371. {
  4372. char *oldt, *newt;
  4373. if ((Previous == IDENTIFIER_TOKEN) || (Previous == EMPTY_ARRAY_TOKEN))
  4374. {
  4375. return;
  4376. }
  4377. if (Previous == *NumberPtr)
  4378. {
  4379. Destroy_Ident_Data(Data,*NumberPtr);
  4380. }
  4381. else
  4382. {
  4383. oldt = Get_Token_String (Previous);
  4384. newt = Get_Token_String (*NumberPtr);
  4385. *NumberPtr = Previous;
  4386. Error ("Attempted to redefine %s as %s.", oldt, newt);
  4387. }
  4388. }
  4389. /*****************************************************************************
  4390. *
  4391. * FUNCTION
  4392. *
  4393. * INPUT
  4394. *
  4395. * OUTPUT
  4396. *
  4397. * RETURNS
  4398. *
  4399. * AUTHOR
  4400. *
  4401. * DESCRIPTION
  4402. *
  4403. * CHANGES
  4404. *
  4405. ******************************************************************************/
  4406. void Parse_Error (TOKEN Token_Id)
  4407. {
  4408. char *expected;
  4409. expected = Get_Token_String (Token_Id);
  4410. Parse_Error_Str(expected);
  4411. }
  4412. /*****************************************************************************
  4413. *
  4414. * FUNCTION
  4415. *
  4416. * INPUT
  4417. *
  4418. * OUTPUT
  4419. *
  4420. * RETURNS
  4421. *
  4422. * AUTHOR
  4423. *
  4424. * DESCRIPTION
  4425. *
  4426. * CHANGES
  4427. *
  4428. ******************************************************************************/
  4429. void Parse_Error_Str (char *str)
  4430. {
  4431. Where_Error ();
  4432. Error_Line("%s expected but", str);
  4433. Found_Instead ();
  4434. }
  4435. /*****************************************************************************
  4436. *
  4437. * FUNCTION
  4438. *
  4439. * INPUT
  4440. *
  4441. * OUTPUT
  4442. *
  4443. * RETURNS
  4444. *
  4445. * AUTHOR
  4446. *
  4447. * DESCRIPTION
  4448. *
  4449. * CHANGES
  4450. *
  4451. ******************************************************************************/
  4452. static void Found_Instead ()
  4453. {
  4454. char *found;
  4455. Stage=STAGE_FOUND_INSTEAD;
  4456. switch(Token.Token_Id)
  4457. {
  4458. case IDENTIFIER_TOKEN:
  4459. Error (" undeclared identifier '%s' found instead.\n", Token.Token_String);
  4460. break;
  4461. case VECTOR_FUNCT_TOKEN:
  4462. found = Get_Token_String (Token.Function_Id);
  4463. Error (" vector function '%s' found instead.\n", found);
  4464. break;
  4465. case FLOAT_FUNCT_TOKEN:
  4466. found = Get_Token_String (Token.Function_Id);
  4467. Error (" float function '%s' found instead.\n", found);
  4468. break;
  4469. case COLOUR_KEY_TOKEN:
  4470. found = Get_Token_String (Token.Function_Id);
  4471. Error (" color keyword '%s' found instead.\n", found);
  4472. break;
  4473. default:
  4474. found = Get_Token_String (Token.Token_Id);
  4475. Error (" %s found instead.\n", found);
  4476. }
  4477. }
  4478. /*****************************************************************************
  4479. *
  4480. * FUNCTION
  4481. *
  4482. * INPUT
  4483. *
  4484. * OUTPUT
  4485. *
  4486. * RETURNS
  4487. *
  4488. * AUTHOR
  4489. *
  4490. * DESCRIPTION
  4491. *
  4492. * CHANGES
  4493. *
  4494. ******************************************************************************/
  4495. void Warn_State (TOKEN Token_Id,TOKEN Type)
  4496. {
  4497. char *found;
  4498. char *should;
  4499. found = Get_Token_String (Token_Id);
  4500. should = Get_Token_String (Type);
  4501. Warning (1.5, "%s:%d: warning: Found %s that should be in %s statement.\n",
  4502. Token.Filename, Token.Token_Line_No+1, found, should);
  4503. }
  4504. /*****************************************************************************
  4505. *
  4506. * FUNCTION
  4507. *
  4508. * INPUT
  4509. *
  4510. * OUTPUT
  4511. *
  4512. * RETURNS
  4513. *
  4514. * AUTHOR
  4515. *
  4516. * DESCRIPTION
  4517. *
  4518. * CHANGES
  4519. *
  4520. ******************************************************************************/
  4521. void Warn (DBL Level, char *str)
  4522. {
  4523. if (opts.Language_Version < Level)
  4524. return;
  4525. Warning(Level, "%s:%d: warning: %s\n", Token.Filename, Token.Token_Line_No+1, str);
  4526. }
  4527. /*****************************************************************************
  4528. *
  4529. * FUNCTION
  4530. *
  4531. * INPUT
  4532. *
  4533. * OUTPUT
  4534. *
  4535. * RETURNS
  4536. *
  4537. * AUTHOR
  4538. *
  4539. * DESCRIPTION
  4540. *
  4541. * CHANGES
  4542. *
  4543. ******************************************************************************/
  4544. void MAError (char *str,size_t size)
  4545. {
  4546. Error ("Out of memory. Cannot allocate %ld bytes for %s.\n",size,str);
  4547. }
  4548. /*****************************************************************************
  4549. *
  4550. * FUNCTION
  4551. *
  4552. * INPUT
  4553. *
  4554. * OUTPUT
  4555. *
  4556. * RETURNS
  4557. *
  4558. * AUTHOR
  4559. *
  4560. * DESCRIPTION
  4561. *
  4562. * CHANGES
  4563. *
  4564. ******************************************************************************/
  4565. static void Post_Process (OBJECT *Object,OBJECT *Parent)
  4566. {
  4567. DBL Volume;
  4568. OBJECT *Sib;
  4569. FINISH *Finish;
  4570. if (Object == NULL)
  4571. {
  4572. return;
  4573. }
  4574. if (Object->Type & LT_SRC_UNION_OBJECT)
  4575. {
  4576. for (Sib = ((CSG *)Object)->Children; Sib != NULL; Sib = Sib->Sibling)
  4577. {
  4578. Post_Process(Sib, Object);
  4579. }
  4580. return;
  4581. }
  4582. /* Promote texture etc. from parent to children. */
  4583. if (Parent != NULL)
  4584. {
  4585. if (Object->Texture == NULL)
  4586. {
  4587. Object->Texture = Copy_Texture_Pointer(Parent->Texture);
  4588. }
  4589. if (Object->Interior == NULL)
  4590. {
  4591. Object->Interior = Copy_Interior_Pointer(Parent->Interior);
  4592. }
  4593. if (Test_Flag(Parent, NO_SHADOW_FLAG))
  4594. {
  4595. Set_Flag(Object, NO_SHADOW_FLAG);
  4596. }
  4597. }
  4598. if (Object->Interior != NULL)
  4599. {
  4600. Post_Media(Object->Interior->IMedia);
  4601. }
  4602. if ((Object->Texture == NULL) &&
  4603. !(Object->Type & TEXTURED_OBJECT) &&
  4604. !(Object->Type & LIGHT_SOURCE_OBJECT))
  4605. {
  4606. Object->Texture = Copy_Textures(Default_Texture);
  4607. }
  4608. Post_Textures(Object->Texture); /*moved cey 6/97*/
  4609. if (Object->Type & LIGHT_SOURCE_OBJECT)
  4610. {
  4611. ((LIGHT_SOURCE *)Object)->Next_Light_Source = Frame.Light_Sources;
  4612. Frame.Light_Sources = (LIGHT_SOURCE *)Object;
  4613. Frame.Number_Of_Light_Sources++;
  4614. }
  4615. else
  4616. {
  4617. /* If there is no interior create one. */
  4618. if (Object->Interior == NULL)
  4619. {
  4620. Object->Interior = Create_Interior();
  4621. }
  4622. /* Promote hollow flag to interior. */
  4623. Object->Interior->hollow = (Test_Flag(Object, HOLLOW_FLAG) != FALSE);
  4624. /* Promote finish's IOR to interior IOR. */
  4625. if (Object->Texture != NULL)
  4626. {
  4627. if (Object->Texture->Type == PLAIN_PATTERN)
  4628. {
  4629. if ((Finish = Object->Texture->Finish) != NULL)
  4630. {
  4631. if (Finish->Temp_IOR >= 0.0)
  4632. {
  4633. Object->Interior->IOR = Finish->Temp_IOR;
  4634. }
  4635. if (Finish->Temp_Caustics >= 0.0)
  4636. {
  4637. Object->Interior->Caustics = Finish->Temp_Caustics;
  4638. }
  4639. Object->Interior->Old_Refract = Finish->Temp_Refract;
  4640. }
  4641. }
  4642. }
  4643. /* If there is no IOR specified use the atmopshere ior. */
  4644. if (Object->Interior->IOR == 0.0)
  4645. {
  4646. Object->Interior->IOR = Frame.Atmosphere_IOR;
  4647. }
  4648. }
  4649. if (Object->Type & COMPOUND_OBJECT)
  4650. {
  4651. for (Sib = ((CSG *)Object)->Children; Sib != NULL; Sib = Sib->Sibling)
  4652. {
  4653. Post_Process(Sib, Object);
  4654. }
  4655. }
  4656. /* [removed by CEY 01/98]
  4657. else
  4658. {
  4659. if (Object->Texture != NULL)
  4660. {
  4661. if (Object->Texture->Type == PLAIN_PATTERN)
  4662. {
  4663. if (Object->Texture->Tnormal != NULL)
  4664. {
  4665. Object->Type |= DOUBLE_ILLUMINATE;
  4666. }
  4667. }
  4668. }
  4669. }
  4670. */
  4671. /* Test wether the object is finite or infinite. [DB 9/94] */
  4672. BOUNDS_VOLUME(Volume, Object->BBox);
  4673. if (Volume > INFINITE_VOLUME)
  4674. {
  4675. Set_Flag(Object, INFINITE_FLAG);
  4676. }
  4677. /* Test wether the object is opaque or not. [DB 8/94] */
  4678. if ((Object->Methods != &Blob_Methods) &&
  4679. (Object->Methods != &Mesh_Methods) &&
  4680. (Test_Opacity(Object->Texture)))
  4681. {
  4682. Set_Flag(Object, OPAQUE_FLAG);
  4683. }
  4684. else
  4685. {
  4686. /* Objects with multiple textures have to be handled separately. */
  4687. if (Object->Methods == &Blob_Methods)
  4688. {
  4689. Test_Blob_Opacity((BLOB *)Object);
  4690. }
  4691. if (Object->Methods == &Mesh_Methods)
  4692. {
  4693. Test_Mesh_Opacity((MESH *)Object);
  4694. }
  4695. }
  4696. }
  4697. /*****************************************************************************
  4698. *
  4699. * FUNCTION
  4700. *
  4701. * Link_To_Frame
  4702. *
  4703. * INPUT
  4704. *
  4705. * Object - Pointer to object
  4706. *
  4707. * OUTPUT
  4708. *
  4709. * Object
  4710. *
  4711. * RETURNS
  4712. *
  4713. * AUTHOR
  4714. *
  4715. * POV-Ray Team
  4716. *
  4717. * DESCRIPTION
  4718. *
  4719. * -
  4720. *
  4721. * CHANGES
  4722. *
  4723. * Sep 1994 : Added optional splitting of bounded unions if children are
  4724. * finite. Added removing of unnecessary bounding. [DB]
  4725. *
  4726. ******************************************************************************/
  4727. static void Link_To_Frame(OBJECT *Object)
  4728. {
  4729. int finite;
  4730. DBL Volume;
  4731. OBJECT *This_Sib, *Next_Sib;
  4732. if (Object == NULL) /* patches a memory addressing error jdm mar/95 */
  4733. return;
  4734. /* Remove bounding object if object is cheap to intersect. [DB 8/94] */
  4735. if ((opts.Options & REMOVE_BOUNDS) && (Object->Bound != NULL))
  4736. {
  4737. if ((Object->Methods != &CSG_Union_Methods) &&
  4738. (Object->Methods != &CSG_Intersection_Methods) &&
  4739. (Object->Methods != &CSG_Merge_Methods) &&
  4740. (Object->Methods != &Poly_Methods) &&
  4741. (Object->Methods != &TTF_Methods))
  4742. {
  4743. /* Destroy only, if bounding object is not used as clipping object. */
  4744. if (Object->Bound != Object->Clip)
  4745. {
  4746. Destroy_Object(Object->Bound);
  4747. }
  4748. Object->Bound = NULL;
  4749. Warn(0.0, "Unnecessary bounding object removed.");
  4750. }
  4751. }
  4752. /*
  4753. * Link the object to the frame if it's not a CSG union object,
  4754. * if it's clipped or if bounding slabs aren't used.
  4755. */
  4756. if ((Object->Methods != &CSG_Union_Methods) ||
  4757. (Object->Clip != NULL) ||
  4758. (!opts.Use_Slabs))
  4759. {
  4760. Link(Object, &(Object->Sibling), &(Frame.Objects));
  4761. return;
  4762. }
  4763. /*
  4764. * [DB 8/94]
  4765. *
  4766. * The object is a CSG union object. It will be split if all siblings are
  4767. * finite, i.e. the volume of the bounding box doesn't exceed a threshold.
  4768. */
  4769. if (Object->Bound != NULL)
  4770. {
  4771. /* Test if all siblings are finite. */
  4772. finite = TRUE;
  4773. for (This_Sib = ((CSG *)Object)->Children; This_Sib != NULL; This_Sib = This_Sib->Sibling)
  4774. {
  4775. BOUNDS_VOLUME(Volume, This_Sib->BBox);
  4776. if (Volume > BOUND_HUGE)
  4777. {
  4778. finite = FALSE;
  4779. break;
  4780. }
  4781. }
  4782. /*
  4783. * If the union has infinite children or splitting is not used link
  4784. * the union to the frame.
  4785. */
  4786. if ((!finite) || !(opts.Options & SPLIT_UNION))
  4787. {
  4788. if (finite)
  4789. {
  4790. Warn(0.0, "CSG union unnecessarily bounded.");
  4791. }
  4792. Link(Object, &(Object->Sibling), &(Frame.Objects));
  4793. return;
  4794. }
  4795. Warn(0.0, "Bounded CSG union split.");
  4796. }
  4797. /* Link all siblings of a union to the frame. */
  4798. for (This_Sib = ((CSG *)Object)->Children; This_Sib != NULL; This_Sib = Next_Sib)
  4799. {
  4800. /* Link_To_Frame() changes Sibling so save it */
  4801. Next_Sib = This_Sib->Sibling;
  4802. /* Sibling is no longer inside a CSG object. */
  4803. This_Sib->Type &= ~IS_CHILD_OBJECT;
  4804. Link_To_Frame (This_Sib);
  4805. }
  4806. /*
  4807. Object->Texture = NULL;
  4808. */
  4809. Object->Sibling = NULL;
  4810. ((CSG *)Object)->Children = NULL;
  4811. Destroy_Object (Object);
  4812. }
  4813. /*****************************************************************************
  4814. *
  4815. * FUNCTION
  4816. *
  4817. * INPUT
  4818. *
  4819. * OUTPUT
  4820. *
  4821. * RETURNS
  4822. *
  4823. * AUTHOR
  4824. *
  4825. * DESCRIPTION
  4826. *
  4827. * CHANGES
  4828. *
  4829. ******************************************************************************/
  4830. void Only_In(char *s1,char *s2)
  4831. {
  4832. Error("Keyword '%s' can only be used in a %s statement.",s1,s2);
  4833. }
  4834. /*****************************************************************************
  4835. *
  4836. * FUNCTION
  4837. *
  4838. * INPUT
  4839. *
  4840. * OUTPUT
  4841. *
  4842. * RETURNS
  4843. *
  4844. * AUTHOR
  4845. *
  4846. * DESCRIPTION
  4847. *
  4848. * CHANGES
  4849. *
  4850. ******************************************************************************/
  4851. void Not_With(char *s1,char *s2)
  4852. {
  4853. Error("Keyword '%s' cannot be used %s.",s1,s2);
  4854. }
  4855. void Warn_Compat(int f)
  4856. {
  4857. Warning(0.0,"Use of this syntax ");
  4858. if (f)
  4859. {
  4860. Warning(0.0,"is not");
  4861. }
  4862. else
  4863. {
  4864. Warning(0.0,"may not be");
  4865. }
  4866. Warning(0.0," backwards compatable with earlier versions\n%s",
  4867. "of POV-Ray. The #version directive or +MV switch will not help.\n\n");
  4868. }
  4869. /*****************************************************************************
  4870. *
  4871. * FUNCTION
  4872. *
  4873. * Set_CSG_Children_Hollow
  4874. *
  4875. * INPUT
  4876. *
  4877. * OUTPUT
  4878. *
  4879. * RETURNS
  4880. *
  4881. * AUTHOR
  4882. *
  4883. * DESCRIPTION
  4884. *
  4885. * CHANGES
  4886. *
  4887. ******************************************************************************/
  4888. static void Set_CSG_Children_Flag(OBJECT *Object, unsigned long f, unsigned long flag, unsigned long set_flag)
  4889. {
  4890. OBJECT *Sib;
  4891. for (Sib = ((CSG *)Object)->Children; Sib != NULL; Sib = Sib->Sibling)
  4892. {
  4893. if (!Test_Flag(Sib, set_flag))
  4894. {
  4895. if ((Sib->Methods == &CSG_Intersection_Methods) ||
  4896. (Sib->Methods == &CSG_Merge_Methods) ||
  4897. (Sib->Methods == &CSG_Union_Methods))
  4898. {
  4899. Set_CSG_Children_Flag(Sib, f, flag, set_flag);
  4900. }
  4901. else
  4902. {
  4903. Sib->Flags = (Sib->Flags & (~flag)) | f;
  4904. }
  4905. }
  4906. }
  4907. }
  4908. static void *Copy_Identifier (void *Data, int Type)
  4909. {
  4910. int i;
  4911. POV_ARRAY *a, *na;
  4912. VECTOR *vp;
  4913. DBL *dp;
  4914. UV_VECT *uvp;
  4915. VECTOR_4D *v4p;
  4916. void *New;
  4917. if (Data==NULL)
  4918. {
  4919. return(NULL);
  4920. }
  4921. switch (Type)
  4922. {
  4923. case COLOUR_ID_TOKEN:
  4924. New = (void *)Copy_Colour(*(COLOUR *)Data);
  4925. break;
  4926. case VECTOR_ID_TOKEN:
  4927. vp = Create_Vector();
  4928. Assign_Vector((*vp),(*((VECTOR *)Data)));
  4929. New=vp;
  4930. break;
  4931. case UV_ID_TOKEN:
  4932. uvp = Create_UV_Vect();
  4933. Assign_Vector((*uvp),(*((UV_VECT *)Data)));
  4934. New=uvp;
  4935. break;
  4936. case VECTOR_4D_ID_TOKEN:
  4937. v4p = Create_Vector_4D();
  4938. Assign_Vector_4D((*v4p),(*((VECTOR_4D *)Data)));
  4939. New=v4p;
  4940. break;
  4941. case FLOAT_ID_TOKEN:
  4942. dp = Create_Float();
  4943. *dp = *((DBL *)Data);
  4944. New = dp;
  4945. break;
  4946. case PIGMENT_ID_TOKEN:
  4947. case DENSITY_ID_TOKEN:
  4948. New = (void *)Copy_Pigment((PIGMENT *)Data);
  4949. break;
  4950. case TNORMAL_ID_TOKEN:
  4951. New = (void *)Copy_Tnormal((TNORMAL *)Data);
  4952. break;
  4953. case FINISH_ID_TOKEN:
  4954. New = (void *)Copy_Finish((FINISH *)Data);
  4955. break;
  4956. case MEDIA_ID_TOKEN:
  4957. New = (void *)Copy_Media((IMEDIA *)Data);
  4958. break;
  4959. case INTERIOR_ID_TOKEN:
  4960. New = (void *)Copy_Interior((INTERIOR *)Data);
  4961. break;
  4962. case MATERIAL_ID_TOKEN:
  4963. New = (void *)Copy_Material((MATERIAL *)Data);
  4964. break;
  4965. case TEXTURE_ID_TOKEN:
  4966. New = (void *)Copy_Textures((TEXTURE *)Data);
  4967. break;
  4968. case OBJECT_ID_TOKEN:
  4969. New = (void *)Copy_Object((OBJECT *)Data);
  4970. break;
  4971. case COLOUR_MAP_ID_TOKEN:
  4972. case PIGMENT_MAP_ID_TOKEN:
  4973. case SLOPE_MAP_ID_TOKEN:
  4974. case TEXTURE_MAP_ID_TOKEN:
  4975. case NORMAL_MAP_ID_TOKEN:
  4976. case DENSITY_MAP_ID_TOKEN:
  4977. New = (void *)Copy_Blend_Map((BLEND_MAP *)Data);
  4978. break;
  4979. case TRANSFORM_ID_TOKEN:
  4980. New = (void *)Copy_Transform((TRANSFORM *)Data);
  4981. break;
  4982. case CAMERA_ID_TOKEN:
  4983. New = (void *)Copy_Camera((CAMERA *)Data);
  4984. break;
  4985. case RAINBOW_ID_TOKEN:
  4986. New = (void *)Copy_Rainbow((RAINBOW *)Data);
  4987. break;
  4988. case FOG_ID_TOKEN:
  4989. New = (void *)Copy_Fog((FOG *)Data);
  4990. break;
  4991. case SKYSPHERE_ID_TOKEN:
  4992. New = (void *)Copy_Skysphere((SKYSPHERE *)Data);
  4993. break;
  4994. case STRING_ID_TOKEN:
  4995. New = (void *)POV_STRDUP((char *)Data);
  4996. break;
  4997. case ARRAY_ID_TOKEN:
  4998. a=(POV_ARRAY *)Data;
  4999. na=(POV_ARRAY *)POV_MALLOC(sizeof(POV_ARRAY),"array");
  5000. *na=*a;
  5001. na->DataPtrs = (void **)POV_MALLOC(sizeof(void *)*(a->Total),"array");
  5002. for (i=0; i<a->Total; i++)
  5003. {
  5004. na->DataPtrs[i] = (void *)Copy_Identifier (a->DataPtrs[i],a->Type);
  5005. }
  5006. New = (void *)na;
  5007. break;
  5008. default:
  5009. Error("Cannot copy identifier");
  5010. New = NULL; /* tw */
  5011. }
  5012. return(New);
  5013. }