| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256 |
- /****************************************************************************
- * parse.c
- *
- * This module implements a parser for the scene description files.
- *
- * from Persistence of Vision(tm) Ray Tracer
- * Copyright 1996,1999 Persistence of Vision Team
- *---------------------------------------------------------------------------
- * NOTICE: This source code file is provided so that users may experiment
- * with enhancements to POV-Ray and to port the software to platforms other
- * than those supported by the POV-Ray Team. There are strict rules under
- * which you are permitted to use this file. The rules are in the file
- * named POVLEGAL.DOC which should be distributed with this file.
- * If POVLEGAL.DOC is not available or for more info please contact the POV-Ray
- * Team Coordinator by email to team-coord@povray.org or visit us on the web at
- * http://www.povray.org. The latest version of POV-Ray may be found at this site.
- *
- * This program is based on the popular DKB raytracer version 2.12.
- * DKBTrace was originally written by David K. Buck.
- * DKBTrace Ver 2.0-2.12 were written by David K. Buck & Aaron A. Collins.
- *
- * Modifications by Thomas Willhalm, March 1999, used with permission.
- *
- *****************************************************************************/
- #include "frame.h"
- #include "vector.h"
- #include "povproto.h"
- #include "parse.h"
- #include "parstxtr.h"
- #include "atmosph.h"
- #include "bezier.h"
- #include "blob.h"
- #include "boxes.h"
- #include "bsphere.h"
- #include "colour.h"
- #include "cones.h"
- #include "csg.h"
- #include "discs.h"
- #include "express.h"
- #include "fractal.h"
- #include "gif.h"
- #include "hfield.h"
- #include "iff.h"
- #include "image.h"
- #include "interior.h"
- #include "lathe.h"
- #include "polysolv.h"
- #include "matrices.h"
- #include "mesh.h"
- #include "normal.h"
- #include "objects.h"
- #include "octree.h"
- #include "pigment.h"
- #include "planes.h"
- #include "poly.h"
- #include "polygon.h"
- #include "povray.h"
- #include "pgm.h"
- #include "ppm.h"
- #include "prism.h"
- #include "quadrics.h"
- #include "radiosit.h"
- #include "render.h"
- #include "sor.h"
- #include "spheres.h"
- #include "super.h"
- #include "targa.h"
- #include "texture.h"
- #include "tokenize.h"
- #include "torus.h"
- #include "triangle.h"
- #include "truetype.h"
- /*****************************************************************************
- * Local preprocessor defines
- ******************************************************************************/
- /* Volume that is considered to be infinite. [DB 9/94] */
- #define INFINITE_VOLUME BOUND_HUGE
- /*****************************************************************************
- * Local typedefs
- ******************************************************************************/
- /*****************************************************************************
- * Local variables
- ******************************************************************************/
- short Not_In_Default;
- short Ok_To_Declare;
- short LValue_Ok;
- static TOKEN *Brace_Stack;
- static int Brace_Index;
- static CAMERA *Default_Camera;
- /*****************************************************************************
- * Static functions
- ******************************************************************************/
- static TRANSFORM *Parse_Transform (void);
- static void Frame_Init (void);
- static void Parse_Coeffs (int order, DBL *Coeffs);
- static OBJECT *Parse_Bicubic_Patch (void);
- static OBJECT *Parse_Blob (void);
- static OBJECT *Parse_Bound_Clip (void);
- static OBJECT *Parse_Box (void);
- static OBJECT *Parse_Cone (void);
- static OBJECT *Parse_CSG (int CSG_Type);
- static OBJECT *Parse_Cylinder (void);
- static OBJECT *Parse_Disc (void);
- static OBJECT *Parse_Julia_Fractal (void);
- static OBJECT *Parse_HField (void);
- static OBJECT *Parse_Lathe (void);
- static OBJECT *Parse_Light_Source (void);
- static OBJECT *Parse_Object_Id (void);
- static OBJECT *Parse_Plane (void);
- static OBJECT *Parse_Poly (int order);
- static OBJECT *Parse_Polygon (void);
- static OBJECT *Parse_Prism (void);
- static OBJECT *Parse_Quadric (void);
- static OBJECT *Parse_Smooth_Triangle (void);
- static OBJECT *Parse_Sor (void);
- static OBJECT *Parse_Sphere (void);
- static OBJECT *Parse_Superellipsoid (void);
- static OBJECT *Parse_Torus (void);
- static OBJECT *Parse_Triangle (void);
- static OBJECT *Parse_Mesh (void);
- static TEXTURE *Parse_Mesh_Texture (void);
- static OBJECT *Parse_TrueType (void);
- static void Parse_Blob_Element_Mods (BLOB_ELEMENT *Element);
- static void Parse_Camera (CAMERA **Camera_Ptr);
- static void Parse_Frame (void);
- static void Found_Instead (void);
- static void Link (OBJECT *New_Object,OBJECT **Field,OBJECT **Old_Object_List);
- static void Link_To_Frame (OBJECT *Object);
- static void Post_Process (OBJECT *Object, OBJECT *Parent);
- static void Parse_Global_Settings (void);
- static void Global_Setting_Warn (void);
- static void Set_CSG_Children_Flag (OBJECT*, unsigned long, unsigned long, unsigned long);
- static void *Copy_Identifier (void *Data, int Type);
- /*****************************************************************************
- *
- * FUNCTION
- *
- * INPUT
- *
- * OUTPUT
- *
- * RETURNS
- *
- * AUTHOR
- *
- * DESCRIPTION
- *
- * CHANGES
- *
- ******************************************************************************/
- /* Parse the file. */
- void Parse ()
- {
- Initialize_Tokenizer();
- Brace_Stack = (TOKEN *)POV_MALLOC(MAX_BRACES*sizeof (TOKEN), "brace stack");
- Brace_Index = 0;
- Default_Camera = Create_Camera();
- Default_Texture = Create_Texture();
- Default_Texture->Pigment = Create_Pigment();
- Default_Texture->Tnormal = NULL;
- Default_Texture->Finish = Create_Finish();
- Not_In_Default = TRUE;
- Ok_To_Declare = TRUE;
- LValue_Ok = FALSE;
- Frame_Init ();
-
- Stage = STAGE_PARSING;
- Parse_Frame ();
- Post_Media(Frame.Atmosphere);
- if (Frame.Objects == NULL)
- {
- Error ("No objects in scene.");
- }
-
- Stage = STAGE_CLEANUP_PARSE;
- Terminate_Tokenizer();
- Destroy_Textures(Default_Texture);
- Destroy_Camera(Default_Camera);
- POV_FREE (Brace_Stack);
- Default_Texture = NULL;
- Default_Camera = NULL;
- Brace_Stack = NULL;
- }
- /*****************************************************************************
- *
- * FUNCTION
- *
- * INPUT
- *
- * OUTPUT
- *
- * RETURNS
- *
- * AUTHOR
- *
- * DESCRIPTION
- *
- * CHANGES
- *
- ******************************************************************************/
- /* Set up the fields in the frame to default values. */
- static
- void Frame_Init ()
- {
- Frame.Camera = Copy_Camera(Default_Camera);
- Frame.Number_Of_Light_Sources = 0;
- Frame.Light_Sources = NULL;
- Frame.Objects = NULL;
- Frame.Atmosphere_IOR = 1.0;
- Frame.Antialias_Threshold = opts.Antialias_Threshold;
- /* dmf -- the first is physically "more correct". The second works better */
- /* Make_Colour (Frame.Irid_Wavelengths, 0.70, 0.52, 0.48); */
- Make_Colour (Frame.Irid_Wavelengths, 0.25, 0.18, 0.14);
- Make_Colour (Frame.Background_Colour, 0.0, 0.0, 0.0);
- Make_Colour (Frame.Ambient_Light, 1.0, 1.0, 1.0);
- /* Init atmospheric stuff. [DB 12/94] */
- Frame.Atmosphere = NULL;
- Frame.Fog = NULL;
- Frame.Rainbow = NULL;
- Frame.Skysphere = NULL;
- }
- /*****************************************************************************
- *
- * FUNCTION
- *
- * INPUT
- *
- * OUTPUT
- *
- * RETURNS
- *
- * AUTHOR
- *
- * DESCRIPTION
- *
- * CHANGES
- *
- ******************************************************************************/
- void Parse_Begin ()
- {
- char *front;
-
- if (++Brace_Index >= MAX_BRACES)
- {
- Warn(0.0,"Too many nested '{' braces.\n");
- Brace_Index--;
- }
- Brace_Stack[Brace_Index]=Token.Token_Id;
- Get_Token ();
- if (Token.Token_Id == LEFT_CURLY_TOKEN)
- {
- return;
- }
-
- front = Get_Token_String (Brace_Stack[Brace_Index]);
- Where_Error ();
- Error_Line ("Missing { after %s, ", front);
- Found_Instead ();
- }
- /*****************************************************************************
- *
- * FUNCTION
- *
- * INPUT
- *
- * OUTPUT
- *
- * RETURNS
- *
- * AUTHOR
- *
- * DESCRIPTION
- *
- * CHANGES
- *
- ******************************************************************************/
- void Parse_End ()
- {
- char *front;
- Get_Token ();
- if (Token.Token_Id == RIGHT_CURLY_TOKEN)
- {
- if(--Brace_Index < 0)
- {
- Warn(0.0,"Possible '}' brace missmatch.");
- Brace_Index = 0;
- }
- return;
- }
- front = Get_Token_String (Brace_Stack[Brace_Index]);
- Where_Error ();
- Error_Line("No matching } in %s,", front);
- Found_Instead ();
- }
- /*****************************************************************************
- *
- * FUNCTION
- *
- * INPUT
- *
- * OUTPUT
- *
- * RETURNS
- *
- * AUTHOR
- *
- * DESCRIPTION
- *
- * CHANGES
- *
- ******************************************************************************/
- static OBJECT *Parse_Object_Id ()
- {
- OBJECT *Object;
- EXPECT
- CASE (OBJECT_ID_TOKEN)
- Warn_State(OBJECT_ID_TOKEN, OBJECT_TOKEN);
- Object = Copy_Object((OBJECT *) Token.Data);
- Parse_Object_Mods (Object);
- EXIT
- END_CASE
- OTHERWISE
- Object = NULL;
- UNGET
- EXIT
- END_CASE
- END_EXPECT
- return (Object);
- }
- /*****************************************************************************
- *
- * FUNCTION
- *
- * INPUT
- *
- * OUTPUT
- *
- * RETURNS
- *
- * AUTHOR
- *
- * DESCRIPTION
- *
- * CHANGES
- *
- ******************************************************************************/
- void Parse_Comma (void)
- {
- Get_Token();
- if (Token.Token_Id != COMMA_TOKEN)
- {
- UNGET;
- }
- }
- void Parse_Semi_Colon (void)
- {
- Get_Token();
- if (Token.Token_Id != SEMI_COLON_TOKEN)
- {
- UNGET;
- if (opts.Language_Version >= 3.1)
- {
- Warn(0.0,"All #version and #declares of float, vector, and color require semi-colon ';' at end.\n");
- }
- }
- }
- /*****************************************************************************
- *
- * FUNCTION
- *
- * INPUT
- *
- * OUTPUT
- *
- * RETURNS
- *
- * AUTHOR
- *
- * DESCRIPTION
- *
- * CHANGES
- *
- ******************************************************************************/
- static void Parse_Coeffs(int order, DBL *Coeffs)
- {
- int i;
- EXPECT
- CASE (LEFT_ANGLE_TOKEN)
- Coeffs[0] = Parse_Float();
- for (i = 1; i < term_counts(order); i++)
- {
- Parse_Comma();
- Coeffs[i] = Parse_Float();
- }
- GET (RIGHT_ANGLE_TOKEN);
- EXIT
- END_CASE
- OTHERWISE
- Parse_Error (LEFT_ANGLE_TOKEN);
- END_CASE
- END_EXPECT
- }
- /*****************************************************************************
- *
- * FUNCTION
- *
- * INPUT
- *
- * OUTPUT
- *
- * RETURNS
- *
- * AUTHOR
- *
- * DESCRIPTION
- *
- * CHANGES
- *
- ******************************************************************************/
- static
- OBJECT *Parse_Bound_Clip ()
- {
- VECTOR Local_Vector;
- MATRIX Local_Matrix;
- TRANSFORM Local_Trans;
- OBJECT *First, *Current, *Prev;
- First = Prev = NULL;
- while ((Current = Parse_Object ()) != NULL)
- {
- if (Current->Type & (TEXTURED_OBJECT+PATCH_OBJECT))
- Error ("Illegal texture or patch in clip or bound.");
- if (First == NULL)
- First = Current;
- if (Prev != NULL)
- Prev->Sibling = Current;
- Prev = Current;
- }
- EXPECT
- CASE (TRANSLATE_TOKEN)
- Parse_Vector (Local_Vector);
- Compute_Translation_Transform(&Local_Trans, Local_Vector);
- for (Current = First; Current != NULL; Current = Current->Sibling)
- {
- Translate_Object (Current, Local_Vector, &Local_Trans);
- }
- END_CASE
- CASE (ROTATE_TOKEN)
- Parse_Vector (Local_Vector);
- Compute_Rotation_Transform(&Local_Trans, Local_Vector);
- for (Current = First; Current != NULL; Current = Current->Sibling)
- {
- Rotate_Object (Current, Local_Vector, &Local_Trans);
- }
- END_CASE
- CASE (SCALE_TOKEN)
- Parse_Scale_Vector (Local_Vector);
- Compute_Scaling_Transform(&Local_Trans, Local_Vector);
- for (Current = First; Current != NULL; Current = Current->Sibling)
- {
- Scale_Object (Current, Local_Vector, &Local_Trans);
- }
- END_CASE
- CASE (TRANSFORM_TOKEN)
- GET(TRANSFORM_ID_TOKEN)
- for (Current = First; Current != NULL; Current = Current->Sibling)
- {
- Transform_Object (Current, (TRANSFORM *)Token.Data);
- }
- END_CASE
- CASE (MATRIX_TOKEN)
- Parse_Matrix (Local_Matrix);
- Compute_Matrix_Transform(&Local_Trans, Local_Matrix);
- for (Current = First; Current != NULL; Current = Current->Sibling)
- {
- Transform_Object (Current, &Local_Trans);
- }
- END_CASE
- OTHERWISE
- UNGET
- EXIT
- END_CASE
- END_EXPECT
- if (First==NULL)
- {
- Parse_Error_Str("object");
- }
- return (First);
- }
- /*****************************************************************************
- *
- * FUNCTION
- *
- * INPUT
- *
- * OUTPUT
- *
- * RETURNS
- *
- * AUTHOR
- *
- * DESCRIPTION
- *
- * CHANGES
- *
- ******************************************************************************/
- void Parse_Object_Mods (OBJECT *Object)
- {
- DBL Temp_Water_Level;
- DBL V1, V2;
- VECTOR Min, Max;
- VECTOR Local_Vector;
- MATRIX Local_Matrix;
- TRANSFORM Local_Trans;
- BBOX BBox;
- OBJECT *Sib;
- TEXTURE *Local_Texture;
- MATERIAL Local_Material;
- OBJECT *Temp1_Object;
- OBJECT *Temp2_Object;
- COLOUR Local_Colour;
- EXPECT
- CASE_COLOUR
- Parse_Colour (Local_Colour);
- if (opts.Language_Version < 1.5)
- if (Object->Texture != NULL)
- if (Object->Texture->Type == PLAIN_PATTERN)
- if (opts.Quality_Flags & Q_QUICKC)
- {
- Assign_Colour(Object->Texture->Pigment->Colour,Local_Colour);
- break; /* acts like END_CASE */
- }
- Warn(0.0, "Quick color belongs in texture. Color ignored.");
- END_CASE
- CASE (TRANSLATE_TOKEN)
- Parse_Vector (Local_Vector);
- Compute_Translation_Transform(&Local_Trans, Local_Vector);
- Translate_Object (Object, Local_Vector, &Local_Trans);
- END_CASE
- CASE (ROTATE_TOKEN)
- Parse_Vector (Local_Vector);
- Compute_Rotation_Transform(&Local_Trans, Local_Vector);
- Rotate_Object (Object, Local_Vector, &Local_Trans);
- END_CASE
- CASE (SCALE_TOKEN)
- Parse_Scale_Vector (Local_Vector);
- Compute_Scaling_Transform(&Local_Trans, Local_Vector);
- Scale_Object (Object, Local_Vector, &Local_Trans);
- END_CASE
- CASE (TRANSFORM_TOKEN)
- GET(TRANSFORM_ID_TOKEN)
- Transform_Object (Object, (TRANSFORM *)Token.Data);
- END_CASE
- CASE (MATRIX_TOKEN)
- Parse_Matrix (Local_Matrix);
- Compute_Matrix_Transform(&Local_Trans, Local_Matrix);
- Transform_Object (Object, &Local_Trans);
- END_CASE
- CASE (BOUNDED_BY_TOKEN)
- Parse_Begin ();
- if (Object->Bound != NULL)
- if (Object->Clip == Object->Bound)
- Error ("Cannot add bounds after linking bounds and clips.");
- EXPECT
- CASE (CLIPPED_BY_TOKEN)
- if (Object->Bound != NULL)
- Error ("Cannot link clips with previous bounds.");
- Object->Bound = Object->Clip;
- EXIT
- END_CASE
- OTHERWISE
- UNGET
- Temp1_Object = Temp2_Object = Parse_Bound_Clip ();
- while (Temp2_Object->Sibling != NULL)
- Temp2_Object = Temp2_Object->Sibling;
- Temp2_Object->Sibling = Object->Bound;
- Object->Bound = Temp1_Object;
- EXIT
- END_CASE
- END_EXPECT
- Parse_End ();
- END_CASE
- CASE (CLIPPED_BY_TOKEN)
- Parse_Begin ();
- if (Object->Clip != NULL)
- if (Object->Clip == Object->Bound)
- Error ("Cannot add clips after linking bounds and clips.");
- EXPECT
- CASE (BOUNDED_BY_TOKEN)
- if (Object->Clip != NULL)
- Error ("Cannot link bounds with previous clips.");
- Object->Clip = Object->Bound;
- EXIT
- END_CASE
- OTHERWISE
- UNGET
- Temp1_Object = Temp2_Object = Parse_Bound_Clip ();
- while (Temp2_Object->Sibling != NULL)
- Temp2_Object = Temp2_Object->Sibling;
- Temp2_Object->Sibling = Object->Clip;
- Object->Clip = Temp1_Object;
- /* Compute quadric bounding box before transformations. [DB 8/94] */
- if (Object->Methods == &Quadric_Methods)
- {
- Make_Vector(Min, -BOUND_HUGE, -BOUND_HUGE, -BOUND_HUGE);
- Make_Vector(Max, BOUND_HUGE, BOUND_HUGE, BOUND_HUGE);
- Compute_Quadric_BBox((QUADRIC *)Object, Min, Max);
- }
- EXIT
- END_CASE
- END_EXPECT
- Parse_End ();
- END_CASE
- CASE (TEXTURE_TOKEN)
- Object->Type |= TEXTURED_OBJECT;
- Parse_Begin ();
- Local_Texture = Parse_Texture ();
- Parse_End ();
- Link_Textures(&(Object->Texture), Local_Texture);
- END_CASE
- CASE (INTERIOR_TOKEN)
- Parse_Interior((INTERIOR **)(&Object->Interior));
- END_CASE
- CASE (MATERIAL_TOKEN)
- Local_Material.Texture = Object->Texture;
- Local_Material.Interior = Object->Interior;
- Parse_Material(&Local_Material);
- Object->Texture = Local_Material.Texture;
- Object->Interior = Local_Material.Interior;
- END_CASE
- CASE3 (PIGMENT_TOKEN, TNORMAL_TOKEN, FINISH_TOKEN)
- Object->Type |= TEXTURED_OBJECT;
- if (Object->Texture == NULL)
- Object->Texture = Copy_Textures(Default_Texture);
- else
- if (Object->Texture->Type != PLAIN_PATTERN)
- Link_Textures(&(Object->Texture), Copy_Textures(Default_Texture));
- UNGET
- EXPECT
- CASE (PIGMENT_TOKEN)
- Parse_Begin ();
- Parse_Pigment ( &(Object->Texture->Pigment) );
- Parse_End ();
- END_CASE
- CASE (TNORMAL_TOKEN)
- Parse_Begin ();
- Parse_Tnormal ( &(Object->Texture->Tnormal) );
- Parse_End ();
- END_CASE
- CASE (FINISH_TOKEN)
- Parse_Finish ( &(Object->Texture->Finish) );
- END_CASE
- OTHERWISE
- UNGET
- EXIT
- END_CASE
- END_EXPECT
- END_CASE
- CASE (INVERSE_TOKEN)
- if (Object->Type & PATCH_OBJECT)
- Warn (0.0, "Cannot invert a patch object.");
- Invert_Object (Object);
- END_CASE
- CASE (STURM_TOKEN)
- if (!(Object->Type & STURM_OK_OBJECT))
- Not_With ("sturm","this object");
- Bool_Flag (Object, STURM_FLAG, (Allow_Float(1.0) > 0.0));
- END_CASE
- CASE (WATER_LEVEL_TOKEN)
- if (!(Object->Type & WATER_LEVEL_OK_OBJECT))
- Not_With ("water_level","this object");
- Temp_Water_Level = Parse_Float();
- if (opts.Language_Version < 2.0)
- Temp_Water_Level /=256.0;
- ((HFIELD *) Object)->bounding_box->bounds[0][Y] = 65536.0 * Temp_Water_Level;
- END_CASE
- CASE (SMOOTH_TOKEN)
- if (!(Object->Type & SMOOTH_OK_OBJECT))
- Not_With ("smooth","this object");
- Set_Flag(Object, SMOOTHED_FLAG);
- Object->Type |= DOUBLE_ILLUMINATE;
- END_CASE
- CASE (NO_SHADOW_TOKEN)
- Set_Flag(Object, NO_SHADOW_FLAG);
- END_CASE
- CASE (LIGHT_SOURCE_TOKEN)
- Error("Light source must be defined using new syntax.");
- END_CASE
- CASE(HIERARCHY_TOKEN)
- if (!(Object->Type & HIERARCHY_OK_OBJECT))
- Not_With ("hierarchy", "this object");
- Bool_Flag (Object, HIERARCHY_FLAG, (Allow_Float(1.0) > 0.0));
- END_CASE
- CASE(HOLLOW_TOKEN)
- Bool_Flag (Object, HOLLOW_FLAG, (Allow_Float(1.0) > 0.0));
- Set_Flag (Object, HOLLOW_SET_FLAG);
- if ((Object->Methods == &CSG_Intersection_Methods) ||
- (Object->Methods == &CSG_Merge_Methods) ||
- (Object->Methods == &CSG_Union_Methods))
- {
- Set_CSG_Children_Flag(Object, Test_Flag(Object, HOLLOW_FLAG), HOLLOW_FLAG, HOLLOW_SET_FLAG);
- }
- END_CASE
- OTHERWISE
- UNGET
- EXIT
- END_CASE
- END_EXPECT
- /*
- * Assign bounding objects' bounding box to object
- * if object's bounding box is larger. [DB 9/94]
- */
- if (Object->Bound != NULL)
- {
- /* Get bounding objects bounding box. */
- Make_Vector(Min, -BOUND_HUGE, -BOUND_HUGE, -BOUND_HUGE);
- Make_Vector(Max, BOUND_HUGE, BOUND_HUGE, BOUND_HUGE);
- for (Sib = Object->Bound; Sib != NULL; Sib = Sib->Sibling)
- {
- if (!Test_Flag(Sib, INVERTED_FLAG))
- {
- Min[X] = max(Min[X], Sib->BBox.Lower_Left[X]);
- Min[Y] = max(Min[Y], Sib->BBox.Lower_Left[Y]);
- Min[Z] = max(Min[Z], Sib->BBox.Lower_Left[Z]);
- Max[X] = min(Max[X], Sib->BBox.Lower_Left[X] + Sib->BBox.Lengths[X]);
- Max[Y] = min(Max[Y], Sib->BBox.Lower_Left[Y] + Sib->BBox.Lengths[Y]);
- Max[Z] = min(Max[Z], Sib->BBox.Lower_Left[Z] + Sib->BBox.Lengths[Z]);
- }
- }
- Make_BBox_from_min_max(BBox, Min, Max);
- /* Get bounding boxes' volumes. */
- BOUNDS_VOLUME(V1, BBox);
- BOUNDS_VOLUME(V2, Object->BBox);
- if (V1 < V2)
- {
- Object->BBox = BBox;
- }
- }
- /*
- * Assign clipping objects' bounding box to object
- * if object's bounding box is larger. [DB 9/94]
- */
- if (Object->Clip != NULL)
- {
- /* Get clipping objects bounding box. */
- Make_Vector(Min, -BOUND_HUGE, -BOUND_HUGE, -BOUND_HUGE);
- Make_Vector(Max, BOUND_HUGE, BOUND_HUGE, BOUND_HUGE);
- for (Sib = Object->Clip; Sib != NULL; Sib = Sib->Sibling)
- {
- if (!Test_Flag(Sib, INVERTED_FLAG))
- {
- Min[X] = max(Min[X], Sib->BBox.Lower_Left[X]);
- Min[Y] = max(Min[Y], Sib->BBox.Lower_Left[Y]);
- Min[Z] = max(Min[Z], Sib->BBox.Lower_Left[Z]);
- Max[X] = min(Max[X], Sib->BBox.Lower_Left[X] + Sib->BBox.Lengths[X]);
- Max[Y] = min(Max[Y], Sib->BBox.Lower_Left[Y] + Sib->BBox.Lengths[Y]);
- Max[Z] = min(Max[Z], Sib->BBox.Lower_Left[Z] + Sib->BBox.Lengths[Z]);
- }
- }
- Make_BBox_from_min_max(BBox, Min, Max);
- /* Get bounding boxes' volumes. */
- BOUNDS_VOLUME(V1, BBox);
- BOUNDS_VOLUME(V2, Object->BBox);
- if (V1 < V2)
- {
- Object->BBox = BBox;
- }
- }
- Parse_End ();
- }
- /*****************************************************************************
- *
- * FUNCTION
- *
- * INPUT
- *
- * OUTPUT
- *
- * RETURNS
- *
- * AUTHOR
- *
- * DESCRIPTION
- *
- * CHANGES
- *
- ******************************************************************************/
- static OBJECT *Parse_Sphere()
- {
- SPHERE *Object;
- Parse_Begin();
- if ((Object = (SPHERE *)Parse_Object_Id()) != NULL)
- {
- return ((OBJECT *) Object);
- }
- Object = Create_Sphere();
- Parse_Vector(Object->Center);
- Parse_Comma();
- Object->Radius = Parse_Float();
- Compute_Sphere_BBox(Object);
- Parse_Object_Mods((OBJECT *)Object);
- return((OBJECT *)Object);
- }
- /*****************************************************************************
- *
- * FUNCTION
- *
- * INPUT
- *
- * OUTPUT
- *
- * RETURNS
- *
- * AUTHOR
- *
- * DESCRIPTION
- *
- * CHANGES
- *
- ******************************************************************************/
- static
- OBJECT *Parse_Plane ()
- {
- DBL len;
- PLANE *Object;
- Parse_Begin ();
- if ( (Object = (PLANE *)Parse_Object_Id()) != NULL)
- return ((OBJECT *) Object);
- Object = Create_Plane();
- Parse_Vector(Object->Normal_Vector); Parse_Comma();
- VLength(len, Object->Normal_Vector);
- if (len < EPSILON)
- {
- Error("Degenerate plane normal.");
- }
- VInverseScaleEq(Object->Normal_Vector, len);
- Object->Distance = -Parse_Float();
- Compute_Plane_BBox(Object);
- Parse_Object_Mods ((OBJECT *)Object);
- return ((OBJECT *) Object);
- }
- /*****************************************************************************
- *
- * FUNCTION
- *
- * INPUT
- *
- * OUTPUT
- *
- * RETURNS
- *
- * AUTHOR
- *
- * DESCRIPTION
- *
- * CHANGES
- *
- ******************************************************************************/
- static
- OBJECT *Parse_HField ()
- {
- HFIELD *Object;
- VECTOR Local_Vector;
- IMAGE *Image;
- Parse_Begin ();
- if ( (Object = (HFIELD *)Parse_Object_Id()) != NULL)
- return ((OBJECT *) Object);
- Object = Create_HField();
- Image = Parse_Image (HF_FILE);
- Image->Use_Colour_Flag = FALSE;
- Make_Vector(Object->bounding_box->bounds[0], 0.0, 0.0, 0.0);
- if (Image->File_Type == POT_FILE)
- {
- Object->bounding_box->bounds[1][X] = Image->width/2.0 - 1.0;
- }
- else
- {
- Object->bounding_box->bounds[1][X] = Image->width - 1.0;
- }
- Object->bounding_box->bounds[1][Y] = 65536.0;
- Object->bounding_box->bounds[1][Z] = Image->height - 1.0;
- Make_Vector(Local_Vector,
- 1.0 / (Object->bounding_box->bounds[1][X]),
- 1.0 / (Object->bounding_box->bounds[1][Y]),
- 1.0 / (Object->bounding_box->bounds[1][Z]));
- Compute_Scaling_Transform(Object->Trans, Local_Vector);
- Parse_Object_Mods ((OBJECT *)Object);
- Compute_HField(Object, Image);
- Compute_HField_BBox(Object);
- Destroy_Image (Image);
- return ((OBJECT *) Object);
- }
- /*****************************************************************************
- *
- * FUNCTION
- *
- * INPUT
- *
- * OUTPUT
- *
- * RETURNS
- *
- * AUTHOR
- *
- * DESCRIPTION
- *
- * CHANGES
- *
- ******************************************************************************/
- static OBJECT *Parse_Triangle()
- {
- TRIANGLE *Object;
- Parse_Begin();
- if ((Object = (TRIANGLE *)Parse_Object_Id()) != NULL)
- {
- return((OBJECT *) Object);
- }
- Object = Create_Triangle();
- Parse_Vector(Object->P1); Parse_Comma();
- Parse_Vector(Object->P2); Parse_Comma();
- Parse_Vector(Object->P3);
- /* Note that Compute_Triangle also computes the bounding box. */
- if (!Compute_Triangle(Object, FALSE))
- {
- Warn(0.0, "Degenerate triangle. Please remove.");
- }
- Parse_Object_Mods((OBJECT *)Object);
- return((OBJECT *)Object);
- }
- /*****************************************************************************
- *
- * FUNCTION
- *
- * INPUT
- *
- * OUTPUT
- *
- * RETURNS
- *
- * AUTHOR
- *
- * DESCRIPTION
- *
- * CHANGES
- *
- ******************************************************************************/
- static
- OBJECT *Parse_Smooth_Triangle ()
- {
- SMOOTH_TRIANGLE *Object;
- short degen;
- DBL vlen;
- degen=FALSE;
- Parse_Begin ();
- if ( (Object = (SMOOTH_TRIANGLE *)Parse_Object_Id()) != NULL)
- return ((OBJECT *) Object);
- Object = Create_Smooth_Triangle();
- Parse_Vector (Object->P1); Parse_Comma();
- Parse_Vector (Object->N1); Parse_Comma();
- VLength(vlen,Object->N1);
- if (vlen == 0.0)
- degen=TRUE;
- else
- VNormalize (Object->N1, Object->N1);
- Parse_Vector (Object->P2); Parse_Comma();
- Parse_Vector (Object->N2); Parse_Comma();
- VLength(vlen,Object->N2);
- if (vlen == 0.0)
- degen=TRUE;
- else
- VNormalize (Object->N2, Object->N2);
- Parse_Vector (Object->P3); Parse_Comma();
- Parse_Vector (Object->N3);
- VLength(vlen,Object->N3);
- if (vlen == 0.0)
- degen=TRUE;
- else
- VNormalize (Object->N3, Object->N3);
- if (!degen)
- {
- degen=!Compute_Triangle ((TRIANGLE *) Object,TRUE);
- }
- if (degen)
- {
- Warn(0.0, "Degenerate triangle. Please remove.");
- }
- Compute_Triangle_BBox((TRIANGLE *)Object);
- Parse_Object_Mods ((OBJECT *)Object);
- return ((OBJECT *) Object);
- }
- /*****************************************************************************
- *
- * FUNCTION
- *
- * INPUT
- *
- * OUTPUT
- *
- * RETURNS
- *
- * AUTHOR
- *
- * DESCRIPTION
- *
- * CHANGES
- *
- ******************************************************************************/
- static
- OBJECT *Parse_Quadric ()
- {
- VECTOR Min, Max;
- QUADRIC *Object;
- Parse_Begin ();
- if ( (Object = (QUADRIC *)Parse_Object_Id()) != NULL)
- return ((OBJECT *) Object);
- Object = Create_Quadric();
- Parse_Vector(Object->Square_Terms); Parse_Comma();
- Parse_Vector(Object->Mixed_Terms); Parse_Comma();
- Parse_Vector(Object->Terms); Parse_Comma();
- Object->Constant = Parse_Float();
- Make_Vector(Min, -BOUND_HUGE, -BOUND_HUGE, -BOUND_HUGE);
- Make_Vector(Max, BOUND_HUGE, BOUND_HUGE, BOUND_HUGE);
- Compute_Quadric_BBox(Object, Min, Max);
- Parse_Object_Mods ((OBJECT *)Object);
- return ((OBJECT *) Object);
- }
- /*****************************************************************************
- *
- * FUNCTION
- *
- * INPUT
- *
- * OUTPUT
- *
- * RETURNS
- *
- * AUTHOR
- *
- * DESCRIPTION
- *
- * CHANGES
- *
- ******************************************************************************/
- static
- OBJECT *Parse_Box ()
- {
- BOX *Object;
- DBL temp;
- Parse_Begin ();
- if ( (Object = (BOX *)Parse_Object_Id()) != NULL)
- return ((OBJECT *) Object);
- Object = Create_Box();
- Parse_Vector(Object->bounds[0]); Parse_Comma();
- Parse_Vector(Object->bounds[1]);
- if (Object->bounds[0][X] > Object->bounds[1][X]) {
- temp = Object->bounds[0][X];
- Object->bounds[0][X] = Object->bounds[1][X];
- Object->bounds[1][X] = temp;
- }
- if (Object->bounds[0][Y] > Object->bounds[1][Y]) {
- temp = Object->bounds[0][Y];
- Object->bounds[0][Y] = Object->bounds[1][Y];
- Object->bounds[1][Y] = temp;
- }
- if (Object->bounds[0][Z] > Object->bounds[1][Z]) {
- temp = Object->bounds[0][Z];
- Object->bounds[0][Z] = Object->bounds[1][Z];
- Object->bounds[1][Z] = temp;
- }
- Compute_Box_BBox(Object);
- Parse_Object_Mods ((OBJECT *)Object);
- return ((OBJECT *) Object);
- }
- /*****************************************************************************
- *
- * FUNCTION
- *
- * INPUT
- *
- * OUTPUT
- *
- * RETURNS
- *
- * AUTHOR
- *
- * DESCRIPTION
- *
- * CHANGES
- *
- ******************************************************************************/
- static
- OBJECT *Parse_Disc ()
- {
- DISC *Object;
- DBL tmpf;
- Parse_Begin ();
- if ( (Object = (DISC *)Parse_Object_Id()) != NULL)
- return ((OBJECT *) Object);
- Object = Create_Disc();
- Parse_Vector(Object->center); Parse_Comma ();
- Parse_Vector(Object->normal); Parse_Comma ();
- VNormalize(Object->normal, Object->normal);
- tmpf = Parse_Float(); Parse_Comma ();
- Object->oradius2 = tmpf * tmpf;
- EXPECT
- CASE_FLOAT
- tmpf = Parse_Float();
- Object->iradius2 = tmpf * tmpf;
- END_CASE
- OTHERWISE
- UNGET
- EXIT
- END_CASE
- END_EXPECT
- /* Calculate info needed for ray-disc intersections */
- VDot(tmpf, Object->center, Object->normal);
- Object->d = -tmpf;
- Compute_Disc(Object);
- Parse_Object_Mods ((OBJECT *)Object);
- return ((OBJECT *) Object);
- }
- /*****************************************************************************
- *
- * FUNCTION
- *
- * INPUT
- *
- * OUTPUT
- *
- * RETURNS
- *
- * AUTHOR
- *
- * DESCRIPTION
- *
- * CHANGES
- *
- ******************************************************************************/
- static
- OBJECT *Parse_Cylinder ()
- {
- CONE *Object;
- Parse_Begin ();
- if ( (Object = (CONE *)Parse_Object_Id()) != NULL)
- return ((OBJECT *) Object);
- Object = Create_Cylinder();
- Parse_Vector(Object->apex); Parse_Comma ();
- Parse_Vector(Object->base); Parse_Comma ();
- Object->apex_radius = Parse_Float();
- Object->base_radius = Object->apex_radius;
- EXPECT
- CASE(OPEN_TOKEN)
- Clear_Flag(Object, CLOSED_FLAG);
- EXIT
- END_CASE
- OTHERWISE
- UNGET
- EXIT
- END_CASE
- END_EXPECT
- Compute_Cylinder_Data((OBJECT *)Object);
- Compute_Cone_BBox(Object);
- Parse_Object_Mods ((OBJECT *)Object);
- return ((OBJECT *) Object);
- }
- /*****************************************************************************
- *
- * FUNCTION
- *
- * INPUT
- *
- * OUTPUT
- *
- * RETURNS
- *
- * AUTHOR
- *
- * DESCRIPTION
- *
- * CHANGES
- *
- ******************************************************************************/
- static
- OBJECT *Parse_Cone ()
- {
- CONE *Object;
- Parse_Begin ();
- if ( (Object = (CONE *)Parse_Object_Id()) != NULL)
- return ((OBJECT *) Object);
- Object = Create_Cone();
- Parse_Vector(Object->apex); Parse_Comma ();
- Object->apex_radius = Parse_Float(); Parse_Comma ();
- Parse_Vector(Object->base); Parse_Comma ();
- Object->base_radius = Parse_Float();
- EXPECT
- CASE(OPEN_TOKEN)
- Clear_Flag(Object, CLOSED_FLAG);
- EXIT
- END_CASE
-
- OTHERWISE
- UNGET
- EXIT
- END_CASE
- END_EXPECT
- /* Compute run-time values for the cone */
- Compute_Cone_Data((OBJECT *)Object);
- Compute_Cone_BBox(Object);
- Parse_Object_Mods ((OBJECT *)Object);
- return ((OBJECT *) Object);
- }
- /*****************************************************************************
- *
- * FUNCTION
- *
- * Parse_Blob_Element_Mods
- *
- * INPUT
- *
- * OUTPUT
- *
- * RETURNS
- *
- * AUTHOR
- *
- * Dieter Bayer
- *
- * DESCRIPTION
- *
- * -
- *
- * CHANGES
- *
- * Sep 1994 : Creation.
- *
- ******************************************************************************/
- static void Parse_Blob_Element_Mods(BLOB_ELEMENT *Element)
- {
- VECTOR Local_Vector;
- MATRIX Local_Matrix;
- TRANSFORM Local_Trans;
- TEXTURE *Local_Texture;
- EXPECT
- CASE (TRANSLATE_TOKEN)
- Parse_Vector (Local_Vector);
- Translate_Blob_Element (Element, Local_Vector);
- END_CASE
- CASE (ROTATE_TOKEN)
- Parse_Vector (Local_Vector);
- Rotate_Blob_Element (Element, Local_Vector);
- END_CASE
- CASE (SCALE_TOKEN)
- Parse_Scale_Vector (Local_Vector);
- Scale_Blob_Element (Element, Local_Vector);
- END_CASE
- CASE (TRANSFORM_TOKEN)
- GET(TRANSFORM_ID_TOKEN)
- Transform_Blob_Element (Element, (TRANSFORM *)Token.Data);
- END_CASE
- CASE (MATRIX_TOKEN)
- Parse_Matrix (Local_Matrix);
- Compute_Matrix_Transform(&Local_Trans, Local_Matrix);
- Transform_Blob_Element (Element, &Local_Trans);
- END_CASE
- CASE (TEXTURE_TOKEN)
- Parse_Begin ();
- Local_Texture = Parse_Texture();
- Parse_End ();
- Link_Textures(&Element->Texture, Local_Texture);
- END_CASE
- CASE3 (PIGMENT_TOKEN, TNORMAL_TOKEN, FINISH_TOKEN)
- if (Element->Texture == NULL)
- {
- Element->Texture = Copy_Textures(Default_Texture);
- }
- else
- {
- if (Element->Texture->Type != PLAIN_PATTERN)
- {
- Link_Textures(&Element->Texture, Copy_Textures(Default_Texture));
- }
- }
- UNGET
- EXPECT
- CASE (PIGMENT_TOKEN)
- Parse_Begin ();
- Parse_Pigment(&Element->Texture->Pigment);
- Parse_End ();
- END_CASE
- CASE (TNORMAL_TOKEN)
- Parse_Begin ();
- Parse_Tnormal(&Element->Texture->Tnormal);
- Parse_End ();
- END_CASE
- CASE (FINISH_TOKEN)
- Parse_Finish(&Element->Texture->Finish);
- END_CASE
- OTHERWISE
- UNGET
- EXIT
- END_CASE
- END_EXPECT
- END_CASE
- OTHERWISE
- UNGET
- EXIT
- END_CASE
- END_EXPECT
- Parse_End();
- /* Postprocess to make sure that HAS_FILTER will be set correctly. */
- Post_Textures(Element->Texture);
- }
- /*****************************************************************************
- *
- * FUNCTION
- *
- * Parse_Blob
- *
- * INPUT
- *
- * OUTPUT
- *
- * RETURNS
- *
- * AUTHOR
- *
- * Dieter Bayer
- *
- * DESCRIPTION
- *
- * -
- *
- * CHANGES
- *
- * Jul 1994 : Creation.
- *
- ******************************************************************************/
- static OBJECT *Parse_Blob()
- {
- int npoints;
- DBL threshold;
- VECTOR Axis, Base, Apex;
- BLOB *Object;
- BLOB_LIST *blob_components, *blob_component;
- Parse_Begin();
- if ((Object = (BLOB *)Parse_Object_Id()) != NULL)
- {
- return ((OBJECT *) Object);
- }
- Object = Create_Blob();
- blob_components = NULL;
- npoints = 0;
- threshold = 1.0;
- EXPECT
- CASE (THRESHOLD_TOKEN)
- threshold = Parse_Float();
- END_CASE
- /*************************************************************************
- * Read sperical component (old syntax).
- *************************************************************************/
- CASE (COMPONENT_TOKEN)
- blob_component = Create_Blob_List_Element();
- blob_component->elem.Type = BLOB_SPHERE;
- blob_component->elem.c[2] = Parse_Float();
- Parse_Comma();
- blob_component->elem.rad2 = Parse_Float();
- Parse_Comma();
- blob_component->elem.rad2 = Sqr(blob_component->elem.rad2);
- Parse_Vector(blob_component->elem.O);
- /* Next component. */
- blob_component->next = blob_components;
- blob_components = blob_component;
- npoints++;
- END_CASE
- /*************************************************************************
- * Read sperical component (new syntax).
- *************************************************************************/
- CASE (SPHERE_TOKEN)
- blob_component = Create_Blob_List_Element();
- blob_component->elem.Type = BLOB_SPHERE;
- Parse_Begin();
- Parse_Vector(blob_component->elem.O);
- Parse_Comma();
- blob_component->elem.rad2 = Parse_Float();
- blob_component->elem.rad2 = Sqr(blob_component->elem.rad2);
- Parse_Comma();
- ALLOW(STRENGTH_TOKEN)
- blob_component->elem.c[2] = Parse_Float();
- Parse_Blob_Element_Mods(&blob_component->elem);
- /* Next component. */
- blob_component->next = blob_components;
- blob_components = blob_component;
- npoints++;
- END_CASE
- /*************************************************************************
- * Read cylindrical component.
- *************************************************************************/
- CASE (CYLINDER_TOKEN)
- blob_component = Create_Blob_List_Element();
- blob_component->elem.Type = BLOB_CYLINDER;
- blob_component->elem.Trans = Create_Transform();
- Parse_Begin();
- Parse_Vector(Base);
- Parse_Comma();
- Parse_Vector(Apex);
- Parse_Comma();
- blob_component->elem.rad2 = Parse_Float();
- blob_component->elem.rad2 = Sqr(blob_component->elem.rad2);
- Parse_Comma();
- ALLOW(STRENGTH_TOKEN)
- blob_component->elem.c[2] = Parse_Float();
- /* Calculate cylinder's coordinate system. */
- VSub(Axis, Apex, Base);
- VLength(blob_component->elem.len, Axis);
- if (blob_component->elem.len < EPSILON)
- {
- Error("Degenerate cylindrical component in blob.\n");
- }
- VInverseScaleEq(Axis, blob_component->elem.len);
- Compute_Coordinate_Transform(blob_component->elem.Trans, Base, Axis, 1.0, 1.0);
- Parse_Blob_Element_Mods(&blob_component->elem);
- /* Next component. */
- blob_component->next = blob_components;
- blob_components = blob_component;
- npoints++;
- END_CASE
- OTHERWISE
- UNGET
- EXIT
- END_CASE
- END_EXPECT
- Create_Blob_Element_Texture_List(Object, blob_components, npoints);
- Parse_Object_Mods((OBJECT *)Object);
- /* The blob's texture has to be processed before Make_Blob() is called. */
- Post_Textures(Object->Texture);
-
- /* Finally, process the information */
- Make_Blob(Object, threshold, blob_components, npoints);
- return((OBJECT *)Object);
- }
- /*****************************************************************************
- *
- * FUNCTION
- *
- * Parse_Julia_Fractal
- *
- * INPUT None
- *
- * OUTPUT Fractal Objecstructure filledt
- *
- * RETURNS
- *
- * OBJECT * -
- *
- * AUTHOR
- *
- * Pascal Massimino
- *
- * DESCRIPTION
- *
- * -
- *
- * CHANGES
- *
- * Dec 1994 : Adopted to version 3.0. [DB]
- * Sept 1995 : Total rewrite for new syntax [TW]
- *
- ******************************************************************************/
- static OBJECT *Parse_Julia_Fractal ()
- {
- FRACTAL *Object;
- DBL P;
- Parse_Begin();
- if ( (Object = (FRACTAL *)Parse_Object_Id()) != NULL)
- return((OBJECT *)Object);
- Object = Create_Fractal();
- Parse_Vector4D(Object->Julia_Parm);
- EXPECT
- CASE(MAX_ITERATION_TOKEN)
- Object->n = (int)floor(Parse_Float());
- if (Object->n <= 0)
- {
- Object->n = 1;
- }
- END_CASE
- CASE(SLICE_TOKEN)
- Parse_Vector4D(Object->Slice);
- Parse_Comma();
- Object->SliceDist = Parse_Float();
- /* normalize slice vector */
- V4D_Dot(P,Object->Slice, Object->Slice);
- if (fabs(P) < EPSILON)
- {
- Error("Slice vector is zero.\n");
- }
- if (fabs(Object->Slice[T]) < EPSILON)
- {
- Error("Slice t component is zero.\n");
- }
- P = sqrt(P);
- V4D_InverseScaleEq(Object->Slice, P);
- END_CASE
- CASE(PRECISION_TOKEN)
- P = Parse_Float();
- if ( P < 1.0 )
- {
- P = 1.0;
- }
- Object->Precision = 1.0 / P;
- END_CASE
-
- CASE(FLOAT_FUNCT_TOKEN)
- switch(Token.Function_Id)
- {
- case EXP_TOKEN:
- Object->Sub_Type = EXP_STYPE;
- break;
- case LOG_TOKEN:
- Object->Sub_Type = LOG_STYPE;
- break;
- case SIN_TOKEN:
- Object->Sub_Type = SIN_STYPE;
- break;
- case ASIN_TOKEN:
- Object->Sub_Type = ASIN_STYPE;
- break;
- case COS_TOKEN:
- Object->Sub_Type = COS_STYPE;
- break;
- case ACOS_TOKEN:
- Object->Sub_Type = ACOS_STYPE;
- break;
- default: Parse_Error_Str ("fractal keyword");
- }
- END_CASE
- /* if any of the next become supported by the expression parser,
- * then their handling would need to move above to the FUNC_TOKEN
- * case above.
- */
- CASE(ATAN_TOKEN)
- Object->Sub_Type = ATAN_STYPE;
- END_CASE
- CASE(COSH_TOKEN)
- Object->Sub_Type = COSH_STYPE;
- END_CASE
- CASE(SINH_TOKEN)
- Object->Sub_Type = SINH_STYPE;
- END_CASE
- CASE(TANH_TOKEN)
- Object->Sub_Type = TANH_STYPE;
- END_CASE
- CASE(ATANH_TOKEN)
- Object->Sub_Type = ATANH_STYPE;
- END_CASE
- CASE(ACOSH_TOKEN)
- Object->Sub_Type = ACOSH_STYPE;
- END_CASE
- CASE(ASINH_TOKEN)
- Object->Sub_Type = ASINH_STYPE;
- END_CASE
- CASE(SQR_TOKEN)
- Object->Sub_Type = SQR_STYPE;
- END_CASE
- CASE(PWR_TOKEN)
- Object->Sub_Type = PWR_STYPE;
- Parse_Float_Param2(&Object->exponent.x,&Object->exponent.y);
- END_CASE
- CASE(CUBE_TOKEN)
- Object->Sub_Type = CUBE_STYPE;
- END_CASE
- CASE(RECIPROCAL_TOKEN)
- Object->Sub_Type = RECIPROCAL_STYPE;
- END_CASE
- CASE(HYPERCOMPLEX_TOKEN)
- Object->Algebra = HYPERCOMPLEX_TYPE;
- END_CASE
- CASE(QUATERNION_TOKEN)
- Object->Algebra = QUATERNION_TYPE;
- END_CASE
- OTHERWISE
- UNGET
- EXIT
- END_CASE
- END_EXPECT
- Parse_Object_Mods((OBJECT *)Object);
- SetUp_Fractal(Object);
- return((OBJECT *)Object);
- }
- /*****************************************************************************
- *
- * FUNCTION
- *
- * Parse_Polygon
- *
- * INPUT
- *
- * OUTPUT
- *
- * RETURNS
- *
- * OBJECT * -
- *
- * AUTHOR
- *
- * Dieter Bayer
- *
- * DESCRIPTION
- *
- * -
- *
- * CHANGES
- *
- * May 1994 : Creation.
- *
- * Oct 1994 : Modified to use new polygon data structure. [DB]
- *
- ******************************************************************************/
- static OBJECT *Parse_Polygon()
- {
- int i, closed = FALSE;
- int Number;
- POLYGON *Object;
- VECTOR *Points, P;
- Parse_Begin();
- if ((Object = (POLYGON *)Parse_Object_Id()) != NULL)
- {
- return((OBJECT *) Object);
- }
- Object = Create_Polygon();
- Number = (int)Parse_Float();
- if (Number < 3)
- {
- Error("Polygon needs at least three points.");
- }
- Points = (VECTOR *)POV_MALLOC((Number+1)*sizeof(VECTOR), "temporary polygon points");
- for (i = 0; i < Number; i++)
- {
- Parse_Comma();
- Parse_Vector(Points[i]);
- }
- /* Check for closed polygons. */
- Assign_Vector(P, Points[0]);
- for (i = 1; i < Number; i++)
- {
- closed = FALSE;
- if ((fabs(P[X] - Points[i][X]) < EPSILON) &&
- (fabs(P[Y] - Points[i][Y]) < EPSILON) &&
- (fabs(P[Z] - Points[i][Z]) < EPSILON))
- {
- i++;
- if (i < Number)
- {
- Assign_Vector(P, Points[i]);
- }
- closed = TRUE;
- }
- }
- if (!closed)
- {
- Warn(0.0, "Polygon not closed. Closing it.");
- Assign_Vector(Points[Number], P);
- Number++;
- }
- Compute_Polygon(Object, Number, Points);
- POV_FREE (Points);
- Parse_Object_Mods ((OBJECT *)Object);
- return((OBJECT *) Object);
- }
- /*****************************************************************************
- *
- * FUNCTION
- *
- * Parse_Prism
- *
- * INPUT
- *
- * OUTPUT
- *
- * RETURNS
- *
- * OBJECT * -
- *
- * AUTHOR
- *
- * Dieter Bayer
- *
- * DESCRIPTION
- *
- * -
- *
- * CHANGES
- *
- * May 1994 : Creation.
- *
- ******************************************************************************/
- static OBJECT *Parse_Prism()
- {
- int i, closed = FALSE;
- DBL h;
- PRISM *Object;
- UV_VECT *Points, P;
- Parse_Begin();
- if ((Object = (PRISM *)Parse_Object_Id()) != NULL)
- {
- return((OBJECT *) Object);
- }
- Object = Create_Prism();
- /*
- * Determine kind of spline used (linear, quadratic, cubic)
- * and type of sweeping (linear, conic).
- */
- EXPECT
- CASE(LINEAR_SPLINE_TOKEN)
- Object->Spline_Type = LINEAR_SPLINE;
- END_CASE
- CASE(QUADRATIC_SPLINE_TOKEN)
- Object->Spline_Type = QUADRATIC_SPLINE;
- END_CASE
- CASE(CUBIC_SPLINE_TOKEN)
- Object->Spline_Type = CUBIC_SPLINE;
- END_CASE
- CASE(BEZIER_SPLINE_TOKEN)
- Object->Spline_Type = BEZIER_SPLINE;
- END_CASE
- CASE(LINEAR_SWEEP_TOKEN)
- Object->Sweep_Type = LINEAR_SWEEP;
- END_CASE
- CASE(CONIC_SWEEP_TOKEN)
- Object->Sweep_Type = CONIC_SWEEP;
- END_CASE
- OTHERWISE
- UNGET
- EXIT
- END_CASE
- END_EXPECT
- /* Read prism heights. */
- Object->Height1 = Parse_Float(); Parse_Comma();
- Object->Height2 = Parse_Float(); Parse_Comma();
- if (Object->Height1 > Object->Height2)
- {
- h = Object->Height1;
- Object->Height1 = Object->Height2;
- Object->Height2 = h;
- }
- /* Get number of points = number of segments. */
- Object->Number = (int)Parse_Float();
- switch (Object->Spline_Type)
- {
- case LINEAR_SPLINE :
- if (Object->Number < 3)
- {
- Error("Prism with linear splines must have at least three points.");
- }
- break;
- case QUADRATIC_SPLINE :
- if (Object->Number < 5)
- {
- Error("Prism with quadratic splines must have at least five points.");
- }
- break;
- case CUBIC_SPLINE :
- if (Object->Number < 6)
- {
- Error("Prism with cubic splines must have at least six points.");
- }
- break;
- case BEZIER_SPLINE :
- if ((Object->Number & 3) != 0)
- {
- Error("Prism with Bezier splines must have four points per segment.");
- }
- break;
- }
- /* Allocate Object->Number points for the prism. */
- Points = (UV_VECT *)POV_MALLOC((Object->Number+1) * sizeof(UV_VECT), "temporary prism points");
- /* Read points (x, y : coordinate of 2d point; z : not used). */
- for (i = 0; i < Object->Number; i++)
- {
- Parse_Comma();
- Parse_UV_Vect(Points[i]);
- }
- /* Closed or not closed that's the question. */
- EXPECT
- CASE(OPEN_TOKEN)
- Clear_Flag(Object, CLOSED_FLAG);
- EXIT
- END_CASE
- OTHERWISE
- UNGET
- EXIT
- END_CASE
- END_EXPECT
- /* Check for closed prism. */
- if ((Object->Spline_Type == LINEAR_SPLINE) ||
- (Object->Spline_Type == QUADRATIC_SPLINE) ||
- (Object->Spline_Type == CUBIC_SPLINE))
- {
- switch (Object->Spline_Type)
- {
- case LINEAR_SPLINE :
- i = 1;
- Assign_UV_Vect(P, Points[0]);
- break;
- case QUADRATIC_SPLINE :
- case CUBIC_SPLINE :
- i = 2;
- Assign_UV_Vect(P, Points[1]);
- break;
- }
- for ( ; i < Object->Number; i++)
- {
- closed = FALSE;
- if ((fabs(P[X] - Points[i][X]) < EPSILON) &&
- (fabs(P[Y] - Points[i][Y]) < EPSILON))
- {
- switch (Object->Spline_Type)
- {
- case LINEAR_SPLINE :
- i++;
- if (i < Object->Number)
- {
- Assign_UV_Vect(P, Points[i]);
- }
- break;
- case QUADRATIC_SPLINE :
- i += 2;
- if (i < Object->Number)
- {
- Assign_UV_Vect(P, Points[i]);
- }
- break;
- case CUBIC_SPLINE :
- i += 3;
- if (i < Object->Number)
- {
- Assign_UV_Vect(P, Points[i]);
- }
- break;
- }
- closed = TRUE;
- }
- }
- }
- else
- {
- closed = TRUE;
- for (i = 0; i < Object->Number; i += 4)
- {
- if ((fabs(Points[i][X] - Points[(i-1+Object->Number) % Object->Number][X]) > EPSILON) ||
- (fabs(Points[i][Y] - Points[(i-1+Object->Number) % Object->Number][Y]) > EPSILON))
- {
- closed = FALSE;
- break;
- }
- }
- }
- if (!closed)
- {
- if (Object->Spline_Type == LINEAR_SPLINE)
- {
- Assign_UV_Vect(Points[Object->Number], P);
- Object->Number++;
- Warn(0.0, "Linear prism not closed. Closing it.");
- }
- else
- {
- Set_Flag(Object, DEGENERATE_FLAG);
- Warn(0.0, "Prism not closed. Ignoring it.");
- }
- }
- /* Compute spline segments. */
- Compute_Prism(Object, Points);
- /* Compute bounding box. */
- Compute_Prism_BBox(Object);
- /* Parse object's modifiers. */
- Parse_Object_Mods((OBJECT *)Object);
- /* Destroy temporary points. */
- POV_FREE (Points);
- return((OBJECT *) Object);
- }
- /*****************************************************************************
- *
- * FUNCTION
- *
- * Parse_Sor
- *
- * INPUT
- *
- * OUTPUT
- *
- * RETURNS
- *
- * OBJECT * -
- *
- * AUTHOR
- *
- * Dieter Bayer
- *
- * DESCRIPTION
- *
- * Read a surface of revolution primitive.
- *
- * CHANGES
- *
- * May 1994 : Creation.
- *
- ******************************************************************************/
- static OBJECT *Parse_Sor()
- {
- int i;
- SOR *Object;
- UV_VECT *Points;
- Parse_Begin();
- if ((Object = (SOR *)Parse_Object_Id()) != NULL)
- {
- return((OBJECT *)Object);
- }
- Object = Create_Sor();
- /* Get number of points. */
- Object->Number = (int)Parse_Float();
- if (Object->Number <4)
- {
- Error("Surface of revolution must have at least four points.");
- }
- /* Get temporary points describing the rotated curve. */
- Points = (UV_VECT *)POV_MALLOC(Object->Number*sizeof(UV_VECT), "temporary surface of revolution points");
- /* Read points (x : radius; y : height; z : not used). */
- for (i = 0; i < Object->Number; i++)
- {
- Parse_Comma();
- Parse_UV_Vect(Points[i]);
- if ((Points[i][X] < 0.0) ||
- ((i > 1 ) && (i < Object->Number - 1) && (Points[i][Y] <= Points[i-1][Y])))
- {
- Error("Incorrect point in surface of revolution.");
- }
- }
- /* Closed or not closed that's the question. */
- EXPECT
- CASE(OPEN_TOKEN)
- Clear_Flag(Object, CLOSED_FLAG);
- EXIT
- END_CASE
- OTHERWISE
- UNGET
- EXIT
- END_CASE
- END_EXPECT
- /* There are Number-3 segments! */
- Object->Number -= 3;
- /* Compute spline segments. */
- Compute_Sor(Object, Points);
- /* Compute bounding box. */
- Compute_Sor_BBox(Object);
- /* Parse object's modifiers. */
- Parse_Object_Mods((OBJECT *)Object);
- /* Destroy temporary points. */
- POV_FREE (Points);
- return ((OBJECT *) Object);
- }
- /*****************************************************************************
- *
- * FUNCTION
- *
- * Parse_Lathe
- *
- * INPUT
- *
- * OUTPUT
- *
- * RETURNS
- *
- * OBJECT * -
- *
- * AUTHOR
- *
- * Dieter Bayer
- *
- * DESCRIPTION
- *
- * Read a lathe primitive.
- *
- * CHANGES
- *
- * Jun 1994 : Creation.
- *
- ******************************************************************************/
- static OBJECT *Parse_Lathe()
- {
- int i;
- LATHE *Object;
- UV_VECT *Points;
- Parse_Begin();
- if ((Object = (LATHE *)Parse_Object_Id()) != NULL)
- {
- return((OBJECT *)Object);
- }
- Object = Create_Lathe();
- /* Determine kind of spline used and aspect ratio. */
- EXPECT
- CASE(LINEAR_SPLINE_TOKEN)
- Object->Spline_Type = LINEAR_SPLINE;
- END_CASE
- CASE(QUADRATIC_SPLINE_TOKEN)
- Object->Spline_Type = QUADRATIC_SPLINE;
- END_CASE
- CASE(CUBIC_SPLINE_TOKEN)
- Object->Spline_Type = CUBIC_SPLINE;
- END_CASE
- CASE(BEZIER_SPLINE_TOKEN)
- Object->Spline_Type = BEZIER_SPLINE;
- END_CASE
- OTHERWISE
- UNGET
- EXIT
- END_CASE
- END_EXPECT
- /* Get number of points. */
- Object->Number = (int)Parse_Float();
- switch (Object->Spline_Type)
- {
- case LINEAR_SPLINE :
- if (Object->Number < 2)
- {
- Error("Lathe with linear splines must have at least two points.");
- }
- break;
- case QUADRATIC_SPLINE :
- if (Object->Number < 3)
- {
- Error("Lathe with quadratic splines must have at least three points.");
- }
- break;
- case CUBIC_SPLINE :
- if (Object->Number < 4)
- {
- Error("Prism with cubic splines must have at least four points.");
- }
- break;
- case BEZIER_SPLINE :
- if ((Object->Number & 3) != 0)
- {
- Error("Lathe with Bezier splines must have four points per segment.");
- }
- break;
- }
- /* Get temporary points describing the rotated curve. */
- Points = (UV_VECT *)POV_MALLOC(Object->Number*sizeof(UV_VECT), "temporary lathe points");
- /* Read points (x : radius; y : height; z : not used). */
- for (i = 0; i < Object->Number; i++)
- {
- Parse_Comma();
- Parse_UV_Vect(Points[i]);
- if ((i > 0) && (i < Object->Number - 1) && (Points[i][X] < 0.0))
- {
- Error("Incorrect point in lathe.");
- }
- }
- /* Compute spline segments. */
- Compute_Lathe(Object, Points);
- /* Compute bounding box. */
- Compute_Lathe_BBox(Object);
- /* Parse object's modifiers. */
- Parse_Object_Mods((OBJECT *)Object);
- /* Destroy temporary points. */
- POV_FREE (Points);
- return((OBJECT *) Object);
- }
- /*****************************************************************************
- *
- * FUNCTION
- *
- * Parse_Superellipsoid
- *
- * INPUT
- *
- * OUTPUT
- *
- * RETURNS
- *
- * OBJECT * -
- *
- * AUTHOR
- *
- * Dieter Bayer
- *
- * DESCRIPTION
- *
- * Read a superellipsoid primitive.
- *
- * CHANGES
- *
- * Oct 1994 : Creation.
- *
- ******************************************************************************/
- static OBJECT *Parse_Superellipsoid()
- {
- UV_VECT V1;
- SUPERELLIPSOID *Object;
- Parse_Begin();
- if ((Object = (SUPERELLIPSOID *)Parse_Object_Id()) != NULL)
- {
- return((OBJECT *)Object);
- }
- Object = Create_Superellipsoid();
- Parse_UV_Vect(V1);
- /* The x component is e, the y component is n. */
- Object->Power[X] = 2.0 / V1[X];
- Object->Power[Y] = V1[X] / V1[Y];
- Object->Power[Z] = 2.0 / V1[Y];
- /* Compute bounding box. */
- Compute_Superellipsoid_BBox(Object);
- /* Parse object's modifiers. */
- Parse_Object_Mods((OBJECT *)Object);
- return((OBJECT *) Object);
- }
- /*****************************************************************************
- *
- * FUNCTION
- *
- * Parse_Torus
- *
- * INPUT
- *
- * OUTPUT
- *
- * RETURNS
- *
- * OBJECT
- *
- * AUTHOR
- *
- * Dieter Bayer
- *
- * DESCRIPTION
- *
- * -
- *
- * CHANGES
- *
- * Jul 1994 : Creation.
- *
- ******************************************************************************/
- static OBJECT *Parse_Torus()
- {
- TORUS *Object;
- Parse_Begin();
- if ((Object = (TORUS *)Parse_Object_Id()) != NULL)
- {
- return((OBJECT *)Object);
- }
- Object = Create_Torus();
- /* Read in the two radii. */
- Object->R = Parse_Float(); /* Big radius */
- Parse_Comma();
- Object->r = Parse_Float(); /* Little radius */
- Compute_Torus_BBox(Object);
- Parse_Object_Mods ((OBJECT *)Object);
- return ((OBJECT *) Object);
- }
- /*****************************************************************************
- *
- * FUNCTION
- *
- * Parse_Mesh_Texture
- *
- * INPUT
- *
- * OUTPUT
- *
- * RETURNS
- *
- * OBJECT
- *
- * AUTHOR
- *
- * Dieter Bayer
- *
- * DESCRIPTION
- *
- * Read an individual triangle mesh texture.
- *
- * CHANGES
- *
- * Feb 1995 : Creation.
- *
- ******************************************************************************/
- static TEXTURE *Parse_Mesh_Texture()
- {
- TEXTURE *Texture;
- Texture = NULL;
- EXPECT
- CASE(TEXTURE_TOKEN)
- Parse_Begin();
- GET(TEXTURE_ID_TOKEN);
- Texture = (TEXTURE *)Token.Data;
- Parse_End();
- END_CASE
- OTHERWISE
- UNGET
- EXIT
- END_CASE
- END_EXPECT
- return(Texture);
- }
- /*****************************************************************************
- *
- * FUNCTION
- *
- * Parse_Mesh
- *
- * INPUT
- *
- * OUTPUT
- *
- * RETURNS
- *
- * OBJECT
- *
- * AUTHOR
- *
- * Dieter Bayer
- *
- * DESCRIPTION
- *
- * Read a triangle mesh.
- *
- * CHANGES
- *
- * Feb 1995 : Creation.
- *
- ******************************************************************************/
- static OBJECT *Parse_Mesh()
- {
- int i;
- int number_of_normals, number_of_textures, number_of_triangles, number_of_vertices;
- int max_normals, max_textures, max_triangles, max_vertices;
- DBL l1, l2, l3;
- VECTOR D1, D2, P1, P2, P3, N1, N2, N3, N;
- SNGL_VECT *Normals, *Vertices;
- TEXTURE **Textures;
- MESH *Object;
- MESH_TRIANGLE *Triangles;
- int fully_textured=TRUE;
- Parse_Begin();
- if ((Object = (MESH *)Parse_Object_Id()) != NULL)
- {
- return((OBJECT *)Object);
- }
- /* Create object. */
- Object = Create_Mesh();
- /* Allocate temporary normals, textures, triangles and vertices. */
- max_normals = 256;
- max_vertices = 256;
- max_textures = 16;
- max_triangles = 256;
- Normals = (SNGL_VECT *)POV_MALLOC(max_normals*sizeof(SNGL_VECT), "temporary triangle mesh data");
- Textures = (TEXTURE **)POV_MALLOC(max_textures*sizeof(TEXTURE *), "temporary triangle mesh data");
- Triangles = (MESH_TRIANGLE *)POV_MALLOC(max_triangles*sizeof(MESH_TRIANGLE), "temporary triangle mesh data");
- Vertices = (SNGL_VECT *)POV_MALLOC(max_vertices*sizeof(SNGL_VECT), "temporary triangle mesh data");
- /* Read raw triangle file. */
- number_of_normals = 0;
- number_of_textures = 0;
- number_of_triangles = 0;
- number_of_vertices = 0;
- /* Create hash tables. */
- Create_Mesh_Hash_Tables();
- EXPECT
- CASE(TRIANGLE_TOKEN)
- Parse_Begin();
- Parse_Vector(P1); Parse_Comma();
- Parse_Vector(P2); Parse_Comma();
- Parse_Vector(P3);
- if (!Mesh_Degenerate(P1, P2, P3))
- {
- if (number_of_triangles >= max_triangles)
- {
- if (max_triangles >= INT_MAX/2)
- {
- Error("Too many triangles in triangle mesh.\n");
- }
- max_triangles *= 2;
- Triangles = (MESH_TRIANGLE *)POV_REALLOC(Triangles, max_triangles*sizeof(MESH_TRIANGLE), "triangle triangle mesh data");
- }
- /* Init triangle. */
- Init_Mesh_Triangle(&Triangles[number_of_triangles]);
- Triangles[number_of_triangles].P1 = Mesh_Hash_Vertex(&number_of_vertices, &max_vertices, &Vertices, P1);
- Triangles[number_of_triangles].P2 = Mesh_Hash_Vertex(&number_of_vertices, &max_vertices, &Vertices, P2);
- Triangles[number_of_triangles].P3 = Mesh_Hash_Vertex(&number_of_vertices, &max_vertices, &Vertices, P3);
- Compute_Mesh_Triangle(&Triangles[number_of_triangles], FALSE, P1, P2, P3, N);
- Triangles[number_of_triangles].Normal_Ind = Mesh_Hash_Normal(&number_of_normals, &max_normals, &Normals, N);
- Triangles[number_of_triangles].Texture = Mesh_Hash_Texture(&number_of_textures, &max_textures, &Textures, Parse_Mesh_Texture());
- if (Triangles[number_of_triangles].Texture < 0)
- {
- fully_textured = FALSE;
- }
- number_of_triangles++;
- }
- Parse_End();
- END_CASE
- CASE(SMOOTH_TRIANGLE_TOKEN)
- Parse_Begin();
- Parse_Vector(P1); Parse_Comma();
- Parse_Vector(N1); Parse_Comma();
- Parse_Vector(P2); Parse_Comma();
- Parse_Vector(N2); Parse_Comma();
- Parse_Vector(P3); Parse_Comma();
- Parse_Vector(N3);
- VLength(l1, N1);
- VLength(l2, N2);
- VLength(l3, N3);
- if ((l1 != 0.0) && (l2 != 0.0) && (l3 != 0.0) && (!Mesh_Degenerate(P1, P2, P3)))
- {
- if (number_of_triangles >= max_triangles)
- {
- if (max_triangles >= INT_MAX/2)
- {
- Error("Too many triangles in triangle mesh.\n");
- }
- max_triangles *= 2;
- Triangles = (MESH_TRIANGLE *)POV_REALLOC(Triangles, max_triangles*sizeof(MESH_TRIANGLE), "triangle triangle mesh data");
- }
- VInverseScaleEq(N1, l1);
- VInverseScaleEq(N2, l2);
- VInverseScaleEq(N3, l3);
- /* Init triangle. */
- Init_Mesh_Triangle(&Triangles[number_of_triangles]);
- Triangles[number_of_triangles].P1 = Mesh_Hash_Vertex(&number_of_vertices, &max_vertices, &Vertices, P1);
- Triangles[number_of_triangles].P2 = Mesh_Hash_Vertex(&number_of_vertices, &max_vertices, &Vertices, P2);
- Triangles[number_of_triangles].P3 = Mesh_Hash_Vertex(&number_of_vertices, &max_vertices, &Vertices, P3);
- /* Check for equal normals. */
- VSub(D1, N1, N2);
- VSub(D2, N1, N3);
- VDot(l1, D1, D1);
- VDot(l2, D2, D2);
- if ((fabs(l1) > EPSILON) || (fabs(l2) > EPSILON))
- {
- /* Smooth triangle. */
- Triangles[number_of_triangles].N1 = Mesh_Hash_Normal(&number_of_normals, &max_normals, &Normals, N1);
- Triangles[number_of_triangles].N2 = Mesh_Hash_Normal(&number_of_normals, &max_normals, &Normals, N2);
- Triangles[number_of_triangles].N3 = Mesh_Hash_Normal(&number_of_normals, &max_normals, &Normals, N3);
- Compute_Mesh_Triangle(&Triangles[number_of_triangles], TRUE, P1, P2, P3, N);
- }
- else
- {
- /* Flat triangle. */
- Compute_Mesh_Triangle(&Triangles[number_of_triangles], FALSE, P1, P2, P3, N);
- }
- Triangles[number_of_triangles].Normal_Ind = Mesh_Hash_Normal(&number_of_normals, &max_normals, &Normals, N);
- Triangles[number_of_triangles].Texture = Mesh_Hash_Texture(&number_of_textures, &max_textures, &Textures, Parse_Mesh_Texture());
- if (Triangles[number_of_triangles].Texture < 0)
- {
- fully_textured = FALSE;
- }
- number_of_triangles++;
- }
- Parse_End();
- END_CASE
- OTHERWISE
- UNGET
- EXIT
- END_CASE
- END_EXPECT
- /* Destroy hash tables. */
- Destroy_Mesh_Hash_Tables();
- /* If there are no triangles something went wrong. */
- if (number_of_triangles == 0)
- {
- Error("No triangles in triangle mesh.\n");
- }
- /* Init triangle mesh data. */
- Object->Data = (MESH_DATA *)POV_MALLOC(sizeof(MESH_DATA), "triangle mesh data");
- Object->Data->References = 1;
- Object->Data->Tree = NULL;
-
- Object->Data->Normals = NULL;
- Object->Data->Textures = NULL;
- Object->Data->Triangles = NULL;
- Object->Data->Vertices = NULL;
- /* Allocate memory for normals, textures, triangles and vertices. */
- Object->Data->Number_Of_Normals = number_of_normals;
- Object->Data->Number_Of_Textures = number_of_textures;
- Object->Data->Number_Of_Triangles = number_of_triangles;
- Object->Data->Number_Of_Vertices = number_of_vertices;
- Object->Data->Normals = (SNGL_VECT *)POV_MALLOC(number_of_normals*sizeof(SNGL_VECT), "triangle mesh data");
- if (number_of_textures)
- {
- Set_Flag(Object, MULTITEXTURE_FLAG);
- Object->Data->Textures = (TEXTURE **)POV_MALLOC(number_of_textures*sizeof(TEXTURE *), "triangle mesh data");
- }
- Object->Data->Triangles = (MESH_TRIANGLE *)POV_MALLOC(number_of_triangles*sizeof(MESH_TRIANGLE), "triangle mesh data");
- Object->Data->Vertices = (SNGL_VECT *)POV_MALLOC(number_of_vertices*sizeof(SNGL_VECT), "triangle mesh data");
- /* Copy normals, textures, triangles and vertices into mesh. */
- for (i = 0; i < number_of_normals; i++)
- {
- Assign_SNGL_Vect(Object->Data->Normals[i], Normals[i]);
- }
- for (i = 0; i < number_of_textures; i++)
- {
- Object->Data->Textures[i] = Copy_Textures(Textures[i]);
- /* now free the texture, in order to decrement the reference count */
- Destroy_Textures(Textures[i]);
- }
-
- if (fully_textured)
- {
- Object->Type |= TEXTURED_OBJECT;
- }
- for (i = 0; i < number_of_triangles; i++)
- {
- Object->Data->Triangles[i] = Triangles[i];
- }
- for (i = 0; i < number_of_vertices; i++)
- {
- Assign_SNGL_Vect(Object->Data->Vertices[i], Vertices[i]);
- }
- /* Free temporary memory. */
- POV_FREE(Normals);
- POV_FREE(Textures);
- POV_FREE(Triangles);
- POV_FREE(Vertices);
- /*
- Render_Info("Mesh: %ld bytes: %ld vertices, %ld normals, %ld textures, %ld triangles\n",
- Object->Data->Number_Of_Normals*sizeof(SNGL_VECT)+
- Object->Data->Number_Of_Textures*sizeof(TEXTURE *)+
- Object->Data->Number_Of_Triangles*sizeof(MESH_TRIANGLE)+
- Object->Data->Number_Of_Vertices*sizeof(SNGL_VECT),
- Object->Data->Number_Of_Vertices,
- Object->Data->Number_Of_Normals,
- Object->Data->Number_Of_Textures,
- Object->Data->Number_Of_Triangles);
- */
- /* Create bounding box. */
- Compute_Mesh_BBox(Object);
- /* Parse object modifiers. */
- Parse_Object_Mods((OBJECT *)Object);
- /* Create bounding box tree. */
- Build_Mesh_BBox_Tree(Object);
- return((OBJECT *)Object);
- }
- /*****************************************************************************
- *
- * FUNCTION
- *
- * INPUT
- *
- * OUTPUT
- *
- * RETURNS
- *
- * AUTHOR
- *
- * DESCRIPTION
- *
- * CHANGES
- *
- ******************************************************************************/
- static
- OBJECT *Parse_Poly (int order)
- {
- POLY *Object;
- Parse_Begin ();
- if ( (Object = (POLY *)Parse_Object_Id()) != NULL)
- return ((OBJECT *) Object);
- if (order == 0)
- {
- order = (int)Parse_Float(); Parse_Comma();
- if (order < 2 || order > MAX_ORDER)
- Error("Order of poly is out of range.");
- }
- Object = Create_Poly(order);
- Parse_Coeffs(Object->Order, &(Object->Coeffs[0]));
- Compute_Poly_BBox(Object);
- Parse_Object_Mods ((OBJECT *)Object);
- return ((OBJECT *) Object);
- }
- /*****************************************************************************
- *
- * FUNCTION
- *
- * INPUT
- *
- * OUTPUT
- *
- * RETURNS
- *
- * AUTHOR
- *
- * DESCRIPTION
- *
- * CHANGES
- *
- ******************************************************************************/
- static
- OBJECT *Parse_Bicubic_Patch ()
- {
- BICUBIC_PATCH *Object;
- int i, j;
- Parse_Begin ();
- if ( (Object = (BICUBIC_PATCH *)Parse_Object_Id()) != NULL)
- return ((OBJECT *) Object);
- Object = Create_Bicubic_Patch();
- EXPECT
- CASE_FLOAT
- Warn(1.5, "Should use keywords for bicubic parameters.");
- Object->Patch_Type = (int)Parse_Float();
- if (Object->Patch_Type == 2 ||
- Object->Patch_Type == 3)
- Object->Flatness_Value = Parse_Float();
- else
- Object->Flatness_Value = 0.1;
- Object->U_Steps = (int)Parse_Float();
- Object->V_Steps = (int)Parse_Float();
- EXIT
- END_CASE
-
- CASE (TYPE_TOKEN)
- Object->Patch_Type = (int)Parse_Float();
- END_CASE
- CASE (FLATNESS_TOKEN)
- Object->Flatness_Value = Parse_Float();
- END_CASE
- CASE (V_STEPS_TOKEN)
- Object->V_Steps = (int)Parse_Float();
- END_CASE
- CASE (U_STEPS_TOKEN)
- Object->U_Steps = (int)Parse_Float();
- END_CASE
- OTHERWISE
- UNGET
- EXIT
- END_CASE
- END_EXPECT
- if (Object->Patch_Type > 1)
- {
- Object->Patch_Type = 1;
- Warn(0.0, "Patch type no longer supported. Using type 1.");
- }
- if ((Object->Patch_Type < 0) || (Object->Patch_Type > MAX_PATCH_TYPE))
- Error("Undefined bicubic patch type.");
- Parse_Comma();
- for (i=0;i<4;i++)
- for (j=0;j<4;j++)
- {
- Parse_Vector(Object->Control_Points[i][j]);
- if (!((i==3)&&(j==3)))
- Parse_Comma();
- };
- Precompute_Patch_Values(Object); /* interpolated mesh coords */
- Compute_Bicubic_Patch_BBox(Object);
- Parse_Object_Mods ((OBJECT *)Object);
- return ((OBJECT *) Object);
- }
- /*****************************************************************************
- *
- * FUNCTION
- *
- * INPUT
- *
- * OUTPUT
- *
- * RETURNS
- *
- * AUTHOR
- *
- * DESCRIPTION
- *
- * CHANGES
- *
- ******************************************************************************/
- static
- OBJECT *Parse_TrueType ()
- {
- OBJECT *Object;
- char *filename, *text_string;
- DBL depth;
- VECTOR offset;
- TRANSFORM Local_Trans;
- Parse_Begin ();
-
- GET(TTF_TOKEN);
- if ( (Object = (OBJECT *)Parse_Object_Id()) != NULL)
- return ((OBJECT *) Object);
-
- Object = (OBJECT *)Create_CSG_Union ();
- /*** Object = Create_TTF(); */
- /* Parse the TrueType font file name */
- filename = Parse_String();
- Parse_Comma();
- /* Parse the text string to be rendered */
- text_string = Parse_String();
- Parse_Comma();
- /* Get the extrusion depth */
- depth = Parse_Float(); Parse_Comma ();
- /* Get the offset vector */
- Parse_Vector(offset);
- /* Process all this good info */
- ProcessNewTTF((OBJECT *)Object, filename, text_string, depth, offset);
- /* Free up the filename and text string memory */
- POV_FREE (filename);
- POV_FREE (text_string);
- /**** Compute_TTF_BBox(Object); */
- Compute_CSG_BBox((OBJECT *)Object);
- /* This tiny rotation should fix cracks in text that lies along an axis */
- Make_Vector(offset, 0.001, 0.001, 0.001);
- Compute_Rotation_Transform(&Local_Trans, offset);
- Rotate_Object ((OBJECT *)Object, offset, &Local_Trans);
- /* Get any rotate/translate or texturing stuff */
- Parse_Object_Mods ((OBJECT *)Object);
- return ((OBJECT *) Object);
- }
- /*****************************************************************************
- *
- * FUNCTION
- *
- * INPUT
- *
- * OUTPUT
- *
- * RETURNS
- *
- * AUTHOR
- *
- * DESCRIPTION
- *
- * CHANGES
- *
- ******************************************************************************/
- static
- OBJECT *Parse_CSG (int CSG_Type)
- {
- CSG *Object;
- OBJECT *Local;
- int Object_Count = 0;
- int Light_Source_Union = TRUE;
- Parse_Begin ();
- if ( (Object = (CSG *)Parse_Object_Id()) != NULL)
- return ((OBJECT *) Object);
- if (CSG_Type & CSG_UNION_TYPE)
- Object = Create_CSG_Union ();
- else
- if (CSG_Type & CSG_MERGE_TYPE)
- Object = Create_CSG_Merge ();
- else
- Object = Create_CSG_Intersection ();
- Object->Children = NULL;
- while ((Local = Parse_Object ()) != NULL)
- {
- if ((CSG_Type & CSG_INTERSECTION_TYPE) && (Local->Type & PATCH_OBJECT))
- Warn(0.0, "Patch objects not allowed in intersection.");
- Object_Count++;
- if ((CSG_Type & CSG_DIFFERENCE_TYPE) && (Object_Count > 1))
- Invert_Object (Local);
- Object->Type |= (Local->Type & CHILDREN_FLAGS);
- if (!(Local->Type & LIGHT_SOURCE_OBJECT))
- {
- Light_Source_Union = FALSE;
- }
- Local->Type |= IS_CHILD_OBJECT;
- Link(Local, &Local->Sibling, &Object->Children);
- };
- if (Light_Source_Union)
- {
- Object->Type |= LT_SRC_UNION_OBJECT;
- }
-
- if ((Object_Count < 2) && (opts.Language_Version >= 1.5))
- Warn(1.5, "Should have at least 2 objects in csg.");
- Compute_CSG_BBox((OBJECT *)Object);
- Parse_Object_Mods ((OBJECT *)Object);
- return ((OBJECT *) Object);
- }
- /*****************************************************************************
- *
- * FUNCTION
- *
- * INPUT
- *
- * OUTPUT
- *
- * RETURNS
- *
- * AUTHOR
- *
- * DESCRIPTION
- *
- * CHANGES
- *
- ******************************************************************************/
- static
- OBJECT *Parse_Light_Source ()
- {
- DBL Len;
- VECTOR Local_Vector;
- MATRIX Local_Matrix;
- TRANSFORM Local_Trans;
- LIGHT_SOURCE *Object;
- Parse_Begin ();
- if ( (Object = (LIGHT_SOURCE *)Parse_Object_Id()) != NULL)
- return ((OBJECT *) Object);
-
- Object = Create_Light_Source ();
- Parse_Vector(Object->Center);
- Parse_Comma();
- Parse_Colour (Object->Colour);
- EXPECT
- CASE (LOOKS_LIKE_TOKEN)
- if (Object->Children != NULL)
- Error("Only one looks_like allowed per light_source.");
- Parse_Begin ();
- Object->Type &= ~(int)PATCH_OBJECT;
- if ((Object->Children = Parse_Object ()) == NULL)
- Parse_Error_Str ("object");
- Compute_Translation_Transform(&Local_Trans, Object->Center);
- Translate_Object (Object->Children, Object->Center, &Local_Trans);
- Parse_Object_Mods (Object->Children);
- Set_Flag(Object->Children, NO_SHADOW_FLAG);
- Set_Flag(Object, NO_SHADOW_FLAG);
- Object->Type |= (Object->Children->Type & CHILDREN_FLAGS);
- END_CASE
- CASE (FILL_LIGHT_TOKEN)
- Object->Light_Type = FILL_LIGHT_SOURCE;
- END_CASE
- CASE (SPOTLIGHT_TOKEN)
- Object->Light_Type = SPOT_SOURCE;
- END_CASE
- CASE (CYLINDER_TOKEN)
- Object->Light_Type = CYLINDER_SOURCE;
- END_CASE
- CASE (POINT_AT_TOKEN)
- if ((Object->Light_Type == SPOT_SOURCE) || (Object->Light_Type == CYLINDER_SOURCE))
- Parse_Vector(Object->Points_At);
- else
- Not_With ("point_at","standard light source");
- END_CASE
- CASE (TIGHTNESS_TOKEN)
- if ((Object->Light_Type == SPOT_SOURCE) || (Object->Light_Type == CYLINDER_SOURCE))
- Object->Coeff = Parse_Float();
- else
- Not_With ("tightness","standard light source");
- END_CASE
- CASE (RADIUS_TOKEN)
- if ((Object->Light_Type == SPOT_SOURCE) || (Object->Light_Type == CYLINDER_SOURCE))
- Object->Radius = Parse_Float();
- else
- Not_With ("radius","standard light source");
- END_CASE
- CASE (FALLOFF_TOKEN)
- if ((Object->Light_Type == SPOT_SOURCE) || (Object->Light_Type == CYLINDER_SOURCE))
- Object->Falloff = Parse_Float();
- else
- Not_With ("falloff","standard light source");
- END_CASE
- CASE (FADE_DISTANCE_TOKEN)
- Object->Fade_Distance = Parse_Float();
- END_CASE
- CASE (FADE_POWER_TOKEN)
- Object->Fade_Power = Parse_Float();
- END_CASE
- CASE (AREA_LIGHT_TOKEN)
- Object->Area_Light = TRUE;
- Parse_Vector (Object->Axis1); Parse_Comma ();
- Parse_Vector (Object->Axis2); Parse_Comma ();
- Object->Area_Size1 = (int)Parse_Float(); Parse_Comma ();
- Object->Area_Size2 = (int)Parse_Float();
- Object->Light_Grid = Create_Light_Grid (Object->Area_Size1, Object->Area_Size2);
- END_CASE
- CASE (JITTER_TOKEN)
- Object->Jitter = TRUE;
- END_CASE
- CASE (TRACK_TOKEN)
- Object->Track = TRUE;
- END_CASE
- CASE (ADAPTIVE_TOKEN)
- Object->Adaptive_Level = (int)Parse_Float();
- END_CASE
- CASE (MEDIA_ATTENUATION_TOKEN)
- Object->Media_Attenuation = Allow_Float(1.0) > 0.0;
- END_CASE
- CASE (MEDIA_INTERACTION_TOKEN)
- Object->Media_Interaction = Allow_Float(1.0) > 0.0;
- END_CASE
- CASE (TRANSLATE_TOKEN)
- Parse_Vector (Local_Vector);
- Compute_Translation_Transform(&Local_Trans, Local_Vector);
- Translate_Object ((OBJECT *)Object, Local_Vector, &Local_Trans);
- END_CASE
- CASE (ROTATE_TOKEN)
- Parse_Vector (Local_Vector);
- Compute_Rotation_Transform(&Local_Trans, Local_Vector);
- Rotate_Object ((OBJECT *)Object, Local_Vector, &Local_Trans);
- END_CASE
- CASE (SCALE_TOKEN)
- Parse_Scale_Vector (Local_Vector);
- Compute_Scaling_Transform(&Local_Trans, Local_Vector);
- Scale_Object ((OBJECT *)Object, Local_Vector, &Local_Trans);
- END_CASE
- CASE (TRANSFORM_TOKEN)
- GET(TRANSFORM_ID_TOKEN)
- Transform_Object ((OBJECT *)Object, (TRANSFORM *)Token.Data);
- END_CASE
- CASE (MATRIX_TOKEN)
- Parse_Matrix (Local_Matrix);
- Compute_Matrix_Transform(&Local_Trans, Local_Matrix);
- Transform_Object ((OBJECT *)Object, &Local_Trans);
- END_CASE
- OTHERWISE
- UNGET
- EXIT
- END_CASE
- END_EXPECT
- Parse_End ();
- if (Object->Light_Type == SPOT_SOURCE)
- {
- Object->Radius = cos(Object->Radius * M_PI_180);
- Object->Falloff = cos(Object->Falloff * M_PI_180);
- }
- VSub(Object->Direction, Object->Points_At, Object->Center);
- VLength(Len, Object->Direction);
- if (Len > EPSILON)
- {
- VInverseScaleEq(Object->Direction, Len);
- }
- return ((OBJECT *)Object);
- }
- /*****************************************************************************
- *
- * FUNCTION
- *
- * INPUT
- *
- * OUTPUT
- *
- * RETURNS
- *
- * AUTHOR
- *
- * DESCRIPTION
- *
- * CHANGES
- *
- ******************************************************************************/
- OBJECT *Parse_Object ()
- {
- OBJECT *Object = NULL;
- EXPECT
- CASE (JULIA_FRACTAL_TOKEN)
- Object = Parse_Julia_Fractal ();
- EXIT
- END_CASE
- CASE (SPHERE_TOKEN)
- Object = Parse_Sphere ();
- EXIT
- END_CASE
- CASE (PLANE_TOKEN)
- Object = Parse_Plane ();
- EXIT
- END_CASE
- CASE (CONE_TOKEN)
- Object = Parse_Cone ();
- EXIT
- END_CASE
- CASE (CYLINDER_TOKEN)
- Object = Parse_Cylinder ();
- EXIT
- END_CASE
- CASE (DISC_TOKEN)
- Object = Parse_Disc ();
- EXIT
- END_CASE
- CASE (QUADRIC_TOKEN)
- Object = Parse_Quadric ();
- EXIT
- END_CASE
- CASE (CUBIC_TOKEN)
- Object = Parse_Poly (3);
- EXIT
- END_CASE
- CASE (QUARTIC_TOKEN)
- Object = Parse_Poly (4);
- EXIT
- END_CASE
- CASE (POLY_TOKEN)
- Object = Parse_Poly (0);
- EXIT
- END_CASE
- CASE (TORUS_TOKEN)
- Object = Parse_Torus ();
- EXIT
- END_CASE
- /* Parse lathe primitive. [DB 8/94] */
- CASE (LATHE_TOKEN)
- Object = Parse_Lathe();
- EXIT
- END_CASE
- /* Parse polygon primitive. [DB 8/94] */
- CASE (POLYGON_TOKEN)
- Object = Parse_Polygon();
- EXIT
- END_CASE
- /* Parse prism primitive. [DB 8/94] */
- CASE (PRISM_TOKEN)
- Object = Parse_Prism();
- EXIT
- END_CASE
- /* Parse surface of revolution primitive. [DB 8/94] */
- CASE (SOR_TOKEN)
- Object = Parse_Sor();
- EXIT
- END_CASE
- /* Parse superellipsoid primitive. [DB 11/94] */
- CASE (SUPERELLIPSOID_TOKEN)
- Object = Parse_Superellipsoid();
- EXIT
- END_CASE
- /* Parse triangle mesh primitive. [DB 2/95] */
- CASE (MESH_TOKEN)
- Object = Parse_Mesh();
- EXIT
- END_CASE
- CASE (TEXT_TOKEN)
- Object = Parse_TrueType ();
- EXIT
- END_CASE
- CASE (OBJECT_ID_TOKEN)
- Object = Copy_Object((OBJECT *) Token.Data);
- EXIT
- END_CASE
- CASE (UNION_TOKEN)
- Object = Parse_CSG (CSG_UNION_TYPE);
- EXIT
- END_CASE
- CASE (COMPOSITE_TOKEN)
- Warn(1.5, "Use union instead of composite.");
- Object = Parse_CSG (CSG_UNION_TYPE);
- EXIT
- END_CASE
- CASE (MERGE_TOKEN)
- Object = Parse_CSG (CSG_MERGE_TYPE);
- EXIT
- END_CASE
- CASE (INTERSECTION_TOKEN)
- Object = Parse_CSG (CSG_INTERSECTION_TYPE);
- EXIT
- END_CASE
- CASE (DIFFERENCE_TOKEN)
- Object = Parse_CSG (CSG_DIFFERENCE_TYPE+CSG_INTERSECTION_TYPE);
- EXIT
- END_CASE
- CASE (BICUBIC_PATCH_TOKEN)
- Object = Parse_Bicubic_Patch ();
- EXIT
- END_CASE
- CASE (TRIANGLE_TOKEN)
- Object = Parse_Triangle ();
- EXIT
- END_CASE
- CASE (SMOOTH_TRIANGLE_TOKEN)
- Object = Parse_Smooth_Triangle ();
- EXIT
- END_CASE
- CASE (HEIGHT_FIELD_TOKEN)
- Object = Parse_HField ();
- EXIT
- END_CASE
- CASE (BOX_TOKEN)
- Object = Parse_Box ();
- EXIT
- END_CASE
- CASE (BLOB_TOKEN)
- Object = Parse_Blob ();
- EXIT
- END_CASE
- CASE (LIGHT_SOURCE_TOKEN)
- Object = Parse_Light_Source ();
- EXIT
- END_CASE
- CASE (OBJECT_TOKEN)
- Parse_Begin ();
- Object = Parse_Object ();
- if (!Object)
- Parse_Error_Str ("object");
- Parse_Object_Mods ((OBJECT *)Object);
- EXIT
- END_CASE
- OTHERWISE
- UNGET
- EXIT
- END_CASE
- END_EXPECT
- return ((OBJECT *) Object);
- }
-
- /*****************************************************************************
- *
- * FUNCTION
- *
- * INPUT
- *
- * OUTPUT
- *
- * RETURNS
- *
- * AUTHOR
- *
- * DESCRIPTION
- *
- * CHANGES
- *
- ******************************************************************************/
- void Parse_Default ()
- {
- TEXTURE *Local_Texture;
- PIGMENT *Local_Pigment;
- TNORMAL *Local_Tnormal;
- FINISH *Local_Finish;
- Not_In_Default = FALSE;
- Parse_Begin();
- EXPECT
- CASE (TEXTURE_TOKEN)
- Local_Texture = Default_Texture;
- Parse_Begin ();
- Default_Texture = Parse_Texture();
- Parse_End ();
- if (Default_Texture->Type != PLAIN_PATTERN)
- Error("Default texture cannot be material map or tiles.");
- if (Default_Texture->Next != NULL)
- Error("Default texture cannot be layered.");
- Destroy_Textures(Local_Texture);
- END_CASE
- CASE (PIGMENT_TOKEN)
- Local_Pigment = Copy_Pigment((Default_Texture->Pigment));
- Parse_Begin ();
- Parse_Pigment (&Local_Pigment);
- Parse_End ();
- Destroy_Pigment(Default_Texture->Pigment);
- Default_Texture->Pigment = Local_Pigment;
- END_CASE
- CASE (TNORMAL_TOKEN)
- Local_Tnormal = Copy_Tnormal((Default_Texture->Tnormal));
- Parse_Begin ();
- Parse_Tnormal (&Local_Tnormal);
- Parse_End ();
- Destroy_Tnormal(Default_Texture->Tnormal);
- Default_Texture->Tnormal = Local_Tnormal;
- END_CASE
- CASE (FINISH_TOKEN)
- Local_Finish = Copy_Finish((Default_Texture->Finish));
- Parse_Finish (&Local_Finish);
- Destroy_Finish(Default_Texture->Finish);
- Default_Texture->Finish = Local_Finish;
- END_CASE
- CASE (CAMERA_TOKEN)
- Parse_Camera (&Default_Camera);
- END_CASE
- OTHERWISE
- UNGET
- EXIT
- END_CASE
- END_EXPECT
- Parse_End();
- Not_In_Default = TRUE;
- }
- /*****************************************************************************
- *
- * FUNCTION
- *
- * INPUT
- *
- * OUTPUT
- *
- * RETURNS
- *
- * AUTHOR
- *
- * DESCRIPTION
- *
- * CHANGES
- *
- ******************************************************************************/
- static void Parse_Frame ()
- {
- OBJECT *Object;
- RAINBOW *Local_Rainbow;
- FOG *Local_Fog;
- SKYSPHERE *Local_Skysphere;
- int i;
- EXPECT
- CASE (RAINBOW_TOKEN)
- Local_Rainbow = Parse_Rainbow();
- Local_Rainbow->Next = Frame.Rainbow;
- Frame.Rainbow = Local_Rainbow;
- END_CASE
- CASE (SKYSPHERE_TOKEN)
- Local_Skysphere = Parse_Skysphere();
- if (Frame.Skysphere != NULL)
- {
- Warn(0.0, "Only one sky-sphere allowed (last one will be used).");
- Destroy_Skysphere(Frame.Skysphere);
- }
- Frame.Skysphere = Local_Skysphere;
- for (i=0; i<Local_Skysphere->Count; i++)
- {
- Post_Pigment(Local_Skysphere->Pigments[i]);
- }
- END_CASE
- CASE (FOG_TOKEN)
- Local_Fog = Parse_Fog();
- Local_Fog->Next = Frame.Fog;
- Frame.Fog = Local_Fog;
- END_CASE
- CASE (MEDIA_TOKEN)
- Parse_Media(&Frame.Atmosphere);
- END_CASE
- CASE (BACKGROUND_TOKEN)
- Parse_Begin();
- Parse_Colour (Frame.Background_Colour);
- Parse_End();
- END_CASE
- CASE (CAMERA_TOKEN)
- Parse_Camera (&Frame.Camera);
- END_CASE
- CASE (DECLARE_TOKEN)
- UNGET
- Warn(2.99,"Should have '#' before 'declare'.");
- Parse_Directive (FALSE);
- END_CASE
- CASE (INCLUDE_TOKEN)
- UNGET
- Warn(2.99,"Should have '#' before 'include'.");
- Parse_Directive (FALSE);
- END_CASE
- CASE (FLOAT_FUNCT_TOKEN)
- switch(Token.Function_Id)
- {
- case VERSION_TOKEN:
- UNGET
- Parse_Directive (FALSE);
- UNGET
- break;
-
- default:
- UNGET
- Parse_Error_Str ("object or directive");
- break;
- }
- END_CASE
- CASE (MAX_TRACE_LEVEL_TOKEN)
- Global_Setting_Warn();
- Max_Trace_Level = (int) Parse_Float ();
- END_CASE
- CASE (MAX_INTERSECTIONS)
- Global_Setting_Warn();
- Max_Intersections = (int)Parse_Float ();
- END_CASE
- CASE (DEFAULT_TOKEN)
- Parse_Default();
- END_CASE
- CASE (END_OF_FILE_TOKEN)
- EXIT
- END_CASE
- CASE (GLOBAL_SETTINGS_TOKEN)
- Parse_Global_Settings();
- END_CASE
- OTHERWISE
- UNGET
- Object = Parse_Object();
- if (Object == NULL)
- Parse_Error_Str ("object or directive");
- Post_Process (Object, NULL);
- Link_To_Frame (Object);
- END_CASE
- END_EXPECT
- }
- /*****************************************************************************
- *
- * FUNCTION
- *
- * INPUT
- *
- * OUTPUT
- *
- * RETURNS
- *
- * AUTHOR
- *
- * DESCRIPTION
- *
- * CHANGES
- *
- * Mar 1996 : Add line number info to warning message [AED]
- *
- ******************************************************************************/
- static void Global_Setting_Warn()
- {
- if (opts.Language_Version >= 3.0)
- {
- Warning(0.0, "%s:%d: warning: '%s' should be in 'global_settings{...}' statement.\n",
- Token.Filename, Token.Token_Line_No+1, Token.Token_String);
- }
- }
- /*****************************************************************************
- *
- * FUNCTION
- *
- * INPUT
- *
- * OUTPUT
- *
- * RETURNS
- *
- * AUTHOR
- *
- * DESCRIPTION
- *
- * CHANGES
- *
- ******************************************************************************/
- static void Parse_Global_Settings()
- {
- Parse_Begin();
- EXPECT
- CASE (IRID_WAVELENGTH_TOKEN)
- Parse_Colour (Frame.Irid_Wavelengths);
- END_CASE
- CASE (ASSUMED_GAMMA_TOKEN)
- {
- DBL AssumedGamma;
- AssumedGamma = Parse_Float ();
- if (fabs(AssumedGamma - opts.DisplayGamma) < 0.1)
- {
- opts.GammaFactor = 1.0;
- opts.Options &= ~GAMMA_CORRECT; /* turn off gamma correction */
- }
- else
- {
- opts.GammaFactor = AssumedGamma/opts.DisplayGamma;
- opts.Options |= GAMMA_CORRECT; /* turn on gamma correction */
- }
- }
- END_CASE
- CASE (MAX_TRACE_LEVEL_TOKEN)
- Max_Trace_Level = (int) Parse_Float ();
- END_CASE
- CASE (ADC_BAILOUT_TOKEN)
- ADC_Bailout = Parse_Float ();
- END_CASE
- CASE (NUMBER_OF_WAVES_TOKEN)
- Number_Of_Waves = (int) Parse_Float ();
- if(Number_Of_Waves <=0)
- {
- Warn(0.0, "Illegal Value: Number_Of_Waves = 0. Changed to 1.");
- Number_Of_Waves = 1;
- }
- END_CASE
- CASE (MAX_INTERSECTIONS)
- Max_Intersections = (int)Parse_Float ();
- END_CASE
- CASE (AMBIENT_LIGHT_TOKEN)
- Parse_Colour (Frame.Ambient_Light);
- END_CASE
- CASE (RADIOSITY_TOKEN)
- Experimental_Flag |= EF_RADIOS;
- Parse_Begin();
- EXPECT
- CASE (BRIGHTNESS_TOKEN)
- if ((opts.Radiosity_Brightness = Parse_Float()) <= 0.0)
- {
- Error("Radiosity brightness must be a positive number.");
- }
- END_CASE
- CASE (COUNT_TOKEN)
- if (( opts.Radiosity_Count = (int)Parse_Float()) <= 0)
- {
- Error("Radiosity count must be a positive number.");
- }
- if ( opts.Radiosity_Count > 1600)
- {
- Error("Radiosity count can not be more than 1600.");
- opts.Radiosity_Count = 1600;
- }
- END_CASE
- CASE (DISTANCE_MAXIMUM_TOKEN)
- if (( opts.Radiosity_Dist_Max = Parse_Float()) < 0.0)
- {
- Error("Radiosity distance maximum must be a positive number.");
- }
- END_CASE
- CASE (ERROR_BOUND_TOKEN)
- if (( opts.Radiosity_Error_Bound = Parse_Float()) <= 0.0)
- {
- Error("Radiosity error bound must be a positive number.");
- }
- END_CASE
- CASE (GRAY_THRESHOLD_TOKEN)
- opts.Radiosity_Gray = Parse_Float();
- if (( opts.Radiosity_Gray < 0.0) || ( opts.Radiosity_Gray > 1.0))
- {
- Error("Radiosity gray threshold must be from 0.0 to 1.0.");
- }
- END_CASE
- CASE (LOW_ERROR_FACTOR_TOKEN)
- if (( opts.Radiosity_Low_Error_Factor = Parse_Float()) <= 0.0)
- {
- Error("Radiosity low error factor must be a positive number.");
- }
- END_CASE
- CASE (MINIMUM_REUSE_TOKEN)
- if (( opts.Radiosity_Min_Reuse = Parse_Float()) < 0.0)
- {
- Error("Radiosity min reuse can not be a negative number.");
- }
- END_CASE
- CASE (NEAREST_COUNT_TOKEN)
- opts.Radiosity_Nearest_Count = (int)Parse_Float();
- if (( opts.Radiosity_Nearest_Count < 1) ||
- ( opts.Radiosity_Nearest_Count > MAX_NEAREST_COUNT))
- {
- Error("Radiosity nearest count must be a value from 1 to %ld.", (long)MAX_NEAREST_COUNT);
- }
- END_CASE
- CASE (RECURSION_LIMIT_TOKEN)
- if (( opts.Radiosity_Recursion_Limit = (int)Parse_Float()) <= 0)
- {
- Error("Radiosity recursion limit must be a positive number.");
- }
- END_CASE
- OTHERWISE
- UNGET
- EXIT
- END_CASE
- END_EXPECT
- Parse_End();
- END_CASE
-
- CASE (HF_GRAY_16_TOKEN)
- if (Allow_Float(1.0)>EPSILON)
- {
- opts.Options |= HF_GRAY_16;
- opts.PaletteOption = GREY; /* Force gray scale preview */
- Output_File_Handle->file_type = HF_FTYPE;
- }
- END_CASE
- OTHERWISE
- UNGET
- EXIT
- END_CASE
- END_EXPECT
- Parse_End();
- }
- /*****************************************************************************
- *
- * FUNCTION
- *
- * INPUT
- *
- * OUTPUT
- *
- * RETURNS
- *
- * AUTHOR
- *
- * DESCRIPTION
- *
- * CHANGES
- *
- ******************************************************************************/
- void Destroy_Frame()
- {
- FOG *Fog, *Next_Fog;
- RAINBOW *Rainbow, *Next_Rainbow;
- Destroy_Camera (Frame.Camera); Frame.Camera=NULL;
- /* Destroy fogs. [DB 12/94] */
- for (Fog = Frame.Fog; Fog != NULL;)
- {
- Next_Fog = Fog->Next;
- Destroy_Fog(Fog);
- Fog = Next_Fog;
- }
-
- Frame.Fog = NULL;
- /* Destroy rainbows. [DB 12/94] */
- for (Rainbow = Frame.Rainbow; Rainbow != NULL;)
- {
- Next_Rainbow = Rainbow->Next;
- Destroy_Rainbow(Rainbow);
- Rainbow = Next_Rainbow;
- }
- Frame.Rainbow = NULL;
- /* Destroy skysphere. [DB 12/94] */
- Destroy_Skysphere(Frame.Skysphere);
- Frame.Skysphere = NULL;
- /* Destroy atmosphere. [DB 1/95] */
- Destroy_Media(Frame.Atmosphere);
- Frame.Atmosphere = NULL;
- if (Frame.Objects != NULL) {
- Destroy_Object (Frame.Objects);
- Frame.Objects = NULL;
- Frame.Light_Sources = NULL;
- }
- }
- /*****************************************************************************
- *
- * FUNCTION
- *
- * INPUT
- *
- * OUTPUT
- *
- * RETURNS
- *
- * AUTHOR
- *
- * DESCRIPTION
- *
- * CHANGES
- *
- ******************************************************************************/
- static void Parse_Camera (CAMERA **Camera_Ptr)
- {
- int i;
- DBL Direction_Length = 1.0, Up_Length, Right_Length, Handedness;
- DBL k1, k2, k3;
- VECTOR Local_Vector;
- MATRIX Local_Matrix;
- TRANSFORM Local_Trans;
- CAMERA *New;
- Parse_Begin ();
- EXPECT
- CASE (CAMERA_ID_TOKEN)
- Destroy_Camera(*Camera_Ptr);
- *Camera_Ptr = Copy_Camera ((CAMERA *) Token.Data);
- EXIT
- END_CASE
- OTHERWISE
- UNGET
- EXIT
- END_CASE
- END_EXPECT
- New = *Camera_Ptr;
- EXPECT
- /* Get camera type. [DB 7/94] */
- CASE (PERSPECTIVE_TOKEN)
- New->Type = PERSPECTIVE_CAMERA;
- END_CASE
- CASE (ORTHOGRAPHIC_TOKEN)
- New->Type = ORTHOGRAPHIC_CAMERA;
- /*
- * Resize right and up vector to get the same image
- * area as we get with the perspective camera.
- */
- VSub(Local_Vector, New->Look_At, New->Location);
- VLength(k1, Local_Vector);
- VLength(k2, New->Direction);
- if ((k1 > EPSILON) && (k2 > EPSILON))
- {
- VScaleEq(New->Right, k1 / k2);
- VScaleEq(New->Up, k1 / k2);
- }
- END_CASE
- CASE (FISHEYE_TOKEN)
- New->Type = FISHEYE_CAMERA;
- END_CASE
- CASE (ULTRA_WIDE_ANGLE_TOKEN)
- New->Type = ULTRA_WIDE_ANGLE_CAMERA;
- END_CASE
- CASE (OMNIMAX_TOKEN)
- New->Type = OMNIMAX_CAMERA;
- END_CASE
- CASE (PANORAMIC_TOKEN)
- New->Type = PANORAMIC_CAMERA;
- END_CASE
- CASE (CYLINDER_TOKEN)
- i = (int)Parse_Float();
- switch (i)
- {
- case 1: New->Type = CYL_1_CAMERA; break;
- case 2: New->Type = CYL_2_CAMERA; break;
- case 3: New->Type = CYL_3_CAMERA; break;
- case 4: New->Type = CYL_4_CAMERA; break;
- }
- END_CASE
- /* Read viewing angle. Scale direction vector if necessary. [DB 7/94] */
- CASE (ANGLE_TOKEN)
- New->Angle = Parse_Float();
- if (New->Angle < 0.0)
- {
- Error("Negative viewing angle.");
- }
- if (New->Type == PERSPECTIVE_CAMERA)
- {
- if (New->Angle >= 180.0)
- {
- Error("Viewing angle has to be smaller than 180 degrees.");
- }
- VNormalize(New->Direction, New->Direction);
- VLength (Right_Length, New->Right);
- Direction_Length = Right_Length / tan(New->Angle * M_PI_360)/2.0;
- VScaleEq(New->Direction, Direction_Length);
- }
- END_CASE
- /* Read primary ray pertubation. [DB 7/94] */
- CASE (TNORMAL_TOKEN)
- Parse_Begin ();
- Parse_Tnormal(&(New->Tnormal));
- Parse_End ();
- END_CASE
- CASE (LOCATION_TOKEN)
- Parse_Vector(New->Location);
- END_CASE
- CASE (DIRECTION_TOKEN)
- Parse_Vector(New->Direction);
- END_CASE
- CASE (UP_TOKEN)
- Parse_Vector(New->Up);
- END_CASE
- CASE (RIGHT_TOKEN)
- Parse_Vector(New->Right);
- END_CASE
- CASE (SKY_TOKEN)
- Parse_Vector(New->Sky);
- END_CASE
- CASE (LOOK_AT_TOKEN)
- VLength (Direction_Length, New->Direction);
- VLength (Up_Length, New->Up);
- VLength (Right_Length, New->Right);
- VCross (Local_Vector, New->Up, New->Direction);
- VDot (Handedness, Local_Vector, New->Right);
- Parse_Vector (New->Direction);
- Assign_Vector(New->Look_At, New->Direction);
- VSub (New->Direction, New->Direction, New->Location);
- /* Check for zero length direction vector. */
- if (VSumSqr(New->Direction) < EPSILON)
- {
- Error("Camera location and look_at point must be different.\n");
- }
-
- VNormalize (New->Direction, New->Direction);
- /* Save Right vector */
- Assign_Vector (Local_Vector, New->Right);
- VCross (New->Right, New->Sky, New->Direction);
- /* Avoid DOMAIN error (from Terry Kanakis) */
- if((fabs(New->Right[X]) < EPSILON) &&
- (fabs(New->Right[Y]) < EPSILON) &&
- (fabs(New->Right[Z]) < EPSILON))
- {
- /* Restore Right vector*/
- Assign_Vector (New->Right, Local_Vector);
- }
- VNormalize (New->Right, New->Right);
- VCross (New->Up, New->Direction, New->Right);
- VScale (New->Direction, New->Direction, Direction_Length);
- if (Handedness > 0.0)
- VScaleEq (New->Right, Right_Length)
- else
- VScaleEq (New->Right, -Right_Length);
- VScaleEq(New->Up, Up_Length);
- END_CASE
- CASE (TRANSLATE_TOKEN)
- Parse_Vector (Local_Vector);
- Translate_Camera (New, Local_Vector);
- END_CASE
- CASE (ROTATE_TOKEN)
- Parse_Vector (Local_Vector);
- Rotate_Camera (New, Local_Vector);
- END_CASE
- CASE (SCALE_TOKEN)
- Parse_Scale_Vector (Local_Vector);
- Scale_Camera (New, Local_Vector);
- END_CASE
- CASE (TRANSFORM_TOKEN)
- GET(TRANSFORM_ID_TOKEN)
- Transform_Camera (New, (TRANSFORM *)Token.Data);
- END_CASE
- CASE (MATRIX_TOKEN)
- Parse_Matrix (Local_Matrix);
- Compute_Matrix_Transform(&Local_Trans, Local_Matrix);
- Transform_Camera (New, &Local_Trans);
- END_CASE
- /* Parse focal blur stuff. */
- CASE (BLUR_SAMPLES_TOKEN)
- New->Blur_Samples = Parse_Float();
- if (New->Blur_Samples <= 0)
- {
- Error("Illegal number of focal blur samples.\n");
- }
- END_CASE
- CASE (CONFIDENCE_TOKEN)
- k1 = Parse_Float();
- if ((k1 > 0.0) && (k1 < 1.0))
- {
- New->Confidence = k1;
- }
- else
- {
- Warn(0.0, "Illegal confidence value. Default is used.");
- }
- END_CASE
- CASE (VARIANCE_TOKEN)
- k1 = Parse_Float();
- if ((k1 >= 0.0) && (k1 <= 1.0))
- {
- New->Variance = k1;
- }
- else
- {
- Warn(0.0, "Illegal variance value. Default is used.");
- }
- END_CASE
- CASE (APERTURE_TOKEN)
- New->Aperture = Parse_Float();
- END_CASE
- CASE (FOCAL_POINT_TOKEN)
- Parse_Vector(Local_Vector);
- VSubEq(Local_Vector, New->Location);
- VLength (New->Focal_Distance, Local_Vector);
- END_CASE
- OTHERWISE
- UNGET
- EXIT
- END_CASE
- END_EXPECT
- Parse_End ();
- /* Make sure the focal distance hasn't been explicitly given */
- if ( New->Focal_Distance < 0.0 )
- New->Focal_Distance = Direction_Length;
- if ( New->Focal_Distance == 0.0 )
- New->Focal_Distance = 1.0;
- /* Print a warning message if vectors are not perpendicular. [DB 10/94] */
- VDot(k1, New->Right, New->Up);
- VDot(k2, New->Right, New->Direction);
- VDot(k3, New->Up, New->Direction);
- if ((fabs(k1) > EPSILON) || (fabs(k2) > EPSILON) || (fabs(k3) > EPSILON))
- {
- Warn(0.0, "Camera vectors are not perpendicular. "
- "Making look_at the last statement may help.");
- }
- }
- /*****************************************************************************
- *
- * FUNCTION
- *
- * INPUT
- *
- * OUTPUT
- *
- * RETURNS
- *
- * AUTHOR
- *
- * DESCRIPTION
- *
- * CHANGES
- *
- ******************************************************************************/
- void Parse_Matrix(MATRIX Matrix)
- {
- int i, j;
- EXPECT
- CASE (LEFT_ANGLE_TOKEN)
- Matrix[0][0] = Parse_Float();
- for (i = 0; i < 4; i++)
- {
- for (j = !i ? 1 : 0; j < 3; j++)
- {
- Parse_Comma();
- Matrix[i][j] = Parse_Float();
- }
- Matrix[i][3] = (i != 3 ? 0.0 : 1.0);
- }
- GET (RIGHT_ANGLE_TOKEN);
- /* Check to see that we aren't scaling any dimension by zero */
- for (i = 0; i < 3; i++)
- {
- if (fabs(Matrix[0][i]) < EPSILON && fabs(Matrix[1][i]) < EPSILON &&
- fabs(Matrix[2][i]) < EPSILON)
- {
- Warn(0.0,"Illegal matrix column: Scale by 0.0. Changed to 1.0.");
- Matrix[i][i] = 1.0;
- }
- }
- EXIT
- END_CASE
- OTHERWISE
- Parse_Error (LEFT_ANGLE_TOKEN);
- END_CASE
- END_EXPECT
- }
- /*****************************************************************************
- *
- * FUNCTION
- *
- * INPUT
- *
- * OUTPUT
- *
- * RETURNS
- *
- * AUTHOR
- *
- * DESCRIPTION
- *
- * CHANGES
- *
- ******************************************************************************/
- static
- TRANSFORM *Parse_Transform ()
- {
- MATRIX Local_Matrix;
- TRANSFORM *New, Local_Trans;
- VECTOR Local_Vector;
- Parse_Begin ();
- New = Create_Transform ();
- EXPECT
- CASE(TRANSFORM_ID_TOKEN)
- Compose_Transforms (New, (TRANSFORM *)Token.Data);
- END_CASE
- CASE (TRANSFORM_TOKEN)
- GET(TRANSFORM_ID_TOKEN)
- Compose_Transforms(New, (TRANSFORM *)Token.Data);
- END_CASE
- CASE (TRANSLATE_TOKEN)
- Parse_Vector (Local_Vector);
- Compute_Translation_Transform(&Local_Trans, Local_Vector);
- Compose_Transforms (New, &Local_Trans);
- END_CASE
- CASE (ROTATE_TOKEN)
- Parse_Vector (Local_Vector);
- Compute_Rotation_Transform(&Local_Trans, Local_Vector);
- Compose_Transforms (New, &Local_Trans);
- END_CASE
- CASE (SCALE_TOKEN)
- Parse_Scale_Vector (Local_Vector);
- Compute_Scaling_Transform(&Local_Trans, Local_Vector);
- Compose_Transforms (New, &Local_Trans);
- END_CASE
- CASE (MATRIX_TOKEN)
- Parse_Matrix(Local_Matrix);
- Compute_Matrix_Transform(&Local_Trans, Local_Matrix);
- Compose_Transforms (New, &Local_Trans);
- END_CASE
- OTHERWISE
- UNGET
- EXIT
- END_CASE
- END_EXPECT
- Parse_End ();
- return (New);
- }
- /*****************************************************************************
- *
- * FUNCTION
- *
- * INPUT
- *
- * OUTPUT
- *
- * RETURNS
- *
- * AUTHOR
- *
- * DESCRIPTION
- *
- * CHANGES
- *
- ******************************************************************************/
- void Parse_Declare ()
- {
- int Previous=-1; /* tw */
- int Local_Index,Local_Flag;
- SYM_ENTRY *Temp_Entry;
- if ((Local_Flag=(Token.Token_Id==LOCAL_TOKEN))) /* tw */
- {
- Local_Index=Table_Index;
- }
- else
- {
- Local_Index=1;
- }
-
- LValue_Ok = TRUE;
- EXPECT
- CASE (IDENTIFIER_TOKEN)
- Temp_Entry = Add_Symbol (Local_Index,Token.Token_String,IDENTIFIER_TOKEN);
- Token.NumberPtr = &(Temp_Entry->Token_Number);
- Token.DataPtr = &(Temp_Entry->Data);
- Previous = Token.Token_Id;
- EXIT
- END_CASE
- CASE4 (TNORMAL_ID_TOKEN, FINISH_ID_TOKEN, TEXTURE_ID_TOKEN, OBJECT_ID_TOKEN)
- CASE4 (COLOUR_MAP_ID_TOKEN, TRANSFORM_ID_TOKEN, CAMERA_ID_TOKEN, PIGMENT_ID_TOKEN)
- CASE4 (SLOPE_MAP_ID_TOKEN,NORMAL_MAP_ID_TOKEN,TEXTURE_MAP_ID_TOKEN,COLOUR_ID_TOKEN)
- CASE4 (PIGMENT_MAP_ID_TOKEN, MEDIA_ID_TOKEN,STRING_ID_TOKEN,INTERIOR_ID_TOKEN)
- CASE5 (DENSITY_MAP_ID_TOKEN, ARRAY_ID_TOKEN, DENSITY_ID_TOKEN,UV_ID_TOKEN,VECTOR_4D_ID_TOKEN)
- CASE4 (RAINBOW_ID_TOKEN, FOG_ID_TOKEN, SKYSPHERE_ID_TOKEN,MATERIAL_ID_TOKEN)
- if (Local_Flag && (Token.Table_Index != Table_Index))
- {
- Temp_Entry = Add_Symbol (Local_Index,Token.Token_String,IDENTIFIER_TOKEN);
- Token.NumberPtr = &(Temp_Entry->Token_Number);
- Token.DataPtr = &(Temp_Entry->Data);
- Previous = IDENTIFIER_TOKEN;
- }
- else
- {
- Previous = Token.Token_Id;
- }
- EXIT
- END_CASE
- CASE (EMPTY_ARRAY_TOKEN)
- Previous = Token.Token_Id;
- EXIT
- END_CASE
- CASE2 (VECTOR_FUNCT_TOKEN, FLOAT_FUNCT_TOKEN)
- switch(Token.Function_Id)
- {
- case VECTOR_ID_TOKEN:
- case FLOAT_ID_TOKEN:
- if (Local_Flag && (Token.Table_Index != Table_Index))
- {
- Temp_Entry = Add_Symbol (Local_Index,Token.Token_String,IDENTIFIER_TOKEN);
- Token.NumberPtr = &(Temp_Entry->Token_Number);
- Token.DataPtr = &(Temp_Entry->Data);
- }
- Previous = Token.Function_Id;
- break;
- default:
- Parse_Error(IDENTIFIER_TOKEN);
- break;
- }
- EXIT
- END_CASE
- OTHERWISE
- Parse_Error(IDENTIFIER_TOKEN);
- END_CASE
- END_EXPECT
- LValue_Ok = FALSE;
- GET (EQUALS_TOKEN);
-
- if (!Parse_RValue (Previous,Token.NumberPtr,Token.DataPtr, FALSE,TRUE))
- {
- Parse_Error_Str("RValue to declare");
- }
- }
- int Parse_RValue (int Previous, int *NumberPtr, void **DataPtr, int ParFlag, int SemiFlag)
- {
- EXPRESS Local_Express;
- COLOUR *Local_Colour;
- PIGMENT *Local_Pigment;
- TNORMAL *Local_Tnormal;
- FINISH *Local_Finish;
- TEXTURE *Local_Texture, *Temp_Texture;
- TRANSFORM *Local_Trans;
- OBJECT *Local_Object;
- CAMERA *Local_Camera;
- IMEDIA *Local_Media;
- PIGMENT *Local_Density;
- INTERIOR *Local_Interior;
- MATERIAL *Local_Material;
- void *Temp_Data;
- POV_PARAM *New_Par;
- int Found=TRUE;
- int Temp_Count=30000;
- int Old_Ok=Ok_To_Declare;
- int Terms;
-
- EXPECT
- CASE4 (TNORMAL_ID_TOKEN, FINISH_ID_TOKEN, TEXTURE_ID_TOKEN, OBJECT_ID_TOKEN)
- CASE4 (COLOUR_MAP_ID_TOKEN, TRANSFORM_ID_TOKEN, CAMERA_ID_TOKEN, PIGMENT_ID_TOKEN)
- CASE4 (SLOPE_MAP_ID_TOKEN,NORMAL_MAP_ID_TOKEN,TEXTURE_MAP_ID_TOKEN,ARRAY_ID_TOKEN)
- CASE4 (PIGMENT_MAP_ID_TOKEN, MEDIA_ID_TOKEN,INTERIOR_ID_TOKEN,DENSITY_ID_TOKEN)
- CASE4 (DENSITY_MAP_ID_TOKEN, RAINBOW_ID_TOKEN, FOG_ID_TOKEN, SKYSPHERE_ID_TOKEN)
- CASE (MATERIAL_ID_TOKEN)
- if (ParFlag)
- {
- New_Par = (POV_PARAM *)POV_MALLOC(sizeof(POV_PARAM),"parameter");
- New_Par->NumberPtr = Token.NumberPtr;
- New_Par->DataPtr = Token.DataPtr;
- *NumberPtr = PARAMETER_ID_TOKEN;
- *DataPtr = (void *)New_Par;
- }
- else
- {
- Temp_Data = (void *) Copy_Identifier((void *)*Token.DataPtr,*Token.NumberPtr);
- *NumberPtr = *Token.NumberPtr;
- Test_Redefine(Previous,NumberPtr,*DataPtr);
- *DataPtr = Temp_Data;
- }
- EXIT
- END_CASE
- CASE (IDENTIFIER_TOKEN)
- if (ParFlag)
- {
- Error("Cannot pass uninitialized identifier as macro parameter.\nInitialize first.\n");
- }
- else
- {
- Error("Cannot assign uninitialized identifier.\n");
- }
- EXIT
- END_CASE
- CASE_COLOUR
- Local_Colour = Create_Colour();
- Ok_To_Declare = FALSE;
- Parse_Colour (*Local_Colour);
- if (SemiFlag)
- {
- Parse_Semi_Colon();
- }
- Ok_To_Declare = TRUE;
- *NumberPtr = COLOUR_ID_TOKEN;
- Test_Redefine(Previous,NumberPtr,*DataPtr);
- *DataPtr = (void *) Local_Colour;
- EXIT
- END_CASE
- CASE_VECTOR
- Ok_To_Declare = FALSE;
- if (ParFlag &&
- ( ( (Token.Token_Id==FLOAT_FUNCT_TOKEN) &&
- (Token.Function_Id==FLOAT_ID_TOKEN)
- ) ||
- ( (Token.Token_Id==VECTOR_FUNCT_TOKEN) &&
- (Token.Function_Id==VECTOR_ID_TOKEN)
- ) ||
- (Token.Token_Id==VECTOR_4D_ID_TOKEN)
- ||
- (Token.Token_Id==UV_ID_TOKEN)
- )
- )
- {
- Temp_Count=token_count;
- }
- Terms = Parse_Unknown_Vector (Local_Express);
- if (SemiFlag)
- {
- Parse_Semi_Colon();
- }
- Temp_Count -= token_count;
- if ((Temp_Count==-1) || (Temp_Count==1000))
- {
- New_Par = (POV_PARAM *)POV_MALLOC(sizeof(POV_PARAM),"parameter");
- New_Par->NumberPtr = Token.NumberPtr;
- New_Par->DataPtr = Token.DataPtr;
- *NumberPtr = PARAMETER_ID_TOKEN;
- *DataPtr = (void *)New_Par;
- }
- else
- {
- switch(Terms)
- {
- case 1:
- *NumberPtr = FLOAT_ID_TOKEN;
- Test_Redefine(Previous,NumberPtr,*DataPtr);
- *DataPtr = (void *) Create_Float();
- *((DBL *)*DataPtr) = Local_Express[X];
- break;
-
- case 2:
- *NumberPtr = UV_ID_TOKEN;
- Test_Redefine(Previous,NumberPtr,*DataPtr);
- *DataPtr = (void *) Create_UV_Vect();
- Assign_UV_Vect(*DataPtr, Local_Express);
- break;
-
- case 3:
- *NumberPtr = VECTOR_ID_TOKEN;
- Test_Redefine(Previous,NumberPtr,*DataPtr);
- *DataPtr = (void *) Create_Vector();
- Assign_Vector(*DataPtr, Local_Express);
- break;
-
- case 4:
- *NumberPtr = VECTOR_4D_ID_TOKEN;
- Test_Redefine(Previous,NumberPtr,*DataPtr);
- *DataPtr = (void *) Create_Vector_4D();
- Assign_Vector_4D(*DataPtr, Local_Express);
- break;
-
- case 5:
- *NumberPtr = COLOUR_ID_TOKEN;
- Test_Redefine(Previous,NumberPtr,*DataPtr);
- *DataPtr = (void *) Create_Colour();
- Assign_Colour(*DataPtr, Local_Express);
- break;
- }
- }
- Ok_To_Declare = TRUE;
- EXIT
- END_CASE
- CASE (PIGMENT_TOKEN)
- Local_Pigment = Copy_Pigment((Default_Texture->Pigment));
- Parse_Begin ();
- Parse_Pigment (&Local_Pigment);
- Parse_End ();
- *NumberPtr = PIGMENT_ID_TOKEN;
- Test_Redefine(Previous,NumberPtr,*DataPtr);
- *DataPtr = (void *)Local_Pigment;
- EXIT
- END_CASE
- CASE (TNORMAL_TOKEN)
- Local_Tnormal = Copy_Tnormal((Default_Texture->Tnormal));
- Parse_Begin ();
- Parse_Tnormal (&Local_Tnormal);
- Parse_End ();
- *NumberPtr = TNORMAL_ID_TOKEN;
- Test_Redefine(Previous,NumberPtr,*DataPtr);
- *DataPtr = (void *) Local_Tnormal;
- EXIT
- END_CASE
- CASE (FINISH_TOKEN)
- Local_Finish = Copy_Finish((Default_Texture->Finish));
- Parse_Finish (&Local_Finish);
- *NumberPtr = FINISH_ID_TOKEN;
- Test_Redefine(Previous,NumberPtr,*DataPtr);
- *DataPtr = (void *) Local_Finish;
- EXIT
- END_CASE
- CASE (CAMERA_TOKEN)
- Local_Camera = Copy_Camera(Default_Camera);
- Parse_Camera (&Local_Camera);
- *NumberPtr = CAMERA_ID_TOKEN;
- Test_Redefine(Previous,NumberPtr,*DataPtr);
- *DataPtr = (void *) Local_Camera;
- EXIT
- END_CASE
- CASE (TEXTURE_TOKEN)
- Parse_Begin ();
- Local_Texture = Parse_Texture ();
- Parse_End ();
- Temp_Texture=NULL;
- Link_Textures(&Temp_Texture, Local_Texture);
- Ok_To_Declare = FALSE;
- EXPECT
- CASE (TEXTURE_TOKEN)
- Parse_Begin ();
- Local_Texture = Parse_Texture ();
- Parse_End ();
- Link_Textures(&Temp_Texture, Local_Texture);
- END_CASE
- OTHERWISE
- UNGET
- EXIT
- END_CASE
- END_EXPECT
- *NumberPtr = TEXTURE_ID_TOKEN;
- Test_Redefine(Previous,NumberPtr,*DataPtr);
- *DataPtr = (void *)Temp_Texture;
- Ok_To_Declare = TRUE;
- EXIT
- END_CASE
- CASE (COLOUR_MAP_TOKEN)
- Temp_Data=(void *) Parse_Colour_Map ();
- *NumberPtr = COLOUR_MAP_ID_TOKEN;
- Test_Redefine(Previous,NumberPtr,*DataPtr);
- *DataPtr = Temp_Data;
- EXIT
- END_CASE
- CASE (PIGMENT_MAP_TOKEN)
- Temp_Data = (void *) Parse_Blend_Map (PIGMENT_TYPE,NO_PATTERN);
- *NumberPtr = PIGMENT_MAP_ID_TOKEN;
- Test_Redefine(Previous,NumberPtr,*DataPtr);
- *DataPtr = Temp_Data;
- EXIT
- END_CASE
- CASE (DENSITY_MAP_TOKEN)
- Temp_Data = (void *) Parse_Blend_Map (DENSITY_TYPE,NO_PATTERN);
- *NumberPtr = DENSITY_MAP_ID_TOKEN;
- Test_Redefine(Previous,NumberPtr,*DataPtr);
- *DataPtr = Temp_Data;
- EXIT
- END_CASE
- CASE (SLOPE_MAP_TOKEN)
- Temp_Data = (void *) Parse_Blend_Map (SLOPE_TYPE,NO_PATTERN);
- *NumberPtr = SLOPE_MAP_ID_TOKEN;
- Test_Redefine(Previous,NumberPtr,*DataPtr);
- *DataPtr = Temp_Data;
- EXIT
- END_CASE
- CASE (TEXTURE_MAP_TOKEN)
- Temp_Data = (void *) Parse_Blend_Map (TEXTURE_TYPE,NO_PATTERN);
- *NumberPtr = TEXTURE_MAP_ID_TOKEN;
- Test_Redefine(Previous,NumberPtr,*DataPtr);
- *DataPtr = Temp_Data;
- EXIT
- END_CASE
- CASE (NORMAL_MAP_TOKEN)
- Temp_Data = (void *) Parse_Blend_Map (NORMAL_TYPE,NO_PATTERN);
- *NumberPtr = NORMAL_MAP_ID_TOKEN;
- Test_Redefine(Previous,NumberPtr,*DataPtr);
- *DataPtr = Temp_Data;
- EXIT
- END_CASE
- CASE (RAINBOW_TOKEN)
- Temp_Data = (void *) Parse_Rainbow();
- *NumberPtr = RAINBOW_ID_TOKEN;
- Test_Redefine(Previous,NumberPtr,*DataPtr);
- *DataPtr = Temp_Data;
- EXIT
- END_CASE
- CASE (FOG_TOKEN)
- Temp_Data = (void *) Parse_Fog();
- *NumberPtr = FOG_ID_TOKEN;
- Test_Redefine(Previous,NumberPtr,*DataPtr);
- *DataPtr = Temp_Data;
- EXIT
- END_CASE
- CASE (MEDIA_TOKEN)
- Local_Media = NULL;
- Parse_Media(&Local_Media);
- Temp_Data = (void *)Local_Media;
- *NumberPtr = MEDIA_ID_TOKEN;
- Test_Redefine(Previous,NumberPtr,*DataPtr);
- *DataPtr = Temp_Data;
- EXIT
- END_CASE
- CASE (DENSITY_TOKEN)
- Local_Density = NULL;
- Parse_Begin ();
- Parse_Media_Density_Pattern (&Local_Density);
- Parse_End ();
- *NumberPtr = DENSITY_ID_TOKEN;
- Test_Redefine(Previous,NumberPtr,*DataPtr);
- *DataPtr = (void *)Local_Density;
- EXIT
- END_CASE
- CASE (INTERIOR_TOKEN)
- Local_Interior = NULL;
- Parse_Interior(&Local_Interior);
- Temp_Data = (void *)Local_Interior;
- *NumberPtr = INTERIOR_ID_TOKEN;
- Test_Redefine(Previous,NumberPtr,*DataPtr);
- *DataPtr = Temp_Data;
- EXIT
- END_CASE
- CASE (MATERIAL_TOKEN)
- Local_Material = Create_Material();
- Parse_Material(Local_Material);
- Temp_Data = (void *)Local_Material;
- *NumberPtr = MATERIAL_ID_TOKEN;
- Test_Redefine(Previous,NumberPtr,*DataPtr);
- *DataPtr = Temp_Data;
- EXIT
- END_CASE
- CASE (SKYSPHERE_TOKEN)
- Temp_Data = (void *) Parse_Skysphere();
- *NumberPtr = SKYSPHERE_ID_TOKEN;
- Test_Redefine(Previous,NumberPtr,*DataPtr);
- *DataPtr = Temp_Data;
- EXIT
- END_CASE
- CASE (TRANSFORM_TOKEN)
- Local_Trans = Parse_Transform ();
- *NumberPtr = TRANSFORM_ID_TOKEN;
- Test_Redefine(Previous,NumberPtr,*DataPtr);
- *DataPtr = (void *) Local_Trans;
- EXIT
- END_CASE
- CASE4 (STRING_LITERAL_TOKEN,CHR_TOKEN,SUBSTR_TOKEN,STR_TOKEN)
- CASE4 (CONCAT_TOKEN,STRUPR_TOKEN,STRLWR_TOKEN,STRING_ID_TOKEN)
- UNGET
- Temp_Data = Parse_String();
- *NumberPtr = STRING_ID_TOKEN;
- Test_Redefine(Previous,NumberPtr,*DataPtr);
- *DataPtr = Temp_Data;
- EXIT
- END_CASE
- CASE (ARRAY_TOKEN)
- Temp_Data = (void *) Parse_Array_Declare();
- *NumberPtr = ARRAY_ID_TOKEN;
- Test_Redefine(Previous,NumberPtr,*DataPtr);
- *DataPtr = Temp_Data;
- EXIT
- END_CASE
- OTHERWISE
- UNGET
- Local_Object = Parse_Object ();
- Found=(Local_Object!=NULL);
- *NumberPtr = OBJECT_ID_TOKEN;
- Test_Redefine(Previous,NumberPtr,*DataPtr);
- *DataPtr = (void *) Local_Object;
- EXIT
- END_CASE
- END_EXPECT
-
- Ok_To_Declare=Old_Ok;
- return(Found);
- }
- void Destroy_Ident_Data (void *Data, int Type)
- {
- int i;
- POV_ARRAY *a;
- DATA_FILE *Temp_File;
-
- if (Data==NULL)
- {
- return;
- }
- switch (Type)
- {
- case COLOUR_ID_TOKEN:
- Destroy_Colour((COLOUR *)Data);
- break;
- case VECTOR_ID_TOKEN:
- Destroy_Vector((VECTOR *)Data);
- break;
- case UV_ID_TOKEN:
- Destroy_UV_Vect((UV_VECT *)Data);
- break;
- case VECTOR_4D_ID_TOKEN:
- Destroy_Vector((VECTOR_4D *)Data);
- break;
- case FLOAT_ID_TOKEN:
- Destroy_Float((DBL *)Data);
- break;
- case PIGMENT_ID_TOKEN:
- case DENSITY_ID_TOKEN:
- Destroy_Pigment((PIGMENT *)Data);
- break;
- case TNORMAL_ID_TOKEN:
- Destroy_Tnormal((TNORMAL *)Data);
- break;
- case FINISH_ID_TOKEN:
- Destroy_Finish((FINISH *)Data);
- break;
- case MEDIA_ID_TOKEN:
- Destroy_Media((IMEDIA *)Data);
- break;
- case INTERIOR_ID_TOKEN:
- Destroy_Interior((INTERIOR *)Data);
- break;
- case MATERIAL_ID_TOKEN:
- Destroy_Material((MATERIAL *)Data);
- break;
- case TEXTURE_ID_TOKEN:
- Destroy_Textures((TEXTURE *)Data);
- break;
- case OBJECT_ID_TOKEN:
- Destroy_Object((OBJECT *)Data);
- break;
- case COLOUR_MAP_ID_TOKEN:
- case PIGMENT_MAP_ID_TOKEN:
- case SLOPE_MAP_ID_TOKEN:
- case TEXTURE_MAP_ID_TOKEN:
- case NORMAL_MAP_ID_TOKEN:
- case DENSITY_MAP_ID_TOKEN:
- Destroy_Blend_Map((BLEND_MAP *)Data);
- break;
- case TRANSFORM_ID_TOKEN:
- Destroy_Transform((TRANSFORM *)Data);
- break;
- case CAMERA_ID_TOKEN:
- Destroy_Camera((CAMERA *)Data);
- break;
- case RAINBOW_ID_TOKEN:
- Destroy_Rainbow((RAINBOW *)Data);
- break;
- case FOG_ID_TOKEN:
- Destroy_Fog((FOG *)Data);
- break;
- case SKYSPHERE_ID_TOKEN:
- Destroy_Skysphere((SKYSPHERE *)Data);
- break;
- case MACRO_ID_TOKEN:
- Destroy_Macro((POV_MACRO *)Data);
- break;
- case STRING_ID_TOKEN:
- POV_FREE((char *)Data);
- break;
- case ARRAY_ID_TOKEN:
- a=(POV_ARRAY *)Data;
- for (i=0; i<a->Total; i++)
- {
- Destroy_Ident_Data (a->DataPtrs[i],a->Type);
- }
- POV_FREE(a->DataPtrs);
- POV_FREE(a);
- break;
- case PARAMETER_ID_TOKEN:
- POV_FREE(Data);
- break;
- case FILE_ID_TOKEN:
- Temp_File=(DATA_FILE *)Data;
- if (Temp_File->File!=NULL)
- {
- fflush(Temp_File->File);
- fclose(Temp_File->File);
- }
- if (Temp_File->Filename!=NULL)
- {
- POV_FREE(Temp_File->Filename);
- }
- POV_FREE(Data);
- break;
- }
- }
- /*****************************************************************************
- *
- * FUNCTION
- *
- * INPUT
- *
- * OUTPUT
- *
- * RETURNS
- *
- * AUTHOR
- *
- * DESCRIPTION
- *
- * CHANGES
- *
- ******************************************************************************/
- static void Link (OBJECT *New_Object, OBJECT **Field, OBJECT **Old_Object_List)
- {
- *Field = *Old_Object_List;
- *Old_Object_List = New_Object;
- }
- /*****************************************************************************
- *
- * FUNCTION
- *
- * INPUT
- *
- * OUTPUT
- *
- * RETURNS
- *
- * AUTHOR
- *
- * DESCRIPTION
- *
- * CHANGES
- *
- ******************************************************************************/
- void Link_Textures (TEXTURE **Old_Textures, TEXTURE *New_Textures)
- {
- TEXTURE *Layer;
-
- if (New_Textures == NULL)
- return;
- if ((*Old_Textures) != NULL)
- {
- if ((*Old_Textures)->Type != PLAIN_PATTERN)
- {
- Error("Cannot layer over a patterned texture.\n");
- }
- }
- for (Layer = New_Textures ;
- Layer->Next != NULL ;
- Layer = (TEXTURE *)Layer->Next)
- {}
- Layer->Next = (TPATTERN *)*Old_Textures;
- *Old_Textures = New_Textures;
- if ((New_Textures->Type != PLAIN_PATTERN) && (New_Textures->Next != NULL))
- {
- Error("Cannot layer a patterned texture over another.\n");
- }
- }
- /*****************************************************************************
- *
- * FUNCTION
- *
- * INPUT
- *
- * OUTPUT
- *
- * RETURNS
- *
- * AUTHOR
- *
- * DESCRIPTION
- *
- * CHANGES
- *
- ******************************************************************************/
- char *Get_Token_String (TOKEN Token_Id)
- {
- register int i;
- for (i = 0 ; i < LAST_TOKEN ; i++)
- if (Reserved_Words[i].Token_Number == Token_Id)
- return (Reserved_Words[i].Token_Name);
- return ("");
- }
- /*****************************************************************************
- *
- * FUNCTION
- *
- * INPUT
- *
- * OUTPUT
- *
- * RETURNS
- *
- * AUTHOR
- *
- * DESCRIPTION
- *
- * CHANGES
- *
- ******************************************************************************/
- void Test_Redefine(TOKEN Previous, TOKEN *NumberPtr, void *Data)
- {
- char *oldt, *newt;
- if ((Previous == IDENTIFIER_TOKEN) || (Previous == EMPTY_ARRAY_TOKEN))
- {
- return;
- }
-
- if (Previous == *NumberPtr)
- {
- Destroy_Ident_Data(Data,*NumberPtr);
- }
- else
- {
- oldt = Get_Token_String (Previous);
- newt = Get_Token_String (*NumberPtr);
- *NumberPtr = Previous;
-
- Error ("Attempted to redefine %s as %s.", oldt, newt);
- }
- }
- /*****************************************************************************
- *
- * FUNCTION
- *
- * INPUT
- *
- * OUTPUT
- *
- * RETURNS
- *
- * AUTHOR
- *
- * DESCRIPTION
- *
- * CHANGES
- *
- ******************************************************************************/
- void Parse_Error (TOKEN Token_Id)
- {
- char *expected;
- expected = Get_Token_String (Token_Id);
- Parse_Error_Str(expected);
- }
- /*****************************************************************************
- *
- * FUNCTION
- *
- * INPUT
- *
- * OUTPUT
- *
- * RETURNS
- *
- * AUTHOR
- *
- * DESCRIPTION
- *
- * CHANGES
- *
- ******************************************************************************/
- void Parse_Error_Str (char *str)
- {
- Where_Error ();
- Error_Line("%s expected but", str);
- Found_Instead ();
- }
- /*****************************************************************************
- *
- * FUNCTION
- *
- * INPUT
- *
- * OUTPUT
- *
- * RETURNS
- *
- * AUTHOR
- *
- * DESCRIPTION
- *
- * CHANGES
- *
- ******************************************************************************/
- static void Found_Instead ()
- {
- char *found;
-
- Stage=STAGE_FOUND_INSTEAD;
- switch(Token.Token_Id)
- {
- case IDENTIFIER_TOKEN:
- Error (" undeclared identifier '%s' found instead.\n", Token.Token_String);
- break;
-
- case VECTOR_FUNCT_TOKEN:
- found = Get_Token_String (Token.Function_Id);
- Error (" vector function '%s' found instead.\n", found);
- break;
-
- case FLOAT_FUNCT_TOKEN:
- found = Get_Token_String (Token.Function_Id);
- Error (" float function '%s' found instead.\n", found);
- break;
-
- case COLOUR_KEY_TOKEN:
- found = Get_Token_String (Token.Function_Id);
- Error (" color keyword '%s' found instead.\n", found);
- break;
-
- default:
- found = Get_Token_String (Token.Token_Id);
- Error (" %s found instead.\n", found);
- }
- }
-
- /*****************************************************************************
- *
- * FUNCTION
- *
- * INPUT
- *
- * OUTPUT
- *
- * RETURNS
- *
- * AUTHOR
- *
- * DESCRIPTION
- *
- * CHANGES
- *
- ******************************************************************************/
- void Warn_State (TOKEN Token_Id,TOKEN Type)
- {
- char *found;
- char *should;
- found = Get_Token_String (Token_Id);
- should = Get_Token_String (Type);
- Warning (1.5, "%s:%d: warning: Found %s that should be in %s statement.\n",
- Token.Filename, Token.Token_Line_No+1, found, should);
- }
- /*****************************************************************************
- *
- * FUNCTION
- *
- * INPUT
- *
- * OUTPUT
- *
- * RETURNS
- *
- * AUTHOR
- *
- * DESCRIPTION
- *
- * CHANGES
- *
- ******************************************************************************/
- void Warn (DBL Level, char *str)
- {
- if (opts.Language_Version < Level)
- return;
- Warning(Level, "%s:%d: warning: %s\n", Token.Filename, Token.Token_Line_No+1, str);
- }
- /*****************************************************************************
- *
- * FUNCTION
- *
- * INPUT
- *
- * OUTPUT
- *
- * RETURNS
- *
- * AUTHOR
- *
- * DESCRIPTION
- *
- * CHANGES
- *
- ******************************************************************************/
- void MAError (char *str,size_t size)
- {
- Error ("Out of memory. Cannot allocate %ld bytes for %s.\n",size,str);
- }
- /*****************************************************************************
- *
- * FUNCTION
- *
- * INPUT
- *
- * OUTPUT
- *
- * RETURNS
- *
- * AUTHOR
- *
- * DESCRIPTION
- *
- * CHANGES
- *
- ******************************************************************************/
- static void Post_Process (OBJECT *Object,OBJECT *Parent)
- {
- DBL Volume;
- OBJECT *Sib;
- FINISH *Finish;
- if (Object == NULL)
- {
- return;
- }
- if (Object->Type & LT_SRC_UNION_OBJECT)
- {
- for (Sib = ((CSG *)Object)->Children; Sib != NULL; Sib = Sib->Sibling)
- {
- Post_Process(Sib, Object);
- }
- return;
- }
- /* Promote texture etc. from parent to children. */
- if (Parent != NULL)
- {
- if (Object->Texture == NULL)
- {
- Object->Texture = Copy_Texture_Pointer(Parent->Texture);
- }
- if (Object->Interior == NULL)
- {
- Object->Interior = Copy_Interior_Pointer(Parent->Interior);
- }
- if (Test_Flag(Parent, NO_SHADOW_FLAG))
- {
- Set_Flag(Object, NO_SHADOW_FLAG);
- }
- }
- if (Object->Interior != NULL)
- {
- Post_Media(Object->Interior->IMedia);
- }
- if ((Object->Texture == NULL) &&
- !(Object->Type & TEXTURED_OBJECT) &&
- !(Object->Type & LIGHT_SOURCE_OBJECT))
- {
- Object->Texture = Copy_Textures(Default_Texture);
- }
- Post_Textures(Object->Texture); /*moved cey 6/97*/
- if (Object->Type & LIGHT_SOURCE_OBJECT)
- {
- ((LIGHT_SOURCE *)Object)->Next_Light_Source = Frame.Light_Sources;
- Frame.Light_Sources = (LIGHT_SOURCE *)Object;
- Frame.Number_Of_Light_Sources++;
- }
- else
- {
- /* If there is no interior create one. */
- if (Object->Interior == NULL)
- {
- Object->Interior = Create_Interior();
- }
- /* Promote hollow flag to interior. */
- Object->Interior->hollow = (Test_Flag(Object, HOLLOW_FLAG) != FALSE);
- /* Promote finish's IOR to interior IOR. */
- if (Object->Texture != NULL)
- {
- if (Object->Texture->Type == PLAIN_PATTERN)
- {
- if ((Finish = Object->Texture->Finish) != NULL)
- {
- if (Finish->Temp_IOR >= 0.0)
- {
- Object->Interior->IOR = Finish->Temp_IOR;
- }
- if (Finish->Temp_Caustics >= 0.0)
- {
- Object->Interior->Caustics = Finish->Temp_Caustics;
- }
- Object->Interior->Old_Refract = Finish->Temp_Refract;
- }
- }
- }
- /* If there is no IOR specified use the atmopshere ior. */
- if (Object->Interior->IOR == 0.0)
- {
- Object->Interior->IOR = Frame.Atmosphere_IOR;
- }
- }
- if (Object->Type & COMPOUND_OBJECT)
- {
- for (Sib = ((CSG *)Object)->Children; Sib != NULL; Sib = Sib->Sibling)
- {
- Post_Process(Sib, Object);
- }
- }
- /* [removed by CEY 01/98]
- else
- {
- if (Object->Texture != NULL)
- {
- if (Object->Texture->Type == PLAIN_PATTERN)
- {
- if (Object->Texture->Tnormal != NULL)
- {
- Object->Type |= DOUBLE_ILLUMINATE;
- }
- }
- }
- }
- */
- /* Test wether the object is finite or infinite. [DB 9/94] */
- BOUNDS_VOLUME(Volume, Object->BBox);
- if (Volume > INFINITE_VOLUME)
- {
- Set_Flag(Object, INFINITE_FLAG);
- }
- /* Test wether the object is opaque or not. [DB 8/94] */
- if ((Object->Methods != &Blob_Methods) &&
- (Object->Methods != &Mesh_Methods) &&
- (Test_Opacity(Object->Texture)))
- {
- Set_Flag(Object, OPAQUE_FLAG);
- }
- else
- {
- /* Objects with multiple textures have to be handled separately. */
- if (Object->Methods == &Blob_Methods)
- {
- Test_Blob_Opacity((BLOB *)Object);
- }
- if (Object->Methods == &Mesh_Methods)
- {
- Test_Mesh_Opacity((MESH *)Object);
- }
- }
- }
- /*****************************************************************************
- *
- * FUNCTION
- *
- * Link_To_Frame
- *
- * INPUT
- *
- * Object - Pointer to object
- *
- * OUTPUT
- *
- * Object
- *
- * RETURNS
- *
- * AUTHOR
- *
- * POV-Ray Team
- *
- * DESCRIPTION
- *
- * -
- *
- * CHANGES
- *
- * Sep 1994 : Added optional splitting of bounded unions if children are
- * finite. Added removing of unnecessary bounding. [DB]
- *
- ******************************************************************************/
- static void Link_To_Frame(OBJECT *Object)
- {
- int finite;
- DBL Volume;
- OBJECT *This_Sib, *Next_Sib;
- if (Object == NULL) /* patches a memory addressing error jdm mar/95 */
- return;
- /* Remove bounding object if object is cheap to intersect. [DB 8/94] */
- if ((opts.Options & REMOVE_BOUNDS) && (Object->Bound != NULL))
- {
- if ((Object->Methods != &CSG_Union_Methods) &&
- (Object->Methods != &CSG_Intersection_Methods) &&
- (Object->Methods != &CSG_Merge_Methods) &&
- (Object->Methods != &Poly_Methods) &&
- (Object->Methods != &TTF_Methods))
- {
- /* Destroy only, if bounding object is not used as clipping object. */
- if (Object->Bound != Object->Clip)
- {
- Destroy_Object(Object->Bound);
- }
- Object->Bound = NULL;
- Warn(0.0, "Unnecessary bounding object removed.");
- }
- }
- /*
- * Link the object to the frame if it's not a CSG union object,
- * if it's clipped or if bounding slabs aren't used.
- */
- if ((Object->Methods != &CSG_Union_Methods) ||
- (Object->Clip != NULL) ||
- (!opts.Use_Slabs))
- {
- Link(Object, &(Object->Sibling), &(Frame.Objects));
- return;
- }
- /*
- * [DB 8/94]
- *
- * The object is a CSG union object. It will be split if all siblings are
- * finite, i.e. the volume of the bounding box doesn't exceed a threshold.
- */
- if (Object->Bound != NULL)
- {
- /* Test if all siblings are finite. */
- finite = TRUE;
- for (This_Sib = ((CSG *)Object)->Children; This_Sib != NULL; This_Sib = This_Sib->Sibling)
- {
- BOUNDS_VOLUME(Volume, This_Sib->BBox);
- if (Volume > BOUND_HUGE)
- {
- finite = FALSE;
- break;
- }
- }
- /*
- * If the union has infinite children or splitting is not used link
- * the union to the frame.
- */
- if ((!finite) || !(opts.Options & SPLIT_UNION))
- {
- if (finite)
- {
- Warn(0.0, "CSG union unnecessarily bounded.");
- }
- Link(Object, &(Object->Sibling), &(Frame.Objects));
- return;
- }
- Warn(0.0, "Bounded CSG union split.");
- }
- /* Link all siblings of a union to the frame. */
- for (This_Sib = ((CSG *)Object)->Children; This_Sib != NULL; This_Sib = Next_Sib)
- {
- /* Link_To_Frame() changes Sibling so save it */
- Next_Sib = This_Sib->Sibling;
- /* Sibling is no longer inside a CSG object. */
- This_Sib->Type &= ~IS_CHILD_OBJECT;
- Link_To_Frame (This_Sib);
- }
- /*
- Object->Texture = NULL;
- */
- Object->Sibling = NULL;
- ((CSG *)Object)->Children = NULL;
- Destroy_Object (Object);
- }
- /*****************************************************************************
- *
- * FUNCTION
- *
- * INPUT
- *
- * OUTPUT
- *
- * RETURNS
- *
- * AUTHOR
- *
- * DESCRIPTION
- *
- * CHANGES
- *
- ******************************************************************************/
- void Only_In(char *s1,char *s2)
- {
- Error("Keyword '%s' can only be used in a %s statement.",s1,s2);
- }
- /*****************************************************************************
- *
- * FUNCTION
- *
- * INPUT
- *
- * OUTPUT
- *
- * RETURNS
- *
- * AUTHOR
- *
- * DESCRIPTION
- *
- * CHANGES
- *
- ******************************************************************************/
- void Not_With(char *s1,char *s2)
- {
- Error("Keyword '%s' cannot be used %s.",s1,s2);
- }
- void Warn_Compat(int f)
- {
- Warning(0.0,"Use of this syntax ");
- if (f)
- {
- Warning(0.0,"is not");
- }
- else
- {
- Warning(0.0,"may not be");
- }
-
- Warning(0.0," backwards compatable with earlier versions\n%s",
- "of POV-Ray. The #version directive or +MV switch will not help.\n\n");
- }
- /*****************************************************************************
- *
- * FUNCTION
- *
- * Set_CSG_Children_Hollow
- *
- * INPUT
- *
- * OUTPUT
- *
- * RETURNS
- *
- * AUTHOR
- *
- * DESCRIPTION
- *
- * CHANGES
- *
- ******************************************************************************/
- static void Set_CSG_Children_Flag(OBJECT *Object, unsigned long f, unsigned long flag, unsigned long set_flag)
- {
- OBJECT *Sib;
- for (Sib = ((CSG *)Object)->Children; Sib != NULL; Sib = Sib->Sibling)
- {
- if (!Test_Flag(Sib, set_flag))
- {
- if ((Sib->Methods == &CSG_Intersection_Methods) ||
- (Sib->Methods == &CSG_Merge_Methods) ||
- (Sib->Methods == &CSG_Union_Methods))
- {
- Set_CSG_Children_Flag(Sib, f, flag, set_flag);
- }
- else
- {
- Sib->Flags = (Sib->Flags & (~flag)) | f;
- }
- }
- }
- }
- static void *Copy_Identifier (void *Data, int Type)
- {
- int i;
- POV_ARRAY *a, *na;
- VECTOR *vp;
- DBL *dp;
- UV_VECT *uvp;
- VECTOR_4D *v4p;
- void *New;
-
- if (Data==NULL)
- {
- return(NULL);
- }
- switch (Type)
- {
- case COLOUR_ID_TOKEN:
- New = (void *)Copy_Colour(*(COLOUR *)Data);
- break;
- case VECTOR_ID_TOKEN:
- vp = Create_Vector();
- Assign_Vector((*vp),(*((VECTOR *)Data)));
- New=vp;
- break;
- case UV_ID_TOKEN:
- uvp = Create_UV_Vect();
- Assign_Vector((*uvp),(*((UV_VECT *)Data)));
- New=uvp;
- break;
- case VECTOR_4D_ID_TOKEN:
- v4p = Create_Vector_4D();
- Assign_Vector_4D((*v4p),(*((VECTOR_4D *)Data)));
- New=v4p;
- break;
- case FLOAT_ID_TOKEN:
- dp = Create_Float();
- *dp = *((DBL *)Data);
- New = dp;
- break;
- case PIGMENT_ID_TOKEN:
- case DENSITY_ID_TOKEN:
- New = (void *)Copy_Pigment((PIGMENT *)Data);
- break;
- case TNORMAL_ID_TOKEN:
- New = (void *)Copy_Tnormal((TNORMAL *)Data);
- break;
- case FINISH_ID_TOKEN:
- New = (void *)Copy_Finish((FINISH *)Data);
- break;
- case MEDIA_ID_TOKEN:
- New = (void *)Copy_Media((IMEDIA *)Data);
- break;
- case INTERIOR_ID_TOKEN:
- New = (void *)Copy_Interior((INTERIOR *)Data);
- break;
- case MATERIAL_ID_TOKEN:
- New = (void *)Copy_Material((MATERIAL *)Data);
- break;
- case TEXTURE_ID_TOKEN:
- New = (void *)Copy_Textures((TEXTURE *)Data);
- break;
- case OBJECT_ID_TOKEN:
- New = (void *)Copy_Object((OBJECT *)Data);
- break;
- case COLOUR_MAP_ID_TOKEN:
- case PIGMENT_MAP_ID_TOKEN:
- case SLOPE_MAP_ID_TOKEN:
- case TEXTURE_MAP_ID_TOKEN:
- case NORMAL_MAP_ID_TOKEN:
- case DENSITY_MAP_ID_TOKEN:
- New = (void *)Copy_Blend_Map((BLEND_MAP *)Data);
- break;
- case TRANSFORM_ID_TOKEN:
- New = (void *)Copy_Transform((TRANSFORM *)Data);
- break;
- case CAMERA_ID_TOKEN:
- New = (void *)Copy_Camera((CAMERA *)Data);
- break;
- case RAINBOW_ID_TOKEN:
- New = (void *)Copy_Rainbow((RAINBOW *)Data);
- break;
- case FOG_ID_TOKEN:
- New = (void *)Copy_Fog((FOG *)Data);
- break;
- case SKYSPHERE_ID_TOKEN:
- New = (void *)Copy_Skysphere((SKYSPHERE *)Data);
- break;
- case STRING_ID_TOKEN:
- New = (void *)POV_STRDUP((char *)Data);
- break;
- case ARRAY_ID_TOKEN:
- a=(POV_ARRAY *)Data;
- na=(POV_ARRAY *)POV_MALLOC(sizeof(POV_ARRAY),"array");
- *na=*a;
- na->DataPtrs = (void **)POV_MALLOC(sizeof(void *)*(a->Total),"array");
- for (i=0; i<a->Total; i++)
- {
- na->DataPtrs[i] = (void *)Copy_Identifier (a->DataPtrs[i],a->Type);
- }
- New = (void *)na;
- break;
- default:
- Error("Cannot copy identifier");
- New = NULL; /* tw */
- }
- return(New);
- }
|