CesiumMeshVisualizer.js 382 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196
  1. (function () {
  2. var requirejs, require, define;
  3. (function (undef) {
  4. var main, req, makeMap, handlers,
  5. defined = {},
  6. waiting = {},
  7. config = {},
  8. defining = {},
  9. hasOwn = Object.prototype.hasOwnProperty,
  10. aps = [].slice,
  11. jsSuffixRegExp = /\.js$/;
  12. function hasProp(obj, prop) {
  13. return hasOwn.call(obj, prop);
  14. }
  15. /**
  16. * Given a relative module name, like ./something, normalize it to
  17. * a real name that can be mapped to a path.
  18. * @param {String} name the relative name
  19. * @param {String} baseName a real name that the name arg is relative
  20. * to.
  21. * @returns {String} normalized name
  22. */
  23. function normalize(name, baseName) {
  24. var nameParts, nameSegment, mapValue, foundMap, lastIndex,
  25. foundI, foundStarMap, starI, i, j, part, normalizedBaseParts,
  26. baseParts = baseName && baseName.split("/"),
  27. map = config.map,
  28. starMap = (map && map['*']) || {};
  29. //Adjust any relative paths.
  30. if (name) {
  31. name = name.split('/');
  32. lastIndex = name.length - 1;
  33. // If wanting node ID compatibility, strip .js from end
  34. // of IDs. Have to do this here, and not in nameToUrl
  35. // because node allows either .js or non .js to map
  36. // to same file.
  37. if (config.nodeIdCompat && jsSuffixRegExp.test(name[lastIndex])) {
  38. name[lastIndex] = name[lastIndex].replace(jsSuffixRegExp, '');
  39. }
  40. // Starts with a '.' so need the baseName
  41. if (name[0].charAt(0) === '.' && baseParts) {
  42. //Convert baseName to array, and lop off the last part,
  43. //so that . matches that 'directory' and not name of the baseName's
  44. //module. For instance, baseName of 'one/two/three', maps to
  45. //'one/two/three.js', but we want the directory, 'one/two' for
  46. //this normalization.
  47. normalizedBaseParts = baseParts.slice(0, baseParts.length - 1);
  48. name = normalizedBaseParts.concat(name);
  49. }
  50. //start trimDots
  51. for (i = 0; i < name.length; i++) {
  52. part = name[i];
  53. if (part === '.') {
  54. name.splice(i, 1);
  55. i -= 1;
  56. } else if (part === '..') {
  57. // If at the start, or previous value is still ..,
  58. // keep them so that when converted to a path it may
  59. // still work when converted to a path, even though
  60. // as an ID it is less than ideal. In larger point
  61. // releases, may be better to just kick out an error.
  62. if (i === 0 || (i === 1 && name[2] === '..') || name[i - 1] === '..') {
  63. continue;
  64. } else if (i > 0) {
  65. name.splice(i - 1, 2);
  66. i -= 2;
  67. }
  68. }
  69. }
  70. //end trimDots
  71. name = name.join('/');
  72. }
  73. //Apply map config if available.
  74. if ((baseParts || starMap) && map) {
  75. nameParts = name.split('/');
  76. for (i = nameParts.length; i > 0; i -= 1) {
  77. nameSegment = nameParts.slice(0, i).join("/");
  78. if (baseParts) {
  79. //Find the longest baseName segment match in the config.
  80. //So, do joins on the biggest to smallest lengths of baseParts.
  81. for (j = baseParts.length; j > 0; j -= 1) {
  82. mapValue = map[baseParts.slice(0, j).join('/')];
  83. //baseName segment has config, find if it has one for
  84. //this name.
  85. if (mapValue) {
  86. mapValue = mapValue[nameSegment];
  87. if (mapValue) {
  88. //Match, update name to the new value.
  89. foundMap = mapValue;
  90. foundI = i;
  91. break;
  92. }
  93. }
  94. }
  95. }
  96. if (foundMap) {
  97. break;
  98. }
  99. //Check for a star map match, but just hold on to it,
  100. //if there is a shorter segment match later in a matching
  101. //config, then favor over this star map.
  102. if (!foundStarMap && starMap && starMap[nameSegment]) {
  103. foundStarMap = starMap[nameSegment];
  104. starI = i;
  105. }
  106. }
  107. if (!foundMap && foundStarMap) {
  108. foundMap = foundStarMap;
  109. foundI = starI;
  110. }
  111. if (foundMap) {
  112. nameParts.splice(0, foundI, foundMap);
  113. name = nameParts.join('/');
  114. }
  115. }
  116. return name;
  117. }
  118. function makeRequire(relName, forceSync) {
  119. return function () {
  120. //A version of a require function that passes a moduleName
  121. //value for items that may need to
  122. //look up paths relative to the moduleName
  123. var args = aps.call(arguments, 0);
  124. //If first arg is not require('string'), and there is only
  125. //one arg, it is the array form without a callback. Insert
  126. //a null so that the following concat is correct.
  127. if (typeof args[0] !== 'string' && args.length === 1) {
  128. args.push(null);
  129. }
  130. return req.apply(undef, args.concat([relName, forceSync]));
  131. };
  132. }
  133. function makeNormalize(relName) {
  134. return function (name) {
  135. return normalize(name, relName);
  136. };
  137. }
  138. function makeLoad(depName) {
  139. return function (value) {
  140. defined[depName] = value;
  141. };
  142. }
  143. function callDep(name) {
  144. if (hasProp(waiting, name)) {
  145. var args = waiting[name];
  146. delete waiting[name];
  147. defining[name] = true;
  148. main.apply(undef, args);
  149. }
  150. if (!hasProp(defined, name) && !hasProp(defining, name)) {
  151. throw new Error('No ' + name);
  152. }
  153. return defined[name];
  154. }
  155. //Turns a plugin!resource to [plugin, resource]
  156. //with the plugin being undefined if the name
  157. //did not have a plugin prefix.
  158. function splitPrefix(name) {
  159. var prefix,
  160. index = name ? name.indexOf('!') : -1;
  161. if (index > -1) {
  162. prefix = name.substring(0, index);
  163. name = name.substring(index + 1, name.length);
  164. }
  165. return [prefix, name];
  166. }
  167. //Creates a parts array for a relName where first part is plugin ID,
  168. //second part is resource ID. Assumes relName has already been normalized.
  169. function makeRelParts(relName) {
  170. return relName ? splitPrefix(relName) : [];
  171. }
  172. /**
  173. * Makes a name map, normalizing the name, and using a plugin
  174. * for normalization if necessary. Grabs a ref to plugin
  175. * too, as an optimization.
  176. */
  177. makeMap = function (name, relParts) {
  178. var plugin,
  179. parts = splitPrefix(name),
  180. prefix = parts[0],
  181. relResourceName = relParts[1];
  182. name = parts[1];
  183. if (prefix) {
  184. prefix = normalize(prefix, relResourceName);
  185. plugin = callDep(prefix);
  186. }
  187. //Normalize according
  188. if (prefix) {
  189. if (plugin && plugin.normalize) {
  190. name = plugin.normalize(name, makeNormalize(relResourceName));
  191. } else {
  192. name = normalize(name, relResourceName);
  193. }
  194. } else {
  195. name = normalize(name, relResourceName);
  196. parts = splitPrefix(name);
  197. prefix = parts[0];
  198. name = parts[1];
  199. if (prefix) {
  200. plugin = callDep(prefix);
  201. }
  202. }
  203. //Using ridiculous property names for space reasons
  204. return {
  205. f: prefix ? prefix + '!' + name : name, //fullName
  206. n: name,
  207. pr: prefix,
  208. p: plugin
  209. };
  210. };
  211. function makeConfig(name) {
  212. return function () {
  213. return (config && config.config && config.config[name]) || {};
  214. };
  215. }
  216. handlers = {
  217. require: function (name) {
  218. return makeRequire(name);
  219. },
  220. exports: function (name) {
  221. var e = defined[name];
  222. if (typeof e !== 'undefined') {
  223. return e;
  224. } else {
  225. return (defined[name] = {});
  226. }
  227. },
  228. module: function (name) {
  229. return {
  230. id: name,
  231. uri: '',
  232. exports: defined[name],
  233. config: makeConfig(name)
  234. };
  235. }
  236. };
  237. main = function (name, deps, callback, relName) {
  238. var cjsModule, depName, ret, map, i, relParts,
  239. args = [],
  240. callbackType = typeof callback,
  241. usingExports;
  242. //Use name if no relName
  243. relName = relName || name;
  244. relParts = makeRelParts(relName);
  245. //Call the callback to define the module, if necessary.
  246. if (callbackType === 'undefined' || callbackType === 'function') {
  247. //Pull out the defined dependencies and pass the ordered
  248. //values to the callback.
  249. //Default to [require, exports, module] if no deps
  250. deps = !deps.length && callback.length ? ['require', 'exports', 'module'] : deps;
  251. for (i = 0; i < deps.length; i += 1) {
  252. map = makeMap(deps[i], relParts);
  253. depName = map.f;
  254. //Fast path CommonJS standard dependencies.
  255. if (depName === "require") {
  256. args[i] = handlers.require(name);
  257. } else if (depName === "exports") {
  258. //CommonJS module spec 1.1
  259. args[i] = handlers.exports(name);
  260. usingExports = true;
  261. } else if (depName === "module") {
  262. //CommonJS module spec 1.1
  263. cjsModule = args[i] = handlers.module(name);
  264. } else if (hasProp(defined, depName) ||
  265. hasProp(waiting, depName) ||
  266. hasProp(defining, depName)) {
  267. args[i] = callDep(depName);
  268. } else if (map.p) {
  269. map.p.load(map.n, makeRequire(relName, true), makeLoad(depName), {});
  270. args[i] = defined[depName];
  271. } else {
  272. throw new Error(name + ' missing ' + depName);
  273. }
  274. }
  275. ret = callback ? callback.apply(defined[name], args) : undefined;
  276. if (name) {
  277. //If setting exports via "module" is in play,
  278. //favor that over return value and exports. After that,
  279. //favor a non-undefined return value over exports use.
  280. if (cjsModule && cjsModule.exports !== undef &&
  281. cjsModule.exports !== defined[name]) {
  282. defined[name] = cjsModule.exports;
  283. } else if (ret !== undef || !usingExports) {
  284. //Use the return value from the function.
  285. defined[name] = ret;
  286. }
  287. }
  288. } else if (name) {
  289. //May just be an object definition for the module. Only
  290. //worry about defining if have a module name.
  291. defined[name] = callback;
  292. }
  293. };
  294. requirejs = require = req = function (deps, callback, relName, forceSync, alt) {
  295. if (typeof deps === "string") {
  296. if (handlers[deps]) {
  297. //callback in this case is really relName
  298. return handlers[deps](callback);
  299. }
  300. //Just return the module wanted. In this scenario, the
  301. //deps arg is the module name, and second arg (if passed)
  302. //is just the relName.
  303. //Normalize module name, if it contains . or ..
  304. return callDep(makeMap(deps, makeRelParts(callback)).f);
  305. } else if (!deps.splice) {
  306. //deps is a config object, not an array.
  307. config = deps;
  308. if (config.deps) {
  309. req(config.deps, config.callback);
  310. }
  311. if (!callback) {
  312. return;
  313. }
  314. if (callback.splice) {
  315. //callback is an array, which means it is a dependency list.
  316. //Adjust args if there are dependencies
  317. deps = callback;
  318. callback = relName;
  319. relName = null;
  320. } else {
  321. deps = undef;
  322. }
  323. }
  324. //Support require(['a'])
  325. callback = callback || function () { };
  326. //If relName is a function, it is an errback handler,
  327. //so remove it.
  328. if (typeof relName === 'function') {
  329. relName = forceSync;
  330. forceSync = alt;
  331. }
  332. //Simulate async callback;
  333. if (forceSync) {
  334. main(undef, deps, callback, relName);
  335. } else {
  336. //Using a non-zero value because of concern for what old browsers
  337. //do, and latest browsers "upgrade" to 4 if lower value is used:
  338. //http://www.whatwg.org/specs/web-apps/current-work/multipage/timers.html#dom-windowtimers-settimeout:
  339. //If want a value immediately, use require('id') instead -- something
  340. //that works in almond on the global level, but not guaranteed and
  341. //unlikely to work in other AMD implementations.
  342. setTimeout(function () {
  343. main(undef, deps, callback, relName);
  344. }, 4);
  345. }
  346. return req;
  347. };
  348. /**
  349. * Just drops the config on the floor, but returns req in case
  350. * the config return value is used.
  351. */
  352. req.config = function (cfg) {
  353. return req(cfg);
  354. };
  355. /**
  356. * Expose module registry for debugging and tooling
  357. */
  358. requirejs._defined = defined;
  359. define = function (name, deps, callback) {
  360. if (typeof name !== 'string') {
  361. throw new Error('See almond README: incorrect module build, no module name');
  362. }
  363. //This module may not have dependencies
  364. if (!deps.splice) {
  365. //deps is not an array, so probably means
  366. //an object literal or factory function for
  367. //the value. Adjust args.
  368. callback = deps;
  369. deps = [];
  370. }
  371. if (!hasProp(defined, name) && !hasProp(waiting, name)) {
  372. waiting[name] = [name, deps, callback];
  373. }
  374. };
  375. define.amd = {
  376. jQuery: true
  377. };
  378. }());
  379. /**
  380. *
  381. * @namespace Cesium
  382. */
  383. //----CesiumMeshVisualizer----
  384. define('Core/RendererUtils',[],function () {
  385. var Cartesian3 = Cesium.Cartesian3;
  386. var CesiumMath = Cesium.Math;
  387. var yUpToZUp = Cesium.Matrix4.fromRotationTranslation(Cesium.Matrix3.fromRotationX(CesiumMath.PI_OVER_TWO));
  388. var scratchTranslation = new Cesium.Cartesian3();
  389. var scratchQuaternion = new Cesium.Quaternion();
  390. var scratchScale = new Cesium.Cartesian3();
  391. var scratchTranslationQuaternionRotationScale = new Cesium.Matrix4();
  392. var computeModelMatrix = new Cesium.Matrix4();
  393. var scratchPosition = new Cesium.Cartesian3();
  394. var clearCommandScratch = new Cesium.ClearCommand({
  395. color: new Cesium.Color(0.0, 0.0, 0.0, 0.0)
  396. });
  397. /**
  398. *
  399. *@constructor
  400. *@memberof Cesium
  401. */
  402. function RendererUtils() { }
  403. /**
  404. *使用帧缓冲技术,执行渲染命令,渲染到纹理
  405. *@param {Cesium.DrawCommand|Array<Cesium.DrawCommand>}drawCommand 渲染命令(集合)
  406. *@param {Cesium.FrameState}frameState 帧状态对象,可以从Cesium.Scene中获取
  407. *@param {Cesium.Texture}outpuTexture 将渲染到的目标纹理对象
  408. *@param {Cesium.Texture}[outputDepthTexture] 可选,输出的深度纹理
  409. */
  410. RendererUtils.renderToTexture = function (drawCommand, frameState, outputTexture, outputDepthTexture) {
  411. var drawCommands = Array.isArray(drawCommand) ? drawCommand : [drawCommand];
  412. var context = frameState.context;
  413. var framebuffer = null, destroy = false;
  414. if (outputTexture instanceof Cesium.Framebuffer) {
  415. framebuffer = outputTexture;
  416. }
  417. if (!framebuffer) {
  418. framebuffer = new Cesium.Framebuffer({
  419. context: context,
  420. colorTextures: [outputTexture],
  421. destroyAttachments: false,
  422. depthTexture: outputDepthTexture
  423. });
  424. destroy = true;
  425. }
  426. var clearCommand = clearCommandScratch;
  427. clearCommand.framebuffer = framebuffer;
  428. clearCommand.renderState = frameState.renderState;
  429. clearCommand.execute(context);
  430. drawCommands.forEach(function (drawCommand) {
  431. drawCommand.framebuffer = framebuffer;
  432. drawCommand.execute(context);
  433. });
  434. if (destroy) {
  435. framebuffer.destroy();
  436. }
  437. }
  438. /**
  439. *
  440. *@param {Cesium.Matrix4}srcMatrix
  441. *@param {Cesium.Matrix4}dstMatrix
  442. *@param {Cesium.Matrix4}
  443. */
  444. RendererUtils.yUp2Zup = function (srcMatrix, dstMatrix) {
  445. return Cesium.Matrix4.multiplyTransformation(srcMatrix, yUpToZUp, dstMatrix);
  446. }
  447. /**
  448. *平移、旋转或缩放,返回计算之后的模型转换矩阵
  449. *@param {Cesium.Cartesian3}[translation=undefined]
  450. *@param {Object}[rotation=undefined] 旋转参数
  451. *@param {Cesium.Cartesian3}[rotation.axis] 旋转轴
  452. *@param {Number}[rotation.angle] 旋转角度
  453. *@param {Cesium.Cartesian3}[rotation.scale] 缩放
  454. *@param {Cesium.Matrix4}[outModelMatrix] 计算结果矩阵,和返回值一样,但是传递此参数时则返回值不是新创建的Cesium.Matrix4实例
  455. *@return {Cesium.Matrix4}
  456. */
  457. RendererUtils.computeModelMatrix = function (srcModelMatrix, translation, rotation, scale, outModelMatrix) {
  458. if (arguments.length == 0) {
  459. return srcModelMatrix;
  460. }
  461. var Matrix4 = Cesium.Matrix4;
  462. if (!outModelMatrix) {
  463. outModelMatrix = new Matrix4();
  464. }
  465. Matrix4.clone(srcModelMatrix, outModelMatrix);
  466. if (!translation) {
  467. scratchTranslation.x = 0;
  468. scratchTranslation.y = 0;
  469. scratchTranslation.z = 0;
  470. }
  471. scratchTranslation.x = translation.x;
  472. scratchTranslation.y = translation.y;
  473. scratchTranslation.z = translation.z;
  474. if (!scale) {
  475. scratchScale.x = 0;
  476. scratchScale.y = 0;
  477. scratchScale.z = 0;
  478. }
  479. scratchScale.x = scale.x;
  480. scratchScale.y = scale.y;
  481. scratchScale.z = scale.z;
  482. if (rotation instanceof Cesium.Quaternion) {
  483. Cesium.Quaternion.clone(rotation, scratchQuaternion);
  484. } else {
  485. var axis = rotation.axis;
  486. var angle = rotation.angle;
  487. Cesium.Quaternion.fromAxisAngle(
  488. new Cartesian3(axis.x, axis.y, axis.z),//axis.y=1 y是旋转轴
  489. CesiumMath.toRadians(angle),
  490. scratchQuaternion
  491. );
  492. }
  493. //translate,rotate,scale
  494. Matrix4.fromTranslationQuaternionRotationScale(
  495. scratchTranslation, scratchQuaternion,
  496. scratchScale, scratchTranslationQuaternionRotationScale);
  497. Matrix4.multiplyTransformation(
  498. outModelMatrix,
  499. scratchTranslationQuaternionRotationScale,
  500. outModelMatrix);
  501. return outModelMatrix;
  502. }
  503. return RendererUtils;
  504. });
  505. define('Core/Rotation',[],function () {
  506. /**
  507. *
  508. *@param {Cesium.Cartesian3}axis 旋转轴
  509. *@param {Number}angle 旋转角度
  510. *
  511. *@property {Cesium.Cartesian3}axis 旋转轴
  512. *@property {Number}angle 旋转角度
  513. *@property {Cesium.Event}paramChanged
  514. *@constructor
  515. *@memberof Cesium
  516. */
  517. function Rotation(axis, angle) {
  518. this._axis = axis;
  519. this._angle = angle;
  520. this.paramChanged = new Cesium.Event();
  521. }
  522. Object.defineProperties(Rotation.prototype, {
  523. axis: {
  524. set: function (val) {
  525. if (val.x != this._axis.x
  526. || val.y != this._axis.y
  527. || val.z != this._axis.z) {
  528. this._axis = val;
  529. this.paramChanged.raiseEvent();
  530. }
  531. this._axis = val;
  532. },
  533. get: function () {
  534. return this._axis;
  535. }
  536. },
  537. angle: {
  538. set: function (val) {
  539. if (val != this._angle) {
  540. this._angle = val;
  541. this.paramChanged.raiseEvent();
  542. }
  543. this._angle = val;
  544. },
  545. get: function () {
  546. return this._angle;
  547. }
  548. }
  549. })
  550. return Rotation;
  551. });
  552. define('Util/CSG',[],function () {
  553. // Constructive Solid Geometry (CSG) is a modeling technique that uses Boolean
  554. // operations like union and intersection to combine 3D solids. This library
  555. // implements CSG operations on meshes elegantly and concisely using BSP trees,
  556. // and is meant to serve as an easily understandable implementation of the
  557. // algorithm. All edge cases involving overlapping coplanar polygons in both
  558. // solids are correctly handled.
  559. //
  560. // Example usage:
  561. //
  562. // var cube = CSG.cube();
  563. // var sphere = CSG.sphere({ radius: 1.3 });
  564. // var polygons = cube.subtract(sphere).toPolygons();
  565. //
  566. // ## Implementation Details
  567. //
  568. // All CSG operations are implemented in terms of two functions, `clipTo()` and
  569. // `invert()`, which remove parts of a BSP tree inside another BSP tree and swap
  570. // solid and empty space, respectively. To find the union of `a` and `b`, we
  571. // want to remove everything in `a` inside `b` and everything in `b` inside `a`,
  572. // then combine polygons from `a` and `b` into one solid:
  573. //
  574. // a.clipTo(b);
  575. // b.clipTo(a);
  576. // a.build(b.allPolygons());
  577. //
  578. // The only tricky part is handling overlapping coplanar polygons in both trees.
  579. // The code above keeps both copies, but we need to keep them in one tree and
  580. // remove them in the other tree. To remove them from `b` we can clip the
  581. // inverse of `b` against `a`. The code for union now looks like this:
  582. //
  583. // a.clipTo(b);
  584. // b.clipTo(a);
  585. // b.invert();
  586. // b.clipTo(a);
  587. // b.invert();
  588. // a.build(b.allPolygons());
  589. //
  590. // Subtraction and intersection naturally follow from set operations. If
  591. // union is `A | B`, subtraction is `A - B = ~(~A | B)` and intersection is
  592. // `A & B = ~(~A | ~B)` where `~` is the complement operator.
  593. //
  594. // ## License
  595. //
  596. // Copyright (c) 2011 Evan Wallace (http://madebyevan.com/), under the MIT license.
  597. // # class CSG
  598. // Holds a binary space partition tree representing a 3D solid. Two solids can
  599. // be combined using the `union()`, `subtract()`, and `intersect()` methods.
  600. /**
  601. *源码参见{@link https://github.com/jscad/csg.js} <br/>
  602. *Constructive Solid Geometry (CSG) is a modeling technique that uses Boolean<br/>
  603. *operations like union and intersection to combine 3D solids. This library<br/>
  604. *implements CSG operations on meshes elegantly and concisely using BSP trees,<br/>
  605. *and is meant to serve as an easily understandable implementation of the<br/>
  606. *algorithm. All edge cases involving overlapping coplanar polygons in both<br/>
  607. *solids are correctly handled.<br/>
  608. *
  609. *@example
  610. MeshVisualizer = Cesium.MeshVisualizer;
  611. Mesh = Cesium.Mesh;
  612. MeshMaterial = Cesium.MeshMaterial;
  613. CSG = Cesium.CSG;
  614. GeometryUtils = Cesium.GeometryUtils;
  615. //示例1:
  616. var cube = CSG.cube();
  617. var sphere = CSG.sphere({ radius: 1.3 });
  618. var polygons = cube.subtract(sphere).toPolygons();
  619. //示例2:
  620. var center = Cesium.Cartesian3.fromDegrees(homePosition[0], homePosition[1], 50000);
  621. var modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(center);
  622. var meshVisualizer = new MeshVisualizer({
  623. modelMatrix: modelMatrix,
  624. up: { z: 1 }
  625. });
  626. viewer.scene.primitives.add(meshVisualizer);
  627. var material = new MeshMaterial({
  628. defaultColor: "rgba(0,0,255,1.0)",
  629. wireframe: true,
  630. side: MeshMaterial.Sides.DOUBLE
  631. });
  632. //创建盒子
  633. var dimensions = new Cesium.Cartesian3(100000, 50000, 50000);
  634. var boxGeometry = Cesium.BoxGeometry.createGeometry(Cesium.BoxGeometry.fromDimensions({
  635. dimensions: dimensions,
  636. vertexFormat: Cesium.VertexFormat.POSITION_ONLY
  637. }));
  638. var box = GeometryUtils.toCSG(boxGeometry);
  639. var boxMesh = new Mesh(box, material);
  640. meshVisualizer.add(boxMesh);
  641. //创建球体
  642. var sphere = new Cesium.SphereGeometry({
  643. radius: 50000.0,
  644. vertexFormat: Cesium.VertexFormat.POSITION_ONLY
  645. });
  646. sphere = Cesium.SphereGeometry.createGeometry(sphere);
  647. sphere = CSG.toCSG(sphere);
  648. var sphereMesh = new Mesh(sphere, material);
  649. sphereMesh.position = new Cesium.Cartesian3(100000, 0, 0)
  650. meshVisualizer.add(sphereMesh);
  651. //并
  652. var unionResult = box.union(sphere);
  653. var unionResultMesh = new Mesh(unionResult, material);
  654. unionResultMesh.position = new Cesium.Cartesian3(300000, 0, 0)
  655. meshVisualizer.add(unionResultMesh);
  656. //交
  657. var intersectResult = box.intersect(sphere);
  658. var intersectResultMesh = new Mesh(intersectResult, material);
  659. intersectResultMesh.position = new Cesium.Cartesian3(500000, 0, 0)
  660. meshVisualizer.add(intersectResultMesh);
  661. //球体减盒子
  662. var subResult = sphere.subtract(box);
  663. var subResultMesh = new Mesh(subResult, material);
  664. subResultMesh.position = new Cesium.Cartesian3(700000, 0, 0)
  665. meshVisualizer.add(subResultMesh);
  666. //盒子减球体
  667. var subResult2 = box.subtract(sphere);
  668. var subResultMesh2 = new Mesh(subResult2, material);
  669. subResultMesh2.position = new Cesium.Cartesian3(900000, 0, 0)
  670. meshVisualizer.add(subResultMesh2);
  671. //渲染CSG创建的几何体
  672. var cube = CSG.cube({
  673. center: [0, 0, 0],
  674. radius: 20000
  675. });
  676. var cubeMtl = new MeshMaterial({
  677. defaultColor: "rgba(255,0,0,1)"
  678. });
  679. meshVisualizer.add(new Mesh({
  680. geometry: cube,
  681. material: cubeMtl,
  682. position: new Cesium.Cartesian3(-100000, 0, 0)
  683. }));
  684. *@memberof Cesium
  685. *@constructor
  686. */
  687. function CSG() {
  688. this.polygons = [];
  689. };
  690. /**
  691. *Construct a CSG solid from a list of `CSG.Polygon` instances.
  692. *@param {Array<Cesium.CSG.Polygon>}
  693. *@param {Array<Cesium.CSG>}
  694. */
  695. CSG.fromPolygons = function (polygons) {
  696. var csg = new CSG();
  697. csg.polygons = polygons;
  698. return csg;
  699. };
  700. CSG.prototype = {
  701. /**
  702. *@return {Cesium.CSG}
  703. */
  704. clone: function () {
  705. var csg = new CSG();
  706. csg.polygons = this.polygons.map(function (p) { return p.clone(); });
  707. return csg;
  708. },
  709. /**
  710. *
  711. *@return {Array<Cesium.CSG.Polygon>}
  712. */
  713. toPolygons: function () {
  714. return this.polygons;
  715. },
  716. /**
  717. * Return a new CSG solid representing space in either this solid or in the<br/>
  718. * solid `csg`. Neither this solid nor the solid `csg` are modified.<br/>
  719. * <br/>
  720. * A.union(B)<br/>
  721. * <br/>
  722. *<pre><code>
  723. * +-------+ +-------+
  724. * | | | |
  725. * | A | | |
  726. * | +--+----+ = | +----+
  727. * +----+--+ | +----+ |
  728. * | B | | |
  729. * | | | |
  730. * +-------+ +-------+
  731. *</code></pre>
  732. * @param {Cesium.CSG}csg
  733. * @return {Cesium.CSG}
  734. */
  735. union: function (csg) {
  736. var a = new CSG.Node(this.clone().polygons);
  737. var b = new CSG.Node(csg.clone().polygons);
  738. a.clipTo(b);
  739. b.clipTo(a);
  740. b.invert();
  741. b.clipTo(a);
  742. b.invert();
  743. a.build(b.allPolygons());
  744. return CSG.fromPolygons(a.allPolygons());
  745. },
  746. /**
  747. * Return a new CSG solid representing space in this solid but not in the<br/>
  748. * solid `csg`. Neither this solid nor the solid `csg` are modified.<br/>
  749. * <br/>
  750. * A.subtract(B)<br/>
  751. * <br/>
  752. *<pre><code>
  753. * +-------+ +-------+
  754. * | | | |
  755. * | A | | |
  756. * | +--+----+ = | +--+
  757. * +----+--+ | +----+
  758. * | B |
  759. * | |
  760. * +-------+
  761. *
  762. *</code></pre>
  763. * @param {Cesium.CSG}csg
  764. * @return {Cesium.CSG}
  765. */
  766. subtract: function (csg) {
  767. var a = new CSG.Node(this.clone().polygons);
  768. var b = new CSG.Node(csg.clone().polygons);
  769. a.invert();
  770. a.clipTo(b);
  771. b.clipTo(a);
  772. b.invert();
  773. b.clipTo(a);
  774. b.invert();
  775. a.build(b.allPolygons());
  776. a.invert();
  777. return CSG.fromPolygons(a.allPolygons());
  778. },
  779. /**
  780. * Return a new CSG solid representing space both this solid and in the<br/>
  781. * solid `csg`. Neither this solid nor the solid `csg` are modified.<br/>
  782. * <br/>
  783. * A.intersect(B)<br/>
  784. * <br/>
  785. *<pre><code>
  786. * +-------+
  787. * | |
  788. * | A |
  789. * | +--+----+ = +--+
  790. * +----+--+ | +--+
  791. * | B |
  792. * | |
  793. * +-------+
  794. *
  795. *</code></pre>
  796. * @param {Cesium.CSG}csg
  797. * @return {Cesium.CSG}
  798. */
  799. intersect: function (csg) {
  800. var a = new CSG.Node(this.clone().polygons);
  801. var b = new CSG.Node(csg.clone().polygons);
  802. a.invert();
  803. b.clipTo(a);
  804. b.invert();
  805. a.clipTo(b);
  806. b.clipTo(a);
  807. a.build(b.allPolygons());
  808. a.invert();
  809. return CSG.fromPolygons(a.allPolygons());
  810. },
  811. /**
  812. * Return a new CSG solid with solid and empty space switched. This solid is
  813. * not modified.
  814. * @return {Cesium.CSG}
  815. */
  816. inverse: function () {
  817. var csg = this.clone();
  818. csg.polygons.map(function (p) { p.flip(); });
  819. return csg;
  820. }
  821. };
  822. /**
  823. * Construct an axis-aligned solid cuboid. Optional parameters are `center` and<br/>
  824. * `radius`, which default to `[0, 0, 0]` and `[1, 1, 1]`. The radius can be<br/>
  825. * specified using a single number or a list of three numbers, one for each axis.<br/>
  826. *
  827. *@example
  828. *
  829. * var cube = CSG.cube({
  830. * center: [0, 0, 0],
  831. * radius: 1
  832. * });
  833. *@memberof Cesium.CSG
  834. *@param {Object}options
  835. *@param {Array<Number>|Cesium.CSG.Vector}[options.center=[0, 0, 0]]
  836. *@param {Number|Array<Number>|Cesium.CSG.Vector}[options.radius=1]
  837. *@return {Cesium.CSG}
  838. */
  839. CSG.cube = function (options) {
  840. options = options || {};
  841. var c = new CSG.Vector(options.center || [0, 0, 0]);
  842. var r = !options.radius ? [1, 1, 1] : options.radius.length ?
  843. options.radius : [options.radius, options.radius, options.radius];
  844. return CSG.fromPolygons([
  845. [[0, 4, 6, 2], [-1, 0, 0]],
  846. [[1, 3, 7, 5], [+1, 0, 0]],
  847. [[0, 1, 5, 4], [0, -1, 0]],
  848. [[2, 6, 7, 3], [0, +1, 0]],
  849. [[0, 2, 3, 1], [0, 0, -1]],
  850. [[4, 5, 7, 6], [0, 0, +1]]
  851. ].map(function (info) {
  852. return new CSG.Polygon(info[0].map(function (i) {
  853. var pos = new CSG.Vector(
  854. c.x + r[0] * (2 * !!(i & 1) - 1),
  855. c.y + r[1] * (2 * !!(i & 2) - 1),
  856. c.z + r[2] * (2 * !!(i & 4) - 1)
  857. );
  858. return new CSG.Vertex(pos, new CSG.Vector(info[1]));
  859. }));
  860. }));
  861. };
  862. /**
  863. * Construct a solid sphere. Optional parameters are `center`, `radius`,<br/>
  864. * `slices`, and `stacks`, which default to `[0, 0, 0]`, `1`, `16`, and `8`.<br/>
  865. * The `slices` and `stacks` parameters control the tessellation along the<br/>
  866. * longitude and latitude directions.<br/>
  867. *
  868. *@example
  869. *
  870. * var sphere = CSG.sphere({
  871. * center: [0, 0, 0],
  872. * radius: 1,
  873. * slices: 16,
  874. * stacks: 8
  875. * });
  876. *@memberof Cesium.CSG
  877. *@param {Object}options
  878. *@param {Array<Number>|Cesium.CSG.Vector}[options.center=[0, 0, 0]]
  879. *@param {Number}[options.radius=1]
  880. *@param {Number}[options.slices=16]
  881. *@param {Number}[options.stacks=8]
  882. *@return {Cesium.CSG}
  883. */
  884. CSG.sphere = function (options) {
  885. options = options || {};
  886. var c = new CSG.Vector(options.center || [0, 0, 0]);
  887. var r = options.radius || 1;
  888. var slices = options.slices || 16;
  889. var stacks = options.stacks || 8;
  890. var polygons = [], vertices;
  891. function vertex(theta, phi) {
  892. theta *= Math.PI * 2;
  893. phi *= Math.PI;
  894. var dir = new CSG.Vector(
  895. Math.cos(theta) * Math.sin(phi),
  896. Math.cos(phi),
  897. Math.sin(theta) * Math.sin(phi)
  898. );
  899. vertices.push(new CSG.Vertex(c.plus(dir.times(r)), dir));
  900. }
  901. for (var i = 0; i < slices; i++) {
  902. for (var j = 0; j < stacks; j++) {
  903. vertices = [];
  904. vertex(i / slices, j / stacks);
  905. if (j > 0) vertex((i + 1) / slices, j / stacks);
  906. if (j < stacks - 1) vertex((i + 1) / slices, (j + 1) / stacks);
  907. vertex(i / slices, (j + 1) / stacks);
  908. polygons.push(new CSG.Polygon(vertices));
  909. }
  910. }
  911. return CSG.fromPolygons(polygons);
  912. };
  913. /**
  914. * Construct a solid cylinder. Optional parameters are `start`, `end`,<br/>
  915. * `radius`, and `slices`, which default to `[0, -1, 0]`, `[0, 1, 0]`, `1`, and<br/>
  916. * `16`. The `slices` parameter controls the tessellation.<br/>
  917. *
  918. *@example
  919. *
  920. * var cylinder = CSG.cylinder({
  921. * start: [0, -1, 0],
  922. * end: [0, 1, 0],
  923. * radius: 1,
  924. * slices: 16
  925. * });
  926. *@memberof Cesium.CSG
  927. *@param {Object}options
  928. *@param {Array<Number>|Cesium.CSG.Vector}[options.start=[0, -1, 0]]
  929. *@param {Array<Number>|Cesium.CSG.Vector}[options.end=[0, -1, 0]]
  930. *@param {Number}[options.radius=1]
  931. *@param {Number}[options.slices=16]
  932. *@return {Cesium.CSG}
  933. */
  934. CSG.cylinder = function (options) {
  935. options = options || {};
  936. var s = new CSG.Vector(options.start || [0, -1, 0]);
  937. var e = new CSG.Vector(options.end || [0, 1, 0]);
  938. var ray = e.minus(s);
  939. var r = options.radius || 1;
  940. var slices = options.slices || 16;
  941. var axisZ = ray.unit(), isY = (Math.abs(axisZ.y) > 0.5);
  942. var axisX = new CSG.Vector(isY, !isY, 0).cross(axisZ).unit();
  943. var axisY = axisX.cross(axisZ).unit();
  944. var start = new CSG.Vertex(s, axisZ.negated());
  945. var end = new CSG.Vertex(e, axisZ.unit());
  946. var polygons = [];
  947. function point(stack, slice, normalBlend) {
  948. var angle = slice * Math.PI * 2;
  949. var out = axisX.times(Math.cos(angle)).plus(axisY.times(Math.sin(angle)));
  950. var pos = s.plus(ray.times(stack)).plus(out.times(r));
  951. var normal = out.times(1 - Math.abs(normalBlend)).plus(axisZ.times(normalBlend));
  952. return new CSG.Vertex(pos, normal);
  953. }
  954. for (var i = 0; i < slices; i++) {
  955. var t0 = i / slices, t1 = (i + 1) / slices;
  956. polygons.push(new CSG.Polygon([start, point(0, t0, -1), point(0, t1, -1)]));
  957. polygons.push(new CSG.Polygon([point(0, t1, 0), point(0, t0, 0), point(1, t0, 0), point(1, t1, 0)]));
  958. polygons.push(new CSG.Polygon([end, point(1, t1, 1), point(1, t0, 1)]));
  959. }
  960. return CSG.fromPolygons(polygons);
  961. };
  962. /**
  963. * class Vector<br/>
  964. * Represents a 3D vector.
  965. *@example
  966. *
  967. * new CSG.Vector(1, 2, 3);
  968. * new CSG.Vector([1, 2, 3]);
  969. * new CSG.Vector({ x: 1, y: 2, z: 3 });
  970. *
  971. *@memberof Cesium.CSG
  972. *
  973. *@param {Number|Array<Number>|Cesium.CSG.Vector}xOrArrayXYZOrVec
  974. *@param {Number}[y]
  975. *@param {Number}[z]
  976. *
  977. *@property {Number}x
  978. *@property {Number}y
  979. *@property {Number}z
  980. *
  981. *@constructor
  982. */
  983. CSG.Vector = function (x, y, z) {
  984. if (arguments.length == 3) {
  985. this.x = x;
  986. this.y = y;
  987. this.z = z;
  988. } else if ('x' in x) {
  989. this.x = x.x;
  990. this.y = x.y;
  991. this.z = x.z;
  992. } else {
  993. this.x = x[0];
  994. this.y = x[1];
  995. this.z = x[2];
  996. }
  997. };
  998. CSG.Vector.prototype = {
  999. /**
  1000. *@return {Cesium.CSG.Vector}
  1001. */
  1002. clone: function () {
  1003. return new CSG.Vector(this.x, this.y, this.z);
  1004. },
  1005. /**
  1006. *@return {Cesium.CSG.Vector}
  1007. */
  1008. negated: function () {
  1009. return new CSG.Vector(-this.x, -this.y, -this.z);
  1010. },
  1011. /**
  1012. *@param {Cesium.CSG.Vector}a
  1013. *@return {Cesium.CSG.Vector}
  1014. */
  1015. plus: function (a) {
  1016. return new CSG.Vector(this.x + a.x, this.y + a.y, this.z + a.z);
  1017. },
  1018. /**
  1019. *@param {Cesium.CSG.Vector}a
  1020. *@return {Cesium.CSG.Vector}
  1021. */
  1022. minus: function (a) {
  1023. return new CSG.Vector(this.x - a.x, this.y - a.y, this.z - a.z);
  1024. },
  1025. /**
  1026. *@param {Number}a
  1027. *@return {Cesium.CSG.Vector}
  1028. */
  1029. times: function (a) {
  1030. return new CSG.Vector(this.x * a, this.y * a, this.z * a);
  1031. },
  1032. /**
  1033. *@param {Number}a
  1034. *@return {Cesium.CSG.Vector}
  1035. */
  1036. dividedBy: function (a) {
  1037. return new CSG.Vector(this.x / a, this.y / a, this.z / a);
  1038. },
  1039. /**
  1040. *@param {Cesium.CSG.Vector}a
  1041. *@return {Cesium.CSG.Vector}
  1042. */
  1043. dot: function (a) {
  1044. return this.x * a.x + this.y * a.y + this.z * a.z;
  1045. },
  1046. /**
  1047. *@param {Cesium.CSG.Vector}a
  1048. *@param {Number}t
  1049. *@return {Cesium.CSG.Vector}
  1050. */
  1051. lerp: function (a, t) {
  1052. return this.plus(a.minus(this).times(t));
  1053. },
  1054. /**
  1055. *@return {Number}
  1056. */
  1057. length: function () {
  1058. return Math.sqrt(this.dot(this));
  1059. },
  1060. /**
  1061. *@return {Cesium.CSG.Vector}
  1062. */
  1063. unit: function () {
  1064. return this.dividedBy(this.length());
  1065. },
  1066. /**
  1067. *@param {Cesium.CSG.Vector}a
  1068. *@return {Cesium.CSG.Vector}
  1069. */
  1070. cross: function (a) {
  1071. return new CSG.Vector(
  1072. this.y * a.z - this.z * a.y,
  1073. this.z * a.x - this.x * a.z,
  1074. this.x * a.y - this.y * a.x
  1075. );
  1076. }
  1077. };
  1078. /**
  1079. * class Vertex<br/>
  1080. *<br/>
  1081. * Represents a vertex of a polygon. Use your own vertex class instead of this<br/>
  1082. * one to provide additional features like texture coordinates and vertex<br/>
  1083. * colors. Custom vertex classes need to provide a `pos` property and `clone()`,<br/>
  1084. * `flip()`, and `interpolate()` methods that behave analogous to the ones<br/>
  1085. * defined by `CSG.Vertex`. This class provides `normal` so convenience<br/>
  1086. * functions like `CSG.sphere()` can return a smooth vertex normal, but `normal`<br/>
  1087. * is not used anywhere else.<br/>
  1088. *
  1089. *@memberof Cesium.CSG
  1090. *@param {Array<Number>|Cesium.CSG.Vector}pos
  1091. *@param {Array<Number>|Cesium.CSG.Vector}normal
  1092. *
  1093. *@property {Cesium.CSG.Vector}pos
  1094. *@property {Cesium.CSG.Vector}normal
  1095. *
  1096. *@constructor
  1097. */
  1098. CSG.Vertex = function (pos, normal) {
  1099. this.pos = new CSG.Vector(pos);
  1100. this.normal = new CSG.Vector(normal);
  1101. };
  1102. CSG.Vertex.prototype = {
  1103. /**
  1104. *@return {Cesium.CSG.Vertex}
  1105. */
  1106. clone: function () {
  1107. return new CSG.Vertex(this.pos.clone(), this.normal.clone());
  1108. },
  1109. /**
  1110. * Invert all orientation-specific data (e.g. vertex normal). Called when the<br/>
  1111. * orientation of a polygon is flipped.
  1112. *
  1113. */
  1114. flip: function () {
  1115. this.normal = this.normal.negated();
  1116. },
  1117. /**
  1118. * Create a new vertex between this vertex and `other` by linearly<br/>
  1119. * interpolating all properties using a parameter of `t`. Subclasses should<br/>
  1120. * override this to interpolate additional properties.
  1121. *
  1122. *@param {Cesium.CSG.Vertex}
  1123. *@param {Number}
  1124. *@return {Cesium.CSG.Vertex}
  1125. */
  1126. interpolate: function (other, t) {
  1127. return new CSG.Vertex(
  1128. this.pos.lerp(other.pos, t),
  1129. this.normal.lerp(other.normal, t)
  1130. );
  1131. }
  1132. };
  1133. /**
  1134. * class Plane</br/>
  1135. *
  1136. * Represents a plane in 3D space.
  1137. *
  1138. *@memberof Cesium.CSG
  1139. *@param {Array<Number>|Cesium.CSG.Vector}normal
  1140. *@param {Number}w
  1141. *
  1142. *@property {Cesium.CSG.Vector}normal
  1143. *@property {Number}w
  1144. *
  1145. *@constructor
  1146. */
  1147. CSG.Plane = function (normal, w) {
  1148. this.normal = normal;
  1149. this.w = w;
  1150. };
  1151. /**
  1152. * `CSG.Plane.EPSILON` is the tolerance used by `splitPolygon()` to decide if a</br/>
  1153. * point is on the plane.
  1154. */
  1155. CSG.Plane.EPSILON = 1e-5;
  1156. /**
  1157. *
  1158. *
  1159. *@param {Cesium.CSG.Vector}a
  1160. *@param {Cesium.CSG.Vector}b
  1161. *@param {Cesium.CSG.Vector}c
  1162. */
  1163. CSG.Plane.fromPoints = function (a, b, c) {
  1164. var n = b.minus(a).cross(c.minus(a)).unit();
  1165. return new CSG.Plane(n, n.dot(a));
  1166. };
  1167. CSG.Plane.prototype = {
  1168. /**
  1169. *@return {Cesium.CSG.Plane}
  1170. */
  1171. clone: function () {
  1172. return new CSG.Plane(this.normal.clone(), this.w);
  1173. },
  1174. /**
  1175. *
  1176. */
  1177. flip: function () {
  1178. this.normal = this.normal.negated();
  1179. this.w = -this.w;
  1180. },
  1181. /**
  1182. * Split `polygon` by this plane if needed, then put the polygon or polygon<br/>
  1183. * fragments in the appropriate lists. Coplanar polygons go into either<br/>
  1184. * `coplanarFront` or `coplanarBack` depending on their orientation with<br/>
  1185. * respect to this plane. Polygons in front or in back of this plane go into<br/>
  1186. * either `front` or `back`.
  1187. *
  1188. *@param {Cesium.CSG.Polygon}polygon
  1189. *@param {Array<Cesium.CSG.Polygon>}coplanarFront
  1190. *@param {Array<Cesium.CSG.Polygon>}coplanarBack
  1191. *@param {Array<Cesium.CSG.Polygon>}front
  1192. *@param {Array<Cesium.CSG.Polygon>}back
  1193. */
  1194. splitPolygon: function (polygon, coplanarFront, coplanarBack, front, back) {
  1195. var COPLANAR = 0;
  1196. var FRONT = 1;
  1197. var BACK = 2;
  1198. var SPANNING = 3;
  1199. // Classify each point as well as the entire polygon into one of the above
  1200. // four classes.
  1201. var polygonType = 0;
  1202. var types = [];
  1203. for (var i = 0; i < polygon.vertices.length; i++) {
  1204. var t = this.normal.dot(polygon.vertices[i].pos) - this.w;
  1205. var type = (t < -CSG.Plane.EPSILON) ? BACK : (t > CSG.Plane.EPSILON) ? FRONT : COPLANAR;
  1206. polygonType |= type;
  1207. types.push(type);
  1208. }
  1209. // Put the polygon in the correct list, splitting it when necessary.
  1210. switch (polygonType) {
  1211. case COPLANAR:
  1212. (this.normal.dot(polygon.plane.normal) > 0 ? coplanarFront : coplanarBack).push(polygon);
  1213. break;
  1214. case FRONT:
  1215. front.push(polygon);
  1216. break;
  1217. case BACK:
  1218. back.push(polygon);
  1219. break;
  1220. case SPANNING:
  1221. var f = [], b = [];
  1222. for (var i = 0; i < polygon.vertices.length; i++) {
  1223. var j = (i + 1) % polygon.vertices.length;
  1224. var ti = types[i], tj = types[j];
  1225. var vi = polygon.vertices[i], vj = polygon.vertices[j];
  1226. if (ti != BACK) f.push(vi);
  1227. if (ti != FRONT) b.push(ti != BACK ? vi.clone() : vi);
  1228. if ((ti | tj) == SPANNING) {
  1229. var t = (this.w - this.normal.dot(vi.pos)) / this.normal.dot(vj.pos.minus(vi.pos));
  1230. var v = vi.interpolate(vj, t);
  1231. f.push(v);
  1232. b.push(v.clone());
  1233. }
  1234. }
  1235. if (f.length >= 3) front.push(new CSG.Polygon(f, polygon.shared));
  1236. if (b.length >= 3) back.push(new CSG.Polygon(b, polygon.shared));
  1237. break;
  1238. }
  1239. }
  1240. };
  1241. /**
  1242. * class Polygon<br/>
  1243. *<br/>
  1244. * Represents a convex polygon. The vertices used to initialize a polygon must<br/>
  1245. * be coplanar and form a convex loop. They do not have to be `CSG.Vertex`<br/>
  1246. * instances but they must behave similarly (duck typing can be used for<br/>
  1247. * customization).<br/>
  1248. * <br/>
  1249. * Each convex polygon has a `shared` property, which is shared between all<br/>
  1250. * polygons that are clones of each other or were split from the same polygon.<br/>
  1251. * This can be used to define per-polygon properties (such as surface color).<br/>
  1252. *
  1253. *@memberof Cesium.CSG
  1254. *@param {Array<Cesium.CSG.Vertex>}vertices
  1255. *@param {Boolean}shared
  1256. *
  1257. *@property {Array<Cesium.CSG.Vertex>}vertices
  1258. *@property {Boolean}shared
  1259. *@property {Cesium.CSG.Plane}plane
  1260. *@constructor
  1261. */
  1262. CSG.Polygon = function (vertices, shared) {
  1263. this.vertices = vertices;
  1264. this.shared = shared;
  1265. this.plane = CSG.Plane.fromPoints(vertices[0].pos, vertices[1].pos, vertices[2].pos);
  1266. };
  1267. CSG.Polygon.prototype = {
  1268. /**
  1269. *@return {Cesium.CSG.Polygon}
  1270. */
  1271. clone: function () {
  1272. var vertices = this.vertices.map(function (v) { return v.clone(); });
  1273. return new CSG.Polygon(vertices, this.shared);
  1274. },
  1275. /**
  1276. *
  1277. */
  1278. flip: function () {
  1279. this.vertices.reverse().map(function (v) { v.flip(); });
  1280. this.plane.flip();
  1281. }
  1282. };
  1283. /**
  1284. *
  1285. * class Node<br/>
  1286. *<br/>
  1287. * Holds a node in a BSP tree. A BSP tree is built from a collection of polygons<br/>
  1288. * by picking a polygon to split along. That polygon (and all other coplanar<br/>
  1289. * polygons) are added directly to that node and the other polygons are added to<br/>
  1290. * the front and/or back subtrees. This is not a leafy BSP tree since there is<br/>
  1291. * no distinction between internal and leaf nodes.<br/>
  1292. *
  1293. *@memberof Cesium.CSG
  1294. *@param {Array<Cesium.CSG.Polygon>}polygons
  1295. *
  1296. *@property {Array<Cesium.CSG.Polygon>}polygons
  1297. *@property {Cesium.CSG.Plane}plane
  1298. *@property {Cesium.CSG.Plane}front
  1299. *@property {Cesium.CSG.Plane}back
  1300. *@constructor
  1301. */
  1302. CSG.Node = function (polygons) {
  1303. this.plane = null;
  1304. this.front = null;
  1305. this.back = null;
  1306. this.polygons = [];
  1307. if (polygons) this.build(polygons);
  1308. };
  1309. CSG.Node.prototype = {
  1310. /**
  1311. *@return {Cesium.CSG.Node}
  1312. */
  1313. clone: function () {
  1314. var node = new CSG.Node();
  1315. node.plane = this.plane && this.plane.clone();
  1316. node.front = this.front && this.front.clone();
  1317. node.back = this.back && this.back.clone();
  1318. node.polygons = this.polygons.map(function (p) { return p.clone(); });
  1319. return node;
  1320. },
  1321. /**
  1322. * Convert solid space to empty space and empty space to solid space.
  1323. */
  1324. invert: function () {
  1325. for (var i = 0; i < this.polygons.length; i++) {
  1326. this.polygons[i].flip();
  1327. }
  1328. this.plane.flip();
  1329. if (this.front) this.front.invert();
  1330. if (this.back) this.back.invert();
  1331. var temp = this.front;
  1332. this.front = this.back;
  1333. this.back = temp;
  1334. },
  1335. /**
  1336. * Recursively remove all polygons in `polygons` that are inside this BSP<br/>
  1337. * tree.
  1338. *@param {Array<Cesium.CSG.Polygon>}polygons
  1339. *@return {Array<Cesium.CSG.Polygon>}
  1340. */
  1341. clipPolygons: function (polygons) {
  1342. if (!this.plane) return polygons.slice();
  1343. var front = [], back = [];
  1344. for (var i = 0; i < polygons.length; i++) {
  1345. this.plane.splitPolygon(polygons[i], front, back, front, back);
  1346. }
  1347. if (this.front) front = this.front.clipPolygons(front);
  1348. if (this.back) back = this.back.clipPolygons(back);
  1349. else back = [];
  1350. return front.concat(back);
  1351. },
  1352. /**
  1353. * Remove all polygons in this BSP tree that are inside the other BSP tree<br/>
  1354. * `bsp`.
  1355. */
  1356. clipTo: function (bsp) {
  1357. this.polygons = bsp.clipPolygons(this.polygons);
  1358. if (this.front) this.front.clipTo(bsp);
  1359. if (this.back) this.back.clipTo(bsp);
  1360. },
  1361. /**
  1362. * Return a list of all polygons in this BSP tree.
  1363. *@return {Array<Cesium.CSG.Polygon>}
  1364. */
  1365. allPolygons: function () {
  1366. var polygons = this.polygons.slice();
  1367. if (this.front) polygons = polygons.concat(this.front.allPolygons());
  1368. if (this.back) polygons = polygons.concat(this.back.allPolygons());
  1369. return polygons;
  1370. },
  1371. /**
  1372. * Build a BSP tree out of `polygons`. When called on an existing tree, the<br/>
  1373. * new polygons are filtered down to the bottom of the tree and become new<br/>
  1374. * nodes there. Each set of polygons is partitioned using the first polygon<br/>
  1375. * (no heuristic is used to pick a good split).<br/>
  1376. */
  1377. build: function (polygons) {
  1378. if (!polygons.length) return;
  1379. if (!this.plane) this.plane = polygons[0].plane.clone();
  1380. var front = [], back = [];
  1381. for (var i = 0; i < polygons.length; i++) {
  1382. this.plane.splitPolygon(polygons[i], this.polygons, this.polygons, front, back);
  1383. }
  1384. if (front.length) {
  1385. if (!this.front) this.front = new CSG.Node();
  1386. this.front.build(front);
  1387. }
  1388. if (back.length) {
  1389. if (!this.back) this.back = new CSG.Node();
  1390. this.back.build(back);
  1391. }
  1392. }
  1393. };
  1394. /**
  1395. *@param {Cesium.Geometry}
  1396. *@param {Cesium.Cartesian3}[offset]
  1397. *@return {CSG}
  1398. */
  1399. CSG.toCSG = function (geometry, offset) {
  1400. if (!offset) {
  1401. offset = { x: 0, y: 0, z: 0 };
  1402. }
  1403. if (!geometry.attributes.normal) {
  1404. geometry = Cesium.GeometryPipeline.computeNormal(geometry);
  1405. }
  1406. if (geometry.primitiveType !== Cesium.PrimitiveType.TRIANGLES) {
  1407. throw new Error("暂不支持此类几何体");
  1408. }
  1409. if (!CSG) {
  1410. throw new Error('CSG 库未加载。请从 https://github.com/evanw/csg.js 获取');
  1411. }
  1412. var faceCount = geometry.indices.length / 3;
  1413. var polygons = [], vertices = [];
  1414. var positions = geometry.attributes.position.values;
  1415. var normals = geometry.attributes.normal.values;
  1416. var normalIdx = 0, positionIdx = 0;
  1417. for (var i = 0; i < geometry.indices.length ; i += 3) {
  1418. vertices = [];
  1419. var idx1 = geometry.indices[i];
  1420. var idx2 = geometry.indices[i + 1];
  1421. var idx3 = geometry.indices[i + 2];
  1422. positionIdx = idx1 * 3;
  1423. normalIdx = idx1 * 3;
  1424. vertices.push(new CSG.Vertex(
  1425. [positions[positionIdx++] + offset.x, positions[positionIdx++] + offset.y, positions[positionIdx++] + offset.z],
  1426. [normals[normalIdx++], normals[normalIdx++], normals[normalIdx++]]
  1427. ));
  1428. positionIdx = idx2 * 3;
  1429. normalIdx = idx2 * 3;
  1430. vertices.push(new CSG.Vertex(
  1431. [positions[positionIdx++] + offset.x, positions[positionIdx++] + offset.y, positions[positionIdx++] + offset.z],
  1432. [normals[normalIdx++], normals[normalIdx++], normals[normalIdx++]]
  1433. ));
  1434. positionIdx = idx3 * 3;
  1435. normalIdx = idx3 * 3;
  1436. vertices.push(new CSG.Vertex(
  1437. [positions[positionIdx++] + offset.x, positions[positionIdx++] + offset.y, positions[positionIdx++] + offset.z],
  1438. [normals[normalIdx++], normals[normalIdx++], normals[normalIdx++]]
  1439. ));
  1440. polygons.push(new CSG.Polygon(vertices));
  1441. }
  1442. return CSG.fromPolygons(polygons);
  1443. }
  1444. /**
  1445. *@param {CSG}csg_model
  1446. *@return {Cesium.Geometry}
  1447. */
  1448. CSG.fromCSG = function (csg_model) {
  1449. var i, j, vertices,
  1450. polygons = csg_model.toPolygons();
  1451. if (!CSG) {
  1452. throw new Error('CSG 库未加载。请从 https://github.com/evanw/csg.js 获取');
  1453. }
  1454. var positions = [];
  1455. var normals = [];
  1456. var indices = [];
  1457. for (i = 0; i < polygons.length; i++) {
  1458. // Vertices
  1459. vertices = [];
  1460. for (j = 0; j < polygons[i].vertices.length; j++) {
  1461. vertices.push(this.getGeometryVertice(positions, normals, polygons[i].vertices[j].pos, polygons[i].plane.normal));
  1462. }
  1463. if (vertices[0] === vertices[vertices.length - 1]) {
  1464. vertices.pop();
  1465. }
  1466. for (var j = 2; j < vertices.length; j++) {
  1467. indices.push(vertices[0], vertices[j - 1], vertices[j]);
  1468. }
  1469. }
  1470. positions = new Float32Array(positions);
  1471. normals = new Float32Array(normals);
  1472. indices = new Int32Array(indices);
  1473. var attributes = {};
  1474. attributes.position = new Cesium.GeometryAttribute({
  1475. componentDatatype: Cesium.ComponentDatatype.FLOAT,
  1476. componentsPerAttribute: 3,
  1477. values: positions
  1478. });
  1479. attributes.normal = new Cesium.GeometryAttribute({
  1480. componentDatatype: Cesium.ComponentDatatype.FLOAT,
  1481. componentsPerAttribute: 3,
  1482. values: normals
  1483. });
  1484. var cesGeometry = new Cesium.Geometry({
  1485. attributes: attributes,
  1486. indices: indices,
  1487. primitiveType: Cesium.PrimitiveType.TRIANGLES
  1488. });
  1489. return cesGeometry;
  1490. },
  1491. /**
  1492. *@param {Array<Number>}positions
  1493. *@param {Array<Number>}normals
  1494. *@param {Cesium.CSG.Vector}vertice_position
  1495. *@param {Cesium.CSG.Vector}plane_normal
  1496. *@return {Number}
  1497. *@private
  1498. */
  1499. CSG.getGeometryVertice = function (positions, normals, vertice_position, plane_normal) {
  1500. var i, idx = 0;
  1501. for (i = 0; i < positions.length; i += 3) {
  1502. if (positions[i] === vertice_position.x
  1503. && positions[i + 1] === vertice_position.y
  1504. && positions[i + 2] === vertice_position.z) {
  1505. // Vertice already exists
  1506. return idx;
  1507. }
  1508. idx++;
  1509. };
  1510. positions.push(vertice_position.x, vertice_position.y, vertice_position.z);
  1511. normals.push(plane_normal.x, plane_normal.y, plane_normal.z);
  1512. return idx;
  1513. }
  1514. return CSG;
  1515. });
  1516. define('Util/defineProperty',[],function () {
  1517. /**
  1518. *定义属性,并监听属性变化事件,属性值的数据类型可以实现equals接口用于进行更进一步的比较
  1519. *@param {Object}owner
  1520. *@param {String}name
  1521. *@param {Any}defaultVal
  1522. *@param {Function}onChanged
  1523. *@memberof Cesium
  1524. */
  1525. function defineProperty(owner, name, defaultVal, onChanged) {
  1526. owner["_" + name] = defaultVal;
  1527. var value = {
  1528. get: function () {
  1529. return this["_" + name];
  1530. },
  1531. set: function (val) {
  1532. var changed = val != this["_" + name];
  1533. if (this["_" + name] && this["_" + name].equals && val) {
  1534. changed = this["_" + name].equals(val);
  1535. }
  1536. this["_" + name] = val;
  1537. if (typeof onChanged == 'function' && changed) {
  1538. onChanged(changed, owner);
  1539. }
  1540. }
  1541. };
  1542. var properties = {};
  1543. properties[name] = value;
  1544. Object.defineProperties(owner, properties)
  1545. }
  1546. return defineProperty;
  1547. });
  1548. define('Core/MeshMaterial',['Util/defineProperty'], function (defineProperty) {
  1549. var defaultValue = Cesium.defaultValue;
  1550. /**
  1551. *
  1552. *@param {Object}options
  1553. *@param {Object}[options.uniforms]
  1554. *@param {Object}[options.uniformStateUsed]
  1555. *@param {Boolean}[options.translucent]
  1556. *@param {Boolean}[options.wireframe]
  1557. *@param {Enum}[options.side=Cesium.MeshMaterial.Sides.DOUBLE]
  1558. *@param {String|Cesium.Color}[options.defaultColor=Cesium.Color.WHITE]
  1559. *@param {String}[options.vertexShader]
  1560. *@param {String}[options.fragmentShader]
  1561. *
  1562. *
  1563. *@property {Object}uniforms
  1564. *@property {Object}uniformStateUsed
  1565. *@property {Boolean}translucent
  1566. *@property {Boolean}wireframe
  1567. *@property {Enum}side
  1568. *@property {String|Cesium.Color}defaultColor
  1569. *@property {String}vertexShader
  1570. *@property {String}fragmentShader
  1571. *
  1572. *@constructor
  1573. *@memberof Cesium
  1574. */
  1575. function MeshMaterial(options) {
  1576. options = defaultValue(options, {});
  1577. options.uniforms = defaultValue(options.uniforms, {});
  1578. var that = this;
  1579. this._uuid = Cesium.createGuid();
  1580. function initUniform(srcUniforms) {
  1581. var _uniforms = {};
  1582. for (var i in srcUniforms) {
  1583. if (srcUniforms.hasOwnProperty(i) && Cesium.defined(srcUniforms[i])) {
  1584. var item = srcUniforms[i];
  1585. var val = {};
  1586. val.needsUpdate = true;
  1587. if (Array.isArray(item) && item.length >= 3 && item.length <= 4 && typeof item[0] === 'number') {
  1588. srcUniforms[i] = new Cesium.Color(srcUniforms[i][0], srcUniforms[i][1], srcUniforms[i][2], srcUniforms[i][3]);
  1589. } else if (Cesium.defined(item.value)) {
  1590. for (var n in item) {
  1591. if (item.hasOwnProperty(n)) {
  1592. val[n] = item[n];
  1593. }
  1594. }
  1595. }
  1596. if (srcUniforms[i].hasOwnProperty("uuid")) {
  1597. defineProperty(val, "uuid", srcUniforms[i].uuid, function (changed, owner) {
  1598. owner.needsUpdate = changed;
  1599. });
  1600. } else {
  1601. defineProperty(val, "uuid", Cesium.createGuid(), function (changed, owner) {
  1602. owner.needsUpdate = changed;
  1603. });
  1604. }
  1605. if (srcUniforms[i].hasOwnProperty("value")) {
  1606. defineProperty(val, "value", srcUniforms[i].value, function (changed, owner) {
  1607. owner.needsUpdate = changed;
  1608. });
  1609. } else {
  1610. defineProperty(val, "value", srcUniforms[i], function (changed, owner) {
  1611. owner.needsUpdate = changed;
  1612. });
  1613. }
  1614. _uniforms[i] = val;
  1615. //defineProperty(_uniforms, i, val, function (changed) {
  1616. // that.needsUpdate = changed;
  1617. //});
  1618. }
  1619. }
  1620. return _uniforms;
  1621. }
  1622. this._defaultColor = defaultValue(options.defaultColor, Cesium.Color.WHITE);
  1623. if (typeof this._defaultColor == 'string') {
  1624. this._defaultColor = Cesium.Color.fromCssColorString(this._defaultColor);
  1625. }
  1626. this._pickedColor = defaultValue(options.pickedColor, Cesium.Color.YELLOW);
  1627. if (typeof this._pickedColor == 'string') {
  1628. this._pickedColor = Cesium.Color.fromCssColorString(this._pickedColor);
  1629. }
  1630. this._picked = defaultValue(options.picked, 0);
  1631. options.uniforms.pickedColor = this._pickedColor;
  1632. options.uniforms.defaultColor = this._defaultColor;
  1633. options.uniforms.picked = this._picked;
  1634. this._uniforms = initUniform(options.uniforms);
  1635. function onPropertyChanged(changed) {
  1636. that.needsUpdate = changed;
  1637. }
  1638. defineProperty(this, "translucent", defaultValue(options.translucent, false), onPropertyChanged);
  1639. defineProperty(this, "wireframe", defaultValue(options.wireframe, false), onPropertyChanged);
  1640. defineProperty(this, "side", defaultValue(options.side, MeshMaterial.Sides.DOUBLE), onPropertyChanged);
  1641. defineProperty(this, "uniformStateUsed", defaultValue(options.uniformStateUsed, [{
  1642. uniformStateName: "model",
  1643. glslVarName: "modelMatrix"
  1644. }]), onPropertyChanged);
  1645. defineProperty(this, "uniforms", this._uniforms, function () {
  1646. that._uniforms = initUniform(that._uniforms);
  1647. });
  1648. this._vertexShader = '//#inner\n void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\n}';
  1649. this._fragmentShader = '//#inner' + this._uuid + '\n uniform float picked;\n uniform vec4 pickedColor;\n uniform vec4 defaultColor;\n void main() {\ngl_FragColor = defaultColor;\n if(picked!=0.0){\ngl_FragColor = pickedColor;}}';// vec4( ' + this._defaultColor.red + ',' + this._defaultColor.green + ',' + this._defaultColor.blue + ',' + this._defaultColor.alpha + ');\n}';
  1650. defineProperty(this, "vertexShader", defaultValue(options.vertexShader, this._vertexShader), onPropertyChanged);
  1651. defineProperty(this, "fragmentShader", defaultValue(options.fragmentShader, this._fragmentShader), onPropertyChanged);
  1652. this.depthTest =defaultValue(options.depthTest, true);
  1653. this.depthMask = defaultValue(options.depthMask, true);
  1654. this.blending = defaultValue(options.blending, true);
  1655. this.needsUpdate = true;
  1656. }
  1657. Object.defineProperties(MeshMaterial.prototype, {
  1658. uuid: {
  1659. get: function () {
  1660. return this._uuid;
  1661. }
  1662. },
  1663. defaultColor: {
  1664. set: function (val) {
  1665. if (typeof val == 'string') {
  1666. val = Cesium.Color.fromCssColorString(val);
  1667. }
  1668. Cesium.Color.clone(val, this._defaultColor);
  1669. },
  1670. get: function () {
  1671. return this._defaultColor;
  1672. }
  1673. }
  1674. });
  1675. /**
  1676. *
  1677. *@memberof Cesium.MeshMaterial
  1678. *@property {Enum}FRONT
  1679. *@property {Enum}BACK
  1680. *@property {Enum}DOUBLE
  1681. */
  1682. MeshMaterial.Sides = {
  1683. FRONT: 3,
  1684. BACK: 1,
  1685. DOUBLE: 2
  1686. }
  1687. return MeshMaterial;
  1688. });
  1689. define('Core/GeometryUtils',[
  1690. 'Util/CSG'
  1691. ], function (CSG) {
  1692. /**
  1693. *
  1694. *@constructor
  1695. *@memberof Cesium
  1696. */
  1697. function GeometryUtils() {
  1698. }
  1699. function getAttrs(geo) {
  1700. var attrNames = [];
  1701. for (var name in geo.attributes) {
  1702. if (geo.attributes.hasOwnProperty(name) && geo.attributes[name]) {
  1703. attrNames.push(name);
  1704. }
  1705. }
  1706. return attrNames
  1707. }
  1708. var scratchPosition = new Cesium.Cartesian3();
  1709. var scratchQuaternion = new Cesium.Quaternion();
  1710. var scratchMatrix4 = new Cesium.Matrix4();
  1711. var scratchRotation = new Cesium.Matrix3();
  1712. /**
  1713. *绕x轴旋转,修改顶点坐标
  1714. *@param {Cesium.Geometry}geometry
  1715. *@param {Number}angle 弧度
  1716. */
  1717. GeometryUtils.rotateX = function (geometry, angle) {
  1718. var positions = geometry.attributes.position.values;
  1719. Cesium.Matrix3.fromRotationX(angle, scratchRotation);
  1720. Cesium.Matrix4.fromRotationTranslation(scratchRotation, Cesium.Cartesian3.ZERO, scratchMatrix4);
  1721. for (var i = 0; i < positions.length; i += 3) {
  1722. scratchPosition.x = positions[i];
  1723. scratchPosition.y = positions[i + 1];
  1724. scratchPosition.z = positions[i + 2];
  1725. Cesium.Matrix4.multiplyByPoint(scratchMatrix4, scratchPosition, scratchPosition);
  1726. positions[i] = scratchPosition.x;
  1727. positions[i + 1] = scratchPosition.y;
  1728. positions[i + 2] = scratchPosition.z;
  1729. }
  1730. }
  1731. /**
  1732. *绕y轴旋转,修改顶点坐标
  1733. *@param {Cesium.Geometry}geometry
  1734. *@param {Number}angle 弧度
  1735. */
  1736. GeometryUtils.rotateY = function (geometry, angle) {
  1737. var positions = geometry.attributes.position.values;
  1738. Cesium.Matrix3.fromRotationY(angle, scratchRotation);
  1739. Cesium.Matrix4.fromRotationTranslation(scratchRotation, Cesium.Cartesian3.ZERO, scratchMatrix4);
  1740. for (var i = 0; i < positions.length; i += 3) {
  1741. scratchPosition.x = positions[i];
  1742. scratchPosition.y = positions[i + 1];
  1743. scratchPosition.z = positions[i + 2];
  1744. Cesium.Matrix4.multiplyByPoint(scratchMatrix4, scratchPosition, scratchPosition);
  1745. positions[i] = scratchPosition.x;
  1746. positions[i + 1] = scratchPosition.y;
  1747. positions[i + 2] = scratchPosition.z;
  1748. }
  1749. }
  1750. /**
  1751. *绕z轴旋转,修改顶点坐标
  1752. *@param {Cesium.Geometry}geometry
  1753. *@param {Number}angle 弧度
  1754. */
  1755. GeometryUtils.rotateZ = function (geometry, angle) {
  1756. var positions = geometry.attributes.position.values;
  1757. Cesium.Matrix3.fromRotationZ(angle, scratchRotation);
  1758. Cesium.Matrix4.fromRotationTranslation(scratchRotation, Cesium.Cartesian3.ZERO, scratchMatrix4);
  1759. for (var i = 0; i < positions.length; i += 3) {
  1760. scratchPosition.x = positions[i];
  1761. scratchPosition.y = positions[i + 1];
  1762. scratchPosition.z = positions[i + 2];
  1763. Cesium.Matrix4.multiplyByPoint(scratchMatrix4, scratchPosition, scratchPosition);
  1764. positions[i] = scratchPosition.x;
  1765. positions[i + 1] = scratchPosition.y;
  1766. positions[i + 2] = scratchPosition.z;
  1767. }
  1768. }
  1769. /**
  1770. *
  1771. *@param {Cesium.Geometry}geometry
  1772. */
  1773. GeometryUtils.computeVertexNormals = function (geometry) {
  1774. var indices = geometry.indices;
  1775. var attributes = geometry.attributes;
  1776. var il = indices.length;
  1777. if (attributes.position) {
  1778. var positions = attributes.position.values;
  1779. if (attributes.normal === undefined) {
  1780. attributes.normal = new Cesium.GeometryAttribute({
  1781. componentDatatype: Cesium.ComponentDatatype.FLOAT,
  1782. componentsPerAttribute: 3,
  1783. values: new Float32Array(positions.length)
  1784. })
  1785. } else {
  1786. // reset existing normals to zero
  1787. var array = attributes.normal.values;
  1788. for (var i = 0; i < il; i++) {
  1789. array[i] = 0;
  1790. }
  1791. }
  1792. var normals = attributes.normal.values;
  1793. var vA, vB, vC;
  1794. var pA = new Cesium.Cartesian3(), pB = new Cesium.Cartesian3(), pC = new Cesium.Cartesian3();
  1795. var cb = new Cesium.Cartesian3(), ab = new Cesium.Cartesian3();
  1796. for (var i = 0; i < il; i += 3) {
  1797. vA = indices[i + 0] * 3;
  1798. vB = indices[i + 1] * 3;
  1799. vC = indices[i + 2] * 3;
  1800. Cesium.Cartesian3.fromArray(positions, vA, pA);
  1801. Cesium.Cartesian3.fromArray(positions, vB, pB);
  1802. Cesium.Cartesian3.fromArray(positions, vC, pC);
  1803. Cesium.Cartesian3.subtract(pC, pB, cb);
  1804. Cesium.Cartesian3.subtract(pA, pB, ab);
  1805. Cesium.Cartesian3.cross(cb, ab, cb);
  1806. normals[vA] += cb.x;
  1807. normals[vA + 1] += cb.y;
  1808. normals[vA + 2] += cb.z;
  1809. normals[vB] += cb.x;
  1810. normals[vB + 1] += cb.y;
  1811. normals[vB + 2] += cb.z;
  1812. normals[vC] += cb.x;
  1813. normals[vC + 1] += cb.y;
  1814. normals[vC + 2] += cb.z;
  1815. }
  1816. normalizeNormals(geometry);
  1817. attributes.normal.needsUpdate = true;
  1818. }
  1819. return geometry;
  1820. }
  1821. function normalizeNormals(geometry) {
  1822. var normals = geometry.attributes.normal.values;
  1823. var x, y, z, n;
  1824. for (var i = 0; i < normals.length; i += 3) {
  1825. x = normals[i];
  1826. y = normals[i + 1];
  1827. z = normals[i + 2];
  1828. n = 1.0 / Math.sqrt(x * x + y * y + z * z);
  1829. normals[i] = x * n;
  1830. normals[i + 1] = y * n;
  1831. normals[i + 2] = z * n;
  1832. }
  1833. }
  1834. /**
  1835. *合并两个或两个以上图形类型(primitiveType),属性数量、名称以及属性值的类型(GeometryAttribute的componentDatatype、componentsPerAttribute等)都一致的几何体
  1836. *@param {Array<Cesium.Geometry>}geometries
  1837. *@return {Cesium.Geometry}
  1838. */
  1839. GeometryUtils.mergeGeometries = function (geometries) {
  1840. if (!geometries || !geometries.length) {
  1841. throw new Error("缺少geometries参数");
  1842. }
  1843. if (geometries.length == 1) {
  1844. return geometries[0];
  1845. }
  1846. var geometriesAttrs = [];
  1847. var lengthChanged = false;
  1848. var primitiveTypeChanged = false;
  1849. var primitiveType = geometries[0].primitiveType;
  1850. for (var i = 0; i < geometries.length; i++) {
  1851. geometriesAttrs[i] = getAttrs(geometries[i]);
  1852. if (i > 0) {
  1853. if (primitiveType != geometries[i].primitiveType) {
  1854. primitiveTypeChanged = true;
  1855. break;
  1856. }
  1857. var lastGeoAttrs = geometriesAttrs[i - 1];
  1858. lengthChanged = lastGeoAttrs.length != geometriesAttrs[i].length;
  1859. if (!lengthChanged) {
  1860. for (var j = 0; j < lastGeoAttrs.length; j++) {
  1861. if (lastGeoAttrs[j] != geometriesAttrs[i][j]) {
  1862. lengthChanged = true;
  1863. break;
  1864. }
  1865. }
  1866. }
  1867. }
  1868. primitiveType = geometries[i].primitiveType;
  1869. if (lengthChanged || primitiveTypeChanged) {
  1870. break;
  1871. }
  1872. }
  1873. if (primitiveTypeChanged) {
  1874. throw new Error("待合并的几何体中primitiveType属性不完全一致");
  1875. }
  1876. if (lengthChanged) {
  1877. throw new Error("待合并的几何体中属性数量和和名称不完全一致");
  1878. }
  1879. var newAttrs = {};
  1880. var attrNames = geometriesAttrs[0];
  1881. for (var i = 0; i < attrNames.length; i++) {
  1882. var attrName = attrNames[i];
  1883. var geometry = geometries[0];
  1884. newAttrs[attrName] = {};
  1885. //newAttrs[attrName] = Cesium.clone(geometry.attributes[attrName]);
  1886. for (var n in geometry.attributes[attrName]) {
  1887. if (geometry.attributes[attrName].hasOwnProperty(n)) {
  1888. newAttrs[attrName][n] = geometry.attributes[attrName][n];
  1889. }
  1890. }
  1891. var values = Array.from(newAttrs[attrName].values);
  1892. for (var j = 1; j < geometries.length; j++) {
  1893. geometry = geometries[j];
  1894. for (var vi = 0; vi < geometry.attributes[attrName].values.length; vi++) {
  1895. values.push(geometry.attributes[attrName].values[vi]);
  1896. }
  1897. }
  1898. newAttrs[attrName].values = new newAttrs[attrName].values.constructor(values);
  1899. }
  1900. var indices = [];
  1901. var currIndex = 0;
  1902. for (var j = 0; j < geometries.length; j++) {
  1903. var geometry = geometries[0];
  1904. for (var i = 0; i < geometry.indices.length; i++) {
  1905. indices.push(geometry.indices[i] + currIndex);
  1906. }
  1907. currIndex += geometry.attributes.position.values.length / 3;
  1908. }
  1909. var bs = Cesium.BoundingSphere.fromVertices(newAttrs.position.values);
  1910. var geo = new Cesium.Geometry({
  1911. attributes: newAttrs,
  1912. indices: new Int32Array(indices),
  1913. primitiveType: geometries[0].primitiveType,
  1914. boundingSphere: bs
  1915. });
  1916. return geo;
  1917. }
  1918. var scratchOffset = new Cesium.Cartesian3();
  1919. /**
  1920. *
  1921. *@param {Cesium.Geometry}geometry
  1922. *@param {Cesium.Cartesian3}offset
  1923. */
  1924. GeometryUtils.translate = function (geometry, offset) {
  1925. if (Array.isArray(offset)) {
  1926. scratchOffset.x = offset[0];
  1927. scratchOffset.y = offset[1];
  1928. scratchOffset.z = offset[2];
  1929. } else {
  1930. Cesium.Cartesian3.clone(offset, scratchOffset);
  1931. }
  1932. for (var i = 0; i < geometry.attributes.position.values.length; i += 3) {
  1933. geometry.attributes.position.values[i] += scratchOffset.x;
  1934. geometry.attributes.position.values[i + 1] += scratchOffset.y;
  1935. geometry.attributes.position.values[i + 2] += scratchOffset.z;
  1936. }
  1937. //if (geometry.attributes.normal) {
  1938. // Cesium.GeometryPipeline.computeNormal(geometry);
  1939. //}
  1940. }
  1941. /**
  1942. *
  1943. *@param {TypeArray} array
  1944. *@return {Cesium.ComponentDatatype}
  1945. */
  1946. GeometryUtils.getAttributeComponentType = function (array) {
  1947. var attributeComponentType = Cesium.ComponentDatatype.SHORT;
  1948. if (array instanceof Int8Array) {
  1949. attributeComponentType = Cesium.ComponentDatatype.BYTE;
  1950. } else if (array instanceof Uint8Array || array instanceof Uint8ClampedArray) {
  1951. attributeComponentType = Cesium.ComponentDatatype.UNSIGNED_BYTE;
  1952. } else if (array instanceof Int16Array) {
  1953. attributeComponentType = Cesium.ComponentDatatype.SHORT;
  1954. } else if (array instanceof Uint16Array) {
  1955. attributeComponentType = Cesium.ComponentDatatype.UNSIGNED_SHORT;
  1956. } else if (array instanceof Int32Array) {
  1957. attributeComponentType = Cesium.ComponentDatatype.INT;
  1958. } else if (array instanceof Uint32Array) {
  1959. attributeComponentType = Cesium.ComponentDatatype.UNSIGNED_INT;
  1960. } else if (array instanceof Float32Array) {
  1961. attributeComponentType = Cesium.ComponentDatatype.FLOAT;
  1962. } else if (array instanceof Float64Array) {
  1963. attributeComponentType = Cesium.ComponentDatatype.DOUBLE;
  1964. }
  1965. return attributeComponentType;
  1966. }
  1967. /**
  1968. *
  1969. *@param {Object}geometry
  1970. *@return {Boolean}
  1971. */
  1972. GeometryUtils.isGeometry3js = function (geometry) {
  1973. return (typeof THREE !== 'undefined' && (geometry instanceof THREE.Geometry || geometry instanceof THREE.BufferGeometry))
  1974. || (geometry.attributes && geometry.attributes.position && geometry.index)
  1975. || (geometry.vertices && geometry.faces);
  1976. }
  1977. /**
  1978. *
  1979. *@param {THREE.BufferGeometry}geometry
  1980. *@private
  1981. */
  1982. GeometryUtils.parseBufferGeometry3js = function (geometry) {
  1983. // var start = new Date();
  1984. var attributes = {};
  1985. if (!geometry.attributes.normal) {
  1986. geometry.computeFaceNormals();
  1987. }
  1988. for (var attrName in geometry.attributes) {
  1989. if (geometry.attributes.hasOwnProperty(attrName)) {
  1990. var attr = geometry.getAttribute(attrName);
  1991. if (attr && attr.array.length > 0) {
  1992. attributes[attrName] = new Cesium.GeometryAttribute({
  1993. componentDatatype: GeometryUtils.getAttributeComponentType(attr.array),
  1994. componentsPerAttribute: attr.itemSize,
  1995. values: attr.array,
  1996. normalize: attr.normalized
  1997. });
  1998. }
  1999. }
  2000. }
  2001. var indices = [];
  2002. if (!geometry.index && geometry.groups) {
  2003. geometry.groups.forEach(function (group) {
  2004. for (var i = 0; i < group.count; i++) {
  2005. indices.push(i + group.start);
  2006. }
  2007. })
  2008. indices = new Int32Array(indices);
  2009. } else {
  2010. indices = geometry.index.array;
  2011. }
  2012. var cesGeometry = new Cesium.Geometry({
  2013. attributes: attributes,
  2014. indices: indices,
  2015. primitiveType: Cesium.PrimitiveType.TRIANGLES
  2016. });
  2017. return cesGeometry;
  2018. }
  2019. /**
  2020. *
  2021. *@param {THREE.Geometry}geometry3js
  2022. *@return {Cesium.Geometry}
  2023. */
  2024. GeometryUtils.fromGeometry3js = function (geometry3js) {
  2025. if (geometry3js.attributes && (geometry3js.index || geometry3js.groups.length)) {
  2026. } else {
  2027. geometry3js = new THREE.BufferGeometry().fromGeometry(geometry3js);
  2028. }
  2029. var geometry = GeometryUtils.parseBufferGeometry3js(geometry3js);
  2030. //GeometryUtils.computeVertexNormals(geometry);
  2031. Cesium.GeometryPipeline.computeNormal(geometry);
  2032. return geometry;
  2033. var positions = new Float32Array(geometry3js.vertices.length * 3);
  2034. for (var i = 0; i < geometry3js.vertices.length; i++) {
  2035. positions[i * 3] = geometry3js.vertices[i].x;
  2036. if (!geometry3js.up || geometry3js.up.y) {
  2037. positions[i * 3 + 1] = geometry3js.vertices[i].z;
  2038. positions[i * 3 + 2] = geometry3js.vertices[i].y;
  2039. } else {
  2040. positions[i * 3 + 1] = geometry3js.vertices[i].y;
  2041. positions[i * 3 + 2] = geometry3js.vertices[i].z;
  2042. }
  2043. }
  2044. var indices = new Int32Array(geometry3js.faces.length * 3);
  2045. for (var i = 0; i < geometry3js.faces.length; i++) {
  2046. indices[i * 3] = geometry3js.faces[i].a;
  2047. indices[i * 3 + 1] = geometry3js.faces[i].b;
  2048. indices[i * 3 + 2] = geometry3js.faces[i].c;
  2049. }
  2050. var attributes = {};
  2051. attributes.position = new Cesium.GeometryAttribute({
  2052. componentDatatype: Cesium.ComponentDatatype.FLOAT,
  2053. componentsPerAttribute: 3,
  2054. values: positions
  2055. });
  2056. var cesGeometry = new Cesium.Geometry({
  2057. attributes: attributes,
  2058. indices: indices,
  2059. primitiveType: Cesium.PrimitiveType.TRIANGLES
  2060. });
  2061. return cesGeometry;
  2062. }
  2063. /**
  2064. *
  2065. *@param {Cesium.Geometry}geometry
  2066. *@return {THREE.Geometry}
  2067. */
  2068. GeometryUtils.toGeometry3js = function (geometry) {
  2069. if (typeof THREE === 'undefined') {
  2070. throw new Error("THREE 未加载");
  2071. }
  2072. var positions = geometry.attributes.position.values;
  2073. var positionIdx = 0;
  2074. var geometry3js = new THREE.Geometry();
  2075. for (var i = 0; i < positions.length ; i += 3) {
  2076. positionIdx = i * 3;
  2077. geometry3js.vertices.push(
  2078. new THREE.Vector3(positions[positionIdx], positions[positionIdx + 2], positions[positionIdx + 1])
  2079. );
  2080. }
  2081. for (var i = 0; i < geometry.indices.length ; i += 3) {
  2082. var idx1 = geometry.indices[i];
  2083. var idx2 = geometry.indices[i + 1];
  2084. var idx3 = geometry.indices[i + 2];
  2085. geometry3js.faces.push(new THREE.Face3(idx1, idx2, idx3));
  2086. }
  2087. return geometry3js;
  2088. }
  2089. /**
  2090. *@param {Cesium.Geometry|THREE.Geometry}
  2091. *@param {Cesium.Cartesian3}[offset]
  2092. *@return {CSG}
  2093. */
  2094. GeometryUtils.toCSG = function (geometry, offset) {
  2095. if (!(typeof THREE === 'undefined')) {
  2096. if (geometry instanceof THREE.Geometry) {
  2097. return GeometryUtils._toCSG3js(geometry, offset);
  2098. }
  2099. }
  2100. if (!offset) {
  2101. offset = { x: 0, y: 0, z: 0 };
  2102. }
  2103. if (!geometry.attributes.normal) {
  2104. geometry = Cesium.GeometryPipeline.computeNormal(geometry);
  2105. }
  2106. if (geometry.primitiveType !== Cesium.PrimitiveType.TRIANGLES) {
  2107. throw new Error("暂不支持此类几何体");
  2108. }
  2109. if (!CSG) {
  2110. throw new Error('CSG 库未加载。请从 https://github.com/evanw/csg.js 获取');
  2111. }
  2112. var faceCount = geometry.indices.length / 3;
  2113. var polygons = [], vertices = [];
  2114. var positions = geometry.attributes.position.values;
  2115. var normals = geometry.attributes.normal.values;
  2116. var normalIdx = 0, positionIdx = 0;
  2117. for (var i = 0; i < geometry.indices.length ; i += 3) {
  2118. vertices = [];
  2119. var idx1 = geometry.indices[i];
  2120. var idx2 = geometry.indices[i + 1];
  2121. var idx3 = geometry.indices[i + 2];
  2122. positionIdx = idx1 * 3;
  2123. normalIdx = idx1 * 3;
  2124. vertices.push(new CSG.Vertex(
  2125. [positions[positionIdx++] + offset.x, positions[positionIdx++] + offset.y, positions[positionIdx++] + offset.z],
  2126. [normals[normalIdx++], normals[normalIdx++], normals[normalIdx++]]
  2127. ));
  2128. positionIdx = idx2 * 3;
  2129. normalIdx = idx2 * 3;
  2130. vertices.push(new CSG.Vertex(
  2131. [positions[positionIdx++] + offset.x, positions[positionIdx++] + offset.y, positions[positionIdx++] + offset.z],
  2132. [normals[normalIdx++], normals[normalIdx++], normals[normalIdx++]]
  2133. ));
  2134. positionIdx = idx3 * 3;
  2135. normalIdx = idx3 * 3;
  2136. vertices.push(new CSG.Vertex(
  2137. [positions[positionIdx++] + offset.x, positions[positionIdx++] + offset.y, positions[positionIdx++] + offset.z],
  2138. [normals[normalIdx++], normals[normalIdx++], normals[normalIdx++]]
  2139. ));
  2140. polygons.push(new CSG.Polygon(vertices));
  2141. }
  2142. return CSG.fromPolygons(polygons);
  2143. }
  2144. /**
  2145. *@param {CSG}csg_model
  2146. *@param {Boolean}[toGeometry3js=false]
  2147. *@return {Cesium.Geometry|THREE.Geometry}
  2148. */
  2149. GeometryUtils.fromCSG = function (csg_model, toGeometry3js) {
  2150. if (!(typeof THREE === 'undefined')) {
  2151. if (geometry instanceof THREE.Geometry) {
  2152. return GeometryUtils._fromCSG3js(geometry, offset);
  2153. }
  2154. }
  2155. var i, j, vertices,
  2156. polygons = csg_model.toPolygons();
  2157. if (!CSG) {
  2158. throw new Error('CSG 库未加载。请从 https://github.com/evanw/csg.js 获取');
  2159. }
  2160. var positions = [];
  2161. var normals = [];
  2162. var indices = [];
  2163. for (i = 0; i < polygons.length; i++) {
  2164. // Vertices
  2165. vertices = [];
  2166. for (j = 0; j < polygons[i].vertices.length; j++) {
  2167. vertices.push(this.getGeometryVertice(positions, normals, polygons[i].vertices[j].pos, polygons[i].plane.normal));
  2168. }
  2169. if (vertices[0] === vertices[vertices.length - 1]) {
  2170. vertices.pop();
  2171. }
  2172. for (var j = 2; j < vertices.length; j++) {
  2173. indices.push(vertices[0], vertices[j - 1], vertices[j]);
  2174. }
  2175. }
  2176. positions = new Float32Array(positions);
  2177. normals = new Float32Array(normals);
  2178. indices = new Int32Array(indices);
  2179. var attributes = {};
  2180. attributes.position = new Cesium.GeometryAttribute({
  2181. componentDatatype: Cesium.ComponentDatatype.FLOAT,
  2182. componentsPerAttribute: 3,
  2183. values: positions
  2184. });
  2185. attributes.normal = new Cesium.GeometryAttribute({
  2186. componentDatatype: Cesium.ComponentDatatype.FLOAT,
  2187. componentsPerAttribute: 3,
  2188. values: normals
  2189. });
  2190. var cesGeometry = new Cesium.Geometry({
  2191. attributes: attributes,
  2192. indices: indices,
  2193. primitiveType: Cesium.PrimitiveType.TRIANGLES
  2194. });
  2195. return cesGeometry;
  2196. }
  2197. GeometryUtils._toCSG3js = function (three_model, offset, rotation) {
  2198. if (typeof THREE === 'undefined') {
  2199. throw new Error("THREE 未加载");
  2200. }
  2201. var i, geometry, polygons, vertices, rotation_matrix;
  2202. if (!CSG) {
  2203. throw 'CSG library not loaded. Please get a copy from https://github.com/evanw/csg.js';
  2204. }
  2205. if (three_model instanceof THREE.Mesh) {
  2206. geometry = three_model.geometry;
  2207. offset = offset || three_model.position;
  2208. rotation = rotation || three_model.rotation;
  2209. } else if (three_model instanceof THREE.Geometry) {
  2210. geometry = three_model;
  2211. offset = offset || new THREE.Vector3(0, 0, 0);
  2212. rotation = rotation || new THREE.Euler(0, 0, 0);
  2213. } else {
  2214. throw 'Model type not supported.';
  2215. }
  2216. rotation_matrix = new THREE.Matrix4().makeRotationFromEuler(rotation);
  2217. var polygons = [];
  2218. for (i = 0; i < geometry.faces.length; i++) {
  2219. if (geometry.faces[i] instanceof THREE.Face3) {
  2220. vertices = [];
  2221. vertices.push(new CSG.Vertex(geometry.vertices[geometry.faces[i].a].clone().add(offset).applyMatrix4(rotation_matrix), [geometry.faces[i].normal.x, geometry.faces[i].normal.y, geometry.faces[i].normal.z]));
  2222. vertices.push(new CSG.Vertex(geometry.vertices[geometry.faces[i].b].clone().add(offset).applyMatrix4(rotation_matrix), [geometry.faces[i].normal.x, geometry.faces[i].normal.y, geometry.faces[i].normal.z]));
  2223. vertices.push(new CSG.Vertex(geometry.vertices[geometry.faces[i].c].clone().add(offset).applyMatrix4(rotation_matrix), [geometry.faces[i].normal.x, geometry.faces[i].normal.y, geometry.faces[i].normal.z]));
  2224. polygons.push(new CSG.Polygon(vertices));
  2225. } else if (geometry.faces[i] instanceof THREE.Face4) {
  2226. vertices = [];
  2227. vertices.push(new CSG.Vertex(geometry.vertices[geometry.faces[i].a].clone().add(offset).applyMatrix4(rotation_matrix), [geometry.faces[i].normal.x, geometry.faces[i].normal.y, geometry.faces[i].normal.z]));
  2228. vertices.push(new CSG.Vertex(geometry.vertices[geometry.faces[i].b].clone().add(offset).applyMatrix4(rotation_matrix), [geometry.faces[i].normal.x, geometry.faces[i].normal.y, geometry.faces[i].normal.z]));
  2229. vertices.push(new CSG.Vertex(geometry.vertices[geometry.faces[i].d].clone().add(offset).applyMatrix4(rotation_matrix), [geometry.faces[i].normal.x, geometry.faces[i].normal.y, geometry.faces[i].normal.z]));
  2230. polygons.push(new CSG.Polygon(vertices));
  2231. vertices = [];
  2232. vertices.push(new CSG.Vertex(geometry.vertices[geometry.faces[i].b].clone().add(offset).applyMatrix4(rotation_matrix), [geometry.faces[i].normal.x, geometry.faces[i].normal.y, geometry.faces[i].normal.z]));
  2233. vertices.push(new CSG.Vertex(geometry.vertices[geometry.faces[i].c].clone().add(offset).applyMatrix4(rotation_matrix), [geometry.faces[i].normal.x, geometry.faces[i].normal.y, geometry.faces[i].normal.z]));
  2234. vertices.push(new CSG.Vertex(geometry.vertices[geometry.faces[i].d].clone().add(offset).applyMatrix4(rotation_matrix), [geometry.faces[i].normal.x, geometry.faces[i].normal.y, geometry.faces[i].normal.z]));
  2235. polygons.push(new CSG.Polygon(vertices));
  2236. } else {
  2237. throw 'Model contains unsupported face.';
  2238. }
  2239. }
  2240. return CSG.fromPolygons(polygons);
  2241. }
  2242. GeometryUtils._fromCSG3js = function (csg_model) {
  2243. if (typeof THREE === 'undefined') {
  2244. throw new Error("THREE 未加载");
  2245. }
  2246. var i, j, vertices, face,
  2247. three_geometry = new THREE.Geometry(),
  2248. polygons = csg_model.toPolygons();
  2249. if (!CSG) {
  2250. throw 'CSG library not loaded. Please get a copy from https://github.com/evanw/csg.js';
  2251. }
  2252. for (i = 0; i < polygons.length; i++) {
  2253. // Vertices
  2254. vertices = [];
  2255. for (j = 0; j < polygons[i].vertices.length; j++) {
  2256. vertices.push(GeometryUtils._getGeometryVertice3js(three_geometry, polygons[i].vertices[j].pos));
  2257. }
  2258. if (vertices[0] === vertices[vertices.length - 1]) {
  2259. vertices.pop();
  2260. }
  2261. for (var j = 2; j < vertices.length; j++) {
  2262. face = new THREE.Face3(vertices[0], vertices[j - 1], vertices[j], new THREE.Vector3().copy(polygons[i].plane.normal));
  2263. three_geometry.faces.push(face);
  2264. three_geometry.faceVertexUvs[0].push(new THREE.Vector2());
  2265. }
  2266. }
  2267. three_geometry.computeBoundingBox();
  2268. return three_geometry;
  2269. },
  2270. GeometryUtils._getGeometryVertice3js = function (geometry, vertice_position) {
  2271. var i;
  2272. for (i = 0; i < geometry.vertices.length; i++) {
  2273. if (geometry.vertices[i].x === vertice_position.x && geometry.vertices[i].y === vertice_position.y && geometry.vertices[i].z === vertice_position.z) {
  2274. // Vertice already exists
  2275. return i;
  2276. }
  2277. };
  2278. geometry.vertices.push(new THREE.Vector3(vertice_position.x, vertice_position.y, vertice_position.z));
  2279. return geometry.vertices.length - 1;
  2280. }
  2281. return GeometryUtils;
  2282. });
  2283. define('Core/Shaders/phong_frag',[],function () {
  2284. var phong_frag = '\n\
  2285. varying vec3 v_position;\n\
  2286. varying vec3 v_normal;\n\
  2287. uniform float picked;\n\
  2288. uniform vec4 pickedColor;\n\
  2289. uniform vec4 defaultColor;\n\
  2290. uniform float specular;\n\
  2291. uniform float shininess;\n\
  2292. uniform vec3 emission;\n\
  2293. void main() {\n\
  2294. vec3 positionToEyeEC = -v_position; \n\
  2295. vec3 normalEC =normalize(v_normal);\n\
  2296. vec4 color=defaultColor;\n\
  2297. if(picked!=0.0){\n\
  2298. color = pickedColor;\n\
  2299. }\n\
  2300. czm_material material;\n\
  2301. material.specular = specular;\n\
  2302. material.shininess = shininess;\n\
  2303. material.normal = normalEC;\n\
  2304. material.emission =emission;//vec3(0.2,0.2,0.2);\n\
  2305. material.diffuse = color.rgb ;\n\
  2306. material.alpha = color.a;\n\
  2307. gl_FragColor = czm_phong(normalize(positionToEyeEC), material,czm_lightDirectionEC);\n\
  2308. }';
  2309. return phong_frag;
  2310. })
  2311. ;
  2312. define('Core/Shaders/phong_vert',[],function () {
  2313. var phong_vert = "\n\
  2314. #ifdef GL_ES\n\
  2315. precision highp float;\n\
  2316. #endif\n\
  2317. \n\
  2318. \n\
  2319. \n\
  2320. varying vec3 v_position;\n\
  2321. varying vec3 v_normal;\n\
  2322. \n\
  2323. varying vec3 v_light0Direction;\n\
  2324. \n\
  2325. void main(void) \n\
  2326. {\n\
  2327. vec4 pos = modelViewMatrix * vec4( position,1.0);\n\
  2328. v_normal = normalMatrix * normal;\n\
  2329. v_position = pos.xyz;\n\
  2330. v_light0Direction = mat3( modelViewMatrix) * vec3(1.0,1.0,1.0);\n\
  2331. gl_Position = projectionMatrix * pos;\n\
  2332. }";
  2333. return phong_vert;
  2334. });
  2335. define('Core/MeshPhongMaterial',[
  2336. 'Core/MeshMaterial',
  2337. 'Core/Shaders/phong_frag',
  2338. 'Core/Shaders/phong_vert'
  2339. ], function (
  2340. MeshMaterial,
  2341. phong_frag,
  2342. phong_vert
  2343. ) {
  2344. /**
  2345. *
  2346. *@constructor
  2347. *@memberof Cesium
  2348. *@extends Cesium.MeshMaterial
  2349. */
  2350. function MeshPhongMaterial(options) {
  2351. options = options ? options : {};
  2352. options.uniforms = options.uniforms ? options.uniforms : {
  2353. shininess: -1,
  2354. emission: [0, 0, 0],
  2355. specular: 0
  2356. };
  2357. options.uniforms.shininess = Cesium.defaultValue(options.uniforms.shininess, 0);
  2358. options.uniforms.emission = Cesium.defaultValue(options.uniforms.emission, [0.2, 0.2, 0.2]);
  2359. options.uniforms.specular = Cesium.defaultValue(options.uniforms.specular, 0);
  2360. MeshMaterial.apply(this, arguments);
  2361. this.vertexShader = phong_vert;
  2362. this.fragmentShader = phong_frag;
  2363. }
  2364. MeshPhongMaterial.prototype = new MeshMaterial();
  2365. return MeshPhongMaterial;
  2366. })
  2367. ;
  2368. define('Core/Mesh',[
  2369. 'Core/Rotation',
  2370. 'Util/CSG',
  2371. 'Core/MeshMaterial',
  2372. 'Core/GeometryUtils',
  2373. 'Core/MeshPhongMaterial'
  2374. ], function (
  2375. Rotation,
  2376. CSG,
  2377. MeshMaterial,
  2378. GeometryUtils,
  2379. MeshPhongMaterial
  2380. ) {
  2381. var defaultValue = Cesium.defaultValue;
  2382. /**
  2383. *
  2384. *@param {Object|geometry}options
  2385. *@param {Cesium.Geometry|Cesium.CSG|THREE.Geometry|THREE.BufferGeometry}options.geometry
  2386. *@param {Cesium.MeshMaterial}options.material
  2387. *@param {Boolean}[options.show=true]
  2388. *@param {Cesium.Cartesian3}[options.position]
  2389. *@param {Cesium.Rotation}[options.rotation]
  2390. *@param {Cesium.Cartesian3}[options.scale]
  2391. *@param {Cesium.MeshMaterial}[material]
  2392. *
  2393. *@property {Cesium.Geometry}geometry
  2394. *@property {Cesium.MeshMaterial}material
  2395. *@property {Boolean}show
  2396. *@property {Cesium.Cartesian3}position
  2397. *@property {Cesium.VolumeRendering.Rotation}rotation
  2398. *@property {Cesium.Cartesian3}scale
  2399. *@property {Boolean}needUpdate
  2400. *@property {Cesium.Mesh|Cesium.LOD}parent
  2401. *
  2402. *@constructor
  2403. *@memberof Cesium
  2404. *@example
  2405. //1.
  2406. var mesh=new Mesh(geomertry,material);
  2407. //2.
  2408. var mesh2=new Mesh({
  2409. geomertry:geomertry2,
  2410. material:material2,
  2411. position:position2
  2412. });
  2413. */
  2414. function Mesh(options) {
  2415. if (Mesh.isGeometrySupported(options)) {
  2416. var geometry = options;
  2417. options = {
  2418. geometry: geometry,
  2419. material: arguments[1]
  2420. };
  2421. }
  2422. if (!options || !options.geometry) {
  2423. throw new Error("geometry是必须参数");
  2424. }
  2425. if (!Mesh.isGeometrySupported(options.geometry)) {
  2426. throw new Error("暂不支持此类型的geometry");
  2427. }
  2428. if (GeometryUtils.isGeometry3js(options.geometry)) {
  2429. options.geometry = GeometryUtils.fromGeometry3js(options.geometry);
  2430. } else if (options.geometry instanceof CSG) {
  2431. if (options.geometry.polygons.length == 0) {
  2432. options.show = false;
  2433. }
  2434. options.geometry = CSG.fromCSG(options.geometry);
  2435. } else if (typeof options.geometry.constructor.createGeometry == 'function') {
  2436. options.geometry = options.geometry.constructor.createGeometry(options.geometry);
  2437. }
  2438. this.uuid = Cesium.createGuid();
  2439. this.show = defaultValue(options.show, true);
  2440. this._geometry = options.geometry;
  2441. this._material = defaultValue(options.material, new MeshMaterial());
  2442. this._position = defaultValue(options.position, new Cesium.Cartesian3(0, 0, 0));
  2443. this._scale = defaultValue(options.scale, new Cesium.Cartesian3(1, 1, 1));
  2444. this._rotation = defaultValue(options.rotation, { axis: new Cesium.Cartesian3(0, 0, 1), angle: 0 });
  2445. this._rotation = new Rotation(this._rotation.axis, this._rotation.angle);
  2446. this._needsUpdate = false;
  2447. this._modelMatrix = new Cesium.Matrix4();
  2448. Cesium.Matrix4.clone(Cesium.Matrix4.IDENTITY, this._modelMatrix);
  2449. //用于设置旋转,优先级大于rotation
  2450. this.quaternion = null;
  2451. this._modelMatrixNeedsUpdate = true;
  2452. this._onNeedUpdateChanged = function () {
  2453. this.modelMatrixNeedsUpdate = true;
  2454. };
  2455. this._rotation.paramChanged.removeEventListener(this._onNeedUpdateChanged);
  2456. this._drawCommand = null;
  2457. this._children = [];
  2458. this._parent = null;
  2459. this.userData = {};
  2460. if (!this._geometry.attributes.normal
  2461. && this.material instanceof MeshPhongMaterial
  2462. && this._geometry.primitiveType == Cesium.PrimitiveType.TRIANGLES
  2463. ) {
  2464. Cesium.GeometryPipeline.computeNormal(this._geometry);
  2465. //GeometryUtils.computeVertexNormals(this._geometry);
  2466. }
  2467. }
  2468. Mesh.isGeometrySupported = function (geometry) {
  2469. var supported = (geometry instanceof Cesium.Geometry
  2470. || geometry instanceof CSG
  2471. || typeof geometry.constructor.createGeometry == 'function'
  2472. || GeometryUtils.isGeometry3js(geometry));
  2473. return supported;
  2474. }
  2475. /**
  2476. *
  2477. *@param {Cesium.Mesh|Cesium.LOD}node
  2478. *@param {Cesium.Mesh~TraverseCallback}callback
  2479. */
  2480. Mesh.traverse = function (node, callback) {
  2481. callback(node);
  2482. if (node.children) {
  2483. node.children.forEach(function (child) {
  2484. callback(child);
  2485. })
  2486. }
  2487. }
  2488. /**
  2489. *
  2490. * @callback Cesium.Mesh~TraverseCallback
  2491. * @param {Cesium.Mesh|Cesium.LOD}node
  2492. */
  2493. Object.defineProperties(Mesh.prototype, {
  2494. modelMatrix: {
  2495. get: function () {
  2496. return this._modelMatrix;
  2497. }
  2498. },
  2499. parent: {
  2500. get: function () {
  2501. return this._parent;
  2502. },
  2503. set: function (val) {
  2504. this._parent = val;
  2505. this.modelMatrixNeedsUpdate = true;
  2506. }
  2507. },
  2508. modelMatrixNeedsUpdate: {
  2509. get: function () {
  2510. return this._modelMatrixNeedsUpdate;
  2511. },
  2512. set: function (val) {
  2513. this._modelMatrixNeedsUpdate = val;
  2514. if (this._modelMatrixNeedsUpdate) {
  2515. Mesh.traverse(this, function (mesh) {
  2516. mesh._modelMatrixNeedsUpdate = val;
  2517. });
  2518. }
  2519. }
  2520. },
  2521. children: {
  2522. get: function () {
  2523. return this._children;
  2524. },
  2525. set: function (val) {
  2526. this._children = val;
  2527. this._needsUpdate = true;
  2528. }
  2529. },
  2530. geometry: {
  2531. get: function () {
  2532. return this._geometry;
  2533. },
  2534. set: function (val) {
  2535. this._geometry = val;
  2536. this._needsUpdate = true;
  2537. this.modelMatrixNeedsUpdate = true;
  2538. }
  2539. },
  2540. material: {
  2541. get: function () {
  2542. return this._material;
  2543. },
  2544. set: function (val) {
  2545. this._material = val;
  2546. this._needsUpdate = true;
  2547. }
  2548. },
  2549. needsUpdate: {
  2550. get: function () {
  2551. return this._needsUpdate;
  2552. },
  2553. set: function (val) {
  2554. this._needsUpdate = val;
  2555. }
  2556. },
  2557. rotation: {
  2558. get: function () {
  2559. return this._rotation;
  2560. },
  2561. set: function (val) {
  2562. if (val != this._rotation) {
  2563. this._rotation = val;
  2564. // this._needUpdate = true;
  2565. this.modelMatrixNeedsUpdate = true;
  2566. }
  2567. this._rotation.paramChanged.removeEventListener(this._onNeedUpdateChanged);
  2568. this._rotation = val;
  2569. this._rotation.paramChanged.addEventListener(this._onNeedUpdateChanged);
  2570. }
  2571. },
  2572. position: {
  2573. get: function () {
  2574. return this._position;
  2575. },
  2576. set: function (val) {
  2577. if (val.x != this._position.x || val.y != this._position.y || val.z != this._position.z) {
  2578. this._position = val;
  2579. //this._needsUpdate = true;
  2580. this.modelMatrixNeedsUpdate = true;
  2581. }
  2582. this._position = val;
  2583. }
  2584. },
  2585. scale: {
  2586. get: function () {
  2587. return this._scale;
  2588. },
  2589. set: function (val) {
  2590. if (val.x != this._scale.x || val.y != this._scale.y || val.z != this._scale.z) {
  2591. this._scale = val;
  2592. // this._needsUpdate = true;
  2593. this.modelMatrixNeedsUpdate = true;
  2594. }
  2595. this._scale = val;
  2596. }
  2597. }
  2598. });
  2599. /**
  2600. *@oaram {Cesium.Mesh|Cesium.LOD}child
  2601. */
  2602. Mesh.prototype.add = function (mesh) {
  2603. if (mesh.parent !== this) {
  2604. mesh.parent = this;
  2605. }
  2606. this._children.push(mesh);
  2607. }
  2608. return Mesh;
  2609. })
  2610. ;
  2611. define('Core/Shaders/none_frag',[],function () {
  2612. var none_frag = "\n\
  2613. #ifdef GL_ES\n\
  2614. precision highp float;\n\
  2615. #endif\n\
  2616. \n\
  2617. varying vec3 v_position;\n\
  2618. \n\
  2619. uniform vec4 ambientColor;\n\
  2620. uniform vec4 diffuseColor;\n\
  2621. uniform vec4 specularColor;\n\
  2622. uniform float specularShininess;\n\
  2623. uniform float picked;\n\
  2624. uniform vec4 pickedColor;\n\
  2625. \n\
  2626. void main(void) \n\
  2627. {\n\
  2628. vec4 color = vec4(0.0, 0.0, 0.0, 0.0);\n\
  2629. vec4 ambient = ambientColor;\n\
  2630. vec4 diffuse = diffuseColor;\n\
  2631. vec4 specular = specularColor;\n\
  2632. color.xyz += ambient.xyz;\n\
  2633. color.xyz += diffuse.xyz;\n\
  2634. color.xyz += specular.xyz;\n\
  2635. color = vec4(color.rgb * diffuse.a, diffuse.a);\n\
  2636. gl_FragColor = color;\n\
  2637. if(picked!=0.0){\n\
  2638. gl_FragColor =mix(color, pickedColor*0.5,1.0);\n\
  2639. }\n\
  2640. }";
  2641. return none_frag;
  2642. })
  2643. ;
  2644. define('Core/Shaders/none_vert',[],function () {
  2645. var none_vert = "\n\
  2646. #ifdef GL_ES\n\
  2647. precision highp float;\n\
  2648. #endif\n\
  2649. \n\
  2650. \n\
  2651. \n\
  2652. varying vec3 v_position;\n\
  2653. \n\
  2654. void main(void) \n\
  2655. {\n\
  2656. vec4 pos = modelViewMatrix * vec4( position,1.0);\n\
  2657. v_position = pos.xyz;\n\
  2658. gl_Position = projectionMatrix * pos;\n\
  2659. }";
  2660. return none_vert;
  2661. });
  2662. define('Core/Shaders/normals_frag',[],function () {
  2663. var normals_frag = "\n\
  2664. #ifdef GL_ES\n\
  2665. precision highp float;\n\
  2666. #endif\n\
  2667. \n\
  2668. varying vec3 v_position;\n\
  2669. varying vec3 v_normal;\n\
  2670. \n\
  2671. uniform vec4 ambientColor;\n\
  2672. uniform vec4 diffuseColor;\n\
  2673. uniform vec4 specularColor;\n\
  2674. uniform float specularShininess;\n\
  2675. uniform float alpha;\n\
  2676. uniform float picked;\n\
  2677. uniform vec4 pickedColor;\n\
  2678. \n\
  2679. varying vec3 v_light0Direction;\n\
  2680. \n\
  2681. void main(void) \n\
  2682. {\n\
  2683. vec3 normal = normalize(v_normal);\n\
  2684. vec4 color = vec4(0.0, 0.0, 0.0, 0.0);\n\
  2685. vec3 diffuseLight = vec3(0.0, 0.0, 0.0);\n\
  2686. vec3 lightColor = vec3(1.0,1.0,1.0);\n\
  2687. vec4 ambient = ambientColor;\n\
  2688. vec4 diffuse = diffuseColor;\n\
  2689. vec4 specular = specularColor;\n\
  2690. \n\
  2691. vec3 specularLight = vec3(0.0, 0.0, 0.0);\n\
  2692. {\n\
  2693. float specularIntensity = 0.0;\n\
  2694. float attenuation = 1.0;\n\
  2695. vec3 l = normalize(v_light0Direction);\n\
  2696. vec3 viewDir = -normalize(v_position);\n\
  2697. vec3 h = normalize(l+viewDir);\n\
  2698. specularIntensity = max(0.0, pow(max(dot(normal,h), 0.0) , specularShininess)) * attenuation;\n\
  2699. specularLight += lightColor * specularIntensity;\n\
  2700. diffuseLight += lightColor * max(dot(normal,l), 0.0) * attenuation;\n\
  2701. }\n\
  2702. //specular.xyz *= specularLight;\n\
  2703. //diffuse.xyz *= diffuseLight;\n\
  2704. color.xyz += ambient.xyz;\n\
  2705. color.xyz += diffuse.xyz;\n\
  2706. color.xyz += specular.xyz;\n\
  2707. color = vec4(color.rgb * diffuse.a, diffuse.a*alpha);\n\
  2708. gl_FragColor = color;\n\
  2709. if(picked!=0.0){\n\
  2710. gl_FragColor =mix(color, pickedColor*0.5,1.0);\n\
  2711. }\n\
  2712. }";
  2713. return normals_frag;
  2714. });
  2715. define('Core/Shaders/normals_vert',[],function () {
  2716. var normals_vert = "\n\
  2717. #ifdef GL_ES\n\
  2718. precision highp float;\n\
  2719. #endif\n\
  2720. \n\
  2721. \n\
  2722. \n\
  2723. varying vec3 v_position;\n\
  2724. varying vec3 v_normal;\n\
  2725. \n\
  2726. varying vec3 v_light0Direction;\n\
  2727. \n\
  2728. void main(void) \n\
  2729. {\n\
  2730. vec4 pos = modelViewMatrix * vec4( position,1.0);\n\
  2731. v_normal = normalMatrix * normal;\n\
  2732. v_position = pos.xyz;\n\
  2733. v_light0Direction = mat3( modelViewMatrix) * vec3(1.0,1.0,1.0);\n\
  2734. gl_Position = projectionMatrix * pos;\n\
  2735. }";
  2736. return normals_vert;
  2737. });
  2738. define('Core/Shaders/texture_frag',[],function () {
  2739. var texture_frag = "\n\
  2740. #ifdef GL_ES\n\
  2741. precision highp float;\n\
  2742. #endif\n\
  2743. \n\
  2744. varying vec3 v_position;\n\
  2745. varying vec2 v_texcoord0;\n\
  2746. \n\
  2747. uniform vec4 ambientColor;\n\
  2748. uniform sampler2D diffuseColorMap;\n\
  2749. uniform vec4 specularColor;\n\
  2750. uniform float specularShininess;\n\
  2751. uniform float picked;\n\
  2752. uniform vec4 pickedColor;\n\
  2753. \n\
  2754. uniform float alpha;\n\
  2755. \n\
  2756. void main(void) \n\
  2757. {\n\
  2758. vec4 color = vec4(0.0, 0.0, 0.0, 0.0);\n\
  2759. vec3 diffuseLight = vec3(0.0, 0.0, 0.0);\n\
  2760. vec3 lightColor = vec3(1.0,1.0,1.0);\n\
  2761. vec4 ambient = ambientColor;\n\
  2762. vec4 diffuse = texture2D(diffuseColorMap, v_texcoord0);\n\
  2763. vec4 specular = specularColor;\n\
  2764. color.xyz += ambient.xyz;\n\
  2765. color.xyz += diffuse.xyz;\n\
  2766. color.xyz += specular.xyz;\n\
  2767. color = vec4(diffuse.rgb * diffuse.a, diffuse.a*alpha);\n\
  2768. gl_FragColor = color;\n\
  2769. if(picked!=0.0){\n\
  2770. gl_FragColor =mix(color, pickedColor*0.5,1.0);\n\
  2771. }\n\
  2772. }";
  2773. return texture_frag;
  2774. })
  2775. ;
  2776. define('Core/Shaders/texture_vert',[],function () {
  2777. var texture_vert = "\n\
  2778. #ifdef GL_ES\n\
  2779. precision highp float;\n\
  2780. #endif\n\
  2781. \n\
  2782. \n\
  2783. \n\
  2784. varying vec3 v_position;\n\
  2785. varying vec2 v_texcoord0;\n\
  2786. \n\
  2787. void main(void) \n\
  2788. {\n\
  2789. vec4 pos = modelViewMatrix * vec4( position,1.0);\n\
  2790. v_texcoord0 = uv;\n\
  2791. v_position = pos.xyz;\n\
  2792. gl_Position = projectionMatrix * pos;\n\
  2793. }";
  2794. return texture_vert;
  2795. });
  2796. define('Core/Shaders/texture_normals_frag',[],function () {
  2797. var texture_normals_frag = "\n\
  2798. #ifdef GL_ES\n\
  2799. precision highp float;\n\
  2800. #endif\n\
  2801. \n\
  2802. varying vec3 v_position;\n\
  2803. varying vec2 v_texcoord0;\n\
  2804. varying vec3 v_normal;\n\
  2805. \n\
  2806. uniform vec4 ambientColor;\n\
  2807. uniform sampler2D diffuseColorMap;\n\
  2808. uniform vec4 specularColor;\n\
  2809. uniform float specularShininess;\n\
  2810. uniform float picked;\n\
  2811. uniform vec4 pickedColor;\n\
  2812. \n\
  2813. varying vec3 v_light0Direction;\n\
  2814. \n\
  2815. void main(void) \n\
  2816. {\n\
  2817. vec3 normal = normalize(v_normal);\n\
  2818. vec4 color = vec4(0.0, 0.0, 0.0, 0.0);\n\
  2819. vec3 diffuseLight = vec3(0.0, 0.0, 0.0);\n\
  2820. vec3 lightColor = vec3(1.0,1.0,1.0);\n\
  2821. vec4 ambient = ambientColor;\n\
  2822. vec4 diffuse = texture2D(diffuseColorMap, v_texcoord0);\n\
  2823. vec4 specular = specularColor;\n\
  2824. \n\
  2825. vec3 specularLight = vec3(0.0, 0.0, 0.0);\n\
  2826. {\n\
  2827. float specularIntensity = 0.0;\n\
  2828. float attenuation = 1.0;\n\
  2829. vec3 l = normalize(v_light0Direction);\n\
  2830. vec3 viewDir = -normalize(v_position);\n\
  2831. vec3 h = normalize(l+viewDir);\n\
  2832. specularIntensity = max(0.0, pow(max(dot(normal,h), 0.0) , specularShininess)) * attenuation;\n\
  2833. specularLight += lightColor * specularIntensity;\n\
  2834. diffuseLight += lightColor * max(dot(normal,l), 0.0) * attenuation;\n\
  2835. }\n\
  2836. //specular.xyz *= specularLight;\n\
  2837. //diffuse.xyz *= diffuseLight;\n\
  2838. color.xyz += ambient.xyz;\n\
  2839. color.xyz += diffuse.xyz;\n\
  2840. color.xyz += specular.xyz;\n\
  2841. color = vec4(diffuse.rgb * diffuse.a, diffuse.a);\n\
  2842. gl_FragColor = color;\n\
  2843. if(picked!=0.0){\n\
  2844. gl_FragColor = pickedColor*color;\n\
  2845. }\n\
  2846. }";
  2847. return texture_normals_frag;
  2848. });
  2849. define('Core/Shaders/texture_normals_vert',[],function () {
  2850. var texture_normals_vert = "\n\
  2851. #ifdef GL_ES\n\
  2852. precision highp float;\n\
  2853. #endif\n\
  2854. \n\
  2855. \n\
  2856. \n\
  2857. varying vec3 v_position;\n\
  2858. varying vec2 v_texcoord0;\n\
  2859. varying vec3 v_normal;\n\
  2860. \n\
  2861. varying vec3 v_light0Direction;\n\
  2862. \n\
  2863. void main(void) \n\
  2864. {\n\
  2865. vec4 pos = modelViewMatrix * vec4( position,1.0);\n\
  2866. v_normal = normalMatrix * normal;\n\
  2867. v_texcoord0 =uv;\n\
  2868. v_position = pos.xyz;\n\
  2869. v_light0Direction = mat3( modelViewMatrix) * vec3(1.0,1.0,1.0);\n\
  2870. gl_Position = projectionMatrix * pos;\n\
  2871. }";
  2872. return texture_normals_vert;
  2873. });
  2874. define('Core/Shaders/ShaderChunk',[
  2875. "Core/Shaders/none_frag",
  2876. "Core/Shaders/none_vert",
  2877. "Core/Shaders/normals_frag",
  2878. "Core/Shaders/normals_vert",
  2879. "Core/Shaders/texture_frag",
  2880. "Core/Shaders/texture_vert",
  2881. "Core/Shaders/texture_normals_frag",
  2882. "Core/Shaders/texture_normals_vert"
  2883. ], function (
  2884. none_frag,
  2885. none_vert,
  2886. normals_frag,
  2887. normals_vert,
  2888. texture_frag,
  2889. texture_vert,
  2890. texture_normals_frag,
  2891. texture_normals_vert
  2892. ) {
  2893. var alphamap_fragment = "#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif\n";
  2894. var alphamap_pars_fragment = "#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif\n";
  2895. var alphatest_fragment = "#ifdef ALPHATEST\n\tif ( diffuseColor.a < ALPHATEST ) discard;\n#endif\n";
  2896. var aomap_fragment = "#ifdef USE_AOMAP\n\tfloat ambientOcclusion = ( texture2D( aoMap, vUv2 ).r - 1.0 ) * aoMapIntensity + 1.0;\n\treflectedLight.indirectDiffuse *= ambientOcclusion;\n\t#if defined( USE_ENVMAP ) && defined( PHYSICAL )\n\t\tfloat dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n\t\treflectedLight.indirectSpecular *= computeSpecularOcclusion( dotNV, ambientOcclusion, material.specularRoughness );\n\t#endif\n#endif\n";
  2897. var aomap_pars_fragment = "#ifdef USE_AOMAP\n\tuniform sampler2D aoMap;\n\tuniform float aoMapIntensity;\n#endif";
  2898. var begin_vertex = "\nvec3 transformed = vec3( position );\n";
  2899. var beginnormal_vertex = "\nvec3 objectNormal = vec3( normal );\n";
  2900. var bsdfs = "float punctualLightIntensityToIrradianceFactor( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {\n\tif( decayExponent > 0.0 ) {\n#if defined ( PHYSICALLY_CORRECT_LIGHTS )\n\t\tfloat distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );\n\t\tfloat maxDistanceCutoffFactor = pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );\n\t\treturn distanceFalloff * maxDistanceCutoffFactor;\n#else\n\t\treturn pow( saturate( -lightDistance / cutoffDistance + 1.0 ), decayExponent );\n#endif\n\t}\n\treturn 1.0;\n}\nvec3 BRDF_Diffuse_Lambert( const in vec3 diffuseColor ) {\n\treturn RECIPROCAL_PI * diffuseColor;\n}\nvec3 F_Schlick( const in vec3 specularColor, const in float dotLH ) {\n\tfloat fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );\n\treturn ( 1.0 - specularColor ) * fresnel + specularColor;\n}\nfloat G_GGX_Smith( const in float alpha, const in float dotNL, const in float dotNV ) {\n\tfloat a2 = pow2( alpha );\n\tfloat gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\n\tfloat gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\n\treturn 1.0 / ( gl * gv );\n}\nfloat G_GGX_SmithCorrelated( const in float alpha, const in float dotNL, const in float dotNV ) {\n\tfloat a2 = pow2( alpha );\n\tfloat gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\n\tfloat gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\n\treturn 0.5 / max( gv + gl, EPSILON );\n}\nfloat D_GGX( const in float alpha, const in float dotNH ) {\n\tfloat a2 = pow2( alpha );\n\tfloat denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0;\n\treturn RECIPROCAL_PI * a2 / pow2( denom );\n}\nvec3 BRDF_Specular_GGX( const in IncidentLight incidentLight, const in GeometricContext geometry, const in vec3 specularColor, const in float roughness ) {\n\tfloat alpha = pow2( roughness );\n\tvec3 halfDir = normalize( incidentLight.direction + geometry.viewDir );\n\tfloat dotNL = saturate( dot( geometry.normal, incidentLight.direction ) );\n\tfloat dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n\tfloat dotNH = saturate( dot( geometry.normal, halfDir ) );\n\tfloat dotLH = saturate( dot( incidentLight.direction, halfDir ) );\n\tvec3 F = F_Schlick( specularColor, dotLH );\n\tfloat G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );\n\tfloat D = D_GGX( alpha, dotNH );\n\treturn F * ( G * D );\n}\nvec2 LTC_Uv( const in vec3 N, const in vec3 V, const in float roughness ) {\n\tconst float LUT_SIZE = 64.0;\n\tconst float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE;\n\tconst float LUT_BIAS = 0.5 / LUT_SIZE;\n\tfloat theta = acos( dot( N, V ) );\n\tvec2 uv = vec2(\n\t\tsqrt( saturate( roughness ) ),\n\t\tsaturate( theta / ( 0.5 * PI ) ) );\n\tuv = uv * LUT_SCALE + LUT_BIAS;\n\treturn uv;\n}\nfloat LTC_ClippedSphereFormFactor( const in vec3 f ) {\n\tfloat l = length( f );\n\treturn max( ( l * l + f.z ) / ( l + 1.0 ), 0.0 );\n}\nvec3 LTC_EdgeVectorFormFactor( const in vec3 v1, const in vec3 v2 ) {\n\tfloat x = dot( v1, v2 );\n\tfloat y = abs( x );\n\tfloat a = 0.86267 + (0.49788 + 0.01436 * y ) * y;\n\tfloat b = 3.45068 + (4.18814 + y) * y;\n\tfloat v = a / b;\n\tfloat theta_sintheta = (x > 0.0) ? v : 0.5 * inversesqrt( 1.0 - x * x ) - v;\n\treturn cross( v1, v2 ) * theta_sintheta;\n}\nvec3 LTC_Evaluate( const in vec3 N, const in vec3 V, const in vec3 P, const in mat3 mInv, const in vec3 rectCoords[ 4 ] ) {\n\tvec3 v1 = rectCoords[ 1 ] - rectCoords[ 0 ];\n\tvec3 v2 = rectCoords[ 3 ] - rectCoords[ 0 ];\n\tvec3 lightNormal = cross( v1, v2 );\n\tif( dot( lightNormal, P - rectCoords[ 0 ] ) < 0.0 ) return vec3( 0.0 );\n\tvec3 T1, T2;\n\tT1 = normalize( V - N * dot( V, N ) );\n\tT2 = - cross( N, T1 );\n\tmat3 mat = mInv * transpose( mat3( T1, T2, N ) );\n\tvec3 coords[ 4 ];\n\tcoords[ 0 ] = mat * ( rectCoords[ 0 ] - P );\n\tcoords[ 1 ] = mat * ( rectCoords[ 1 ] - P );\n\tcoords[ 2 ] = mat * ( rectCoords[ 2 ] - P );\n\tcoords[ 3 ] = mat * ( rectCoords[ 3 ] - P );\n\tcoords[ 0 ] = normalize( coords[ 0 ] );\n\tcoords[ 1 ] = normalize( coords[ 1 ] );\n\tcoords[ 2 ] = normalize( coords[ 2 ] );\n\tcoords[ 3 ] = normalize( coords[ 3 ] );\n\tvec3 vectorFormFactor = vec3( 0.0 );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 0 ], coords[ 1 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 1 ], coords[ 2 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 2 ], coords[ 3 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 3 ], coords[ 0 ] );\n\tvec3 result = vec3( LTC_ClippedSphereFormFactor( vectorFormFactor ) );\n\treturn result;\n}\nvec3 BRDF_Specular_GGX_Environment( const in GeometricContext geometry, const in vec3 specularColor, const in float roughness ) {\n\tfloat dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n\tconst vec4 c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 );\n\tconst vec4 c1 = vec4( 1, 0.0425, 1.04, - 0.04 );\n\tvec4 r = roughness * c0 + c1;\n\tfloat a004 = min( r.x * r.x, exp2( - 9.28 * dotNV ) ) * r.x + r.y;\n\tvec2 AB = vec2( -1.04, 1.04 ) * a004 + r.zw;\n\treturn specularColor * AB.x + AB.y;\n}\nfloat G_BlinnPhong_Implicit( ) {\n\treturn 0.25;\n}\nfloat D_BlinnPhong( const in float shininess, const in float dotNH ) {\n\treturn RECIPROCAL_PI * ( shininess * 0.5 + 1.0 ) * pow( dotNH, shininess );\n}\nvec3 BRDF_Specular_BlinnPhong( const in IncidentLight incidentLight, const in GeometricContext geometry, const in vec3 specularColor, const in float shininess ) {\n\tvec3 halfDir = normalize( incidentLight.direction + geometry.viewDir );\n\tfloat dotNH = saturate( dot( geometry.normal, halfDir ) );\n\tfloat dotLH = saturate( dot( incidentLight.direction, halfDir ) );\n\tvec3 F = F_Schlick( specularColor, dotLH );\n\tfloat G = G_BlinnPhong_Implicit( );\n\tfloat D = D_BlinnPhong( shininess, dotNH );\n\treturn F * ( G * D );\n}\nfloat GGXRoughnessToBlinnExponent( const in float ggxRoughness ) {\n\treturn ( 2.0 / pow2( ggxRoughness + 0.0001 ) - 2.0 );\n}\nfloat BlinnExponentToGGXRoughness( const in float blinnExponent ) {\n\treturn sqrt( 2.0 / ( blinnExponent + 2.0 ) );\n}\n";
  2901. var bumpmap_pars_fragment = "#ifdef USE_BUMPMAP\n\tuniform sampler2D bumpMap;\n\tuniform float bumpScale;\n\tvec2 dHdxy_fwd() {\n\t\tvec2 dSTdx = dFdx( vUv );\n\t\tvec2 dSTdy = dFdy( vUv );\n\t\tfloat Hll = bumpScale * texture2D( bumpMap, vUv ).x;\n\t\tfloat dBx = bumpScale * texture2D( bumpMap, vUv + dSTdx ).x - Hll;\n\t\tfloat dBy = bumpScale * texture2D( bumpMap, vUv + dSTdy ).x - Hll;\n\t\treturn vec2( dBx, dBy );\n\t}\n\tvec3 perturbNormalArb( vec3 surf_pos, vec3 surf_norm, vec2 dHdxy ) {\n\t\tvec3 vSigmaX = vec3( dFdx( surf_pos.x ), dFdx( surf_pos.y ), dFdx( surf_pos.z ) );\n\t\tvec3 vSigmaY = vec3( dFdy( surf_pos.x ), dFdy( surf_pos.y ), dFdy( surf_pos.z ) );\n\t\tvec3 vN = surf_norm;\n\t\tvec3 R1 = cross( vSigmaY, vN );\n\t\tvec3 R2 = cross( vN, vSigmaX );\n\t\tfloat fDet = dot( vSigmaX, R1 );\n\t\tvec3 vGrad = sign( fDet ) * ( dHdxy.x * R1 + dHdxy.y * R2 );\n\t\treturn normalize( abs( fDet ) * surf_norm - vGrad );\n\t}\n#endif\n";
  2902. var clipping_planes_fragment = "#if NUM_CLIPPING_PLANES > 0\n\tfor ( int i = 0; i < UNION_CLIPPING_PLANES; ++ i ) {\n\t\tvec4 plane = clippingPlanes[ i ];\n\t\tif ( dot( vViewPosition, plane.xyz ) > plane.w ) discard;\n\t}\n\t\t\n\t#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\n\t\tbool clipped = true;\n\t\tfor ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; ++ i ) {\n\t\t\tvec4 plane = clippingPlanes[ i ];\n\t\t\tclipped = ( dot( vViewPosition, plane.xyz ) > plane.w ) && clipped;\n\t\t}\n\t\tif ( clipped ) discard;\n\t\n\t#endif\n#endif\n";
  2903. var clipping_planes_pars_fragment = "#if NUM_CLIPPING_PLANES > 0\n\t#if ! defined( PHYSICAL ) && ! defined( PHONG )\n\t\tvarying vec3 vViewPosition;\n\t#endif\n\tuniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];\n#endif\n";
  2904. var clipping_planes_pars_vertex = "#if NUM_CLIPPING_PLANES > 0 && ! defined( PHYSICAL ) && ! defined( PHONG )\n\tvarying vec3 vViewPosition;\n#endif\n";
  2905. var clipping_planes_vertex = "#if NUM_CLIPPING_PLANES > 0 && ! defined( PHYSICAL ) && ! defined( PHONG )\n\tvViewPosition = - mvPosition.xyz;\n#endif\n";
  2906. var color_fragment = "#ifdef USE_COLOR\n\tdiffuseColor.rgb *= vColor;\n#endif";
  2907. var color_pars_fragment = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif\n";
  2908. var color_pars_vertex = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";
  2909. var color_vertex = "#ifdef USE_COLOR\n\tvColor.xyz = color.xyz;\n#endif";
  2910. var common = "#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI_HALF 1.5707963267949\n#define RECIPROCAL_PI 0.31830988618\n#define RECIPROCAL_PI2 0.15915494\n#define LOG2 1.442695\n#define EPSILON 1e-6\n#define saturate(a) clamp( a, 0.0, 1.0 )\n#define whiteCompliment(a) ( 1.0 - saturate( a ) )\nfloat pow2( const in float x ) { return x*x; }\nfloat pow3( const in float x ) { return x*x*x; }\nfloat pow4( const in float x ) { float x2 = x*x; return x2*x2; }\nfloat average( const in vec3 color ) { return dot( color, vec3( 0.3333 ) ); }\nhighp float rand( const in vec2 uv ) {\n\tconst highp float a = 12.9898, b = 78.233, c = 43758.5453;\n\thighp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );\n\treturn fract(sin(sn) * c);\n}\nstruct IncidentLight {\n\tvec3 color;\n\tvec3 direction;\n\tbool visible;\n};\nstruct ReflectedLight {\n\tvec3 directDiffuse;\n\tvec3 directSpecular;\n\tvec3 indirectDiffuse;\n\tvec3 indirectSpecular;\n};\nstruct GeometricContext {\n\tvec3 position;\n\tvec3 normal;\n\tvec3 viewDir;\n};\nvec3 transformDirection( in vec3 dir, in mat4 matrix ) {\n\treturn normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );\n}\nvec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) {\n\treturn normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );\n}\nvec3 projectOnPlane(in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\tfloat distance = dot( planeNormal, point - pointOnPlane );\n\treturn - distance * planeNormal + point;\n}\nfloat sideOfPlane( in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\treturn sign( dot( point - pointOnPlane, planeNormal ) );\n}\nvec3 linePlaneIntersect( in vec3 pointOnLine, in vec3 lineDirection, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\treturn lineDirection * ( dot( planeNormal, pointOnPlane - pointOnLine ) / dot( planeNormal, lineDirection ) ) + pointOnLine;\n}\nmat3 transpose( const in mat3 v ) {\n\tmat3 tmp;\n\ttmp[0] = vec3(v[0].x, v[1].x, v[2].x);\n\ttmp[1] = vec3(v[0].y, v[1].y, v[2].y);\n\ttmp[2] = vec3(v[0].z, v[1].z, v[2].z);\n\treturn tmp;\n}\n";
  2911. var cube_uv_reflection_fragment = "#ifdef ENVMAP_TYPE_CUBE_UV\n#define cubeUV_textureSize (1024.0)\nint getFaceFromDirection(vec3 direction) {\n\tvec3 absDirection = abs(direction);\n\tint face = -1;\n\tif( absDirection.x > absDirection.z ) {\n\t\tif(absDirection.x > absDirection.y )\n\t\t\tface = direction.x > 0.0 ? 0 : 3;\n\t\telse\n\t\t\tface = direction.y > 0.0 ? 1 : 4;\n\t}\n\telse {\n\t\tif(absDirection.z > absDirection.y )\n\t\t\tface = direction.z > 0.0 ? 2 : 5;\n\t\telse\n\t\t\tface = direction.y > 0.0 ? 1 : 4;\n\t}\n\treturn face;\n}\n#define cubeUV_maxLods1 (log2(cubeUV_textureSize*0.25) - 1.0)\n#define cubeUV_rangeClamp (exp2((6.0 - 1.0) * 2.0))\nvec2 MipLevelInfo( vec3 vec, float roughnessLevel, float roughness ) {\n\tfloat scale = exp2(cubeUV_maxLods1 - roughnessLevel);\n\tfloat dxRoughness = dFdx(roughness);\n\tfloat dyRoughness = dFdy(roughness);\n\tvec3 dx = dFdx( vec * scale * dxRoughness );\n\tvec3 dy = dFdy( vec * scale * dyRoughness );\n\tfloat d = max( dot( dx, dx ), dot( dy, dy ) );\n\td = clamp(d, 1.0, cubeUV_rangeClamp);\n\tfloat mipLevel = 0.5 * log2(d);\n\treturn vec2(floor(mipLevel), fract(mipLevel));\n}\n#define cubeUV_maxLods2 (log2(cubeUV_textureSize*0.25) - 2.0)\n#define cubeUV_rcpTextureSize (1.0 / cubeUV_textureSize)\nvec2 getCubeUV(vec3 direction, float roughnessLevel, float mipLevel) {\n\tmipLevel = roughnessLevel > cubeUV_maxLods2 - 3.0 ? 0.0 : mipLevel;\n\tfloat a = 16.0 * cubeUV_rcpTextureSize;\n\tvec2 exp2_packed = exp2( vec2( roughnessLevel, mipLevel ) );\n\tvec2 rcp_exp2_packed = vec2( 1.0 ) / exp2_packed;\n\tfloat powScale = exp2_packed.x * exp2_packed.y;\n\tfloat scale = rcp_exp2_packed.x * rcp_exp2_packed.y * 0.25;\n\tfloat mipOffset = 0.75*(1.0 - rcp_exp2_packed.y) * rcp_exp2_packed.x;\n\tbool bRes = mipLevel == 0.0;\n\tscale = bRes && (scale < a) ? a : scale;\n\tvec3 r;\n\tvec2 offset;\n\tint face = getFaceFromDirection(direction);\n\tfloat rcpPowScale = 1.0 / powScale;\n\tif( face == 0) {\n\t\tr = vec3(direction.x, -direction.z, direction.y);\n\t\toffset = vec2(0.0+mipOffset,0.75 * rcpPowScale);\n\t\toffset.y = bRes && (offset.y < 2.0*a) ? a : offset.y;\n\t}\n\telse if( face == 1) {\n\t\tr = vec3(direction.y, direction.x, direction.z);\n\t\toffset = vec2(scale+mipOffset, 0.75 * rcpPowScale);\n\t\toffset.y = bRes && (offset.y < 2.0*a) ? a : offset.y;\n\t}\n\telse if( face == 2) {\n\t\tr = vec3(direction.z, direction.x, direction.y);\n\t\toffset = vec2(2.0*scale+mipOffset, 0.75 * rcpPowScale);\n\t\toffset.y = bRes && (offset.y < 2.0*a) ? a : offset.y;\n\t}\n\telse if( face == 3) {\n\t\tr = vec3(direction.x, direction.z, direction.y);\n\t\toffset = vec2(0.0+mipOffset,0.5 * rcpPowScale);\n\t\toffset.y = bRes && (offset.y < 2.0*a) ? 0.0 : offset.y;\n\t}\n\telse if( face == 4) {\n\t\tr = vec3(direction.y, direction.x, -direction.z);\n\t\toffset = vec2(scale+mipOffset, 0.5 * rcpPowScale);\n\t\toffset.y = bRes && (offset.y < 2.0*a) ? 0.0 : offset.y;\n\t}\n\telse {\n\t\tr = vec3(direction.z, -direction.x, direction.y);\n\t\toffset = vec2(2.0*scale+mipOffset, 0.5 * rcpPowScale);\n\t\toffset.y = bRes && (offset.y < 2.0*a) ? 0.0 : offset.y;\n\t}\n\tr = normalize(r);\n\tfloat texelOffset = 0.5 * cubeUV_rcpTextureSize;\n\tvec2 s = ( r.yz / abs( r.x ) + vec2( 1.0 ) ) * 0.5;\n\tvec2 base = offset + vec2( texelOffset );\n\treturn base + s * ( scale - 2.0 * texelOffset );\n}\n#define cubeUV_maxLods3 (log2(cubeUV_textureSize*0.25) - 3.0)\nvec4 textureCubeUV(vec3 reflectedDirection, float roughness ) {\n\tfloat roughnessVal = roughness* cubeUV_maxLods3;\n\tfloat r1 = floor(roughnessVal);\n\tfloat r2 = r1 + 1.0;\n\tfloat t = fract(roughnessVal);\n\tvec2 mipInfo = MipLevelInfo(reflectedDirection, r1, roughness);\n\tfloat s = mipInfo.y;\n\tfloat level0 = mipInfo.x;\n\tfloat level1 = level0 + 1.0;\n\tlevel1 = level1 > 5.0 ? 5.0 : level1;\n\tlevel0 += min( floor( s + 0.5 ), 5.0 );\n\tvec2 uv_10 = getCubeUV(reflectedDirection, r1, level0);\n\tvec4 color10 = envMapTexelToLinear(texture2D(envMap, uv_10));\n\tvec2 uv_20 = getCubeUV(reflectedDirection, r2, level0);\n\tvec4 color20 = envMapTexelToLinear(texture2D(envMap, uv_20));\n\tvec4 result = mix(color10, color20, t);\n\treturn vec4(result.rgb, 1.0);\n}\n#endif\n";
  2912. var defaultnormal_vertex = "vec3 transformedNormal = normalMatrix * objectNormal;\n#ifdef FLIP_SIDED\n\ttransformedNormal = - transformedNormal;\n#endif\n";
  2913. var displacementmap_pars_vertex = "#ifdef USE_DISPLACEMENTMAP\n\tuniform sampler2D displacementMap;\n\tuniform float displacementScale;\n\tuniform float displacementBias;\n#endif\n";
  2914. var displacementmap_vertex = "#ifdef USE_DISPLACEMENTMAP\n\ttransformed += normalize( objectNormal ) * ( texture2D( displacementMap, uv ).x * displacementScale + displacementBias );\n#endif\n";
  2915. var emissivemap_fragment = "#ifdef USE_EMISSIVEMAP\n\tvec4 emissiveColor = texture2D( emissiveMap, vUv );\n\temissiveColor.rgb = emissiveMapTexelToLinear( emissiveColor ).rgb;\n\ttotalEmissiveRadiance *= emissiveColor.rgb;\n#endif\n";
  2916. var emissivemap_pars_fragment = "#ifdef USE_EMISSIVEMAP\n\tuniform sampler2D emissiveMap;\n#endif\n";
  2917. var encodings_fragment = " gl_FragColor = linearToOutputTexel( gl_FragColor );\n";
  2918. var encodings_pars_fragment = "\nvec4 LinearToLinear( in vec4 value ) {\n\treturn value;\n}\nvec4 GammaToLinear( in vec4 value, in float gammaFactor ) {\n\treturn vec4( pow( value.xyz, vec3( gammaFactor ) ), value.w );\n}\nvec4 LinearToGamma( in vec4 value, in float gammaFactor ) {\n\treturn vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );\n}\nvec4 sRGBToLinear( in vec4 value ) {\n\treturn vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.w );\n}\nvec4 LinearTosRGB( in vec4 value ) {\n\treturn vec4( mix( pow( value.rgb, vec3( 0.41666 ) ) * 1.055 - vec3( 0.055 ), value.rgb * 12.92, vec3( lessThanEqual( value.rgb, vec3( 0.0031308 ) ) ) ), value.w );\n}\nvec4 RGBEToLinear( in vec4 value ) {\n\treturn vec4( value.rgb * exp2( value.a * 255.0 - 128.0 ), 1.0 );\n}\nvec4 LinearToRGBE( in vec4 value ) {\n\tfloat maxComponent = max( max( value.r, value.g ), value.b );\n\tfloat fExp = clamp( ceil( log2( maxComponent ) ), -128.0, 127.0 );\n\treturn vec4( value.rgb / exp2( fExp ), ( fExp + 128.0 ) / 255.0 );\n}\nvec4 RGBMToLinear( in vec4 value, in float maxRange ) {\n\treturn vec4( value.xyz * value.w * maxRange, 1.0 );\n}\nvec4 LinearToRGBM( in vec4 value, in float maxRange ) {\n\tfloat maxRGB = max( value.x, max( value.g, value.b ) );\n\tfloat M = clamp( maxRGB / maxRange, 0.0, 1.0 );\n\tM = ceil( M * 255.0 ) / 255.0;\n\treturn vec4( value.rgb / ( M * maxRange ), M );\n}\nvec4 RGBDToLinear( in vec4 value, in float maxRange ) {\n\treturn vec4( value.rgb * ( ( maxRange / 255.0 ) / value.a ), 1.0 );\n}\nvec4 LinearToRGBD( in vec4 value, in float maxRange ) {\n\tfloat maxRGB = max( value.x, max( value.g, value.b ) );\n\tfloat D = max( maxRange / maxRGB, 1.0 );\n\tD = min( floor( D ) / 255.0, 1.0 );\n\treturn vec4( value.rgb * ( D * ( 255.0 / maxRange ) ), D );\n}\nconst mat3 cLogLuvM = mat3( 0.2209, 0.3390, 0.4184, 0.1138, 0.6780, 0.7319, 0.0102, 0.1130, 0.2969 );\nvec4 LinearToLogLuv( in vec4 value ) {\n\tvec3 Xp_Y_XYZp = value.rgb * cLogLuvM;\n\tXp_Y_XYZp = max(Xp_Y_XYZp, vec3(1e-6, 1e-6, 1e-6));\n\tvec4 vResult;\n\tvResult.xy = Xp_Y_XYZp.xy / Xp_Y_XYZp.z;\n\tfloat Le = 2.0 * log2(Xp_Y_XYZp.y) + 127.0;\n\tvResult.w = fract(Le);\n\tvResult.z = (Le - (floor(vResult.w*255.0))/255.0)/255.0;\n\treturn vResult;\n}\nconst mat3 cLogLuvInverseM = mat3( 6.0014, -2.7008, -1.7996, -1.3320, 3.1029, -5.7721, 0.3008, -1.0882, 5.6268 );\nvec4 LogLuvToLinear( in vec4 value ) {\n\tfloat Le = value.z * 255.0 + value.w;\n\tvec3 Xp_Y_XYZp;\n\tXp_Y_XYZp.y = exp2((Le - 127.0) / 2.0);\n\tXp_Y_XYZp.z = Xp_Y_XYZp.y / value.y;\n\tXp_Y_XYZp.x = value.x * Xp_Y_XYZp.z;\n\tvec3 vRGB = Xp_Y_XYZp.rgb * cLogLuvInverseM;\n\treturn vec4( max(vRGB, 0.0), 1.0 );\n}\n";
  2919. var envmap_fragment = "#ifdef USE_ENVMAP\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG )\n\t\tvec3 cameraToVertex = normalize( vWorldPosition - cameraPosition );\n\t\tvec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t\tvec3 reflectVec = reflect( cameraToVertex, worldNormal );\n\t\t#else\n\t\t\tvec3 reflectVec = refract( cameraToVertex, worldNormal, refractionRatio );\n\t\t#endif\n\t#else\n\t\tvec3 reflectVec = vReflect;\n\t#endif\n\t#ifdef ENVMAP_TYPE_CUBE\n\t\tvec4 envColor = textureCube( envMap, flipNormal * vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );\n\t#elif defined( ENVMAP_TYPE_EQUIREC )\n\t\tvec2 sampleUV;\n\t\tsampleUV.y = asin( flipNormal * reflectVec.y ) * RECIPROCAL_PI + 0.5;\n\t\tsampleUV.x = atan( flipNormal * reflectVec.z, flipNormal * reflectVec.x ) * RECIPROCAL_PI2 + 0.5;\n\t\tvec4 envColor = texture2D( envMap, sampleUV );\n\t#elif defined( ENVMAP_TYPE_SPHERE )\n\t\tvec3 reflectView = flipNormal * normalize( ( viewMatrix * vec4( reflectVec, 0.0 ) ).xyz + vec3( 0.0, 0.0, 1.0 ) );\n\t\tvec4 envColor = texture2D( envMap, reflectView.xy * 0.5 + 0.5 );\n\t#else\n\t\tvec4 envColor = vec4( 0.0 );\n\t#endif\n\tenvColor = envMapTexelToLinear( envColor );\n\t#ifdef ENVMAP_BLENDING_MULTIPLY\n\t\toutgoingLight = mix( outgoingLight, outgoingLight * envColor.xyz, specularStrength * reflectivity );\n\t#elif defined( ENVMAP_BLENDING_MIX )\n\t\toutgoingLight = mix( outgoingLight, envColor.xyz, specularStrength * reflectivity );\n\t#elif defined( ENVMAP_BLENDING_ADD )\n\t\toutgoingLight += envColor.xyz * specularStrength * reflectivity;\n\t#endif\n#endif\n";
  2920. var envmap_pars_fragment = "#if defined( USE_ENVMAP ) || defined( PHYSICAL )\n\tuniform float reflectivity;\n\tuniform float envMapIntensity;\n#endif\n#ifdef USE_ENVMAP\n\t#if ! defined( PHYSICAL ) && ( defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) )\n\t\tvarying vec3 vWorldPosition;\n\t#endif\n\t#ifdef ENVMAP_TYPE_CUBE\n\t\tuniform samplerCube envMap;\n\t#else\n\t\tuniform sampler2D envMap;\n\t#endif\n\tuniform float flipEnvMap;\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( PHYSICAL )\n\t\tuniform float refractionRatio;\n\t#else\n\t\tvarying vec3 vReflect;\n\t#endif\n#endif\n";
  2921. var envmap_pars_vertex = "#ifdef USE_ENVMAP\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG )\n\t\tvarying vec3 vWorldPosition;\n\t#else\n\t\tvarying vec3 vReflect;\n\t\tuniform float refractionRatio;\n\t#endif\n#endif\n";
  2922. var envmap_vertex = "#ifdef USE_ENVMAP\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG )\n\t\tvWorldPosition = worldPosition.xyz;\n\t#else\n\t\tvec3 cameraToVertex = normalize( worldPosition.xyz - cameraPosition );\n\t\tvec3 worldNormal = inverseTransformDirection( transformedNormal, viewMatrix );\n\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t\tvReflect = reflect( cameraToVertex, worldNormal );\n\t\t#else\n\t\t\tvReflect = refract( cameraToVertex, worldNormal, refractionRatio );\n\t\t#endif\n\t#endif\n#endif\n";
  2923. var fog_vertex = "\n#ifdef USE_FOG\nfogDepth = -mvPosition.z;\n#endif";
  2924. var fog_pars_vertex = "#ifdef USE_FOG\n varying float fogDepth;\n#endif\n";
  2925. var fog_fragment = "#ifdef USE_FOG\n\t#ifdef FOG_EXP2\n\t\tfloat fogFactor = whiteCompliment( exp2( - fogDensity * fogDensity * fogDepth * fogDepth * LOG2 ) );\n\t#else\n\t\tfloat fogFactor = smoothstep( fogNear, fogFar, fogDepth );\n\t#endif\n\tgl_FragColor.rgb = mix( gl_FragColor.rgb, fogColor, fogFactor );\n#endif\n";
  2926. var fog_pars_fragment = "#ifdef USE_FOG\n\tuniform vec3 fogColor;\n\tvarying float fogDepth;\n\t#ifdef FOG_EXP2\n\t\tuniform float fogDensity;\n\t#else\n\t\tuniform float fogNear;\n\t\tuniform float fogFar;\n\t#endif\n#endif\n";
  2927. var gradientmap_pars_fragment = "#ifdef TOON\n\tuniform sampler2D gradientMap;\n\tvec3 getGradientIrradiance( vec3 normal, vec3 lightDirection ) {\n\t\tfloat dotNL = dot( normal, lightDirection );\n\t\tvec2 coord = vec2( dotNL * 0.5 + 0.5, 0.0 );\n\t\t#ifdef USE_GRADIENTMAP\n\t\t\treturn texture2D( gradientMap, coord ).rgb;\n\t\t#else\n\t\t\treturn ( coord.x < 0.7 ) ? vec3( 0.7 ) : vec3( 1.0 );\n\t\t#endif\n\t}\n#endif\n";
  2928. var lightmap_fragment = "#ifdef USE_LIGHTMAP\n\treflectedLight.indirectDiffuse += PI * texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\n#endif\n";
  2929. var lightmap_pars_fragment = "#ifdef USE_LIGHTMAP\n\tuniform sampler2D lightMap;\n\tuniform float lightMapIntensity;\n#endif";
  2930. var lights_lambert_vertex = "vec3 diffuse = vec3( 1.0 );\nGeometricContext geometry;\ngeometry.position = mvPosition.xyz;\ngeometry.normal = normalize( transformedNormal );\ngeometry.viewDir = normalize( -mvPosition.xyz );\nGeometricContext backGeometry;\nbackGeometry.position = geometry.position;\nbackGeometry.normal = -geometry.normal;\nbackGeometry.viewDir = geometry.viewDir;\nvLightFront = vec3( 0.0 );\n#ifdef DOUBLE_SIDED\n\tvLightBack = vec3( 0.0 );\n#endif\nIncidentLight directLight;\nfloat dotNL;\nvec3 directLightColor_Diffuse;\n#if NUM_POINT_LIGHTS > 0\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\t\tgetPointDirectLightIrradiance( pointLights[ i ], geometry, directLight );\n\t\tdotNL = dot( geometry.normal, directLight.direction );\n\t\tdirectLightColor_Diffuse = PI * directLight.color;\n\t\tvLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tvLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\n\t\t#endif\n\t}\n#endif\n#if NUM_SPOT_LIGHTS > 0\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n\t\tgetSpotDirectLightIrradiance( spotLights[ i ], geometry, directLight );\n\t\tdotNL = dot( geometry.normal, directLight.direction );\n\t\tdirectLightColor_Diffuse = PI * directLight.color;\n\t\tvLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tvLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\n\t\t#endif\n\t}\n#endif\n#if NUM_DIR_LIGHTS > 0\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\t\tgetDirectionalDirectLightIrradiance( directionalLights[ i ], geometry, directLight );\n\t\tdotNL = dot( geometry.normal, directLight.direction );\n\t\tdirectLightColor_Diffuse = PI * directLight.color;\n\t\tvLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tvLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\n\t\t#endif\n\t}\n#endif\n#if NUM_HEMI_LIGHTS > 0\n\tfor ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n\t\tvLightFront += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry );\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tvLightBack += getHemisphereLightIrradiance( hemisphereLights[ i ], backGeometry );\n\t\t#endif\n\t}\n#endif\n";
  2931. var lights_pars = "uniform vec3 ambientLightColor;\nvec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {\n\tvec3 irradiance = ambientLightColor;\n\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\tirradiance *= PI;\n\t#endif\n\treturn irradiance;\n}\n#if NUM_DIR_LIGHTS > 0\n\tstruct DirectionalLight {\n\t\tvec3 direction;\n\t\tvec3 color;\n\t\tint shadow;\n\t\tfloat shadowBias;\n\t\tfloat shadowRadius;\n\t\tvec2 shadowMapSize;\n\t};\n\tuniform DirectionalLight directionalLights[ NUM_DIR_LIGHTS ];\n\tvoid getDirectionalDirectLightIrradiance( const in DirectionalLight directionalLight, const in GeometricContext geometry, out IncidentLight directLight ) {\n\t\tdirectLight.color = directionalLight.color;\n\t\tdirectLight.direction = directionalLight.direction;\n\t\tdirectLight.visible = true;\n\t}\n#endif\n#if NUM_POINT_LIGHTS > 0\n\tstruct PointLight {\n\t\tvec3 position;\n\t\tvec3 color;\n\t\tfloat distance;\n\t\tfloat decay;\n\t\tint shadow;\n\t\tfloat shadowBias;\n\t\tfloat shadowRadius;\n\t\tvec2 shadowMapSize;\n\t};\n\tuniform PointLight pointLights[ NUM_POINT_LIGHTS ];\n\tvoid getPointDirectLightIrradiance( const in PointLight pointLight, const in GeometricContext geometry, out IncidentLight directLight ) {\n\t\tvec3 lVector = pointLight.position - geometry.position;\n\t\tdirectLight.direction = normalize( lVector );\n\t\tfloat lightDistance = length( lVector );\n\t\tdirectLight.color = pointLight.color;\n\t\tdirectLight.color *= punctualLightIntensityToIrradianceFactor( lightDistance, pointLight.distance, pointLight.decay );\n\t\tdirectLight.visible = ( directLight.color != vec3( 0.0 ) );\n\t}\n#endif\n#if NUM_SPOT_LIGHTS > 0\n\tstruct SpotLight {\n\t\tvec3 position;\n\t\tvec3 direction;\n\t\tvec3 color;\n\t\tfloat distance;\n\t\tfloat decay;\n\t\tfloat coneCos;\n\t\tfloat penumbraCos;\n\t\tint shadow;\n\t\tfloat shadowBias;\n\t\tfloat shadowRadius;\n\t\tvec2 shadowMapSize;\n\t};\n\tuniform SpotLight spotLights[ NUM_SPOT_LIGHTS ];\n\tvoid getSpotDirectLightIrradiance( const in SpotLight spotLight, const in GeometricContext geometry, out IncidentLight directLight ) {\n\t\tvec3 lVector = spotLight.position - geometry.position;\n\t\tdirectLight.direction = normalize( lVector );\n\t\tfloat lightDistance = length( lVector );\n\t\tfloat angleCos = dot( directLight.direction, spotLight.direction );\n\t\tif ( angleCos > spotLight.coneCos ) {\n\t\t\tfloat spotEffect = smoothstep( spotLight.coneCos, spotLight.penumbraCos, angleCos );\n\t\t\tdirectLight.color = spotLight.color;\n\t\t\tdirectLight.color *= spotEffect * punctualLightIntensityToIrradianceFactor( lightDistance, spotLight.distance, spotLight.decay );\n\t\t\tdirectLight.visible = true;\n\t\t} else {\n\t\t\tdirectLight.color = vec3( 0.0 );\n\t\t\tdirectLight.visible = false;\n\t\t}\n\t}\n#endif\n#if NUM_RECT_AREA_LIGHTS > 0\n\tstruct RectAreaLight {\n\t\tvec3 color;\n\t\tvec3 position;\n\t\tvec3 halfWidth;\n\t\tvec3 halfHeight;\n\t};\n\tuniform sampler2D ltcMat;\tuniform sampler2D ltcMag;\n\tuniform RectAreaLight rectAreaLights[ NUM_RECT_AREA_LIGHTS ];\n#endif\n#if NUM_HEMI_LIGHTS > 0\n\tstruct HemisphereLight {\n\t\tvec3 direction;\n\t\tvec3 skyColor;\n\t\tvec3 groundColor;\n\t};\n\tuniform HemisphereLight hemisphereLights[ NUM_HEMI_LIGHTS ];\n\tvec3 getHemisphereLightIrradiance( const in HemisphereLight hemiLight, const in GeometricContext geometry ) {\n\t\tfloat dotNL = dot( geometry.normal, hemiLight.direction );\n\t\tfloat hemiDiffuseWeight = 0.5 * dotNL + 0.5;\n\t\tvec3 irradiance = mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight );\n\t\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\t\tirradiance *= PI;\n\t\t#endif\n\t\treturn irradiance;\n\t}\n#endif\n#if defined( USE_ENVMAP ) && defined( PHYSICAL )\n\tvec3 getLightProbeIndirectIrradiance( const in GeometricContext geometry, const in int maxMIPLevel ) {\n\t\tvec3 worldNormal = inverseTransformDirection( geometry.normal, viewMatrix );\n\t\t#ifdef ENVMAP_TYPE_CUBE\n\t\t\tvec3 queryVec = vec3( flipEnvMap * worldNormal.x, worldNormal.yz );\n\t\t\t#ifdef TEXTURE_LOD_EXT\n\t\t\t\tvec4 envMapColor = textureCubeLodEXT( envMap, queryVec, float( maxMIPLevel ) );\n\t\t\t#else\n\t\t\t\tvec4 envMapColor = textureCube( envMap, queryVec, float( maxMIPLevel ) );\n\t\t\t#endif\n\t\t\tenvMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;\n\t\t#elif defined( ENVMAP_TYPE_CUBE_UV )\n\t\t\tvec3 queryVec = vec3( flipEnvMap * worldNormal.x, worldNormal.yz );\n\t\t\tvec4 envMapColor = textureCubeUV( queryVec, 1.0 );\n\t\t#else\n\t\t\tvec4 envMapColor = vec4( 0.0 );\n\t\t#endif\n\t\treturn PI * envMapColor.rgb * envMapIntensity;\n\t}\n\tfloat getSpecularMIPLevel( const in float blinnShininessExponent, const in int maxMIPLevel ) {\n\t\tfloat maxMIPLevelScalar = float( maxMIPLevel );\n\t\tfloat desiredMIPLevel = maxMIPLevelScalar - 0.79248 - 0.5 * log2( pow2( blinnShininessExponent ) + 1.0 );\n\t\treturn clamp( desiredMIPLevel, 0.0, maxMIPLevelScalar );\n\t}\n\tvec3 getLightProbeIndirectRadiance( const in GeometricContext geometry, const in float blinnShininessExponent, const in int maxMIPLevel ) {\n\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t\tvec3 reflectVec = reflect( -geometry.viewDir, geometry.normal );\n\t\t#else\n\t\t\tvec3 reflectVec = refract( -geometry.viewDir, geometry.normal, refractionRatio );\n\t\t#endif\n\t\treflectVec = inverseTransformDirection( reflectVec, viewMatrix );\n\t\tfloat specularMIPLevel = getSpecularMIPLevel( blinnShininessExponent, maxMIPLevel );\n\t\t#ifdef ENVMAP_TYPE_CUBE\n\t\t\tvec3 queryReflectVec = vec3( flipEnvMap * reflectVec.x, reflectVec.yz );\n\t\t\t#ifdef TEXTURE_LOD_EXT\n\t\t\t\tvec4 envMapColor = textureCubeLodEXT( envMap, queryReflectVec, specularMIPLevel );\n\t\t\t#else\n\t\t\t\tvec4 envMapColor = textureCube( envMap, queryReflectVec, specularMIPLevel );\n\t\t\t#endif\n\t\t\tenvMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;\n\t\t#elif defined( ENVMAP_TYPE_CUBE_UV )\n\t\t\tvec3 queryReflectVec = vec3( flipEnvMap * reflectVec.x, reflectVec.yz );\n\t\t\tvec4 envMapColor = textureCubeUV(queryReflectVec, BlinnExponentToGGXRoughness(blinnShininessExponent));\n\t\t#elif defined( ENVMAP_TYPE_EQUIREC )\n\t\t\tvec2 sampleUV;\n\t\t\tsampleUV.y = saturate( reflectVec.y * 0.5 + 0.5 );\n\t\t\tsampleUV.x = atan( reflectVec.z, reflectVec.x ) * RECIPROCAL_PI2 + 0.5;\n\t\t\t#ifdef TEXTURE_LOD_EXT\n\t\t\t\tvec4 envMapColor = texture2DLodEXT( envMap, sampleUV, specularMIPLevel );\n\t\t\t#else\n\t\t\t\tvec4 envMapColor = texture2D( envMap, sampleUV, specularMIPLevel );\n\t\t\t#endif\n\t\t\tenvMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;\n\t\t#elif defined( ENVMAP_TYPE_SPHERE )\n\t\t\tvec3 reflectView = normalize( ( viewMatrix * vec4( reflectVec, 0.0 ) ).xyz + vec3( 0.0,0.0,1.0 ) );\n\t\t\t#ifdef TEXTURE_LOD_EXT\n\t\t\t\tvec4 envMapColor = texture2DLodEXT( envMap, reflectView.xy * 0.5 + 0.5, specularMIPLevel );\n\t\t\t#else\n\t\t\t\tvec4 envMapColor = texture2D( envMap, reflectView.xy * 0.5 + 0.5, specularMIPLevel );\n\t\t\t#endif\n\t\t\tenvMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;\n\t\t#endif\n\t\treturn envMapColor.rgb * envMapIntensity;\n\t}\n#endif\n";
  2932. var lights_phong_fragment = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;\n";
  2933. var lights_phong_pars_fragment = "varying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\nstruct BlinnPhongMaterial {\n\tvec3\tdiffuseColor;\n\tvec3\tspecularColor;\n\tfloat\tspecularShininess;\n\tfloat\tspecularStrength;\n};\nvoid RE_Direct_BlinnPhong( const in IncidentLight directLight, const in GeometricContext geometry, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {\n\t#ifdef TOON\n\t\tvec3 irradiance = getGradientIrradiance( geometry.normal, directLight.direction ) * directLight.color;\n\t#else\n\t\tfloat dotNL = saturate( dot( geometry.normal, directLight.direction ) );\n\t\tvec3 irradiance = dotNL * directLight.color;\n\t#endif\n\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\tirradiance *= PI;\n\t#endif\n\treflectedLight.directDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n\treflectedLight.directSpecular += irradiance * BRDF_Specular_BlinnPhong( directLight, geometry, material.specularColor, material.specularShininess ) * material.specularStrength;\n}\nvoid RE_IndirectDiffuse_BlinnPhong( const in vec3 irradiance, const in GeometricContext geometry, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n}\n#define RE_Direct\t\t\t\tRE_Direct_BlinnPhong\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_BlinnPhong\n#define Material_LightProbeLOD( material )\t(0)\n";
  2934. var lights_physical_fragment = "PhysicalMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb * ( 1.0 - metalnessFactor );\nmaterial.specularRoughness = clamp( roughnessFactor, 0.04, 1.0 );\n#ifdef STANDARD\n\tmaterial.specularColor = mix( vec3( DEFAULT_SPECULAR_COEFFICIENT ), diffuseColor.rgb, metalnessFactor );\n#else\n\tmaterial.specularColor = mix( vec3( MAXIMUM_SPECULAR_COEFFICIENT * pow2( reflectivity ) ), diffuseColor.rgb, metalnessFactor );\n\tmaterial.clearCoat = saturate( clearCoat );\tmaterial.clearCoatRoughness = clamp( clearCoatRoughness, 0.04, 1.0 );\n#endif\n";
  2935. var lights_physical_pars_fragment = "struct PhysicalMaterial {\n\tvec3\tdiffuseColor;\n\tfloat\tspecularRoughness;\n\tvec3\tspecularColor;\n\t#ifndef STANDARD\n\t\tfloat clearCoat;\n\t\tfloat clearCoatRoughness;\n\t#endif\n};\n#define MAXIMUM_SPECULAR_COEFFICIENT 0.16\n#define DEFAULT_SPECULAR_COEFFICIENT 0.04\nfloat clearCoatDHRApprox( const in float roughness, const in float dotNL ) {\n\treturn DEFAULT_SPECULAR_COEFFICIENT + ( 1.0 - DEFAULT_SPECULAR_COEFFICIENT ) * ( pow( 1.0 - dotNL, 5.0 ) * pow( 1.0 - roughness, 2.0 ) );\n}\n#if NUM_RECT_AREA_LIGHTS > 0\n\tvoid RE_Direct_RectArea_Physical( const in RectAreaLight rectAreaLight, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\t\tvec3 normal = geometry.normal;\n\t\tvec3 viewDir = geometry.viewDir;\n\t\tvec3 position = geometry.position;\n\t\tvec3 lightPos = rectAreaLight.position;\n\t\tvec3 halfWidth = rectAreaLight.halfWidth;\n\t\tvec3 halfHeight = rectAreaLight.halfHeight;\n\t\tvec3 lightColor = rectAreaLight.color;\n\t\tfloat roughness = material.specularRoughness;\n\t\tvec3 rectCoords[ 4 ];\n\t\trectCoords[ 0 ] = lightPos - halfWidth - halfHeight;\t\trectCoords[ 1 ] = lightPos + halfWidth - halfHeight;\n\t\trectCoords[ 2 ] = lightPos + halfWidth + halfHeight;\n\t\trectCoords[ 3 ] = lightPos - halfWidth + halfHeight;\n\t\tvec2 uv = LTC_Uv( normal, viewDir, roughness );\n\t\tfloat norm = texture2D( ltcMag, uv ).a;\n\t\tvec4 t = texture2D( ltcMat, uv );\n\t\tmat3 mInv = mat3(\n\t\t\tvec3( 1, 0, t.y ),\n\t\t\tvec3( 0, t.z, 0 ),\n\t\t\tvec3( t.w, 0, t.x )\n\t\t);\n\t\treflectedLight.directSpecular += lightColor * material.specularColor * norm * LTC_Evaluate( normal, viewDir, position, mInv, rectCoords );\n\t\treflectedLight.directDiffuse += lightColor * material.diffuseColor * LTC_Evaluate( normal, viewDir, position, mat3( 1 ), rectCoords );\n\t}\n#endif\nvoid RE_Direct_Physical( const in IncidentLight directLight, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\tfloat dotNL = saturate( dot( geometry.normal, directLight.direction ) );\n\tvec3 irradiance = dotNL * directLight.color;\n\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\tirradiance *= PI;\n\t#endif\n\t#ifndef STANDARD\n\t\tfloat clearCoatDHR = material.clearCoat * clearCoatDHRApprox( material.clearCoatRoughness, dotNL );\n\t#else\n\t\tfloat clearCoatDHR = 0.0;\n\t#endif\n\treflectedLight.directSpecular += ( 1.0 - clearCoatDHR ) * irradiance * BRDF_Specular_GGX( directLight, geometry, material.specularColor, material.specularRoughness );\n\treflectedLight.directDiffuse += ( 1.0 - clearCoatDHR ) * irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n\t#ifndef STANDARD\n\t\treflectedLight.directSpecular += irradiance * material.clearCoat * BRDF_Specular_GGX( directLight, geometry, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearCoatRoughness );\n\t#endif\n}\nvoid RE_IndirectDiffuse_Physical( const in vec3 irradiance, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectSpecular_Physical( const in vec3 radiance, const in vec3 clearCoatRadiance, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\t#ifndef STANDARD\n\t\tfloat dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n\t\tfloat dotNL = dotNV;\n\t\tfloat clearCoatDHR = material.clearCoat * clearCoatDHRApprox( material.clearCoatRoughness, dotNL );\n\t#else\n\t\tfloat clearCoatDHR = 0.0;\n\t#endif\n\treflectedLight.indirectSpecular += ( 1.0 - clearCoatDHR ) * radiance * BRDF_Specular_GGX_Environment( geometry, material.specularColor, material.specularRoughness );\n\t#ifndef STANDARD\n\t\treflectedLight.indirectSpecular += clearCoatRadiance * material.clearCoat * BRDF_Specular_GGX_Environment( geometry, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearCoatRoughness );\n\t#endif\n}\n#define RE_Direct\t\t\t\tRE_Direct_Physical\n#define RE_Direct_RectArea\t\tRE_Direct_RectArea_Physical\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_Physical\n#define RE_IndirectSpecular\t\tRE_IndirectSpecular_Physical\n#define Material_BlinnShininessExponent( material ) GGXRoughnessToBlinnExponent( material.specularRoughness )\n#define Material_ClearCoat_BlinnShininessExponent( material ) GGXRoughnessToBlinnExponent( material.clearCoatRoughness )\nfloat computeSpecularOcclusion( const in float dotNV, const in float ambientOcclusion, const in float roughness ) {\n\treturn saturate( pow( dotNV + ambientOcclusion, exp2( - 16.0 * roughness - 1.0 ) ) - 1.0 + ambientOcclusion );\n}\n";
  2936. var lights_template = "\nGeometricContext geometry;\ngeometry.position = - vViewPosition;\ngeometry.normal = normal;\ngeometry.viewDir = normalize( vViewPosition );\nIncidentLight directLight;\n#if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )\n\tPointLight pointLight;\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\t\tpointLight = pointLights[ i ];\n\t\tgetPointDirectLightIrradiance( pointLight, geometry, directLight );\n\t\t#ifdef USE_SHADOWMAP\n\t\tdirectLight.color *= all( bvec2( pointLight.shadow, directLight.visible ) ) ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ] ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\t}\n#endif\n#if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )\n\tSpotLight spotLight;\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n\t\tspotLight = spotLights[ i ];\n\t\tgetSpotDirectLightIrradiance( spotLight, geometry, directLight );\n\t\t#ifdef USE_SHADOWMAP\n\t\tdirectLight.color *= all( bvec2( spotLight.shadow, directLight.visible ) ) ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowBias, spotLight.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\t}\n#endif\n#if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )\n\tDirectionalLight directionalLight;\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\t\tdirectionalLight = directionalLights[ i ];\n\t\tgetDirectionalDirectLightIrradiance( directionalLight, geometry, directLight );\n\t\t#ifdef USE_SHADOWMAP\n\t\tdirectLight.color *= all( bvec2( directionalLight.shadow, directLight.visible ) ) ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\t}\n#endif\n#if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea )\n\tRectAreaLight rectAreaLight;\n\tfor ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) {\n\t\trectAreaLight = rectAreaLights[ i ];\n\t\tRE_Direct_RectArea( rectAreaLight, geometry, material, reflectedLight );\n\t}\n#endif\n#if defined( RE_IndirectDiffuse )\n\tvec3 irradiance = getAmbientLightIrradiance( ambientLightColor );\n\t#ifdef USE_LIGHTMAP\n\t\tvec3 lightMapIrradiance = texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\n\t\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\t\tlightMapIrradiance *= PI;\n\t\t#endif\n\t\tirradiance += lightMapIrradiance;\n\t#endif\n\t#if ( NUM_HEMI_LIGHTS > 0 )\n\t\tfor ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n\t\t\tirradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry );\n\t\t}\n\t#endif\n\t#if defined( USE_ENVMAP ) && defined( PHYSICAL ) && defined( ENVMAP_TYPE_CUBE_UV )\n\t\tirradiance += getLightProbeIndirectIrradiance( geometry, 8 );\n\t#endif\n\tRE_IndirectDiffuse( irradiance, geometry, material, reflectedLight );\n#endif\n#if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )\n\tvec3 radiance = getLightProbeIndirectRadiance( geometry, Material_BlinnShininessExponent( material ), 8 );\n\t#ifndef STANDARD\n\t\tvec3 clearCoatRadiance = getLightProbeIndirectRadiance( geometry, Material_ClearCoat_BlinnShininessExponent( material ), 8 );\n\t#else\n\t\tvec3 clearCoatRadiance = vec3( 0.0 );\n\t#endif\n\tRE_IndirectSpecular( radiance, clearCoatRadiance, geometry, material, reflectedLight );\n#endif\n";
  2937. var logdepthbuf_fragment = "#if defined(USE_LOGDEPTHBUF) && defined(USE_LOGDEPTHBUF_EXT)\n\tgl_FragDepthEXT = log2(vFragDepth) * logDepthBufFC * 0.5;\n#endif";
  2938. var logdepthbuf_pars_fragment = "#ifdef USE_LOGDEPTHBUF\n\tuniform float logDepthBufFC;\n\t#ifdef USE_LOGDEPTHBUF_EXT\n\t\tvarying float vFragDepth;\n\t#endif\n#endif\n";
  2939. var logdepthbuf_pars_vertex = "#ifdef USE_LOGDEPTHBUF\n\t#ifdef USE_LOGDEPTHBUF_EXT\n\t\tvarying float vFragDepth;\n\t#endif\n\tuniform float logDepthBufFC;\n#endif";
  2940. var logdepthbuf_vertex = "#ifdef USE_LOGDEPTHBUF\n\tgl_Position.z = log2(max( EPSILON, gl_Position.w + 1.0 )) * logDepthBufFC;\n\t#ifdef USE_LOGDEPTHBUF_EXT\n\t\tvFragDepth = 1.0 + gl_Position.w;\n\t#else\n\t\tgl_Position.z = (gl_Position.z - 1.0) * gl_Position.w;\n\t#endif\n#endif\n";
  2941. var map_fragment = "#ifdef USE_MAP\n\tvec4 texelColor = texture2D( map, vUv );\n\ttexelColor = mapTexelToLinear( texelColor );\n\tdiffuseColor *= texelColor;\n#endif\n";
  2942. var map_pars_fragment = "#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif\n";
  2943. var map_particle_fragment = "#ifdef USE_MAP\n\tvec4 mapTexel = texture2D( map, vec2( gl_PointCoord.x, 1.0 - gl_PointCoord.y ) * offsetRepeat.zw + offsetRepeat.xy );\n\tdiffuseColor *= mapTexelToLinear( mapTexel );\n#endif\n";
  2944. var map_particle_pars_fragment = "#ifdef USE_MAP\n\tuniform vec4 offsetRepeat;\n\tuniform sampler2D map;\n#endif\n";
  2945. var metalnessmap_fragment = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n\tvec4 texelMetalness = texture2D( metalnessMap, vUv );\n\tmetalnessFactor *= texelMetalness.b;\n#endif\n";
  2946. var metalnessmap_pars_fragment = "#ifdef USE_METALNESSMAP\n\tuniform sampler2D metalnessMap;\n#endif";
  2947. var morphnormal_vertex = "#ifdef USE_MORPHNORMALS\n\tobjectNormal += ( morphNormal0 - normal ) * morphTargetInfluences[ 0 ];\n\tobjectNormal += ( morphNormal1 - normal ) * morphTargetInfluences[ 1 ];\n\tobjectNormal += ( morphNormal2 - normal ) * morphTargetInfluences[ 2 ];\n\tobjectNormal += ( morphNormal3 - normal ) * morphTargetInfluences[ 3 ];\n#endif\n";
  2948. var morphtarget_pars_vertex = "#ifdef USE_MORPHTARGETS\n\t#ifndef USE_MORPHNORMALS\n\tuniform float morphTargetInfluences[ 8 ];\n\t#else\n\tuniform float morphTargetInfluences[ 4 ];\n\t#endif\n#endif";
  2949. var morphtarget_vertex = "#ifdef USE_MORPHTARGETS\n\ttransformed += ( morphTarget0 - position ) * morphTargetInfluences[ 0 ];\n\ttransformed += ( morphTarget1 - position ) * morphTargetInfluences[ 1 ];\n\ttransformed += ( morphTarget2 - position ) * morphTargetInfluences[ 2 ];\n\ttransformed += ( morphTarget3 - position ) * morphTargetInfluences[ 3 ];\n\t#ifndef USE_MORPHNORMALS\n\ttransformed += ( morphTarget4 - position ) * morphTargetInfluences[ 4 ];\n\ttransformed += ( morphTarget5 - position ) * morphTargetInfluences[ 5 ];\n\ttransformed += ( morphTarget6 - position ) * morphTargetInfluences[ 6 ];\n\ttransformed += ( morphTarget7 - position ) * morphTargetInfluences[ 7 ];\n\t#endif\n#endif\n";
  2950. var normal_flip = "#ifdef DOUBLE_SIDED\n\tfloat flipNormal = ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n#else\n\tfloat flipNormal = 1.0;\n#endif\n";
  2951. var normal_fragment = "#ifdef FLAT_SHADED\n\tvec3 fdx = vec3( dFdx( vViewPosition.x ), dFdx( vViewPosition.y ), dFdx( vViewPosition.z ) );\n\tvec3 fdy = vec3( dFdy( vViewPosition.x ), dFdy( vViewPosition.y ), dFdy( vViewPosition.z ) );\n\tvec3 normal = normalize( cross( fdx, fdy ) );\n#else\n\tvec3 normal = normalize( vNormal ) * flipNormal;\n#endif\n#ifdef USE_NORMALMAP\n\tnormal = perturbNormal2Arb( -vViewPosition, normal );\n#elif defined( USE_BUMPMAP )\n\tnormal = perturbNormalArb( -vViewPosition, normal, dHdxy_fwd() );\n#endif\n";
  2952. var normalmap_pars_fragment = "#ifdef USE_NORMALMAP\n\tuniform sampler2D normalMap;\n\tuniform vec2 normalScale;\n\tvec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm ) {\n\t\tvec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );\n\t\tvec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );\n\t\tvec2 st0 = dFdx( vUv.st );\n\t\tvec2 st1 = dFdy( vUv.st );\n\t\tvec3 S = normalize( q0 * st1.t - q1 * st0.t );\n\t\tvec3 T = normalize( -q0 * st1.s + q1 * st0.s );\n\t\tvec3 N = normalize( surf_norm );\n\t\tvec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;\n\t\tmapN.xy = normalScale * mapN.xy;\n\t\tmat3 tsn = mat3( S, T, N );\n\t\treturn normalize( tsn * mapN );\n\t}\n#endif\n";
  2953. var packing = "vec3 packNormalToRGB( const in vec3 normal ) {\n\treturn normalize( normal ) * 0.5 + 0.5;\n}\nvec3 unpackRGBToNormal( const in vec3 rgb ) {\n\treturn 1.0 - 2.0 * rgb.xyz;\n}\nconst float PackUpscale = 256. / 255.;const float UnpackDownscale = 255. / 256.;\nconst vec3 PackFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );\nconst vec4 UnpackFactors = UnpackDownscale / vec4( PackFactors, 1. );\nconst float ShiftRight8 = 1. / 256.;\nvec4 packDepthToRGBA( const in float v ) {\n\tvec4 r = vec4( fract( v * PackFactors ), v );\n\tr.yzw -= r.xyz * ShiftRight8;\treturn r * PackUpscale;\n}\nfloat unpackRGBAToDepth( const in vec4 v ) {\n\treturn dot( v, UnpackFactors );\n}\nfloat viewZToOrthographicDepth( const in float viewZ, const in float near, const in float far ) {\n\treturn ( viewZ + near ) / ( near - far );\n}\nfloat orthographicDepthToViewZ( const in float linearClipZ, const in float near, const in float far ) {\n\treturn linearClipZ * ( near - far ) - near;\n}\nfloat viewZToPerspectiveDepth( const in float viewZ, const in float near, const in float far ) {\n\treturn (( near + viewZ ) * far ) / (( far - near ) * viewZ );\n}\nfloat perspectiveDepthToViewZ( const in float invClipZ, const in float near, const in float far ) {\n\treturn ( near * far ) / ( ( far - near ) * invClipZ - far );\n}\n";
  2954. var premultiplied_alpha_fragment = "#ifdef PREMULTIPLIED_ALPHA\n\tgl_FragColor.rgb *= gl_FragColor.a;\n#endif\n";
  2955. var project_vertex = "vec4 mvPosition = modelViewMatrix * vec4( transformed, 1.0 );\ngl_Position = projectionMatrix * mvPosition;\n";
  2956. var dithering_fragment = "#if defined( DITHERING )\n gl_FragColor.rgb = dithering( gl_FragColor.rgb );\n#endif\n";
  2957. var dithering_pars_fragment = "#if defined( DITHERING )\n\tvec3 dithering( vec3 color ) {\n\t\tfloat grid_position = rand( gl_FragCoord.xy );\n\t\tvec3 dither_shift_RGB = vec3( 0.25 / 255.0, -0.25 / 255.0, 0.25 / 255.0 );\n\t\tdither_shift_RGB = mix( 2.0 * dither_shift_RGB, -2.0 * dither_shift_RGB, grid_position );\n\t\treturn color + dither_shift_RGB;\n\t}\n#endif\n";
  2958. var roughnessmap_fragment = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n\tvec4 texelRoughness = texture2D( roughnessMap, vUv );\n\troughnessFactor *= texelRoughness.g;\n#endif\n";
  2959. var roughnessmap_pars_fragment = "#ifdef USE_ROUGHNESSMAP\n\tuniform sampler2D roughnessMap;\n#endif";
  2960. var shadowmap_pars_fragment = "#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHTS > 0\n\t\tuniform sampler2D directionalShadowMap[ NUM_DIR_LIGHTS ];\n\t\tvarying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHTS ];\n\t#endif\n\t#if NUM_SPOT_LIGHTS > 0\n\t\tuniform sampler2D spotShadowMap[ NUM_SPOT_LIGHTS ];\n\t\tvarying vec4 vSpotShadowCoord[ NUM_SPOT_LIGHTS ];\n\t#endif\n\t#if NUM_POINT_LIGHTS > 0\n\t\tuniform sampler2D pointShadowMap[ NUM_POINT_LIGHTS ];\n\t\tvarying vec4 vPointShadowCoord[ NUM_POINT_LIGHTS ];\n\t#endif\n\tfloat texture2DCompare( sampler2D depths, vec2 uv, float compare ) {\n\t\treturn step( compare, unpackRGBAToDepth( texture2D( depths, uv ) ) );\n\t}\n\tfloat texture2DShadowLerp( sampler2D depths, vec2 size, vec2 uv, float compare ) {\n\t\tconst vec2 offset = vec2( 0.0, 1.0 );\n\t\tvec2 texelSize = vec2( 1.0 ) / size;\n\t\tvec2 centroidUV = floor( uv * size + 0.5 ) / size;\n\t\tfloat lb = texture2DCompare( depths, centroidUV + texelSize * offset.xx, compare );\n\t\tfloat lt = texture2DCompare( depths, centroidUV + texelSize * offset.xy, compare );\n\t\tfloat rb = texture2DCompare( depths, centroidUV + texelSize * offset.yx, compare );\n\t\tfloat rt = texture2DCompare( depths, centroidUV + texelSize * offset.yy, compare );\n\t\tvec2 f = fract( uv * size + 0.5 );\n\t\tfloat a = mix( lb, lt, f.y );\n\t\tfloat b = mix( rb, rt, f.y );\n\t\tfloat c = mix( a, b, f.x );\n\t\treturn c;\n\t}\n\tfloat getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord ) {\n\t\tfloat shadow = 1.0;\n\t\tshadowCoord.xyz /= shadowCoord.w;\n\t\tshadowCoord.z += shadowBias;\n\t\tbvec4 inFrustumVec = bvec4 ( shadowCoord.x >= 0.0, shadowCoord.x <= 1.0, shadowCoord.y >= 0.0, shadowCoord.y <= 1.0 );\n\t\tbool inFrustum = all( inFrustumVec );\n\t\tbvec2 frustumTestVec = bvec2( inFrustum, shadowCoord.z <= 1.0 );\n\t\tbool frustumTest = all( frustumTestVec );\n\t\tif ( frustumTest ) {\n\t\t#if defined( SHADOWMAP_TYPE_PCF )\n\t\t\tvec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n\t\t\tfloat dx0 = - texelSize.x * shadowRadius;\n\t\t\tfloat dy0 = - texelSize.y * shadowRadius;\n\t\t\tfloat dx1 = + texelSize.x * shadowRadius;\n\t\t\tfloat dy1 = + texelSize.y * shadowRadius;\n\t\t\tshadow = (\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z )\n\t\t\t) * ( 1.0 / 9.0 );\n\t\t#elif defined( SHADOWMAP_TYPE_PCF_SOFT )\n\t\t\tvec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n\t\t\tfloat dx0 = - texelSize.x * shadowRadius;\n\t\t\tfloat dy0 = - texelSize.y * shadowRadius;\n\t\t\tfloat dx1 = + texelSize.x * shadowRadius;\n\t\t\tfloat dy1 = + texelSize.y * shadowRadius;\n\t\t\tshadow = (\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy, shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z )\n\t\t\t) * ( 1.0 / 9.0 );\n\t\t#else\n\t\t\tshadow = texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z );\n\t\t#endif\n\t\t}\n\t\treturn shadow;\n\t}\n\tvec2 cubeToUV( vec3 v, float texelSizeY ) {\n\t\tvec3 absV = abs( v );\n\t\tfloat scaleToCube = 1.0 / max( absV.x, max( absV.y, absV.z ) );\n\t\tabsV *= scaleToCube;\n\t\tv *= scaleToCube * ( 1.0 - 2.0 * texelSizeY );\n\t\tvec2 planar = v.xy;\n\t\tfloat almostATexel = 1.5 * texelSizeY;\n\t\tfloat almostOne = 1.0 - almostATexel;\n\t\tif ( absV.z >= almostOne ) {\n\t\t\tif ( v.z > 0.0 )\n\t\t\t\tplanar.x = 4.0 - v.x;\n\t\t} else if ( absV.x >= almostOne ) {\n\t\t\tfloat signX = sign( v.x );\n\t\t\tplanar.x = v.z * signX + 2.0 * signX;\n\t\t} else if ( absV.y >= almostOne ) {\n\t\t\tfloat signY = sign( v.y );\n\t\t\tplanar.x = v.x + 2.0 * signY + 2.0;\n\t\t\tplanar.y = v.z * signY - 2.0;\n\t\t}\n\t\treturn vec2( 0.125, 0.25 ) * planar + vec2( 0.375, 0.75 );\n\t}\n\tfloat getPointShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord ) {\n\t\tvec2 texelSize = vec2( 1.0 ) / ( shadowMapSize * vec2( 4.0, 2.0 ) );\n\t\tvec3 lightToPosition = shadowCoord.xyz;\n\t\tvec3 bd3D = normalize( lightToPosition );\n\t\tfloat dp = ( length( lightToPosition ) - shadowBias ) / 1000.0;\n\t\t#if defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_PCF_SOFT )\n\t\t\tvec2 offset = vec2( - 1, 1 ) * shadowRadius * texelSize.y;\n\t\t\treturn (\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyx, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyx, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxx, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxx, texelSize.y ), dp )\n\t\t\t) * ( 1.0 / 9.0 );\n\t\t#else\n\t\t\treturn texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp );\n\t\t#endif\n\t}\n#endif\n";
  2961. var shadowmap_pars_vertex = "#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHTS > 0\n\t\tuniform mat4 directionalShadowMatrix[ NUM_DIR_LIGHTS ];\n\t\tvarying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHTS ];\n\t#endif\n\t#if NUM_SPOT_LIGHTS > 0\n\t\tuniform mat4 spotShadowMatrix[ NUM_SPOT_LIGHTS ];\n\t\tvarying vec4 vSpotShadowCoord[ NUM_SPOT_LIGHTS ];\n\t#endif\n\t#if NUM_POINT_LIGHTS > 0\n\t\tuniform mat4 pointShadowMatrix[ NUM_POINT_LIGHTS ];\n\t\tvarying vec4 vPointShadowCoord[ NUM_POINT_LIGHTS ];\n\t#endif\n#endif\n";
  2962. var shadowmap_vertex = "#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHTS > 0\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\t\tvDirectionalShadowCoord[ i ] = directionalShadowMatrix[ i ] * worldPosition;\n\t}\n\t#endif\n\t#if NUM_SPOT_LIGHTS > 0\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n\t\tvSpotShadowCoord[ i ] = spotShadowMatrix[ i ] * worldPosition;\n\t}\n\t#endif\n\t#if NUM_POINT_LIGHTS > 0\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\t\tvPointShadowCoord[ i ] = pointShadowMatrix[ i ] * worldPosition;\n\t}\n\t#endif\n#endif\n";
  2963. var shadowmask_pars_fragment = "float getShadowMask() {\n\tfloat shadow = 1.0;\n\t#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHTS > 0\n\tDirectionalLight directionalLight;\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\t\tdirectionalLight = directionalLights[ i ];\n\t\tshadow *= bool( directionalLight.shadow ) ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\t}\n\t#endif\n\t#if NUM_SPOT_LIGHTS > 0\n\tSpotLight spotLight;\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n\t\tspotLight = spotLights[ i ];\n\t\tshadow *= bool( spotLight.shadow ) ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowBias, spotLight.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;\n\t}\n\t#endif\n\t#if NUM_POINT_LIGHTS > 0\n\tPointLight pointLight;\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\t\tpointLight = pointLights[ i ];\n\t\tshadow *= bool( pointLight.shadow ) ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ] ) : 1.0;\n\t}\n\t#endif\n\t#endif\n\treturn shadow;\n}\n";
  2964. var skinbase_vertex = "#ifdef USE_SKINNING\n\tmat4 boneMatX = getBoneMatrix( skinIndex.x );\n\tmat4 boneMatY = getBoneMatrix( skinIndex.y );\n\tmat4 boneMatZ = getBoneMatrix( skinIndex.z );\n\tmat4 boneMatW = getBoneMatrix( skinIndex.w );\n#endif";
  2965. var skinning_pars_vertex = "#ifdef USE_SKINNING\n\tuniform mat4 bindMatrix;\n\tuniform mat4 bindMatrixInverse;\n\t#ifdef BONE_TEXTURE\n\t\tuniform sampler2D boneTexture;\n\t\tuniform int boneTextureSize;\n\t\tmat4 getBoneMatrix( const in float i ) {\n\t\t\tfloat j = i * 4.0;\n\t\t\tfloat x = mod( j, float( boneTextureSize ) );\n\t\t\tfloat y = floor( j / float( boneTextureSize ) );\n\t\t\tfloat dx = 1.0 / float( boneTextureSize );\n\t\t\tfloat dy = 1.0 / float( boneTextureSize );\n\t\t\ty = dy * ( y + 0.5 );\n\t\t\tvec4 v1 = texture2D( boneTexture, vec2( dx * ( x + 0.5 ), y ) );\n\t\t\tvec4 v2 = texture2D( boneTexture, vec2( dx * ( x + 1.5 ), y ) );\n\t\t\tvec4 v3 = texture2D( boneTexture, vec2( dx * ( x + 2.5 ), y ) );\n\t\t\tvec4 v4 = texture2D( boneTexture, vec2( dx * ( x + 3.5 ), y ) );\n\t\t\tmat4 bone = mat4( v1, v2, v3, v4 );\n\t\t\treturn bone;\n\t\t}\n\t#else\n\t\tuniform mat4 boneMatrices[ MAX_BONES ];\n\t\tmat4 getBoneMatrix( const in float i ) {\n\t\t\tmat4 bone = boneMatrices[ int(i) ];\n\t\t\treturn bone;\n\t\t}\n\t#endif\n#endif\n";
  2966. var skinning_vertex = "#ifdef USE_SKINNING\n\tvec4 skinVertex = bindMatrix * vec4( transformed, 1.0 );\n\tvec4 skinned = vec4( 0.0 );\n\tskinned += boneMatX * skinVertex * skinWeight.x;\n\tskinned += boneMatY * skinVertex * skinWeight.y;\n\tskinned += boneMatZ * skinVertex * skinWeight.z;\n\tskinned += boneMatW * skinVertex * skinWeight.w;\n\ttransformed = ( bindMatrixInverse * skinned ).xyz;\n#endif\n";
  2967. var skinnormal_vertex = "#ifdef USE_SKINNING\n\tmat4 skinMatrix = mat4( 0.0 );\n\tskinMatrix += skinWeight.x * boneMatX;\n\tskinMatrix += skinWeight.y * boneMatY;\n\tskinMatrix += skinWeight.z * boneMatZ;\n\tskinMatrix += skinWeight.w * boneMatW;\n\tskinMatrix = bindMatrixInverse * skinMatrix * bindMatrix;\n\tobjectNormal = vec4( skinMatrix * vec4( objectNormal, 0.0 ) ).xyz;\n#endif\n";
  2968. var specularmap_fragment = "float specularStrength;\n#ifdef USE_SPECULARMAP\n\tvec4 texelSpecular = texture2D( specularMap, vUv );\n\tspecularStrength = texelSpecular.r;\n#else\n\tspecularStrength = 1.0;\n#endif";
  2969. var specularmap_pars_fragment = "#ifdef USE_SPECULARMAP\n\tuniform sampler2D specularMap;\n#endif";
  2970. var tonemapping_fragment = "#if defined( TONE_MAPPING )\n gl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif\n";
  2971. var tonemapping_pars_fragment = "#define saturate(a) clamp( a, 0.0, 1.0 )\nuniform float toneMappingExposure;\nuniform float toneMappingWhitePoint;\nvec3 LinearToneMapping( vec3 color ) {\n\treturn toneMappingExposure * color;\n}\nvec3 ReinhardToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\treturn saturate( color / ( vec3( 1.0 ) + color ) );\n}\n#define Uncharted2Helper( x ) max( ( ( x * ( 0.15 * x + 0.10 * 0.50 ) + 0.20 * 0.02 ) / ( x * ( 0.15 * x + 0.50 ) + 0.20 * 0.30 ) ) - 0.02 / 0.30, vec3( 0.0 ) )\nvec3 Uncharted2ToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\treturn saturate( Uncharted2Helper( color ) / Uncharted2Helper( vec3( toneMappingWhitePoint ) ) );\n}\nvec3 OptimizedCineonToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\tcolor = max( vec3( 0.0 ), color - 0.004 );\n\treturn pow( ( color * ( 6.2 * color + 0.5 ) ) / ( color * ( 6.2 * color + 1.7 ) + 0.06 ), vec3( 2.2 ) );\n}\n";
  2972. var uv_pars_fragment = "#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP ) || defined( USE_EMISSIVEMAP ) || defined( USE_ROUGHNESSMAP ) || defined( USE_METALNESSMAP )\n\tvarying vec2 vUv;\n#endif";
  2973. var uv_pars_vertex = "#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP ) || defined( USE_EMISSIVEMAP ) || defined( USE_ROUGHNESSMAP ) || defined( USE_METALNESSMAP )\n\tvarying vec2 vUv;\n\tuniform vec4 offsetRepeat;\n#endif\n";
  2974. var uv_vertex = "#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP ) || defined( USE_EMISSIVEMAP ) || defined( USE_ROUGHNESSMAP ) || defined( USE_METALNESSMAP )\n\tvUv = uv * offsetRepeat.zw + offsetRepeat.xy;\n#endif";
  2975. var uv2_pars_fragment = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvarying vec2 vUv2;\n#endif";
  2976. var uv2_pars_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tattribute vec2 uv2;\n\tvarying vec2 vUv2;\n#endif";
  2977. var uv2_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvUv2 = uv2;\n#endif";
  2978. var worldpos_vertex = "#if defined( USE_ENVMAP ) || defined( PHONG ) || defined( PHYSICAL ) || defined( LAMBERT ) || defined ( USE_SHADOWMAP )\n\tvec4 worldPosition = modelMatrix * vec4( transformed, 1.0 );\n#endif\n";
  2979. var cube_frag = "uniform samplerCube tCube;\nuniform float tFlip;\nuniform float opacity;\nvarying vec3 vWorldPosition;\n#include <common>\nvoid main() {\n\tgl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );\n\tgl_FragColor.a *= opacity;\n}\n";
  2980. var cube_vert = "varying vec3 vWorldPosition;\n#include <common>\nvoid main() {\n\tvWorldPosition = transformDirection( position, modelMatrix );\n\t#include <begin_vertex>\n\t#include <project_vertex>\n}\n";
  2981. var depth_frag = "#if DEPTH_PACKING == 3200\n\tuniform float opacity;\n#endif\n#include <common>\n#include <packing>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( 1.0 );\n\t#if DEPTH_PACKING == 3200\n\t\tdiffuseColor.a = opacity;\n\t#endif\n\t#include <map_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <logdepthbuf_fragment>\n\t#if DEPTH_PACKING == 3200\n\t\tgl_FragColor = vec4( vec3( gl_FragCoord.z ), opacity );\n\t#elif DEPTH_PACKING == 3201\n\t\tgl_FragColor = packDepthToRGBA( gl_FragCoord.z );\n\t#endif\n}\n";
  2982. var depth_vert = "#include <common>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <skinbase_vertex>\n\t#ifdef USE_DISPLACEMENTMAP\n\t\t#include <beginnormal_vertex>\n\t\t#include <morphnormal_vertex>\n\t\t#include <skinnormal_vertex>\n\t#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n}\n";
  2983. var distanceRGBA_frag = "uniform vec3 lightPos;\nvarying vec4 vWorldPosition;\n#include <common>\n#include <packing>\n#include <clipping_planes_pars_fragment>\nvoid main () {\n\t#include <clipping_planes_fragment>\n\tgl_FragColor = packDepthToRGBA( length( vWorldPosition.xyz - lightPos.xyz ) / 1000.0 );\n}\n";
  2984. var distanceRGBA_vert = "varying vec4 vWorldPosition;\n#include <common>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <skinbase_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <project_vertex>\n\t#include <worldpos_vertex>\n\t#include <clipping_planes_vertex>\n\tvWorldPosition = worldPosition;\n}\n";
  2985. var equirect_frag = "uniform sampler2D tEquirect;\nuniform float tFlip;\nvarying vec3 vWorldPosition;\n#include <common>\nvoid main() {\n\tvec3 direction = normalize( vWorldPosition );\n\tvec2 sampleUV;\n\tsampleUV.y = saturate( tFlip * direction.y * -0.5 + 0.5 );\n\tsampleUV.x = atan( direction.z, direction.x ) * RECIPROCAL_PI2 + 0.5;\n\tgl_FragColor = texture2D( tEquirect, sampleUV );\n}\n";
  2986. var equirect_vert = "varying vec3 vWorldPosition;\n#include <common>\nvoid main() {\n\tvWorldPosition = transformDirection( position, modelMatrix );\n\t#include <begin_vertex>\n\t#include <project_vertex>\n}\n";
  2987. var linedashed_frag = "uniform vec3 diffuse;\nuniform float opacity;\nuniform float dashSize;\nuniform float totalSize;\nvarying float vLineDistance;\n#include <common>\n#include <color_pars_fragment>\n#include <fog_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tif ( mod( vLineDistance, totalSize ) > dashSize ) {\n\t\tdiscard;\n\t}\n\tvec3 outgoingLight = vec3( 0.0 );\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <logdepthbuf_fragment>\n\t#include <color_fragment>\n\toutgoingLight = diffuseColor.rgb;\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <premultiplied_alpha_fragment>\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n}\n";
  2988. var linedashed_vert = "uniform float scale;\nattribute float lineDistance;\nvarying float vLineDistance;\n#include <common>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <color_vertex>\n\tvLineDistance = scale * lineDistance;\n\tvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\n\tgl_Position = projectionMatrix * mvPosition;\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <fog_vertex>\n}\n";
  2989. var meshbasic_frag = "uniform vec3 diffuse;\nuniform float opacity;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include <common>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <envmap_pars_fragment>\n#include <fog_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <specularmap_fragment>\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\t#ifdef USE_LIGHTMAP\n\t\treflectedLight.indirectDiffuse += texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\n\t#else\n\t\treflectedLight.indirectDiffuse += vec3( 1.0 );\n\t#endif\n\t#include <aomap_fragment>\n\treflectedLight.indirectDiffuse *= diffuseColor.rgb;\n\tvec3 outgoingLight = reflectedLight.indirectDiffuse;\n\t#include <normal_flip>\n\t#include <envmap_fragment>\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <premultiplied_alpha_fragment>\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n}\n";
  2990. var meshbasic_vert = "#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <envmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <uv2_vertex>\n\t#include <color_vertex>\n\t#include <skinbase_vertex>\n\t#ifdef USE_ENVMAP\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <worldpos_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <envmap_vertex>\n\t#include <fog_vertex>\n}\n";
  2991. var meshlambert_frag = "uniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float opacity;\nvarying vec3 vLightFront;\n#ifdef DOUBLE_SIDED\n\tvarying vec3 vLightBack;\n#endif\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <envmap_pars_fragment>\n#include <bsdfs>\n#include <lights_pars>\n#include <fog_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <shadowmask_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <specularmap_fragment>\n\t#include <emissivemap_fragment>\n\treflectedLight.indirectDiffuse = getAmbientLightIrradiance( ambientLightColor );\n\t#include <lightmap_fragment>\n\treflectedLight.indirectDiffuse *= BRDF_Diffuse_Lambert( diffuseColor.rgb );\n\t#ifdef DOUBLE_SIDED\n\t\treflectedLight.directDiffuse = ( gl_FrontFacing ) ? vLightFront : vLightBack;\n\t#else\n\t\treflectedLight.directDiffuse = vLightFront;\n\t#endif\n\treflectedLight.directDiffuse *= BRDF_Diffuse_Lambert( diffuseColor.rgb ) * getShadowMask();\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;\n\t#include <normal_flip>\n\t#include <envmap_fragment>\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}\n";
  2992. var meshlambert_vert = "#define LAMBERT\nvarying vec3 vLightFront;\n#ifdef DOUBLE_SIDED\n\tvarying vec3 vLightBack;\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <envmap_pars_vertex>\n#include <bsdfs>\n#include <lights_pars>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <uv2_vertex>\n\t#include <color_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <worldpos_vertex>\n\t#include <envmap_vertex>\n\t#include <lights_lambert_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}\n";
  2993. var meshphong_frag = "#define PHONG\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform vec3 specular;\nuniform float shininess;\nuniform float opacity;\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <envmap_pars_fragment>\n#include <gradientmap_pars_fragment>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars>\n#include <lights_phong_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <specularmap_fragment>\n\t#include <normal_flip>\n\t#include <normal_fragment>\n\t#include <emissivemap_fragment>\n\t#include <lights_phong_fragment>\n\t#include <lights_template>\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;\n\t#include <envmap_fragment>\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}\n";
  2994. var meshphong_vert = "#define PHONG\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <envmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <uv2_vertex>\n\t#include <color_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n#ifndef FLAT_SHADED\n\tvNormal = normalize( transformedNormal );\n#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <envmap_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}\n";
  2995. var meshphysical_frag = "#define PHYSICAL\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float roughness;\nuniform float metalness;\nuniform float opacity;\n#ifndef STANDARD\n\tuniform float clearCoat;\n\tuniform float clearCoatRoughness;\n#endif\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <envmap_pars_fragment>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <cube_uv_reflection_fragment>\n#include <lights_pars>\n#include <lights_physical_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <roughnessmap_pars_fragment>\n#include <metalnessmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <roughnessmap_fragment>\n\t#include <metalnessmap_fragment>\n\t#include <normal_flip>\n\t#include <normal_fragment>\n\t#include <emissivemap_fragment>\n\t#include <lights_physical_fragment>\n\t#include <lights_template>\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}\n";
  2996. var meshphysical_vert = "#define PHYSICAL\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <uv2_vertex>\n\t#include <color_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n#ifndef FLAT_SHADED\n\tvNormal = normalize( transformedNormal );\n#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}\n";
  2997. var normal_frag = "#define NORMAL\nuniform float opacity;\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP )\n\tvarying vec3 vViewPosition;\n#endif\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include <packing>\n#include <uv_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\nvoid main() {\n\t#include <logdepthbuf_fragment>\n\t#include <normal_flip>\n\t#include <normal_fragment>\n\tgl_FragColor = vec4( packNormalToRGB( normal ), opacity );\n}\n";
  2998. var normal_vert = "#define NORMAL\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP )\n\tvarying vec3 vViewPosition;\n#endif\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n#ifndef FLAT_SHADED\n\tvNormal = normalize( transformedNormal );\n#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP )\n\tvViewPosition = - mvPosition.xyz;\n#endif\n}\n";
  2999. var points_frag = "uniform vec3 diffuse;\nuniform float opacity;\n#include <common>\n#include <packing>\n#include <color_pars_fragment>\n#include <map_particle_pars_fragment>\n#include <fog_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec3 outgoingLight = vec3( 0.0 );\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <logdepthbuf_fragment>\n\t#include <map_particle_fragment>\n\t#include <color_fragment>\n\t#include <alphatest_fragment>\n\toutgoingLight = diffuseColor.rgb;\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <premultiplied_alpha_fragment>\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n}\n";
  3000. var points_vert = "uniform float size;\nuniform float scale;\n#include <common>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <color_vertex>\n\t#include <begin_vertex>\n\t#include <project_vertex>\n\t#ifdef USE_SIZEATTENUATION\n\t\tgl_PointSize = size * ( scale / - mvPosition.z );\n\t#else\n\t\tgl_PointSize = size;\n\t#endif\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <worldpos_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}\n";
  3001. var shadow_frag = "uniform float opacity;\n#include <common>\n#include <packing>\n#include <bsdfs>\n#include <lights_pars>\n#include <shadowmap_pars_fragment>\n#include <shadowmask_pars_fragment>\nvoid main() {\n\tgl_FragColor = vec4( 0.0, 0.0, 0.0, opacity * ( 1.0 - getShadowMask() ) );\n}\n";
  3002. var shadow_vert = "#include <shadowmap_pars_vertex>\nvoid main() {\n\t#include <begin_vertex>\n\t#include <project_vertex>\n\t#include <worldpos_vertex>\n\t#include <shadowmap_vertex>\n}\n";
  3003. var ShaderChunk = {
  3004. alphamap_fragment: alphamap_fragment,
  3005. alphamap_pars_fragment: alphamap_pars_fragment,
  3006. alphatest_fragment: alphatest_fragment,
  3007. aomap_fragment: aomap_fragment,
  3008. aomap_pars_fragment: aomap_pars_fragment,
  3009. begin_vertex: begin_vertex,
  3010. beginnormal_vertex: beginnormal_vertex,
  3011. bsdfs: bsdfs,
  3012. bumpmap_pars_fragment: bumpmap_pars_fragment,
  3013. clipping_planes_fragment: clipping_planes_fragment,
  3014. clipping_planes_pars_fragment: clipping_planes_pars_fragment,
  3015. clipping_planes_pars_vertex: clipping_planes_pars_vertex,
  3016. clipping_planes_vertex: clipping_planes_vertex,
  3017. color_fragment: color_fragment,
  3018. color_pars_fragment: color_pars_fragment,
  3019. color_pars_vertex: color_pars_vertex,
  3020. color_vertex: color_vertex,
  3021. common: common,
  3022. cube_uv_reflection_fragment: cube_uv_reflection_fragment,
  3023. defaultnormal_vertex: defaultnormal_vertex,
  3024. displacementmap_pars_vertex: displacementmap_pars_vertex,
  3025. displacementmap_vertex: displacementmap_vertex,
  3026. emissivemap_fragment: emissivemap_fragment,
  3027. emissivemap_pars_fragment: emissivemap_pars_fragment,
  3028. encodings_fragment: encodings_fragment,
  3029. encodings_pars_fragment: encodings_pars_fragment,
  3030. envmap_fragment: envmap_fragment,
  3031. envmap_pars_fragment: envmap_pars_fragment,
  3032. envmap_pars_vertex: envmap_pars_vertex,
  3033. envmap_vertex: envmap_vertex,
  3034. fog_vertex: fog_vertex,
  3035. fog_pars_vertex: fog_pars_vertex,
  3036. fog_fragment: fog_fragment,
  3037. fog_pars_fragment: fog_pars_fragment,
  3038. gradientmap_pars_fragment: gradientmap_pars_fragment,
  3039. lightmap_fragment: lightmap_fragment,
  3040. lightmap_pars_fragment: lightmap_pars_fragment,
  3041. lights_lambert_vertex: lights_lambert_vertex,
  3042. lights_pars: lights_pars,
  3043. lights_phong_fragment: lights_phong_fragment,
  3044. lights_phong_pars_fragment: lights_phong_pars_fragment,
  3045. lights_physical_fragment: lights_physical_fragment,
  3046. lights_physical_pars_fragment: lights_physical_pars_fragment,
  3047. lights_template: lights_template,
  3048. logdepthbuf_fragment: logdepthbuf_fragment,
  3049. logdepthbuf_pars_fragment: logdepthbuf_pars_fragment,
  3050. logdepthbuf_pars_vertex: logdepthbuf_pars_vertex,
  3051. logdepthbuf_vertex: logdepthbuf_vertex,
  3052. map_fragment: map_fragment,
  3053. map_pars_fragment: map_pars_fragment,
  3054. map_particle_fragment: map_particle_fragment,
  3055. map_particle_pars_fragment: map_particle_pars_fragment,
  3056. metalnessmap_fragment: metalnessmap_fragment,
  3057. metalnessmap_pars_fragment: metalnessmap_pars_fragment,
  3058. morphnormal_vertex: morphnormal_vertex,
  3059. morphtarget_pars_vertex: morphtarget_pars_vertex,
  3060. morphtarget_vertex: morphtarget_vertex,
  3061. normal_flip: normal_flip,
  3062. normal_fragment: normal_fragment,
  3063. normalmap_pars_fragment: normalmap_pars_fragment,
  3064. packing: packing,
  3065. premultiplied_alpha_fragment: premultiplied_alpha_fragment,
  3066. project_vertex: project_vertex,
  3067. dithering_fragment: dithering_fragment,
  3068. dithering_pars_fragment: dithering_pars_fragment,
  3069. roughnessmap_fragment: roughnessmap_fragment,
  3070. roughnessmap_pars_fragment: roughnessmap_pars_fragment,
  3071. shadowmap_pars_fragment: shadowmap_pars_fragment,
  3072. shadowmap_pars_vertex: shadowmap_pars_vertex,
  3073. shadowmap_vertex: shadowmap_vertex,
  3074. shadowmask_pars_fragment: shadowmask_pars_fragment,
  3075. skinbase_vertex: skinbase_vertex,
  3076. skinning_pars_vertex: skinning_pars_vertex,
  3077. skinning_vertex: skinning_vertex,
  3078. skinnormal_vertex: skinnormal_vertex,
  3079. specularmap_fragment: specularmap_fragment,
  3080. specularmap_pars_fragment: specularmap_pars_fragment,
  3081. tonemapping_fragment: tonemapping_fragment,
  3082. tonemapping_pars_fragment: tonemapping_pars_fragment,
  3083. uv_pars_fragment: uv_pars_fragment,
  3084. uv_pars_vertex: uv_pars_vertex,
  3085. uv_vertex: uv_vertex,
  3086. uv2_pars_fragment: uv2_pars_fragment,
  3087. uv2_pars_vertex: uv2_pars_vertex,
  3088. uv2_vertex: uv2_vertex,
  3089. worldpos_vertex: worldpos_vertex,
  3090. cube_frag: cube_frag,
  3091. cube_vert: cube_vert,
  3092. depth_frag: depth_frag,
  3093. depth_vert: depth_vert,
  3094. distanceRGBA_frag: distanceRGBA_frag,
  3095. distanceRGBA_vert: distanceRGBA_vert,
  3096. equirect_frag: equirect_frag,
  3097. equirect_vert: equirect_vert,
  3098. linedashed_frag: linedashed_frag,
  3099. linedashed_vert: linedashed_vert,
  3100. meshbasic_frag: meshbasic_frag,
  3101. meshbasic_vert: meshbasic_vert,
  3102. meshlambert_frag: meshlambert_frag,
  3103. meshlambert_vert: meshlambert_vert,
  3104. meshphong_frag: meshphong_frag,
  3105. meshphong_vert: meshphong_vert,
  3106. meshphysical_frag: meshphysical_frag,
  3107. meshphysical_vert: meshphysical_vert,
  3108. normal_frag: normal_frag,
  3109. normal_vert: normal_vert,
  3110. points_frag: points_frag,
  3111. points_vert: points_vert,
  3112. shadow_frag: shadow_frag,
  3113. shadow_vert: shadow_vert,
  3114. none_frag: none_frag,
  3115. none_vert:none_vert,
  3116. normals_frag: normals_frag,
  3117. normals_vert: normals_vert,
  3118. texture_frag: texture_frag,
  3119. texture_vert: texture_vert,
  3120. texture_normals_frag: texture_normals_frag,
  3121. texture_normals_vert: texture_normals_vert
  3122. };
  3123. ShaderChunk.parseIncludes = function (string) {
  3124. var pattern = /#include +<([\w\d.]+)>/g;
  3125. function replace(match, include) {
  3126. var replace = ShaderChunk[include];
  3127. if (replace === undefined) {
  3128. throw new Error('Can not resolve #include <' + include + '>');
  3129. }
  3130. return ShaderChunk.parseIncludes(replace);
  3131. }
  3132. return string.replace(pattern, replace);
  3133. }
  3134. return ShaderChunk;
  3135. });
  3136. define('Core/FramebufferTexture',[], function () {
  3137. /**
  3138. *帧缓存纹理类,可以将一个mesh渲染到帧缓存并作为纹理提供给其他mesh。<br/>
  3139. *需要配合{@link Cesium.MeshVisualizer}、{@link Cesium.Mesh}、{@link Cesium.MeshMaterial}使用。
  3140. *@param {Cesium.Mesh}mesh
  3141. *
  3142. *@property {Cesium.Mesh}mesh
  3143. *@property {Cesium.Texture}texture
  3144. *
  3145. *@constructor
  3146. *@memberof Cesium
  3147. *@example
  3148. MeshVisualizer = Cesium.MeshVisualizer;
  3149. Mesh = Cesium.Mesh;
  3150. MeshMaterial = Cesium.MeshMaterial;
  3151. FramebufferTexture = Cesium.FramebufferTexture;
  3152. Shaders = VolumeRendering.Shaders;
  3153. var center2 = Cesium.Cartesian3.fromDegrees(homePosition[0]+3.5, homePosition[1] , 50000);
  3154. var modelMatrix2 = Cesium.Transforms.eastNorthUpToFixedFrame(center2);
  3155. var meshVisualizer = new MeshVisualizer({
  3156. modelMatrix: modelMatrix2,
  3157. up: { y: 1 },
  3158. scale: new Cesium.Cartesian3(2,2,2)
  3159. });
  3160. viewer.scene.primitives.add(meshVisualizer);
  3161. var guiControls = new function () {
  3162. this.model = 'bonsai';
  3163. this.steps = 256.0;
  3164. this.alphaCorrection = 1.0;
  3165. this.color1 = "#00FA58";
  3166. this.stepPos1 = 0.1;
  3167. this.color2 = "#CC6600";
  3168. this.stepPos2 = 0.7;
  3169. this.color3 = "#F2F200";
  3170. this.stepPos3 = 1.0;
  3171. };
  3172. function updateTransferFunction() {
  3173. var canvas = document.createElement('canvas');
  3174. canvas.height = 20;
  3175. canvas.width = 256;
  3176. var ctx = canvas.getContext('2d');
  3177. var grd = ctx.createLinearGradient(0, 0, canvas.width - 1, canvas.height - 1);
  3178. grd.addColorStop(guiControls.stepPos1, guiControls.color1);
  3179. grd.addColorStop(guiControls.stepPos2, guiControls.color2);
  3180. grd.addColorStop(guiControls.stepPos3, guiControls.color3);
  3181. ctx.fillStyle = grd;
  3182. ctx.fillRect(0, 0, canvas.width - 1, canvas.height - 1);
  3183. return canvas;
  3184. }
  3185. var dimensions = new Cesium.Cartesian3(50000, 50000, 50000);
  3186. var boxGeometry = Cesium.BoxGeometry.createGeometry(Cesium.BoxGeometry.fromDimensions({
  3187. dimensions: dimensions,
  3188. vertexFormat: Cesium.VertexFormat.POSITION_ONLY
  3189. }));
  3190. var materialFirstPass = new MeshMaterial({
  3191. vertexShader: Shaders.vertexShaderFirstPass,
  3192. fragmentShader: Shaders.fragmentShaderFirstPass,
  3193. side: MeshMaterial.Sides.BACK,
  3194. uniforms: {
  3195. dimensions: dimensions
  3196. }
  3197. });
  3198. var meshFirstPass = new Mesh(boxGeometry, materialFirstPass);
  3199. var rtTexture = new FramebufferTexture(meshFirstPass);//这里使用FramebufferTexture
  3200. var transferTexture = updateTransferFunction();
  3201. var materialSecondPass = new MeshMaterial({
  3202. vertexShader: Shaders.vertexShaderSecondPass,
  3203. fragmentShader: Shaders.fragmentShaderSecondPass,
  3204. side: MeshMaterial.Sides.FRONT,
  3205. uniforms: {
  3206. alpha: 1,
  3207. dimensions: dimensions,
  3208. tex: rtTexture,
  3209. cubeTex: "./teapot.raw.png",
  3210. transferTex: transferTexture,
  3211. steps: guiControls.steps,
  3212. alphaCorrection: guiControls.alphaCorrection
  3213. }
  3214. });
  3215. var meshSecondPass = new Mesh(boxGeometry, materialSecondPass);
  3216. meshVisualizer.add(meshSecondPass);
  3217. */
  3218. function FramebufferTexture(mesh,renderTarget) {
  3219. this.mesh = mesh;
  3220. this.texture = renderTarget;
  3221. }
  3222. return FramebufferTexture;
  3223. });
  3224. define('Core/LOD',[
  3225. 'Core/Rotation',
  3226. 'Core/RendererUtils'
  3227. ], function (
  3228. Rotation,
  3229. RendererUtils
  3230. ) {
  3231. var defaultValue = Cesium.defaultValue;
  3232. /**
  3233. *
  3234. *@param {Object|geometry}options
  3235. *@param {Boolean}[options.show=true]
  3236. *@param {Cesium.Cartesian3}[options.position]
  3237. *@param {Cesium.Rotation}[options.rotation]
  3238. *@param {Cesium.Cartesian3}[options.scale]
  3239. *
  3240. *@property {Boolean}show
  3241. *@property {Cesium.Cartesian3}position
  3242. *@property {Cesium.Rotation}rotation
  3243. *@property {Cesium.Cartesian3}scale
  3244. *@property {Boolean}needUpdate
  3245. *
  3246. *@constructor
  3247. *@memberof Cesium
  3248. *@example
  3249. MeshVisualizer = Cesium.MeshVisualizer;
  3250. Mesh = Cesium.Mesh;
  3251. MeshMaterial = Cesium.MeshMaterial;
  3252. LOD = Cesium.LOD;
  3253. var center = Cesium.Cartesian3.fromDegrees(homePosition[0], homePosition[1], 50000);
  3254. var modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(center);
  3255. var meshVisualizer = new MeshVisualizer({
  3256. modelMatrix: modelMatrix,
  3257. up: { z: 1 }
  3258. });
  3259. viewer.scene.primitives.add(meshVisualizer);
  3260. var material = new MeshMaterial({
  3261. defaultColor: "rgba(200,0,0,1.0)",
  3262. wireframe: true,
  3263. side: MeshMaterial.Sides.FRONT
  3264. });
  3265. var radius = 20000;
  3266. var sphereL0 = Cesium.SphereGeometry.createGeometry(new Cesium.SphereGeometry({
  3267. radius: radius,
  3268. vertexFormat: Cesium.VertexFormat.POSITION_ONLY,
  3269. stackPartitions:4,
  3270. slicePartitions: 4
  3271. }));
  3272. var sphereL1 = Cesium.SphereGeometry.createGeometry(new Cesium.SphereGeometry({
  3273. radius: radius,
  3274. vertexFormat: Cesium.VertexFormat.POSITION_ONLY,
  3275. stackPartitions: 8,
  3276. slicePartitions: 8
  3277. }));
  3278. var sphereL2 = Cesium.SphereGeometry.createGeometry(new Cesium.SphereGeometry({
  3279. radius: radius,
  3280. vertexFormat: Cesium.VertexFormat.POSITION_ONLY,
  3281. stackPartitions: 16,
  3282. slicePartitions: 16
  3283. }));
  3284. var sphereL3 = Cesium.SphereGeometry.createGeometry(new Cesium.SphereGeometry({
  3285. radius: radius,
  3286. vertexFormat: Cesium.VertexFormat.POSITION_ONLY,
  3287. stackPartitions: 32,
  3288. slicePartitions: 32
  3289. }));
  3290. var sphereL4 = Cesium.SphereGeometry.createGeometry(new Cesium.SphereGeometry({
  3291. radius: radius,
  3292. vertexFormat: Cesium.VertexFormat.POSITION_ONLY,
  3293. stackPartitions: 64,
  3294. slicePartitions: 64
  3295. }));
  3296. var geometries = [
  3297. [sphereL4, 5],
  3298. [sphereL3, 200],
  3299. [sphereL2, 300],
  3300. [sphereL1, 500],
  3301. [sphereL0, 2000]
  3302. ];
  3303. var maxAvailableDistance = 10000000;
  3304. var i, j, mesh, lod;
  3305. var scale = new Cesium.Cartesian3(1, 1, 1);
  3306. for (j = 0; j < 1000; j++) {
  3307. lod = new LOD();
  3308. for (i = 0; i < geometries.length; i++) {
  3309. mesh = new Mesh(geometries[i][0], material);
  3310. mesh.scale = scale;
  3311. lod.addLevel(mesh, geometries[i][1] * 1000);
  3312. }
  3313. lod.maxAvailableDistance = maxAvailableDistance;
  3314. lod.position.x = 1500000 * (0.5 - Math.random());
  3315. lod.position.y = 1750000 * (0.5 - Math.random());
  3316. lod.position.z = 130000 * (0.5 - Math.random());
  3317. meshVisualizer.add(lod);
  3318. }
  3319. */
  3320. function LOD(options) {
  3321. options = defaultValue(options, {});
  3322. this.uuid = Cesium.createGuid();
  3323. this.show = defaultValue(options.show, true);
  3324. this.maxAvailableDistance = defaultValue(options.maxAvailableDistance, Number.MAX_VALUE);
  3325. this._position = defaultValue(options.position, new Cesium.Cartesian3(0, 0, 0));
  3326. this._scale = defaultValue(options.scale, new Cesium.Cartesian3(1, 1, 1));
  3327. this._rotation = defaultValue(options.rotation, { axis: new Cesium.Cartesian3(0, 0, 1), angle: 0 });
  3328. this._rotation = new Rotation(this._rotation.axis, this._rotation.angle);
  3329. this._boundingSphere = new Cesium.BoundingSphere();
  3330. this._needsUpdate = false;
  3331. this._modelMatrixNeedsUpdate = true;
  3332. this._modelMatrix = new Cesium.Matrix4();
  3333. Cesium.Matrix4.clone(Cesium.Matrix4.IDENTITY, this._modelMatrix);
  3334. this._onNeedUpdateChanged = function () {
  3335. this._modelMatrixNeedsUpdate = true;
  3336. };
  3337. this._rotation.paramChanged.removeEventListener(this._onNeedUpdateChanged);
  3338. this._children = [];
  3339. this._parent = null;
  3340. this.type = 'LOD';
  3341. Object.defineProperties(this, {
  3342. levels: {
  3343. enumerable: true,
  3344. value: []
  3345. }
  3346. });
  3347. }
  3348. function removeByValue(arr, val) {
  3349. for (var i = 0; i < arr.length; i++) {
  3350. if (arr[i] == val) {
  3351. arr.splice(i, 1);
  3352. break;
  3353. }
  3354. }
  3355. }
  3356. LOD.prototype = {
  3357. constructor: LOD,
  3358. /**
  3359. *
  3360. *@param {Number}x
  3361. *@param {Number}y
  3362. *@param {Number}z
  3363. */
  3364. setPosition: function (x, y, z) {
  3365. var changed = false;
  3366. if (arguments.length == 1) {
  3367. if (typeof x == 'number') {
  3368. if (x != this._position.x) changed = true;
  3369. this._position.x = x;
  3370. } else if (x instanceof Cesium.Cartesian3) {
  3371. if (x != this._position.x
  3372. || y != this._position.y
  3373. || z != this._position.z) {
  3374. changed = true;
  3375. }
  3376. this._position.x = x.x;
  3377. this._position.y = x.y;
  3378. this._position.z = x.z;
  3379. }
  3380. }
  3381. if (arguments.length == 2 && typeof y == 'number') {
  3382. if (y != this._position.y) changed = true;
  3383. this._position.y = y;
  3384. }
  3385. if (arguments.length == 3 && typeof z == 'number') {
  3386. if (z != this._position.z) changed = true;
  3387. this._position.z = z;
  3388. }
  3389. if (changed) {
  3390. this._modelMatrixNeedsUpdate = true;
  3391. }
  3392. },
  3393. /**
  3394. *
  3395. *@param {Number}x
  3396. *@param {Number}y
  3397. *@param {Number}z
  3398. */
  3399. setScale: function (x, y, z) {
  3400. var changed = false;
  3401. if (arguments.length == 1) {
  3402. if (typeof x == 'number') {
  3403. if (x != this._scale.x) changed = true;
  3404. this._scale.x = x;
  3405. } else if (x instanceof Cesium.Cartesian3) {
  3406. if (x != this._scale.x
  3407. || y != this._scale.y
  3408. || z != this._scale.z) {
  3409. changed = true;
  3410. }
  3411. this._scale.x = x.x;
  3412. this._scale.y = x.y;
  3413. this._scale.z = x.z;
  3414. }
  3415. }
  3416. if (arguments.length == 2 && typeof y == 'number') {
  3417. if (y != this._scale.y) changed = true;
  3418. this._scale.y = y;
  3419. }
  3420. if (arguments.length == 3 && typeof z == 'number') {
  3421. if (z != this._scale.z) changed = true;
  3422. this._scale.z = z;
  3423. }
  3424. if (changed) {
  3425. this._modelMatrixNeedsUpdate = true;
  3426. }
  3427. },
  3428. /**
  3429. *@param {Cesium.Mesh}mesh
  3430. *@param {Number}distance
  3431. */
  3432. addLevel: function (object, distance) {
  3433. if (distance === undefined) distance = 0;
  3434. distance = Math.abs(distance);
  3435. var levels = this.levels;
  3436. for (var l = 0; l < levels.length; l++) {
  3437. if (distance < levels[l].distance) {
  3438. break;
  3439. }
  3440. }
  3441. levels.splice(l, 0, { distance: distance, object: object });
  3442. object.parent = this;
  3443. this._children.push(object);
  3444. if (this.levels[0].object.geometry) {
  3445. this._boundingSphere.radius = this.levels[0].object.geometry.boundingSphere.radius;
  3446. } else if (this.levels[0].object.boundingSphere) {
  3447. this._boundingSphere.radius = this.levels[0].object.boundingSphere.radius;
  3448. }
  3449. },
  3450. update: function () {
  3451. var actualPosition = new Cesium.Cartesian3();
  3452. return function update(parentModelMatrix, frameState) {
  3453. var levels = this.levels;
  3454. if (levels.length > 1) {
  3455. if (this._modelMatrixNeedsUpdate) {
  3456. RendererUtils.computeModelMatrix(
  3457. parentModelMatrix,
  3458. this.position,
  3459. this.rotation,
  3460. this.scale,
  3461. this.modelMatrix
  3462. );
  3463. this._modelMatrixNeedsUpdate = false;
  3464. }
  3465. Cesium.Matrix4.getTranslation(this.modelMatrix, actualPosition);
  3466. Cesium.Cartesian3.clone(actualPosition, this._boundingSphere.center);
  3467. var bs = this._boundingSphere;
  3468. var distance = Math.max(0.0, Cesium.Cartesian3.distance(bs.center, frameState.camera.positionWC) - bs.radius);
  3469. var show = this.maxAvailableDistance > distance;
  3470. show = show && frameState.cullingVolume.computeVisibility(this._boundingSphere) !== Cesium.Intersect.OUTSIDE;
  3471. levels[0].object.show = show;
  3472. for (var i = 1, l = levels.length; i < l; i++) {
  3473. if (distance >= levels[i].distance) {
  3474. levels[i - 1].object.show = false;
  3475. levels[i].object.show = show;
  3476. } else {
  3477. break;
  3478. }
  3479. }
  3480. for (; i < l; i++) {
  3481. levels[i].object.show = false;
  3482. }
  3483. }
  3484. };
  3485. }(),
  3486. getObjectForDistance: function (distance) {
  3487. var levels = this.levels;
  3488. for (var i = 1, l = levels.length; i < l; i++) {
  3489. if (distance < levels[i].distance) {
  3490. break;
  3491. }
  3492. }
  3493. return levels[i - 1].object;
  3494. }
  3495. };
  3496. Object.defineProperties(LOD.prototype, {
  3497. modelMatrix: {
  3498. get: function () {
  3499. return this._modelMatrix;
  3500. }
  3501. },
  3502. parent: {
  3503. get: function () {
  3504. return this._parent;
  3505. },
  3506. set: function (val) {
  3507. if (val && ((val._children && Array.isArray(val._children)) || (val.children && Array.isArray(val.children)))) {
  3508. if (this._parent && this._parent != val) {
  3509. var children = this._parent._children ? this._parent._children : this._parent.children;
  3510. if (Array.isArray(children)) {
  3511. removeByValue(children, this);
  3512. }
  3513. }
  3514. this._parent = val;
  3515. if (typeof this._parent.add === 'function') {
  3516. this._parent.add(this);
  3517. } else {
  3518. var children = val._children ? val._children : val.children;
  3519. children.push(this);
  3520. }
  3521. }
  3522. this._needsUpdate = true;
  3523. }
  3524. },
  3525. children: {
  3526. get: function () {
  3527. return this._children;
  3528. },
  3529. set: function (val) {
  3530. this._children = val;
  3531. this._needsUpdate = true;
  3532. }
  3533. },
  3534. needsUpdate: {
  3535. get: function () {
  3536. return this._needsUpdate;
  3537. },
  3538. set: function (val) {
  3539. this._needsUpdate = val;
  3540. }
  3541. },
  3542. rotation: {
  3543. get: function () {
  3544. return this._rotation;
  3545. },
  3546. set: function (val) {
  3547. if (val != this._rotation) {
  3548. this._rotation = val;
  3549. this._needUpdate = true;
  3550. }
  3551. this._rotation.paramChanged.removeEventListener(this._onNeedUpdateChanged);
  3552. this._rotation = val;
  3553. this._rotation.paramChanged.addEventListener(this._onNeedUpdateChanged);
  3554. }
  3555. },
  3556. position: {
  3557. get: function () {
  3558. return this._position;
  3559. },
  3560. set: function (val) {
  3561. if (val.x != this._position.x || val.y != this._position.y || val.z != this._position.z) {
  3562. this._position = val;
  3563. this._needsUpdate = true;
  3564. }
  3565. this._position = val;
  3566. }
  3567. },
  3568. scale: {
  3569. get: function () {
  3570. return this._scale;
  3571. },
  3572. set: function (val) {
  3573. if (val.x != this._scale.x || val.y != this._scale.y || val.z != this._scale.z) {
  3574. this._scale = val;
  3575. this._needsUpdate = true;
  3576. }
  3577. this._scale = val;
  3578. }
  3579. }
  3580. });
  3581. return LOD;
  3582. });
  3583. define('Core/ArrowGeometry',[
  3584. 'Core/GeometryUtils'
  3585. ], function (
  3586. GeometryUtils
  3587. ) {
  3588. /**
  3589. *
  3590. <pre><code>
  3591. + ——
  3592. + + |
  3593. + + headLength
  3594. + + |
  3595. ++++headWidth++++ ——
  3596. + + |
  3597. + + |
  3598. + + |
  3599. + + length
  3600. + + |
  3601. + + |
  3602. + + |
  3603. ++++ ——
  3604. width
  3605. </code> </pre>
  3606. *@param {Object}[options]
  3607. *@param {Number}[options.length=50000]
  3608. *@param {Number}[options.width=250]
  3609. *@param {Number}[options.headLength=5000]
  3610. *@param {Number}[options.headWidth=1000]
  3611. *@param {Boolean}[options.reverse=false]
  3612. *
  3613. *@property {Number}length
  3614. *@property {Number}width
  3615. *@property {Number}headLength
  3616. *@property {Number}headWidth
  3617. *@property {Boolean}reverse
  3618. *
  3619. *@constructor
  3620. *@memberof Cesium
  3621. */
  3622. function ArrowGeometry(options) {
  3623. options = Cesium.defaultValue(options, {});
  3624. this.length = Cesium.defaultValue(options.length, 50000);
  3625. this.width = Cesium.defaultValue(options.width, 125);
  3626. this.headLength = Cesium.defaultValue(options.headLength, 5000);
  3627. this.headWidth = Cesium.defaultValue(options.headWidth, 1000);
  3628. this.reverse = Cesium.defaultValue(options.reverse, false);
  3629. }
  3630. /**
  3631. *
  3632. *@param {Cesium.ArrowGeometry}
  3633. *@return {Cesium.Geometry}
  3634. */
  3635. ArrowGeometry.createGeometry = function (arrowGeometry) {
  3636. var length = arrowGeometry.length;
  3637. var width = arrowGeometry.width;
  3638. var headLength = arrowGeometry.headLength;
  3639. var headWidth = arrowGeometry.headWidth;
  3640. var reverse = arrowGeometry.reverse;
  3641. var line = Cesium.CylinderGeometry.createGeometry(new Cesium.CylinderGeometry({
  3642. length: length,
  3643. topRadius: width,
  3644. bottomRadius: width,
  3645. }));
  3646. var arrow;
  3647. if (reverse) {
  3648. arrow = Cesium.CylinderGeometry.createGeometry(new Cesium.CylinderGeometry({
  3649. length: headLength,
  3650. topRadius: headWidth,
  3651. bottomRadius: 0,
  3652. }));
  3653. GeometryUtils.translate(arrow, [0, 0, -(length + headLength) / 2]);
  3654. } else {
  3655. arrow = Cesium.CylinderGeometry.createGeometry(new Cesium.CylinderGeometry({
  3656. length: headLength,
  3657. topRadius: 0,
  3658. bottomRadius: headWidth,
  3659. }));
  3660. GeometryUtils.translate(arrow, [0, 0, (length + headLength) / 2]);
  3661. }
  3662. var lineWithArrow = GeometryUtils.mergeGeometries([line, arrow]);
  3663. return lineWithArrow;
  3664. }
  3665. return ArrowGeometry;
  3666. });
  3667. define('Core/PlaneGeometry',[],function () {
  3668. /**
  3669. *
  3670. <pre><code>
  3671. p1++++++++++++p4
  3672. + + +
  3673. + + +
  3674. + + +
  3675. + + +
  3676. + + +
  3677. p2++++++++++++p3
  3678. </code> </pre>
  3679. *@param {Object}options
  3680. *@param {Array<Number|Cesium.Cartesian3>}options.positions [p1,p2,p3,p4]或者[p1.x,p1.y,p1.z,p2.x,...,p4.z]
  3681. *
  3682. *@property {Array<Number|Cesium.Cartesian3>}positions
  3683. *
  3684. *@constructor
  3685. *@memberof Cesium
  3686. */
  3687. function PlaneGeometry(options) {//positions, widthSegments, heightSegments) {
  3688. this.type = 'PlaneGeometry';
  3689. if (!options || !options.positions) {
  3690. throw new Error("缺少positions参数");
  3691. }
  3692. if (options.positions.length != 4 && options.positions.length / 3 != 4) {
  3693. throw new Error("positions参数必须包含四个顶点的位置坐标");
  3694. }
  3695. this.positions = options.positions;
  3696. }
  3697. /**
  3698. *
  3699. *@param {Cesium.PlaneGeometry}
  3700. *@return {Cesium.Geometry}
  3701. */
  3702. PlaneGeometry.createGeometry = function (planeGeometry) {
  3703. var positions = planeGeometry.positions;
  3704. var positionsVal;
  3705. if (Array.isArray(positions)) {
  3706. if (positions[0] instanceof Cesium.Cartesian3) {
  3707. positionsVal = new Float32Array(12);
  3708. for (var i = 0; i < positions.length; i++) {
  3709. var p = positions[i];
  3710. positionsVal[i * 3] = p.x;
  3711. positionsVal[i * 3 + 1] = p.y;
  3712. positionsVal[i * 3 + 2] = p.z;
  3713. }
  3714. } else if (typeof positions[0] === 'number') {
  3715. positionsVal = new Float32Array(positionsVal);
  3716. } else {
  3717. throw new Error("positions参数有误");
  3718. }
  3719. } else {
  3720. throw new Error("positions参数必须是数组类型");
  3721. }
  3722. var indices = new Int32Array([0, 1, 3, 1, 2, 3]);
  3723. var attributes = {
  3724. position: new Cesium.GeometryAttribute({
  3725. componentDatatype: Cesium.ComponentDatatype.DOUBLE,
  3726. componentsPerAttribute: 3,
  3727. values: positions
  3728. })
  3729. };
  3730. var bs = Cesium.BoundingSphere.fromVertices(positions);
  3731. var geo = new Cesium.Geometry({
  3732. attributes: attributes,
  3733. indices: new Int32Array(indices),
  3734. primitiveType: Cesium.PrimitiveType.TRIANGLES,
  3735. boundingSphere: bs
  3736. });
  3737. return geo;
  3738. }
  3739. return PlaneGeometry
  3740. });
  3741. define('Core/ReferenceMesh',[
  3742. 'Core/ArrowGeometry',
  3743. 'Core/PlaneGeometry',
  3744. 'Core/Mesh',
  3745. 'Core/MeshMaterial',
  3746. 'Core/Rotation',
  3747. 'Core/RendererUtils'
  3748. ], function (
  3749. ArrowGeometry,
  3750. PlaneGeometry,
  3751. Mesh,
  3752. MeshMaterial,
  3753. Rotation,
  3754. RendererUtils
  3755. ) {
  3756. var defaultValue = Cesium.defaultValue;
  3757. /**
  3758. *
  3759. *@param {Object}[options]
  3760. *@param {Cesium.ArrowGeometry}[options.axisParameter]
  3761. *@param {Boolean}[options.show=true]
  3762. *@param {Cesium.Cartesian3}[options.position]
  3763. *@param {Cesium.VolumeRendering.Rotation}[options.rotation]
  3764. *@param {Cesium.Cartesian3}[options.scale]
  3765. *
  3766. *@property {Boolean}show
  3767. *@property {Cesium.Cartesian3}position
  3768. *@property {Cesium.Rotation}rotation
  3769. *@property {Cesium.Cartesian3}scale
  3770. *@property {Boolean}needUpdate
  3771. *
  3772. *@constructor
  3773. *@memberof Cesium
  3774. */
  3775. function ReferenceMesh(options) {
  3776. options = Cesium.defaultValue(options, {});
  3777. this._axisParameter = new ArrowGeometry(options.axisParameter);
  3778. this._axisParameterY = new ArrowGeometry(options.axisParameter);
  3779. this._axisParameterY.reverse = true;
  3780. var materialZ = new MeshMaterial({
  3781. defaultColor: "rgba(255,0,0,1)",
  3782. wireframe: false,
  3783. side: MeshMaterial.Sides.DOUBLE,
  3784. translucent: false,
  3785. });
  3786. var materialY = new MeshMaterial({
  3787. defaultColor: "rgba(0,255,0,1)",
  3788. wireframe: false,
  3789. side: MeshMaterial.Sides.DOUBLE,
  3790. translucent: true,
  3791. });
  3792. var materialX = new MeshMaterial({
  3793. defaultColor: "rgba(0,0,255,1)",
  3794. wireframe: false,
  3795. side: MeshMaterial.Sides.DOUBLE,
  3796. translucent: false,
  3797. });
  3798. var axisLine = ArrowGeometry.createGeometry(new ArrowGeometry(this._axisParameter));
  3799. var axisLineY = ArrowGeometry.createGeometry(new ArrowGeometry(this._axisParameterY));
  3800. var meshZ = new Mesh(axisLine, materialZ);
  3801. var meshY = new Mesh(axisLineY, materialY);
  3802. var meshX = new Mesh(axisLine, materialX);
  3803. meshZ.position.z = this._axisParameter.length / 2;
  3804. meshY.position.y = -this._axisParameter.length / 2;
  3805. meshY.rotation.axis.y = 1;
  3806. meshY.rotation.angle = -180;
  3807. meshX.position.x = this._axisParameter.length / 2;
  3808. meshX.rotation.axis.x = 1;
  3809. meshX.rotation.angle = -180;
  3810. meshX.parent = this;
  3811. meshY.parent = this;
  3812. meshZ.parent = this;
  3813. this._children = [meshX, meshY, meshZ];
  3814. this.x = meshX;
  3815. this.y = meshY;
  3816. this.z = meshZ;
  3817. this.uuid = Cesium.createGuid();
  3818. this.show = defaultValue(options.show, true);
  3819. this._position = defaultValue(options.position, new Cesium.Cartesian3(0, 0, 0));
  3820. this._scale = defaultValue(options.scale, new Cesium.Cartesian3(1, 1, 1));
  3821. this._rotation = defaultValue(options.rotation, { axis: new Cesium.Cartesian3(0, 0, 1), angle: 0 });
  3822. this._rotation = new Rotation(this._rotation.axis, this._rotation.angle);
  3823. this._needsUpdate = true;
  3824. this._modelMatrixNeedsUpdate = true;
  3825. this._modelMatrix = new Cesium.Matrix4();
  3826. Cesium.Matrix4.clone(Cesium.Matrix4.IDENTITY, this._modelMatrix);
  3827. this._onNeedUpdateChanged = function () {
  3828. this._modelMatrixNeedsUpdate = true;
  3829. };
  3830. this._rotation.paramChanged.removeEventListener(this._onNeedUpdateChanged);
  3831. this._parent = null;
  3832. }
  3833. function removeByValue(arr, val) {
  3834. for (var i = 0; i < arr.length; i++) {
  3835. if (arr[i] == val) {
  3836. arr.splice(i, 1);
  3837. break;
  3838. }
  3839. }
  3840. }
  3841. Object.defineProperties(ReferenceMesh.prototype, {
  3842. modelMatrix: {
  3843. get: function () {
  3844. return this._modelMatrix;
  3845. }
  3846. },
  3847. parent: {
  3848. get: function () {
  3849. return this._parent;
  3850. },
  3851. set: function (val) {
  3852. if (val && ((val._children && Array.isArray(val._children)) || (val.children && Array.isArray(val.children)))) {
  3853. if (this._parent && this._parent != val) {
  3854. var children = this._parent._children ? this._parent._children : this._parent.children;
  3855. if (Array.isArray(children)) {
  3856. removeByValue(children, this);
  3857. }
  3858. }
  3859. this._parent = val;
  3860. if (typeof this._parent.add === 'function') {
  3861. this._parent.add(this);
  3862. } else {
  3863. var children = val._children ? val._children : val.children;
  3864. children.push(this);
  3865. }
  3866. }
  3867. this.modelMatrixNeedsUpdate = true;
  3868. }
  3869. },
  3870. modelMatrixNeedsUpdate: {
  3871. get: function () {
  3872. return this._modelMatrixNeedsUpdate;
  3873. },
  3874. set: function (val) {
  3875. this._modelMatrixNeedsUpdate = val;
  3876. if (this._modelMatrixNeedsUpdate) {
  3877. Mesh.traverse(this, function (mesh) {
  3878. mesh._modelMatrixNeedsUpdate = val;
  3879. });
  3880. }
  3881. }
  3882. },
  3883. children: {
  3884. get: function () {
  3885. return this._children;
  3886. }
  3887. },
  3888. needsUpdate: {
  3889. get: function () {
  3890. return this._needsUpdate;
  3891. },
  3892. set: function (val) {
  3893. this._needsUpdate = val;
  3894. }
  3895. },
  3896. rotation: {
  3897. get: function () {
  3898. return this._rotation;
  3899. },
  3900. set: function (val) {
  3901. if (val != this._rotation) {
  3902. this._rotation = val;
  3903. this.modelMatrixNeedsUpdate = true;
  3904. }
  3905. this._rotation.paramChanged.removeEventListener(this._onNeedUpdateChanged);
  3906. this._rotation = val;
  3907. this._rotation.paramChanged.addEventListener(this._onNeedUpdateChanged);
  3908. }
  3909. },
  3910. position: {
  3911. get: function () {
  3912. return this._position;
  3913. },
  3914. set: function (val) {
  3915. if (val.x != this._position.x || val.y != this._position.y || val.z != this._position.z) {
  3916. this._position = val;
  3917. this.modelMatrixNeedsUpdate = true;
  3918. }
  3919. this._position = val;
  3920. }
  3921. },
  3922. scale: {
  3923. get: function () {
  3924. return this._scale;
  3925. },
  3926. set: function (val) {
  3927. if (val.x != this._scale.x || val.y != this._scale.y || val.z != this._scale.z) {
  3928. this._scale = val;
  3929. this.modelMatrixNeedsUpdate = true;
  3930. }
  3931. this._scale = val;
  3932. }
  3933. }
  3934. });
  3935. /**
  3936. *
  3937. *@param {Cesium.Matrix4}meshVisulizerModelMatrix
  3938. *@param {Cesium.FrameState}frameState
  3939. */
  3940. ReferenceMesh.prototype.update = function (parentModelMatrix, frameState) {
  3941. if (this._modelMatrixNeedsUpdate || this._needsUpdate) {
  3942. RendererUtils.computeModelMatrix(
  3943. parentModelMatrix,
  3944. this.position,
  3945. this.rotation,
  3946. this.scale,
  3947. this.modelMatrix
  3948. );
  3949. this._modelMatrixNeedsUpdate = false;
  3950. }
  3951. }
  3952. return ReferenceMesh;
  3953. });
  3954. /* This Source Code Form is subject to the terms of the Mozilla Public
  3955. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3956. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  3957. function TIFFParser() {
  3958. this.tiffDataView = undefined;
  3959. this.littleEndian = undefined;
  3960. this.fileDirectories = [];
  3961. };
  3962. TIFFParser.prototype = {
  3963. isLittleEndian: function () {
  3964. // Get byte order mark.
  3965. var BOM = this.getBytes(2, 0);
  3966. // Find out the endianness.
  3967. if (BOM === 0x4949) {
  3968. this.littleEndian = true;
  3969. } else if (BOM === 0x4D4D) {
  3970. this.littleEndian = false;
  3971. } else {
  3972. console.log( BOM );
  3973. throw TypeError("Invalid byte order value.");
  3974. }
  3975. return this.littleEndian;
  3976. },
  3977. hasTowel: function () {
  3978. // Check for towel.
  3979. if (this.getBytes(2, 2) !== 42) {
  3980. throw RangeError("You forgot your towel!");
  3981. return false;
  3982. }
  3983. return true;
  3984. },
  3985. getFieldTagName: function (fieldTag) {
  3986. // See: http://www.digitizationguidelines.gov/guidelines/TIFF_Metadata_Final.pdf
  3987. // See: http://www.digitalpreservation.gov/formats/content/tiff_tags.shtml
  3988. var fieldTagNames = {
  3989. // TIFF Baseline
  3990. 0x013B: 'Artist',
  3991. 0x0102: 'BitsPerSample',
  3992. 0x0109: 'CellLength',
  3993. 0x0108: 'CellWidth',
  3994. 0x0140: 'ColorMap',
  3995. 0x0103: 'Compression',
  3996. 0x8298: 'Copyright',
  3997. 0x0132: 'DateTime',
  3998. 0x0152: 'ExtraSamples',
  3999. 0x010A: 'FillOrder',
  4000. 0x0121: 'FreeByteCounts',
  4001. 0x0120: 'FreeOffsets',
  4002. 0x0123: 'GrayResponseCurve',
  4003. 0x0122: 'GrayResponseUnit',
  4004. 0x013C: 'HostComputer',
  4005. 0x010E: 'ImageDescription',
  4006. 0x0101: 'ImageLength',
  4007. 0x0100: 'ImageWidth',
  4008. 0x010F: 'Make',
  4009. 0x0119: 'MaxSampleValue',
  4010. 0x0118: 'MinSampleValue',
  4011. 0x0110: 'Model',
  4012. 0x00FE: 'NewSubfileType',
  4013. 0x0112: 'Orientation',
  4014. 0x0106: 'PhotometricInterpretation',
  4015. 0x011C: 'PlanarConfiguration',
  4016. 0x0128: 'ResolutionUnit',
  4017. 0x0116: 'RowsPerStrip',
  4018. 0x0115: 'SamplesPerPixel',
  4019. 0x0131: 'Software',
  4020. 0x0117: 'StripByteCounts',
  4021. 0x0111: 'StripOffsets',
  4022. 0x00FF: 'SubfileType',
  4023. 0x0107: 'Threshholding',
  4024. 0x011A: 'XResolution',
  4025. 0x011B: 'YResolution',
  4026. // TIFF Extended
  4027. 0x0146: 'BadFaxLines',
  4028. 0x0147: 'CleanFaxData',
  4029. 0x0157: 'ClipPath',
  4030. 0x0148: 'ConsecutiveBadFaxLines',
  4031. 0x01B1: 'Decode',
  4032. 0x01B2: 'DefaultImageColor',
  4033. 0x010D: 'DocumentName',
  4034. 0x0150: 'DotRange',
  4035. 0x0141: 'HalftoneHints',
  4036. 0x015A: 'Indexed',
  4037. 0x015B: 'JPEGTables',
  4038. 0x011D: 'PageName',
  4039. 0x0129: 'PageNumber',
  4040. 0x013D: 'Predictor',
  4041. 0x013F: 'PrimaryChromaticities',
  4042. 0x0214: 'ReferenceBlackWhite',
  4043. 0x0153: 'SampleFormat',
  4044. 0x022F: 'StripRowCounts',
  4045. 0x014A: 'SubIFDs',
  4046. 0x0124: 'T4Options',
  4047. 0x0125: 'T6Options',
  4048. 0x0145: 'TileByteCounts',
  4049. 0x0143: 'TileLength',
  4050. 0x0144: 'TileOffsets',
  4051. 0x0142: 'TileWidth',
  4052. 0x012D: 'TransferFunction',
  4053. 0x013E: 'WhitePoint',
  4054. 0x0158: 'XClipPathUnits',
  4055. 0x011E: 'XPosition',
  4056. 0x0211: 'YCbCrCoefficients',
  4057. 0x0213: 'YCbCrPositioning',
  4058. 0x0212: 'YCbCrSubSampling',
  4059. 0x0159: 'YClipPathUnits',
  4060. 0x011F: 'YPosition',
  4061. // EXIF
  4062. 0x9202: 'ApertureValue',
  4063. 0xA001: 'ColorSpace',
  4064. 0x9004: 'DateTimeDigitized',
  4065. 0x9003: 'DateTimeOriginal',
  4066. 0x8769: 'Exif IFD',
  4067. 0x9000: 'ExifVersion',
  4068. 0x829A: 'ExposureTime',
  4069. 0xA300: 'FileSource',
  4070. 0x9209: 'Flash',
  4071. 0xA000: 'FlashpixVersion',
  4072. 0x829D: 'FNumber',
  4073. 0xA420: 'ImageUniqueID',
  4074. 0x9208: 'LightSource',
  4075. 0x927C: 'MakerNote',
  4076. 0x9201: 'ShutterSpeedValue',
  4077. 0x9286: 'UserComment',
  4078. // IPTC
  4079. 0x83BB: 'IPTC',
  4080. // ICC
  4081. 0x8773: 'ICC Profile',
  4082. // XMP
  4083. 0x02BC: 'XMP',
  4084. // GDAL
  4085. 0xA480: 'GDAL_METADATA',
  4086. 0xA481: 'GDAL_NODATA',
  4087. // Photoshop
  4088. 0x8649: 'Photoshop',
  4089. };
  4090. var fieldTagName;
  4091. if (fieldTag in fieldTagNames) {
  4092. fieldTagName = fieldTagNames[fieldTag];
  4093. } else {
  4094. //console.log( "Unknown Field Tag:", fieldTag);
  4095. fieldTagName = "Tag" + fieldTag;
  4096. }
  4097. return fieldTagName;
  4098. },
  4099. getFieldTypeName: function (fieldType) {
  4100. var fieldTypeNames = {
  4101. 0x0001: 'BYTE',
  4102. 0x0002: 'ASCII',
  4103. 0x0003: 'SHORT',
  4104. 0x0004: 'LONG',
  4105. 0x0005: 'RATIONAL',
  4106. 0x0006: 'SBYTE',
  4107. 0x0007: 'UNDEFINED',
  4108. 0x0008: 'SSHORT',
  4109. 0x0009: 'SLONG',
  4110. 0x000A: 'SRATIONAL',
  4111. 0x000B: 'FLOAT',
  4112. 0x000C: 'DOUBLE',
  4113. };
  4114. var fieldTypeName;
  4115. if (fieldType in fieldTypeNames) {
  4116. fieldTypeName = fieldTypeNames[fieldType];
  4117. }
  4118. return fieldTypeName;
  4119. },
  4120. getFieldTypeLength: function (fieldTypeName) {
  4121. var fieldTypeLength;
  4122. if (['BYTE', 'ASCII', 'SBYTE', 'UNDEFINED'].indexOf(fieldTypeName) !== -1) {
  4123. fieldTypeLength = 1;
  4124. } else if (['SHORT', 'SSHORT'].indexOf(fieldTypeName) !== -1) {
  4125. fieldTypeLength = 2;
  4126. } else if (['LONG', 'SLONG', 'FLOAT'].indexOf(fieldTypeName) !== -1) {
  4127. fieldTypeLength = 4;
  4128. } else if (['RATIONAL', 'SRATIONAL', 'DOUBLE'].indexOf(fieldTypeName) !== -1) {
  4129. fieldTypeLength = 8;
  4130. }
  4131. return fieldTypeLength;
  4132. },
  4133. getBits: function (numBits, byteOffset, bitOffset) {
  4134. bitOffset = bitOffset || 0;
  4135. var extraBytes = Math.floor(bitOffset / 8);
  4136. var newByteOffset = byteOffset + extraBytes;
  4137. var totalBits = bitOffset + numBits;
  4138. var shiftRight = 32 - numBits;
  4139. if (totalBits <= 0) {
  4140. console.log( numBits, byteOffset, bitOffset );
  4141. throw RangeError("No bits requested");
  4142. } else if (totalBits <= 8) {
  4143. var shiftLeft = 24 + bitOffset;
  4144. var rawBits = this.tiffDataView.getUint8(newByteOffset, this.littleEndian);
  4145. } else if (totalBits <= 16) {
  4146. var shiftLeft = 16 + bitOffset;
  4147. var rawBits = this.tiffDataView.getUint16(newByteOffset, this.littleEndian);
  4148. } else if (totalBits <= 32) {
  4149. var shiftLeft = bitOffset;
  4150. var rawBits = this.tiffDataView.getUint32(newByteOffset, this.littleEndian);
  4151. } else {
  4152. console.log( numBits, byteOffset, bitOffset );
  4153. throw RangeError("Too many bits requested");
  4154. }
  4155. var chunkInfo = {
  4156. 'bits': ((rawBits << shiftLeft) >>> shiftRight),
  4157. 'byteOffset': newByteOffset + Math.floor(totalBits / 8),
  4158. 'bitOffset': totalBits % 8,
  4159. };
  4160. return chunkInfo;
  4161. },
  4162. getBytes: function (numBytes, offset) {
  4163. if (numBytes <= 0) {
  4164. console.log( numBytes, offset );
  4165. throw RangeError("No bytes requested");
  4166. } else if (numBytes <= 1) {
  4167. return this.tiffDataView.getUint8(offset, this.littleEndian);
  4168. } else if (numBytes <= 2) {
  4169. return this.tiffDataView.getUint16(offset, this.littleEndian);
  4170. } else if (numBytes <= 3) {
  4171. return this.tiffDataView.getUint32(offset, this.littleEndian) >>> 8;
  4172. } else if (numBytes <= 4) {
  4173. return this.tiffDataView.getUint32(offset, this.littleEndian);
  4174. } else {
  4175. console.log( numBytes, offset );
  4176. throw RangeError("Too many bytes requested");
  4177. }
  4178. },
  4179. getFieldValues: function (fieldTagName, fieldTypeName, typeCount, valueOffset) {
  4180. var fieldValues = [];
  4181. var fieldTypeLength = this.getFieldTypeLength(fieldTypeName);
  4182. var fieldValueSize = fieldTypeLength * typeCount;
  4183. if (fieldValueSize <= 4) {
  4184. // The value is stored at the big end of the valueOffset.
  4185. if (this.littleEndian === false) {
  4186. var value = valueOffset >>> ((4 - fieldTypeLength) * 8);
  4187. } else {
  4188. var value = valueOffset;
  4189. }
  4190. fieldValues.push(value);
  4191. } else {
  4192. for (var i = 0; i < typeCount; i++) {
  4193. var indexOffset = fieldTypeLength * i;
  4194. if (fieldTypeLength >= 8) {
  4195. if (['RATIONAL', 'SRATIONAL'].indexOf(fieldTypeName) !== -1) {
  4196. // Numerator
  4197. fieldValues.push(this.getBytes(4, valueOffset + indexOffset));
  4198. // Denominator
  4199. fieldValues.push(this.getBytes(4, valueOffset + indexOffset + 4));
  4200. // } else if (['DOUBLE'].indexOf(fieldTypeName) !== -1) {
  4201. // fieldValues.push(this.getBytes(4, valueOffset + indexOffset) + this.getBytes(4, valueOffset + indexOffset + 4));
  4202. } else {
  4203. console.log( fieldTypeName, typeCount, fieldValueSize );
  4204. throw TypeError("Can't handle this field type or size");
  4205. }
  4206. } else {
  4207. fieldValues.push(this.getBytes(fieldTypeLength, valueOffset + indexOffset));
  4208. }
  4209. }
  4210. }
  4211. if (fieldTypeName === 'ASCII') {
  4212. fieldValues.forEach(function(e, i, a) { a[i] = String.fromCharCode(e); });
  4213. }
  4214. return fieldValues;
  4215. },
  4216. clampColorSample: function(colorSample, bitsPerSample) {
  4217. var multiplier = Math.pow(2, 8 - bitsPerSample);
  4218. return Math.floor((colorSample * multiplier) + (multiplier - 1));
  4219. },
  4220. makeRGBAFillValue: function(r, g, b, a) {
  4221. if(typeof a === 'undefined') {
  4222. a = 1.0;
  4223. }
  4224. return "rgba(" + r + ", " + g + ", " + b + ", " + a + ")";
  4225. },
  4226. parseFileDirectory: function (byteOffset) {
  4227. var numDirEntries = this.getBytes(2, byteOffset);
  4228. var tiffFields = [];
  4229. for (var i = byteOffset + 2, entryCount = 0; entryCount < numDirEntries; i += 12, entryCount++) {
  4230. var fieldTag = this.getBytes(2, i);
  4231. var fieldType = this.getBytes(2, i + 2);
  4232. var typeCount = this.getBytes(4, i + 4);
  4233. var valueOffset = this.getBytes(4, i + 8);
  4234. var fieldTagName = this.getFieldTagName( fieldTag );
  4235. var fieldTypeName = this.getFieldTypeName( fieldType );
  4236. var fieldValues = this.getFieldValues(fieldTagName, fieldTypeName, typeCount, valueOffset);
  4237. tiffFields[fieldTagName] = { 'type': fieldTypeName, 'values': fieldValues };
  4238. }
  4239. this.fileDirectories.push( tiffFields );
  4240. var nextIFDByteOffset = this.getBytes(4, i);
  4241. if (nextIFDByteOffset === 0x00000000) {
  4242. return this.fileDirectories;
  4243. } else {
  4244. return this.parseFileDirectory(nextIFDByteOffset);
  4245. }
  4246. },
  4247. parseTIFF: function (tiffArrayBuffer, canvas) {
  4248. canvas = canvas || document.createElement('canvas');
  4249. this.tiffDataView = new DataView(tiffArrayBuffer);
  4250. this.canvas = canvas;
  4251. this.littleEndian = this.isLittleEndian(this.tiffDataView);
  4252. if (!this.hasTowel(this.tiffDataView, this.littleEndian)) {
  4253. return;
  4254. }
  4255. var firstIFDByteOffset = this.getBytes(4, 4);
  4256. this.fileDirectories = this.parseFileDirectory(firstIFDByteOffset);
  4257. var fileDirectory = this.fileDirectories[0];
  4258. //console.log( fileDirectory );
  4259. var imageWidth = fileDirectory.ImageWidth.values[0];
  4260. var imageLength = fileDirectory.ImageLength.values[0];
  4261. this.canvas.width = imageWidth;
  4262. this.canvas.height = imageLength;
  4263. var strips = [];
  4264. var compression = (fileDirectory.Compression) ? fileDirectory.Compression.values[0] : 1;
  4265. var samplesPerPixel = fileDirectory.SamplesPerPixel.values[0];
  4266. var sampleProperties = [];
  4267. var bitsPerPixel = 0;
  4268. var hasBytesPerPixel = false;
  4269. fileDirectory.BitsPerSample.values.forEach(function(bitsPerSample, i, bitsPerSampleValues) {
  4270. sampleProperties[i] = {
  4271. 'bitsPerSample': bitsPerSample,
  4272. 'hasBytesPerSample': false,
  4273. 'bytesPerSample': undefined,
  4274. };
  4275. if ((bitsPerSample % 8) === 0) {
  4276. sampleProperties[i].hasBytesPerSample = true;
  4277. sampleProperties[i].bytesPerSample = bitsPerSample / 8;
  4278. }
  4279. bitsPerPixel += bitsPerSample;
  4280. }, this);
  4281. if ((bitsPerPixel % 8) === 0) {
  4282. hasBytesPerPixel = true;
  4283. var bytesPerPixel = bitsPerPixel / 8;
  4284. }
  4285. var stripOffsetValues = fileDirectory.StripOffsets.values;
  4286. var numStripOffsetValues = stripOffsetValues.length;
  4287. // StripByteCounts is supposed to be required, but see if we can recover anyway.
  4288. if (fileDirectory.StripByteCounts) {
  4289. var stripByteCountValues = fileDirectory.StripByteCounts.values;
  4290. } else {
  4291. console.log("Missing StripByteCounts!");
  4292. // Infer StripByteCounts, if possible.
  4293. if (numStripOffsetValues === 1) {
  4294. var stripByteCountValues = [Math.ceil((imageWidth * imageLength * bitsPerPixel) / 8)];
  4295. } else {
  4296. throw Error("Cannot recover from missing StripByteCounts");
  4297. }
  4298. }
  4299. // Loop through strips and decompress as necessary.
  4300. for (var i = 0; i < numStripOffsetValues; i++) {
  4301. var stripOffset = stripOffsetValues[i];
  4302. strips[i] = [];
  4303. var stripByteCount = stripByteCountValues[i];
  4304. // Loop through pixels.
  4305. for (var byteOffset = 0, bitOffset = 0, jIncrement = 1, getHeader = true, pixel = [], numBytes = 0, sample = 0, currentSample = 0; byteOffset < stripByteCount; byteOffset += jIncrement) {
  4306. // Decompress strip.
  4307. switch (compression) {
  4308. // Uncompressed
  4309. case 1:
  4310. // Loop through samples (sub-pixels).
  4311. for (var m = 0, pixel = []; m < samplesPerPixel; m++) {
  4312. if (sampleProperties[m].hasBytesPerSample) {
  4313. // XXX: This is wrong!
  4314. var sampleOffset = sampleProperties[m].bytesPerSample * m;
  4315. pixel.push(this.getBytes(sampleProperties[m].bytesPerSample, stripOffset + byteOffset + sampleOffset));
  4316. } else {
  4317. var sampleInfo = this.getBits(sampleProperties[m].bitsPerSample, stripOffset + byteOffset, bitOffset);
  4318. pixel.push(sampleInfo.bits);
  4319. byteOffset = sampleInfo.byteOffset - stripOffset;
  4320. bitOffset = sampleInfo.bitOffset;
  4321. throw RangeError("Cannot handle sub-byte bits per sample");
  4322. }
  4323. }
  4324. strips[i].push(pixel);
  4325. if (hasBytesPerPixel) {
  4326. jIncrement = bytesPerPixel;
  4327. } else {
  4328. jIncrement = 0;
  4329. throw RangeError("Cannot handle sub-byte bits per pixel");
  4330. }
  4331. break;
  4332. // CITT Group 3 1-Dimensional Modified Huffman run-length encoding
  4333. case 2:
  4334. // XXX: Use PDF.js code?
  4335. break;
  4336. // Group 3 Fax
  4337. case 3:
  4338. // XXX: Use PDF.js code?
  4339. break;
  4340. // Group 4 Fax
  4341. case 4:
  4342. // XXX: Use PDF.js code?
  4343. break;
  4344. // LZW
  4345. case 5:
  4346. // XXX: Use PDF.js code?
  4347. break;
  4348. // Old-style JPEG (TIFF 6.0)
  4349. case 6:
  4350. // XXX: Use PDF.js code?
  4351. break;
  4352. // New-style JPEG (TIFF Specification Supplement 2)
  4353. case 7:
  4354. // XXX: Use PDF.js code?
  4355. break;
  4356. // PackBits
  4357. case 32773:
  4358. // Are we ready for a new block?
  4359. if (getHeader) {
  4360. getHeader = false;
  4361. var blockLength = 1;
  4362. var iterations = 1;
  4363. // The header byte is signed.
  4364. var header = this.tiffDataView.getInt8(stripOffset + byteOffset, this.littleEndian);
  4365. if ((header >= 0) && (header <= 127)) { // Normal pixels.
  4366. blockLength = header + 1;
  4367. } else if ((header >= -127) && (header <= -1)) { // Collapsed pixels.
  4368. iterations = -header + 1;
  4369. } else /*if (header === -128)*/ { // Placeholder byte?
  4370. getHeader = true;
  4371. }
  4372. } else {
  4373. var currentByte = this.getBytes(1, stripOffset + byteOffset);
  4374. // Duplicate bytes, if necessary.
  4375. for (var m = 0; m < iterations; m++) {
  4376. if (sampleProperties[sample].hasBytesPerSample) {
  4377. // We're reading one byte at a time, so we need to handle multi-byte samples.
  4378. currentSample = (currentSample << (8 * numBytes)) | currentByte;
  4379. numBytes++;
  4380. // Is our sample complete?
  4381. if (numBytes === sampleProperties[sample].bytesPerSample) {
  4382. pixel.push(currentSample);
  4383. currentSample = numBytes = 0;
  4384. sample++;
  4385. }
  4386. } else {
  4387. throw RangeError("Cannot handle sub-byte bits per sample");
  4388. }
  4389. // Is our pixel complete?
  4390. if (sample === samplesPerPixel)
  4391. {
  4392. strips[i].push(pixel);
  4393. pixel = [];
  4394. sample = 0;
  4395. }
  4396. }
  4397. blockLength--;
  4398. // Is our block complete?
  4399. if (blockLength === 0) {
  4400. getHeader = true;
  4401. }
  4402. }
  4403. jIncrement = 1;
  4404. break;
  4405. // Unknown compression algorithm
  4406. default:
  4407. // Do not attempt to parse the image data.
  4408. break;
  4409. }
  4410. }
  4411. // console.log( strips[i] );
  4412. }
  4413. // console.log( strips );
  4414. if (canvas.getContext) {
  4415. var ctx = this.canvas.getContext("2d");
  4416. // Set a default fill style.
  4417. ctx.fillStyle = this.makeRGBAFillValue(255, 255, 255, 0);
  4418. // If RowsPerStrip is missing, the whole image is in one strip.
  4419. if (fileDirectory.RowsPerStrip) {
  4420. var rowsPerStrip = fileDirectory.RowsPerStrip.values[0];
  4421. } else {
  4422. var rowsPerStrip = imageLength;
  4423. }
  4424. var numStrips = strips.length;
  4425. var imageLengthModRowsPerStrip = imageLength % rowsPerStrip;
  4426. var rowsInLastStrip = (imageLengthModRowsPerStrip === 0) ? rowsPerStrip : imageLengthModRowsPerStrip;
  4427. var numRowsInStrip = rowsPerStrip;
  4428. var numRowsInPreviousStrip = 0;
  4429. var photometricInterpretation = fileDirectory.PhotometricInterpretation.values[0];
  4430. var extraSamplesValues = [];
  4431. var numExtraSamples = 0;
  4432. if (fileDirectory.ExtraSamples) {
  4433. extraSamplesValues = fileDirectory.ExtraSamples.values;
  4434. numExtraSamples = extraSamplesValues.length;
  4435. }
  4436. if (fileDirectory.ColorMap) {
  4437. var colorMapValues = fileDirectory.ColorMap.values;
  4438. var colorMapSampleSize = Math.pow(2, sampleProperties[0].bitsPerSample);
  4439. }
  4440. // Loop through the strips in the image.
  4441. for (var i = 0; i < numStrips; i++) {
  4442. // The last strip may be short.
  4443. if ((i + 1) === numStrips) {
  4444. numRowsInStrip = rowsInLastStrip;
  4445. }
  4446. var numPixels = strips[i].length;
  4447. var yPadding = numRowsInPreviousStrip * i;
  4448. // Loop through the rows in the strip.
  4449. for (var y = 0, j = 0; y < numRowsInStrip, j < numPixels; y++) {
  4450. // Loop through the pixels in the row.
  4451. for (var x = 0; x < imageWidth; x++, j++) {
  4452. var pixelSamples = strips[i][j];
  4453. var red = 0;
  4454. var green = 0;
  4455. var blue = 0;
  4456. var opacity = 1.0;
  4457. if (numExtraSamples > 0) {
  4458. for (var k = 0; k < numExtraSamples; k++) {
  4459. if (extraSamplesValues[k] === 1 || extraSamplesValues[k] === 2) {
  4460. // Clamp opacity to the range [0,1].
  4461. opacity = pixelSamples[3 + k] / 256;
  4462. break;
  4463. }
  4464. }
  4465. }
  4466. switch (photometricInterpretation) {
  4467. // Bilevel or Grayscale
  4468. // WhiteIsZero
  4469. case 0:
  4470. if (sampleProperties[0].hasBytesPerSample) {
  4471. var invertValue = Math.pow(0x10, sampleProperties[0].bytesPerSample * 2);
  4472. }
  4473. // Invert samples.
  4474. pixelSamples.forEach(function(sample, index, samples) { samples[index] = invertValue - sample; });
  4475. // Bilevel or Grayscale
  4476. // BlackIsZero
  4477. case 1:
  4478. red = green = blue = this.clampColorSample(pixelSamples[0], sampleProperties[0].bitsPerSample);
  4479. break;
  4480. // RGB Full Color
  4481. case 2:
  4482. red = this.clampColorSample(pixelSamples[0], sampleProperties[0].bitsPerSample);
  4483. green = this.clampColorSample(pixelSamples[1], sampleProperties[1].bitsPerSample);
  4484. blue = this.clampColorSample(pixelSamples[2], sampleProperties[2].bitsPerSample);
  4485. break;
  4486. // RGB Color Palette
  4487. case 3:
  4488. if (colorMapValues === undefined) {
  4489. throw Error("Palette image missing color map");
  4490. }
  4491. var colorMapIndex = pixelSamples[0];
  4492. red = this.clampColorSample(colorMapValues[colorMapIndex], 16);
  4493. green = this.clampColorSample(colorMapValues[colorMapSampleSize + colorMapIndex], 16);
  4494. blue = this.clampColorSample(colorMapValues[(2 * colorMapSampleSize) + colorMapIndex], 16);
  4495. break;
  4496. // Transparency mask
  4497. case 4:
  4498. throw RangeError( 'Not Yet Implemented: Transparency mask' );
  4499. break;
  4500. // CMYK
  4501. case 5:
  4502. throw RangeError( 'Not Yet Implemented: CMYK' );
  4503. break;
  4504. // YCbCr
  4505. case 6:
  4506. throw RangeError( 'Not Yet Implemented: YCbCr' );
  4507. break;
  4508. // CIELab
  4509. case 8:
  4510. throw RangeError( 'Not Yet Implemented: CIELab' );
  4511. break;
  4512. // Unknown Photometric Interpretation
  4513. default:
  4514. throw RangeError( 'Unknown Photometric Interpretation:', photometricInterpretation );
  4515. break;
  4516. }
  4517. ctx.fillStyle = this.makeRGBAFillValue(red, green, blue, opacity);
  4518. ctx.fillRect(x, yPadding + y, 1, 1);
  4519. }
  4520. }
  4521. numRowsInPreviousStrip = numRowsInStrip;
  4522. }
  4523. }
  4524. /* for (var i = 0, numFileDirectories = this.fileDirectories.length; i < numFileDirectories; i++) {
  4525. // Stuff
  4526. }*/
  4527. return this.canvas;
  4528. },
  4529. }
  4530. if (typeof module === "undefined") {
  4531. this.TIFFParser = TIFFParser;
  4532. } else {
  4533. module.exports = TIFFParser;
  4534. }
  4535. if (typeof define === "function") {
  4536. define('ThirdParty/tiff-js/tiff',[],function () { return TIFFParser; });
  4537. }
  4538. ;
  4539. //define(function () {
  4540. /**
  4541. *@class
  4542. *@memberof Cesium
  4543. */
  4544. function Path() { }
  4545. /**
  4546. *
  4547. *获取文件扩展名(后缀)
  4548. *@param {String}fname 文件名
  4549. */
  4550. Path.GetExtension = function (fname) {
  4551. var start = fname.lastIndexOf(".");
  4552. if (start >= 0) {
  4553. return fname.substring(start, fname.length);
  4554. }
  4555. return "";
  4556. }
  4557. /**
  4558. *
  4559. *获取文件扩展名(后缀)
  4560. *@param {String}fname 文件名
  4561. */
  4562. Path.GetFileName = function (fname) {
  4563. var start = fname.lastIndexOf("/");
  4564. if (start < 0) {
  4565. return fname;
  4566. }
  4567. return fname.substring(start + 1, fname.length);
  4568. }
  4569. /**
  4570. *
  4571. *获取文件夹
  4572. *@param {String}fname 文件名
  4573. */
  4574. Path.GetDirectoryName = function (fname) {
  4575. var start = fname.lastIndexOf("/");
  4576. if (start < 0) {
  4577. return "";
  4578. }
  4579. return fname.substring(0, start);
  4580. }
  4581. /**
  4582. *
  4583. *获取文件夹
  4584. *@param {String}fname 文件名
  4585. */
  4586. Path.Combine = function (dir, fname) {
  4587. return dir + fname;
  4588. }
  4589. Path.ChangeExtension = function (fname, newExt) {
  4590. return fname.replace(Path.GetExtension(fname), newExt);
  4591. }
  4592. // return Path;
  4593. //});
  4594. if (typeof module === "undefined") {
  4595. this.Path = Path;
  4596. } else {
  4597. module.exports = Path;
  4598. }
  4599. if (typeof define === "function") {
  4600. define('Util/Path',[],function () { return Path; });
  4601. }
  4602. ;
  4603. define('Core/Shaders/ShaderLib',[
  4604. 'Core/Shaders/ShaderChunk'
  4605. ], function (
  4606. ShaderChunk
  4607. ) {
  4608. /**
  4609. * Uniforms library for shared webgl shaders
  4610. */
  4611. var UniformsLib = {
  4612. common: {
  4613. diffuse: { value: new Cesium.Color(0xeeeeee) },
  4614. opacity: { value: 1.0 },
  4615. map: { value: null },
  4616. offsetRepeat: { value: new Cesium.Cartesian4(0, 0, 1, 1) },
  4617. specularMap: { value: null },
  4618. alphaMap: { value: null },
  4619. envMap: { value: null },
  4620. flipEnvMap: { value: -1 },
  4621. reflectivity: { value: 1.0 },
  4622. refractionRatio: { value: 0.98 }
  4623. },
  4624. aomap: {
  4625. aoMap: { value: null },
  4626. aoMapIntensity: { value: 1 }
  4627. },
  4628. lightmap: {
  4629. lightMap: { value: null },
  4630. lightMapIntensity: { value: 1 }
  4631. },
  4632. emissivemap: {
  4633. emissiveMap: { value: null }
  4634. },
  4635. bumpmap: {
  4636. bumpMap: { value: null },
  4637. bumpScale: { value: 1 }
  4638. },
  4639. normalmap: {
  4640. normalMap: { value: null },
  4641. normalScale: { value: new Cesium.Cartesian2(1, 1) }
  4642. },
  4643. displacementmap: {
  4644. displacementMap: { value: null },
  4645. displacementScale: { value: 1 },
  4646. displacementBias: { value: 0 }
  4647. },
  4648. roughnessmap: {
  4649. roughnessMap: { value: null }
  4650. },
  4651. metalnessmap: {
  4652. metalnessMap: { value: null }
  4653. },
  4654. gradientmap: {
  4655. gradientMap: { value: null }
  4656. },
  4657. fog: {
  4658. fogDensity: { value: 0.00025 },
  4659. fogNear: { value: 1 },
  4660. fogFar: { value: 2000 },
  4661. fogColor: { value: new Cesium.Color(0xffffff) }
  4662. },
  4663. lights: {
  4664. ambientLightColor: { value: [] },
  4665. directionalLights: {
  4666. value: [], properties: {
  4667. direction: {},
  4668. color: {},
  4669. shadow: {},
  4670. shadowBias: {},
  4671. shadowRadius: {},
  4672. shadowMapSize: {}
  4673. }
  4674. },
  4675. directionalShadowMap: { value: [] },
  4676. directionalShadowMatrix: { value: [] },
  4677. spotLights: {
  4678. value: [], properties: {
  4679. color: {},
  4680. position: {},
  4681. direction: {},
  4682. distance: {},
  4683. coneCos: {},
  4684. penumbraCos: {},
  4685. decay: {},
  4686. shadow: {},
  4687. shadowBias: {},
  4688. shadowRadius: {},
  4689. shadowMapSize: {}
  4690. }
  4691. },
  4692. spotShadowMap: { value: [] },
  4693. spotShadowMatrix: { value: [] },
  4694. pointLights: {
  4695. value: [], properties: {
  4696. color: {},
  4697. position: {},
  4698. decay: {},
  4699. distance: {},
  4700. shadow: {},
  4701. shadowBias: {},
  4702. shadowRadius: {},
  4703. shadowMapSize: {}
  4704. }
  4705. },
  4706. pointShadowMap: { value: [] },
  4707. pointShadowMatrix: { value: [] },
  4708. hemisphereLights: {
  4709. value: [], properties: {
  4710. direction: {},
  4711. skyColor: {},
  4712. groundColor: {}
  4713. }
  4714. },
  4715. // TODO (abelnation): RectAreaLight BRDF data needs to be moved from example to main src
  4716. rectAreaLights: {
  4717. value: [], properties: {
  4718. color: {},
  4719. position: {},
  4720. width: {},
  4721. height: {}
  4722. }
  4723. }
  4724. },
  4725. points: {
  4726. diffuse: { value: new Cesium.Color(0xeeeeee) },
  4727. opacity: { value: 1.0 },
  4728. size: { value: 1.0 },
  4729. scale: { value: 1.0 },
  4730. map: { value: null },
  4731. offsetRepeat: { value: new Cesium.Cartesian4(0, 0, 1, 1) }
  4732. }
  4733. };
  4734. /**
  4735. * Uniform Utilities
  4736. */
  4737. var UniformsUtils = {
  4738. merge: function (uniforms) {
  4739. var merged = {};
  4740. for (var u = 0; u < uniforms.length; u++) {
  4741. var tmp = this.clone(uniforms[u]);
  4742. for (var p in tmp) {
  4743. merged[p] = tmp[p];
  4744. }
  4745. }
  4746. return merged;
  4747. },
  4748. clone: function (uniforms_src) {
  4749. var uniforms_dst = {};
  4750. for (var u in uniforms_src) {
  4751. uniforms_dst[u] = {};
  4752. for (var p in uniforms_src[u]) {
  4753. var parameter_src = uniforms_src[u][p];
  4754. if (parameter_src && (parameter_src instanceof Cesium.Color ||
  4755. parameter_src instanceof Cesium.Matrix3 || parameter_src instanceof Cesium.Matrix4 ||
  4756. parameter_src instanceof Cesium.Cartesian2 || parameter_src instanceof Cesium.Cartesian3
  4757. || parameter_src instanceof Cesium.Cartesian4
  4758. //||parameter_src.isTexture
  4759. )) {
  4760. uniforms_dst[u][p] = parameter_src.constructor.clone(parameter_src);//.clone();
  4761. } else if (Array.isArray(parameter_src)) {
  4762. uniforms_dst[u][p] = parameter_src.slice();
  4763. } else {
  4764. uniforms_dst[u][p] = parameter_src;
  4765. }
  4766. }
  4767. }
  4768. return uniforms_dst;
  4769. }
  4770. };
  4771. /**
  4772. * @author alteredq / http://alteredqualia.com/
  4773. * @author mrdoob / http://mrdoob.com/
  4774. * @author mikael emtinger / http://gomo.se/
  4775. */
  4776. var ShaderLib = {
  4777. basic: {
  4778. uniforms: UniformsUtils.merge([
  4779. UniformsLib.common,
  4780. UniformsLib.aomap,
  4781. UniformsLib.lightmap,
  4782. UniformsLib.fog
  4783. ]),
  4784. vertexShader: ShaderChunk.meshbasic_vert,
  4785. fragmentShader: ShaderChunk.meshbasic_frag
  4786. },
  4787. lambert: {
  4788. uniforms: UniformsUtils.merge([
  4789. UniformsLib.common,
  4790. UniformsLib.aomap,
  4791. UniformsLib.lightmap,
  4792. UniformsLib.emissivemap,
  4793. UniformsLib.fog,
  4794. UniformsLib.lights,
  4795. {
  4796. emissive: { value: new Cesium.Color(0x000000) }
  4797. }
  4798. ]),
  4799. vertexShader: ShaderChunk.meshlambert_vert,
  4800. fragmentShader: ShaderChunk.meshlambert_frag
  4801. },
  4802. phong: {
  4803. uniforms: UniformsUtils.merge([
  4804. UniformsLib.common,
  4805. UniformsLib.aomap,
  4806. UniformsLib.lightmap,
  4807. UniformsLib.emissivemap,
  4808. UniformsLib.bumpmap,
  4809. UniformsLib.normalmap,
  4810. UniformsLib.displacementmap,
  4811. UniformsLib.gradientmap,
  4812. UniformsLib.fog,
  4813. UniformsLib.lights,
  4814. {
  4815. emissive: { value: new Cesium.Color(0x000000) },
  4816. specular: { value: new Cesium.Color(0x111111) },
  4817. shininess: { value: 30 }
  4818. }
  4819. ]),
  4820. vertexShader: ShaderChunk.meshphong_vert,
  4821. fragmentShader: ShaderChunk.meshphong_frag
  4822. },
  4823. standard: {
  4824. uniforms: UniformsUtils.merge([
  4825. UniformsLib.common,
  4826. UniformsLib.aomap,
  4827. UniformsLib.lightmap,
  4828. UniformsLib.emissivemap,
  4829. UniformsLib.bumpmap,
  4830. UniformsLib.normalmap,
  4831. UniformsLib.displacementmap,
  4832. UniformsLib.roughnessmap,
  4833. UniformsLib.metalnessmap,
  4834. UniformsLib.fog,
  4835. UniformsLib.lights,
  4836. {
  4837. emissive: { value: new Cesium.Color(0x000000) },
  4838. roughness: { value: 0.5 },
  4839. metalness: { value: 0.5 },
  4840. envMapIntensity: { value: 1 } // temporary
  4841. }
  4842. ]),
  4843. vertexShader: ShaderChunk.meshphysical_vert,
  4844. fragmentShader: ShaderChunk.meshphysical_frag
  4845. },
  4846. points: {
  4847. uniforms: UniformsUtils.merge([
  4848. UniformsLib.points,
  4849. UniformsLib.fog
  4850. ]),
  4851. vertexShader: ShaderChunk.points_vert,
  4852. fragmentShader: ShaderChunk.points_frag
  4853. },
  4854. dashed: {
  4855. uniforms: UniformsUtils.merge([
  4856. UniformsLib.common,
  4857. UniformsLib.fog,
  4858. {
  4859. scale: { value: 1 },
  4860. dashSize: { value: 1 },
  4861. totalSize: { value: 2 }
  4862. }
  4863. ]),
  4864. vertexShader: ShaderChunk.linedashed_vert,
  4865. fragmentShader: ShaderChunk.linedashed_frag
  4866. },
  4867. depth: {
  4868. uniforms: UniformsUtils.merge([
  4869. UniformsLib.common,
  4870. UniformsLib.displacementmap
  4871. ]),
  4872. vertexShader: ShaderChunk.depth_vert,
  4873. fragmentShader: ShaderChunk.depth_frag
  4874. },
  4875. normal: {
  4876. uniforms: UniformsUtils.merge([
  4877. UniformsLib.common,
  4878. UniformsLib.bumpmap,
  4879. UniformsLib.normalmap,
  4880. UniformsLib.displacementmap,
  4881. {
  4882. opacity: { value: 1.0 }
  4883. }
  4884. ]),
  4885. vertexShader: ShaderChunk.normal_vert,
  4886. fragmentShader: ShaderChunk.normal_frag
  4887. },
  4888. /* -------------------------------------------------------------------------
  4889. // Cube map shader
  4890. ------------------------------------------------------------------------- */
  4891. cube: {
  4892. uniforms: {
  4893. tCube: { value: null },
  4894. tFlip: { value: -1 },
  4895. opacity: { value: 1.0 }
  4896. },
  4897. vertexShader: ShaderChunk.cube_vert,
  4898. fragmentShader: ShaderChunk.cube_frag
  4899. },
  4900. /* -------------------------------------------------------------------------
  4901. // Cube map shader
  4902. ------------------------------------------------------------------------- */
  4903. equirect: {
  4904. uniforms: {
  4905. tEquirect: { value: null },
  4906. tFlip: { value: -1 }
  4907. },
  4908. vertexShader: ShaderChunk.equirect_vert,
  4909. fragmentShader: ShaderChunk.equirect_frag
  4910. },
  4911. distanceRGBA: {
  4912. uniforms: {
  4913. lightPos: { value: new Cesium.Cartesian3() }
  4914. },
  4915. vertexShader: ShaderChunk.distanceRGBA_vert,
  4916. fragmentShader: ShaderChunk.distanceRGBA_frag
  4917. }
  4918. };
  4919. ShaderLib.physical = {
  4920. uniforms: UniformsUtils.merge([
  4921. ShaderLib.standard.uniforms,
  4922. {
  4923. clearCoat: { value: 0 },
  4924. clearCoatRoughness: { value: 0 }
  4925. }
  4926. ]),
  4927. vertexShader: ShaderChunk.meshphysical_vert,
  4928. fragmentShader: ShaderChunk.meshphysical_frag
  4929. };
  4930. return ShaderLib;
  4931. });
  4932. define('Core/MaterialUtils',[
  4933. 'Core/Shaders/ShaderChunk',
  4934. 'Core/Shaders/ShaderLib',
  4935. 'Core/MeshMaterial'
  4936. ], function (
  4937. ShaderChunk,
  4938. ShaderLib,
  4939. MeshMaterial
  4940. ) {
  4941. var shaderIDs = {
  4942. MeshDepthMaterial: 'depth',
  4943. MeshNormalMaterial: 'normal',
  4944. MeshBasicMaterial: 'basic',
  4945. MeshLambertMaterial: 'lambert',
  4946. MeshPhongMaterial: 'phong',
  4947. MeshToonMaterial: 'phong',
  4948. MeshStandardMaterial: 'physical',
  4949. MeshPhysicalMaterial: 'physical',
  4950. LineBasicMaterial: 'basic',
  4951. LineDashedMaterial: 'dashed',
  4952. PointsMaterial: 'points'
  4953. };
  4954. /**
  4955. *
  4956. *@constructor
  4957. *@memberof Cesium
  4958. */
  4959. function MaterialUtils() {
  4960. }
  4961. /**
  4962. *
  4963. *@param {THREE.Material}material3js
  4964. *@return {Cesium.MeshMaterial}
  4965. */
  4966. MaterialUtils.fromMaterial3js = function (material3js) {
  4967. var shaderID = shaderIDs[material3js.type];
  4968. material3js["is" + material3js.type] = true;
  4969. var shader = THREE.ShaderLib[shaderID];
  4970. if (!shader) {
  4971. shader = material3js;
  4972. }
  4973. var material = new MeshMaterial({
  4974. vertexShader: shader.vertexShader,
  4975. fragmentShader: shader.fragmentShader,
  4976. uniforms: cloneUniforms(shader.uniforms)
  4977. });
  4978. material.material3js = material3js;
  4979. MaterialUtils.updateMaterialFrom3js(material);
  4980. return material;
  4981. }
  4982. function cloneUniforms(uniforms3js) {
  4983. var uniforms = {};
  4984. for (var i in uniforms3js) {
  4985. if (uniforms3js.hasOwnProperty(i)) {
  4986. uniforms[i] = {
  4987. value: {}
  4988. };
  4989. for (var n in uniforms3js[i]) {
  4990. if (n!=="value") {
  4991. uniforms[i][n] = uniforms3js[i][n];
  4992. }
  4993. }
  4994. if (uniforms3js[i].t) {
  4995. switch (uniforms3js[i].t) {
  4996. default:
  4997. }
  4998. }
  4999. bindUniformValue(uniforms[i], uniforms3js[i].value);
  5000. }
  5001. }
  5002. return uniforms;
  5003. }
  5004. /**
  5005. *
  5006. *@param {Cesium.MeshMaterial}materialWidth3js
  5007. *@private
  5008. */
  5009. MaterialUtils.updateMaterialFrom3js = function (materialWidth3js) {
  5010. if (!materialWidth3js || !materialWidth3js.material3js) {
  5011. return;
  5012. }
  5013. var material3js = materialWidth3js.material3js;
  5014. materialWidth3js.translucent = material3js.transparent;
  5015. materialWidth3js.wireframe = material3js.wireframe;
  5016. var m_uniforms = materialWidth3js.uniforms;
  5017. var material = materialWidth3js.material3js;
  5018. if (material.isMeshBasicMaterial ||
  5019. material.isMeshLambertMaterial ||
  5020. material.isMeshPhongMaterial ||
  5021. material.isMeshStandardMaterial ||
  5022. material.isMeshNormalMaterial ||
  5023. material.isMeshDepthMaterial) {
  5024. refreshUniformsCommon(m_uniforms, material);
  5025. }
  5026. // refresh single material specific uniforms
  5027. if (material.isLineBasicMaterial) {
  5028. refreshUniformsLine(m_uniforms, material);
  5029. } else if (material.isLineDashedMaterial) {
  5030. refreshUniformsLine(m_uniforms, material);
  5031. refreshUniformsDash(m_uniforms, material);
  5032. } else if (material.isPointsMaterial) {
  5033. refreshUniformsPoints(m_uniforms, material);
  5034. } else if (material.isMeshLambertMaterial) {
  5035. refreshUniformsLambert(m_uniforms, material);
  5036. } else if (material.isMeshToonMaterial) {
  5037. refreshUniformsToon(m_uniforms, material);
  5038. } else if (material.isMeshPhongMaterial) {
  5039. refreshUniformsPhong(m_uniforms, material);
  5040. } else if (material.isMeshPhysicalMaterial) {
  5041. refreshUniformsPhysical(m_uniforms, material);
  5042. } else if (material.isMeshStandardMaterial) {
  5043. refreshUniformsStandard(m_uniforms, material);
  5044. } else if (material.isMeshDepthMaterial) {
  5045. if (material.displacementMap) {
  5046. bindUniformValue(m_uniforms.displacementMap, material.displacementMap);
  5047. bindUniformValue(m_uniforms.displacementScale, material.displacementScale);
  5048. bindUniformValue(m_uniforms.displacementBias, material.displacementBias);
  5049. }
  5050. } else if (material.isMeshNormalMaterial) {
  5051. refreshUniformsNormal(m_uniforms, material);
  5052. } else {
  5053. for (var i in material.uniforms) {
  5054. if (material.uniforms.hasOwnProperty(i)) {
  5055. bindUniformValue(m_uniforms[i], material.uniforms[i].value);
  5056. }
  5057. }
  5058. }
  5059. //if (material.lights) {
  5060. // // wire up the material to this renderer's lighting state
  5061. // //uniforms.ambientLightColor.value = _lights.ambient;
  5062. // //uniforms.directionalLights.value = _lights.directional;
  5063. // //uniforms.spotLights.value = _lights.spot;
  5064. // //uniforms.rectAreaLights.value = _lights.rectArea;
  5065. // //uniforms.pointLights.value = _lights.point;
  5066. // //uniforms.hemisphereLights.value = _lights.hemi;
  5067. // //uniforms.directionalShadowMap.value = _lights.directionalShadowMap;
  5068. // //uniforms.directionalShadowMatrix.value = _lights.directionalShadowMatrix;
  5069. // //uniforms.spotShadowMap.value = _lights.spotShadowMap;
  5070. // //uniforms.spotShadowMatrix.value = _lights.spotShadowMatrix;
  5071. // //uniforms.pointShadowMap.value = _lights.pointShadowMap;
  5072. // //uniforms.pointShadowMatrix.value = _lights.pointShadowMatrix;
  5073. // // TODO (abelnation): add area lights shadow info to uniforms
  5074. //} else {
  5075. m_uniforms.ambientLightColor = { value: new Cesium.Color(0.06666666666666667, 0.06666666666666667, 0.06666666666666667) };
  5076. //}
  5077. }
  5078. /**
  5079. *
  5080. *@param {Object}material3js
  5081. *@return {Boolean}
  5082. */
  5083. MaterialUtils.isMaterial3js = function (material3js) {
  5084. return typeof THREE !== 'undefined' && material3js instanceof THREE.Material;
  5085. }
  5086. // Uniforms (refresh bindUniformValue(uniforms objects)
  5087. function refreshUniformsCommon(uniforms, material) {
  5088. bindUniformValue(uniforms.opacity, material.opacity);
  5089. bindUniformValue(uniforms.diffuse, material.color);
  5090. if (material.emissive) {
  5091. var val3js = new material.emissive.constructor().copy(material.emissive).multiplyScalar(material.emissiveIntensity)
  5092. bindUniformValue(uniforms.emissive, val3js);
  5093. }
  5094. bindUniformValue(uniforms.map, material.map);
  5095. bindUniformValue(uniforms.specularMap, material.specularMap);
  5096. bindUniformValue(uniforms.alphaMap, material.alphaMap);
  5097. if (material.lightMap) {
  5098. bindUniformValue(uniforms.lightMap, material.lightMap);
  5099. bindUniformValue(uniforms.lightMapIntensity, material.lightMapIntensity);
  5100. }
  5101. if (material.aoMap) {
  5102. bindUniformValue(uniforms.aoMap, material.aoMap);
  5103. bindUniformValue(uniforms.aoMapIntensity, material.aoMapIntensity);
  5104. }
  5105. // uv repeat and offset setting priorities
  5106. // 1. color map
  5107. // 2. specular map
  5108. // 3. normal map
  5109. // 4. bump map
  5110. // 5. alpha map
  5111. // 6. emissive map
  5112. var uvScaleMap
  5113. if (material.map) {
  5114. uvScaleMap = material.map
  5115. } else if (material.specularMap) {
  5116. uvScaleMap = material.specularMap
  5117. } else if (material.displacementMap) {
  5118. uvScaleMap = material.displacementMap
  5119. } else if (material.normalMap) {
  5120. uvScaleMap = material.normalMap
  5121. } else if (material.bumpMap) {
  5122. uvScaleMap = material.bumpMap
  5123. } else if (material.roughnessMap) {
  5124. uvScaleMap = material.roughnessMap
  5125. } else if (material.metalnessMap) {
  5126. uvScaleMap = material.metalnessMap
  5127. } else if (material.alphaMap) {
  5128. uvScaleMap = material.alphaMap
  5129. } else if (material.emissiveMap) {
  5130. uvScaleMap = material.emissiveMap
  5131. }
  5132. if (uvScaleMap !== undefined) {
  5133. // backwards compatibility
  5134. if (uvScaleMap.isWebGLRenderTarget) {
  5135. uvScaleMap = uvScaleMap.texture
  5136. }
  5137. var offset = uvScaleMap.offset
  5138. var repeat = uvScaleMap.repeat
  5139. bindUniformValue(uniforms.offsetRepeat, offset);
  5140. }
  5141. bindUniformValue(uniforms.envMap, material.envMap);
  5142. // don't flip CubeTexture envMaps, flip everything else:
  5143. // WebGLRenderTargetCube will be flipped for backwards compatibility
  5144. // WebGLRenderTargetCube.texture will be flipped because it's a Texture and NOT a CubeTexture
  5145. // this check must be handled differently, or removed entirely, if WebGLRenderTargetCube uses a CubeTexture in the future
  5146. bindUniformValue(uniforms.flipEnvMap, (!(material.envMap && material.envMap.isCubeTexture)) ? 1 : -1);
  5147. bindUniformValue(uniforms.reflectivity, material.reflectivity);
  5148. bindUniformValue(uniforms.refractionRatio, material.refractionRatio);
  5149. }
  5150. function refreshUniformsLine(uniforms, material) {
  5151. bindUniformValue(uniforms.diffuse, material.color);
  5152. bindUniformValue(uniforms.opacity, material.opacity);
  5153. }
  5154. function refreshUniformsDash(uniforms, material) {
  5155. bindUniformValue(uniforms.dashSize, material.dashSize);
  5156. bindUniformValue(uniforms.totalSize, material.dashSize + material.gapSize);
  5157. bindUniformValue(uniforms.scale, material.scale);
  5158. }
  5159. function refreshUniformsPoints(uniforms, material) {
  5160. bindUniformValue(uniforms.diffuse, material.color);
  5161. bindUniformValue(uniforms.opacity, material.opacity);
  5162. bindUniformValue(uniforms.size, material.size * _pixelRatio);
  5163. bindUniformValue(uniforms.scale, _height * 0.5);
  5164. bindUniformValue(uniforms.map, material.map);
  5165. if (material.map !== null) {
  5166. var offset = material.map.offset;
  5167. var repeat = material.map.repeat;
  5168. bindUniformValue(uniforms.offsetRepeat.value.set(offset.x, offset.y, repeat.x, repeat.y));
  5169. }
  5170. }
  5171. function refreshUniformsFog(uniforms, fog) {
  5172. bindUniformValue(uniforms.fogColor, fog.color);
  5173. if (fog.isFog) {
  5174. bindUniformValue(uniforms.fogNear, fog.near);
  5175. bindUniformValue(uniforms.fogFar, fog.far);
  5176. } else if (fog.isFogExp2) {
  5177. bindUniformValue(uniforms.fogDensity, fog.density);
  5178. }
  5179. }
  5180. function refreshUniformsLambert(uniforms, material) {
  5181. if (material.emissiveMap) {
  5182. bindUniformValue(uniforms.emissiveMap, material.emissiveMap);
  5183. }
  5184. }
  5185. function refreshUniformsPhong(uniforms, material) {
  5186. bindUniformValue(uniforms.specular, material.specular);
  5187. bindUniformValue(uniforms.shininess, Math.max(material.shininess, 1e-4)); // to prevent pow( 0.0, 0.0 )
  5188. if (material.emissiveMap) {
  5189. bindUniformValue(uniforms.emissiveMap, material.emissiveMap);
  5190. }
  5191. if (material.bumpMap) {
  5192. bindUniformValue(uniforms.bumpMap, material.bumpMap);
  5193. bindUniformValue(uniforms.bumpScale, material.bumpScale);
  5194. }
  5195. if (material.normalMap) {
  5196. bindUniformValue(uniforms.normalMap, material.normalMap);
  5197. bindUniformValue(uniforms.normalScale.value.copy(material.normalScale));
  5198. }
  5199. if (material.displacementMap) {
  5200. bindUniformValue(uniforms.displacementMap, material.displacementMap);
  5201. bindUniformValue(uniforms.displacementScale, material.displacementScale);
  5202. bindUniformValue(uniforms.displacementBias, material.displacementBias);
  5203. }
  5204. }
  5205. function refreshUniformsToon(uniforms, material) {
  5206. refreshUniformsPhong(uniforms, material);
  5207. if (material.gradientMap) {
  5208. bindUniformValue(uniforms.gradientMap, material.gradientMap);
  5209. }
  5210. }
  5211. function refreshUniformsStandard(uniforms, material) {
  5212. bindUniformValue(uniforms.roughness, material.roughness);
  5213. bindUniformValue(uniforms.metalness, material.metalness);
  5214. if (material.roughnessMap) {
  5215. bindUniformValue(uniforms.roughnessMap, material.roughnessMap);
  5216. }
  5217. if (material.metalnessMap) {
  5218. bindUniformValue(uniforms.metalnessMap, material.metalnessMap);
  5219. }
  5220. if (material.emissiveMap) {
  5221. bindUniformValue(uniforms.emissiveMap, material.emissiveMap);
  5222. }
  5223. if (material.bumpMap) {
  5224. bindUniformValue(uniforms.bumpMap, material.bumpMap);
  5225. bindUniformValue(uniforms.bumpScale, material.bumpScale);
  5226. }
  5227. if (material.normalMap) {
  5228. bindUniformValue(uniforms.normalMap, material.normalMap);
  5229. bindUniformValue(uniforms.normalScale.value.copy(material.normalScale));
  5230. }
  5231. if (material.displacementMap) {
  5232. bindUniformValue(uniforms.displacementMap, material.displacementMap);
  5233. bindUniformValue(uniforms.displacementScale, material.displacementScale);
  5234. bindUniformValue(uniforms.displacementBias, material.displacementBias);
  5235. }
  5236. if (material.envMap) {
  5237. //bindUniformValue(uniforms.envMap, material.envMap); // part of bindUniformValue(uniforms common
  5238. bindUniformValue(uniforms.envMapIntensity, material.envMapIntensity);
  5239. }
  5240. }
  5241. function refreshUniformsPhysical(uniforms, material) {
  5242. bindUniformValue(uniforms.clearCoat, material.clearCoat);
  5243. bindUniformValue(uniforms.clearCoatRoughness, material.clearCoatRoughness);
  5244. refreshUniformsStandard(uniforms, material)
  5245. }
  5246. function refreshUniformsNormal(uniforms, material) {
  5247. if (material.bumpMap) {
  5248. bindUniformValue(uniforms.bumpMap, material.bumpMap);
  5249. bindUniformValue(uniforms.bumpScale, material.bumpScale);
  5250. }
  5251. if (material.normalMap) {
  5252. bindUniformValue(uniforms.normalMap, material.normalMap);
  5253. bindUniformValue(uniforms.normalScale.value.copy(material.normalScale));
  5254. }
  5255. if (material.displacementMap) {
  5256. bindUniformValue(uniforms.displacementMap, material.displacementMap);
  5257. bindUniformValue(uniforms.displacementScale, material.displacementScale);
  5258. bindUniformValue(uniforms.displacementBias, material.displacementBias);
  5259. }
  5260. }
  5261. function bindUniformValue(valCesium, val3js) {
  5262. var type = typeof val3js;
  5263. if (type === 'undefined') {
  5264. valCesium.value = undefined;
  5265. return;
  5266. }
  5267. if (val3js === null) {
  5268. valCesium.value = null; return;
  5269. }
  5270. if (typeof valCesium.value !== "undefined"
  5271. && valCesium.value != null
  5272. && (valCesium.value.constructor
  5273. && valCesium.value.constructor.clone
  5274. && val3js.constructor == valCesium.value.constructor)) {
  5275. valCesium.value = valCesium.value.constructor.clone(val3js);
  5276. } else {
  5277. switch (type) {
  5278. case "number":
  5279. case "string":
  5280. valCesium.value = val3js;
  5281. break;
  5282. case "object":
  5283. if (val3js instanceof THREE.Vector2) {
  5284. if (!valCesium.value.constructor.clone) {
  5285. valCesium.value = new Cesium.Cartesian2();
  5286. }
  5287. }
  5288. if (val3js instanceof THREE.Vector3) {
  5289. if (!valCesium.value.constructor.clone) {
  5290. valCesium.value = new Cesium.Cartesian3();
  5291. }
  5292. }
  5293. if (val3js instanceof THREE.Vector4) {
  5294. if (!valCesium.value.constructor.clone) {
  5295. valCesium.value = new Cesium.Cartesian4();
  5296. }
  5297. }
  5298. if (val3js instanceof THREE.Matrix3) {
  5299. if (!valCesium.value.constructor.clone) {
  5300. valCesium.value = new Cesium.Matrix3();
  5301. }
  5302. }
  5303. if (val3js instanceof THREE.Matrix4) {
  5304. if (!valCesium.value.constructor.clone) {
  5305. valCesium.value = new Cesium.Matrix4();
  5306. }
  5307. }
  5308. if (val3js instanceof THREE.Color) {
  5309. if (!valCesium.value.constructor.clone) {
  5310. valCesium.value = new Cesium.Color(val3js.r, val3js.g, val3js.b, val3js.a);
  5311. }
  5312. } else if (valCesium.value != null && valCesium.value.constructor.clone) {
  5313. valCesium.value.constructor.clone(val3js, valCesium.value);
  5314. } else if (val3js instanceof THREE.Texture) {
  5315. if (valCesium.value != val3js.image) {
  5316. valCesium.value = val3js.image;
  5317. var sampler = {};
  5318. sampler.magnificationFilter = Cesium.WebGLConstants.LINEAR;
  5319. sampler.minificationFilter = Cesium.WebGLConstants.NEAREST_MIPMAP_LINEAR;
  5320. sampler.wrapS = Cesium.WebGLConstants.REPEAT;
  5321. sampler.wrapT = Cesium.WebGLConstants.REPEAT;
  5322. valCesium.sampler = sampler;
  5323. valCesium.flipY = val3js.flipY;
  5324. valCesium.needsUpdate = true;
  5325. }
  5326. } else {
  5327. valCesium.value = val3js;
  5328. }
  5329. break;
  5330. default:
  5331. console.log("未知uniform.value类型");
  5332. break;
  5333. }
  5334. }
  5335. }
  5336. return MaterialUtils;
  5337. });
  5338. define('Core/MeshUtils',[
  5339. 'Core/MaterialUtils',
  5340. 'Core/GeometryUtils',
  5341. 'Core/Mesh'
  5342. ], function (
  5343. MaterialUtils,
  5344. GeometryUtils,
  5345. Mesh
  5346. ) {
  5347. /**
  5348. *
  5349. *@constructor
  5350. *@memberof Cesium
  5351. */
  5352. function MeshUtils() {
  5353. }
  5354. /**
  5355. *
  5356. *@param {THREE.Mesh}mesh3js
  5357. *@return {Cesium.Mesh}
  5358. */
  5359. MeshUtils.fromMesh3js = function (mesh3js) {
  5360. if (!MeshUtils.isMesh3js(mesh3js)) {
  5361. return undefined;
  5362. }
  5363. var geometry = mesh3js.geometry;
  5364. if (GeometryUtils.isGeometry3js(geometry)) {
  5365. geometry = GeometryUtils.fromGeometry3js(geometry);
  5366. //if (mesh3js.material.type === "MeshNormalMaterial" || mesh3js.material.type === "MeshPhongMaterial") {
  5367. // GeometryUtils.computeVertexNormals(geometry)
  5368. //}
  5369. }
  5370. var material = mesh3js.material;
  5371. if (MaterialUtils.isMaterial3js(material)) {
  5372. material = MaterialUtils.fromMaterial3js(material);
  5373. }
  5374. var mesh = new Mesh({
  5375. geometry: geometry,
  5376. material: material,
  5377. position: mesh3js.position,
  5378. scale: mesh3js.scale
  5379. });
  5380. mesh.quaternion = mesh3js.quaternion;
  5381. return mesh;
  5382. }
  5383. /**
  5384. *
  5385. *@param {Object}mesh
  5386. *@return {Boolean}
  5387. */
  5388. MeshUtils.isMesh3js = function (mesh) {
  5389. return typeof THREE !== 'undefined' && mesh instanceof THREE.Mesh;
  5390. }
  5391. return MeshUtils;
  5392. });
  5393. define('Core/ShaderUtils',[ ], function (
  5394. ) {
  5395. /**
  5396. *
  5397. *@memberof Cesium
  5398. *@constructor
  5399. */
  5400. function ShaderUtils() {
  5401. }
  5402. /**
  5403. *
  5404. *
  5405. */
  5406. ShaderUtils.processShader3js = function (material3js, shader) {
  5407. var program = new WebGLProgram(material3js, shader);
  5408. return program;
  5409. }
  5410. if (typeof THREE=='undefined') {
  5411. return ShaderUtils;
  5412. }
  5413. var shaderIDs = {
  5414. MeshDepthMaterial: 'depth',
  5415. MeshNormalMaterial: 'normal',
  5416. MeshBasicMaterial: 'basic',
  5417. MeshLambertMaterial: 'lambert',
  5418. MeshPhongMaterial: 'phong',
  5419. MeshToonMaterial: 'phong',
  5420. MeshStandardMaterial: 'physical',
  5421. MeshPhysicalMaterial: 'physical',
  5422. LineBasicMaterial: 'basic',
  5423. LineDashedMaterial: 'dashed',
  5424. PointsMaterial: 'points'
  5425. };
  5426. var parameterNames = [
  5427. "precision", "supportsVertexTextures", "map", "mapEncoding", "envMap", "envMapMode", "envMapEncoding",
  5428. "lightMap", "aoMap", "emissiveMap", "emissiveMapEncoding", "bumpMap", "normalMap", "displacementMap", "specularMap",
  5429. "roughnessMap", "metalnessMap", "gradientMap",
  5430. "alphaMap", "combine", "vertexColors", "fog", "useFog", "fogExp",
  5431. "flatShading", "sizeAttenuation", "logarithmicDepthBuffer", "skinning",
  5432. "maxBones", "useVertexTexture", "morphTargets", "morphNormals",
  5433. "maxMorphTargets", "maxMorphNormals", "premultipliedAlpha",
  5434. "numDirLights", "numPointLights", "numSpotLights", "numHemiLights", "numRectAreaLights",
  5435. "shadowMapEnabled", "shadowMapType", "toneMapping", 'physicallyCorrectLights',
  5436. "alphaTest", "doubleSided", "flipSided", "numClippingPlanes", "numClipIntersection", "depthPacking"
  5437. ];
  5438. var ShaderChunk = THREE.ShaderChunk;
  5439. var ShaderLib = THREE.ShaderLib;
  5440. var BackSide = THREE.BackSide,
  5441. DoubleSide = THREE.DoubleSide,
  5442. FlatShading = THREE.FlatShading,
  5443. CubeUVRefractionMapping = THREE.CubeUVRefractionMapping,
  5444. CubeUVReflectionMapping = THREE.CubeUVReflectionMapping,
  5445. GammaEncoding = THREE.GammaEncoding,
  5446. LinearEncoding = THREE.LinearEncoding,
  5447. NoToneMapping = THREE.NoToneMapping,
  5448. AddOperation = THREE.AddOperation,
  5449. MixOperation = THREE.MixOperation,
  5450. MultiplyOperation = THREE.MultiplyOperation,
  5451. EquirectangularRefractionMapping = THREE.EquirectangularRefractionMapping,
  5452. CubeRefractionMapping = THREE.CubeRefractionMapping,
  5453. SphericalReflectionMapping = THREE.SphericalReflectionMapping,
  5454. EquirectangularReflectionMapping = THREE.EquirectangularReflectionMapping,
  5455. CubeReflectionMapping = THREE.CubeReflectionMapping,
  5456. PCFSoftShadowMap = THREE.PCFSoftShadowMap,
  5457. PCFShadowMap = THREE.PCFShadowMap,
  5458. CineonToneMapping = THREE.CineonToneMapping,
  5459. Uncharted2ToneMapping = THREE.Uncharted2ToneMapping,
  5460. ReinhardToneMapping = THREE.ReinhardToneMapping,
  5461. LinearToneMapping = THREE.LinearToneMapping,
  5462. GammaEncoding = THREE.GammaEncoding,
  5463. RGBDEncoding = THREE.RGBDEncoding,
  5464. RGBM16Encoding = THREE.RGBM16Encoding,
  5465. RGBM7Encoding = THREE.RGBM7Encoding,
  5466. RGBEEncoding = THREE.RGBEEncoding,
  5467. sRGBEncoding = THREE.sRGBEncoding;
  5468. function getTextureEncodingFromMap(map, gammaOverrideLinear) {
  5469. var encoding;
  5470. if (!map) {
  5471. encoding = LinearEncoding;
  5472. } else if (map.isTexture) {
  5473. encoding = map.encoding;
  5474. } else if (map.isWebGLRenderTarget) {
  5475. console.warn("THREE.WebGLPrograms.getTextureEncodingFromMap: don't use render targets as textures. Use their .texture property instead.");
  5476. encoding = map.texture.encoding;
  5477. }
  5478. // add backwards compatibility for WebGLRenderer.gammaInput/gammaOutput parameter, should probably be removed at some point.
  5479. if (encoding === LinearEncoding && gammaOverrideLinear) {
  5480. encoding = GammaEncoding;
  5481. }
  5482. return encoding;
  5483. }
  5484. function getParameters(material) {//, lights, fog, nClipPlanes, nClipIntersection, object) {
  5485. var shaderID = shaderIDs[material.type];
  5486. // heuristics to create shader parameters according to lights in the scene
  5487. // (not to blow over maxLights budget)
  5488. //var maxBones = allocateBones(object);
  5489. //var precision = renderer.getPrecision();
  5490. //if (material.precision !== null) {
  5491. // precision = capabilities.getMaxPrecision(material.precision);
  5492. // if (precision !== material.precision) {
  5493. // console.warn('THREE.WebGLProgram.getParameters:', material.precision, 'not supported, using', precision, 'instead.');
  5494. // }
  5495. //}
  5496. var currentRenderTarget = null;// renderer.getCurrentRenderTarget();
  5497. var renderer = {};
  5498. var parameters = {
  5499. shaderID: shaderID,
  5500. precision: "high",//precision,
  5501. supportsVertexTextures: true,// capabilities.vertexTextures,
  5502. outputEncoding: getTextureEncodingFromMap((!currentRenderTarget) ? null : currentRenderTarget.texture, renderer.gammaOutput),
  5503. map: !!material.map,
  5504. mapEncoding: getTextureEncodingFromMap(material.map, renderer.gammaInput),
  5505. envMap: !!material.envMap,
  5506. envMapMode: material.envMap && material.envMap.mapping,
  5507. envMapEncoding: getTextureEncodingFromMap(material.envMap, renderer.gammaInput),
  5508. envMapCubeUV: (!!material.envMap) && ((material.envMap.mapping === CubeUVReflectionMapping) || (material.envMap.mapping === CubeUVRefractionMapping)),
  5509. lightMap: !!material.lightMap,
  5510. aoMap: !!material.aoMap,
  5511. emissiveMap: !!material.emissiveMap,
  5512. emissiveMapEncoding: getTextureEncodingFromMap(material.emissiveMap, renderer.gammaInput),
  5513. bumpMap: !!material.bumpMap,
  5514. normalMap: !!material.normalMap,
  5515. displacementMap: !!material.displacementMap,
  5516. roughnessMap: !!material.roughnessMap,
  5517. metalnessMap: !!material.metalnessMap,
  5518. specularMap: !!material.specularMap,
  5519. alphaMap: !!material.alphaMap,
  5520. gradientMap: !!material.gradientMap,
  5521. combine: material.combine,
  5522. vertexColors: material.vertexColors,
  5523. fog: false,//!!fog,
  5524. useFog: material.fog,
  5525. fogExp: false,//(fog && fog.isFogExp2),
  5526. flatShading: material.shading === FlatShading,
  5527. sizeAttenuation: material.sizeAttenuation,
  5528. logarithmicDepthBuffer: false,// capabilities.logarithmicDepthBuffer,
  5529. skinning: material.skinning,
  5530. //maxBones: maxBones,
  5531. //useVertexTexture: capabilities.floatVertexTextures && object && object.skeleton && object.skeleton.useVertexTexture,
  5532. morphTargets: material.morphTargets,
  5533. morphNormals: material.morphNormals,
  5534. //maxMorphTargets: renderer.maxMorphTargets,
  5535. //maxMorphNormals: renderer.maxMorphNormals,
  5536. numDirLights: 0,// lights.directional.length,
  5537. numPointLights: 0,// lights.point.length,
  5538. numSpotLights: 0,// lights.spot.length,
  5539. numRectAreaLights: 0,// lights.rectArea.length,
  5540. numHemiLights: 0,// lights.hemi.length,
  5541. numClippingPlanes: 0,//nClipPlanes,
  5542. numClipIntersection: 0,//nClipIntersection,
  5543. //shadowMapEnabled: renderer.shadowMap.enabled && object.receiveShadow && lights.shadows.length > 0,
  5544. //shadowMapType: renderer.shadowMap.type,
  5545. //toneMapping: renderer.toneMapping,
  5546. //physicallyCorrectLights: renderer.physicallyCorrectLights,
  5547. premultipliedAlpha: material.premultipliedAlpha,
  5548. alphaTest: material.alphaTest,
  5549. doubleSided: material.side === DoubleSide,
  5550. flipSided: material.side === BackSide,
  5551. depthPacking: (material.depthPacking !== undefined) ? material.depthPacking : false
  5552. };
  5553. return parameters;
  5554. };
  5555. /**
  5556. * @author mrdoob / http://mrdoob.com/
  5557. */
  5558. var programIdCount = 0;
  5559. function getEncodingComponents(encoding) {
  5560. switch (encoding) {
  5561. case LinearEncoding:
  5562. return ['Linear', '( value )'];
  5563. case sRGBEncoding:
  5564. return ['sRGB', '( value )'];
  5565. case RGBEEncoding:
  5566. return ['RGBE', '( value )'];
  5567. case RGBM7Encoding:
  5568. return ['RGBM', '( value, 7.0 )'];
  5569. case RGBM16Encoding:
  5570. return ['RGBM', '( value, 16.0 )'];
  5571. case RGBDEncoding:
  5572. return ['RGBD', '( value, 256.0 )'];
  5573. case GammaEncoding:
  5574. return ['Gamma', '( value, float( GAMMA_FACTOR ) )'];
  5575. default:
  5576. throw new Error('unsupported encoding: ' + encoding);
  5577. }
  5578. }
  5579. function getTexelDecodingFunction(functionName, encoding) {
  5580. var components = getEncodingComponents(encoding);
  5581. return "vec4 " + functionName + "( vec4 value ) { return " + components[0] + "ToLinear" + components[1] + " ; }";
  5582. }
  5583. function getTexelEncodingFunction(functionName, encoding) {
  5584. var components = getEncodingComponents(encoding);
  5585. return "vec4 " + functionName + "( vec4 value ) { return LinearTo" + components[0] + components[1] + " ; }";
  5586. }
  5587. function getToneMappingFunction(functionName, toneMapping) {
  5588. var toneMappingName;
  5589. switch (toneMapping) {
  5590. case LinearToneMapping:
  5591. toneMappingName = "Linear";
  5592. break;
  5593. case ReinhardToneMapping:
  5594. toneMappingName = "Reinhard";
  5595. break;
  5596. case Uncharted2ToneMapping:
  5597. toneMappingName = "Uncharted2";
  5598. break;
  5599. case CineonToneMapping:
  5600. toneMappingName = "OptimizedCineon";
  5601. break;
  5602. default:
  5603. throw new Error('unsupported toneMapping: ' + toneMapping);
  5604. }
  5605. return "vec3 " + functionName + "( vec3 color ) { return " + toneMappingName + "ToneMapping( color ); }";
  5606. }
  5607. function generateExtensions(extensions, parameters, rendererExtensions) {
  5608. extensions = extensions || {};
  5609. var chunks = [
  5610. (extensions.derivatives || parameters.envMapCubeUV || parameters.bumpMap || parameters.normalMap || parameters.flatShading) ? '#extension GL_OES_standard_derivatives : enable' : '',
  5611. (extensions.fragDepth || parameters.logarithmicDepthBuffer) && rendererExtensions.get('EXT_frag_depth') ? '#extension GL_EXT_frag_depth : enable' : '',
  5612. (extensions.drawBuffers) && rendererExtensions.get('WEBGL_draw_buffers') ? '#extension GL_EXT_draw_buffers : require' : '',
  5613. (extensions.shaderTextureLOD || parameters.envMap) && rendererExtensions.get('EXT_shader_texture_lod') ? '#extension GL_EXT_shader_texture_lod : enable' : ''
  5614. ];
  5615. return chunks.filter(filterEmptyLine).join('\n');
  5616. }
  5617. function generateDefines(defines) {
  5618. var chunks = [];
  5619. for (var name in defines) {
  5620. var value = defines[name];
  5621. if (value === false) continue;
  5622. chunks.push('#define ' + name + ' ' + value);
  5623. }
  5624. return chunks.join('\n');
  5625. }
  5626. function filterEmptyLine(string) {
  5627. return string !== '';
  5628. }
  5629. function replaceLightNums(string, parameters) {
  5630. return string
  5631. .replace(/NUM_DIR_LIGHTS/g, parameters.numDirLights)
  5632. .replace(/NUM_SPOT_LIGHTS/g, parameters.numSpotLights)
  5633. .replace(/NUM_RECT_AREA_LIGHTS/g, parameters.numRectAreaLights)
  5634. .replace(/NUM_POINT_LIGHTS/g, parameters.numPointLights)
  5635. .replace(/NUM_HEMI_LIGHTS/g, parameters.numHemiLights);
  5636. }
  5637. function parseIncludes(string) {
  5638. var pattern = /^[ \t]*#include +<([\w\d.]+)>/gm;
  5639. function replace(match, include) {
  5640. var replace = ShaderChunk[include];
  5641. if (replace === undefined) {
  5642. throw new Error('Can not resolve #include <' + include + '>');
  5643. }
  5644. return parseIncludes(replace);
  5645. }
  5646. return string.replace(pattern, replace);
  5647. }
  5648. function unrollLoops(string) {
  5649. var pattern = /for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
  5650. function replace(match, start, end, snippet) {
  5651. var unroll = '';
  5652. for (var i = parseInt(start) ; i < parseInt(end) ; i++) {
  5653. unroll += snippet.replace(/\[ i \]/g, '[ ' + i + ' ]');
  5654. }
  5655. return unroll;
  5656. }
  5657. return string.replace(pattern, replace);
  5658. }
  5659. function WebGLProgram(material, shader) {//, parameters) {
  5660. var parameters = getParameters(material);
  5661. //var shader = ShaderLib[parameters.shaderID];
  5662. //var extensions = material.extensions;
  5663. var defines = material.defines;
  5664. var vertexShader = shader.vertexShader;
  5665. var fragmentShader = shader.fragmentShader;
  5666. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  5667. if (parameters.shadowMapType === THREE.PCFShadowMap) {
  5668. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  5669. } else if (parameters.shadowMapType === THREE.PCFSoftShadowMap) {
  5670. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  5671. }
  5672. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  5673. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  5674. var envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  5675. if (parameters.envMap) {
  5676. switch (material.envMap.mapping) {
  5677. case CubeReflectionMapping:
  5678. case CubeRefractionMapping:
  5679. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  5680. break;
  5681. case CubeUVReflectionMapping:
  5682. case CubeUVRefractionMapping:
  5683. envMapTypeDefine = 'ENVMAP_TYPE_CUBE_UV';
  5684. break;
  5685. case EquirectangularReflectionMapping:
  5686. case EquirectangularRefractionMapping:
  5687. envMapTypeDefine = 'ENVMAP_TYPE_EQUIREC';
  5688. break;
  5689. case SphericalReflectionMapping:
  5690. envMapTypeDefine = 'ENVMAP_TYPE_SPHERE';
  5691. break;
  5692. }
  5693. switch (material.envMap.mapping) {
  5694. case CubeRefractionMapping:
  5695. case EquirectangularRefractionMapping:
  5696. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  5697. break;
  5698. }
  5699. switch (material.combine) {
  5700. case MultiplyOperation:
  5701. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  5702. break;
  5703. case MixOperation:
  5704. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  5705. break;
  5706. case AddOperation:
  5707. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  5708. break;
  5709. }
  5710. }
  5711. var gammaFactorDefine = 1.0;// (renderer.gammaFactor > 0) ? renderer.gammaFactor : 1.0;
  5712. // var customExtensions = generateExtensions(extensions, parameters, renderer.extensions);
  5713. var customDefines = generateDefines(defines);
  5714. var prefixVertex, prefixFragment;
  5715. if (material.isRawShaderMaterial) {
  5716. prefixVertex = [
  5717. customDefines,
  5718. '\n'
  5719. ].filter(filterEmptyLine).join('\n');
  5720. prefixFragment = [
  5721. //customExtensions,
  5722. customDefines,
  5723. '\n'
  5724. ].filter(filterEmptyLine).join('\n');
  5725. } else {
  5726. prefixVertex = [
  5727. //'precision ' + parameters.precision + ' float;',
  5728. //'precision ' + parameters.precision + ' int;',
  5729. '#define SHADER_NAME ' + shader.name,
  5730. //customDefines,
  5731. parameters.supportsVertexTextures ? '#define VERTEX_TEXTURES' : '',
  5732. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  5733. '#define MAX_BONES ' + parameters.maxBones,
  5734. //(parameters.useFog && parameters.fog) ? '#define USE_FOG' : '',
  5735. //(parameters.useFog && parameters.fogExp) ? '#define FOG_EXP2' : '',
  5736. parameters.map ? '#define USE_MAP' : '',
  5737. parameters.envMap ? '#define USE_ENVMAP' : '',
  5738. parameters.envMap ? '#define ' + envMapModeDefine : '',
  5739. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  5740. parameters.aoMap ? '#define USE_AOMAP' : '',
  5741. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  5742. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  5743. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  5744. parameters.displacementMap && parameters.supportsVertexTextures ? '#define USE_DISPLACEMENTMAP' : '',
  5745. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  5746. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  5747. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  5748. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  5749. parameters.vertexColors ? '#define USE_COLOR' : '',
  5750. parameters.flatShading ? '#define FLAT_SHADED' : '',
  5751. parameters.skinning ? '#define USE_SKINNING' : '',
  5752. parameters.useVertexTexture ? '#define BONE_TEXTURE' : '',
  5753. parameters.morphTargets ? '#define USE_MORPHTARGETS' : '',
  5754. parameters.morphNormals && parameters.flatShading === false ? '#define USE_MORPHNORMALS' : '',
  5755. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  5756. parameters.flipSided ? '#define FLIP_SIDED' : '',
  5757. '#define NUM_CLIPPING_PLANES ' + parameters.numClippingPlanes,
  5758. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  5759. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  5760. parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '',
  5761. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  5762. //parameters.logarithmicDepthBuffer && renderer.extensions.get('EXT_frag_depth') ? '#define USE_LOGDEPTHBUF_EXT' : '',
  5763. //'uniform mat4 modelMatrix;',
  5764. //'uniform mat4 modelViewMatrix;',
  5765. //'uniform mat4 projectionMatrix;',
  5766. //'uniform mat4 viewMatrix;',
  5767. //'uniform mat3 normalMatrix;',
  5768. //'uniform vec3 cameraPosition;',
  5769. //'attribute vec3 position;',
  5770. //'attribute vec3 normal;',
  5771. //'attribute vec2 uv;',
  5772. '#ifdef USE_COLOR',
  5773. ' attribute vec3 color;',
  5774. '#endif',
  5775. '#ifdef USE_MORPHTARGETS',
  5776. ' attribute vec3 morphTarget0;',
  5777. ' attribute vec3 morphTarget1;',
  5778. ' attribute vec3 morphTarget2;',
  5779. ' attribute vec3 morphTarget3;',
  5780. ' #ifdef USE_MORPHNORMALS',
  5781. ' attribute vec3 morphNormal0;',
  5782. ' attribute vec3 morphNormal1;',
  5783. ' attribute vec3 morphNormal2;',
  5784. ' attribute vec3 morphNormal3;',
  5785. ' #else',
  5786. ' attribute vec3 morphTarget4;',
  5787. ' attribute vec3 morphTarget5;',
  5788. ' attribute vec3 morphTarget6;',
  5789. ' attribute vec3 morphTarget7;',
  5790. ' #endif',
  5791. '#endif',
  5792. '#ifdef USE_SKINNING',
  5793. ' attribute vec4 skinIndex;',
  5794. ' attribute vec4 skinWeight;',
  5795. '#endif',
  5796. '\n'
  5797. ].filter(filterEmptyLine).join('\n');
  5798. prefixFragment = [
  5799. //customExtensions,
  5800. //'precision ' + parameters.precision + ' float;',
  5801. //'precision ' + parameters.precision + ' int;',
  5802. '#define SHADER_NAME ' + shader.name,
  5803. customDefines,
  5804. parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest : '',
  5805. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  5806. (parameters.useFog && parameters.fog) ? '#define USE_FOG' : '',
  5807. (parameters.useFog && parameters.fogExp) ? '#define FOG_EXP2' : '',
  5808. parameters.map ? '#define USE_MAP' : '',
  5809. parameters.envMap ? '#define USE_ENVMAP' : '',
  5810. parameters.envMap ? '#define ' + envMapTypeDefine : '',
  5811. parameters.envMap ? '#define ' + envMapModeDefine : '',
  5812. parameters.envMap ? '#define ' + envMapBlendingDefine : '',
  5813. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  5814. parameters.aoMap ? '#define USE_AOMAP' : '',
  5815. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  5816. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  5817. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  5818. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  5819. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  5820. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  5821. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  5822. parameters.vertexColors ? '#define USE_COLOR' : '',
  5823. parameters.gradientMap ? '#define USE_GRADIENTMAP' : '',
  5824. parameters.flatShading ? '#define FLAT_SHADED' : '',
  5825. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  5826. parameters.flipSided ? '#define FLIP_SIDED' : '',
  5827. '#define NUM_CLIPPING_PLANES ' + parameters.numClippingPlanes,
  5828. '#define UNION_CLIPPING_PLANES ' + (parameters.numClippingPlanes - parameters.numClipIntersection),
  5829. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  5830. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  5831. parameters.premultipliedAlpha ? "#define PREMULTIPLIED_ALPHA" : '',
  5832. parameters.physicallyCorrectLights ? "#define PHYSICALLY_CORRECT_LIGHTS" : '',
  5833. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  5834. //parameters.logarithmicDepthBuffer && renderer.extensions.get('EXT_frag_depth') ? '#define USE_LOGDEPTHBUF_EXT' : '',
  5835. //parameters.envMap && renderer.extensions.get('EXT_shader_texture_lod') ? '#define TEXTURE_LOD_EXT' : '',
  5836. 'uniform mat4 viewMatrix;',
  5837. 'uniform vec3 cameraPosition;',
  5838. //(parameters.toneMapping !== THREE.NoToneMapping) ? "#define TONE_MAPPING" : '',
  5839. //(parameters.toneMapping !== THREE.NoToneMapping) ? ShaderChunk['tonemapping_pars_fragment'] : '', // this code is required here because it is used by the toneMapping() function defined below
  5840. //(parameters.toneMapping !== THREE.NoToneMapping) ? getToneMappingFunction("toneMapping", parameters.toneMapping) : '',
  5841. parameters.dithering ? '#define DITHERING' : '',
  5842. (parameters.outputEncoding || parameters.mapEncoding || parameters.envMapEncoding || parameters.emissiveMapEncoding) ? ShaderChunk['encodings_pars_fragment'] : '', // this code is required here because it is used by the various encoding/decoding function defined below
  5843. parameters.mapEncoding ? getTexelDecodingFunction('mapTexelToLinear', parameters.mapEncoding) : '',
  5844. parameters.envMapEncoding ? getTexelDecodingFunction('envMapTexelToLinear', parameters.envMapEncoding) : '',
  5845. parameters.emissiveMapEncoding ? getTexelDecodingFunction('emissiveMapTexelToLinear', parameters.emissiveMapEncoding) : '',
  5846. parameters.outputEncoding ? getTexelEncodingFunction("linearToOutputTexel", parameters.outputEncoding) : '',
  5847. parameters.depthPacking ? "#define DEPTH_PACKING " + material.depthPacking : '',
  5848. '\n'
  5849. ].filter(filterEmptyLine).join('\n');
  5850. }
  5851. vertexShader = parseIncludes(vertexShader);
  5852. vertexShader = replaceLightNums(vertexShader, parameters);
  5853. fragmentShader = parseIncludes(fragmentShader);
  5854. fragmentShader = replaceLightNums(fragmentShader, parameters);
  5855. if (!material.isShaderMaterial) {
  5856. vertexShader = unrollLoops(vertexShader);
  5857. fragmentShader = unrollLoops(fragmentShader);
  5858. }
  5859. var vertexGlsl = prefixVertex + vertexShader;
  5860. var fragmentGlsl = prefixFragment + fragmentShader;
  5861. this.id = programIdCount++;
  5862. this.usedTimes = 1;
  5863. this.vertexShader = vertexGlsl;
  5864. this.fragmentShader = fragmentGlsl;
  5865. return this;
  5866. }
  5867. return ShaderUtils;
  5868. });
  5869. define('Core/MeshVisualizer',[
  5870. 'Core/Mesh',
  5871. 'Core/RendererUtils',
  5872. 'Core/MeshMaterial',
  5873. 'Core/Shaders/ShaderChunk',
  5874. 'Core/Rotation',
  5875. 'Core/FramebufferTexture',
  5876. 'Core/LOD',
  5877. 'Core/ReferenceMesh',
  5878. 'ThirdParty/tiff-js/tiff',
  5879. 'Util/Path',
  5880. 'Core/GeometryUtils',
  5881. 'Core/MaterialUtils',
  5882. 'Core/MeshUtils',
  5883. 'Core/ShaderUtils'
  5884. ], function (
  5885. Mesh,
  5886. RendererUtils,
  5887. MeshMaterial,
  5888. ShaderChunk,
  5889. Rotation,
  5890. FramebufferTexture,
  5891. LOD,
  5892. ReferenceMesh,
  5893. TIFFParser,
  5894. Path,
  5895. GeometryUtils,
  5896. MaterialUtils,
  5897. MeshUtils,
  5898. ShaderUtils
  5899. ) {
  5900. var Matrix4 = Cesium.Matrix4;
  5901. var DrawCommand = Cesium.DrawCommand;
  5902. var defined = Cesium.defined;
  5903. var GeometryPipeline = Cesium.GeometryPipeline;
  5904. var BufferUsage = Cesium.BufferUsage;
  5905. var BlendingState = Cesium.BlendingState;
  5906. var VertexArray = Cesium.VertexArray;
  5907. var ShaderProgram = Cesium.ShaderProgram;
  5908. var DepthFunction = Cesium.DepthFunction;
  5909. var CullFace = Cesium.CullFace;
  5910. var RenderState = Cesium.RenderState;
  5911. var defaultValue = Cesium.defaultValue;
  5912. var Texture = Cesium.Texture;
  5913. var PixelFormat = Cesium.PixelFormat;
  5914. var BoxGeometry = Cesium.BoxGeometry;
  5915. var Cartesian3 = Cesium.Cartesian3;
  5916. var VertexFormat = Cesium.VertexFormat;
  5917. var CubeMap = Cesium.CubeMap;
  5918. var loadCubeMap = Cesium.loadCubeMap;
  5919. var Matrix3 = Cesium.Matrix3;
  5920. var CesiumMath = Cesium.Math;
  5921. var Color = Cesium.Color;
  5922. var scratchTranslation = new Cartesian3();
  5923. var scratchQuaternion = new Cesium.Quaternion();
  5924. var scratchScale = new Cartesian3();
  5925. var scratchTranslationQuaternionRotationScale = new Matrix4();
  5926. var computeModelMatrix = new Matrix4();
  5927. var scratchPosition = new Cartesian3();
  5928. var scratchTraverseArgs = {
  5929. cancelCurrent: false //停止遍历当前节点的所有子节点
  5930. };
  5931. Cesium.Cartesian3.prototype.set = function (x, y, z) {
  5932. this.x = x; this.y = y; this.z = z;
  5933. }
  5934. Cesium.Cartesian3.prototype.copy = function (src) {
  5935. this.x = src.x; this.y = src.y; this.z = src.z;
  5936. }
  5937. Cesium.Cartesian2.prototype.set = function (x, y) {
  5938. this.x = x; this.y = y;
  5939. }
  5940. Cesium.Cartesian2.prototype.copy = function (src) {
  5941. this.x = src.x; this.y = src.y;
  5942. }
  5943. Cesium.Quaternion.prototype.set = function (x, y, z, w) {
  5944. this.x = x; this.y = y; this.z = z; this.w = w;
  5945. }
  5946. Cesium.Quaternion.prototype.copy = function (src) {
  5947. this.x = src.x; this.y = src.y; this.z = src.z; this.w = src.w;
  5948. }
  5949. /**
  5950. *
  5951. *
  5952. *@param {Object}options
  5953. *@param {Cesium.Matrix4}[options.modelMatrix=Cesium.Matrix4.IDENTITY]
  5954. *@param {Cesium.Cartesian3}[options.up=Cesium.Cartesian3.UNIT_Z]
  5955. *@param {Cesium.Cartesian3}[options.position=Cesium.Cartesian3.ZERO]
  5956. *@param {Cesium.Cartesian3}[options.scale=new Cartesian3(1, 1, 1)]
  5957. *@param {Cesium.Rotation}[options.rotation]
  5958. *@param {Boolean}[options.show=true]
  5959. *@param {Boolean}[options.showReference=true]
  5960. *@param {Cesium.ArrowGeometry}[options.referenceAxisParameter]
  5961. *
  5962. *@property {Cesium.Matrix4}modelMatrix
  5963. *@property {Cesium.Cartesian3}up
  5964. *@property {Cesium.Cartesian3}position
  5965. *@property {Cesium.Cartesian3}scale
  5966. *@property {Cesium.Rotation}rotation
  5967. *@property {Boolean}show
  5968. *@property {Boolean}showReference
  5969. *@property {Boolean}modelMatrixNeedsUpdate
  5970. *@property {Cesium.Event}beforeUpdate
  5971. *
  5972. *@constructor
  5973. *@memberof Cesium
  5974. *@extends Cesium.Primitive
  5975. *
  5976. *@example
  5977. MeshVisualizer = Cesium.MeshVisualizer;
  5978. Mesh = Cesium.Mesh;
  5979. MeshMaterial = Cesium.MeshMaterial;
  5980. FramebufferTexture = Cesium.FramebufferTexture;
  5981. var center = Cesium.Cartesian3.fromDegrees(homePosition[0], homePosition[1], 50000);
  5982. var modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(center);
  5983. var meshVisualizer = new MeshVisualizer({
  5984. modelMatrix: modelMatrix,
  5985. });
  5986. viewer.scene.primitives.add(meshVisualizer);
  5987. //示例1:Cesium.Geometry+Cesium.MeshMaterial组合
  5988. var box = Cesium.BoxGeometry.createGeometry(Cesium.BoxGeometry.fromDimensions({
  5989. dimensions: new Cesium.Cartesian3(100000, 50000, 50000),
  5990. vertexFormat: Cesium.VertexFormat.POSITION_ONLY
  5991. }));
  5992. var material = new MeshMaterial({
  5993. defaultColor: "rgba(255,0,0,1.0)",
  5994. wireframe: false,
  5995. side: MeshMaterial.Sides.DOUBLE
  5996. });
  5997. var boxMesh = new Mesh(box, material);
  5998. meshVisualizer.add(boxMesh);
  5999. //示例2:Cesium.CSG+Cesium.MeshMaterial组合,可以用Cesium.CSG做布尔运算并渲染运算结果
  6000. //首先使用Cesium创建球体
  6001. var sphere = new Cesium.SphereGeometry({
  6002. radius: 50000.0,
  6003. vertexFormat: Cesium.VertexFormat.POSITION_ONLY
  6004. });
  6005. sphere = Cesium.SphereGeometry.createGeometry(sphere);
  6006. var sphereMesh = new Mesh(sphere, material);
  6007. sphereMesh.position = new Cesium.Cartesian3(100000, 0, 0)
  6008. meshVisualizer.add(sphereMesh);
  6009. //将球体对象Cesium.SphereGeometry转成Cesium.CSG实例
  6010. sphere = CSG.toCSG(sphere);
  6011. //将盒子对象转成Cesium.CSG实例
  6012. box = CSG.toCSG(box);
  6013. //做布尔运算
  6014. var subResult = sphere.subtract(box);
  6015. //渲染运算结果
  6016. var subResultMesh = new Mesh(subResult, material);
  6017. subResultMesh.position = new Cesium.Cartesian3(700000, 0, 0)
  6018. meshVisualizer.add(subResultMesh);
  6019. //示例3:使用帧缓存作纹理,实际应用中如体绘制,风场流场绘制等等都可以运用此技术
  6020. function createGeometry() {
  6021. var p1 = new Cesium.Cartesian3(-50000, 50000, 100);
  6022. var p2 = new Cesium.Cartesian3(-50000, -50000, 100);
  6023. var p3 = new Cesium.Cartesian3(50000, -50000, 100);
  6024. var p4 = new Cesium.Cartesian3(50000, 50000, 100);
  6025. var positions = new Float64Array([
  6026. p1.x, p1.y, p1.z,
  6027. p2.x, p2.y, p2.z,
  6028. p3.x, p3.y, p3.z,
  6029. p4.x, p4.y, p4.z
  6030. ]);
  6031. var indices = new Uint16Array([
  6032. 0, 1, 3,
  6033. 1, 2, 3,
  6034. ]);
  6035. var sts = new Float32Array([
  6036. 1, 1,
  6037. 1, 0,
  6038. 0, 0,
  6039. 0, 1
  6040. ]);
  6041. var geometry = new Cesium.Geometry({
  6042. attributes: {
  6043. position: new Cesium.GeometryAttribute({
  6044. componentDatatype: Cesium.ComponentDatatype.DOUBLE,
  6045. componentsPerAttribute: 3,
  6046. values: positions
  6047. }),
  6048. st: new Cesium.GeometryAttribute({
  6049. componentDatatype: Cesium.ComponentDatatype.FLOAT,
  6050. componentsPerAttribute: 2,
  6051. values: sts
  6052. })
  6053. },
  6054. indices: indices,
  6055. primitiveType: Cesium.PrimitiveType.TRIANGLES,
  6056. boundingSphere: Cesium.BoundingSphere.fromVertices(positions)
  6057. });
  6058. return geometry;
  6059. }
  6060. //将上文中的盒子渲染到缓存,作为纹理参与createGeometry()方法创建的几何体渲染过程
  6061. var framebufferTex = new FramebufferTexture(boxMesh);
  6062. var geometry = createGeometry();
  6063. var customMesh = new Mesh(geometry, new MeshMaterial({
  6064. uniforms: {
  6065. u_textureMap: framebufferTex//Cesium.buildModuleUrl('Widgets/Images/TerrainProviders/STK.png')
  6066. },
  6067. side: MeshMaterial.Sides.DOUBLE,
  6068. vertexShader : "\n\
  6069. \n\
  6070. varying vec3 v_position;\n\
  6071. varying vec2 v_st;\n\
  6072. \n\
  6073. void main(void) \n\
  6074. {\n\
  6075. vec4 pos = u_modelViewMatrix * vec4(position,1.0);\n\
  6076. v_position = pos.xyz;\n\
  6077. v_st=st;\n\
  6078. gl_Position = u_projectionMatrix * pos;\n\
  6079. }",
  6080. fragmentShader : "varying vec2 v_st;\
  6081. uniform sampler2D u_textureMap;\
  6082. void main()\
  6083. {\
  6084. gl_FragColor = texture2D(u_textureMap,v_st);\n\
  6085. \
  6086. }\
  6087. "
  6088. }));
  6089. customMesh.position = new Cesium.Cartesian3(100000, 0, 0);
  6090. meshVisualizer.add(customMesh);
  6091. */
  6092. function MeshVisualizer(options) {
  6093. this._modelMatrix = defaultValue(options.modelMatrix, Matrix4.IDENTITY);
  6094. this._actualModelMatrix = Matrix4.clone(this._modelMatrix);
  6095. this._ready = true;
  6096. this._modelMatrixNeedsUpdate = true;
  6097. this._isWireframe = false;
  6098. this._up = defaultValue(options.up, new Cartesian3(0, 0, 1));
  6099. this._position = defaultValue(options.position, new Cartesian3(0, 0, 0));
  6100. this._scale = defaultValue(options.scale, new Cartesian3(1, 1, 1));
  6101. this._rotation = defaultValue(options.rotation, { axis: new Cartesian3(0, 0, 1), angle: 0 });
  6102. this._rotation = new Rotation(this._rotation.axis, this._rotation.angle);
  6103. this._rotation.paramChanged.addEventListener(this.onModelMatrixNeedUpdate, this);
  6104. this._chidren = [];
  6105. this._debug = false;
  6106. this._show = defaultValue(options.show, true);
  6107. this._center = new Cartesian3();
  6108. Cesium.Matrix4.getTranslation(this._modelMatrix, this._center);
  6109. this._framebufferTextures = {};
  6110. this._uniformValueCache = {};
  6111. this._textureCache = {};
  6112. this._uniformMaps = {};
  6113. this.referenceMesh = new ReferenceMesh({
  6114. axisParameter: defaultValue(options.referenceAxisParameter, { length: 50000 * 2 }),
  6115. show: defaultValue(options.showReference, false)
  6116. });
  6117. this.add(this.referenceMesh);
  6118. this._pickIds = [];
  6119. this.beforeUpdate = new Cesium.Event();
  6120. this._scene = options.scene;
  6121. }
  6122. var world2localMatrix = new Cesium.Matrix4();
  6123. var surfacePointLocal = new Cesium.Cartesian3();
  6124. var rayDir = new Cesium.Cartesian3();
  6125. var pos = new Cesium.Cartesian3();
  6126. var rayOriginLocal = new Cesium.Cartesian3();
  6127. var scratchRay = new Cesium.Ray();
  6128. MeshVisualizer.prototype = {
  6129. /**
  6130. *@param {Cesium.Mesh}mesh
  6131. */
  6132. remove: function (mesh) {
  6133. for (var i = 0; i < this._chidren.length; i++) {
  6134. if (this._chidren[i] == mesh) {
  6135. this._chidren.splice(i, 1);
  6136. }
  6137. }
  6138. MeshVisualizer.traverse(mesh, function () {
  6139. if (mesh._drawCommand) {
  6140. mesh._drawCommand.destroy && mesh._drawCommand.destroy();
  6141. }
  6142. if (mesh._actualMesh && mesh._actualMesh._drawCommand) {
  6143. Cesium.destroyObject(mesh._actualMesh._drawCommand);
  6144. Cesium.destroyObject(mesh._actualMesh.geometry);
  6145. Cesium.destroyObject(mesh._actualMesh);
  6146. Cesium.destroyObject(mesh);
  6147. }
  6148. }, false);
  6149. },
  6150. /**
  6151. *
  6152. *拾取点,用局部坐标系表达。内部使用Cesium.Scene.pickPosition和MeshVisualizer.worldCoordinatesToLocal实现。
  6153. *@param {Cesium.Cartesian2}windowPosition
  6154. *@param {Cesium.Ray}result
  6155. *@return {Cesium.Cartesian3}
  6156. */
  6157. pickPosition: function (windowPosition, result) {
  6158. if (!this._scene) {
  6159. return undefined;
  6160. }
  6161. this._scene.pickPosition(windowPosition, surfacePointLocal);
  6162. if (!surfacePointLocal) {
  6163. return undefined;
  6164. }
  6165. this.worldCoordinatesToLocal(surfacePointLocal, surfacePointLocal);
  6166. Cesium.Cartesian3.clone(surfacePointLocal, result);
  6167. return result;
  6168. },
  6169. /**
  6170. *
  6171. *创建一条射线,用局部坐标系表达
  6172. *@param {Cesium.Cartesian2}windowPosition
  6173. *@param {Cesium.Ray}result
  6174. *@return {Cesium.Ray}
  6175. */
  6176. getPickRay: function (windowPosition, result) {
  6177. if (!this._scene) {
  6178. return undefined;
  6179. }
  6180. if (!result) {
  6181. result = Cesium.Ray();
  6182. }
  6183. this._scene.camera.getPickRay(windowPosition, scratchRay);//ray用于计算小球发射点位置,这里射线的起始点是世界坐标,不能像Threejs那样直接拿来计算,需要转成局部坐标
  6184. this._scene.pickPosition(windowPosition, surfacePointLocal);//射线和局部场景的交点
  6185. if (!surfacePointLocal) {
  6186. return undefined;
  6187. }
  6188. Cesium.Cartesian3.clone(scratchRay.direction, rayDir);
  6189. //世界坐标转局部坐标
  6190. this.worldCoordinatesToLocal(scratchRay.origin, rayOriginLocal);
  6191. this.worldCoordinatesToLocal(surfacePointLocal, surfacePointLocal);
  6192. Cesium.Cartesian3.add(rayOriginLocal, rayDir, pos);
  6193. //计算发射方向
  6194. Cesium.Cartesian3.subtract(surfacePointLocal, pos, rayDir);
  6195. Cesium.Cartesian3.clone(surfacePointLocal, result.origin);
  6196. Cesium.Cartesian3.clone(rayDir, result.direction);
  6197. return result;
  6198. },
  6199. /**
  6200. *世界坐标到局部坐标
  6201. *@param {Cesium.Cartesian3}worldCoordinates
  6202. *@param {Cesium.Cartesian3}result
  6203. *@return {Cesium.Cartesian3}
  6204. */
  6205. worldCoordinatesToLocal: function (worldCoordinates, result) {
  6206. if (!result) {
  6207. result = new Cartesian3();
  6208. }
  6209. Cesium.Matrix4.inverseTransformation(this._actualModelMatrix, world2localMatrix)
  6210. Cesium.Matrix4.multiplyByPoint(world2localMatrix, worldCoordinates, result);
  6211. return result;
  6212. },
  6213. /**
  6214. *局部坐标到世界坐标
  6215. *@param {Cesium.Cartesian3}localCoordinates
  6216. *@param {Cesium.Cartesian3}result
  6217. *@return {Cesium.Cartesian3}
  6218. */
  6219. localToWorldCoordinates: function (localCoordinates, result) {
  6220. if (!result) {
  6221. result = new Cartesian3();
  6222. }
  6223. Cesium.Matrix4.multiplyByPoint(this._actualModelMatrix, localCoordinates, result);
  6224. return result;
  6225. },
  6226. onModelMatrixNeedUpdate: function () {
  6227. this._modelMatrixNeedsUpdate = true;
  6228. },
  6229. /**
  6230. *
  6231. *@param {Number}x
  6232. *@param {Number}y
  6233. *@param {Number}z
  6234. */
  6235. setPosition: function (x, y, z) {
  6236. var changed = false;
  6237. if (arguments.length == 1) {
  6238. if (typeof x == 'number') {
  6239. if (x != this._position.x) changed = true;
  6240. this._position.x = x;
  6241. } else if (x instanceof Cesium.Cartesian3) {
  6242. if (x != this._position.x
  6243. || y != this._position.y
  6244. || z != this._position.z) {
  6245. changed = true;
  6246. }
  6247. this._position.x = x.x;
  6248. this._position.y = x.y;
  6249. this._position.z = x.z;
  6250. }
  6251. }
  6252. if (arguments.length == 2 && typeof y == 'number') {
  6253. if (y != this._position.y) changed = true;
  6254. this._position.y = y;
  6255. }
  6256. if (arguments.length == 3 && typeof z == 'number') {
  6257. if (z != this._position.z) changed = true;
  6258. this._position.z = z;
  6259. }
  6260. if (changed) {
  6261. this._modelMatrixNeedsUpdate = true;
  6262. }
  6263. },
  6264. /**
  6265. *
  6266. *@param {Number}x
  6267. *@param {Number}y
  6268. *@param {Number}z
  6269. */
  6270. setScale: function (x, y, z) {
  6271. var changed = false;
  6272. if (arguments.length == 1) {
  6273. if (typeof x == 'number') {
  6274. if (x != this._scale.x) changed = true;
  6275. this._scale.x = x;
  6276. } else if (x instanceof Cesium.Cartesian3) {
  6277. if (x != this._scale.x
  6278. || y != this._scale.y
  6279. || z != this._scale.z) {
  6280. changed = true;
  6281. }
  6282. this._scale.x = x.x;
  6283. this._scale.y = x.y;
  6284. this._scale.z = x.z;
  6285. }
  6286. }
  6287. if (arguments.length == 2 && typeof y == 'number') {
  6288. if (y != this._scale.y) changed = true;
  6289. this._scale.y = y;
  6290. }
  6291. if (arguments.length == 3 && typeof z == 'number') {
  6292. if (z != this._scale.z) changed = true;
  6293. this._scale.z = z;
  6294. }
  6295. if (changed) {
  6296. this._modelMatrixNeedsUpdate = true;
  6297. }
  6298. },
  6299. toWireframe: function (geometry) {
  6300. if (geometry.primitiveType !== Cesium.PrimitiveType.TRIANGLES
  6301. && geometry.primitiveType !== Cesium.PrimitiveType.TRIANGLE_FAN
  6302. && geometry.primitiveType !== Cesium.PrimitiveType.TRIANGLE_STRIP) {
  6303. return geometry;
  6304. }
  6305. if (!geometry.triangleIndices) {
  6306. geometry.triangleIndices = geometry.indices;
  6307. }
  6308. //if (geometry.lineIndices) {
  6309. // geometry.indices = geometry.lineIndices;
  6310. // return geometry;
  6311. //}
  6312. geometry = GeometryPipeline.toWireframe(geometry);
  6313. //geometry.lineIndices = geometry.indices;
  6314. return geometry;
  6315. },
  6316. restoreFromWireframe: function (geometry) {
  6317. if (geometry.triangleIndices) {
  6318. geometry.indices = geometry.triangleIndices;
  6319. }
  6320. geometry.primitiveType = Cesium.PrimitiveType.TRIANGLES;
  6321. return geometry;
  6322. },
  6323. /**
  6324. *
  6325. *@param {Cesium.Mesh} mesh
  6326. *@param {Cesium.FrameState} frameState
  6327. *@return {Cesium.DrawCommand}
  6328. *@private
  6329. */
  6330. createDrawCommand: function (mesh, frameState) {
  6331. var that = this;
  6332. var context = frameState.context;
  6333. var geometry = mesh.geometry;
  6334. var material = mesh.material;
  6335. var command = new Cesium.DrawCommand({
  6336. modelMatrix: Matrix4.clone(this.modelMatrix),
  6337. owner: mesh,
  6338. primitiveType: geometry.primitiveType,
  6339. cull: material.cullFrustum,
  6340. pass: material.translucent ? Cesium.Pass.TRANSLUCENT : Cesium.Pass.OPAQUE
  6341. //,boundingVolume: geometry.boundingSphere
  6342. });
  6343. var attributeLocations = GeometryPipeline.createAttributeLocations(geometry);
  6344. command.vertexArray = VertexArray.fromGeometry({
  6345. context: context,
  6346. geometry: geometry,
  6347. attributeLocations: attributeLocations,
  6348. bufferUsage: BufferUsage.STATIC_DRAW
  6349. });
  6350. command.vertexArray._attributeLocations = attributeLocations;
  6351. var pickObject = {
  6352. primitive: this,
  6353. id: mesh
  6354. };
  6355. var pickId = context.createPickId(pickObject);
  6356. that._pickIds.push(pickId);
  6357. var pickColor = pickId.color;
  6358. var shader = {
  6359. fragmentShader: this.getFragmentShaderSource(material),
  6360. vertexShader: this.getVertexShaderSource(geometry, material)
  6361. };
  6362. if (material.material3js) {
  6363. shader = ShaderUtils.processShader3js(material.material3js, shader);
  6364. }
  6365. command._sp = ShaderProgram.fromCache({
  6366. context: context,
  6367. fragmentShaderSource: shader.fragmentShader,//this.getFragmentShaderSource(material),
  6368. vertexShaderSource: shader.vertexShader,//this.getVertexShaderSource(geometry, material),
  6369. attributeLocations: attributeLocations
  6370. });
  6371. if (!Cesium.defined(mesh.material.allowPick)) {
  6372. mesh.material.allowPick = true;
  6373. }
  6374. if (mesh.material.allowPick) {
  6375. command._pickSp = ShaderProgram.fromCache({
  6376. context: context,
  6377. fragmentShaderSource: 'void main() {\n\tgl_FragColor = vec4(' + pickColor.red + ',' + pickColor.green + ',' + pickColor.blue + ',' + pickColor.alpha + ');\n}',
  6378. vertexShaderSource: shader.vertexShader,
  6379. attributeLocations: attributeLocations
  6380. });
  6381. }
  6382. command.shaderProgram = command._sp;
  6383. command.renderState = this.getRenderState(material);
  6384. command.uniformMap = this.getUniformMap(material, frameState);
  6385. return command;
  6386. },
  6387. /**
  6388. *
  6389. *
  6390. *@param {THREE.Material}material
  6391. *@return {Cesium.RenderState}frameState
  6392. *@private
  6393. */
  6394. getRenderState: function (material) {
  6395. var renderState = {
  6396. blending: material.blending ? BlendingState.ALPHA_BLEND : BlendingState.DISABLED,
  6397. depthTest: {
  6398. enabled: material.depthTest,
  6399. func: DepthFunction.LESS
  6400. },
  6401. cull: {
  6402. enabled: true,
  6403. face: CullFace.FRONT
  6404. },
  6405. depthRange: {
  6406. near: 0,
  6407. far: 1
  6408. },
  6409. colorMask: {
  6410. red: true,
  6411. green: true,
  6412. blue: true,
  6413. alpha: true
  6414. },
  6415. depthMask: material.depthMask
  6416. }
  6417. renderState.cull.enabled = true;
  6418. renderState.blending.color = {
  6419. red: 0.0,
  6420. green: 0.0,
  6421. blue: 0.0,
  6422. alpha: 0.0
  6423. };
  6424. switch (material.side) {
  6425. case MeshMaterial.Sides.FRONT:
  6426. renderState.cull.face = CullFace.BACK;
  6427. break;
  6428. case MeshMaterial.Sides.BACK:
  6429. renderState.cull.face = CullFace.FRONT;
  6430. break;
  6431. default:
  6432. renderState.cull.enabled = false;
  6433. break;
  6434. }
  6435. renderState = RenderState.fromCache(renderState);
  6436. return renderState;
  6437. },
  6438. /**
  6439. *
  6440. *
  6441. *@param {THREE.Material}material
  6442. *@param {Cesium.FrameState}frameState
  6443. *@private
  6444. */
  6445. getUniformMap: function (material, frameState) {
  6446. if (this._uniformMaps[material.uuid] && !material.needsUpdate) {
  6447. return this._uniformMaps[material.uuid];
  6448. }
  6449. var uniformMap = {};
  6450. this._uniformMaps[material.uuid] = uniformMap;
  6451. material.needsUpdate = false;
  6452. uniformMap.cameraPosition = function () {
  6453. return frameState.camera.position;
  6454. }
  6455. uniformMap.u_cameraPosition = function () {
  6456. return frameState.camera.position;
  6457. }
  6458. //base matrix
  6459. uniformMap.u_normalMatrix = function () {
  6460. return frameState.context.uniformState.normal;
  6461. }
  6462. uniformMap.u_projectionMatrix = function () {
  6463. return frameState.context.uniformState.projection;
  6464. }
  6465. uniformMap.u_modelViewMatrix = function () {
  6466. return frameState.context.uniformState.modelView;
  6467. }
  6468. //base matrix for threejs
  6469. uniformMap.normalMatrix = function () {
  6470. return frameState.context.uniformState.normal;
  6471. }
  6472. uniformMap.projectionMatrix = function () {
  6473. return frameState.context.uniformState.projection;
  6474. }
  6475. uniformMap.modelViewMatrix = function () {
  6476. return frameState.context.uniformState.modelView;
  6477. }
  6478. uniformMap.modelMatrix = function () {
  6479. return frameState.context.uniformState.model;
  6480. }
  6481. uniformMap.u_modelMatrix = function () {
  6482. return frameState.context.uniformState.model;
  6483. }
  6484. uniformMap.u_viewMatrix = function () {
  6485. return frameState.context.uniformState.view;
  6486. }
  6487. uniformMap.viewMatrix = function () {
  6488. return frameState.context.uniformState.view;
  6489. }
  6490. uniformMap.logDepthBufFC = function () {
  6491. return 2.0 / (Math.log(frameState.camera.frustum.far + 1.0) / Math.LN2)
  6492. }
  6493. if (material.uniformStateUsed && material.uniformStateUsed.length) {
  6494. material.uniformStateUsed.forEach(function (item) {
  6495. if (!uniformMap[item.glslVarName]) {
  6496. if (!frameState.context.uniformState[item.uniformStateName]) {
  6497. throw new Error(item.uniformStateName + "不是Cesium引擎的内置对象");
  6498. }
  6499. uniformMap[item.glslVarName] = function () {
  6500. return frameState.context.uniformState[item.uniformStateName];
  6501. }
  6502. }
  6503. });
  6504. }
  6505. var that = this;
  6506. function getCubeTextureCallback(name, item, mtl) {
  6507. var callback = function () {
  6508. if (!that._textureCache[item.uuid] || item.needsUpdate) {
  6509. if (!callback.allLoaded && !callback.isLoading) {
  6510. var promises = [];
  6511. for (var i = 0; i < item.value.length; i++) {
  6512. if (item.value[i] instanceof HTMLCanvasElement
  6513. || item.value[i] instanceof HTMLVideoElement
  6514. || item.value[i] instanceof HTMLImageElement
  6515. ) {
  6516. var deferred = Cesium.when.defer();
  6517. requestAnimationFrame(function () {
  6518. deferred.resolve(item.value[i]);
  6519. });
  6520. promises.push(deferred);
  6521. } else if (typeof item.value[i] === 'string') {
  6522. promises.push(Cesium.loadImage(item.value[i]));
  6523. } else {
  6524. throw Error(name + "" + i + "给定值“ " + item[i] + "” 不是有效的纹理图片");
  6525. }
  6526. }
  6527. callback.isLoading = true;
  6528. item.needsUpdate = false;
  6529. Cesium.when.all(promises, function (images) {
  6530. that._textureCache[item.uuid] = new Cesium.CubeMap({
  6531. context: frameState.context,
  6532. source: {
  6533. positiveX: images[0],
  6534. negativeX: images[1],
  6535. positiveY: images[2],
  6536. negativeY: images[3],
  6537. positiveZ: images[4],
  6538. negativeZ: images[5]
  6539. }
  6540. });
  6541. callback.allLoaded = true;
  6542. callback.isLoading = false;
  6543. });
  6544. }
  6545. }
  6546. if (callback.allLoaded) {
  6547. return that._textureCache[item.uuid];
  6548. }
  6549. else {
  6550. if (!that.defaultCubeMap) {
  6551. if (!that.defaultTextureImage) {
  6552. that.defaultTextureImage = document.createElement("canvas");
  6553. that.defaultTextureImage.width = 1;
  6554. that.defaultTextureImage.height = 1;
  6555. }
  6556. that.defaultCubeMap = new Cesium.CubeMap({
  6557. context: frameState.context,
  6558. source: {
  6559. positiveX: that.defaultTextureImage,
  6560. negativeX: that.defaultTextureImage,
  6561. positiveY: that.defaultTextureImage,
  6562. negativeY: that.defaultTextureImage,
  6563. positiveZ: that.defaultTextureImage,
  6564. negativeZ: that.defaultTextureImage
  6565. }
  6566. });
  6567. }
  6568. return that.defaultCubeMap;
  6569. }
  6570. }
  6571. if (callback.allLoaded) {
  6572. callback.allLoaded = false;
  6573. callback.isLoading = false;
  6574. }
  6575. return callback;
  6576. }
  6577. function createTexture(texture, context) {
  6578. var TextureMinificationFilter = Cesium.TextureMinificationFilter;
  6579. var TextureWrap = Cesium.TextureWrap;
  6580. var sampler = texture.sampler;
  6581. var mipmap =
  6582. (sampler.minificationFilter === TextureMinificationFilter.NEAREST_MIPMAP_NEAREST) ||
  6583. (sampler.minificationFilter === TextureMinificationFilter.NEAREST_MIPMAP_LINEAR) ||
  6584. (sampler.minificationFilter === TextureMinificationFilter.LINEAR_MIPMAP_NEAREST) ||
  6585. (sampler.minificationFilter === TextureMinificationFilter.LINEAR_MIPMAP_LINEAR);
  6586. var requiresNpot = mipmap ||
  6587. (sampler.wrapS === TextureWrap.REPEAT) ||
  6588. (sampler.wrapS === TextureWrap.MIRRORED_REPEAT) ||
  6589. (sampler.wrapT === TextureWrap.REPEAT) ||
  6590. (sampler.wrapT === TextureWrap.MIRRORED_REPEAT);
  6591. var source = texture.source;
  6592. var npot = !CesiumMath.isPowerOfTwo(source.width) || !CesiumMath.isPowerOfTwo(source.height);
  6593. if (requiresNpot && npot) {
  6594. // WebGL requires power-of-two texture dimensions for mipmapping and REPEAT/MIRRORED_REPEAT wrap modes.
  6595. var canvas = document.createElement('canvas');
  6596. canvas.width = CesiumMath.nextPowerOfTwo(source.width);
  6597. canvas.height = CesiumMath.nextPowerOfTwo(source.height);
  6598. var canvasContext = canvas.getContext('2d');
  6599. canvasContext.drawImage(source, 0, 0, source.width, source.height, 0, 0, canvas.width, canvas.height);
  6600. source = canvas;
  6601. }
  6602. var tx;
  6603. if (texture.target === WebGLConstants.TEXTURE_2D) {
  6604. tx = new Texture({
  6605. context: context,
  6606. source: source,
  6607. width: texture.width,
  6608. height: texture.height,
  6609. pixelFormat: texture.internalFormat,
  6610. pixelDatatype: texture.type,
  6611. sampler: sampler,
  6612. flipY: texture.flipY
  6613. });
  6614. }
  6615. // GLTF_SPEC: Support TEXTURE_CUBE_MAP. https://github.com/KhronosGroup/glTF/issues/40
  6616. if (mipmap) {
  6617. tx.generateMipmap();
  6618. }
  6619. return tx;
  6620. }
  6621. var WebGLConstants = Cesium.WebGLConstants;
  6622. function onTextureImageLoaded(image, item) {
  6623. var tex;
  6624. if (defined(image.internalFormat)) {
  6625. tex = new Texture({
  6626. context: frameState.context,
  6627. pixelFormat: image.internalFormat,
  6628. width: image.width,
  6629. height: image.height,
  6630. source: {
  6631. arrayBufferView: image.bufferView
  6632. },
  6633. flipY: item.flipY
  6634. });
  6635. } else {
  6636. var format = Cesium.WebGLConstants.RGB;
  6637. if (image instanceof HTMLCanvasElement
  6638. || image instanceof HTMLVideoElement
  6639. || (image.src && image.src.toLocaleLowerCase().indexOf(".png") >= 0)
  6640. ) {
  6641. format = Cesium.WebGLConstants.RGBA;
  6642. }
  6643. if (item.sampler) {
  6644. tex = createTexture({
  6645. context: frameState.context,
  6646. source: image,
  6647. target: WebGLConstants.TEXTURE_2D,
  6648. width: item.width,
  6649. height: item.height,
  6650. pixelFormat: format,
  6651. flipY: item.flipY,
  6652. sampler: new Cesium.Sampler(item.sampler)
  6653. }, frameState.context);
  6654. } else {
  6655. tex = new Texture({
  6656. context: frameState.context,
  6657. source: image,
  6658. target: WebGLConstants.TEXTURE_2D,
  6659. width: item.width,
  6660. height: item.height,
  6661. pixelFormat: format,
  6662. flipY: Cesium.defined(item.flipY) ? item.flipY : true
  6663. });
  6664. }
  6665. }
  6666. return tex;
  6667. }
  6668. function getTextureCallback(item) {
  6669. var callback = function () {
  6670. if (!that._textureCache[item.value] || item.needsUpdate) {
  6671. if (item.value instanceof HTMLImageElement
  6672. || item.value instanceof HTMLCanvasElement
  6673. || item.value instanceof HTMLVideoElement
  6674. ) {
  6675. var image = item.value;
  6676. that._textureCache[item.value] = onTextureImageLoaded(image, item);
  6677. item.needsUpdate = false;
  6678. return that._textureCache[item.value];
  6679. } else {
  6680. if (typeof item.value === "string" && !callback.isLoading) {
  6681. callback.isLoading = true;
  6682. item.needsUpdate = false;
  6683. var url = item.value.toLocaleLowerCase();
  6684. var extension = Path.GetExtension(url).slice(1);
  6685. if (extension == 'tif') {//处理tif纹理
  6686. Cesium.Resource.fetchArrayBuffer({ url: url }).then(function (imageArrayBuffer) {
  6687. var tiffParser = new TIFFParser();
  6688. var tiffCanvas = tiffParser.parseTIFF(imageArrayBuffer);
  6689. if (that._textureCache[item.value]) {
  6690. that._textureCache[item.value].destroy && that._textureCache[item.value].destroy();
  6691. }
  6692. that._textureCache[item.value] = onTextureImageLoaded(tiffCanvas, item);
  6693. callback.isLoading = false;
  6694. }).otherwise(function (err) {
  6695. console.log(err);
  6696. })
  6697. } else {
  6698. Cesium.Resource.fetchImage({ url: item.value }).then(function (image) {
  6699. if (that._textureCache[item.value]) {
  6700. that._textureCache[item.value].destroy && that._textureCache[item.value].destroy();
  6701. }
  6702. that._textureCache[item.value] = onTextureImageLoaded(image, item);
  6703. callback.isLoading = false;
  6704. }).otherwise(function (err) {
  6705. console.log(err);
  6706. })
  6707. }
  6708. }
  6709. if (!that.defaultTextureImage) {
  6710. that.defaultTextureImage = document.createElement("canvas");
  6711. that.defaultTextureImage.width = 1;
  6712. that.defaultTextureImage.height = 1;
  6713. }
  6714. if (!that.defaultTexture) {
  6715. that.defaultTexture = new Texture({
  6716. context: frameState.context,
  6717. source: that.defaultTextureImage
  6718. });
  6719. }
  6720. return that.defaultTexture;
  6721. }
  6722. } else {
  6723. return that._textureCache[item.value];
  6724. }
  6725. }
  6726. return callback;
  6727. }
  6728. if (material.uniforms) {
  6729. function setUniformCallbackFunc(name, item) {
  6730. if (item !== undefined && item !== null) {//item may be 0
  6731. var isImageUrl = typeof item.value === "string";
  6732. var isCssColorString = typeof item.value === "string";
  6733. if (typeof item.value === "string") {
  6734. var itemLowerCase = item.value.toLocaleLowerCase();
  6735. if (itemLowerCase.endsWith(".png")
  6736. || itemLowerCase.endsWith(".jpg")
  6737. || itemLowerCase.endsWith(".bmp")
  6738. || itemLowerCase.endsWith(".gif")
  6739. || itemLowerCase.endsWith(".tif")
  6740. || itemLowerCase.endsWith(".tiff")
  6741. || itemLowerCase.startsWith("data:")
  6742. ) {
  6743. isImageUrl = true;
  6744. isCssColorString = false;
  6745. } else {
  6746. try {
  6747. Cesium.Color.fromCssColorString(item.value);
  6748. isImageUrl = true;
  6749. isCssColorString = false;
  6750. } catch (e) {
  6751. isImageUrl = false;
  6752. isCssColorString = false;
  6753. }
  6754. }
  6755. }
  6756. if (item.value instanceof Cesium.Cartesian2
  6757. || item.value instanceof Cesium.Cartesian3
  6758. || item.value instanceof Cesium.Cartesian4
  6759. || item.value instanceof Cesium.Color
  6760. || item.value instanceof Cesium.Matrix4
  6761. || item.value instanceof Cesium.Matrix3
  6762. || item.value instanceof Cesium.Matrix2
  6763. || item.value instanceof Cesium.Texture
  6764. || typeof item.value === "number"
  6765. || isCssColorString
  6766. || item.value instanceof Cesium.Texture
  6767. || (item.value instanceof Array && (typeof item.value[0] === 'number'
  6768. || item.value[0] instanceof Cesium.Cartesian2
  6769. || item.value[0] instanceof Cesium.Cartesian3
  6770. || item.value[0] instanceof Cesium.Cartesian4))
  6771. ) {
  6772. if (!that._uniformValueCache) {
  6773. that._uniformValueCache = {};
  6774. }
  6775. that._uniformValueCache[item.uuid] = item;
  6776. if (isCssColorString) {
  6777. item.value = Cesium.Color.fromCssColorString(item.value);
  6778. }
  6779. uniformMap[name] = function () {
  6780. return that._uniformValueCache[item.uuid].value;
  6781. }
  6782. } else if (item.value instanceof Array && item.value.length == 6) {
  6783. uniformMap[name] = getCubeTextureCallback(name, item);
  6784. } else if (isImageUrl
  6785. || item.value instanceof HTMLImageElement
  6786. || item.value instanceof HTMLCanvasElement
  6787. || item.value instanceof HTMLVideoElement
  6788. ) {
  6789. uniformMap[name] = getTextureCallback(item, material);
  6790. } else if (item.value instanceof FramebufferTexture) {
  6791. if (!that._renderToTextureCommands) {
  6792. that._renderToTextureCommands = [];
  6793. }
  6794. if (!that._framebufferTextures[item.uuid]) {
  6795. that._framebufferTextures[item.uuid] = item;
  6796. }
  6797. uniformMap[name] = function () {
  6798. if (!that._framebufferTextures[item.uuid]
  6799. || !that._framebufferTextures[item.uuid].value.texture) {
  6800. return frameState.context.defaultTexture;
  6801. }
  6802. return that._framebufferTextures[item.uuid].value.texture;
  6803. }
  6804. }
  6805. }
  6806. }
  6807. var uniforms = material.uniforms;
  6808. for (var name in uniforms) {
  6809. if (uniforms.hasOwnProperty(name) && Cesium.defined(uniforms[name].value) && uniforms[name].value != null) {
  6810. if (Array.isArray(uniforms[name].value) && uniforms[name].value.length == 0) {
  6811. continue;
  6812. }
  6813. var item = uniforms[name];
  6814. if (item == undefined || item == null) {
  6815. continue;
  6816. }
  6817. setUniformCallbackFunc(name, item);
  6818. }
  6819. }
  6820. }
  6821. return this._uniformMaps[material.uuid];
  6822. },
  6823. /**
  6824. *
  6825. *@param {Cesium.Geometry} geometry
  6826. *@param {Cesium.Material} material
  6827. *@return {String}
  6828. *@private
  6829. */
  6830. getVertexShaderSource: function (geometry, material) {
  6831. function getAttributeDefineBlok(userDefine) {
  6832. var glsl = "";
  6833. var attrs = geometry.attributes;
  6834. for (var name in attrs) {
  6835. if (attrs.hasOwnProperty(name)) {
  6836. var attr = attrs[name]
  6837. if (attr) {
  6838. var type = null;
  6839. switch (attr.componentsPerAttribute) {
  6840. case 1:
  6841. type = "float";
  6842. break;
  6843. case 2:
  6844. type = "vec2";
  6845. break;
  6846. case 3:
  6847. type = "vec3";
  6848. break;
  6849. case 4:
  6850. type = "vec4";
  6851. break;
  6852. default:
  6853. }
  6854. if (type) {
  6855. if (userDefine.indexOf("attribute " + type + " " + name) >= 0) {
  6856. continue;
  6857. }
  6858. glsl += "attribute " + type + " " + name + ";\n";
  6859. }
  6860. }
  6861. }
  6862. }
  6863. return glsl;
  6864. }
  6865. var uniforms = "\n\
  6866. uniform mat4 modelViewMatrix;\n\
  6867. uniform mat4 viewMatrix;\n\
  6868. uniform mat4 modelMatrix;\n\
  6869. uniform mat4 projectionMatrix;\n\
  6870. uniform mat3 normalMatrix;\n\
  6871. uniform mat4 u_modelViewMatrix;\n\
  6872. uniform mat4 u_viewMatrix;\n\
  6873. uniform mat4 u_modelMatrix;\n\
  6874. uniform mat4 u_projectionMatrix;\n\
  6875. uniform mat3 u_normalMatrix;\n\
  6876. uniform vec3 cameraPosition;\n\
  6877. uniform vec3 u_cameraPosition;\n";
  6878. var innerUniforms = [
  6879. "uniform mat4 modelViewMatrix",
  6880. "uniform mat4 modelMatrix",
  6881. "uniform mat4 projectionMatrix",
  6882. "uniform mat3 normalMatrix",
  6883. "uniform mat4 u_modelViewMatrix",
  6884. "uniform mat4 u_modelMatrix",
  6885. "uniform mat4 u_projectionMatrix",
  6886. "uniform mat3 u_normalMatrix",
  6887. "uniform mat4 u_viewMatrix",
  6888. "uniform mat4 viewMatrix",
  6889. "uniform vec3 cameraPosition",
  6890. "uniform vec3 u_cameraPosition"
  6891. ];
  6892. if (material.vertexShader) {
  6893. uniforms = "";
  6894. innerUniforms.forEach(function (item) {
  6895. if (material.vertexShader.indexOf(item) < 0) {
  6896. uniforms += item + ";\n";
  6897. }
  6898. });
  6899. var vs = getAttributeDefineBlok(material.vertexShader) + uniforms +
  6900. material.vertexShader;
  6901. vs = ShaderChunk.parseIncludes(vs);
  6902. return vs;
  6903. }
  6904. else {
  6905. throw new Error("material.vertexShader 是必须参数");
  6906. }
  6907. },
  6908. /**
  6909. *
  6910. *@param {Cesium.Material} material
  6911. *@return {String}
  6912. *@private
  6913. */
  6914. getFragmentShaderSource: function (material) {
  6915. if (material.fragmentShader) {
  6916. var fs = ShaderChunk.parseIncludes(material.fragmentShader);
  6917. return fs;
  6918. } else {
  6919. throw new Error("material.fragmentShader 是必须参数");
  6920. }
  6921. }
  6922. }
  6923. MeshVisualizer.prototype._computeModelMatrix = function (mesh, frameState) {
  6924. if (mesh._actualMesh) {
  6925. mesh = mesh._actualMesh;
  6926. }
  6927. var that = this;
  6928. if (mesh instanceof LOD || mesh instanceof ReferenceMesh || typeof mesh.update === 'function') {
  6929. if (mesh.parent) {
  6930. if (mesh.parent == that) {
  6931. mesh.update(that._actualModelMatrix, frameState);
  6932. } else if (mesh.parent.modelMatrix) {
  6933. mesh.update(mesh.parent.modelMatrix, frameState);
  6934. } else {
  6935. mesh.update(that._actualModelMatrix, frameState);
  6936. }
  6937. } else {
  6938. mesh.update(that._actualModelMatrix, frameState);
  6939. }
  6940. } else {
  6941. var position = mesh.position;
  6942. if (mesh.parent instanceof LOD) {
  6943. Matrix4.clone(mesh.parent.modelMatrix, mesh.modelMatrix);
  6944. } else if (mesh._modelMatrixNeedsUpdate) {
  6945. var rotation = mesh.quaternion ? mesh.quaternion : mesh.rotation;
  6946. if (mesh.parent && mesh.parent.modelMatrix) {
  6947. var actualModelMatrix = mesh.parent.modelMatrix ? mesh.parent.modelMatrix : mesh._drawCommand.modelMatrix;
  6948. RendererUtils.computeModelMatrix(
  6949. actualModelMatrix,
  6950. mesh.position,
  6951. rotation,
  6952. mesh.scale,
  6953. mesh.modelMatrix
  6954. );
  6955. } else {
  6956. RendererUtils.computeModelMatrix(
  6957. that._actualModelMatrix,
  6958. mesh.position,
  6959. rotation,
  6960. mesh.scale,
  6961. mesh.modelMatrix
  6962. );
  6963. }
  6964. mesh._modelMatrixNeedsUpdate = false;
  6965. }
  6966. }
  6967. }
  6968. /**
  6969. *
  6970. *@param {Cesium.FrameState}frameState
  6971. */
  6972. MeshVisualizer.prototype.update = function (frameState) {
  6973. if (!this._scene) {
  6974. this._scene = frameState.camera._scene;
  6975. }
  6976. if (!this._ready || !this.show && this._chidren.length > 0) {//如果未准备好则不加入渲染队列
  6977. return;
  6978. }
  6979. this.beforeUpdate.raiseEvent(frameState);
  6980. var that = this;
  6981. var wireframeChanged = false;
  6982. var sysWireframe = frameState.camera._scene._globe._surface.tileProvider._debug.wireframe;
  6983. if (this.debug) {
  6984. sysWireframe = true;
  6985. }
  6986. if (sysWireframe != this._isWireframe) {
  6987. wireframeChanged = true;
  6988. }
  6989. if (this._modelMatrixNeedsUpdate) {
  6990. this._actualModelMatrix = RendererUtils.computeModelMatrix(
  6991. this._modelMatrix,
  6992. this._position,
  6993. this._rotation,
  6994. this._scale,
  6995. this._actualModelMatrix
  6996. );
  6997. if (this._up && this._up.y) {
  6998. this._actualModelMatrix = RendererUtils.yUp2Zup(this._actualModelMatrix, this._actualModelMatrix);
  6999. }
  7000. Cesium.Cartesian3.clone(this._scale, this._oldScale);
  7001. Cesium.Cartesian3.clone(this._position, this._oldPosition);
  7002. this._modelMatrixNeedsUpdate = false;
  7003. }
  7004. MeshVisualizer.traverse(this, function (mesh) {
  7005. if (MeshUtils.isMesh3js(mesh)) {
  7006. var needsUpdate = !mesh._actualMesh
  7007. || mesh.needsUpdate
  7008. || mesh.geometry.needsUpdate;
  7009. if (needsUpdate) {
  7010. mesh._actualMesh = MeshUtils.fromMesh3js(mesh);
  7011. mesh.modelMatrixNeedsUpdate = true;
  7012. }
  7013. if (!needsUpdate) {
  7014. for (var pn in mesh.geometry.attributes) {
  7015. if (mesh.geometry.attributes.hasOwnProperty(pn)) {
  7016. mesh._actualMesh.geometry.attributes[pn].needsUpdate = mesh.geometry.attributes[pn].needsUpdate;
  7017. }
  7018. }
  7019. var index = mesh.geometry.index;
  7020. if (index && index.needsUpdate) {
  7021. mesh._actualMesh.geometry.needsUpdate = true;
  7022. }
  7023. }
  7024. mesh._actualMesh.quaternion = Cesium.Quaternion.clone(mesh.quaternion);
  7025. mesh._actualMesh.position = mesh.position;
  7026. mesh._actualMesh.scale = mesh.scale;
  7027. mesh._actualMesh.modelMatrixNeedsUpdate = mesh.modelMatrixNeedsUpdate;
  7028. mesh = mesh._actualMesh;
  7029. MaterialUtils.updateMaterialFrom3js(mesh.material);
  7030. }
  7031. that._computeModelMatrix(mesh, frameState);
  7032. if (typeof mesh.update !== 'function') {
  7033. if (frameState.passes.pick && !mesh.material.allowPick) {
  7034. return;
  7035. }
  7036. if (!mesh._drawCommand
  7037. || mesh.needsUpdate
  7038. || mesh.geometry.needsUpdate
  7039. || wireframeChanged
  7040. ) {//重新构建绘图命令,比如geometry完全不同于之前一帧 或者顶点和索引数量都发生改变等时,执行这段
  7041. if (sysWireframe || mesh.material.wireframe) {
  7042. that.toWireframe(mesh.geometry);
  7043. } else {
  7044. that.restoreFromWireframe(mesh.geometry);
  7045. }
  7046. mesh._drawCommand = that.createDrawCommand(mesh, frameState);
  7047. mesh.needsUpdate = false;
  7048. mesh.geometry.needsUpdate = false;
  7049. } else {//在不需要重新构建绘图命令时,检查各个属性和索引是否需要更新,需要则将更新相应的缓冲区
  7050. //更新属性缓冲区
  7051. for (var name in mesh.geometry.attributes) {
  7052. if (mesh.geometry.attributes.hasOwnProperty(name)) {
  7053. if (mesh.geometry.attributes[name] && mesh.geometry.attributes[name].needsUpdate) {
  7054. var attrLocation = mesh._drawCommand.vertexArray._attributeLocations[name]
  7055. var vb = mesh._drawCommand.vertexArray._attributes[attrLocation].vertexBuffer;
  7056. vb.copyFromArrayView(mesh.geometry.attributes[name].values, 0);
  7057. }
  7058. }
  7059. }
  7060. //更新索引缓冲区
  7061. if (mesh.geometry.indexNeedsUpdate) {
  7062. var vb = mesh._drawCommand.vertexArray.indexBuffer;
  7063. vb.copyFromArrayView(mesh.geometry.indices, 0);
  7064. }
  7065. }
  7066. mesh._drawCommand.modelMatrix = mesh.modelMatrix;
  7067. if (!mesh._drawCommand.boundingVolume) {
  7068. if (!mesh.geometry.boundingSphere) {
  7069. mesh.geometry.boundingSphere = Cesium.BoundingSphere.fromVertices(mesh.geometry.attributes.position.values);
  7070. }
  7071. mesh._drawCommand.boundingVolume = Cesium.BoundingSphere.clone(mesh.geometry.boundingSphere);
  7072. }
  7073. Cesium.Matrix4.getTranslation(mesh.modelMatrix, mesh._drawCommand.boundingVolume.center);
  7074. mesh._drawCommand.uniformMap = that.getUniformMap(mesh.material, frameState);
  7075. if (frameState.passes.pick) {
  7076. mesh._drawCommand.shaderProgram = mesh._drawCommand._pickSp;
  7077. frameState.commandList.push(mesh._drawCommand);
  7078. } else {
  7079. mesh._drawCommand.renderState.depthTest.enabled = mesh.material.depthTest;
  7080. mesh._drawCommand.shaderProgram = mesh._drawCommand._sp;
  7081. frameState.commandList.push(mesh._drawCommand);
  7082. }
  7083. } else {
  7084. mesh.needsUpdate = false;
  7085. }
  7086. }, true);
  7087. //执行帧缓冲绘图命令
  7088. for (var i in that._framebufferTextures) {
  7089. if (that._framebufferTextures.hasOwnProperty(i)) {
  7090. var item = that._framebufferTextures[i].value;
  7091. that.updateFrameBufferTexture(frameState, item);
  7092. }
  7093. }
  7094. this._isWireframe = sysWireframe;
  7095. wireframeChanged = false;
  7096. this._modelMatrixNeedsUpdate = false;
  7097. this._geometryChanged = false;
  7098. }
  7099. /**
  7100. *单独渲染frameBufferTexture中的mesh,最终更新frameBufferTexture中的texture
  7101. *@param {Cesium.FrameState}frameState
  7102. *@param {Cesium.FramebufferTexture}frameBufferTexture
  7103. */
  7104. MeshVisualizer.prototype.updateFrameBufferTexture = function (frameState, frameBufferTexture,viewport) {
  7105. var that = this;
  7106. var item = frameBufferTexture;
  7107. if (item instanceof FramebufferTexture) {
  7108. item.drawCommands = [];
  7109. MeshVisualizer.traverse(item.mesh, function (mesh) {
  7110. if (MeshUtils.isMesh3js(mesh)) {
  7111. var needsUpdate = !mesh._actualMesh
  7112. || mesh.needsUpdate
  7113. || mesh.geometry.needsUpdate;
  7114. if (needsUpdate) {
  7115. mesh._actualMesh = MeshUtils.fromMesh3js(mesh);
  7116. }
  7117. if (!needsUpdate) {
  7118. for (var pn in mesh.geometry.attributes) {
  7119. if (mesh.geometry.attributes.hasOwnProperty(pn)) {
  7120. mesh._actualMesh.geometry[pn].needsUpdate = mesh.geometry.attributes[pn].needsUpdate;
  7121. }
  7122. }
  7123. var index = mesh.geometry.getIndex();
  7124. if (index && index.needsUpdate) {
  7125. mesh._actualMesh.geometry.needsUpdate = true;
  7126. }
  7127. }
  7128. mesh._actualMesh.quaternion = Cesium.Quaternion.clone(mesh.quaternion);
  7129. mesh._actualMesh.position = mesh.position;
  7130. mesh._actualMesh.scale = mesh.scale;
  7131. mesh._actualMesh.modelMatrixNeedsUpdate = mesh.modelMatrixNeedsUpdate;
  7132. mesh = mesh._actualMesh;
  7133. MaterialUtils.updateMaterialFrom3js(mesh.material);
  7134. }
  7135. that._computeModelMatrix(mesh, frameState);
  7136. if (!mesh._textureCommand
  7137. || mesh.needsUpdate
  7138. || mesh.geometry.needsUpdate
  7139. ) {
  7140. if (mesh.material.wireframe) {
  7141. that.toWireframe(mesh.geometry);
  7142. } else {
  7143. that.restoreFromWireframe(mesh.geometry);
  7144. }
  7145. mesh._textureCommand = that.createDrawCommand(mesh, frameState);
  7146. //mesh._textureCommand.boundingVolume = mesh.geometry.boundingSphere;
  7147. mesh.needsUpdate = false;
  7148. mesh.material.needsUpdate = false;
  7149. } else {//在不需要重新构建绘图命令时,检查各个属性和索引是否需要更新,需要则将更新相应的缓冲区
  7150. //更新属性缓冲区
  7151. for (var name in mesh.geometry.attributes) {
  7152. if (mesh.geometry.attributes.hasOwnProperty(name)
  7153. && mesh.geometry.attributes[name]) {
  7154. if (mesh.geometry.attributes[name] && mesh.geometry.attributes[name].needsUpdate) {
  7155. var attrLocation = mesh._textureCommand.vertexArray._attributeLocations[name]
  7156. var vb = mesh._textureCommand.vertexArray._attributes[attrLocation].vertexBuffer;
  7157. vb.copyFromArrayView(mesh.geometry.attributes[name].values, 0);
  7158. }
  7159. }
  7160. }
  7161. //更新索引缓冲区
  7162. if (mesh.geometry.indexNeedsUpdate) {
  7163. var vb = mesh._textureCommand.vertexArray.indexBuffer;
  7164. vb.copyFromArrayView(mesh.geometry.indices, 0);
  7165. }
  7166. }
  7167. mesh._textureCommand.modelMatrix = mesh.modelMatrix;
  7168. var context = frameState.context;
  7169. var drawingBufferWidth = context.drawingBufferWidth;
  7170. var drawingBufferHeight = context.drawingBufferHeight;
  7171. if (!item.texture
  7172. || item.texture.width != drawingBufferWidth
  7173. || item.texture.height != drawingBufferHeight
  7174. ) {
  7175. var notFullScreen = item._notFullScreen || Cesium.defined(item.texture);
  7176. if (!notFullScreen) {
  7177. item.texture = new Texture({
  7178. context: context,
  7179. width: drawingBufferWidth,
  7180. height: drawingBufferHeight,
  7181. pixelFormat: PixelFormat.RGBA
  7182. });
  7183. }
  7184. item._notFullScreen = notFullScreen;
  7185. }
  7186. mesh._textureCommand.renderState.depthTest.enabled = mesh.depthTest;
  7187. if (viewport) {
  7188. mesh._textureCommand.renderState.viewport = viewport;
  7189. }
  7190. item.drawCommands.push(mesh._textureCommand);
  7191. }, true);
  7192. RendererUtils.renderToTexture(item.drawCommands, frameState, item.texture);
  7193. }
  7194. }
  7195. /**
  7196. *
  7197. *@param {Cesium.Mesh}mesh
  7198. */
  7199. MeshVisualizer.prototype.add = function (mesh) {
  7200. this._chidren.push(mesh);
  7201. }
  7202. /**
  7203. *
  7204. */
  7205. MeshVisualizer.prototype.destroy = function () {
  7206. this._ready = false;
  7207. MeshVisualizer.traverse(this, function (mesh) {
  7208. if (mesh._drawCommand) {
  7209. delete mesh._drawCommand;
  7210. }
  7211. }, false);
  7212. for (var i in this._uniformValueCache) {
  7213. if (this._uniformValueCache.hasOwnProperty(i)) {
  7214. delete this._uniformValueCache[i];
  7215. }
  7216. }
  7217. for (var i in this._textureCache) {
  7218. if (this._textureCache.hasOwnProperty(i)) {
  7219. delete this._textureCache[i];
  7220. }
  7221. }
  7222. for (var i in this._uniformMaps) {
  7223. if (this._uniformMaps.hasOwnProperty(i)) {
  7224. delete this._uniformMaps[i];
  7225. }
  7226. }
  7227. for (var i in this._framebufferTextures) {
  7228. if (this._framebufferTextures.hasOwnProperty(i)) {
  7229. delete this._framebufferTextures[i];
  7230. }
  7231. }
  7232. this._uniformValueCache = {};
  7233. this._textureCache = {};
  7234. this._uniformMaps = {};
  7235. this._framebufferTextures = {};
  7236. if (this._pickIds) {
  7237. for (i = 0; i < this._pickIds.length; ++i) {
  7238. this._pickIds[i].destroy && this._pickIds[i].destroy();
  7239. }
  7240. }
  7241. }
  7242. /**
  7243. *
  7244. *遍历节点
  7245. *@param {Cesium.MeshVisualizer|Cesium.Mesh}root
  7246. *@param {Cesium.MeshVisualizer~TraverseCallback}traverseFunc 访问每个节点时回调该函数,进行相关操作。回调函数包含一个参数,traverseArgs,其中封装了一个属性cancelCurrent,可以通过改变此属性达到终止遍历当前节点的子节点
  7247. *@param {Boolean}visibleOnly visibleOnly为true时仅遍历可见的节点,如果父级节点不可见则不再访问其子节点
  7248. */
  7249. MeshVisualizer.traverse = function (node, traverseFunc, visibleOnly, scratchTraverseArgs) {
  7250. if (!node) {
  7251. return;
  7252. }
  7253. if (!scratchTraverseArgs) {
  7254. scratchTraverseArgs = {
  7255. cancelCurrent: false,
  7256. cancelAll: false
  7257. };
  7258. }
  7259. scratchTraverseArgs.cancelCurrent = false;
  7260. if (visibleOnly && (!node.show && !node.visible)) {
  7261. return;
  7262. }
  7263. if ((node.geometry && node.material) || node instanceof LOD || node instanceof ReferenceMesh) {
  7264. traverseFunc(node, scratchTraverseArgs);
  7265. }
  7266. if (node.children) {
  7267. for (var i = 0; i < node.children.length; i++) {
  7268. if (scratchTraverseArgs.cancelCurrent) {
  7269. continue;
  7270. }
  7271. if (scratchTraverseArgs.cancelAll) {
  7272. break;
  7273. }
  7274. MeshVisualizer.traverse(node.children[i], traverseFunc, visibleOnly, scratchTraverseArgs);
  7275. }
  7276. }
  7277. },
  7278. /**
  7279. *
  7280. *@Cesium.MeshVisualizer~TraverseCallback
  7281. *@param {Cesium.Mesh|Cesium.LOD|Cesium.MeshVisualizer|Object}node
  7282. *@param {Object}traverseArgs
  7283. *@param {Boolean}traverseArgs.cancelCurrent 为true时终止遍历当前节点的子节点
  7284. *@param {Boolean}traverseArgs.cancelAll 为true时终止遍历,退出遍历循环
  7285. */
  7286. Object.defineProperties(MeshVisualizer.prototype, {
  7287. scene: {
  7288. set: function (val) {
  7289. this._scene = val;
  7290. },
  7291. get: function () {
  7292. return this._scene;
  7293. }
  7294. },
  7295. frameState: {
  7296. get: function () {
  7297. if (!this._scene) {
  7298. return undefined;
  7299. }
  7300. return this._scene.frameState;
  7301. }
  7302. },
  7303. modelMatrixNeedsUpdate: {
  7304. get: function () {
  7305. return this._modelMatrixNeedsUpdate;
  7306. },
  7307. set: function (val) {
  7308. this._modelMatrixNeedsUpdate = val;
  7309. if (val) {
  7310. MeshVisualizer.traverse(this, function (child) {
  7311. child._modelMatrixNeedsUpdate = val;
  7312. }, false);
  7313. }
  7314. }
  7315. },
  7316. showReference: {
  7317. get: function () {
  7318. return this.referenceMesh.show;
  7319. },
  7320. set: function (val) {
  7321. this.referenceMesh.show = val;
  7322. }
  7323. },
  7324. children: {
  7325. get: function () {
  7326. return this._chidren;
  7327. },
  7328. set: function (val) {
  7329. this._chidren = val;
  7330. }
  7331. },
  7332. show: {
  7333. get: function () {
  7334. return this._show;
  7335. },
  7336. set: function (val) {
  7337. this._show = val;
  7338. }
  7339. },
  7340. debug: {
  7341. get: function () {
  7342. return this._debug;
  7343. },
  7344. set: function (val) {
  7345. this._debug = val;
  7346. }
  7347. },
  7348. ready: {
  7349. get: function () {
  7350. return this._ready;
  7351. }
  7352. },
  7353. modelMatrix: {
  7354. get: function () {
  7355. return this._modelMatrix;
  7356. },
  7357. set: function (val) {
  7358. this._modelMatrix = val;
  7359. this._modelMatrixNeedsUpdate = true;
  7360. }
  7361. },
  7362. rotation: {
  7363. get: function () {
  7364. return this._rotation;
  7365. },
  7366. set: function (val) {
  7367. if (val != this._rotation) {
  7368. this._rotation = val;
  7369. this._needUpdate = true;
  7370. }
  7371. this._rotation.paramChanged.removeEventListener(this._onNeedUpdateChanged);
  7372. this._rotation = val;
  7373. this._rotation.paramChanged.addEventListener(this._onNeedUpdateChanged);
  7374. }
  7375. },
  7376. position: {
  7377. get: function () {
  7378. return this._position;
  7379. },
  7380. set: function (val) {
  7381. if (val.x != this._position.x || val.y != this._position.y || val.z != this._position.z) {
  7382. this._position = val;
  7383. this._modelMatrixNeedsUpdate = true;
  7384. }
  7385. this._position = val;
  7386. }
  7387. },
  7388. scale: {
  7389. get: function () {
  7390. return this._scale;
  7391. },
  7392. set: function (val) {
  7393. if (val.x != this._scale.x || val.y != this._scale.y || val.z != this._scale.z) {
  7394. this._scale = val;
  7395. this._modelMatrixNeedsUpdate = true;
  7396. }
  7397. this._scale = val;
  7398. }
  7399. }
  7400. });
  7401. return MeshVisualizer;
  7402. });
  7403. define('Core/BasicMeshMaterial',[
  7404. 'Core/MeshMaterial',
  7405. 'Core/Shaders/ShaderChunk',
  7406. 'Core/Shaders/ShaderLib',
  7407. 'Util/Path'
  7408. ], function (
  7409. MeshMaterial,
  7410. ShaderChunk,
  7411. ShaderLib,
  7412. Path
  7413. ) {
  7414. var WebGLConstants = Cesium.WebGLConstants;
  7415. function BasicMeshMaterial(options) {
  7416. options = options ? options : {};
  7417. options.uniforms = options.uniforms ? options.uniforms : {
  7418. ambientColor: [0, 0, 0, 1.0], // Ka
  7419. emissionColor: [0, 0, 0, 1.0], // Ke
  7420. diffuseColor: [0, 0, 0, 1.0], // Kd
  7421. specularColor: [0, 0, 0, 1.0], // Ks
  7422. specularShininess: 0, // Ns
  7423. alpha: undefined, // d / Tr
  7424. ambientColorMap: undefined, // map_Ka
  7425. emissionColorMap: undefined, // map_Ke
  7426. diffuseColorMap: undefined, // map_Kd
  7427. specularColorMap: undefined, // map_Ks
  7428. specularShininessMap: undefined, // map_Ns
  7429. normalMap: undefined, // map_Bump
  7430. alphaMap: undefined // map_d
  7431. };
  7432. options.uniforms.ambientColor = Cesium.defaultValue(options.uniforms.ambientColor, [0, 0, 0, 1.0]);
  7433. options.uniforms.emissionColor = Cesium.defaultValue(options.uniforms.emissionColor, [0, 0, 0, 1.0]);
  7434. options.uniforms.diffuseColor = Cesium.defaultValue(options.uniforms.diffuseColor, [0, 0, 0, 1.0]);
  7435. options.uniforms.specularColor = Cesium.defaultValue(options.uniforms.specularColor, [0, 0, 0, 1.0]);
  7436. options.uniforms.alpha = Cesium.defaultValue(options.uniforms.alpha, 1);
  7437. options.uniforms.specularShininess = Cesium.defaultValue(options.uniforms.specularShininess, 0);
  7438. options.side = Cesium.defaultValue(options.side, MeshMaterial.Sides.FRONT)
  7439. MeshMaterial.apply(this, [options]);
  7440. this.blendEnable = false;
  7441. var withTexture = options.withTexture;
  7442. var withNormals = options.withNormals;
  7443. this.depthTest = true;
  7444. this.depthMask = true;
  7445. this.blending = true;
  7446. if (options.uniforms.diffuseColorMap) {//&& options.uniforms.diffuseColorMap.toLowerCase().indexOf(".png")) {
  7447. if (typeof options.uniforms.diffuseColorMap === 'string') {
  7448. var diffuseColorMap = options.uniforms.diffuseColorMap.toLowerCase();
  7449. var extension = Path.GetExtension(diffuseColorMap);
  7450. if (extension == ".tif" || extension == ".png") {
  7451. this.translucent = true;
  7452. } else if (diffuseColorMap.slice(0, "data:image/png".length) === "data:image/png") {
  7453. this.translucent = true;
  7454. } else if (diffuseColorMap.slice(0, "data:image/tif".length) === "data:image/tif") {
  7455. this.translucent = true;
  7456. }
  7457. } else if (diffuseColorMap instanceof HTMLCanvasElement
  7458. || diffuseColorMap instanceof HTMLVideoElement
  7459. ) {
  7460. this.translucent = true;
  7461. }
  7462. withTexture = true;
  7463. if (!Cesium.defined(this.uniforms.diffuseColorMap.flipY)) {
  7464. this.uniforms.diffuseColorMap.flipY = false;
  7465. }
  7466. if (!this.uniforms.diffuseColorMap.sampler) {
  7467. var sampler = {};
  7468. sampler.magnificationFilter = WebGLConstants.LINEAR;
  7469. sampler.minificationFilter = WebGLConstants.NEAREST_MIPMAP_LINEAR;
  7470. sampler.wrapS = WebGLConstants.REPEAT;
  7471. sampler.wrapT = WebGLConstants.REPEAT;
  7472. this.uniforms.diffuseColorMap.sampler = sampler;
  7473. }
  7474. } else {
  7475. withTexture = false;
  7476. }
  7477. var vertexShaderUri = null;// "texture_normals.vert";
  7478. var fragmentShaderUri = null; //"texture_normals.frag";
  7479. if (withTexture && withNormals) {
  7480. vertexShaderUri = ShaderChunk.texture_normals_vert;// "texture_normals.vert";
  7481. fragmentShaderUri = ShaderChunk.texture_normals_frag; //"texture_normals.frag";
  7482. } else if (withTexture && !withNormals) {
  7483. vertexShaderUri = ShaderChunk.texture_vert;//"texture.vert";
  7484. fragmentShaderUri = ShaderChunk.texture_frag;// "texture.frag";
  7485. } else if (!withTexture && withNormals) {
  7486. vertexShaderUri = ShaderChunk.normals_vert;// "normals.vert";
  7487. fragmentShaderUri = ShaderChunk.normals_frag;//"normals.frag";
  7488. }
  7489. else {
  7490. vertexShaderUri = ShaderChunk.none_vert;// "none.vert";
  7491. fragmentShaderUri = ShaderChunk.none_frag;// "none.frag";
  7492. }
  7493. this.vertexShader = vertexShaderUri;
  7494. this.fragmentShader = fragmentShaderUri;
  7495. }
  7496. BasicMeshMaterial.prototype = new MeshMaterial();
  7497. return BasicMeshMaterial;
  7498. });
  7499. define('Core/BasicGeometry',[], function () {
  7500. /**
  7501. *
  7502. *@param {Object}options
  7503. *@param {Array<Number>|Float32Array}options.positions
  7504. *@param {Array<Number>|Int32Array}options.indices
  7505. *@param {Array<Number>|Float32Array}[options.normals]
  7506. *@param {Array<Number>|Float32Array}[options.uvs]
  7507. *
  7508. *@memberof Cesium
  7509. *@constructor
  7510. */
  7511. function BasicGeometry(options) {
  7512. this.positions = options.positions;
  7513. this.normals = options.normals;
  7514. this.uvs = options.uvs;
  7515. this.indices = options.indices;
  7516. }
  7517. /**
  7518. *
  7519. *@param {Cesium.BasicGeometry}basicGeometry
  7520. *@return {Cesiumm.Geometry}
  7521. */
  7522. BasicGeometry.createGeometry = function (basicGeometry) {
  7523. if (!basicGeometry.positions) {
  7524. throw new Error("缺少positions参数");
  7525. }
  7526. if (!basicGeometry.indices) {
  7527. throw new Error("缺少indices参数");
  7528. }
  7529. var positions = basicGeometry.positions;
  7530. var normals = basicGeometry.normals;
  7531. var uvs = basicGeometry.uvs;
  7532. var indices = basicGeometry.indices instanceof Int32Array ? basicGeometry.indices : new Int32Array(basicGeometry.indices);
  7533. var attributes = {
  7534. position: new Cesium.GeometryAttribute({
  7535. componentDatatype: Cesium.ComponentDatatype.DOUBLE,
  7536. componentsPerAttribute: 3,
  7537. values: positions instanceof Float32Array ? positions : new Float32Array(basicGeometry.positions)
  7538. })
  7539. };
  7540. if (normals) {
  7541. attributes.normal = new Cesium.GeometryAttribute({
  7542. componentDatatype: Cesium.ComponentDatatype.FLOAT,
  7543. componentsPerAttribute: 3,
  7544. values: normals instanceof Float32Array ? normals : new Float32Array(normals)
  7545. })
  7546. }
  7547. if (uvs) {
  7548. attributes.uv = new Cesium.GeometryAttribute({
  7549. componentDatatype: Cesium.ComponentDatatype.FLOAT,
  7550. componentsPerAttribute: 2,
  7551. values: uvs instanceof Float32Array ? uvs : new Float32Array(uvs)
  7552. })
  7553. }
  7554. var bs = Cesium.BoundingSphere.fromVertices(positions);
  7555. var geo = new Cesium.Geometry({
  7556. attributes: attributes,
  7557. indices: new Int32Array(indices),
  7558. primitiveType: Cesium.PrimitiveType.TRIANGLES,
  7559. boundingSphere: bs
  7560. });
  7561. return geo;
  7562. }
  7563. return BasicGeometry;
  7564. });
  7565. define('Core/PlaneBufferGeometry',[
  7566. 'Core/BasicGeometry'
  7567. ], function (
  7568. BasicGeometry
  7569. ) {
  7570. /**
  7571. *
  7572. *@param {Number}width
  7573. *@param {Number}height
  7574. *@param {Number}widthSegments
  7575. *@param {Number}heightSegments
  7576. *@constructor
  7577. *@memberof Cesium
  7578. */
  7579. function PlaneBufferGeometry(width, height, widthSegments, heightSegments) {
  7580. this.width = width;
  7581. this.height = height;
  7582. this.widthSegments = widthSegments;
  7583. this.heightSegments = heightSegments;
  7584. }
  7585. /**
  7586. *
  7587. *@param {}
  7588. */
  7589. PlaneBufferGeometry.createGeometry = function (planeBufferGeometry) {
  7590. var width = planeBufferGeometry.width,
  7591. height = planeBufferGeometry.height,
  7592. widthSegments = planeBufferGeometry.widthSegments,
  7593. heightSegments = planeBufferGeometry.heightSegments;
  7594. width = width || 1;
  7595. height = height || 1;
  7596. var width_half = width / 2;
  7597. var height_half = height / 2;
  7598. var gridX = Math.floor(widthSegments) || 1;
  7599. var gridY = Math.floor(heightSegments) || 1;
  7600. var gridX1 = gridX + 1;
  7601. var gridY1 = gridY + 1;
  7602. var segment_width = width / gridX;
  7603. var segment_height = height / gridY;
  7604. var ix, iy;
  7605. // buffers
  7606. var indices = [];
  7607. var vertices = [];
  7608. var normals = [];
  7609. var uvs = [];
  7610. // generate vertices, normals and uvs
  7611. for (iy = 0; iy < gridY1; iy++) {
  7612. var y = iy * segment_height - height_half;
  7613. for (ix = 0; ix < gridX1; ix++) {
  7614. var x = ix * segment_width - width_half;
  7615. vertices.push(x, -y, 0);
  7616. normals.push(0, 0, 1);
  7617. uvs.push(ix / gridX);
  7618. uvs.push(1 - (iy / gridY));
  7619. }
  7620. }
  7621. // indices
  7622. for (iy = 0; iy < gridY; iy++) {
  7623. for (ix = 0; ix < gridX; ix++) {
  7624. var a = ix + gridX1 * iy;
  7625. var b = ix + gridX1 * (iy + 1);
  7626. var c = (ix + 1) + gridX1 * (iy + 1);
  7627. var d = (ix + 1) + gridX1 * iy;
  7628. // faces
  7629. indices.push(a, b, d);
  7630. indices.push(b, c, d);
  7631. }
  7632. }
  7633. var geom= BasicGeometry.createGeometry({
  7634. positions: new Float32Array(vertices),
  7635. normals: new Float32Array(normals),
  7636. uvs: new Float32Array(uvs),
  7637. indices: new Int32Array(indices)
  7638. })
  7639. return geom;
  7640. }
  7641. return PlaneBufferGeometry;
  7642. });
  7643. define('Main',[
  7644. 'Core/RendererUtils',
  7645. 'Core/Mesh',
  7646. 'Core/MeshMaterial',
  7647. 'Core/Shaders/ShaderChunk',
  7648. 'Core/MeshVisualizer',
  7649. 'Core/FramebufferTexture',
  7650. 'Core/GeometryUtils',
  7651. 'Core/LOD',
  7652. 'Core/PlaneGeometry',
  7653. 'Core/Rotation',
  7654. 'Core/ReferenceMesh',
  7655. 'Core/BasicMeshMaterial',
  7656. 'Core/BasicGeometry',
  7657. 'Core/Shaders/ShaderLib',
  7658. 'Core/PlaneBufferGeometry',
  7659. 'Util/CSG',
  7660. 'Core/MeshPhongMaterial',
  7661. 'Core/MaterialUtils',
  7662. 'Core/ShaderUtils'
  7663. ], function (
  7664. RendererUtils,
  7665. Mesh,
  7666. MeshMaterial,
  7667. ShaderChunk,
  7668. MeshVisualizer,
  7669. FramebufferTexture,
  7670. GeometryUtils,
  7671. LOD,
  7672. PlaneGeometry,
  7673. Rotation,
  7674. ReferenceMesh,
  7675. BasicMeshMaterial,
  7676. BasicGeometry,
  7677. ShaderLib,
  7678. PlaneBufferGeometry,
  7679. CSG,
  7680. MeshPhongMaterial,
  7681. MaterialUtils,
  7682. ShaderUtils
  7683. ) {
  7684. if (typeof Cesium==='undefined') {
  7685. Cesium = {};
  7686. }
  7687. Cesium.RendererUtils = RendererUtils;
  7688. Cesium.Mesh = Mesh;
  7689. Cesium.MeshMaterial = MeshMaterial;
  7690. Cesium.ShaderChunk = ShaderChunk;
  7691. Cesium.ShaderLib = ShaderLib;
  7692. Cesium.MeshVisualizer = MeshVisualizer;
  7693. Cesium.FramebufferTexture = FramebufferTexture;
  7694. Cesium.GeometryUtils = GeometryUtils;
  7695. Cesium.LOD = LOD;
  7696. Cesium.PlaneGeometry = PlaneGeometry;
  7697. Cesium.Rotation = Rotation;
  7698. Cesium.ReferenceMesh = ReferenceMesh;
  7699. Cesium.BasicMeshMaterial = BasicMeshMaterial;
  7700. Cesium.BasicGeometry = BasicGeometry;
  7701. Cesium.PlaneBufferGeometry = PlaneBufferGeometry;
  7702. Cesium.CSG = CSG;
  7703. Cesium.MeshPhongMaterial = MeshPhongMaterial;
  7704. Cesium.MaterialUtils = MaterialUtils;
  7705. Cesium.ShaderUtils = ShaderUtils;
  7706. return Cesium;
  7707. });
  7708. require([
  7709. 'Main'
  7710. ], function (
  7711. Cesium) {
  7712. 'use strict';
  7713. /*global self*/
  7714. var scope = typeof window !== 'undefined' ? window : typeof self !== 'undefined' ? self : {};
  7715. scope.Cesium = Cesium;
  7716. if (scope.onLoad) {
  7717. scope.onLoad(Cesium)
  7718. }
  7719. }, undefined, true);
  7720. })();
  7721. if (typeof define === "function") {
  7722. define(function () {
  7723. var newLib = Cesium;
  7724. Cesium = undefined;
  7725. return newLib;
  7726. });
  7727. } else if (typeof module === "undefined") {
  7728. window.Cesium = Cesium;
  7729. } else {
  7730. module.exports = Cesium;
  7731. }